7fd59977 |
1 | // HLRDoc.cpp : implementation of the CHLRDoc class |
2 | // |
3 | |
4 | |
5 | #include "stdafx.h" |
6 | |
7 | #include "HLRDoc.h" |
7fd59977 |
8 | #include "HLRApp.h" |
9 | #include <OCC_2dView.h> |
10 | #include <OCC_3dView.h> |
11 | |
12 | |
13 | #include <ImportExport/ImportExport.h> |
14 | #include "AISDialogs.h" |
7fd59977 |
15 | #include <AIS_ListOfInteractive.hxx> |
16 | |
17 | #ifdef _DEBUG |
18 | //#define new DEBUG_NEW // by cascade |
19 | #undef THIS_FILE |
20 | static char THIS_FILE[] = __FILE__; |
21 | #endif |
22 | |
23 | ///////////////////////////////////////////////////////////////////////////// |
24 | // CHLRDoc |
25 | |
26 | IMPLEMENT_DYNCREATE(CHLRDoc, CDocument) |
27 | |
28 | |
29 | BEGIN_MESSAGE_MAP(CHLRDoc, OCC_3dBaseDoc) |
5c1f974e |
30 | //{{AFX_MSG_MAP(CHLRDoc) |
31 | ON_COMMAND(ID_WINDOW_NEW3D, OnWindowNew3d) |
32 | ON_COMMAND(ID_WINDOW_NEW2D, OnWindowNew2d) |
b3837d74 |
33 | ON_COMMAND(ID_FILE_HLR, OnBUTTONHLRDialog) |
5c1f974e |
34 | ON_COMMAND(ID_FILE_IMPORT_BREP, OnFileImportBrep) |
35 | ON_COMMAND(ID_BUTTON_HLRDialog, OnBUTTONHLRDialog) |
b3837d74 |
36 | ON_COMMAND(ID_OBJECT_ERASE, OnObjectErase) |
7fd59977 |
37 | //}}AFX_MSG_MAP |
38 | |
39 | |
40 | END_MESSAGE_MAP() |
41 | |
42 | ///////////////////////////////////////////////////////////////////////////// |
43 | // CHLRDoc construction/destruction |
44 | |
45 | CHLRDoc::CHLRDoc() |
46 | { |
5c1f974e |
47 | // TODO: add one-time construction code here |
48 | Handle(Graphic3d_GraphicDriver) theGraphicDriver = |
49 | ((CHLRApp*)AfxGetApp())->GetGraphicDriver(); |
50 | |
51 | // VIEWER 3D |
52 | TCollection_ExtendedString a3DName ("Visu3D"); |
53 | myViewer = new V3d_Viewer (theGraphicDriver, a3DName.ToExtString(), "", 1000.0, |
54 | V3d_XposYnegZpos, Quantity_NOC_GRAY30, |
55 | V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT, |
56 | Standard_True, Standard_False); |
57 | |
58 | myViewer->SetDefaultLights(); |
59 | myViewer->SetLightOn(); |
60 | |
61 | myAISContext =new AIS_InteractiveContext (myViewer); |
62 | |
63 | // 2D VIEWER: exploit V3d viewer for 2D visualization |
64 | TCollection_ExtendedString a2DName ("Visu2D"); |
65 | my2DViewer = new V3d_Viewer (theGraphicDriver, a2DName.ToExtString()); |
66 | my2DViewer->SetCircularGridValues (0, 0, 10, 8, 0); |
67 | my2DViewer->SetRectangularGridValues (0, 0, 10, 10, 0); |
68 | |
69 | //Set projection mode for 2D visualization |
70 | my2DViewer->SetDefaultViewProj (V3d_Zpos); |
71 | |
72 | myInteractiveContext2D = new AIS_InteractiveContext (my2DViewer); |
73 | |
74 | CFrameWnd* pFrame2d = ((CHLRApp*)AfxGetApp())->CreateView2D (this); |
75 | pFrame2d->ShowWindow (SW_SHOWNORMAL); |
76 | myCSelectionDialogIsCreated = false; |
7fd59977 |
77 | } |
78 | |
79 | CHLRDoc::~CHLRDoc() |
80 | { |
5c1f974e |
81 | if (myCSelectionDialogIsCreated) |
82 | { |
83 | myCSelectionDialog->ShowWindow(SW_ERASE); |
84 | delete myCSelectionDialog; |
85 | } |
7fd59977 |
86 | } |
87 | |
b3837d74 |
88 | void CHLRDoc::OnWindowNew2d() |
7fd59977 |
89 | { |
b3837d74 |
90 | ((CHLRApp*)AfxGetApp())->CreateView2D(this); |
7fd59977 |
91 | } |
92 | |
b3837d74 |
93 | void CHLRDoc::OnWindowNew3d() |
7fd59977 |
94 | { |
b3837d74 |
95 | ((CHLRApp*)AfxGetApp())->CreateView3D(this); |
7fd59977 |
96 | } |
97 | |
b3837d74 |
98 | // nCmdShow could be : ( default is SW_RESTORE ) |
7fd59977 |
99 | // SW_HIDE SW_SHOWNORMAL SW_NORMAL |
100 | // SW_SHOWMINIMIZED SW_SHOWMAXIMIZED |
101 | // SW_MAXIMIZE SW_SHOWNOACTIVATE |
102 | // SW_SHOW SW_MINIMIZE |
103 | // SW_SHOWMINNOACTIVE SW_SHOWNA |
104 | // SW_RESTORE SW_SHOWDEFAULT |
105 | // SW_MAX |
106 | |
107 | // use pViewClass = RUNTIME_CLASS( CHLRView3D ) for 3D Views |
108 | // use pViewClass = RUNTIME_CLASS( CHLRView2D ) for 2D Views |
109 | |
110 | void CHLRDoc::ActivateFrame(CRuntimeClass* pViewClass,int nCmdShow) |
111 | { |
112 | POSITION position = GetFirstViewPosition(); |
113 | while (position != (POSITION)NULL) |
114 | { |
115 | CView* pCurrentView = (CView*)GetNextView(position); |
5c1f974e |
116 | if(pCurrentView->IsKindOf(pViewClass) ) |
7fd59977 |
117 | { |
5c1f974e |
118 | ASSERT_VALID(pCurrentView); |
119 | CFrameWnd* pParentFrm = pCurrentView->GetParentFrame(); |
120 | ASSERT(pParentFrm != (CFrameWnd *)NULL); |
121 | // simply make the frame window visible |
122 | pParentFrm->ActivateFrame(nCmdShow); |
7fd59977 |
123 | } |
124 | } |
125 | } |
126 | |
127 | void CHLRDoc::FitAll2DViews(Standard_Boolean UpdateViewer) |
128 | { |
129 | if (UpdateViewer) my2DViewer->Update(); |
130 | POSITION position = GetFirstViewPosition(); |
131 | while (position != (POSITION)NULL) |
132 | { |
133 | CView* pCurrentView = (CView*)GetNextView(position); |
134 | if(pCurrentView->IsKindOf(RUNTIME_CLASS(OCC_2dView)) ) |
5c1f974e |
135 | { |
7fd59977 |
136 | ASSERT_VALID(pCurrentView); |
5c1f974e |
137 | ((OCC_2dView*)pCurrentView)->GetV2dView()->FitAll(); |
7fd59977 |
138 | } |
139 | } |
140 | } |
141 | |
7fd59977 |
142 | ///////////////////////////////////////////////////////////////////////////// |
143 | // CHLRDoc diagnostics |
144 | |
145 | #ifdef _DEBUG |
146 | void CHLRDoc::AssertValid() const |
147 | { |
5c1f974e |
148 | CDocument::AssertValid(); |
7fd59977 |
149 | } |
150 | |
151 | void CHLRDoc::Dump(CDumpContext& dc) const |
152 | { |
5c1f974e |
153 | CDocument::Dump(dc); |
7fd59977 |
154 | } |
155 | #endif //_DEBUG |
156 | |
157 | ///////////////////////////////////////////////////////////////////////////// |
158 | // CHLRDoc commands |
b3837d74 |
159 | void CHLRDoc::OnBUTTONHLRDialog() |
7fd59977 |
160 | { |
161 | if (!myCSelectionDialogIsCreated) |
5c1f974e |
162 | { |
163 | myCSelectionDialog = new CSelectionDialog(this,AfxGetMainWnd()); |
164 | myCSelectionDialog->Create(CSelectionDialog::IDD, AfxGetMainWnd()); |
165 | myCSelectionDialogIsCreated = true; |
166 | } |
b3837d74 |
167 | myCSelectionDialog->ShowWindow(SW_RESTORE); |
47162471 |
168 | myCSelectionDialog->UpdateWindow(); |
7fd59977 |
169 | } |
170 | |
171 | void CHLRDoc::OnFileImportBrep() |
172 | { CImportExport::ReadBREP(myAISContext); |
173 | Fit(); |
174 | } |
175 | void CHLRDoc::Fit() |
176 | { |
177 | POSITION position = GetFirstViewPosition(); |
178 | while (position != (POSITION)NULL) |
179 | { |
5c1f974e |
180 | CView* pCurrentView = (CView*)GetNextView(position); |
181 | if(pCurrentView->IsKindOf(RUNTIME_CLASS(OCC_3dView)) ) |
7fd59977 |
182 | { |
5c1f974e |
183 | ((OCC_3dView *) pCurrentView)->FitAll(); |
7fd59977 |
184 | } |
185 | } |
186 | } |
b3837d74 |
187 | |
188 | void CHLRDoc::OnObjectErase() |
189 | { |
190 | Standard_Boolean toUpdateDisplayable = Standard_False; |
7140edaf |
191 | myAISContext->InitCurrent(); |
192 | while (myAISContext->MoreCurrent()) |
b3837d74 |
193 | { |
b3837d74 |
194 | if (myAISContext->Current()->Type() == AIS_KOI_Shape && myCSelectionDialogIsCreated) |
195 | { |
196 | myCSelectionDialog->DiplayableShape()->Remove (Handle(AIS_Shape)::DownCast (myAISContext->Current())->Shape()); |
197 | toUpdateDisplayable = Standard_True; |
198 | } |
7140edaf |
199 | |
200 | myAISContext->Erase (myAISContext->Current(), Standard_True); |
201 | myAISContext->InitCurrent(); |
b3837d74 |
202 | } |
203 | |
204 | myAISContext->ClearCurrents(); |
205 | |
206 | if (toUpdateDisplayable) |
207 | { |
208 | // Update view in the HLR dialog if list of displayable shapes has been changed. |
209 | myCSelectionDialog->UpdateViews(); |
210 | } |
211 | } |