7fd59977 |
1 | // OCC_3dBaseDoc.cpp: implementation of the OCC_3dBaseDoc class. |
2 | // |
3 | ////////////////////////////////////////////////////////////////////// |
4 | |
5 | #include <stdafx.h> |
6 | |
7 | #include "OCC_3dBaseDoc.h" |
8 | |
9 | #include "OCC_3dView.h" |
5c1f974e |
10 | #include "OCC_App.h" |
7fd59977 |
11 | #include <res\OCC_Resource.h> |
12 | #include "ImportExport/ImportExport.h" |
13 | #include "AISDialogs.h" |
14 | #include <AIS_ListOfInteractive.hxx> |
15 | #include <AIS_ListIteratorOfListOfInteractive.hxx> |
16 | |
17 | BEGIN_MESSAGE_MAP(OCC_3dBaseDoc, OCC_BaseDoc) |
5c1f974e |
18 | //{{AFX_MSG_MAP(OCC_3dBaseDoc) |
19 | ON_COMMAND(ID_FILE_IMPORT_BREP, OnFileImportBrep) |
20 | ON_COMMAND(ID_FILE_EXPORT_BREP, OnFileExportBrep) |
21 | ON_COMMAND(ID_OBJECT_ERASE, OnObjectErase) |
22 | ON_UPDATE_COMMAND_UI(ID_OBJECT_ERASE, OnUpdateObjectErase) |
23 | ON_COMMAND(ID_OBJECT_COLOR, OnObjectColor) |
24 | ON_UPDATE_COMMAND_UI(ID_OBJECT_COLOR, OnUpdateObjectColor) |
25 | ON_COMMAND(ID_OBJECT_SHADING, OnObjectShading) |
26 | ON_UPDATE_COMMAND_UI(ID_OBJECT_SHADING, OnUpdateObjectShading) |
27 | ON_COMMAND(ID_OBJECT_WIREFRAME, OnObjectWireframe) |
28 | ON_UPDATE_COMMAND_UI(ID_OBJECT_WIREFRAME, OnUpdateObjectWireframe) |
29 | ON_COMMAND(ID_OBJECT_TRANSPARENCY, OnObjectTransparency) |
30 | ON_UPDATE_COMMAND_UI(ID_OBJECT_TRANSPARENCY, OnUpdateObjectTransparency) |
31 | ON_COMMAND(ID_OBJECT_MATERIAL, OnObjectMaterial) |
32 | ON_UPDATE_COMMAND_UI(ID_OBJECT_MATERIAL, OnUpdateObjectMaterial) |
33 | ON_COMMAND(ID_OBJECT_DISPLAYALL, OnObjectDisplayall) |
34 | ON_UPDATE_COMMAND_UI(ID_OBJECT_DISPLAYALL, OnUpdateObjectDisplayall) |
35 | ON_COMMAND(ID_OBJECT_REMOVE, OnObjectRemove) |
36 | ON_UPDATE_COMMAND_UI(ID_OBJECT_REMOVE, OnUpdateObjectRemove) |
37 | //}}AFX_MSG_MAP |
38 | ON_COMMAND_EX_RANGE(ID_OBJECT_MATERIAL_BRASS,ID_OBJECT_MATERIAL_DEFAULT, OnObjectMaterialRange) |
39 | ON_UPDATE_COMMAND_UI_RANGE(ID_OBJECT_MATERIAL_BRASS,ID_OBJECT_MATERIAL_DEFAULT, OnUpdateObjectMaterialRange) |
7fd59977 |
40 | END_MESSAGE_MAP() |
41 | |
42 | |
43 | ////////////////////////////////////////////////////////////////////// |
44 | // Construction/Destruction |
45 | ////////////////////////////////////////////////////////////////////// |
46 | |
47 | OCC_3dBaseDoc::OCC_3dBaseDoc() |
48 | { |
5c1f974e |
49 | AfxInitRichEdit(); |
7fd59977 |
50 | |
5c1f974e |
51 | Handle(Graphic3d_GraphicDriver) aGraphicDriver = |
52 | ((OCC_App*)AfxGetApp())->GetGraphicDriver(); |
7fd59977 |
53 | |
5c1f974e |
54 | myViewer = new V3d_Viewer (aGraphicDriver, Standard_ExtString("Visu3D") ); |
55 | myViewer->SetDefaultLights(); |
56 | myViewer->SetLightOn(); |
57 | myAISContext = new AIS_InteractiveContext (myViewer); |
7fd59977 |
58 | } |
59 | |
5c1f974e |
60 | //----------------------------------------------------------------------------------------- |
61 | // |
62 | //----------------------------------------------------------------------------------------- |
63 | void OCC_3dBaseDoc::DragEvent (const Standard_Integer theMouseX, |
64 | const Standard_Integer theMouseY, |
65 | const Standard_Integer theState, |
66 | const Handle(V3d_View)& theView) |
7fd59977 |
67 | { |
5c1f974e |
68 | // TheState == -1 button down |
69 | // TheState == 0 move |
70 | // TheState == 1 button up |
7fd59977 |
71 | |
5c1f974e |
72 | static Standard_Integer aStartDragX = 0; |
73 | static Standard_Integer aStartDragY = 0; |
7fd59977 |
74 | |
5c1f974e |
75 | if (theState == -1) |
76 | { |
77 | // button down |
78 | aStartDragX = theMouseX; |
79 | aStartDragY = theMouseY; |
80 | } |
7fd59977 |
81 | |
5c1f974e |
82 | if (theState == 1) |
62a0addb |
83 | { |
5c1f974e |
84 | // button up |
85 | myAISContext->Select (aStartDragX, aStartDragY, |
86 | theMouseX, theMouseY, |
87 | theView); |
62a0addb |
88 | } |
7fd59977 |
89 | } |
90 | |
91 | //----------------------------------------------------------------------------------------- |
92 | // |
93 | //----------------------------------------------------------------------------------------- |
5c1f974e |
94 | void OCC_3dBaseDoc::InputEvent (const Standard_Integer theMouseX, |
95 | const Standard_Integer theMouseY, |
96 | const Handle(V3d_View)& theView) |
7fd59977 |
97 | { |
5c1f974e |
98 | myAISContext->MoveTo (theMouseX, theMouseY, theView); |
99 | myAISContext->Select(); |
7fd59977 |
100 | } |
101 | |
102 | //----------------------------------------------------------------------------------------- |
103 | // |
104 | //----------------------------------------------------------------------------------------- |
5c1f974e |
105 | void OCC_3dBaseDoc::MoveEvent (const Standard_Integer theMouseX, |
106 | const Standard_Integer theMouseY, |
107 | const Handle(V3d_View)& theView) |
7fd59977 |
108 | { |
5c1f974e |
109 | myAISContext->MoveTo (theMouseX, theMouseY, theView); |
7fd59977 |
110 | } |
111 | |
112 | //----------------------------------------------------------------------------------------- |
113 | // |
114 | //----------------------------------------------------------------------------------------- |
5c1f974e |
115 | void OCC_3dBaseDoc::ShiftMoveEvent (const Standard_Integer theMouseX, |
116 | const Standard_Integer theMouseY, |
117 | const Handle(V3d_View)& theView) |
7fd59977 |
118 | { |
5c1f974e |
119 | myAISContext->MoveTo (theMouseX, theMouseY, theView); |
7fd59977 |
120 | } |
121 | |
122 | //----------------------------------------------------------------------------------------- |
123 | // |
124 | //----------------------------------------------------------------------------------------- |
5c1f974e |
125 | void OCC_3dBaseDoc::ShiftDragEvent (const Standard_Integer theMouseX, |
126 | const Standard_Integer theMouseY, |
127 | const Standard_Integer theState, |
128 | const Handle(V3d_View)& theView) |
7fd59977 |
129 | { |
5c1f974e |
130 | // TheState == -1 button down |
131 | // TheState == 0 move |
132 | // TheState == 1 button up |
7fd59977 |
133 | |
5c1f974e |
134 | static Standard_Integer aStartDragX = 0; |
135 | static Standard_Integer aStartDragY = 0; |
7fd59977 |
136 | |
5c1f974e |
137 | if (theState == -1) |
138 | { |
139 | // button down |
140 | aStartDragX = theMouseX; |
141 | aStartDragY = theMouseY; |
142 | } |
7fd59977 |
143 | |
5c1f974e |
144 | if (theState == 0) |
145 | { |
146 | // button up |
147 | myAISContext->ShiftSelect (aStartDragX, aStartDragY, |
148 | theMouseX, theMouseY, |
149 | theView); |
150 | } |
151 | } |
7fd59977 |
152 | |
153 | //----------------------------------------------------------------------------------------- |
154 | // |
155 | //----------------------------------------------------------------------------------------- |
5c1f974e |
156 | void OCC_3dBaseDoc::ShiftInputEvent (const Standard_Integer theMouseX, |
157 | const Standard_Integer theMouseY, |
158 | const Handle(V3d_View)& theView) |
7fd59977 |
159 | { |
5c1f974e |
160 | myAISContext->ShiftSelect(); |
7fd59977 |
161 | } |
162 | |
163 | //----------------------------------------------------------------------------------------- |
164 | // |
165 | //----------------------------------------------------------------------------------------- |
5c1f974e |
166 | void OCC_3dBaseDoc::Popup (const Standard_Integer theMouseX, |
167 | const Standard_Integer theMouseY, |
168 | const Handle(V3d_View)& theView) |
7fd59977 |
169 | { |
170 | Standard_Integer PopupMenuNumber=0; |
5c1f974e |
171 | myAISContext->InitCurrent(); |
7fd59977 |
172 | if (myAISContext->MoreCurrent()) |
173 | PopupMenuNumber=1; |
174 | |
175 | CMenu menu; |
176 | VERIFY(menu.LoadMenu(IDR_Popup3D)); |
177 | CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber); |
178 | |
179 | ASSERT(pPopup != NULL); |
180 | if (PopupMenuNumber == 1) // more than 1 object. |
181 | { |
182 | bool OneOrMoreInShading = false; |
183 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
184 | if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true; |
185 | if(!OneOrMoreInShading) |
186 | pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED); |
187 | } |
188 | |
5c1f974e |
189 | POINT winCoord = { theMouseX , theMouseY }; |
7fd59977 |
190 | Handle(WNT_Window) aWNTWindow= |
5c1f974e |
191 | Handle(WNT_Window)::DownCast(theView->Window()); |
7fd59977 |
192 | ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord); |
193 | pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y , |
194 | AfxGetMainWnd()); |
195 | } |
196 | |
197 | void OCC_3dBaseDoc::Fit() |
198 | { |
199 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
200 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
201 | OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView(); |
202 | pView->FitAll(); |
203 | } |
204 | |
205 | int OCC_3dBaseDoc::OnFileImportBrep_WithInitDir(LPCTSTR InitialDir) |
206 | { |
207 | if(CImportExport::ReadBREP(myAISContext, InitialDir) == 1) |
208 | return 1; |
209 | Fit(); |
210 | return 0; |
211 | } |
212 | |
213 | void OCC_3dBaseDoc::OnFileImportBrep() |
214 | { |
215 | if(CImportExport::ReadBREP(myAISContext) == 1) |
216 | return; |
217 | Fit(); |
218 | |
219 | } |
220 | |
221 | void OCC_3dBaseDoc::OnFileExportBrep() |
222 | { CImportExport::SaveBREP(myAISContext);} |
223 | |
224 | void OCC_3dBaseDoc::OnObjectColor() |
225 | { |
226 | Handle_AIS_InteractiveObject Current ; |
227 | COLORREF MSColor ; |
228 | Quantity_Color CSFColor ; |
229 | |
230 | myAISContext->InitCurrent(); |
231 | Current = myAISContext->Current(); |
232 | if ( Current->HasColor () ) { |
233 | CSFColor = myAISContext->Color(myAISContext->Current()); |
234 | MSColor = RGB (CSFColor.Red()*255.,CSFColor.Green()*255.,CSFColor.Blue()*255.); |
235 | } |
236 | else { |
237 | MSColor = RGB (255,255,255) ; |
238 | } |
239 | |
240 | CColorDialog dlgColor(MSColor); |
241 | if (dlgColor.DoModal() == IDOK) |
242 | { |
243 | MSColor = dlgColor.GetColor(); |
244 | CSFColor = Quantity_Color (GetRValue(MSColor)/255.,GetGValue(MSColor)/255., |
245 | GetBValue(MSColor)/255.,Quantity_TOC_RGB); |
246 | for (;myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
247 | myAISContext->SetColor (myAISContext->Current(),CSFColor.Name()); |
248 | } |
249 | } |
250 | void OCC_3dBaseDoc::OnUpdateObjectColor(CCmdUI* pCmdUI) |
251 | { |
7fd59977 |
252 | bool OneOrMoreIsShadingOrWireframe = false; |
253 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
254 | if (myAISContext->IsDisplayed(myAISContext->Current(),0) |
255 | ||myAISContext->IsDisplayed(myAISContext->Current(),1)) |
256 | OneOrMoreIsShadingOrWireframe=true; |
257 | pCmdUI->Enable (OneOrMoreIsShadingOrWireframe); |
7fd59977 |
258 | } |
259 | |
260 | void OCC_3dBaseDoc::OnObjectErase() |
261 | { |
262 | for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->NextCurrent()) |
263 | myAISContext->Erase(myAISContext->Current(),Standard_True,Standard_False); |
264 | myAISContext->ClearCurrents(); |
265 | } |
266 | void OCC_3dBaseDoc::OnUpdateObjectErase(CCmdUI* pCmdUI) |
267 | { |
268 | bool OneOrMoreIsDisplayed = false; |
269 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
270 | if (myAISContext->IsDisplayed(myAISContext->Current())) OneOrMoreIsDisplayed=true; |
271 | pCmdUI->Enable (OneOrMoreIsDisplayed); |
272 | } |
273 | |
274 | void OCC_3dBaseDoc::OnObjectWireframe() |
275 | { |
276 | for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->NextCurrent()) |
277 | myAISContext->SetDisplayMode(myAISContext->Current(),0); |
278 | } |
279 | void OCC_3dBaseDoc::OnUpdateObjectWireframe(CCmdUI* pCmdUI) |
280 | { |
281 | bool OneOrMoreInShading = false; |
282 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
283 | if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true; |
284 | pCmdUI->Enable (OneOrMoreInShading); |
285 | } |
286 | |
287 | void OCC_3dBaseDoc::OnObjectShading() |
288 | { |
289 | for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->NextCurrent()) |
290 | myAISContext->SetDisplayMode(myAISContext->Current(),1); |
291 | } |
292 | |
293 | void OCC_3dBaseDoc::OnUpdateObjectShading(CCmdUI* pCmdUI) |
294 | { |
295 | bool OneOrMoreInWireframe = false; |
296 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
297 | if (myAISContext->IsDisplayed(myAISContext->Current(),0)) OneOrMoreInWireframe=true; |
298 | pCmdUI->Enable (OneOrMoreInWireframe); |
299 | } |
300 | |
301 | void OCC_3dBaseDoc::OnObjectMaterial() |
302 | { |
5c1f974e |
303 | CDialogMaterial DialBox(myAISContext); |
304 | DialBox.DoModal(); |
305 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
306 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
307 | OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView(); |
7fd59977 |
308 | } |
309 | |
310 | void OCC_3dBaseDoc::OnUpdateObjectMaterial(CCmdUI* pCmdUI) |
311 | { |
312 | bool OneOrMoreInShading = false; |
313 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
314 | if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true; |
315 | pCmdUI->Enable (OneOrMoreInShading); |
316 | } |
317 | |
318 | BOOL OCC_3dBaseDoc::OnObjectMaterialRange(UINT nID) |
319 | { |
320 | // the range ID_OBJECT_MATERIAL_BRASS to ID_OBJECT_MATERIAL_SILVER is |
321 | // continue with the same values as enumeration Type Of Material |
322 | Standard_Real aTransparency; |
323 | |
324 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()){ |
325 | aTransparency = myAISContext->Current()->Transparency(); |
326 | myAISContext->SetMaterial (myAISContext->Current(),(Graphic3d_NameOfMaterial)(nID-ID_OBJECT_MATERIAL_BRASS)); |
327 | myAISContext->SetTransparency (myAISContext->Current(),aTransparency); |
328 | } |
329 | return true; |
330 | |
331 | } |
332 | |
333 | void OCC_3dBaseDoc::OnUpdateObjectMaterialRange(CCmdUI* pCmdUI) |
334 | { |
335 | bool OneOrMoreInShading = false; |
336 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
337 | if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true; |
338 | pCmdUI->Enable (OneOrMoreInShading); |
339 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
340 | if (myAISContext->Current()->Material() - (pCmdUI->m_nID - ID_OBJECT_MATERIAL_BRASS) == 0) |
341 | pCmdUI->SetCheck(1); |
342 | } |
343 | |
344 | |
345 | void OCC_3dBaseDoc::OnObjectTransparency() |
346 | { |
347 | CDialogTransparency DialBox(myAISContext); |
348 | DialBox.DoModal(); |
349 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
350 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
351 | OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView(); |
352 | // pView->Redraw(); |
353 | } |
354 | |
355 | void OCC_3dBaseDoc::OnUpdateObjectTransparency(CCmdUI* pCmdUI) |
356 | { |
357 | bool OneOrMoreInShading = false; |
358 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
359 | if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true; |
360 | pCmdUI->Enable (OneOrMoreInShading); |
361 | } |
362 | |
363 | |
364 | void OCC_3dBaseDoc::OnObjectDisplayall() |
365 | { |
b96f3bea |
366 | myAISContext->DisplayAll(Standard_False); |
7fd59977 |
367 | } |
368 | |
369 | void OCC_3dBaseDoc::OnUpdateObjectDisplayall(CCmdUI* pCmdUI) |
370 | { |
371 | |
372 | AIS_ListOfInteractive aList; |
373 | myAISContext->ObjectsInside(aList,AIS_KOI_Shape); |
374 | AIS_ListIteratorOfListOfInteractive aLI; |
375 | Standard_Boolean IS_ANY_OBJECT_ERASED=FALSE; |
376 | for (aLI.Initialize(aList);aLI.More();aLI.Next()){ |
377 | if(!myAISContext->IsDisplayed(aLI.Value())) |
378 | IS_ANY_OBJECT_ERASED=TRUE; |
379 | } |
380 | pCmdUI->Enable (IS_ANY_OBJECT_ERASED); |
381 | |
382 | } |
383 | |
384 | void OCC_3dBaseDoc::OnObjectRemove() |
385 | { |
386 | for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->InitCurrent()) |
387 | myAISContext->Remove(myAISContext->Current(),Standard_True); |
388 | } |
389 | |
390 | void OCC_3dBaseDoc::OnUpdateObjectRemove(CCmdUI* pCmdUI) |
391 | { |
392 | bool OneOrMoreIsDisplayed = false; |
393 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
394 | if (myAISContext->IsDisplayed(myAISContext->Current())) OneOrMoreIsDisplayed=true; |
395 | pCmdUI->Enable (OneOrMoreIsDisplayed); |
396 | } |
397 | |
398 | void OCC_3dBaseDoc::SetMaterial(Graphic3d_NameOfMaterial Material) |
399 | { |
400 | for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ()) |
5c1f974e |
401 | myAISContext->SetMaterial (myAISContext->Current(), |
402 | (Graphic3d_NameOfMaterial)(Material)); |
7fd59977 |
403 | } |