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> |
a6eb515f |
16 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
17 | #include <TColStd_ListOfInteger.hxx> |
18 | #include <TopoDS_Shape.hxx> |
7fd59977 |
19 | |
20 | BEGIN_MESSAGE_MAP(OCC_3dBaseDoc, OCC_BaseDoc) |
5c1f974e |
21 | //{{AFX_MSG_MAP(OCC_3dBaseDoc) |
22 | ON_COMMAND(ID_FILE_IMPORT_BREP, OnFileImportBrep) |
23 | ON_COMMAND(ID_FILE_EXPORT_BREP, OnFileExportBrep) |
24 | ON_COMMAND(ID_OBJECT_ERASE, OnObjectErase) |
25 | ON_UPDATE_COMMAND_UI(ID_OBJECT_ERASE, OnUpdateObjectErase) |
26 | ON_COMMAND(ID_OBJECT_COLOR, OnObjectColor) |
27 | ON_UPDATE_COMMAND_UI(ID_OBJECT_COLOR, OnUpdateObjectColor) |
28 | ON_COMMAND(ID_OBJECT_SHADING, OnObjectShading) |
29 | ON_UPDATE_COMMAND_UI(ID_OBJECT_SHADING, OnUpdateObjectShading) |
30 | ON_COMMAND(ID_OBJECT_WIREFRAME, OnObjectWireframe) |
31 | ON_UPDATE_COMMAND_UI(ID_OBJECT_WIREFRAME, OnUpdateObjectWireframe) |
32 | ON_COMMAND(ID_OBJECT_TRANSPARENCY, OnObjectTransparency) |
33 | ON_UPDATE_COMMAND_UI(ID_OBJECT_TRANSPARENCY, OnUpdateObjectTransparency) |
34 | ON_COMMAND(ID_OBJECT_MATERIAL, OnObjectMaterial) |
35 | ON_UPDATE_COMMAND_UI(ID_OBJECT_MATERIAL, OnUpdateObjectMaterial) |
36 | ON_COMMAND(ID_OBJECT_DISPLAYALL, OnObjectDisplayall) |
37 | ON_UPDATE_COMMAND_UI(ID_OBJECT_DISPLAYALL, OnUpdateObjectDisplayall) |
38 | ON_COMMAND(ID_OBJECT_REMOVE, OnObjectRemove) |
39 | ON_UPDATE_COMMAND_UI(ID_OBJECT_REMOVE, OnUpdateObjectRemove) |
a6eb515f |
40 | |
5c1f974e |
41 | //}}AFX_MSG_MAP |
42 | ON_COMMAND_EX_RANGE(ID_OBJECT_MATERIAL_BRASS,ID_OBJECT_MATERIAL_DEFAULT, OnObjectMaterialRange) |
43 | ON_UPDATE_COMMAND_UI_RANGE(ID_OBJECT_MATERIAL_BRASS,ID_OBJECT_MATERIAL_DEFAULT, OnUpdateObjectMaterialRange) |
2c5b6d9c |
44 | |
45 | //RayTracing |
46 | ON_COMMAND(ID_OBJECT_RAY_TRACING,OnObjectRayTracing) |
47 | ON_COMMAND(ID_OBJECT_SHADOWS,OnObjectShadows) |
48 | ON_COMMAND(ID_OBJECT_REFLECTIONS,OnObjectReflections) |
49 | ON_COMMAND(ID_OBJECT_ANTI_ALIASING,OnObjectAntiAliasing) |
50 | |
51 | ON_UPDATE_COMMAND_UI(ID_OBJECT_RAY_TRACING, OnUpdateV3dButtons) |
52 | ON_UPDATE_COMMAND_UI(ID_OBJECT_SHADOWS, OnUpdateV3dButtons) |
53 | ON_UPDATE_COMMAND_UI(ID_OBJECT_REFLECTIONS, OnUpdateV3dButtons) |
54 | ON_UPDATE_COMMAND_UI(ID_OBJECT_ANTI_ALIASING, OnUpdateV3dButtons) |
7fd59977 |
55 | END_MESSAGE_MAP() |
56 | |
57 | |
58 | ////////////////////////////////////////////////////////////////////// |
59 | // Construction/Destruction |
60 | ////////////////////////////////////////////////////////////////////// |
61 | |
62 | OCC_3dBaseDoc::OCC_3dBaseDoc() |
47162471 |
63 | :myPopupMenuNumber(0) |
7fd59977 |
64 | { |
5c1f974e |
65 | AfxInitRichEdit(); |
7fd59977 |
66 | |
47162471 |
67 | Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((OCC_App*)AfxGetApp())->GetGraphicDriver(); |
7fd59977 |
68 | |
6a24c6de |
69 | myViewer = new V3d_Viewer (aGraphicDriver); |
5c1f974e |
70 | myViewer->SetDefaultLights(); |
71 | myViewer->SetLightOn(); |
72 | myAISContext = new AIS_InteractiveContext (myViewer); |
2c5b6d9c |
73 | |
74 | myRayTracingIsOn = false; |
75 | myRaytracedShadowsIsOn = true; |
76 | myRaytracedReflectionsIsOn = false; |
77 | myRaytracedAntialiasingIsOn = false; |
7fd59977 |
78 | } |
79 | |
234e52be |
80 | OCC_3dBaseDoc::~OCC_3dBaseDoc() |
81 | { |
82 | } |
83 | |
5c1f974e |
84 | //----------------------------------------------------------------------------------------- |
85 | // |
86 | //----------------------------------------------------------------------------------------- |
87 | void OCC_3dBaseDoc::DragEvent (const Standard_Integer theMouseX, |
88 | const Standard_Integer theMouseY, |
89 | const Standard_Integer theState, |
90 | const Handle(V3d_View)& theView) |
7fd59977 |
91 | { |
5c1f974e |
92 | // TheState == -1 button down |
93 | // TheState == 0 move |
94 | // TheState == 1 button up |
7fd59977 |
95 | |
5c1f974e |
96 | static Standard_Integer aStartDragX = 0; |
97 | static Standard_Integer aStartDragY = 0; |
7fd59977 |
98 | |
47162471 |
99 | switch (theState) |
5c1f974e |
100 | { |
47162471 |
101 | case -1: |
102 | { |
103 | aStartDragX = theMouseX; |
104 | aStartDragY = theMouseY; |
105 | break; |
106 | } |
107 | case 0: |
108 | { |
109 | myAISContext->UpdateCurrentViewer(); |
110 | break; |
111 | } |
112 | case 1: |
113 | { |
75cf8250 |
114 | myAISContext->SelectRectangle (Graphic3d_Vec2i (aStartDragX, aStartDragY), |
115 | Graphic3d_Vec2i (theMouseX, theMouseY), |
116 | theView); |
117 | myAISContext->UpdateCurrentViewer(); |
47162471 |
118 | break; |
119 | } |
120 | }; |
7fd59977 |
121 | } |
122 | |
123 | //----------------------------------------------------------------------------------------- |
124 | // |
125 | //----------------------------------------------------------------------------------------- |
5c1f974e |
126 | void OCC_3dBaseDoc::InputEvent (const Standard_Integer theMouseX, |
127 | const Standard_Integer theMouseY, |
128 | const Handle(V3d_View)& theView) |
7fd59977 |
129 | { |
0577ae8c |
130 | myAISContext->MoveTo (theMouseX, theMouseY, theView, Standard_False); |
75cf8250 |
131 | myAISContext->SelectDetected(); |
132 | myAISContext->UpdateCurrentViewer(); |
7fd59977 |
133 | } |
134 | |
135 | //----------------------------------------------------------------------------------------- |
136 | // |
137 | //----------------------------------------------------------------------------------------- |
5c1f974e |
138 | void OCC_3dBaseDoc::MoveEvent (const Standard_Integer theMouseX, |
139 | const Standard_Integer theMouseY, |
140 | const Handle(V3d_View)& theView) |
7fd59977 |
141 | { |
0577ae8c |
142 | myAISContext->MoveTo (theMouseX, theMouseY, theView, Standard_True); |
7fd59977 |
143 | } |
144 | |
145 | //----------------------------------------------------------------------------------------- |
146 | // |
147 | //----------------------------------------------------------------------------------------- |
5c1f974e |
148 | void OCC_3dBaseDoc::ShiftMoveEvent (const Standard_Integer theMouseX, |
149 | const Standard_Integer theMouseY, |
150 | const Handle(V3d_View)& theView) |
7fd59977 |
151 | { |
0577ae8c |
152 | myAISContext->MoveTo (theMouseX, theMouseY, theView, Standard_True); |
7fd59977 |
153 | } |
154 | |
155 | //----------------------------------------------------------------------------------------- |
156 | // |
157 | //----------------------------------------------------------------------------------------- |
5c1f974e |
158 | void OCC_3dBaseDoc::ShiftDragEvent (const Standard_Integer theMouseX, |
159 | const Standard_Integer theMouseY, |
160 | const Standard_Integer theState, |
161 | const Handle(V3d_View)& theView) |
7fd59977 |
162 | { |
5c1f974e |
163 | // TheState == -1 button down |
164 | // TheState == 0 move |
165 | // TheState == 1 button up |
7fd59977 |
166 | |
5c1f974e |
167 | static Standard_Integer aStartDragX = 0; |
168 | static Standard_Integer aStartDragY = 0; |
7fd59977 |
169 | |
5c1f974e |
170 | if (theState == -1) |
171 | { |
172 | // button down |
173 | aStartDragX = theMouseX; |
174 | aStartDragY = theMouseY; |
175 | } |
7fd59977 |
176 | |
5c1f974e |
177 | if (theState == 0) |
178 | { |
179 | // button up |
75cf8250 |
180 | myAISContext->SelectRectangle (Graphic3d_Vec2i (aStartDragX, aStartDragY), |
181 | Graphic3d_Vec2i (theMouseX, theMouseY), |
182 | theView, AIS_SelectionScheme_XOR); |
183 | myAISContext->UpdateCurrentViewer(); |
5c1f974e |
184 | } |
185 | } |
7fd59977 |
186 | |
187 | //----------------------------------------------------------------------------------------- |
188 | // |
189 | //----------------------------------------------------------------------------------------- |
5c573e69 |
190 | void OCC_3dBaseDoc::ShiftInputEvent (const Standard_Integer /*theMouseX*/, |
191 | const Standard_Integer /*theMouseY*/, |
192 | const Handle(V3d_View)& /*theView*/) |
7fd59977 |
193 | { |
75cf8250 |
194 | myAISContext->SelectDetected (AIS_SelectionScheme_XOR); |
195 | myAISContext->UpdateCurrentViewer(); |
7fd59977 |
196 | } |
197 | |
198 | //----------------------------------------------------------------------------------------- |
199 | // |
200 | //----------------------------------------------------------------------------------------- |
5c1f974e |
201 | void OCC_3dBaseDoc::Popup (const Standard_Integer theMouseX, |
202 | const Standard_Integer theMouseY, |
203 | const Handle(V3d_View)& theView) |
7fd59977 |
204 | { |
a6eb515f |
205 | // Base check which context menu to call |
206 | if (!myPopupMenuNumber) |
207 | { |
404c8936 |
208 | myAISContext->InitSelected(); |
209 | if (myAISContext->MoreSelected()) |
a6eb515f |
210 | myPopupMenuNumber=1; |
211 | } |
7fd59977 |
212 | |
213 | CMenu menu; |
214 | VERIFY(menu.LoadMenu(IDR_Popup3D)); |
a6eb515f |
215 | CMenu* pPopup = menu.GetSubMenu(myPopupMenuNumber); |
7fd59977 |
216 | |
217 | ASSERT(pPopup != NULL); |
a6eb515f |
218 | if (myPopupMenuNumber == 1) // more than 1 object. |
7fd59977 |
219 | { |
220 | bool OneOrMoreInShading = false; |
404c8936 |
221 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
222 | if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),1)) OneOrMoreInShading=true; |
7fd59977 |
223 | if(!OneOrMoreInShading) |
224 | pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED); |
225 | } |
226 | |
5c1f974e |
227 | POINT winCoord = { theMouseX , theMouseY }; |
7ff18fb9 |
228 | ClientToScreen ((HWND )theView->Window()->NativeHandle(), &winCoord); |
a6eb515f |
229 | pPopup->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, |
230 | winCoord.x, |
231 | winCoord.y, |
232 | AfxGetMainWnd()); |
7fd59977 |
233 | } |
234 | |
235 | void OCC_3dBaseDoc::Fit() |
236 | { |
237 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
238 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
239 | OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView(); |
240 | pView->FitAll(); |
241 | } |
242 | |
576f8b11 |
243 | int OCC_3dBaseDoc::OnFileImportBrep_WithInitDir (const wchar_t* ) |
244 | { |
245 | if (CImportExport::ReadBREP (myAISContext) == 1) |
246 | return 1; |
247 | Fit(); |
248 | return 0; |
7fd59977 |
249 | } |
250 | |
251 | void OCC_3dBaseDoc::OnFileImportBrep() |
252 | { |
576f8b11 |
253 | OnFileImportBrep_WithInitDir (NULL); |
7fd59977 |
254 | } |
255 | |
256 | void OCC_3dBaseDoc::OnFileExportBrep() |
257 | { CImportExport::SaveBREP(myAISContext);} |
258 | |
259 | void OCC_3dBaseDoc::OnObjectColor() |
260 | { |
92efcf78 |
261 | Handle(AIS_InteractiveObject) Current ; |
7fd59977 |
262 | COLORREF MSColor ; |
7fd59977 |
263 | |
404c8936 |
264 | myAISContext->InitSelected(); |
265 | Current = myAISContext->SelectedInteractive(); |
7fd59977 |
266 | if ( Current->HasColor () ) { |
87432b82 |
267 | Quantity_Color CSFColor; |
268 | myAISContext->Color (Current, CSFColor); |
7fd59977 |
269 | MSColor = RGB (CSFColor.Red()*255.,CSFColor.Green()*255.,CSFColor.Blue()*255.); |
270 | } |
271 | else { |
272 | MSColor = RGB (255,255,255) ; |
273 | } |
274 | |
275 | CColorDialog dlgColor(MSColor); |
276 | if (dlgColor.DoModal() == IDOK) |
277 | { |
278 | MSColor = dlgColor.GetColor(); |
87432b82 |
279 | Quantity_Color CSFColor (GetRValue(MSColor)/255., GetGValue(MSColor)/255., GetBValue(MSColor)/255., Quantity_TOC_RGB); |
404c8936 |
280 | for (;myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
87432b82 |
281 | myAISContext->SetColor (myAISContext->SelectedInteractive(), CSFColor, Standard_False); |
0577ae8c |
282 | myAISContext->UpdateCurrentViewer(); |
7fd59977 |
283 | } |
284 | } |
285 | void OCC_3dBaseDoc::OnUpdateObjectColor(CCmdUI* pCmdUI) |
286 | { |
7fd59977 |
287 | bool OneOrMoreIsShadingOrWireframe = false; |
404c8936 |
288 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
289 | if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),0) |
290 | ||myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),1)) |
7fd59977 |
291 | OneOrMoreIsShadingOrWireframe=true; |
b3837d74 |
292 | pCmdUI->Enable (OneOrMoreIsShadingOrWireframe); |
7fd59977 |
293 | } |
294 | |
295 | void OCC_3dBaseDoc::OnObjectErase() |
296 | { |
50c47573 |
297 | myAISContext->EraseSelected (Standard_True); |
7fd59977 |
298 | } |
299 | void OCC_3dBaseDoc::OnUpdateObjectErase(CCmdUI* pCmdUI) |
300 | { |
301 | bool OneOrMoreIsDisplayed = false; |
404c8936 |
302 | for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected()) |
b3837d74 |
303 | { |
404c8936 |
304 | if (myAISContext->IsDisplayed (myAISContext->SelectedInteractive())) |
b3837d74 |
305 | OneOrMoreIsDisplayed = true; |
306 | } |
307 | pCmdUI->Enable (OneOrMoreIsDisplayed); |
7fd59977 |
308 | } |
309 | |
310 | void OCC_3dBaseDoc::OnObjectWireframe() |
311 | { |
404c8936 |
312 | for(myAISContext->InitSelected();myAISContext->MoreSelected();myAISContext->NextSelected()) |
0577ae8c |
313 | myAISContext->SetDisplayMode (myAISContext->SelectedInteractive(), 0, Standard_False); |
314 | myAISContext->UpdateCurrentViewer(); |
7fd59977 |
315 | } |
316 | void OCC_3dBaseDoc::OnUpdateObjectWireframe(CCmdUI* pCmdUI) |
317 | { |
318 | bool OneOrMoreInShading = false; |
404c8936 |
319 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
320 | if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),1)) OneOrMoreInShading=true; |
7fd59977 |
321 | pCmdUI->Enable (OneOrMoreInShading); |
322 | } |
323 | |
324 | void OCC_3dBaseDoc::OnObjectShading() |
325 | { |
404c8936 |
326 | for(myAISContext->InitSelected();myAISContext->MoreSelected();myAISContext->NextSelected()) |
0577ae8c |
327 | myAISContext->SetDisplayMode (myAISContext->SelectedInteractive(), 1, Standard_False); |
328 | myAISContext->UpdateCurrentViewer(); |
7fd59977 |
329 | } |
330 | |
331 | void OCC_3dBaseDoc::OnUpdateObjectShading(CCmdUI* pCmdUI) |
332 | { |
333 | bool OneOrMoreInWireframe = false; |
404c8936 |
334 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
335 | if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),0)) OneOrMoreInWireframe=true; |
7fd59977 |
336 | pCmdUI->Enable (OneOrMoreInWireframe); |
337 | } |
338 | |
339 | void OCC_3dBaseDoc::OnObjectMaterial() |
340 | { |
5c1f974e |
341 | CDialogMaterial DialBox(myAISContext); |
342 | DialBox.DoModal(); |
5c573e69 |
343 | //CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
344 | //CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
345 | //OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView(); |
7fd59977 |
346 | } |
347 | |
348 | void OCC_3dBaseDoc::OnUpdateObjectMaterial(CCmdUI* pCmdUI) |
349 | { |
350 | bool OneOrMoreInShading = false; |
404c8936 |
351 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
352 | if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),1)) OneOrMoreInShading=true; |
7fd59977 |
353 | pCmdUI->Enable (OneOrMoreInShading); |
354 | } |
355 | |
356 | BOOL OCC_3dBaseDoc::OnObjectMaterialRange(UINT nID) |
357 | { |
358 | // the range ID_OBJECT_MATERIAL_BRASS to ID_OBJECT_MATERIAL_SILVER is |
359 | // continue with the same values as enumeration Type Of Material |
360 | Standard_Real aTransparency; |
361 | |
404c8936 |
362 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()){ |
0577ae8c |
363 | aTransparency = myAISContext->SelectedInteractive()->Transparency(); |
364 | myAISContext->SetMaterial (myAISContext->SelectedInteractive(),(Graphic3d_NameOfMaterial)(nID-ID_OBJECT_MATERIAL_BRASS), Standard_False); |
365 | myAISContext->SetTransparency (myAISContext->SelectedInteractive(),aTransparency, Standard_False); |
7fd59977 |
366 | } |
0577ae8c |
367 | myAISContext->UpdateCurrentViewer(); |
7fd59977 |
368 | return true; |
369 | |
370 | } |
371 | |
372 | void OCC_3dBaseDoc::OnUpdateObjectMaterialRange(CCmdUI* pCmdUI) |
373 | { |
374 | bool OneOrMoreInShading = false; |
404c8936 |
375 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
376 | if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),1)) OneOrMoreInShading=true; |
7fd59977 |
377 | pCmdUI->Enable (OneOrMoreInShading); |
404c8936 |
378 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
379 | if (myAISContext->SelectedInteractive()->Material() - (pCmdUI->m_nID - ID_OBJECT_MATERIAL_BRASS) == 0) |
7fd59977 |
380 | pCmdUI->SetCheck(1); |
381 | } |
382 | |
383 | |
384 | void OCC_3dBaseDoc::OnObjectTransparency() |
385 | { |
386 | CDialogTransparency DialBox(myAISContext); |
387 | DialBox.DoModal(); |
5c573e69 |
388 | //CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
389 | //CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
390 | //OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView(); |
7fd59977 |
391 | // pView->Redraw(); |
392 | } |
393 | |
394 | void OCC_3dBaseDoc::OnUpdateObjectTransparency(CCmdUI* pCmdUI) |
395 | { |
396 | bool OneOrMoreInShading = false; |
404c8936 |
397 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
398 | if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),1)) OneOrMoreInShading=true; |
7fd59977 |
399 | pCmdUI->Enable (OneOrMoreInShading); |
400 | } |
401 | |
402 | |
403 | void OCC_3dBaseDoc::OnObjectDisplayall() |
404 | { |
0577ae8c |
405 | myAISContext->DisplayAll (Standard_True); |
7fd59977 |
406 | } |
407 | |
408 | void OCC_3dBaseDoc::OnUpdateObjectDisplayall(CCmdUI* pCmdUI) |
409 | { |
50c47573 |
410 | AIS_ListOfInteractive aList; |
411 | myAISContext->ObjectsInside (aList); |
412 | for (AIS_ListIteratorOfListOfInteractive aLI (aList);aLI.More();aLI.Next()) |
413 | { |
414 | if (!myAISContext->IsDisplayed (aLI.Value())) |
415 | { |
416 | pCmdUI->Enable (true); |
417 | return; |
418 | } |
419 | } |
420 | pCmdUI->Enable (false); |
7fd59977 |
421 | } |
422 | |
423 | void OCC_3dBaseDoc::OnObjectRemove() |
424 | { |
404c8936 |
425 | for(myAISContext->InitSelected();myAISContext->MoreSelected();myAISContext->InitSelected()) |
426 | myAISContext->Remove(myAISContext->SelectedInteractive(),Standard_True); |
7fd59977 |
427 | } |
428 | |
429 | void OCC_3dBaseDoc::OnUpdateObjectRemove(CCmdUI* pCmdUI) |
430 | { |
431 | bool OneOrMoreIsDisplayed = false; |
404c8936 |
432 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
433 | if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive())) OneOrMoreIsDisplayed=true; |
a6eb515f |
434 | pCmdUI->Enable (OneOrMoreIsDisplayed); |
7fd59977 |
435 | } |
436 | |
437 | void OCC_3dBaseDoc::SetMaterial(Graphic3d_NameOfMaterial Material) |
438 | { |
404c8936 |
439 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
440 | myAISContext->SetMaterial (myAISContext->SelectedInteractive(), |
0577ae8c |
441 | (Graphic3d_NameOfMaterial)(Material), Standard_False); |
442 | myAISContext->UpdateCurrentViewer(); |
7fd59977 |
443 | } |
2c5b6d9c |
444 | |
445 | |
446 | // RayTracing |
447 | void OCC_3dBaseDoc::OnObjectRayTracing() |
448 | { |
449 | myRayTracingIsOn = !myRayTracingIsOn; |
450 | if(!myRayTracingIsOn) |
451 | { |
452 | myRaytracedShadowsIsOn = false; |
453 | myRaytracedReflectionsIsOn = false; |
454 | myRaytracedAntialiasingIsOn = false; |
455 | } |
456 | OnObjectRayTracingAction(); |
457 | } |
458 | // Shadows |
459 | void OCC_3dBaseDoc::OnObjectShadows() |
460 | { |
461 | myRaytracedShadowsIsOn = !myRaytracedShadowsIsOn; |
462 | OnObjectRayTracingAction(); |
463 | } |
464 | // Reflections |
465 | void OCC_3dBaseDoc::OnObjectReflections() |
466 | { |
467 | myRaytracedReflectionsIsOn = !myRaytracedReflectionsIsOn; |
468 | OnObjectRayTracingAction(); |
469 | } |
470 | // Anti-aliasing |
471 | void OCC_3dBaseDoc::OnObjectAntiAliasing() |
472 | { |
473 | myRaytracedAntialiasingIsOn = !myRaytracedAntialiasingIsOn; |
474 | OnObjectRayTracingAction(); |
475 | } |
476 | void OCC_3dBaseDoc::OnUpdateV3dButtons (CCmdUI* pCmdUI) |
477 | { |
478 | if (pCmdUI->m_nID == ID_OBJECT_RAY_TRACING) |
479 | { |
480 | pCmdUI->SetCheck(myRayTracingIsOn); |
481 | } else { |
482 | pCmdUI->Enable(myRayTracingIsOn); |
483 | if (pCmdUI->m_nID == ID_OBJECT_SHADOWS) |
484 | pCmdUI->SetCheck(myRaytracedShadowsIsOn); |
485 | if (pCmdUI->m_nID == ID_OBJECT_REFLECTIONS) |
486 | pCmdUI->SetCheck(myRaytracedReflectionsIsOn); |
487 | if (pCmdUI->m_nID == ID_OBJECT_ANTI_ALIASING) |
488 | pCmdUI->SetCheck(myRaytracedAntialiasingIsOn); |
489 | } |
490 | } |
491 | // Common function to change raytracing params and redraw view |
492 | void OCC_3dBaseDoc::OnObjectRayTracingAction() |
493 | { |
f7fc0c03 |
494 | Handle(V3d_View) aView = myAISContext->CurrentViewer()->ActiveViews().First(); |
2c5b6d9c |
495 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); |
496 | if (myRayTracingIsOn) |
497 | aParams.Method = Graphic3d_RM_RAYTRACING; |
498 | else |
499 | aParams.Method = Graphic3d_RM_RASTERIZATION; |
500 | aParams.IsShadowEnabled = myRaytracedShadowsIsOn; |
501 | aParams.IsReflectionEnabled = myRaytracedReflectionsIsOn; |
502 | aParams.IsAntialiasingEnabled = myRaytracedAntialiasingIsOn; |
503 | myAISContext->UpdateCurrentViewer(); |
504 | } |