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" |
a6eb515f |
14 | #include <AIS_LocalContext.hxx> |
7fd59977 |
15 | #include <AIS_ListOfInteractive.hxx> |
16 | #include <AIS_ListIteratorOfListOfInteractive.hxx> |
a6eb515f |
17 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
18 | #include <TColStd_ListOfInteger.hxx> |
19 | #include <TopoDS_Shape.hxx> |
7fd59977 |
20 | |
21 | BEGIN_MESSAGE_MAP(OCC_3dBaseDoc, OCC_BaseDoc) |
5c1f974e |
22 | //{{AFX_MSG_MAP(OCC_3dBaseDoc) |
23 | ON_COMMAND(ID_FILE_IMPORT_BREP, OnFileImportBrep) |
24 | ON_COMMAND(ID_FILE_EXPORT_BREP, OnFileExportBrep) |
25 | ON_COMMAND(ID_OBJECT_ERASE, OnObjectErase) |
26 | ON_UPDATE_COMMAND_UI(ID_OBJECT_ERASE, OnUpdateObjectErase) |
27 | ON_COMMAND(ID_OBJECT_COLOR, OnObjectColor) |
28 | ON_UPDATE_COMMAND_UI(ID_OBJECT_COLOR, OnUpdateObjectColor) |
29 | ON_COMMAND(ID_OBJECT_SHADING, OnObjectShading) |
30 | ON_UPDATE_COMMAND_UI(ID_OBJECT_SHADING, OnUpdateObjectShading) |
31 | ON_COMMAND(ID_OBJECT_WIREFRAME, OnObjectWireframe) |
32 | ON_UPDATE_COMMAND_UI(ID_OBJECT_WIREFRAME, OnUpdateObjectWireframe) |
33 | ON_COMMAND(ID_OBJECT_TRANSPARENCY, OnObjectTransparency) |
34 | ON_UPDATE_COMMAND_UI(ID_OBJECT_TRANSPARENCY, OnUpdateObjectTransparency) |
35 | ON_COMMAND(ID_OBJECT_MATERIAL, OnObjectMaterial) |
36 | ON_UPDATE_COMMAND_UI(ID_OBJECT_MATERIAL, OnUpdateObjectMaterial) |
37 | ON_COMMAND(ID_OBJECT_DISPLAYALL, OnObjectDisplayall) |
38 | ON_UPDATE_COMMAND_UI(ID_OBJECT_DISPLAYALL, OnUpdateObjectDisplayall) |
39 | ON_COMMAND(ID_OBJECT_REMOVE, OnObjectRemove) |
40 | ON_UPDATE_COMMAND_UI(ID_OBJECT_REMOVE, OnUpdateObjectRemove) |
a6eb515f |
41 | |
5c1f974e |
42 | //}}AFX_MSG_MAP |
43 | ON_COMMAND_EX_RANGE(ID_OBJECT_MATERIAL_BRASS,ID_OBJECT_MATERIAL_DEFAULT, OnObjectMaterialRange) |
44 | ON_UPDATE_COMMAND_UI_RANGE(ID_OBJECT_MATERIAL_BRASS,ID_OBJECT_MATERIAL_DEFAULT, OnUpdateObjectMaterialRange) |
2c5b6d9c |
45 | |
46 | //RayTracing |
47 | ON_COMMAND(ID_OBJECT_RAY_TRACING,OnObjectRayTracing) |
48 | ON_COMMAND(ID_OBJECT_SHADOWS,OnObjectShadows) |
49 | ON_COMMAND(ID_OBJECT_REFLECTIONS,OnObjectReflections) |
50 | ON_COMMAND(ID_OBJECT_ANTI_ALIASING,OnObjectAntiAliasing) |
51 | |
52 | ON_UPDATE_COMMAND_UI(ID_OBJECT_RAY_TRACING, OnUpdateV3dButtons) |
53 | ON_UPDATE_COMMAND_UI(ID_OBJECT_SHADOWS, OnUpdateV3dButtons) |
54 | ON_UPDATE_COMMAND_UI(ID_OBJECT_REFLECTIONS, OnUpdateV3dButtons) |
55 | ON_UPDATE_COMMAND_UI(ID_OBJECT_ANTI_ALIASING, OnUpdateV3dButtons) |
7fd59977 |
56 | END_MESSAGE_MAP() |
57 | |
58 | |
59 | ////////////////////////////////////////////////////////////////////// |
60 | // Construction/Destruction |
61 | ////////////////////////////////////////////////////////////////////// |
62 | |
63 | OCC_3dBaseDoc::OCC_3dBaseDoc() |
47162471 |
64 | :myPopupMenuNumber(0) |
7fd59977 |
65 | { |
5c1f974e |
66 | AfxInitRichEdit(); |
7fd59977 |
67 | |
47162471 |
68 | Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((OCC_App*)AfxGetApp())->GetGraphicDriver(); |
7fd59977 |
69 | |
6a24c6de |
70 | myViewer = new V3d_Viewer (aGraphicDriver); |
5c1f974e |
71 | myViewer->SetDefaultLights(); |
72 | myViewer->SetLightOn(); |
73 | myAISContext = new AIS_InteractiveContext (myViewer); |
2c5b6d9c |
74 | |
75 | myRayTracingIsOn = false; |
76 | myRaytracedShadowsIsOn = true; |
77 | myRaytracedReflectionsIsOn = false; |
78 | myRaytracedAntialiasingIsOn = false; |
7fd59977 |
79 | } |
80 | |
234e52be |
81 | OCC_3dBaseDoc::~OCC_3dBaseDoc() |
82 | { |
83 | } |
84 | |
5c1f974e |
85 | //----------------------------------------------------------------------------------------- |
86 | // |
87 | //----------------------------------------------------------------------------------------- |
88 | void OCC_3dBaseDoc::DragEvent (const Standard_Integer theMouseX, |
89 | const Standard_Integer theMouseY, |
90 | const Standard_Integer theState, |
91 | const Handle(V3d_View)& theView) |
7fd59977 |
92 | { |
5c1f974e |
93 | // TheState == -1 button down |
94 | // TheState == 0 move |
95 | // TheState == 1 button up |
7fd59977 |
96 | |
5c1f974e |
97 | static Standard_Integer aStartDragX = 0; |
98 | static Standard_Integer aStartDragY = 0; |
7fd59977 |
99 | |
47162471 |
100 | switch (theState) |
5c1f974e |
101 | { |
47162471 |
102 | case -1: |
103 | { |
104 | aStartDragX = theMouseX; |
105 | aStartDragY = theMouseY; |
106 | break; |
107 | } |
108 | case 0: |
109 | { |
110 | myAISContext->UpdateCurrentViewer(); |
111 | break; |
112 | } |
113 | case 1: |
114 | { |
115 | myAISContext->Select (aStartDragX, aStartDragY, |
116 | theMouseX, theMouseY, |
0577ae8c |
117 | theView, Standard_True); |
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); |
131 | myAISContext->Select (Standard_True); |
7fd59977 |
132 | } |
133 | |
134 | //----------------------------------------------------------------------------------------- |
135 | // |
136 | //----------------------------------------------------------------------------------------- |
5c1f974e |
137 | void OCC_3dBaseDoc::MoveEvent (const Standard_Integer theMouseX, |
138 | const Standard_Integer theMouseY, |
139 | const Handle(V3d_View)& theView) |
7fd59977 |
140 | { |
0577ae8c |
141 | myAISContext->MoveTo (theMouseX, theMouseY, theView, Standard_True); |
7fd59977 |
142 | } |
143 | |
144 | //----------------------------------------------------------------------------------------- |
145 | // |
146 | //----------------------------------------------------------------------------------------- |
5c1f974e |
147 | void OCC_3dBaseDoc::ShiftMoveEvent (const Standard_Integer theMouseX, |
148 | const Standard_Integer theMouseY, |
149 | const Handle(V3d_View)& theView) |
7fd59977 |
150 | { |
0577ae8c |
151 | myAISContext->MoveTo (theMouseX, theMouseY, theView, Standard_True); |
7fd59977 |
152 | } |
153 | |
154 | //----------------------------------------------------------------------------------------- |
155 | // |
156 | //----------------------------------------------------------------------------------------- |
5c1f974e |
157 | void OCC_3dBaseDoc::ShiftDragEvent (const Standard_Integer theMouseX, |
158 | const Standard_Integer theMouseY, |
159 | const Standard_Integer theState, |
160 | const Handle(V3d_View)& theView) |
7fd59977 |
161 | { |
5c1f974e |
162 | // TheState == -1 button down |
163 | // TheState == 0 move |
164 | // TheState == 1 button up |
7fd59977 |
165 | |
5c1f974e |
166 | static Standard_Integer aStartDragX = 0; |
167 | static Standard_Integer aStartDragY = 0; |
7fd59977 |
168 | |
5c1f974e |
169 | if (theState == -1) |
170 | { |
171 | // button down |
172 | aStartDragX = theMouseX; |
173 | aStartDragY = theMouseY; |
174 | } |
7fd59977 |
175 | |
5c1f974e |
176 | if (theState == 0) |
177 | { |
178 | // button up |
179 | myAISContext->ShiftSelect (aStartDragX, aStartDragY, |
180 | theMouseX, theMouseY, |
0577ae8c |
181 | theView, Standard_True); |
5c1f974e |
182 | } |
183 | } |
7fd59977 |
184 | |
185 | //----------------------------------------------------------------------------------------- |
186 | // |
187 | //----------------------------------------------------------------------------------------- |
5c573e69 |
188 | void OCC_3dBaseDoc::ShiftInputEvent (const Standard_Integer /*theMouseX*/, |
189 | const Standard_Integer /*theMouseY*/, |
190 | const Handle(V3d_View)& /*theView*/) |
7fd59977 |
191 | { |
0577ae8c |
192 | myAISContext->ShiftSelect (Standard_True); |
7fd59977 |
193 | } |
194 | |
195 | //----------------------------------------------------------------------------------------- |
196 | // |
197 | //----------------------------------------------------------------------------------------- |
5c1f974e |
198 | void OCC_3dBaseDoc::Popup (const Standard_Integer theMouseX, |
199 | const Standard_Integer theMouseY, |
200 | const Handle(V3d_View)& theView) |
7fd59977 |
201 | { |
a6eb515f |
202 | // Base check which context menu to call |
203 | if (!myPopupMenuNumber) |
204 | { |
404c8936 |
205 | myAISContext->InitSelected(); |
206 | if (myAISContext->MoreSelected()) |
a6eb515f |
207 | myPopupMenuNumber=1; |
208 | } |
7fd59977 |
209 | |
210 | CMenu menu; |
211 | VERIFY(menu.LoadMenu(IDR_Popup3D)); |
a6eb515f |
212 | CMenu* pPopup = menu.GetSubMenu(myPopupMenuNumber); |
7fd59977 |
213 | |
214 | ASSERT(pPopup != NULL); |
a6eb515f |
215 | if (myPopupMenuNumber == 1) // more than 1 object. |
7fd59977 |
216 | { |
217 | bool OneOrMoreInShading = false; |
404c8936 |
218 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
219 | if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),1)) OneOrMoreInShading=true; |
7fd59977 |
220 | if(!OneOrMoreInShading) |
221 | pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED); |
222 | } |
223 | |
5c1f974e |
224 | POINT winCoord = { theMouseX , theMouseY }; |
7fd59977 |
225 | Handle(WNT_Window) aWNTWindow= |
5c1f974e |
226 | Handle(WNT_Window)::DownCast(theView->Window()); |
7fd59977 |
227 | ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord); |
a6eb515f |
228 | pPopup->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, |
229 | winCoord.x, |
230 | winCoord.y, |
231 | AfxGetMainWnd()); |
7fd59977 |
232 | } |
233 | |
234 | void OCC_3dBaseDoc::Fit() |
235 | { |
236 | CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; |
237 | CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); |
238 | OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView(); |
239 | pView->FitAll(); |
240 | } |
241 | |
576f8b11 |
242 | int OCC_3dBaseDoc::OnFileImportBrep_WithInitDir (const wchar_t* ) |
243 | { |
244 | if (CImportExport::ReadBREP (myAISContext) == 1) |
245 | return 1; |
246 | Fit(); |
247 | return 0; |
7fd59977 |
248 | } |
249 | |
250 | void OCC_3dBaseDoc::OnFileImportBrep() |
251 | { |
576f8b11 |
252 | OnFileImportBrep_WithInitDir (NULL); |
7fd59977 |
253 | } |
254 | |
255 | void OCC_3dBaseDoc::OnFileExportBrep() |
256 | { CImportExport::SaveBREP(myAISContext);} |
257 | |
258 | void OCC_3dBaseDoc::OnObjectColor() |
259 | { |
92efcf78 |
260 | Handle(AIS_InteractiveObject) Current ; |
7fd59977 |
261 | COLORREF MSColor ; |
7fd59977 |
262 | |
404c8936 |
263 | myAISContext->InitSelected(); |
264 | Current = myAISContext->SelectedInteractive(); |
7fd59977 |
265 | if ( Current->HasColor () ) { |
87432b82 |
266 | Quantity_Color CSFColor; |
267 | myAISContext->Color (Current, CSFColor); |
7fd59977 |
268 | MSColor = RGB (CSFColor.Red()*255.,CSFColor.Green()*255.,CSFColor.Blue()*255.); |
269 | } |
270 | else { |
271 | MSColor = RGB (255,255,255) ; |
272 | } |
273 | |
274 | CColorDialog dlgColor(MSColor); |
275 | if (dlgColor.DoModal() == IDOK) |
276 | { |
277 | MSColor = dlgColor.GetColor(); |
87432b82 |
278 | Quantity_Color CSFColor (GetRValue(MSColor)/255., GetGValue(MSColor)/255., GetBValue(MSColor)/255., Quantity_TOC_RGB); |
404c8936 |
279 | for (;myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
87432b82 |
280 | myAISContext->SetColor (myAISContext->SelectedInteractive(), CSFColor, Standard_False); |
0577ae8c |
281 | myAISContext->UpdateCurrentViewer(); |
7fd59977 |
282 | } |
283 | } |
284 | void OCC_3dBaseDoc::OnUpdateObjectColor(CCmdUI* pCmdUI) |
285 | { |
7fd59977 |
286 | bool OneOrMoreIsShadingOrWireframe = false; |
404c8936 |
287 | for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ()) |
288 | if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),0) |
289 | ||myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),1)) |
7fd59977 |
290 | OneOrMoreIsShadingOrWireframe=true; |
b3837d74 |
291 | pCmdUI->Enable (OneOrMoreIsShadingOrWireframe); |
7fd59977 |
292 | } |
293 | |
294 | void OCC_3dBaseDoc::OnObjectErase() |
295 | { |
0577ae8c |
296 | myAISContext->EraseSelected (Standard_False); |
297 | myAISContext->ClearSelected (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 | { |
410 | |
411 | AIS_ListOfInteractive aList; |
412 | myAISContext->ObjectsInside(aList,AIS_KOI_Shape); |
413 | AIS_ListIteratorOfListOfInteractive aLI; |
414 | Standard_Boolean IS_ANY_OBJECT_ERASED=FALSE; |
415 | for (aLI.Initialize(aList);aLI.More();aLI.Next()){ |
416 | if(!myAISContext->IsDisplayed(aLI.Value())) |
417 | IS_ANY_OBJECT_ERASED=TRUE; |
418 | } |
419 | pCmdUI->Enable (IS_ANY_OBJECT_ERASED); |
420 | |
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 | { |
494 | myAISContext->CurrentViewer()->InitActiveViews(); |
495 | Handle(V3d_View) aView = myAISContext->CurrentViewer()->ActiveView(); |
496 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); |
497 | if (myRayTracingIsOn) |
498 | aParams.Method = Graphic3d_RM_RAYTRACING; |
499 | else |
500 | aParams.Method = Graphic3d_RM_RASTERIZATION; |
501 | aParams.IsShadowEnabled = myRaytracedShadowsIsOn; |
502 | aParams.IsReflectionEnabled = myRaytracedReflectionsIsOn; |
503 | aParams.IsAntialiasingEnabled = myRaytracedAntialiasingIsOn; |
504 | myAISContext->UpdateCurrentViewer(); |
505 | } |