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