-
Notifications
You must be signed in to change notification settings - Fork 0
/
ElementManager.cpp
2935 lines (2455 loc) · 76.6 KB
/
ElementManager.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 "Modeler1.h"
#include "ElementManager.h"
#include "Modeler1View.h"
#include "MainFrm.h"
#include "DrawingContext.h"
#include "DrawingElements.h"
#include <sstream>
#include "TabbedView.h"
#include "Modeler1SourceView.h"
//
// CElementManager
//
IMPLEMENT_SERIAL(CElementManager, CObject, VERSIONABLE_SCHEMA | 11)
CElementManager::CElementManager()
{
m_objectId = L"";
m_lastPoint = CPoint(0, 0);
m_paperColor = RGB(255, 255, 255); //RGB(242, 242, 200); //RGB(255, 255, 255); //RGB(188, 251, 255);
m_size = CSize(3000, 3000);
// Initialize Current UI interaction members
m_bDrawing = FALSE;
// Current selected drawing tool = SELECT
m_type = ElementType::type_select;
// Current selected shape type from Ribbon = type_unknown
m_shapeType = ShapeType::unknown;
m_nDragHandle = 1;
m_fZoomFactor = 1.0f;
m_bSavingCode = false;
m_bSizingALine = false;
m_selectType = SelectType::intuitive;
m_elementGroup = _T("ElementGroup");
// Initiate the connection with the Property Window
ConnectToPropertyGrid();
}
CElementManager::CElementManager(const CElementManager& elementManager)
{
// Gabari Drawing objects
//m_objectsGabari = elementManager.m_objectsGabari;
// Drawing objects
//m_objects = elementManager.m_objects;
// Selection objects
//m_selection = elementManager.m_selection;
// Clipboard objects
//m_clipboard = elementManager.m_clipboard;
// Grouped Objects
m_groups = elementManager.m_groups;
m_elementGroup = elementManager.m_elementGroup;
m_paperColor = elementManager.m_paperColor;
// Page size in logical coordinates
m_size = elementManager.m_size;
m_lastPoint = elementManager.m_lastPoint;
// Current working object
m_objectId = elementManager.m_objectId;
// Current Select action
m_selectMode = elementManager.m_selectMode;
// Cursor hanlde
m_nDragHandle = elementManager.m_nDragHandle;
// Zoom float factor (default 1.0f)
m_fZoomFactor = elementManager.m_fZoomFactor;
// Attributes Current UI interaction members
// Is in drawing...
m_bDrawing = elementManager.m_bDrawing;
// Current selected drawing tool
m_type = elementManager.m_type;
// Current selected shape type from Ribbon
m_shapeType = elementManager.m_shapeType;
m_bSavingCode = elementManager.m_bSavingCode;
m_selectType = elementManager.m_selectType;
// Selection 1st point
m_selectPoint = elementManager.m_selectPoint;
// Selection Rect
m_selectionRect = elementManager.m_selectionRect;
m_clickPoint = elementManager.m_clickPoint;
m_bSelectionHasStarted = elementManager.m_bSelectionHasStarted;
pSelectionElement = elementManager.pSelectionElement;
m_bSizingALine = elementManager.m_bSizingALine;
}
void CElementManager::ConnectToPropertyGrid()
{
CWnd * p = AfxGetMainWnd();
CMainFrame * pmf = (CMainFrame *)p;
pmf->SetManager(this);
}
CElementManager::~CElementManager(void)
{
}
void CElementManager::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
//
// Set version of file format
//
ar.SetObjectSchema(11);
//CString elementGroup = W2T((LPTSTR)m_elementGroup.c_str());
//ar << elementGroup;
ar << m_size;
ar << m_paperColor;
ar << m_lastPoint;
}
else
{
int version = ar.GetObjectSchema();
if (version >= 9)
{
//CString elementGroup;
//ar >> elementGroup;
//this->m_elementGroup = T2W((LPTSTR)(LPCTSTR)elementGroup);
}
ar >> m_size;
ar >> m_paperColor;
ar >> m_lastPoint;
}
m_objects.Serialize(this, ar);
}
void CElementManager::FromJSON(const web::json::object& object)
{
int size_cx = object.at(U("Size_cx")).as_integer();
int size_cy = object.at(U("Size_cy")).as_integer();
m_size = CSize(size_cx, size_cy);
m_paperColor = (COLORREF) (object.at(U("PaperColor")).as_integer());
web::json::value p = object.at(U("Objects"));
for (auto iter = p.as_array().begin(); iter != p.as_array().end(); ++iter)
{
if (!iter->is_null())
{
shared_ptr<CElement> pElement = nullptr;
pElement = CElement::FromJSON(iter->as_object());
m_objects.m_objects.push_back(pElement);
}
}
}
web::json::value CElementManager::AsJSON() const
{
web::json::value res = web::json::value::object();
res[U("Size_cx")] = web::json::value::number(m_size.cx);
res[U("Size_cy")] = web::json::value::number(m_size.cy);
res[U("PaperColor")] = web::json::value::number((int)m_paperColor);
web::json::value Objects = web::json::value::array(m_objects.m_objects.size());
int idx = 0;
for (auto iter = m_objects.m_objects.begin(); iter != m_objects.m_objects.end(); iter++)
{
shared_ptr<CElement> pElement = *iter;
Objects[idx++] = pElement->AsJSON();
}
res[U("Objects")] = Objects;
return res;
}
void CElementManager::RemoveSelectedObjects(CModeler1View * pView)
{
m_objects.Remove(m_selection);
SelectNone();
// Update ClassView & FileView
UpdateClassView();//pNewElement);
UpdateFileView();//pNewElement);
Invalidate(pView);
}
void CElementManager::OnFont(CModeler1View * pView)
{
USES_CONVERSION;
CMFCRibbonBar* pRibbon = ((CMainFrame*) pView->GetTopLevelFrame())->GetRibbonBar();
CMFCRibbonFontComboBox* pFontCombo = DYNAMIC_DOWNCAST(CMFCRibbonFontComboBox, pRibbon->FindByID(ID_FONT_FONT));
if (pFontCombo == NULL)
{
return;
}
CString fontName = pFontCombo->GetEditText();
if (pFontCombo->FindItem(fontName) == -1)
{
// Restore current name:
pFontCombo->SelectItem(10);
CString strWarning;
strWarning.Format(_T("The font %s does not exits on your system"), fontName);
AfxMessageBox(strWarning, MB_OK | MB_ICONWARNING);
return;
}
const CMFCFontInfo* pDesc = pFontCombo->GetFontDesc();
std::shared_ptr<CElement> pElement = m_selection.GetHead();
pElement->m_fontName = T2W((LPTSTR)(LPCTSTR)fontName);
UpdatePropertyGrid(pView, pElement);
// Redraw the element
InvalObj(pView, pElement);
}
void CElementManager::OnFontSize(CModeler1View * pView)
{
CMFCRibbonBar* pRibbon = ((CMainFrame*) pView->GetTopLevelFrame())->GetRibbonBar();
CMFCRibbonComboBox* pFontCombo = DYNAMIC_DOWNCAST(CMFCRibbonComboBox, pRibbon->FindByID(ID_FONT_FONTSIZE));
if (pFontCombo == NULL)
{
return;
}
CString fontSize = pFontCombo->GetEditText();
int iFontSize = _ttoi(fontSize);
std::shared_ptr<CElement> pElement = m_selection.GetHead();
pElement->m_fontSize = iFontSize;
UpdatePropertyGrid(pView, pElement);
// Redraw the element
InvalObj(pView, pElement);
}
void CElementManager::OnEditCut(CModeler1View * pView)
{
// the clipboard is cleared
m_clipboard.RemoveAll();
// the current selection is cleared
RemoveSelectedObjects(pView);
}
void CElementManager::OnEditCopy(CModeler1View * pView)
{
m_clipboard.RemoveAll();
//m_selection.ChangeInnerAttributes();
m_clipboard.Clone(m_selection);
//m_clipboard.ChangeInnerAttributes();
}
void CElementManager::OnEditPaste(CModeler1View * pView)
{
m_objects.Clone(m_clipboard);
for( vector<std::shared_ptr<CElement>>::const_iterator itSel = m_clipboard.m_objects.begin() ; itSel!=m_clipboard.m_objects.end() ; itSel++ )
{
std::shared_ptr<CElement> pElement = *itSel;
Select(pElement);
}
m_selectMode = SelectMode::move;
//m_clipboard.RemoveAll();
Invalidate(pView);
}
void CElementManager::MoveToFront(CModeler1View * pView)
{
m_objects.MoveToFront(m_selection);
Invalidate(pView);
}
void CElementManager::MoveForward(CModeler1View * pView)
{
m_objects.MoveForward(m_selection);
Invalidate(pView);
}
void CElementManager::MoveBackward(CModeler1View * pView)
{
m_objects.MoveBackward(m_selection);
Invalidate(pView);
}
void CElementManager::MoveToBack(CModeler1View * pView)
{
m_objects.MoveToBack(m_selection);
Invalidate(pView);
}
bool CElementManager::HasSelection()
{
if( m_selection.GetCount() > 0 )
return true;
else
return false;
}
bool CElementManager::IsSelected(std::shared_ptr<CElement> pElement)
{
std::shared_ptr<CElement> ptr = m_selection.FindElement(pElement->m_objectId);
if (ptr != nullptr)
return true;
else
return false;
}
void CElementManager::SelectNone()
{
m_selection.RemoveAll();
}
bool CElementManager::Select(std::shared_ptr<CElement> pElement)
{
m_selection.AddTail(pElement);
return true;
}
bool CElementManager::Deselect(std::shared_ptr<CElement> pElement)
{
m_selection.Remove(pElement);
return true;
}
void CElementManager::ViewToManager(CModeler1View * pView, CPoint & point)
{
// CScrollView changes the viewport origin and mapping mode.
// It's necessary to convert the point from device coordinates
// to logical coordinates, such as are stored in the document.
//CClientDC dc(pView);
//pView->OnPrepareDC(&dc, NULL);
//dc.DPtoLP(&point);
CString str;
CPoint scrollPoint = pView->GetScrollPosition();
str.Format(_T("scroll point {%d,%d}"), scrollPoint.x, scrollPoint.y);
//pView->LogDebug(str);
point.operator+=(scrollPoint);
CClientDC dc(pView);
Graphics graphics(dc.m_hDC);
graphics.ScaleTransform(m_fZoomFactor, m_fZoomFactor);
Point points[1] = {Point(point.x, point.y)};
// Transform the points in the array from world to page coordinates.
graphics.TransformPoints(
CoordinateSpaceWorld,
CoordinateSpaceDevice,
points,
1);
point.x = points[0].X;
point.y = points[0].Y;
}
void CElementManager::ViewToManager(CModeler1View * pView, CRect & rect)
{
// CScrollView changes the viewport origin and mapping mode.
// It's necessary to convert the point from device coordinates
// to logical coordinates, such as are stored in the document.
//CClientDC dc(pView);
//pView->OnPrepareDC(&dc, NULL);
//dc.DPtoLP(&rect);
CClientDC dc(pView);
Graphics graphics(dc.m_hDC);
graphics.ScaleTransform(m_fZoomFactor, m_fZoomFactor);
CPoint point1 = rect.TopLeft();
CPoint point2 = rect.BottomRight();
Point points[2] = { Point((int) point1.x, (int) point1.y),
Point((int) point2.x, (int) point2.y) };
// Transform the points in the array from world to page coordinates.
graphics.TransformPoints(
CoordinateSpaceWorld,
CoordinateSpaceDevice,
points,
2);
point1.x = points[0].X;
point1.y = points[0].Y;
point2.x = points[1].X;
point2.y = points[1].Y;
rect.SetRect(point1, point2);
}
void CElementManager::ManagerToView(CModeler1View * pView, CPoint & point)
{
//CClientDC dc(pView);
//pView->OnPrepareDC(&dc, NULL);
//dc.LPtoDP(&point);
CClientDC dc(pView);
Graphics graphics(dc.m_hDC);
graphics.ScaleTransform(m_fZoomFactor, m_fZoomFactor);
Point points[1] = {Point(point.x, point.y)};
// Transform the points in the array from world to page coordinates.
graphics.TransformPoints(
CoordinateSpaceDevice,
CoordinateSpaceWorld,
points,
1);
point.x = points[0].X;
point.y = points[0].Y;
}
void CElementManager::ManagerToView(CModeler1View * pView, CRect & rect)
{
//CClientDC dc(pView);
//pView->OnPrepareDC(&dc, NULL);
//dc.LPtoDP(&rect);
CClientDC dc(pView);
Graphics graphics(dc.m_hDC);
graphics.ScaleTransform(m_fZoomFactor, m_fZoomFactor);
CPoint point1 = rect.TopLeft();
CPoint point2 = rect.BottomRight();
Point points[2] = { Point((int) point1.x, (int) point1.y),
Point((int) point2.x, (int) point2.y) };
// Transform the points in the array from world to page coordinates.
graphics.TransformPoints(
CoordinateSpaceDevice,
CoordinateSpaceWorld,
points,
2);
point1.x = points[0].X;
point1.y = points[0].Y;
point2.x = points[1].X;
point2.y = points[1].Y;
rect.SetRect(point1, point2);
}
void CElementManager::PrepareDC(CModeler1View * pView, CDC* pDC, CPrintInfo* pInfo)
{
return;
// mapping mode is MM_ANISOTROPIC
// these extents setup a mode similar to MM_LOENGLISH
// MM_LOENGLISH is in .01 physical inches
// these extents provide .01 logical inches
CSize size = GetSize();
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetViewportExt(size.cx, size.cy);
pDC->SetWindowExt(size.cx, size.cy);
// set the origin of the coordinate system to the center of the page
CPoint ptOrg;
ptOrg.x = 0; //GetDocument()->GetSize().cx / 2;
ptOrg.y = 0; //GetDocument()->GetSize().cy / 2;
// ptOrg is in logical coordinates
pDC->OffsetWindowOrg(0, 0); //-ptOrg.x,ptOrg.y);
}
void CElementManager::DrawBackground(CModeler1View * pView, CDC * pDC)
{
Graphics graphics(pDC->m_hDC);
CSize size = GetSize();
//SolidBrush brush(Color(255, 255, 255, 255));
Color colorLine(255, GetRValue(GetPaperColor()), GetGValue(GetPaperColor()), GetBValue(GetPaperColor()));
SolidBrush brush(colorLine);
Rect fillRect(0, 0 , size.cx, size.cy);
graphics.FillRectangle(&brush, fillRect);
}
void CElementManager::DrawConnector(Graphics& graphics, std::shared_ptr<CElement> pLineElement, ConnectorType connector)
{
shared_ptr<CElement> pElement1; // = pLineElement->m_pConnector->m_pElement1;
if (connector == ConnectorType::connector1)
{
pElement1 = pLineElement->m_pConnector->m_pElement1;
}
else
{
pElement1 = pLineElement->m_pConnector->m_pElement2;
}
CPoint point1;
if (pElement1 == nullptr)
{
point1 = pLineElement->m_rect.TopLeft();
}
else
{
//point1 = pElement1->m_rect.CenterPoint();
int handle;// = pLineElement->m_connectorDragHandle1;
if (connector == ConnectorType::connector1)
{
handle = pLineElement->m_connectorDragHandle1;
}
else
{
handle = pLineElement->m_connectorDragHandle2;
}
if (handle == 0)
{
point1 = pElement1->m_rect.TopLeft();
}
else
{
point1 = pElement1->GetHandle(handle);
}
CPoint point2;
point2.x = point1.x;
point2.y = point1.y;
CRect rect(point1, point2);
//rect.NormalizeRect();
Color color;
if (connector == ConnectorType::connector1)
{
color = Color::Yellow;
}
else
{
color = Color::Blue;
}
SolidBrush colorBrush(color); // Color::DarkOrange);
graphics.FillRectangle(&colorBrush, rect.left - 3, rect.top - 3, 7, 7);
Pen colorPen(Color::Black);
graphics.DrawRectangle(&colorPen, rect.left - 3, rect.top - 3, 7, 7);
std::wstring imagePath = L"Images\\Custom\\Connect2.png";
Image image(CStringW(imagePath.c_str()));
CPoint p1(rect.left, rect.top);
CPoint p2(p1.x + image.GetWidth(), p1.y + image.GetHeight());
graphics.DrawImage(&image, rect.left + 10, rect.top - 3, image.GetWidth(), image.GetHeight());
}
}
void CElementManager::Draw(CModeler1View * pView, CDC * pDC)
{
// Initialize GDI+ graphics context
Graphics graphics(pDC->m_hDC);
// just like that
//graphics.ScaleTransform(0.75f, 0.75f);
graphics.ScaleTransform(m_fZoomFactor, m_fZoomFactor);
// Iterate on Line elements
// if connector1 exists, its draghandle 1 is connector1.centeroint else nothing (its inner value)
// if connector2 exists, its draghandle 2 is connector2.centeroint else nothing (its inner value)
// Then the m_rect value is m_rect = CRrect(point1, point2);
if (m_bSizingALine == false)
{
for (vector<std::shared_ptr<CElement>>::const_iterator i = GetObjects().begin(); i != GetObjects().end(); i++)
{
std::shared_ptr<CElement> pElement = *i;
if (pElement->IsLine() == false)
{
continue;
}
//pElement->m_rect.NormalizeRect();
shared_ptr<CElement> pElement1 = pElement->m_pConnector->m_pElement1;
CPoint point1;
if (pElement1 == nullptr)
{
point1 = pElement->m_rect.TopLeft();
}
else
{
//point1 = pElement1->m_rect.CenterPoint();
int handle = pElement->m_connectorDragHandle1;
if (handle == 0)
{
point1 = pElement1->m_rect.TopLeft();
}
else
{
point1 = pElement1->GetHandle(handle);
}
}
shared_ptr<CElement> pElement2 = pElement->m_pConnector->m_pElement2;
CPoint point2;
if (pElement2 == nullptr)
{
point2 = pElement->m_rect.BottomRight();
}
else
{
//point2 = pElement2->m_rect.CenterPoint();
int handle = pElement->m_connectorDragHandle2;
if (handle == 0)
{
point2 = pElement2->m_rect.TopLeft();
}
else
{
point2 = pElement2->GetHandle(handle);
}
}
CRect rect(point1, point2);
pElement->m_rect = rect;
}
}
// TODO: add draw code for native data here
for( vector<std::shared_ptr<CElement>>::const_iterator i = GetObjects().begin() ; i!=GetObjects().end() ; i++ )
{
std::shared_ptr<CElement> pElement = *i;
// FIXME: Update the view for Property Window
pElement->m_pView = pView;
// Construct the graphic context for each element
CDrawingContext ctxt(pElement);
ctxt.m_pGraphics = &graphics;
//pElement->Draw(pView, pDC);
pElement->Draw(ctxt);
// HACK 14072012 : no more SimpleTextElement / Just other text elements except for caption old element
// caption property is deprecated. be carefull. DO NOT USE m_caption any more !!!
// informations:
// for m_type that are simple shapes ; it means it is not about text shapes,
// the m_text property can be optional and if it exists,
// it should be appended to the rendering area by creating a dedicated object.
// We call it CSimpleTextElement.
if( pElement->m_text.empty() == false &&
(pElement->m_type != ElementType::type_text)
)
{
//std::shared_ptr<CElement> pTextElement(new CSimpleTextElement());
//pTextElement->m_rect = pElement->m_rect;
//pTextElement->m_text = pElement->m_text;
//pTextElement->m_textAlign = pElement->m_textAlign;
//pTextElement->Draw(ctxt);
std::shared_ptr<CElement> pTextElement(new CTextElement());
//pTextElement->m_name = pElement->m_name;
//pTextElement->m_objectId = pElement->m_objectId;
pTextElement->m_caption = pElement->m_caption;
pTextElement->m_text = pElement->m_text;
pTextElement->m_code = pElement->m_code;
pTextElement->m_image = pElement->m_image;
pTextElement->m_lineWidth = pElement->m_lineWidth;
pTextElement->m_pManager = pElement->m_pManager;
pTextElement->m_pView = pElement->m_pView;
pTextElement->m_rect = pElement->m_rect;
pTextElement->m_bColorFill = pElement->m_bColorFill;
pTextElement->m_bColorLine = pElement->m_bColorLine;
pTextElement->m_bLineWidth = pElement->m_bLineWidth;
pTextElement->m_bSolidColorFill = pElement->m_bSolidColorFill;
pTextElement->m_colorFill = pElement->m_colorFill;
pTextElement->m_colorLine = pElement->m_colorLine;
pTextElement->m_textAlign = pElement->m_textAlign;
pTextElement->m_fontName = pElement->m_fontName;
pTextElement->m_bFixed = pElement->m_bFixed;
pTextElement->m_bBold = pElement->m_bBold;
pTextElement->m_bItalic = pElement->m_bItalic;
pTextElement->m_bUnderline = pElement->m_bUnderline;
pTextElement->m_bStrikeThrough = pElement->m_bStrikeThrough;
//pTextElement->m_code = pElement->m_code;
pTextElement->m_fontSize = pElement->m_fontSize;
pTextElement->m_colorText = pElement->m_colorText;
pTextElement->Draw(ctxt);
}
//if( !pDC->IsPrinting() && IsSelected(pObj) )
// DrawTracker(pObj, pDC, TrackerState::selected);
if (pView != NULL && pView->m_bActive && !pDC->IsPrinting() && IsSelected(pElement))
pElement->DrawTracker(ctxt, TrackerState::selected);
}
// Last....
// Add connector shape to the handles
for (vector<std::shared_ptr<CElement>>::const_iterator i = GetObjects().begin(); i != GetObjects().end(); i++)
{
std::shared_ptr<CElement> pElement = *i;
if (pElement->IsLine() == false)
{
continue;
}
DrawConnector(graphics, pElement, ConnectorType::connector1);
DrawConnector(graphics, pElement, ConnectorType::connector2);
}
}
void CElementManager::DrawEx(CModeler1View * pView, CDC * pDC)
{
CDC dc;
CDC* pDrawDC = pDC;
CBitmap bitmap;
CBitmap* pOldBitmap = nullptr;
// only paint the rect that needs repainting
CRect client;
CSize size = GetSize();
CRect fillRect(0, 0 , size.cx, size.cy);
// version n°1
// Previous : it was working since Ribbon UI...
//pDC->GetClipBox(client);
//ManagerToView(pView, rect);
// version n°2
// HACK?
//pView->GetClientRect(client);
// version n°3
client = fillRect;
CRect rect = client;
//rect.NormalizeRect();
//CString str;
//str.Format(_T("client=%d,%d,%d,%d"), client.left, client.top, client.right, client.bottom);
//pView->LogDebug(str);
if (!pDC->IsPrinting())
{
// draw to offscreen bitmap for fast looking repaints
if (dc.CreateCompatibleDC(pDC))
{
if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
{
pView->OnPrepareDC(&dc, NULL);
pDrawDC = &dc;
// offset origin more because bitmap is just piece of the whole drawing
dc.OffsetViewportOrg(rect.left, rect.top);
pOldBitmap = dc.SelectObject(&bitmap);
//dc.SetBrushOrg(rect.left % 8, rect.top % 8);
// might as well clip to the same rectangle
dc.IntersectClipRect(client);
}
}
}
#ifdef DRAW_PAPER_BACKGROUND
// paint background
CBrush brush;
if (!brush.CreateSolidBrush(GetPaperColor()))
return;
brush.UnrealizeObject();
//CSize size = GetSize();
//CRect fillRect(0, 0 , size.cx, size.cy);
pDrawDC->FillRect(fillRect, &brush);
//pDrawDC->FillRect(client, &brush);
//if (!pDC->IsPrinting() && m_bGrid)
// DrawGrid(pDrawDC);
#endif
// Background drawing routine call
DrawBackground(pView, pDrawDC);
// Main drawing routine call
Draw(pView, pDrawDC);
if (pDrawDC != pDC)
{
pDC->SetViewportOrg(0, 0);
pDC->SetWindowOrg(0,0);
pDC->SetMapMode(MM_TEXT);
dc.SetViewportOrg(0, 0);
dc.SetWindowOrg(0,0);
dc.SetMapMode(MM_TEXT);
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY);
dc.SelectObject(pOldBitmap);
}
// Caution, it flicks !
//pView->LogDebug(_T("CElementManager::DrawEx"));
}
void CElementManager::OnLButtonDown(CModeler1View* pView, UINT nFlags, const CPoint& cpoint)
{
// Caution, it flicks !
//pView->LogDebug(_T("CElementManager::OnLButtonDown"));
if( m_type == ElementType::type_unknown )
{
//FIXME : do we need to handle not implemented objects ?
return;
}
//m_bDrawing = true;
CPoint point = cpoint;
//m_clickPoint = point;
ViewToManager(pView, point);
m_clickPoint = point;
//ManagerToView(pView, m_clickPoint);
m_lastPoint = point;
m_selectPoint = point;
// Debugging
CString str;
str.Format(_T("m_clickPoint {%d,%d} / point {%d,%d} / cpoint {%d,%d}"), m_clickPoint.x, m_clickPoint.y, point.x, point.y, cpoint.x, cpoint.y);
pView->LogDebug(str);
if( m_type == ElementType::type_select )
{
m_selectMode = SelectMode::none;
// Check for resizing (only allowed on single selections)
if( HasSelection() && m_selection.GetCount() == 1)
{
std::shared_ptr<CElement> pElement = m_selection.GetHead();
// Change cursor look because mouse click is over an object for sizing
m_nDragHandle = pElement->HitTest(point, pView, TRUE);
if (m_nDragHandle != 0)
{
m_selectMode = SelectMode::size;
CString str;
str.Format(_T("m_nDragHandle=%d - selectMode == sized"), m_nDragHandle);
pView->LogDebug(str);
//pView->LogDebug(_T("selectMode == sized"));
}
}
if( m_selectMode == SelectMode::none )
{
// See if the click was on an object
std::shared_ptr<CElement> pElement = m_objects.ObjectAt(point, m_selectType);
if( pElement != NULL )
{
//if( HasSelection() )
//{
// pView->LogDebug("selection cleared");
// SelectNone();
//}
pView->LogDebug(_T("object found ->") + pElement->ToString());
if( IsSelected(pElement) == false )
{
if( (nFlags & MK_SHIFT) || (nFlags & MK_CONTROL))
{
}
else
SelectNone();
if (pElement->m_bGrouping == false)
{
pView->LogDebug(_T("object selected ->") + pElement->ToString());
m_objectId = pElement->m_objectId;
Select(pElement);
}
else
{
for (vector<std::shared_ptr<CElement>>::const_iterator itSel = pElement->m_pElementGroup->m_Groups.begin(); itSel != pElement->m_pElementGroup->m_Groups.end(); itSel++)
{
std::shared_ptr<CElement> pObj = *itSel;
Select(pObj);
}
}
pElement->m_bMoving = true;
}
m_selectMode = SelectMode::move;
pView->LogDebug(_T("selectMode == move"));
// Update UI
UpdateUI(pView, pElement);
// Redraw
Invalidate(pView, pElement);
}
else
{
// See if the click was on an object
// TRUE -> select and start move if so
// FALSE -> Click on background, start a net-selection
// m_selectMode = netSelect;
if( HasSelection() )
{
pView->LogDebug(_T("selection cleared"));
SelectNone();
Invalidate(pView, pElement);
}
//m_selectPoint = point;
m_selectMode = SelectMode::netselect;
pView->LogDebug(_T("selectMode == netselect"));
}
}
}
// We are not in a select operation
// -> this is a drawing operation
// We have to create...
// Create a Drawable Object...
else
{
#ifdef VERSION_COMMUNITY
if (CFactory::g_counter > MAX_SHAPES)
{
AfxMessageBox(_T("Maximum number or shapes reached !\nFor more, please buy the Architect Edition."));
return;
}
#endif
pView->LogDebug(_T("selection cleared"));
SelectNone();
std::shared_ptr<CElement> pNewElement = CFactory::CreateElementOfType(m_type, m_shapeType);
if( m_type == ElementType::type_unknown )
{
pView->LogDebug(_T("object not implemented yet ! ->") + pNewElement->ToString());
return;
}
if (m_shapeType == ShapeType::selection)
{
m_bSelectionHasStarted = true;
pSelectionElement = pNewElement;
}
pNewElement->m_point = point;
// For plumbing purpose...
pNewElement->m_pManager = this;
pNewElement->m_pView = pView;
// Add an object
m_objects.AddTail(pNewElement);
pView->LogDebug(_T("object created ->") + pNewElement->ToString());
// Store last created object
m_objectId = pNewElement->m_objectId;
// Select the new element
Select(pNewElement);
pView->LogDebug(_T("object selected ->") + pNewElement->ToString());
m_selectMode = SelectMode::size;
pView->LogDebug(_T("selectMode == size"));
m_nDragHandle = 1;
FindAConnectionFor(pNewElement, point, pView, ConnectorType::connector1);
pView->GetDocument()->SetModifiedFlag();
// Update ClassView & FileView
UpdateClassView();//pNewElement);
UpdateFileView();//pNewElement);
// Update UI
UpdateUI(pView, pNewElement);
}
}
void CElementManager::OnLButtonDblClk(CModeler1View* pView, UINT nFlags, const CPoint& cpoint)
{
// Caution, it flicks !
//pView->LogDebug(_T("CElementManager::OnLButtonDblClk"));
}
void CElementManager::DrawSelectionRect(CModeler1View *pView)
{
CClientDC dc(pView);
Graphics graphics(dc.m_hDC);
graphics.ScaleTransform(m_fZoomFactor, m_fZoomFactor);
Color colorBlack(255, 0, 0, 0);
Pen penBlack(colorBlack);
CRect rect = m_selectionRect;
rect.NormalizeRect();
Invalidate(pView);
graphics.DrawRectangle(&penBlack, rect.left, rect.top, rect.Width(), rect.Height());
}
void CElementManager::OnMouseMove(CModeler1View* pView, UINT nFlags, const CPoint& cpoint)
{
// Caution, it flicks !
//pView->LogDebug(_T("CElementManager::OnMouseMove"));
// a SELECT operation is started
if( m_selectMode == SelectMode::none )
{
}