-
Notifications
You must be signed in to change notification settings - Fork 2
/
OnStationSurveyTree.cpp
1149 lines (1072 loc) · 29.2 KB
/
OnStationSurveyTree.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
// OnStationSurveyTree.cpp : implementation file
//
#include "stdafx.h"
#include "onstation.h"
#include "OnStationSurveyTree.h"
#include "onstationdoc.h"
#include "folder.h"
#include "surveyleg.h"
#include "realfolder.h"
#include "legquery.h"
#include "colortool.h"
#include "newfolderdlg.h"
#include "legeditsheet.h"
#include "filehelper.h"
#include "fixedpoint.h"
#include "editfixedpointdialog.h"
#include "surfacedata.h"
#include "folderinfodlg.h"
#include "surfacepropertysheet.h"
#include "nodetree.h"
#include "onstationview.h"
#include "overalldataview.h"
#include "clipboard.h"
extern COnStationView * pView_G;
extern COnStationDoc * pDocument_G;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int COnStationSurveyTree::m_idxFolder=-1;
int COnStationSurveyTree::m_idxSurvey=-1;
int COnStationSurveyTree::m_idxPin=-1;
int COnStationSurveyTree::m_idxPinRoot=-1;
int COnStationSurveyTree::m_idxSurfaceFolder=-1;
int COnStationSurveyTree::m_idxSurfaceRoot=-1;
CImageList COnStationSurveyTree::m_ImageList;
COnStationSurveyTree * pSurveyTree_M;
//Timers don't work for this type of window. God know why?
void CALLBACK EXPORT TimerProc(HWND hWnd,
UINT nMsg,
UINT nIDEvent,
DWORD dwTime)
{
//This window is fucked up. We must do it through a function
pSurveyTree_M->FuckYouMicrosoftMorons();
}
void COnStationSurveyTree::InitializeTreeImageList()
{
if (m_idxFolder==-1)
{
m_ImageList.Create(16,15,FALSE,20,5); //allow up to 5 images if it needs to grow (Drag maybe)
CBitmap hBmp;
CBitmap hBmp2;
CBitmap hBmp3;
CBitmap hBmp4;
CBitmap hBmp5;
CBitmap hBmp6;
hBmp.LoadBitmap(IDB_BMFOLDERS);
m_idxFolder=m_ImageList.Add(&hBmp,(COLORREF)0);
hBmp2.LoadBitmap(IDB_BMSURVEYS);
m_idxSurvey=m_ImageList.Add(&hBmp2,(COLORREF)0);
hBmp3.LoadBitmap(IDB_BITMAPPIN);
m_idxPin=m_ImageList.Add(&hBmp3,(COLORREF)0);
hBmp4.LoadBitmap(IDB_BITMAPPINROOT);
m_idxPinRoot =m_ImageList.Add(&hBmp4,(COLORREF)0);
hBmp5.LoadBitmap(IDB_SURFACEFOLDERROOT);
m_idxSurfaceRoot =m_ImageList.Add(&hBmp5,(COLORREF)0);
hBmp6.LoadBitmap(IDB_SURFACEFOLDER);
m_idxSurfaceFolder =m_ImageList.Add(&hBmp6,(COLORREF)0);
}
}
COnStationSurveyTree::COnStationSurveyTree()
{
pSurveyTree_M=this;
InitializeTreeImageList(); //do static initialization
m_pLegQuery=NULL;
m_iColorScheme=0;
m_bDragging=FALSE;
m_bFixedPointsFolderIsOpen=FALSE;
m_pOverallDataView=NULL;
}
COnStationSurveyTree::~COnStationSurveyTree()
{
m_pLegQuery=NULL;
}
void COnStationSurveyTree::InitialUpdate(COverallDataView * pOverallDataView)
{
SetImageList(&m_ImageList,TVSIL_NORMAL);
UpdateItems();
//Select the first item so that things are more
//consistent
HTREEITEM hItem=GetNextItem(NULL,TVGN_CHILD);
Select(hItem,TVGN_FIRSTVISIBLE);
m_pOverallDataView=pOverallDataView;
}
void COnStationSurveyTree::SetQuery(CLegQuery * pLegQuery)
{
delete m_pLegQuery;
if (pLegQuery!=NULL && !pDocument_G->GetSurveyFolder()->DoesAnythingMatchTheQuery(pLegQuery))
{
AfxMessageBox(IDS_QUERYNOMATCHES);
delete pLegQuery;
m_pLegQuery=NULL;
UpdateItems();
}
else
{
m_pLegQuery=pLegQuery;
UpdateItems();
}
}
void COnStationSurveyTree::SetColorScheme(int iColorScheme)
{
m_iColorScheme=iColorScheme;
InvalidateRect(NULL,FALSE);
}
void COnStationSurveyTree::UpdateItems()
{
char szBuffer[128];
DeleteAllItems();
RecursiveTreeViewFill(pDocument_G->GetSurveyFolder(),TVI_ROOT,m_pLegQuery);
if (m_pLegQuery==NULL)
{
TV_INSERTSTRUCT TVIS;
TVIS.hParent=TVI_ROOT;
TVIS.hInsertAfter=TVI_LAST;
LoadString(AfxGetResourceHandle(),IDS_FIXEDPOINTROOTNAME,szBuffer,sizeof(szBuffer)-1); //the TI_ITEM won't take CStrings
TVIS.item.mask=TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TVIS.item.state=0;
TVIS.item.stateMask=0;
TVIS.item.cchTextMax=MAX_FOLDER_NAME_LENGTH-1;
TVIS.item.pszText=szBuffer;
TVIS.item.iImage=I_IMAGECALLBACK;
TVIS.item.iSelectedImage=I_IMAGECALLBACK;
TVIS.item.lParam=NULL;
HTREEITEM hParent=InsertItem(&TVIS);
ASSERT(GetLastError()==ERROR_SUCCESS);
CSurfaceData * pSurface=pDocument_G->GetSurface();
if (pSurface!=NULL)
{
int iCount=pSurface->GetFixedPointCount();
for (int i=0;i<iCount;i++)
{
CFixedPoint *pFixedPoint=pSurface->GetFixedPoint(i);
TV_INSERTSTRUCT TVIS;
TVIS.hParent=hParent;
TVIS.hInsertAfter=TVI_LAST;
TVIS.item.mask=TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TVIS.item.state=0;
TVIS.item.stateMask=0;
TVIS.item.cchTextMax=MAX_FOLDER_NAME_LENGTH-1;
lstrcpyn(szBuffer,pFixedPoint->GetName(),sizeof(szBuffer)-1);
TVIS.item.pszText=szBuffer;
TVIS.item.iImage=I_IMAGECALLBACK;
TVIS.item.iSelectedImage=I_IMAGECALLBACK;
TVIS.item.lParam=(LONG)((CObject *)pFixedPoint);
InsertItem(&TVIS);
TRACE("Fixed point param=%li\n",TVIS.item.lParam);
#ifdef _DEBUG
CObject * pObject=(CObject *)(TVIS.item.lParam);
ASSERT(dynamic_cast<CSurfaceData *>(pObject)==NULL);
ASSERT(dynamic_cast<CFixedPoint *>(pObject)!=NULL);
ASSERT(dynamic_cast<CFolder *>(pObject)==NULL);
#endif
}
}
Expand(hParent,m_bFixedPointsFolderIsOpen?TVE_EXPAND:TVE_COLLAPSE); //expand here since earlier it had no items.
ASSERT(GetLastError()==ERROR_SUCCESS);
TVIS.hParent=TVI_ROOT;
TVIS.hInsertAfter=TVI_LAST;
LoadString(AfxGetResourceHandle(),IDS_SURFACEFOLDERTITLE,szBuffer,sizeof(szBuffer)-1); //the TI_ITEM won't take CStrings
TVIS.item.mask=TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TVIS.item.state=0;
TVIS.item.stateMask=0;
TVIS.item.cchTextMax=MAX_FOLDER_NAME_LENGTH-1;
TVIS.item.pszText=szBuffer;
TVIS.item.iImage=I_IMAGECALLBACK;
TVIS.item.iSelectedImage=I_IMAGECALLBACK;
TVIS.item.lParam=(LONG)((CObject *)pSurface);
hParent=InsertItem(&TVIS);
ASSERT(GetLastError()==ERROR_SUCCESS);
#ifdef _DEBUG
CObject * pObject=(CObject *)(TVIS.item.lParam);
ASSERT((dynamic_cast<CSurfaceData *>(pObject))!=NULL);
ASSERT((dynamic_cast<CFixedPoint *>(pObject))==NULL);
ASSERT((dynamic_cast<CFolder *>(pObject))==NULL);
#endif
}
}
BEGIN_MESSAGE_MAP(COnStationSurveyTree, CTreeCtrl)
//{{AFX_MSG_MAP(COnStationSurveyTree)
ON_NOTIFY_REFLECT(TVN_BEGINDRAG, OnBegindrag)
ON_NOTIFY_REFLECT(TVN_ENDLABELEDIT, OnEndlabeledit)
ON_NOTIFY_REFLECT(TVN_GETDISPINFO, OnGetdispinfo)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
ON_NOTIFY_REFLECT(TVN_BEGINLABELEDIT, OnBeginlabeledit)
ON_NOTIFY_REFLECT(TVN_SELCHANGED,OnSelChanged)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//Fills a CTreeCtrl with the current heirarchy of folders.
//Uses query criterion to filter out unacceptable data.
void COnStationSurveyTree::RecursiveTreeViewFill(CFolder *folder,HTREEITEM hParent,CLegQuery * pLegQuery,HTREEITEM insertAfter)
{
char szBuffer[MAX_FOLDER_NAME_LENGTH];
TV_INSERTSTRUCT TVIS;
TVIS.hParent=hParent;
TVIS.hInsertAfter=insertAfter;
if (hParent==TVI_ROOT && pLegQuery!=NULL)
{
LoadString(AfxGetResourceHandle(),IDS_QUERYRESULTS,szBuffer,sizeof(szBuffer)-1);
}
else
{
lstrcpyn(szBuffer,folder->GetName(),MAX_FOLDER_NAME_LENGTH-1);
}
TVIS.item.mask=TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TVIS.item.state=0;
TVIS.item.stateMask=0;
TVIS.item.cchTextMax=MAX_FOLDER_NAME_LENGTH-1;
TVIS.item.pszText=szBuffer;
TVIS.item.iImage=I_IMAGECALLBACK;
TVIS.item.iSelectedImage=I_IMAGECALLBACK;
TVIS.item.lParam=(LONG)((CObject *)folder);
TRACE("Adding %s\n",szBuffer);
hParent=InsertItem(&TVIS);
ASSERT(GetLastError()==ERROR_SUCCESS);
folder->m_hTempTreeItem=hParent;
if (folder->IsFolder())
{
CRealFolder *RF=(CRealFolder *)folder;
RF->GotoTop();
CFolder *data=RF->GetCurrent();
while (data!=NULL)
{
if (data->IsFolder() && (pLegQuery==NULL || data->DoesAnythingMatchTheQuery(pLegQuery)))
{
RecursiveTreeViewFill(data,hParent,pLegQuery);
}
if (!data->IsFolder() && (pLegQuery==NULL || pLegQuery->MatchesQuery((CSurveyLeg *)data)))
{
RecursiveTreeViewFill(data,hParent,pLegQuery);
}
data=RF->GetNext();
}
Expand(hParent,pLegQuery!=NULL || (RF->IsExpanded())?TVE_EXPAND:TVE_COLLAPSE); //expand here since earlier it had no items.
ASSERT(GetLastError()==ERROR_SUCCESS);
}
}
CFixedPoint * COnStationSurveyTree::GetSelectedFixedPoint()
{
CFixedPoint *pFixedPoint=NULL;
TV_ITEM Item;
HTREEITEM hItem=GetSelectedItem();
if (hItem!=NULL)
{
Item.hItem=hItem;
Item.mask=TVIF_HANDLE|TVIF_PARAM;
GetItem(&Item);
CObject * pObject=(CObject *)(Item.lParam);
pFixedPoint=dynamic_cast<CFixedPoint *>(pObject);
}
return pFixedPoint;
}
CSurfaceData * COnStationSurveyTree::GetSelectedSurface()
{
CSurfaceData *pSurface=NULL;
TV_ITEM Item;
HTREEITEM hItem=GetSelectedItem();
if (hItem!=NULL)
{
Item.hItem=hItem;
Item.mask=TVIF_HANDLE|TVIF_PARAM;
GetItem(&Item);
CObject * pObject=(CObject *)(Item.lParam);
pSurface=dynamic_cast<CSurfaceData *>(pObject);
}
return pSurface;
}
CRealFolder * COnStationSurveyTree::GetSelectedRealFolder()
{
CRealFolder *folder=NULL;
TV_ITEM Item;
HTREEITEM hItem=GetSelectedItem();
if (hItem!=NULL)
{
Item.hItem=hItem;
Item.mask=TVIF_HANDLE|TVIF_PARAM;
GetItem(&Item);
CObject * pObject=(CObject *)(Item.lParam);
folder=dynamic_cast<CRealFolder *>(pObject);
}
return folder;
}
CSurveyLeg * COnStationSurveyTree::GetSelectedSurveyLeg()
{
CSurveyLeg *pLeg=NULL;
TV_ITEM Item;
HTREEITEM hItem=GetSelectedItem();
if (hItem!=NULL)
{
Item.hItem=hItem;
Item.mask=TVIF_HANDLE|TVIF_PARAM;
GetItem(&Item);
CObject * pObject=(CObject *)(Item.lParam);
pLeg=dynamic_cast<CSurveyLeg *>(pObject);
}
return pLeg;
}
void COnStationSurveyTree::OnDelete()
{
BOOL bRecalculateGeometry=TRUE;
switch (GetSelectedType())
{
case STS_NONE:
AfxMessageBox(IDS_NOSURVEYORFOLDERSELECTED);
break;
case STS_REALFOLDER:
{
CString CS;
CRealFolder * pFolder=GetSelectedRealFolder();
CS.FormatMessage(IDS_DELETEWARNING,pFolder->GetName());
if (pFolder->GetSize()!=0 && AfxMessageBox(CS,MB_YESNO)!=IDYES)
{
return;
}
bRecalculateGeometry=pFolder->GetSize()!=0;
if (pFolder!=pDocument_G->GetSurveyFolder())
{
pFolder->GetParentFolder()->Remove(pFolder);
delete pFolder;
}
else
{
pFolder->DeleteContents();
CString CS;
CS.LoadString(IDS_SURVEYROOT);
pFolder->SetName(CS);
}
UpdateItems();
}
break;
case STS_SURVEY:
{
CSurveyLeg * pLeg=GetSelectedSurveyLeg();
pLeg->DeleteContents();
DeleteItem(pLeg->m_hTempTreeItem);
pLeg->GetParentFolder()->Remove(pLeg);
delete pLeg;
}
break;
case STS_FIXEDPOINT:
{
CFixedPoint * pFixedPoint=GetSelectedFixedPoint();
pDocument_G->GetSurface()->RemoveFixedPoint(pFixedPoint);
DeleteItem(GetSelectedItem());
delete pFixedPoint;
}
break;
case STS_SURFACE:
{
CSurfaceData * pSurface=GetSelectedSurface();
if (AfxMessageBox(IDS_RESETALLSURFACEDATA,MB_YESNO)==IDYES)
{
pSurface->ResetAll();
}
else
{
return;
}
}
break;
case STS_FIXEDPOINTFOLDER:
if (AfxMessageBox(IDS_REMOVEALLFIXEDPOINTS,MB_YESNO)==IDYES)
{
pDocument_G->GetSurface()->RemoveAllFixedPoints();
UpdateItems();
}
else
{
return;
}
break;
}
if (bRecalculateGeometry)
{
pView_G->RecalculateGeometry(TRUE);
}
}
void COnStationSurveyTree::OnSelChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
//TVN_SELCHANGED
switch (GetSelectedType())
{
case STS_SURVEY:
case STS_REALFOLDER:
case STS_SURFACE:
m_pOverallDataView->EnableColorWidget(TRUE);
break;
default:
m_pOverallDataView->EnableColorWidget(FALSE);
break;
}
*pResult=0;
}
void COnStationSurveyTree::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
CObject *pObject=(CObject*)(pNMTreeView->itemNew.lParam);
CFolder * pFolder=dynamic_cast<CFolder *>(pObject);
if (pFolder!=NULL)
{
HCURSOR hCursor=LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_DRAGDROP));
SetCursor(hCursor);
//We don't get mouse messages for some reason, so
//we capture to the parent window instead
GetParent()->SetCapture();
m_bDragging=TRUE;
VERIFY(SetTimer(5,75,TimerProc)!=0);
m_hDragItem=pNMTreeView->itemNew.hItem;
*pResult = 0;
}
else
{
//Don't support dragging of fixed points
*pResult=1;
}
}
void COnStationSurveyTree::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
//Check for cancelation
if (pTVDispInfo->item.pszText!=NULL)
{
// TODO: Add your control notification handler code here
CObject *pObject=(CObject*)pTVDispInfo->item.lParam;
CFolder * pFolder=dynamic_cast<CFolder *>(pObject);
if (pFolder!=NULL)
{
BOOL CS=SetItemText(pTVDispInfo->item.hItem,pTVDispInfo->item.pszText);
pFolder->SetName(pTVDispInfo->item.pszText);
}
}
*pResult = 0;
}
void COnStationSurveyTree::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* Disp = (TV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
CObject * pData=(CObject *)Disp->item.lParam;
CFolder *folder=dynamic_cast<CFolder*>(pData);
//START OF SECTION ASSIGNING FOLDER IMAGE. These images are
//based on the color
if (folder!=NULL)
{
//A real folder is either open or closed
if (folder->IsFolder())
{
if ((Disp->item.state&TVIS_EXPANDED)!=0)
{
Disp->item.iImage=m_idxFolder;
Disp->item.iSelectedImage=m_idxFolder;
((CRealFolder *)folder)->SetExpanded(TRUE);
}
else
{
Disp->item.iImage=m_idxFolder+1;
Disp->item.iSelectedImage=m_idxFolder+1;
((CRealFolder *)folder)->SetExpanded(FALSE);
}
}
else
{
//A survey folder has a color based on the color scheme
if (m_iColorScheme>=0)
{
//Convert the color to a folder index
COLORREF crColor=folder->GetDrawColor(m_iColorScheme);
//First check to see if the survey is turned off or hidden.
if (crColor==COLOR_INACTIVE)
{
Disp->item.iImage=m_idxSurvey+16;
Disp->item.iSelectedImage=m_idxSurvey+16;
*pResult=0;
return;
}
if (crColor==COLOR_INVISIBLE)
{
Disp->item.iImage=m_idxSurvey+15;
Disp->item.iSelectedImage=m_idxSurvey+15;
*pResult=0;
return;
}
//Next check to see if we have a depth, age or 3d
//scheme since that overrides the normal colors
if (m_iColorScheme==COLORSCHEME_DEPTH)
{
Disp->item.iImage=m_idxSurvey+17;
Disp->item.iSelectedImage=m_idxSurvey+17;
*pResult=0;
return;
}
if (m_iColorScheme==COLORSCHEME_BLUNDER)
{
Disp->item.iImage=m_idxSurvey+18;
Disp->item.iSelectedImage=m_idxSurvey+18;
*pResult=0;
return;
}
//We have 15 colored folder bitmaps corresponding to the items in
for (int i=0;i<15;i++)
{
if (CGlobalColorManager::StandardVGAColors[i]==crColor)
{
Disp->item.iImage=m_idxSurvey+i+((m_iColorScheme==COLORSCHEME_AGE)?19:0);
Disp->item.iSelectedImage=m_idxSurvey+i+((m_iColorScheme==COLORSCHEME_AGE)?19:0);
}
}
}
else
{
Disp->item.iImage=m_idxSurvey+17;
Disp->item.iSelectedImage=m_idxSurvey+17;
}
}
}
else
{
//The selected item is not a folder. It must be a fixed point or
//the surface data. The fixed point root has NULL for it's item data.
if (pData==NULL)
{
//Item data is NULL, so we are the fixed point root. Show whether this
//is open or closed.
if ((Disp->item.state&TVIS_EXPANDED)!=0)
{
Disp->item.iImage=m_idxPinRoot;
Disp->item.iSelectedImage=m_idxPinRoot;
m_bFixedPointsFolderIsOpen=FALSE;
}
else
{
Disp->item.iImage=m_idxPinRoot+1;
Disp->item.iSelectedImage=m_idxPinRoot+1;
m_bFixedPointsFolderIsOpen=TRUE;
}
}
else
{
//See if this thing is surface data instead. We use
//the dynamic cast macro to convert this class.
CSurfaceData * pSurfaceData=dynamic_cast<CSurfaceData *>(pData);
TRACE("Trying to test point param=%li\n",Disp->item.lParam);
if (pSurfaceData==NULL)
{
CFixedPoint * pFixedPoint=dynamic_cast<CFixedPoint *>(pData);
BOOL bSuspectPin=TRUE;
if (pFixedPoint!=NULL)
{
bSuspectPin=pDocument_G->GetNodeTree()->FindNode(pFixedPoint->GetName(),FALSE)==NULL;
}
Disp->item.iImage=m_idxPin+(bSuspectPin?1:0);
Disp->item.iSelectedImage=m_idxPin+(bSuspectPin?1:0);
}
else
{
Disp->item.iImage=m_idxSurfaceFolder;
Disp->item.iSelectedImage=m_idxSurfaceFolder;
}
}
}
*pResult = 0;
}
void COnStationSurveyTree::OnMouseMove(UINT nFlags, CPoint pt)
{
ScreenToClient(&pt); //We got this from our parent window
POINT point=pt;
if (m_bDragging)
{
UINT flags;
flags=TVHT_ONITEM;
HTREEITEM hTarget=HitTest(point,&flags);
if (hTarget!=NULL)
{
TV_ITEM Item;
Item.hItem=hTarget;
Item.mask=TVIF_HANDLE|TVIF_PARAM;
GetItem(&Item);
CObject * pObject=(CObject *)(Item.lParam);
CFolder * pFolder;
pFolder=dynamic_cast<CFolder *>(pObject);
if (pFolder!=NULL)
{
if (!pFolder->IsFolder()) //Only drop onto a folder.
{
pFolder=pFolder->GetParentFolder();
}
SetCursor(LoadCursor(AfxGetResourceHandle(),MAKEINTRESOURCE(IDC_DRAGDROP)));
SelectDropTarget((HTREEITEM)pFolder->m_hTempTreeItem);
return;
}
}
//You can't drag and drop to here
SetCursor(LoadCursor(AfxGetResourceHandle(),MAKEINTRESOURCE(IDC_DRAGDROPBAD)));
}
}
void COnStationSurveyTree::OnLButtonUp(UINT nFlags, CPoint pt)
{
VERIFY(KillTimer(5)!=0);
ScreenToClient(&pt); //We got this from our parent window
POINT point=pt;
if (m_bDragging)
{
HTREEITEM hTarget;
TV_ITEM tvTarget;
TV_ITEM tvSource;
SetCursor(LoadCursor(NULL,IDC_ARROW));
hTarget=HitTest(point,&nFlags);
CFolder * pRealHit=NULL;
if (hTarget!=NULL)
{
tvTarget.hItem=hTarget;
tvTarget.mask=TVIF_HANDLE|TVIF_PARAM;
GetItem(&tvTarget);
tvSource.hItem=m_hDragItem;
tvSource.mask=TVIF_HANDLE|TVIF_PARAM;
GetItem(&tvSource);
//Set everything here
CObject *targetObj=(CObject *)tvTarget.lParam;
CObject *sourceObj=(CObject *)tvSource.lParam;
CFolder * target=dynamic_cast<CFolder *>(targetObj);
CFolder * source=dynamic_cast<CFolder *>(sourceObj);
if (target==NULL || source==NULL)
{
AfxMessageBox(IDS_ONLYDRAGSURVEYSANDFOLDER);
return;
}
if (!target->IsFolder()) //Only drop onto a folder.
{
pRealHit=target;
target=target->GetParentFolder();
}
if (target->IsDropTarget(source))
{
if (source!=pRealHit)
{
source->SetParentFolder((CRealFolder *)target,pRealHit);
DeleteItem(source->m_hTempTreeItem);
Select(target->m_hTempTreeItem,TVGN_CARET); //Select it
AddNewOne(source,FALSE,pRealHit);
}
}
//I don't see why this is necessary
// pView_G->RecalculateGeometry(TRUE);
}
SelectDropTarget((HTREEITEM)NULL);
ReleaseCapture();
SetCursor(LoadCursor(NULL,IDC_ARROW));
m_bDragging=FALSE;
}
}
void COnStationSurveyTree::AddNewOne(CFolder * newone,BOOL bRecalculate,CFolder * pInsertAfter)
{
CRealFolder *pFolder=GetSelectedRealFolder();
if (pFolder==NULL)
{
CSurveyLeg * pLeg=GetSelectedSurveyLeg();
if (pLeg!=NULL)
{
pInsertAfter=pLeg;
pFolder=pLeg->GetParentFolder();
}
}
if (pFolder==NULL)
{
pFolder=pDocument_G->GetSurveyFolder();
}
pDocument_G->SetModifiedFlag();
newone->SetParentFolder(pFolder,pInsertAfter);
RecursiveTreeViewFill(newone,pFolder->m_hTempTreeItem,m_pLegQuery,pInsertAfter?pInsertAfter->m_hTempTreeItem:TVI_LAST);
Expand(pFolder->m_hTempTreeItem,TVE_EXPAND); //open the folder if appropriate
EnsureVisible(newone->m_hTempTreeItem);
Select(newone->m_hTempTreeItem,TVGN_CARET); //Select it
if (bRecalculate)
{
pView_G->RecalculateGeometry(TRUE);
}
}
void COnStationSurveyTree::OnNewfolder()
{
CNewFolderDialog nfDlg(NULL);
if (nfDlg.DoModal()==IDOK)
{
CRealFolder *RF=new CRealFolder(pDocument_G);
RF->SetName(nfDlg.GetName());
AddNewOne(RF,FALSE,NULL);
}
}
void COnStationSurveyTree::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
//Delay processing. Otherwise we crash on exit becuause the code
//on the other side of this expects the control to be unchanged.
//Ie: the tree view called us and then we reset everything before
//returning hence KABOOOM!!!
AfxGetMainWnd()->PostMessage(WM_COMMAND,ID_EDIT_EDIT,0l);
// TODO: Add your control notification handler code here
*pResult = 0;
}
void COnStationSurveyTree::OnUpdateEditCopy(CCmdUI * pCmdUI)
{
switch (GetSelectedType())
{
case STS_NONE:
pCmdUI->Enable(FALSE);
break;
default:
pCmdUI->Enable(TRUE);
break;
}
}
void COnStationSurveyTree::OnUpdateEditDelete(CCmdUI * pCmdUI)
{
switch (GetSelectedType())
{
case STS_NONE:
pCmdUI->Enable(FALSE);
break;
default:
pCmdUI->Enable(TRUE);
break;
}
}
void COnStationSurveyTree::OnUpdateEditEdit(CCmdUI * pCmdUI)
{
switch (GetSelectedType())
{
case STS_NONE:
case STS_FIXEDPOINTFOLDER:
case STS_REALFOLDER:
pCmdUI->Enable(FALSE);
break;
default:
pCmdUI->Enable(TRUE);
break;
}
}
void COnStationSurveyTree::OnEditSelectedItem()
{
switch (GetSelectedType())
{
case STS_NONE:
AfxMessageBox(IDS_NOSURVEYORFOLDERSELECTED);
break;
case STS_REALFOLDER:
{
}
break;
case STS_SURVEY:
{
CSurveyLeg * pLeg=GetSelectedSurveyLeg();
ASSERT(AfxCheckMemory());
CEditSheet editdata(pLeg,IDS_SURVEYEDITSHEETTITLE,this,1);
if (editdata.DoModal()==IDOK)
{
// ASSERT(AfxCheckMemory());
if (editdata.NeedRecalculation())
{
pView_G->RecalculateGeometry(TRUE);
}
SetNewName(pLeg->m_hTempTreeItem,pLeg->GetName());
pDocument_G->SetModifiedFlag();
}
}
break;
case STS_FIXEDPOINT:
{
CFixedPoint * pFixedPoint=GetSelectedFixedPoint();
CEditFixedPointDialog dlgFixedPointEditor(pDocument_G,pFixedPoint);
if (dlgFixedPointEditor.DoModal()==IDOK)
{
pView_G->RecalculateGeometry(TRUE);
CSurfaceData * surf=pView_G->GetDocument()->GetSurface();
if (surf!=NULL)
{
pView_G->SetExactView(NAN,NAN,NAN,surf->ConvertXToLocal(pFixedPoint->GetX()),surf->ConvertYToLocal(pFixedPoint->GetY()),pFixedPoint->GetZ());
}
UpdateItems();
pDocument_G->SetModifiedFlag();
}
ASSERT(AfxCheckMemory());
}
break;
case STS_SURFACE:
{
CSurfacePropertySheet CSPS(pDocument_G,IDS_SURFACEPROPERTYSHEETTITLE);
if (CSPS.DoModal()==IDOK && CSPS.NeedRecalculation())
{
pView_G->RecalculateGeometry(TRUE);
pDocument_G->SetModifiedFlag();
}
ASSERT(AfxCheckMemory());
}
break;
case STS_FIXEDPOINTFOLDER:
//This must be the root of the fixed point list.
HTREEITEM hItem=GetSelectedItem();
Expand(hItem,TVE_TOGGLE);
pDocument_G->SetModifiedFlag();
break;
}
}
void COnStationSurveyTree::SetNewName(HTREEITEM hItem,LPCSTR szName)
{
TV_ITEM Item;
Item.hItem=hItem;
Item.mask=TVIF_TEXT;
char szBuffer[64];
lstrcpyn(szBuffer,szName,MAX_FOLDER_NAME_LENGTH-1);
Item.cchTextMax=MAX_FOLDER_NAME_LENGTH-1;
Item.pszText=szBuffer;
SetItem(&Item);
}
void COnStationSurveyTree::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
{
CMenu Menu;
CPoint point;
GetCursorPos(&point);
VERIFY(Menu.LoadMenu(IDR_SURVEYTREEMENU));
CMenu* pPopup = Menu.GetSubMenu(0);
switch (GetSelectedType())
{
case STS_NONE:
pPopup->EnableMenuItem(ID_SURVEYTREE_DELETECURRENTITEM,MF_GRAYED|MF_DISABLED);
//deliberately fall through
case STS_FIXEDPOINTFOLDER:
case STS_REALFOLDER:
pPopup->EnableMenuItem(ID_SURVEYTREE_EDITCURRENTITEM,MF_GRAYED|MF_DISABLED);
break;
}
//We popup the menu as if it belongs to the parent since this control
//does not handle WM_COMMAND messages properly
if (pPopup!=NULL)
{
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x,point.y,GetParent());
}
Menu.DestroyMenu();
}
void COnStationSurveyTree::OnCut()
{
OnCopy();
OnDelete();
}
void COnStationSurveyTree::OnCopy()
{
CWaitCursor w;
try
{
SURVEYTREESELECTED st=GetSelectedType();
if (st==STS_REALFOLDER || st==STS_SURVEY)
{
CBufferFileHelper BF;
CRealFolder *pFolder=GetSelectedRealFolder();
if (pFolder!=NULL)
{
pFolder->Write(&BF);
}
CSurveyLeg * pLeg=GetSelectedSurveyLeg();
if (pLeg!=NULL)
{
pLeg->Write(&BF);
}
CString CS;
CS=BF.GetTextStoring();
CClipboard::StringToClipboard(CS,TRUE);
}
}
catch (CMemoryException*)
{
AfxMessageBox(IDS_GENERALMEMORYERROR);
}
}
void COnStationSurveyTree::OnPaste()
{
CWaitCursor w;
CString string;
if (!CClipboard::StringFromClipboard(string,TRUE))
{
AfxMessageBox(IDS_NOFORMATONCLIPBOARD);
return;
}
try
{
CBufferFileHelper BF(string);
LPCSTR szData=BF.ReadTokenString("Begin");
if (lstrcmpi(szData,"Folder")==0)
{
try
{
BF.UndoLastRead();
CRealFolder *RF=new CRealFolder(pDocument_G);
RF->Read(&BF);
AddNewOne(RF,FALSE,NULL);
}
catch (void *)
{
AfxMessageBox(IDS_NOFORMATONCLIPBOARD);
}
} else if (lstrcmpi(szData,"Survey")==0)
{
try
{
BF.UndoLastRead();
CSurveyLeg *Leg=new CSurveyLeg(pDocument_G);
Leg->Read(&BF);
Leg->GetShotArray()->DoDeferredOffsetCalculation();
AddNewOne(Leg,FALSE,NULL);
}
catch (void *)
{
AfxMessageBox(IDS_NOFORMATONCLIPBOARD);
}
}
else
{
AfxMessageBox(IDS_NOFORMATONCLIPBOARD);
}
pView_G->RecalculateGeometry(TRUE);
}
catch (void *)
{
AfxMessageBox(IDS_NOFORMATONCLIPBOARD);
}
}
void COnStationSurveyTree::OnNewsurvey()
{