-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewUniv.cpp
executable file
·2037 lines (1765 loc) · 59.3 KB
/
ViewUniv.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
//////////////////////////////////////////////////////////////////////
// Calques 3D - a 3D Dynamic Geometry Learning Environment
// Copyright (c) 1997-2007 Nicolas Van Labeke
//////////////////////////////////////////////////////////////////////
// This file is part of Calques 3D.
//
// Calques 3D is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Calques 3D is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Calques 3D; if not, write to The Free Software Foundation, Inc.,
// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//////////////////////////////////////////////////////////////////////
/// @file ViewUniv.cpp
/// Implementation of the CViewUniv class.
//
/// $Date: 2008-01-19 11:43:04+00 $
/// $Revision: 1.26 $
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MainFrm.h"
#include "Calques3D.h"
#include "Calques3DDoc.h"
#include "objects\Vector4.h"
#include "Prefs\Prefs.h"
#include "ViewUniv.h"
#include "ZoomDlg.h"
#include "POVUserDialog.h"
#include "MemDC.h"
#include "objects\Point3D.h"
#include "objects\Droite3D.h"
#include "objects\Sphere3D.h"
#include "objects\Plan3D.h"
#include "objects\Text3D.h"
#include "BCGPShapeMenuButton.h"
#include "objects\Macro3D.h"
#include "MacroInfoDlg.h"
#include "Tasks\Task.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CViewUniv
IMPLEMENT_DYNCREATE(CViewUniv, CView)
BEGIN_MESSAGE_MAP(CViewUniv, CView)
//{{AFX_MSG_MAP(CViewUniv)
ON_WM_WINDOWPOSCHANGING()
ON_WM_MOUSEWHEEL()
ON_WM_SIZE()
ON_WM_KEYDOWN()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDBLCLK()
ON_WM_RBUTTONDOWN()
ON_WM_SETCURSOR()
ON_WM_CREATE()
ON_WM_CONTEXTMENU()
ON_WM_MDIACTIVATE()
ON_WM_SETFOCUS()
ON_WM_TIMER()
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
ON_COMMAND(ID_MACROS_SAVE, OnMacrosSave)
ON_COMMAND(ID_MACROS_INFO, OnMacrosInfo)
ON_UPDATE_COMMAND_UI(ID_MACROS_INFO, OnUpdateMacrosInfo)
ON_COMMAND(ID_VISUALISATION_SHOWMARKS, OnToggleMarks)
ON_COMMAND(ID_VISUALISATION_POINTSOFVIEW, OnChangePointsOfView)
ON_UPDATE_COMMAND_UI(ID_VISUALISATION_SHOWMARKS, OnUpdateToggleMarks)
ON_UPDATE_COMMAND_UI(ID_VISUALISATION_POINTSOFVIEW,OnUpdateReferential)
//}}AFX_MSG_MAP
// Messages added manually because the Class Wizard is crap!
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
ON_UPDATE_COMMAND_UI_RANGE(ID_FORMAT_OBJCOLOR, ID_FORMAT_UNDERLINE, OnUpdateFormat)
ON_COMMAND_RANGE(ID_FORMAT_OBJCOLOR, ID_FORMAT_UNDERLINE, OnFormat)
ON_CBN_SELENDOK(ID_FORMAT_TXTFONT, OnFormat)
ON_CBN_SELENDOK(ID_FORMAT_TXTSIZE, OnFormat)
ON_COMMAND(ID_VISUALISATION_SHOWHIDDEN, OnShowHidden)
ON_UPDATE_COMMAND_UI(ID_VISUALISATION_SHOWHIDDEN, OnUpdateShowHidden)
ON_COMMAND_RANGE(ID_VISUALISATION_ZOOM,ID_VISUALISATION_ZOOM_ADJUST, OnChangeZoom)
ON_COMMAND_RANGE(ID_VISUALISATION_ZOOM_150,ID_VISUALISATION_ZOOM_150, OnChangeZoom)
ON_UPDATE_COMMAND_UI_RANGE(ID_VISUALISATION_ZOOM, ID_VISUALISATION_ZOOM_ADJUST, OnUpdateZoom)
ON_UPDATE_COMMAND_UI_RANGE(ID_VISUALISATION_ZOOM_150, ID_VISUALISATION_ZOOM_150, OnUpdateZoom)
ON_UPDATE_COMMAND_UI_RANGE(ID_VISUALISATION_POV_HSLIDER, ID_VISUALISATION_POV_VSLIDER, OnUpdateSliders)
ON_COMMAND_RANGE(ID_VISUALISATION_PERSPECTIVE_CAVALIERE,ID_VISUALISATION_PERSPECTIVE_OBLIQUE,OnChangePerspective)
ON_UPDATE_COMMAND_UI_RANGE(ID_VISUALISATION_PERSPECTIVE_CAVALIERE,ID_VISUALISATION_PERSPECTIVE_OBLIQUE,OnUpdatePerspective)
ON_COMMAND_RANGE(ID_VISUALISATION_REFERENTIAL,ID_VISUALISATION_REFERENTIAL_WALLS,OnChangeReferential)
ON_UPDATE_COMMAND_UI_RANGE(ID_VISUALISATION_REFERENTIAL,ID_VISUALISATION_REFERENTIAL_WALLS,OnUpdateReferential)
ON_COMMAND_RANGE(ID_VISUALISATION_POV_DEFINE,ID_VISUALISATION_POV_POV4,OnChangePOV)
ON_UPDATE_COMMAND_UI_RANGE(ID_VISUALISATION_POV_DEFINE,ID_VISUALISATION_POV_POV4,OnUpdatePOV)
ON_COMMAND_RANGE(ID_VISUALISATION_DEFAULTTASK,ID_VISUALISATION_APPLYSTYLE, OnStartTask)
ON_COMMAND_RANGE(ID_VISUALISATION_PROJECTION_FRONT,ID_VISUALISATION_PROJECTION_KEEPIT, OnStartTask)
ON_COMMAND_RANGE(ID_VISUALISATION_STYLE_COPY,ID_VISUALISATION_STYLE_MARK, OnStartTask)
ON_COMMAND_RANGE(ID_OBJECT_POINT,ID_OBJECT_CONE, OnStartTask)
ON_COMMAND_RANGE(ID_CONSTRUCTION_POINTON,ID_CONSTRUCTION_DIVSEGMENT, OnStartTask)
//ON_COMMAND_RANGE(ID_CONSTRUCTION_INTERSECTION_LINECIRCLE,ID_CONSTRUCTION_INTERSECTION_LINECONE, OnStartTask)
ON_COMMAND_RANGE(ID_EXPLORATION_MOVE,ID_EXPLORATION_DISCOVERY, OnStartTask)
ON_COMMAND_RANGE(ID_EXPLORATION_EXTRACTION_CALQUE1,ID_EXPLORATION_EXTRACTION_ADDIN, OnStartTask)
ON_COMMAND_RANGE(ID_EXPLORATION_MOVE_MAGNETISM,ID_EXPLORATION_MOVE_TRACE, OnStartTask)
ON_COMMAND_RANGE(ID_EXPLORATION_VERIFY_PAR,ID_EXPLORATION_VERIFY_PTALIGN, OnStartTask)
ON_COMMAND_RANGE(ID_EXPLORATION_MEASURE_DISTANCE,ID_EXPLORATION_MEASURE_LENGTH, OnStartTask)
ON_UPDATE_COMMAND_UI_RANGE(ID_VISUALISATION_DEFAULTTASK,ID_VISUALISATION_APPLYSTYLE, OnUpdateTasks)
ON_UPDATE_COMMAND_UI_RANGE(ID_VISUALISATION_PROJECTION_FRONT,ID_VISUALISATION_PROJECTION_KEEPIT, OnUpdateTasks)
ON_UPDATE_COMMAND_UI_RANGE(ID_VISUALISATION_STYLE_COPY,ID_VISUALISATION_STYLE_MARK, OnUpdateTasks)
ON_UPDATE_COMMAND_UI_RANGE(ID_OBJECT_POINT,ID_OBJECT_CONE, OnUpdateTasks)
ON_UPDATE_COMMAND_UI_RANGE(ID_CONSTRUCTION_POINTON,ID_CONSTRUCTION_DIVSEGMENT, OnUpdateTasks)
//ON_UPDATE_COMMAND_UI_RANGE(ID_CONSTRUCTION_INTERSECTION_LINECIRCLE,ID_CONSTRUCTION_INTERSECTION_LINECONE, OnUpdateTasks)
ON_UPDATE_COMMAND_UI_RANGE(ID_EXPLORATION_MOVE,ID_EXPLORATION_DISCOVERY, OnUpdateTasks)
ON_UPDATE_COMMAND_UI_RANGE(ID_EXPLORATION_EXTRACTION_CALQUE1,ID_EXPLORATION_EXTRACTION_ADDIN, OnUpdateTasks)
ON_UPDATE_COMMAND_UI_RANGE(ID_EXPLORATION_MOVE_MAGNETISM,ID_EXPLORATION_MOVE_TRACE, OnUpdateTasks)
ON_UPDATE_COMMAND_UI_RANGE(ID_EXPLORATION_VERIFY_PAR,ID_EXPLORATION_VERIFY_PTALIGN, OnUpdateTasks)
ON_UPDATE_COMMAND_UI_RANGE(ID_EXPLORATION_MEASURE_DISTANCE,ID_EXPLORATION_MEASURE_LENGTH, OnUpdateTasks)
ON_COMMAND_RANGE(ID_MACROS_LOAD,ID_MACROS_LOAD, OnStartTask)
ON_UPDATE_COMMAND_UI_RANGE(ID_MACROS_SAVE, ID_MACROS_LOAD, OnUpdateTasks)
ON_COMMAND_RANGE(ID_MACROS_USER1, ID_MACROS_USER15, OnStartTask)
ON_UPDATE_COMMAND_UI_RANGE(ID_MACROS_USER1, ID_MACROS_USER15, OnUpdateTasks)
//ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipText)
ON_MESSAGE(WM_SHOWOBJ_TOOLTIPS, OnUpdateObjTooltip)
ON_REGISTERED_MESSAGE(BCGM_RESETTOOLBAR, OnToolbarReset)
ON_MESSAGE(WM_UPDATEZOOM_MANUAL, OnChangeZoom)
ON_COMMAND(ID_VISUALISATION_POV_HSLIDER, OnRotateHor)
ON_COMMAND(ID_VISUALISATION_POV_VSLIDER, OnRotateVer)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CViewUniv::CViewUniv()
{
m_pVisParam = NULL;
m_pCurrentTask = NULL;
}
CViewUniv::~CViewUniv()
{
if (m_pCurrentTask) delete m_pCurrentTask;
if (m_pVisParam) delete m_pVisParam;
m_pVisParam = NULL;
m_pCurrentTask = NULL;
}
/////////////////////////////////////////////////////////////////////////////
// CViewUniv drawing
/////////////////////////////////////////////////////////////////////////////
BOOL CViewUniv::OnEraseBkgnd(CDC* pDC)
{
//return CView::OnEraseBkgnd(pDC);
return FALSE;
}
//////////////////////////////////////////////////////////////////////
/// Method CViewUniv::OnDraw
///
/// Note that the order of drawing the various component of the universe is important, as there is no
/// implementation of a facet-ordering algorithm. Scene rendering is done in a ad-hoc fashion by:
/// - first drawing the System of Reference
/// - second calculating the positions and drawing the polygons (if any)
/// - third drawing the remaining objects
/// - and finally drawing any visual feedbacks coming from the current task
//////////////////////////////////////////////////////////////////////
void CViewUniv::OnDraw(CDC* rDC)
{
CDocument* pDoc = GetDocument();
CMemDC memDC(rDC);
CDC* pDC = &memDC;
//CDC* pDC = rDC;
CRect ClipRect;
CBrush br(::GetSysColor(COLOR_WINDOW));
pDC->GetClipBox(ClipRect);
pDC->FillRect(ClipRect,&br);
int oldM = pDC->SetBkMode(TRANSPARENT);
if (GetVisualParam())
{
// Draw System of Reference
//GetVisualParam()->Draw(pDC);
// Calculate Visual Representation of objects
int nb = GetDocument()->m_cObjectSet.GetSize();
for (int i=0;i<nb;i++)
{
CObject3D* pObj = GetDocument()->m_cObjectSet.GetAt(i);
if (!pObj) continue;
pObj->CalculVisuel(GetVisualParam());
}
// Treats polygons only if adequate referential
int nRep = GetVisualParam()->nVisuKind;
BOOL postTreat = /*TPref::TUniv.bShowPolygon || */(nRep==CVisualParam::VisuNone || nRep==CVisualParam::VisuRep);
if (TPref::TUniv.bShowPolygon)
GetVisualParam()->Draw(pDC);
if (TPref::TUniv.bShowPolygon || (!TPref::TUniv.bShowPolygon && postTreat))
{
// Calculate Position of the Polygons
int nbPol = GetDocument()->m_cPolygonSet.GetSize();
CxObject3DSet mset;
for (int i=0;i<nbPol;i++)
{
CObject3D* pObj = GetDocument()->m_cPolygonSet.GetAt(i);
if (!pObj) continue;
CPolygon3D *pPol = DYNAMIC_DOWNCAST(CPolygon3D,pObj);
if (!pPol) continue;
BOOL bFound=FALSE;
for (int k=0;k<mset.GetSize();k++)
{
CObject3D* pObj2 = mset.GetAt(k);
CPolygon3D *pPol2 = DYNAMIC_DOWNCAST(CPolygon3D,pObj2);
if (pPol->m_nZFact < pPol2->m_nZFact)
{
mset.InsertAt(k,pObj);
bFound=TRUE;
break;
}
}
if (!bFound) mset.Add(pObj);
}
// Draw the Polygons
for (int i=0;i<mset.GetSize();i++)
{
CObject3D* pObj = mset.GetAt(i);
if (!pObj) continue;
pObj->Draw(pDC,GetVisualParam(),FALSE);
}
}
// Draw System of Reference
if (!TPref::TUniv.bShowPolygon)
GetVisualParam()->Draw(pDC);
// Draw the Objects
for (int i=0;i<nb;i++)
{
CObject3D* pObj = GetDocument()->m_cObjectSet.GetAt(i);
if (!pObj) continue;
//if (DYNAMIC_DOWNCAST(CEquation3D,pObj)) continue;
if (DYNAMIC_DOWNCAST(CPolygon3D,pObj))
{
if (!TPref::TUniv.bShowPolygon && !postTreat)
pObj->Draw(pDC,GetVisualParam(),TRUE);
}
else
pObj->Draw(pDC,GetVisualParam());
}
}
// Draw the task feedback
if (IsWindowActivated() && m_pCurrentTask)
{
m_pCurrentTask->DrawFeedBack(pDC);
}
pDC->SetBkMode(oldM);
}
/////////////////////////////////////////////////////////////////////////////
// CViewUniv diagnostics
#ifdef _DEBUG
void CViewUniv::AssertValid() const
{
CView::AssertValid();
}
void CViewUniv::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCalques3DDoc* CViewUniv::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCalques3DDoc)));
return (CCalques3DDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// Getters/Setters for local variables
CObject3D* CViewUniv::GetSelectedObject()
{
return pSelectObj;
}
CVisualParam* CViewUniv::GetVisualParam()
{
return m_pVisParam;
}
void CViewUniv::SetVisualParam(int VP)
{
if (!GetVisualParam()) return;
CVisualParam *pNewParam = NULL;
switch (VP){
case CVisualParam::VisuNone :
pNewParam = new CVisuNone(*GetVisualParam());
break;
case CVisualParam::VisuRep :
pNewParam = new CVisuRep(*GetVisualParam());
break;
case CVisualParam::VisuPlane :
pNewParam = new CVisuPlane(*GetVisualParam());
break;
case CVisualParam::VisuClois :
default:
pNewParam = new CVisuCloison(*GetVisualParam());
break;
}
if (pNewParam)
{
delete m_pVisParam;
m_pVisParam = pNewParam;
if (GetSafeHwnd())
{
Invalidate();
UpdateWindow();
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CViewUniv message handlers
void CViewUniv::OnInitialUpdate()
{
CView::OnInitialUpdate();
m_wndToolTip.Create(this);
m_pVisParam = new CVisuCloison();
SetVisualParam(TPref::TUniv.nDefRep);
m_pCurrentTask = new CDefTask(this,ID_VISUALISATION_DEFAULTTASK);
pSelectObj = NULL;
if (GetVisualParam())
{
//GetVisualParam()->SetProjParam();
OnChangePointsOfView();
CRect mrect;
GetClientRect(&mrect);
GetVisualParam()->ptRepCoord = mrect.CenterPoint();
//GetVisualParam()->ptRepCoord = CPoint(150,150);
m_wndToolTip.AddTool(this);
m_wndToolTip.SetDelayTime(TTDT_INITIAL,100);
m_wndToolTip.SetDelayTime(TTDT_RESHOW,100);
m_wndToolTip.Activate(FALSE);
int r = (int)(GetVisualParam()->ProjParam.phi - 180 -TPref::TUniv.sDefParam.phi);
r = (r < 0) ? r + 360 : ((r > 360) ? r-360 : r);
r /= 5;
//**** wndVSliderBar.SetSliderPos(r);
SetSliderPosition(ID_VISUALISATION_POV_VSLIDER,r);
r = (int)(180 - GetVisualParam()->ProjParam.theta + TPref::TUniv.sDefParam.theta);
r = (r < 0) ? r+ 360 : ((r > 360) ? r-360 : r);
r /= 5;
//**** wndHSliderBar.SetSliderPos(r);
SetSliderPosition(ID_VISUALISATION_POV_HSLIDER,r);
}
}
void CViewUniv::OnSize(UINT nType, int cx, int cy)
{
CRect mrect;
GetClientRect(&mrect);
CView::OnSize(nType, cx, cy);
CBCGPMDIChildWnd *pChild = DYNAMIC_DOWNCAST(CBCGPMDIChildWnd, GetParent());
pChild->RecalcLayout();
// TODO: Add your message handler code here
if (GetVisualParam())
{
//CRect mrect;
GetClientRect(&mrect);
GetVisualParam()->ptRepCoord = mrect.CenterPoint();
GetVisualParam()->nWndWidth = cx;
GetVisualParam()->nWndHeight = cy;
Invalidate();
UpdateWindow();
}
}
int CViewUniv::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{
return CView::OnToolHitTest(point, pTI);
}
BOOL CViewUniv::OnToolTipText(UINT nID, NMHDR* pNMHDR, LRESULT* pResult)
{
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
UINT nID2 =pNMHDR->idFrom;
return FALSE;
}
BOOL CViewUniv::PreTranslateMessage(MSG* pMsg)
{
if (IsWindowActivated())
if(pMsg->message== WM_LBUTTONDOWN ||
pMsg->message== WM_LBUTTONUP ||
pMsg->message== WM_MOUSEMOVE)
m_wndToolTip.RelayEvent(pMsg);
return CView::PreTranslateMessage(pMsg);
}
void CViewUniv::SetFixedProjection(BOOL bFixed)
{
if (GetVisualParam()) GetVisualParam()->bFixed = bFixed;
if (GetVisualParam()) GetVisualParam()->bKeepProj = bFixed;
//**** wndHSliderBar.m_wndSlider.EnableWindow(!bFixed);
//**** wndHSliderBar.m_wndSlider.ShowWindow(!bFixed);
//**** wndHSliderBar.m_wndSlider.Invalidate();
//**** wndHSliderBar.m_wndSlider.UpdateWindow();
//**** wndVSliderBar.m_wndSlider.EnableWindow(!bFixed);
//**** wndVSliderBar.m_wndSlider.ShowWindow(!bFixed);
//**** wndVSliderBar.m_wndSlider.Invalidate();
//**** wndVSliderBar.m_wndSlider.UpdateWindow();
}
void CViewUniv::OnUpdateSliders(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!GetVisualParam()->bFixed);
}
void CViewUniv::OnChangeReferential(UINT nID)
{
// TODO: Add your command handler code here
//SProjection myProj = GetVisualParam()->GetProjParam();
BOOL bFix = (m_pCurrentTask && m_pCurrentTask->m_bIsRepereFixed);
if (bFix) return;
switch (nID){
case ID_VISUALISATION_REFERENTIAL:
// Decide what to do when the icon of the menu button is clicked.
break;
case ID_VISUALISATION_REFERENTIAL_AXES:
SetVisualParam(CVisualParam::VisuRep);
break;
case ID_VISUALISATION_REFERENTIAL_FLOOR:
SetVisualParam(CVisualParam::VisuPlane);
break;
case ID_VISUALISATION_REFERENTIAL_WALLS:
SetVisualParam(CVisualParam::VisuClois);
break;
case ID_VISUALISATION_REFERENTIAL_NONE:
default:
SetVisualParam(CVisualParam::VisuNone);
break;
}
}
void CViewUniv::OnUpdateReferential(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
BOOL bCheck = FALSE;
BOOL bFix = (GetVisualParam() && (GetVisualParam()->bFixed || GetVisualParam()->bKeepProj));
BOOL bFix2 = (m_pCurrentTask && m_pCurrentTask->m_bIsRepereFixed);
int nRep = pCmdUI->m_nID -ID_VISUALISATION_REFERENTIAL_NONE;
switch (pCmdUI->m_nID){
case ID_VISUALISATION_REFERENTIAL_AXES:
case ID_VISUALISATION_REFERENTIAL_FLOOR:
case ID_VISUALISATION_REFERENTIAL_WALLS:
case ID_VISUALISATION_REFERENTIAL_NONE:
if (GetVisualParam())
bCheck = (GetVisualParam()->nVisuKind == nRep);
pCmdUI->Enable(!bFix2);
pCmdUI->SetCheck(bCheck);
break;
case ID_VISUALISATION_POINTSOFVIEW:
case ID_VISUALISATION_REFERENTIAL:
pCmdUI->Enable(!bFix);
break;
default:
break;
}
}
void CViewUniv::OnUpdateZoom(CCmdUI* pCmdUI)
{
BOOL bCheck = FALSE;
switch (pCmdUI->m_nID)
{
case ID_VISUALISATION_ZOOM_150:
bCheck = (GetVisualParam()->nZoom == 1.50);
break;
case ID_VISUALISATION_ZOOM_100:
bCheck = (GetVisualParam()->nZoom == 1.);
break;
case ID_VISUALISATION_ZOOM_75:
bCheck = (GetVisualParam()->nZoom == .75);
break;
case ID_VISUALISATION_ZOOM_50:
bCheck = (GetVisualParam()->nZoom == .50);
break;
case ID_VISUALISATION_ZOOM_25:
bCheck = (GetVisualParam()->nZoom == .25);
break;
case ID_VISUALISATION_ZOOM_ADJUST:
break;
default:
return;
}
pCmdUI->SetCheck(bCheck);
pCmdUI->Enable(TRUE);
}
LRESULT CViewUniv::OnChangeZoom(WPARAM rr,LPARAM)
{
GetVisualParam()->nZoom = rr / 100.;
Invalidate();
UpdateWindow();
return 0L;
}
void CViewUniv::OnChangeZoom(UINT nID)
{
if (!GetVisualParam()) return;
BOOL bRedraw = FALSE;
switch (nID)
{
case ID_VISUALISATION_ZOOM_150:
if (GetVisualParam()->nZoom != 1.50)
{
GetVisualParam()->nZoom = 1.50;
bRedraw = TRUE;
}
break;
case ID_VISUALISATION_ZOOM_100:
if (GetVisualParam()->nZoom != 1.)
{
GetVisualParam()->nZoom = 1.0;
bRedraw = TRUE;
}
break;
case ID_VISUALISATION_ZOOM_75:
if (GetVisualParam()->nZoom != 0.75)
{
GetVisualParam()->nZoom = 0.75;
bRedraw = TRUE;
}
break;
case ID_VISUALISATION_ZOOM_50:
if (GetVisualParam()->nZoom != .5)
{
GetVisualParam()->nZoom = .5;
bRedraw = TRUE;
}
break;
case ID_VISUALISATION_ZOOM_25:
if (GetVisualParam()->nZoom != .25)
{
GetVisualParam()->nZoom = .25;
bRedraw = TRUE;
}
break;
case ID_VISUALISATION_ZOOM_ADJUST:
{
CZoomDlg dlg(this);
dlg.m_nZoom = (int)((GetVisualParam()->nZoom * 100 - 25)/5);
if (dlg.DoModal())
{
GetVisualParam()->nZoom = (25+5*dlg.m_nZoom)/100.;
bRedraw = TRUE;
}
}
return;
default:
break;
}
if (bRedraw)
{
Invalidate();
UpdateWindow();
}
}
void CViewUniv::OnChangePOV(UINT nID)
{
if (nID==ID_VISUALISATION_POV_DEFINE)
{
CPOVUserDialog mdlg(this);
mdlg.SetPOVList(&(GetDocument()->m_cPOVlist));
mdlg.SetProjParam(this->GetVisualParam()->GetProjParam());
mdlg.DoModal();
}
else
{
int npos = 0;
CCalques3DDoc *pDoc = GetDocument();
for (POSITION pos = pDoc->m_cPOVlist.GetHeadPosition (); pos != NULL;)
{
CPOVUserTool *pObj = pDoc->m_cPOVlist.GetNext (pos);
if (pObj && (npos+ID_VISUALISATION_POV_DEFAULT)==nID)
{
// TODO: Add your command handler code here
GetVisualParam()->SetProjParam(pObj->m_projParam);
int r = (int)(GetVisualParam()->ProjParam.phi - 180 -TPref::TUniv.sDefParam.phi);
r = (r < 0) ? r + 360 : ((r > 360) ? r-360 : r);
r /= 5;
//**** wndVSliderBar.SetSliderPos(r);
SetSliderPosition(ID_VISUALISATION_POV_VSLIDER,r);
r = (int)(180 - GetVisualParam()->ProjParam.theta + TPref::TUniv.sDefParam.theta);
r = (r < 0) ? r+ 360 : ((r > 360) ? r-360 : r);
r /= 5;
//**** wndHSliderBar.SetSliderPos(r);
SetSliderPosition(ID_VISUALISATION_POV_HSLIDER,r);
Invalidate();
UpdateWindow();
break;
}
npos++;
}
}
}
void CViewUniv::OnUpdatePOV(CCmdUI* pCmdUI)
{
BOOL bFix = (GetVisualParam() && (GetVisualParam()->bFixed || GetVisualParam()->bKeepProj));
pCmdUI->Enable(!bFix);
}
void CViewUniv::OnShowHidden()
{
TPref::TUniv.bShowHidden = !TPref::TUniv.bShowHidden;
GetDocument()->UpdateAllViews(NULL,WM_UPDATEOBJ_ALL,NULL);
//Invalidate();
//UpdateWindow();
}
void CViewUniv::OnUpdateShowHidden(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(TPref::TUniv.bShowHidden);
}
void CViewUniv::OnChangePerspective(UINT nID)
{
// TODO: Add your command handler code here
if (!GetVisualParam()) return;
int nRep = nID - ID_VISUALISATION_PERSPECTIVE_CAVALIERE;
GetVisualParam()->bParProj = !nRep;
Invalidate();
UpdateWindow();
}
void CViewUniv::OnUpdatePerspective(CCmdUI* pCmdUI)
{
BOOL bCheck = FALSE;
int nRep = pCmdUI->m_nID - ID_VISUALISATION_PERSPECTIVE_CAVALIERE;
switch (pCmdUI->m_nID){
case ID_VISUALISATION_PERSPECTIVE_CAVALIERE:
case ID_VISUALISATION_PERSPECTIVE_OBLIQUE:
if (GetVisualParam())
bCheck = (GetVisualParam()->bParProj != nRep);
pCmdUI->Enable(TRUE);
pCmdUI->SetCheck(bCheck);
default:
break;
}
}
/////////////////////////////////////////////////////////////////////////////
// CViewUniv Command Handlers
void CViewUniv::OnStartTask(UINT nID)
{
// TODO: Add your command handler code here
if (m_pCurrentTask->OnDoTasksOption(nID))
return;
if (m_pCurrentTask->m_nTaskID == nID)
{
//MessageBox("dfdfsfdsfdsa");
return;
}
CTask *pNewTask = NULL;
switch (nID) {
case ID_VISUALISATION_DEFAULTTASK:
pNewTask = new CDefTask(this,nID);
break;
case ID_VISUALISATION_PROJECTION:
pNewTask = new CProjectionTask(this,nID);
break;
case ID_EXPLORATION_MOVE:
pNewTask = new CMoveObjectTask(this,nID);
break;
case ID_EXPLORATION_VERIFY:
pNewTask = new CVerify3DTask(this,nID);
break;
case ID_OBJECT_POINT:
pNewTask = new CPoint3DTask(this,nID);
break;
case ID_OBJECT_LINE:
pNewTask = new CDroite3DTask(this,nID);
break;
case ID_OBJECT_DELETE:
pNewTask = new CDeleteObjectTask(this,nID);
break;
case ID_OBJECT_REDEFINE:
pNewTask = new CRedefine3DTask(this,nID);
break;
case ID_OBJECT_SEGMENT:
case ID_OBJECT_RAY:
pNewTask = new CSegment3DTask(this,nID);
break;
case ID_OBJECT_CIRCLE:
case ID_OBJECT_ARCCIRCLE:
pNewTask = new CCercle3DTask(this,nID);
break;
case ID_OBJECT_PLANE:
pNewTask = new CPlan3DTask(this,nID);
break;
case ID_OBJECT_POLYGON:
pNewTask = new CPolygonTask(this,nID);
break;
case ID_OBJECT_CUBE:
pNewTask = new CCube3DTask(this,nID);
break;
case ID_OBJECT_SPHERE:
pNewTask = new CSphere3DTask(this,nID);
break;
case ID_VISUALISATION_CENTERON:
pNewTask = new CCenterOn3DTask(this,nID);
break;
case ID_OBJECT_CYLINDRE:
pNewTask = new CCylindreTask(this,nID);
break;
case ID_OBJECT_CONE:
pNewTask = new CConeTask(this,nID);
break;
case ID_CONSTRUCTION_POINTON_CYLINDER:
case ID_CONSTRUCTION_POINTON_CONE:
case ID_CONSTRUCTION_POINTON_LINE:
case ID_CONSTRUCTION_POINTON_CIRCLE:
case ID_CONSTRUCTION_POINTON_PLANE:
case ID_CONSTRUCTION_POINTON_SPHERE:
pNewTask = new CPointSur3DTask(this,nID);
break;
case ID_CONSTRUCTION_INTERSECTION_LINELINE:
case ID_CONSTRUCTION_INTERSECTION_LINEPLANE:
case ID_CONSTRUCTION_INTERSECTION_LINESPHERE:
case ID_CONSTRUCTION_INTERSECTION_PLANEPLANE:
case ID_CONSTRUCTION_INTERSECTION_PLANECYLINDER:
case ID_CONSTRUCTION_INTERSECTION_SPHERESPHERE:
case ID_CONSTRUCTION_INTERSECTION_LINECIRCLE:
case ID_CONSTRUCTION_INTERSECTION_PLANECIRCLE:
case ID_CONSTRUCTION_INTERSECTION_SPHEREPLANE:
case ID_CONSTRUCTION_INTERSECTION_LINECONE:
case ID_CONSTRUCTION_INTERSECTION_PLANECONE:
case ID_CONSTRUCTION_CROSSPRODUCT:
pNewTask = new CInter3DTask(this,nID);
break;
case ID_CONSTRUCTION_MIDPOINT:
case ID_CONSTRUCTION_DIVSEGMENT:
pNewTask = new CMilieu3DTask(this,nID);
break;
case ID_CONSTRUCTION_CENTER:
pNewTask = new CCenterTask(this,nID);
break;
case ID_CONSTRUCTION_PARALLELLINE:
pNewTask = new CParallele3DTask(this,nID);
break;
case ID_CONSTRUCTION_NORMALLINE:
case ID_CONSTRUCTION_PERPENDICULARPLANE:
case ID_CONSTRUCTION_PERPENDICULARLINE:
pNewTask = new CPerpendic3DTask(this,nID);
break;
case ID_EXPLORATION_EXTRACTION:
pNewTask = new CExtractCalcTask(this,nID);
break;
case ID_CONSTRUCTION_SYMMETRICALPOINT:
pNewTask = new CSymetricTask(this,nID);
break;
case ID_EXPLORATION_ANIMATION:
pNewTask = new CAnimation3DTask(this,nID);
break;
case ID_CONSTRUCTION_TRANSLATION:
pNewTask = new CTranslatTask(this,nID);
break;
case ID_EXPLORATION_LABEL:
case ID_EXPLORATION_EQUATION:
pNewTask = new CLabelTask(this,nID);
break;
case ID_EXPLORATION_MEASURE:
pNewTask = new CMeasureTask(this,nID);
break;
case ID_VISUALISATION_APPLYSTYLE:
pNewTask = new CCopyShapeTask(this,nID);
break;
case ID_EXPLORATION_LOCUS:
pNewTask = new CLocus3DTask(this,nID);
break;
case ID_MACROS_USER1:
case ID_MACROS_USER2:
case ID_MACROS_USER3:
case ID_MACROS_USER4:
case ID_MACROS_USER5:
case ID_MACROS_USER6:
case ID_MACROS_USER7:
case ID_MACROS_USER8:
case ID_MACROS_USER9:
case ID_MACROS_USER10:
case ID_MACROS_USER11:
case ID_MACROS_USER12:
case ID_MACROS_USER13:
case ID_MACROS_USER14:
case ID_MACROS_USER15:
case ID_MACROS_LOAD:
pNewTask = new CGreffe3DTask(this,nID);
break;
default:
break;
}
if (pNewTask)
{
delete m_pCurrentTask;
m_pCurrentTask = pNewTask;
}
}
void CViewUniv::OnUpdateTasks(CCmdUI* pCmdUI)
{
if (m_pCurrentTask->OnUpdateTasksOption(pCmdUI)) return;
BOOL bCheck = ((m_pCurrentTask) && (m_pCurrentTask->m_nTaskID == pCmdUI->m_nID));
BOOL bEnab = GetDocument()->IsTaskAvailable(pCmdUI->m_nID);
pCmdUI->Enable(bEnab);
pCmdUI->SetCheck(bCheck);
}
/////////////////////////////////////////////////////////////////////////////
// CViewUniv Action Handlers
void CViewUniv::OnRotateHor()
{
int idx = m_wndHorizBar.CommandToIndex(ID_VISUALISATION_POV_HSLIDER);
CBCGPSliderButton* pSlider = DYNAMIC_DOWNCAST(CBCGPSliderButton,m_wndHorizBar.GetButton(idx));
if (pSlider != NULL)
{
int nScrollPos = pSlider->GetPos (ID_VISUALISATION_POV_HSLIDER);
nScrollPos *=5;
int r = (int)(180 - nScrollPos + TPref::TUniv.sDefParam.theta);
r = (r < 0) ? r+ 360 : ((r > 360) ? r-360 : r);
SProjection MySProj = GetVisualParam()->GetProjParam();
MySProj.theta = r;
GetVisualParam()->SetProjParam(MySProj);
//GetVisualParam()->SetProjParam(r,ID_THETA);
SetFocus();
Invalidate();
UpdateWindow();
}
}
void CViewUniv::OnChangePointsOfView()
{
// TODO: Add your command handler code here
//GetVisualParam()->SetProjParam();
CCalques3DDoc *pDoc = GetDocument();
POSITION pos = pDoc->m_cPOVlist.GetHeadPosition ();
if (pos)
{
CPOVUserTool *pObj = pDoc->m_cPOVlist.GetNext (pos);
if (pObj)
GetVisualParam()->SetProjParam(pObj->m_projParam);
else
GetVisualParam()->SetProjParam();
}
else
GetVisualParam()->SetProjParam();
int r = (int)(GetVisualParam()->ProjParam.phi - 180 -TPref::TUniv.sDefParam.phi);
r = (r < 0) ? r + 360 : ((r > 360) ? r-360 : r);
r /= 5;
//**** wndVSliderBar.SetSliderPos(r);
SetSliderPosition(ID_VISUALISATION_POV_VSLIDER,r);
r = (int)(180 - GetVisualParam()->ProjParam.theta + TPref::TUniv.sDefParam.theta);
r = (r < 0) ? r+ 360 : ((r > 360) ? r-360 : r);
r /= 5;
//**** wndHSliderBar.SetSliderPos(r);
SetSliderPosition(ID_VISUALISATION_POV_HSLIDER,r);
Invalidate();
UpdateWindow();
}
void CViewUniv::OnRotateVer()
{
int idx = m_wndVertBar.CommandToIndex(ID_VISUALISATION_POV_VSLIDER);
CBCGPSliderButton* pSlider = DYNAMIC_DOWNCAST(CBCGPSliderButton,m_wndVertBar.GetButton(idx));
if (pSlider != NULL)
{
int nScrollPos = pSlider->GetPos (ID_VISUALISATION_POV_HSLIDER);
nScrollPos *=5;
int r = (int)(180 + nScrollPos + TPref::TUniv.sDefParam.phi);
r = (r < 0) ? r + 360 : ((r > 360) ? r-360 : r);
SProjection MySProj = GetVisualParam()->GetProjParam();
MySProj.phi = r;
GetVisualParam()->SetProjParam(MySProj);
SetFocus();
Invalidate();
UpdateWindow();
}
}
void CViewUniv::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CView::OnKeyDown(nChar, nRepCnt, nFlags);
if (!GetVisualParam()) return;
if (GetVisualParam()->bFixed) return;
BOOL bRedraw = TRUE;
switch (nChar){
case VK_NUMPAD8 :
case VK_UP:
GetVisualParam()->AddProjParam(-5,CVisualParam::ID_PHI);
break;
case VK_NUMPAD2 :
case VK_DOWN:
GetVisualParam()->AddProjParam(+5,CVisualParam::ID_PHI);
break;
case VK_NUMPAD4 :
case VK_LEFT:
GetVisualParam()->AddProjParam(+5,CVisualParam::ID_THETA);
break;
case VK_NUMPAD6 :
case VK_RIGHT:
GetVisualParam()->AddProjParam(-5,CVisualParam::ID_THETA);
break;
case VK_ADD :
if (GetVisualParam()->bParProj)
bRedraw = FALSE;
else