-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calques3DDoc.cpp
executable file
·1863 lines (1638 loc) · 43 KB
/
Calques3DDoc.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
//////////////////////////////////////////////////////////////////////
// Calques3DDoc.cpp: implementation of the CCalques3DDoc class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Calques3D.h"
#include <io.h>
#include <stdio.h>
#include <process.h>
#include "Prefs\Prefs.h"
#include "prefs\UndoBar.h"
#include "Calques3DDoc.h"
#include "objects\Point3D.h"
#include "objects\Droite3D.h"
#include "objects\Sphere3D.h"
#include "objects\Plan3D.h"
#include "objects\Cylinder3D.h"
#include "objects\CompositeObj3D.h"
#include "objects\Text3D.h"
#include "MainFrm.h"
#include "FormatToolBar.h"
#include "WarningDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//CxObject3DSet* GLOBALObjectSet;
CxObject3DSet* CCalques3DDoc::GLOBALObjectSet = NULL;
//***************************************************************************
// CWinPlacement
//***************************************************************************
IMPLEMENT_SERIAL(CWinPlacement, CObject, VERSIONABLE_SCHEMA | 1)
CWinPlacement::CWinPlacement()
{
m_pl.flags = 0;
m_pl.length = 0;
m_pl.ptMaxPosition = CPoint(0,0);
m_pl.ptMinPosition = CPoint(0,0);
m_pl.rcNormalPosition = CRect();
m_pl.showCmd = 0;
m_nIDWin = 0;
}
CWinPlacement::CWinPlacement(const CWinPlacement& src)
{
m_pl = src.m_pl;
m_nIDWin = src.m_nIDWin;
}
CWinPlacement::CWinPlacement(UINT str,WINDOWPLACEMENT tt)
{
m_pl = tt;
m_nIDWin = str;
}
void CWinPlacement::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << m_nIDWin;
ar << m_pl.flags;
ar << m_pl.ptMaxPosition;
ar << m_pl.ptMinPosition;
ar << m_pl.rcNormalPosition;
ar << m_pl.showCmd;
}
else
{
ar >> m_nIDWin;
ar >> m_pl.flags;
ar >> m_pl.ptMaxPosition;
ar >> m_pl.ptMinPosition;
ar >> m_pl.rcNormalPosition;
ar >> m_pl.showCmd;
m_pl.length = 0;
}
}
void CWinPlacement::operator =(const CWinPlacement& other)
{
m_pl = other.m_pl;
m_nIDWin = other.m_nIDWin;
}
//***************************************************************************
// CUndoObject
//***************************************************************************
IMPLEMENT_SERIAL(CUndoObject, CObject, VERSIONABLE_SCHEMA | 1)
CUndoObject::CUndoObject()
{
m_bCanDelete = FALSE;
m_nUndoState = CCalques3DDoc::UndoNone;
}
CUndoObject::~CUndoObject()
{
if (m_bCanDelete)
for (int i=0;i<m_cUndoSet.GetSize();i++)
{
CObject3D* pObj = m_cUndoSet.GetAt(i);
if (pObj) delete pObj;
}
m_cUndoSet.RemoveAll();
}
void CUndoObject::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar >> m_bCanDelete;
}
else
{
ar >> m_bCanDelete;
}
}
CString CUndoObject::GetUndoText()
{
CString m_strUndoObj;
CString strDesc,strName;
UINT nCmdID = m_nUndoState + IDS_UNDO_NONE;
strDesc.LoadString(nCmdID);
strName.Empty();
if (m_cUndoSet.GetSize())
{
CObject3D* pCObj = m_cUndoSet.GetAt(0);
if (pCObj) strName = pCObj->GetObjectName();
}
if (!strName.IsEmpty())
{
strName = _T(" (") + strName + _T(")");
}
m_strUndoObj = strDesc + strName;
return m_strUndoObj;
}
//***************************************************************************
// CCalques3DDoc
//***************************************************************************
//IMPLEMENT_DYNCREATE(CCalques3DDoc, CDocument)
IMPLEMENT_SERIAL(CCalques3DDoc, CDocument, VERSIONABLE_SCHEMA | 1)
BEGIN_MESSAGE_MAP(CCalques3DDoc, CDocument)
//{{AFX_MSG_MAP(CCalques3DDoc)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
ON_COMMAND(ID_EXPLORATION_DISCOVERY, OnDiscovery)
//ON_COMMAND(ID_VIEW_PLACEMENT_SAVE, OnViewPlacementSave)
//ON_COMMAND(ID_VIEW_PLACEMENT_RESTORE, OnViewPlacementRestore)
//ON_UPDATE_COMMAND_UI(ID_VIEW_PLACEMENT_RESTORE, OnUpdatePlacementRestore)
//}}AFX_MSG_MAP
ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCalques3DDoc construction/destruction
CCalques3DDoc::CCalques3DDoc()
{
// TODO: add one-time construction code here
m_nDocUndoState = UndoNone;
m_bMathPadUsed = false;
m_bLegacyVersion = FALSE;
m_cObjectSet.RemoveAll();
m_cPolygonSet.RemoveAll();
m_cPOVlist.RemoveAll();
//m_cUndoSet.RemoveAll();
m_cNewUndoSet.RemoveAll();
//m_pMemObj = NULL;
CCalques3DDoc::GLOBALObjectSet = NULL;
}
CCalques3DDoc::~CCalques3DDoc()
{
m_cPolygonSet.RemoveAll();
int nbObj = m_cObjectSet.GetSize();
for (int i=0;i<nbObj;i++)
{
CObject3D *pObj = m_cObjectSet.GetAt(i);
delete pObj;
}
m_cObjectSet.RemoveAll();
for (POSITION pos = m_cPOVlist.GetHeadPosition (); pos != NULL;)
{
CPOVUserTool *pObj = m_cPOVlist.GetNext (pos);
delete pObj;
}
m_cPOVlist.RemoveAll();
CleanUndo();
}
/////////////////////////////////////////////////////////////////////////////
// CCalques3DDoc file management
//////////////////////////////////////////////////////////////////////
/// Called by the framework as part of the File New command.
//////////////////////////////////////////////////////////////////////
BOOL CCalques3DDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
int idx = 1;
CPOVUserTool *tool = new CPOVUserTool();
tool->m_bCanRemove = FALSE;
tool->m_strLabel = _T("Default");
tool->m_projParam = TPref::TUniv.sDefParam;
m_cPOVlist.AddHead(tool);
return TRUE;
}
//////////////////////////////////////////////////////////////////////
/// Called by the framework as part of the File Open command.
///
/// The current implementation checks for the old serialization method (prior to version 2.4.0)
/// in case the current method (with version check) is failing.
///
/// @param lpszPathName Points to the path of the document to be opened.
///
/// @todo In case of a legacy document, the warning message needs to be modified in order to
/// take macro-constructions into account
//////////////////////////////////////////////////////////////////////
BOOL CCalques3DDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (IsModified())
TRACE0("Warning: OnOpenDocument replaces an unsaved document.\n");
CFileException fe;
CFile* pFile = GetFile(lpszPathName, CFile::modeRead|CFile::shareDenyWrite, &fe);
if (pFile == NULL)
{
ReportSaveLoadException(lpszPathName, &fe, FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
return FALSE;
}
DeleteContents();
SetModifiedFlag(); // dirty during de-serialize
CArchive loadArchive(pFile, CArchive::load | CArchive::bNoFlushOnDelete);
loadArchive.m_pDocument = this;
loadArchive.m_bForceFlat = FALSE;
try
{
// Try the current serialization method
CWaitCursor wait;
if (pFile->GetLength() != 0)
Serialize(loadArchive); // load me
loadArchive.Close();
ReleaseFile(pFile, FALSE);
}
catch (CException* e)
{
// If it failed, close the file and reopen it using the SerializeLegacy method
loadArchive.Close();
ReleaseFile(pFile, FALSE);
pFile = GetFile(lpszPathName, CFile::modeRead|CFile::shareDenyWrite, &fe);
CArchive loadArchive2(pFile, CArchive::load | CArchive::bNoFlushOnDelete);
loadArchive2.m_pDocument = this;
loadArchive2.m_bForceFlat = FALSE;
try
{
// Try the legacy serialization method
CWaitCursor wait;
SerializeLegacy(loadArchive2); // load me
loadArchive2.Close();
ReleaseFile(pFile, FALSE);
//ReportSaveLoadException(lpszPathName, NULL, FALSE, AFX_IDP_C3D_OLDVERSION);
m_bLegacyVersion = TRUE;
}
catch (CException* e2)
{
// If it failed, the document cannot be read by Calques 3D
ReleaseFile(pFile, TRUE);
DeleteContents(); // remove failed contents
ReportSaveLoadException(lpszPathName, e, FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
e->Delete();
e2->Delete();
return FALSE;
}
e->Delete();
}
// start off with unmodified or modified if legacy serialization
SetModifiedFlag(m_bLegacyVersion);
if (m_bMathPadUsed)
{
if (TPref::TMathPad.nShowView==1)
{
CMainFrame *pMFrame = DYNAMIC_DOWNCAST(CMainFrame,AfxGetMainWnd());
if (pMFrame) pMFrame->LaunchView(this,ID_VIEW_ANALYTIC);
m_bMathPadUsed = FALSE;
}
}
return TRUE;
}
BOOL CCalques3DDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
return CDocument::OnSaveDocument(lpszPathName);
}
BOOL CCalques3DDoc::CanCloseFrame(CFrameWnd* pFrame)
{
return CDocument::CanCloseFrame(pFrame);
}
void CCalques3DDoc::OnFileSave()
{
CDocument::OnFileSave();
}
void CCalques3DDoc::OnFileSaveAs()
{
CDocument::OnFileSaveAs();
}
/////////////////////////////////////////////////////////////////////////////
// CCalques3DDoc serialization
//////////////////////////////////////////////////////////////////////
/// Called by the framework to read or write this document from or to an archive.
/// This method is a legacy of older Calques 3D versions (prior to version 2.4.0 and
/// versionable serialization) and is maintained to allow access to old document.
///
/// @warning This method is assumed to be used only for loading document.
///
/// @param ar A CArchive object to serialize to or from.
//////////////////////////////////////////////////////////////////////
void CCalques3DDoc::SerializeLegacy(CArchive& ar)
{
if (ar.IsLoading())
{
CxObject3DSet pObjectSet;
CxObject3DSet pGlobalObjectSet;
CCalques3DDoc::GLOBALObjectSet = &pGlobalObjectSet;
pObjectSet.Serialize(ar);
int nb = pObjectSet.GetSize();
for (int i=0;i<nb;i++)
{
CObject3D *pObj = pObjectSet.GetAt(i);
if (!pObj) continue;
if (DYNAMIC_DOWNCAST(CEquation3D,pObj))
{
m_bMathPadUsed = TRUE;
}
AddObject(pObj,FALSE);
}
CCalques3DDoc::GLOBALObjectSet = NULL;
CPOVUserTool *tool = new CPOVUserTool();
tool->m_bCanRemove = FALSE;
tool->m_strLabel = _T("Default");
tool->m_projParam = TPref::TUniv.sDefParam;
m_cPOVlist.AddHead(tool);
}
}
//////////////////////////////////////////////////////////////////////
/// Called by the framework to read or write this document from or to an archive.
/// @param ar A CArchive object to serialize to or from.
//////////////////////////////////////////////////////////////////////
void CCalques3DDoc::Serialize(CArchive& ar)
{
ar.SerializeClass(RUNTIME_CLASS(CCalques3DDoc));
UINT schema = ar.GetObjectSchema();
if (ar.IsStoring())
{
// TODO: add storing code here
m_cObjectSet.Serialize(ar);
m_cPOVlist.Serialize(ar);
}
else
{
// TODO: add loading code here
CxObject3DSet pObjectSet;
CxObject3DSet pGlobalObjectSet;
CCalques3DDoc::GLOBALObjectSet = &pGlobalObjectSet;
pObjectSet.Serialize(ar);
int nb = pObjectSet.GetSize();
for (int i=0;i<nb;i++)
{
CObject3D *pObj = pObjectSet.GetAt(i);
if (!pObj) continue;
if (DYNAMIC_DOWNCAST(CEquation3D,pObj))
{
m_bMathPadUsed = TRUE;
}
AddObject(pObj,FALSE);
}
CCalques3DDoc::GLOBALObjectSet = NULL;
m_cPOVlist.Serialize(ar);
}
// try
// {
// m_cWinPos.Serialize(ar);
// }
// catch (CException* pEx)
// {
// pEx->Delete ();
// m_strPathName.Empty(); // no path name yet
// SetModifiedFlag(TRUE); // make clean
// }
}
/////////////////////////////////////////////////////////////////////////////
// CCalques3DDoc diagnostics
#ifdef _DEBUG
void CCalques3DDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CCalques3DDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCalques3DDoc commands
int CCalques3DDoc::GetObjectSize(UINT nID)
{
int nb = 0,
nb2=0;
BOOL bRet = FALSE;
switch (nID){
case IDS_NAME_OBJECT:
case IDS_NAME_POINT:
case IDS_NAME_SEG:
case IDS_NAME_CIRCLE:
case IDS_NAME_PLANE:
case IDS_NAME_CUBE:
case IDS_NAME_SPHERE:
case IDS_NAME_CYLIN:
case IDS_NAME_CONE:
bRet= m_cObjectSize.Lookup(nID,nb);
break;
case IDS_NAME_LINE:
bRet= m_cObjectSize.Lookup(IDS_NAME_LINE,nb2);
bRet= m_cObjectSize.Lookup(IDS_NAME_SEG,nb);
nb+=nb2;
break;
default:
nb = 0;//m_cObjectSet.GetSize();
break;
}
return nb;
}
void CCalques3DDoc::RenumberObjects()
{
int nIdx = 1;
int nbObj = m_cObjectSet.GetSize();
for (int i=0;i<nbObj;i++)
{
CObject3D *pObj = m_cObjectSet.GetAt(i);
if (!pObj) continue;
nIdx = pObj->SetObjectID(nIdx);
nIdx++;
}
}
void CCalques3DDoc::OnCountObjects(CObject3D *pObj,BOOL bAdd)
{
if (!pObj) return;
UINT nID = pObj->GetNameID();
int nSize = 0;
int nTotSize = 0;
BOOL bFound = m_cObjectSize.Lookup(nID,nSize);
bFound = m_cObjectSize.Lookup(IDS_NAME_OBJECT,nTotSize);
if (bAdd)
{
nTotSize++;
nSize++;
}
else
{
nTotSize--;
nSize--;
}
m_cObjectSize.SetAt(nID,nSize);
m_cObjectSize.SetAt(IDS_NAME_OBJECT,nTotSize);
CCompositeObj3D *pCptObj= DYNAMIC_DOWNCAST(CCompositeObj3D,pObj);
if (pCptObj)
{
for (int i=pCptObj->nStartShow;i<pCptObj->m_cSubObjects.GetSize();i++)
{
CObject3D *pobj2 = pCptObj->m_cSubObjects.GetAt(i);
OnCountObjects(pobj2,bAdd);
}
}
}
void CCalques3DDoc::OnUpdateEditUndo(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_cNewUndoSet.IsEmpty());
}
void CCalques3DDoc::OnUpdateEditRedo(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_cNewRedoSet.IsEmpty());
}
BOOL CCalques3DDoc::AddUndoObject(CUndoObject *pUndoObj/*=NULL*/)
{
if (!pUndoObj) return FALSE;
for (POSITION pos = m_cNewRedoSet.GetHeadPosition (); pos != NULL;)
{
CUndoObject *pObj = m_cNewRedoSet.GetNext (pos);
delete pObj;
}
m_cNewRedoSet.RemoveAll();
m_cNewUndoSet.AddHead(pUndoObj);
return TRUE;
}
BOOL CCalques3DDoc::AddObject(CObject3D* pObj,BOOL bUndo)
{
if (!pObj) return FALSE;
pObj->SetDepth();
int nbObj = m_cObjectSet.GetSize();
pObj->CalculConceptuel();
pObj->nObjectId = nbObj+1;
m_cObjectSet.Add(pObj);
RenumberObjects();
//if (DYNAMIC_DOWNCAST(CPolygon3D,pObj))
// m_cPolygonSet.Add(pObj);
pObj->GetPolygons(&m_cPolygonSet);
pObj->SetInGraph();
OnCountObjects(pObj,TRUE);
//OnPrepareUndo();
if (bUndo)
{
m_nDocUndoState = UndoAppend;
//m_cUndoSet.Add(pObj);
CUndoObject * pUndoObj = new CUndoObject();
pUndoObj->m_cUndoSet.Add(pObj);
pUndoObj->m_bCanDelete = FALSE;
pUndoObj->m_nUndoState = UndoAppend;
//int nbO = CUndoButton::m_lstActions.GetCount();
//UINT nCmdID = m_nUndoState + IDS_UNDO_NONE;
//CString mstr,strID;
//mstr.LoadString(nCmdID);
//strID.Format(_T("%d - "),nbO+1);
//mstr = strID + mstr;
//CUndoButton::m_lstActions.AddHead (mstr);
//CRedoButton::m_lstActions.AddHead (mstr);
AddUndoObject(pUndoObj);
}
else
{
CleanUndo();
m_nDocUndoState = UndoNone;
}
SetModifiedFlag(TRUE);
//delete pList;
return TRUE;
}
BOOL CCalques3DDoc::RemoveObject(CObject3D* pObj,BOOL bUndo)
{
if (!pObj) return FALSE;
CxObject3DSet mySet;
pObj->GetDependList(&mySet);
OnPrepareUndo();
CUndoObject * pUndoObj = new CUndoObject();
pUndoObj->m_bCanDelete = TRUE;
pUndoObj->m_nUndoState = UndoDelete;
int nbDel = mySet.GetSize();
for (int j=nbDel-1;j>=0;j--)
{
CObject3D *zObj = mySet.GetAt(j);
CObject3D *pMyObj = NULL;
int nbObj = m_cObjectSet.GetSize();
int nCount = -1;
for (int i=0;i<nbObj;i++)
{
CObject3D* pO = m_cObjectSet.GetAt(i);
if (pO != zObj) continue;
pMyObj = zObj;
nCount = i;
break;
}
if (!pMyObj) continue;
OnCountObjects(pMyObj,FALSE);
//m_cUndoSet.Add(pMyObj);
pUndoObj->m_cUndoSet.Add(pMyObj);
m_cObjectSet.RemoveAt(nCount);
pMyObj->SetInGraph(FALSE);
RenumberObjects();
CxObject3DSet polylist;
pMyObj->GetPolygons(&polylist);
for (int z=0;z<polylist.GetSize();z++)
{
CObject3D* ppoly = polylist.GetAt(z);
if (!ppoly) continue;
for (int j=0;j<m_cPolygonSet.GetSize();j++)
{
CObject3D* pO2 = m_cPolygonSet.GetAt(j);
if (pO2==ppoly)
{
m_cPolygonSet.RemoveAt(j);
break;
}
}
}
/*if (DYNAMIC_DOWNCAST(CPolygon3D,pMyObj))
{
for (int j=0;j<m_cPolygonSet.GetSize();j++)
{
CObject3D* pO2 = m_cPolygonSet.GetAt(j);
if (pO2==pMyObj)
{
m_cPolygonSet.RemoveAt(j);
break;
}
}
}*/
UpdateAllViews(NULL,WM_UPDATEOBJ_DEL,pMyObj);
}
AddUndoObject(pUndoObj);
m_nDocUndoState = UndoDelete;
SetModifiedFlag(TRUE);
return TRUE;
}
BOOL CCalques3DDoc::ModifyPropObject(CObject3D* pObj,CObject3DAttr *pAttr /*= NULL*/)
{
if (!pObj) return FALSE;
// CObject3D *temp = pObj->CopyObject();
// if (!temp) return FALSE;
CUndoObject * pUndoObj = new CUndoObject();
pUndoObj->m_pAttr = pObj->GetAttributes();
//pUndoObj->m_pAttr.m_bVisible = pObj->bVisible;
//pUndoObj->m_pAttr.m_bMarked = pObj->bMarked;
//pUndoObj->m_pAttr.m_strObjectName = pObj->GetObjectName();
//pUndoObj->m_pAttr.m_nCalque = pObj->nCalque;
//pUndoObj->m_pAttr.m_pObjectShape = pObj->pObjectShape;
BOOL bRet = TRUE;
if (!pAttr)
{
bRet = pObj->SetProperties();
if (bRet)
{
/*CShape pNew = CShape(temp->pObjectShape);
//delete pObj->pObjectShape;
pObj->pObjectShape = pNew;
pObj->bVisible = temp->bVisible;
pObj->bMarked = temp->bMarked;
pObj->nCalque = pObj->nCalque & 1;*/
OnPrepareUndo();
m_nDocUndoState = UndoModify;
//m_cUndoSet.Add(pObj);
//m_pMemObj = temp;
pUndoObj->m_cUndoSet.Add(pObj);
pUndoObj->m_bCanDelete = FALSE;
pUndoObj->m_nUndoState = UndoModify;
//CUndoButton::m_lstActions.AddHead (mstr);
m_cNewUndoSet.AddHead(pUndoObj);
SetModifiedFlag(TRUE);
UpdateAllViews(NULL,WM_UPDATEOBJ_MOD,pObj);
}
else
{
//delete temp;
delete pUndoObj;
}
}
else
{
pObj->SetAttributes(*pAttr);
OnPrepareUndo();
m_nDocUndoState = UndoModify;
//m_cUndoSet.Add(pObj);
//m_pMemObj = temp;
pUndoObj->m_cUndoSet.Add(pObj);
pUndoObj->m_bCanDelete = FALSE;
pUndoObj->m_nUndoState = UndoModify;
//CUndoButton::m_lstActions.AddHead (mstr);
m_cNewUndoSet.AddHead(pUndoObj);
SetModifiedFlag(TRUE);
UpdateAllViews(NULL,WM_UPDATEOBJ_MOD,pObj);
}
return bRet;
}
BOOL CCalques3DDoc::MoveObject(CObject3D* pObj)
{
if (!pObj) return FALSE;
// CObject3D *temp = pObj->CopyObject();
// if (!temp) return FALSE;
OnPrepareUndo();
m_nDocUndoState = UndoMove;
//m_cUndoSet.Add(pObj);
//m_pMemObj = temp;
CUndoObject * pUndoObj = new CUndoObject();
pUndoObj->m_cUndoSet.Add(pObj);
pUndoObj->m_bCanDelete = FALSE;
pUndoObj->m_nUndoState = UndoMove;
CPoint3D *ptDes= DYNAMIC_DOWNCAST(CPoint3D,pObj);
pUndoObj->m_ptOldPos = ptDes->Concept_pt;
//int nbO = CUndoButton::m_lstActions.GetCount();
//UINT nCmdID = m_nUndoState + IDS_UNDO_NONE;
//CString mstr,strID;
//mstr.LoadString(nCmdID);
//strID.Format(_T("%d - "),nbO+1);
//mstr = strID + mstr;
//CUndoButton::m_lstActions.AddHead (mstr);
AddUndoObject(pUndoObj);
SetModifiedFlag(TRUE);
return TRUE;
}
void CCalques3DDoc::OnPrepareUndo()
{
/*int nb = m_cUndoSet.GetSize();
int i;
if (m_pMemObj) delete m_pMemObj;
m_pMemObj = NULL;
switch (m_nUndoState){
case UndoDelete:
for (i=0;i<nb;i++)
delete m_cUndoSet.GetAt(i);
case UndoModify:
case UndoMove:
case UndoAppend:
case UndoNone:
break;
}
m_cUndoSet.RemoveAll();*/
}
BOOL CCalques3DDoc::OnSetUndo()
{
return TRUE;
}
void CCalques3DDoc::CleanUndo()
{
POSITION pos = NULL;
for (pos = m_cNewUndoSet.GetHeadPosition (); pos != NULL;)
{
CUndoObject *pObj = m_cNewUndoSet.GetNext (pos);
delete pObj;
}
m_cNewUndoSet.RemoveAll();
for (pos = m_cNewRedoSet.GetHeadPosition (); pos != NULL;)
{
CUndoObject *pObj = m_cNewRedoSet.GetNext (pos);
delete pObj;
}
m_cNewRedoSet.RemoveAll();
}
BOOL CCalques3DDoc::OnDoRedo(CView *pView)
{
if (m_cNewRedoSet.IsEmpty()) return FALSE;
CUndoObject *pUndoObj = m_cNewRedoSet.GetHead();
if (!pUndoObj) return FALSE;
switch (pUndoObj->m_nUndoState){
case UndoAppend:
{
pUndoObj->m_bCanDelete = FALSE;
int nb = pUndoObj->m_cUndoSet.GetSize();
for (int i=nb-1;i>=0;i--)
{
CObject3D *pObj = pUndoObj->m_cUndoSet.GetAt(i);
if (!pObj) continue;
int nbObj = m_cObjectSet.GetSize();
pObj->CalculConceptuel();
pObj->nObjectId = nbObj+1;
m_cObjectSet.Add(pObj);
pObj->SetInGraph();
OnCountObjects(pObj,TRUE);
//if (DYNAMIC_DOWNCAST(CPolygon3D,pObj))
// m_cPolygonSet.Add(pObj);
pObj->GetPolygons(&m_cPolygonSet);
UpdateAllViews(pView,WM_UPDATEOBJ_ADD,pObj);
if (pView)
{
pView->Invalidate();
pView->UpdateWindow();
}
}
}
break;
case UndoModify:
{
int nb = pUndoObj->m_cUndoSet.GetSize();
//CString strName; ///< Old name of the object
//BOOL bVisible; ///< Old visible flag
//BOOL bMarked; ///< Old Marked flag
//int nCalque;
//CShape pOldShape; ///< Old Shape
for (int i=0;i<nb;i++)
{
CObject3D *pObj = pUndoObj->m_cUndoSet.GetAt(i);
if (!pObj) continue;
CObject3DAttr mAttr = pObj->GetAttributes();
//bVisible = pObj->bVisible;
//bMarked = pObj->bMarked;
//strName = pObj->GetObjectName();
//nCalque = pObj->nCalque;
//pOldShape = pObj->pObjectShape;
pObj->SetAttributes(pUndoObj->m_pAttr);
pUndoObj->m_pAttr = mAttr;
//pObj->bVisible = pUndoObj->m_bVisible;
//pObj->bMarked = pUndoObj->m_bMarked;
//pObj->nCalque = pUndoObj->m_nCalque;
//pObj->pObjectShape = pUndoObj->m_pOldShape;
//pObj->SetStyle(pObj->pObjectShape.nShapeId);
//pObj->SetColor(pObj->pObjectShape.clrObject);
//pObj->SetName(pUndoObj->m_strName);
//pUndoObj->m_bVisible = bVisible;
//pUndoObj->m_bMarked = bMarked;
//pUndoObj->m_strName = strName;
//pUndoObj->m_nCalque = nCalque;
//pUndoObj->m_pOldShape = pOldShape;
//OnPrepareUndo();
//m_nUndoState = UndoNone;
UpdateAllViews(pView,WM_UPDATEOBJ_MOD,pObj);
if (pView)
{
pView->Invalidate();
pView->UpdateWindow();
}
}
//if (TPref::Synchron)
}
break;
case UndoMove:
{
int nb = pUndoObj->m_cUndoSet.GetSize();
CVector4 ptNewPos;
for (int i=0;i<nb;i++)
{
CObject3D *pObj = pUndoObj->m_cUndoSet.GetAt(i);
CxObject3DSet pSet;
if (pObj->pComposite)
{
pObj->pComposite->GetDependList(&pSet);
}
else
{
pObj->GetDependList(&pSet);
}
int trr = pSet.GetSize();
//CPoint3D *ptSrc= DYNAMIC_DOWNCAST(CPoint3D,m_pMemObj);
CPoint3D *ptDes= DYNAMIC_DOWNCAST(CPoint3D,pObj);
if (ptDes)
{
ptNewPos = ptDes->Concept_pt;
ptDes->Concept_pt = pUndoObj->m_ptOldPos;
ptDes->CopyPointPosition(pUndoObj->m_ptOldPos);
pUndoObj->m_ptOldPos = ptNewPos;
}
//CObject3D* myObj = pSet.GetAt(j);
for (int j=0;j<trr;j++)
{
CObject3D* myObj = pSet.GetAt(j);
if (!myObj) continue;
//if (myObj == pObj) continue;
//if (myObj == pObj->pComposite) continue;
myObj->CalculConceptuel();
//myObj->CalculVisuel(myVisuParam);
}
if (pObj->pComposite)
{
pObj->CalculConceptuel();
}
UpdateAllViews(pView,WM_UPDATEOBJ_MOV,pObj);
if (pView)
{
pView->Invalidate();
pView->UpdateWindow();
}
//OnPrepareUndo();
//m_nUndoState = UndoNone;