-
Notifications
You must be signed in to change notification settings - Fork 0
/
Element.cpp
1887 lines (1696 loc) · 52.9 KB
/
Element.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "StdAfx.h"
#include "Element.h"
#include "ElementFactory.h"
#include "Modeler1Doc.h"
#include "Modeler1View.h"
#include "MainFrm.h"
#include "DrawingContext.h"
#include "DrawingElements.h"
//
// CShapeType
//
ShapeType CShapeType::ToShapeType(int value)
{
ShapeType ret = ShapeType::unknown;
switch( value)
{
case line:
case line_right:
case rectangle:
case ellipse:
case rectangle_round:
case triangle:
case line_broken:
case line_broken_right:
case notimp_igloo:
case notimpl_multi_line:
case arrow_right:
case arrow_down:
case line2:
case line_right2:
case line_left_right:
case parenthese_left:
case parenthese_right:
case star:
ret = (ShapeType)value;
break;
case image_fixed:
case image_scaled:
ret = (ShapeType)value;
break;
case infrastructure_server_ad:
case infrastructure_server:
case infrastructure_server_web:
case infrastructure_server_database:
case infrastructure_workstation:
case infrastructure_laptop:
case infrastructure_firewall:
case infrastructure_network:
case infrastructure_virtual_server:
case infrastructure_virtual_server_web:
case infrastructure_virtual_server_database:
case infrastructure_virtualization_server:
case infrastructure_server_ad_grey:
case infrastructure_server_grey:
case infrastructure_server_database_grey:
case infrastructure_server_farm:
case infrastructure_workstation_grey:
case infrastructure_laptop_grey:
ret = (ShapeType)value;
break;
case text:
case text_left:
case text_center:
case text_right:
case text_justify:
ret = (ShapeType)value;
break;
case development_class:
case development_interface:
case development_enumeration:
case development_package:
case development_comment:
case development_association:
case development_aggregation:
case development_composition:
case development_dependency:
case development_inheritance:
case development_package_import:
case development_connector:
case development_component:
ret = (ShapeType)value;
break;
case planning_month:
case planning_task:
ret = (ShapeType)value;
default: break;
}
return ret;
}
//
// CElement Class
//
IMPLEMENT_SERIAL(CElement, CObject, VERSIONABLE_SCHEMA | 11)
int CElement::m_counter = 0;
std::wstring CElement::m_elementGroupNames = _T("");
std::wstring CElement::m_elementGroupElements = _T("");
CElement::CElement()
{
m_pManager = NULL;
m_pView = NULL;
m_shapeType = ShapeType::unknown;
m_rect.SetRectEmpty();
m_point = CPoint(0, 0);
m_last = m_point;
m_text = _T("");
m_code = _T("");
m_textAlign = _T("Left");
m_bColorFill = true;
m_colorFill = RGB(154, 200, 249);
m_bSolidColorFill = false;
m_bColorLine = true;
m_colorLine = RGB(0, 0, 0);
m_bLineWidth = true;
m_lineWidth = 1;
m_image = _T("");
m_bFixed = true;
m_fontName = _T("Calibri");
m_fontSize = 12;
m_bBold = false;
m_bItalic = false;
m_bUnderline = false;
m_bStrikeThrough = false;
m_colorText = RGB(0, 0, 0);
m_pConnector = make_shared<CConnector>();
m_pConnector->m_pElement1 = nullptr;
m_pConnector->m_pElement2 = nullptr;
m_connectorName1 = _T("");
m_connectorName2 = _T("");
m_connectorDragHandle1 = 0;
m_connectorDragHandle2 = 0;
m_document = _T("");
m_documentType = DocumentType::document_none;
m_documentTypeText = _T("None");
m_bMoving = FALSE;
m_type = ElementType::type_unknown;
m_shapeType = ShapeType::unknown;
SetGuid();
SetName();
}
CElement::~CElement(void)
{
}
void CElement::SetGuid()
{
USES_CONVERSION;
m_counter++;
CGuid guid;
#ifdef GUID_TRUE
m_objectId = guid.ToString();
#else
SYSTEMTIME st;
GetSystemTime(&st);
CTime dt = CTime::GetCurrentTime();
CString objectId;
objectId.Format(_T("guid_%d_%s_%03d_%ld"), m_counter, dt.Format(_T("%H%M%S")), st.wMilliseconds, GetTickCount());
this->m_objectId = T2W((LPTSTR)(LPCTSTR)objectId);
#endif
}
void CElement::SetName()
{
USES_CONVERSION;
// element name
CTime dt = CTime::GetCurrentTime();
CString name;
name.Format(_T("Element n_%d"), CFactory::g_counter); //_%s.%03d", dt.Format("%H%M%S"), tm.wMilliseconds);
this->m_name = T2W((LPTSTR)(LPCTSTR)name);
}
std::shared_ptr<CElement> CElement::MakeCopy()
{
std::shared_ptr<CElement> pNewElement = CFactory::CreateElementOfType((ElementType)this->m_type,
(ShapeType)this->m_shapeType);
pNewElement->m_name = this->m_name;
pNewElement->m_objectId = this->m_objectId;
pNewElement->m_caption = this->m_caption;
pNewElement->m_text = this->m_text;
pNewElement->m_code = this->m_code;
pNewElement->m_image = this->m_image;
pNewElement->m_lineWidth = this->m_lineWidth;
pNewElement->m_pManager = this->m_pManager;
pNewElement->m_pView = this->m_pView;
pNewElement->m_rect = this->m_rect;
pNewElement->m_bColorFill = m_bColorFill;
pNewElement->m_bColorLine = m_bColorLine;
pNewElement->m_bLineWidth = m_bLineWidth;
pNewElement->m_bSolidColorFill = m_bSolidColorFill;
pNewElement->m_colorFill = m_colorFill;
pNewElement->m_colorLine = m_colorLine;
pNewElement->m_textAlign = m_textAlign;
pNewElement->m_fontName = m_fontName;
pNewElement->m_bFixed = m_bFixed;
pNewElement->m_bBold = m_bBold;
pNewElement->m_bItalic = m_bItalic;
pNewElement->m_bUnderline = m_bUnderline;
pNewElement->m_bStrikeThrough = m_bStrikeThrough;
pNewElement->m_code = m_code;
pNewElement->m_fontSize = m_fontSize;
pNewElement->m_colorText = m_colorText;
pNewElement->m_document = m_document;
pNewElement->m_elementGroupNames = m_elementGroupNames;
pNewElement->m_elementGroupElements = m_elementGroupElements;
pNewElement->m_documentType = m_documentType;
pNewElement->m_connectorDragHandle1 = m_connectorDragHandle1;
pNewElement->m_connectorDragHandle2 = m_connectorDragHandle2;
return pNewElement;
}
CElement::CElement(const CElement& element)
{
this->m_name = element.m_name;
this->m_objectId = element.m_objectId;
this->m_caption = element.m_caption;
this->m_text = element.m_text;
this->m_code = element.m_code;
this->m_image = element.m_image;
this->m_lineWidth = element.m_lineWidth;
this->m_pManager = element.m_pManager;
this->m_pView = element.m_pView;
this->m_rect = element.m_rect;
this->m_bColorFill = element.m_bColorFill;
this->m_bColorLine = element.m_bColorLine;
this->m_bLineWidth = element.m_bLineWidth;
this->m_bSolidColorFill = element.m_bSolidColorFill;
this->m_colorFill = element.m_colorFill;
this->m_colorLine = element.m_colorLine;
this->m_textAlign = element.m_textAlign;
this->m_fontName = element.m_fontName;
this->m_bFixed = element.m_bFixed;
this->m_bBold = element.m_bBold;
this->m_bItalic = element.m_bItalic;
this->m_bUnderline = element.m_bUnderline;
this->m_bStrikeThrough = element.m_bStrikeThrough;
this->m_code = element.m_code;
this->m_fontSize = element.m_fontSize;
this->m_colorText = element.m_colorText;
this->m_document = m_document;
this->m_elementGroupNames = m_elementGroupNames;
this->m_elementGroupElements = m_elementGroupElements;
this->m_documentType = m_documentType;
this->m_connectorDragHandle1 = m_connectorDragHandle1;
this->m_connectorDragHandle2 = m_connectorDragHandle2;
}
CString CElement::ToString(shared_ptr<CElement> pElement)
{
CString str = pElement == nullptr ? _T("") : W2T((LPTSTR)pElement->m_name.c_str());
return str;
}
shared_ptr<CElement> CElement::FromJSON(const web::json::object& object)
{
ElementType type = (ElementType)(object.at(U("Type")).as_integer());
ShapeType shapeType = (ShapeType)(object.at(U("ShapeType")).as_integer());
//shared_ptr<CElement> pElement = make_shared<CElement>();
std::shared_ptr<CElement> pElement = CFactory::CreateElementOfType(type, shapeType);
pElement->m_objectId = object.at(U("ObjectId")).as_string();
pElement->m_name = object.at(U("Name")).as_string();
pElement->m_caption = object.at(U("Caption")).as_string();
pElement->m_text = object.at(U("Text")).as_string();
pElement->m_code = object.at(U("Code")).as_string();
pElement->m_type = (ElementType)(object.at(U("Type")).as_integer());
pElement->m_shapeType = (ShapeType)(object.at(U("ShapeType")).as_integer());
int left = object.at(U("Rect.left")).as_integer();
int right = object.at(U("Rect.right")).as_integer();
int top = object.at(U("Rect.top")).as_integer();
int bottom = object.at(U("Rect.bottom")).as_integer();
CRect rect(left, top, right, bottom);
pElement->m_rect = rect;
int px = object.at(U("Point.x")).as_integer();
int py = object.at(U("Point.y")).as_integer();
CPoint point(px, py);
pElement->m_last = point;
pElement->m_colorFill = (COLORREF)(object.at(U("ColorFill")).as_integer());
pElement->m_colorLine = (COLORREF)(object.at(U("ColorLine")).as_integer());
pElement->m_lineWidth = (COLORREF)(object.at(U("LineWidth")).as_integer());
pElement->m_bColorFill = (object.at(U("bColorFill")).as_integer()) == 1 ? true: false;
pElement->m_bColorLine = (object.at(U("bColorLine")).as_integer()) == 1 ? true : false;
pElement->m_bLineWidth = (object.at(U("bLineWidth")).as_integer()) == 1 ? true : false;
pElement->m_textAlign = object.at(U("TextAlign")).as_string();
pElement->m_fontName = object.at(U("FontName")).as_string();;
pElement->m_bFixed = object.at(U("bFixed")).as_integer();
pElement->m_bBold = object.at(U("bBold")).as_integer();
pElement->m_bItalic = object.at(U("bItalic")).as_integer();
pElement->m_bUnderline = object.at(U("bUnderline")).as_integer();
pElement->m_bStrikeThrough = object.at(U("bStrikeThrough")).as_integer();
pElement->m_code = object.at(U("Code")).as_string();;
pElement->m_fontSize = object.at(U("FontSize")).as_integer();
pElement->m_colorText = (COLORREF)(object.at(U("ColorText")).as_integer());
pElement->m_document = object.at(U("Document")).as_string();
pElement->m_documentType = (DocumentType)(object.at(U("DocumentType")).as_integer());
pElement->m_elementGroupNames = object.at(U("GroupNames")).as_string();
pElement->m_elementGroupElements = object.at(U("GroupElements")).as_string();
pElement->m_connectorDragHandle1 = object.at(U("ConnectorDragHandle1")).as_integer();
pElement->m_connectorDragHandle2 = object.at(U("ConnectorDragHandle2")).as_integer();
pElement->m_connectorName1 = object.at(U("ConnectorName1")).as_string();
pElement->m_connectorName2 = object.at(U("ConnectorName2")).as_string();
return pElement;
}
web::json::value CElement::AsJSON() const
{
web::json::value res = web::json::value::object();
res[U("ObjectId")] = web::json::value::string(m_objectId);
res[U("Name")] = web::json::value::string(m_name);
res[U("Caption")] = web::json::value::string(m_caption);
res[U("Text")] = web::json::value::string(m_text);
res[U("Code")] = web::json::value::string(m_code);
res[U("Type")] = web::json::value::number(m_type);
res[U("ShapeType")] = web::json::value::number(m_shapeType);
res[U("Rect.left")] = web::json::value::number(m_rect.left);
res[U("Rect.right")] = web::json::value::number(m_rect.right);
res[U("Rect.top")] = web::json::value::number(m_rect.top);
res[U("Rect.bottom")] = web::json::value::number(m_rect.bottom);
res[U("Point.x")] = web::json::value::number(m_point.x);
res[U("Point.y")] = web::json::value::number(m_point.y);
res[U("Last.x")] = web::json::value::number(m_last.x);
res[U("Last.y")] = web::json::value::number(m_last.y);
res[U("ColorFill")] = web::json::value::number((int)m_colorFill);
res[U("ColorLine")] = web::json::value::number((int)m_colorLine);
res[U("LineWidth")] = web::json::value::number((int)m_lineWidth);
res[U("Image")] = web::json::value::string(m_image);
res[U("bColorFill")] = web::json::value::number((int)m_bColorFill);
res[U("bColorLine")] = web::json::value::number((int)m_bColorLine);
res[U("bLineWidth")] = web::json::value::number((int)m_bLineWidth);
res[U("TextAlign")] = web::json::value::string(m_textAlign);
res[U("FontName")] = web::json::value::string(m_fontName);
res[U("bFixed")] = web::json::value::number((int)m_bFixed);
res[U("bBold")] = web::json::value::number((int)m_bBold);
res[U("bItalic")] = web::json::value::number((int)m_bItalic);
res[U("bUnderline")] = web::json::value::number((int)m_bUnderline);
res[U("bStrikeThrough")] = web::json::value::number((int)m_bStrikeThrough);
res[U("Code")] = web::json::value::string(m_code);
res[U("FontSize")] = web::json::value::number(m_fontSize);
res[U("ColorText")] = web::json::value::number((int)m_colorText);
res[U("Document")] = web::json::value::string(m_document);
res[U("DocumentType")] = web::json::value::number(m_documentType);
res[U("GroupNames")] = web::json::value::string(m_elementGroupNames);
res[U("GroupElements")] = web::json::value::string(m_elementGroupElements);
res[U("ConnectorDragHandle1")] = web::json::value::number(m_connectorDragHandle1);
res[U("ConnectorDragHandle2")] = web::json::value::number(m_connectorDragHandle2);
res[U("ConnectorName1")] = web::json::value::string(m_connectorName1);
res[U("ConnectorName2")] = web::json::value::string(m_connectorName2);
return res;
}
void CElement::Serialize(CArchive& ar)
{
USES_CONVERSION;
if (ar.IsStoring())
{
// Get reteurn -1 by default
//int version = ar.GetObjectSchema();
//CString str;
//str.Format(_T("version=%d"), version);
//AfxMessageBox(str);
//
// Set version of file format
//
ar.SetObjectSchema(11);
// The schema v11 contains extra info: connectorDragHandle1 & 2
ar << m_connectorDragHandle1;
ar << m_connectorDragHandle2;
// The schema v10 contains extra info: documenttypetext
//CString doct = W2T((LPTSTR)m_documentTypeText.c_str());
//ar << doct;
int doct = m_documentType;
ar << doct;
// The schema v9 contains extra info: names, elements
CString n;
CString elts;
for (shared_ptr<CElementGroup> pElementGroup : this->m_pManager->m_groups)
{
//elts += CString(_T("|"));
n += /*CString(_T("|")) +*/ CString(pElementGroup->m_name.c_str()) + CString(_T("|"));
for (shared_ptr<CElement> pElement : pElementGroup->m_Groups)
{
elts += CString(pElement->m_name.c_str()) + CString(_T(";"));
}
elts += CString(_T("|"));
}
CElement::m_elementGroupNames = n;
CElement::m_elementGroupElements = elts;
CString names = W2T((LPTSTR)CElement::m_elementGroupNames.c_str());
ar << names;
CString elements = W2T((LPTSTR)CElement::m_elementGroupElements.c_str());
ar << elements;
// The schema v8 contains extra info: document
CString doc = W2T((LPTSTR)m_document.c_str());
ar << doc;
// The schema v7 contains extra info: connector1 & 2
CString cn1 = CElement::ToString(m_pConnector->m_pElement1);
ar << cn1;
CString cn2 = CElement::ToString(m_pConnector->m_pElement2);
ar << cn2;
// The schema v6 contains extra info: colortext
ar << m_colorText;
// The schema v5 contains extra info: bold, italic, underline, StrikeThrough
ar << m_bBold;
ar << m_bItalic;
ar << m_bUnderline;
ar << m_bStrikeThrough;
// The schema v4 contains extra info: code
CString code = W2T((LPTSTR)m_code.c_str());
ar << code;
// The schema v3 contains extra info: fontName, fontSize and Fixed
CString fontName = W2T((LPTSTR)m_fontName.c_str());
ar << fontName;
int fontSize = m_fontSize;
ar << fontSize;
ar << m_bFixed;
// The schema v2 contains extra info: textAlign
CString textAlign = W2T((LPTSTR)m_textAlign.c_str());
ar << textAlign;
CString name = W2T((LPTSTR)m_name.c_str());
ar << name;
int type = m_type;
ar << type;
int shapeType = m_shapeType;
ar << shapeType;
CString objectId = W2T((LPTSTR)m_objectId.c_str());
ar << objectId;
CString caption = W2T((LPTSTR)m_caption.c_str());
ar << caption;
CString text = W2T((LPTSTR)m_text.c_str());
ar << text;
ar << m_rect;
ar << m_point;
ar << m_last;
ar << m_colorFill;
ar << m_bColorFill;
ar << m_colorLine;
ar << m_bColorLine;
ar << m_bColorLine;
ar << m_lineWidth;
CString image = W2T((LPTSTR)m_image.c_str());
ar << image;
}
else
{
int version = ar.GetObjectSchema();
//CString str;
//str.Format(_T("version=%d"), version);
//AfxMessageBox(str);
// get the document back pointer from the archive
CModeler1Doc * pDocument = (CModeler1Doc*)ar.m_pDocument;
m_pManager = pDocument->GetManager();
if (version >= 11)
{
ar >> m_connectorDragHandle1;
ar >> m_connectorDragHandle2;
}
if (version >= 10)
{
//CString doct;
//ar >> doct;
//this->m_documentTypeText = T2W((LPTSTR)(LPCTSTR)doct);
int doct;
ar >> doct;
m_documentType = (DocumentType)doct;
}
if (version >= 9)
{
CString names;
ar >> names;
CElement::m_elementGroupNames = T2W((LPTSTR)(LPCTSTR)names);
CString elements;
ar >> elements;
CElement::m_elementGroupElements = T2W((LPTSTR)(LPCTSTR)elements);
}
if (version >= 8)
{
CString doc;
ar >> doc;
this->m_document = T2W((LPTSTR)(LPCTSTR)doc);
}
if (version >= 7)
{
CString cn1;
ar >> cn1;
this->m_connectorName1 = T2W((LPTSTR)(LPCTSTR)cn1);
CString cn2;
ar >> cn2;
this->m_connectorName2 = T2W((LPTSTR)(LPCTSTR)cn2);
}
if (version >= 6)
{
ar >> m_colorText;
}
if (version >= 5)
{
ar >> m_bBold;
ar >> m_bItalic;
ar >> m_bUnderline;
ar >> m_bStrikeThrough;
}
if (version >= 4)
{
CString code;
ar >> code;
this->m_code = T2W((LPTSTR)(LPCTSTR)code);
}
if (version >= 3)
{
CString fontName;
ar >> fontName;
this->m_fontName = T2W((LPTSTR)(LPCTSTR)fontName);
int fontSize;
ar >> fontSize;
m_fontSize = fontSize;
ar >> m_bFixed;
}
if (version >= 2)
{
CString textAlign;
ar >> textAlign;
this->m_textAlign = T2W((LPTSTR)(LPCTSTR)textAlign);
}
CString name;
ar >> name;
this->m_name = T2W((LPTSTR)(LPCTSTR)name);
int type;
ar >> type;
m_type = (ElementType)type;
int shapeType;
ar >> shapeType;
m_shapeType = (ShapeType)shapeType;
CString objectId;
ar >> objectId;
this->m_objectId = T2W((LPTSTR)(LPCTSTR)objectId);
CString caption;
ar >> caption;
this->m_caption = T2W((LPTSTR)(LPCTSTR)caption);
CString text;
ar >> text;
this->m_text = T2W((LPTSTR)(LPCTSTR)text);
ar >> m_rect;
ar >> m_point;
ar >> m_last;
ar >> m_colorFill;
ar >> m_bColorFill;
ar >> m_colorLine;
ar >> m_bColorLine;
ar >> m_bColorLine;
ar >> m_lineWidth;
CString image;
ar >> image;
this->m_image = T2W((LPTSTR)(LPCTSTR)image);
}
}
CString CElement::ToString()
{
CString str;
str.Format(_T("Element name=<%s> id={%s} type=<%s> shape=<%s> rect={%d,%d,%d,%d} caption=<%s> text=<%s> connector=<%s> handle1=<%d> handle2=<%d> image=<%s> colorFill={%03d%03d%03d} colorLine={%03d%03d%03d}"),
m_name.c_str(), m_objectId.c_str(), ToString(m_type), ToString(m_shapeType),
m_rect.left, m_rect.top, m_rect.right, m_rect.bottom,
m_caption.c_str(), m_text.c_str(),
ToString(m_pConnector),
m_connectorDragHandle1, m_connectorDragHandle1,
m_image.c_str(),
GetRValue(m_colorFill), GetGValue(m_colorFill), GetBValue(m_colorFill),
GetRValue(m_colorLine), GetGValue(m_colorLine), GetBValue(m_colorLine));
return str;
}
CString CElement::ToString(shared_ptr<CConnector> pConnector)
{
CString str = _T("");
shared_ptr<CElement> pElement1 = pConnector->m_pElement1;
shared_ptr<CElement> pElement2 = pConnector->m_pElement2;
str.Format(_T("c1:%s c2:%s"), pElement1 == nullptr ? _T("NULL") : pElement1->m_name.c_str(),
pElement2 == nullptr ? _T("NULL") : pElement2->m_name.c_str());
return str;
}
CString CElement::ToString(ElementType type)
{
CString str = _T("");
switch(type)
{
case ElementType::type_unknown:
str = _T("type_unknown->not implemented yet");
break;
case ElementType::type_shapes_simple:
str = _T("type_shapes_simple");
break;
case ElementType::type_image:
str = _T("type_image");
break;
case ElementType::type_shapes_infrastructure:
str = _T("type_shapes_infrastructure");
break;
case ElementType::type_text:
str = _T("type_text");
break;
case ElementType::type_shapes_development:
str = _T("type_shapes_development");
break;
default:
break;
}
return str;
}
CString CElement::ToString(ShapeType type)
{
CString str = _T("");
switch(type)
{
case line:
str = _T("line");
break;
case line_right:
str = _T("line_right");
break;
case rectangle:
str = _T("rectangle");
break;
case ellipse:
str = _T("ellipse");
break;
case rectangle_round:
str = _T("rectangle_round");
break;
case triangle:
str = _T("triangle");
break;
case line_broken:
str = _T("line_broken");
break;
case line_broken_right:
str = _T("line_broken_right");
break;
case line2:
str = _T("line2");
break;
case line_right2:
str = _T("line_right2");
break;
case line_left_right:
str = _T("line_left_right");
break;
case arrow_right:
str = _T("arrow_right");
break;
case arrow_down:
str = _T("arrow_down");
break;
case parenthese_left:
str = _T("parenthese_left");
break;
case parenthese_right:
str = _T("parenthese_right");
break;
case star:
str = _T("star");
break;
case image_fixed:
str = _T("image_fixed");
break;
case image_scaled:
str = _T("image_scaled");
break;
case infrastructure_server_ad:
str = _T("infrastructure_server_ad");
break;
case infrastructure_server:
str = _T("infrastructure_server");
break;
case infrastructure_server_web:
str = _T("infrastructure_server_web");
break;
case infrastructure_server_database:
str = _T("infrastructure_server_web");
break;
case infrastructure_workstation:
str = _T("infrastructure_workstation");
break;
case infrastructure_laptop:
str = _T("infrastructure_laptop");
break;
case infrastructure_firewall:
str = _T("infrastructure_firewall");
break;
case infrastructure_network:
str = _T("infrastructure_network");
break;
case infrastructure_virtual_server:
str = _T("infrastructure_virtual_server");
break;
case infrastructure_virtual_server_web:
str = _T("infrastructure_virtual_server_web");
break;
case infrastructure_virtual_server_database:
str = _T("infrastructure_virtual_server_database");
break;
case infrastructure_virtualization_server:
str = _T("infrastructure_virtualization_server");
break;
case infrastructure_server_ad_grey:
str = _T("infrastructure_server_ad");
break;
case infrastructure_server_grey:
str = _T("infrastructure_server");
break;
case infrastructure_server_database_grey:
str = _T("infrastructure_server_database");
break;
case infrastructure_server_farm:
str = _T("infrastructure_server_farm");
break;
case infrastructure_workstation_grey:
str = _T("infrastructure_workstation");
break;
case infrastructure_laptop_grey:
str = _T("infrastructure_laptop");
break;
case text:
str = _T("text");
break;
case text_left:
str = _T("text_left");
break;
case text_center:
str = _T("text_center");
break;
case text_right:
str = _T("text_right");
break;
case text_justify:
str = _T("text_justify");
break;
case development_class:
str = _T("development_class");
break;
case development_interface:
str = _T("development_interface");
break;
case development_enumeration:
str = _T("development_enumeration");
break;
case development_package:
str = _T("development_package");
break;
case development_comment:
str = _T("development_comment");
break;
case development_association:
str = _T("development_association");
break;
case development_aggregation:
str = _T("development_aggregation");
break;
case development_composition:
str = _T("development_composition");
break;
case development_dependency:
str = _T("development_dependency");
break;
case development_inheritance:
str = _T("development_inheritance");
break;
case development_package_import:
str = _T("development_package_import");
break;
case development_connector:
str = _T("development_connector");
break;
case development_component:
str = _T("development_component");
break;
}
return str;
}
CString CElement::ToString(DocumentType type)
{
CString str = _T("");
switch (type)
{
case DocumentType::document_none:
str = _T("None");
break;
case DocumentType::document_file:
str = _T("File");
break;
case DocumentType::document_folder:
str = _T("Folder");
break;
case DocumentType::document_diagram:
str = _T("Diagram");
break;
default:
break;
}
return str;
}
DocumentType CElement::FromString(wstring type)
{
DocumentType doctype = DocumentType::document_none;
if (type == _T("None"))
{
doctype = DocumentType::document_none;
}
if (type == _T("File"))
{
doctype = DocumentType::document_file;
}
if (type == _T("Folder"))
{
doctype = DocumentType::document_folder;
}
if (type == _T("Diagram"))
{
doctype = DocumentType::document_diagram;
}
return doctype;
}
/*
bool CElement::IsDrawable(ElementType type)
{
bool ret = false;
switch(type)
{
case ElementType::type_rectangle:
case ElementType::type_class:
case ElementType::type_line:
case ElementType::type_ellipse:
case ElementType::type_image:
case ElementType::type_shapes:
ret = true;
break;
}
return ret;
}
*/
bool CElement::CanChangeFillColor() const
{
return true;
}
bool CElement::CanChangeLineColor() const
{
return true;
}
bool CElement::CanChangeLineWidth() const
{
return true;
}
bool CElement::Intersects(const CRect& rect)
{
CRect fixed = m_rect;
CSize addSize(5,5);
fixed.InflateRect(addSize);
fixed.NormalizeRect();
CRect rectT = rect;
rectT.NormalizeRect();
// Debug
#ifdef DRAW_EXTERNAL_RECTANGLE_HITS
//CClientDC dc(this->m_pView);
//Graphics graphics(dc.m_hDC);
//
//Color colorBlack(255, 0, 0, 0);
//Pen penBlack(colorBlack);
//CRect rect1 = fixed;
//CRect rect2 = rectT;
//CRect rect3 = rect1 & rect2;
//GetManager()->ManagerToView(this->m_pView, rect1);
//GetManager()->ManagerToView(this->m_pView, rect2);
//GetManager()->ManagerToView(this->m_pView, rect3);
//graphics.DrawRectangle(&penBlack, rect1.left, rect1.top, rect1.Width(), rect1.Height());
//graphics.DrawRectangle(&penBlack, rect2.left, rect2.top, rect2.Width(), rect2.Height());
//graphics.DrawRectangle(&penBlack, rect3.left, rect3.top, rect3.Width(), rect3.Height());
#endif
return !(rectT & fixed).IsRectEmpty();
}
bool CElement::IsLine()
{
if( m_shapeType == ShapeType::line || m_shapeType == ShapeType::line2 ||
m_shapeType == ShapeType::line_left_right ||
m_shapeType == ShapeType::line_broken || m_shapeType == line_broken_right ||
m_shapeType == ShapeType::line_right || m_shapeType == ShapeType::line_right2 )
{
return true;
}
else
{
return false;
}
}
void CElement::InvalidateObj(void)
{
this->m_rect.SetRect(this->m_point, this->m_last);
if( IsLine() )
{
}
else
{
// rectangle
this->m_rect.NormalizeRect();
}
}
void CElement::CheckForKeepingAMinimumSize()
{
const int defaultSize = 10;
// For all types
if( m_type == type_shapes_simple || m_type == type_image ) //m_type == type_shapes_infrastructure ) //|| )
{
if( m_rect.Width() < defaultSize && m_rect.Height() < defaultSize )
{
CPoint p1 = m_rect.TopLeft();
CPoint p2;
p2.x = p1.x + defaultSize;
p2.y = p1.y + defaultSize;
m_rect.SetRect(p1, p2);
}
}
}
// Selection & Tracker helpers