0024133: Development of improvement of dimensions implementation; new length, radius...
[occt.git] / samples / mfc / standard / 04_Viewer3d / src / Viewer3dDoc.cpp
CommitLineData
7fd59977 1// Viewer3dDoc.cpp : implementation of the CViewer3dDoc class
2//
3
4#include "stdafx.h"
5#include "Viewer3dApp.h"
6#include "BoxRadius.h"
7#include "DlgIsos.h"
8
9#include "Viewer3dDoc.h"
10#include "Viewer3dView.h"
11#include "OffsetDlg.h"
12#include "ResultDialog.h"
13#include "User_Cylinder.hxx"
14
15#include "AIS_Trihedron.hxx"
16#include "Geom_Axis2Placement.hxx"
17
18/////////////////////////////////////////////////////////////////////////////
19// CViewer3dDoc
20
21IMPLEMENT_DYNCREATE(CViewer3dDoc, CDocument)
22
23BEGIN_MESSAGE_MAP(CViewer3dDoc, OCC_3dBaseDoc)
24 //{{AFX_MSG_MAP(CViewer3dDoc)
25 ON_COMMAND(ID_BOX, OnBox)
26 ON_COMMAND(ID_Cylinder, OnCylinder)
27 ON_COMMAND(ID_SPHERE, OnSphere)
28 ON_COMMAND(ID_ERASEALL, OnRemoveAll)
29 ON_COMMAND(ID_NBISOS, OnNbisos)
30 ON_COMMAND(ID_FACES, OnFaces)
31 ON_COMMAND(ID_EDGES, OnEdges)
32 ON_COMMAND(ID_VERTICES, OnVertices)
33 ON_COMMAND(ID_NEUTRAL, OnNeutral)
34 ON_COMMAND(ID_USERCYLINDER_CHANGEFACECOLOR, OnUsercylinderChangefacecolor)
35 ON_COMMAND(ID_FILLET3D, OnFillet3d)
36 ON_COMMAND(ID_CIRCLE, OnCircle)
37 ON_COMMAND(ID_LINE, OnLine)
38 ON_COMMAND(ID_OVERLAPPED_BOX, OnOverlappedBox)
39 ON_COMMAND(ID_OVERLAPPED_CYLINDER, OnOverlappedCylinder)
40 ON_COMMAND(ID_OVERLAPPED_SPHERE, OnOverlappedSphere)
41 ON_COMMAND(ID_POLYGON_OFFSETS, OnPolygonOffsets)
42 ON_UPDATE_COMMAND_UI(ID_POLYGON_OFFSETS, OnUpdatePolygonOffsets)
43 ON_UPDATE_COMMAND_UI(ID_Cylinder, OnUpdateCylinder)
44 ON_UPDATE_COMMAND_UI(ID_SPHERE, OnUpdateSphere)
45 ON_UPDATE_COMMAND_UI(ID_BOX, OnUpdateBox)
46 ON_UPDATE_COMMAND_UI(ID_OVERLAPPED_CYLINDER, OnUpdateOverlappedCylinder)
47 ON_UPDATE_COMMAND_UI(ID_OVERLAPPED_SPHERE, OnUpdateOverlappedSphere)
48 ON_UPDATE_COMMAND_UI(ID_OVERLAPPED_BOX, OnUpdateOverlappedBox)
49 ON_COMMAND(ID_OBJECT_REMOVE, OnObjectRemove)
50 ON_COMMAND(ID_OBJECT_ERASE, OnObjectErase)
51 ON_COMMAND(ID_OBJECT_DISPLAYALL, OnObjectDisplayall)
52 ON_COMMAND(ID_OBJECT_COLORED_MESH, OnObjectColoredMesh)
53 ON_UPDATE_COMMAND_UI(ID_OBJECT_COLORED_MESH, OnUpdateObjectColoredMesh)
54 ON_UPDATE_COMMAND_UI(ID_OBJECT_SHADING, OnUpdateObjectShading)
55 ON_UPDATE_COMMAND_UI(ID_OBJECT_WIREFRAME, OnUpdateObjectWireframe)
56 ON_COMMAND(ID_OPTIONS_TRIHEDRON_DYNAMIC_TRIHEDRON, OnOptionsTrihedronDynamicTrihedron)
57 ON_UPDATE_COMMAND_UI(ID_OPTIONS_TRIHEDRON_DYNAMIC_TRIHEDRON, OnUpdateOptionsTrihedronDynamicTrihedron)
58 ON_UPDATE_COMMAND_UI(ID_OPTIONS_TRIHEDRON_STATIC_TRIHEDRON, OnUpdateOptionsTrihedronStaticTrihedron)
59 ON_COMMAND(ID_OBJECT_MATERIAL, OnObjectMaterial)
60 ON_COMMAND(ID_TEXTURE_ON, OnTextureOn)
61 ON_COMMAND(ID_BUTTONNext, OnBUTTONNext)
62 ON_COMMAND(ID_BUTTONStart, OnBUTTONStart)
63 ON_COMMAND(ID_BUTTONRepeat, OnBUTTONRepeat)
64 ON_COMMAND(ID_BUTTONPrev, OnBUTTONPrev)
65 ON_COMMAND(ID_BUTTONEnd, OnBUTTONEnd)
66 ON_UPDATE_COMMAND_UI(ID_BUTTONNext, OnUpdateBUTTONNext)
67 ON_UPDATE_COMMAND_UI(ID_BUTTONPrev, OnUpdateBUTTONPrev)
68 ON_UPDATE_COMMAND_UI(ID_BUTTONStart, OnUpdateBUTTONStart)
69 ON_UPDATE_COMMAND_UI(ID_BUTTONRepeat, OnUpdateBUTTONRepeat)
70 ON_UPDATE_COMMAND_UI(ID_BUTTONEnd, OnUpdateBUTTONEnd)
71 ON_COMMAND(ID_FILE_NEW, OnFileNew)
72 ON_COMMAND(ID_DUMP_VIEW, OnDumpView)
73 //}}AFX_MSG_MAP
74END_MESSAGE_MAP()
75
76/////////////////////////////////////////////////////////////////////////////
77// CViewer3dDoc construction/destruction
78
79CViewer3dDoc::CViewer3dDoc()
a6eb515f 80:OCC_3dDoc()
7fd59977 81{
82 myCylinder.Nullify();
83 mySphere.Nullify();
84 myBox.Nullify();
85 myOverlappedCylinder.Nullify();
86 myOverlappedSphere.Nullify();
87 myOverlappedBox.Nullify();
88 myOffsetDlg = NULL;
89 myStaticTrihedronAxisIsDisplayed = FALSE;
7fd59977 90 myState = -1;
91
92 isTextureSampleStarted = FALSE;
7fd59977 93
94 myPresentation = OCCDemo_Presentation::Current;
95 myPresentation->SetDocument(this);
96
97
98 myAISContext->DefaultDrawer()->ShadingAspect()->SetColor(Quantity_NOC_CHARTREUSE1);
99 myAISContext->DefaultDrawer()->ShadingAspect()->SetMaterial(Graphic3d_NOM_SILVER);
100
101 strcpy_s(myDataDir, "Data");
102 strcpy_s(myLastPath, ".");
103
104 /*
105 Handle(AIS_Trihedron) myTrihedron;
106 Handle(Geom_Axis2Placement) myTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
107 myTrihedron=new AIS_Trihedron(myTrihedronAxis);
108 myAISContext->Display(myTrihedron);
109 */
110}
111
112CViewer3dDoc::~CViewer3dDoc()
113{
114}
115
116/////////////////////////////////////////////////////////////////////////////
117// CViewer3dDoc diagnostics
118
119#ifdef _DEBUG
120void CViewer3dDoc::AssertValid() const
121{
122 CDocument::AssertValid();
123}
124
125void CViewer3dDoc::Dump(CDumpContext& dc) const
126{
127 CDocument::Dump(dc);
128}
129#endif //_DEBUG
130
131/////////////////////////////////////////////////////////////////////////////
132// CViewer3dDoc commands
133
134void CViewer3dDoc::UpdateResultMessageDlg(CString Title, TCollection_AsciiString aMessage)
135{
136 CString text(aMessage.ToCString());
137 myCResultDialog.SetText(text);
138
139 myCResultDialog.SetTitle(Title);
140}
141
142void CViewer3dDoc::OnBox()
143{
144 if(myBox.IsNull()){
145 BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
146
147
148 myBox = new AIS_Shape(B.Shape());
149
150 myAISContext->SetMaterial(myBox,Graphic3d_NOM_PEWTER);
151 myAISContext->SetDisplayMode(myBox,1);
152
153 myAISContext->Display(myBox);
154 TCollection_AsciiString Message("\
155BRepPrimAPI_MakeBox Box1(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
156 ");
157
158 UpdateResultMessageDlg("Create Box",Message);
159
160 }
161}
162
163void CViewer3dDoc::OnCylinder()
164{
165 if(myCylinder.IsNull()) {
166 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
167
168 //BRepPrimAPI_MakeCylinder C(CylAx2, 80.,200.);
169
170 myCylinder = new User_Cylinder(CylAx2, 80.,200.);
171
172// myCylinder = new AIS_Shape(C.Shape());
173/*
174 myCylinder->SetTransparency(0.5);
175
176 myAISContext->SetColor(myCylinder,Quantity_NOC_WHITE);
177 myAISContext->SetMaterial(myCylinder,Graphic3d_NOM_SHINY_PLASTIC);
178*/
179 myAISContext->SetDisplayMode(myCylinder,1);
180
181 myAISContext->Display(myCylinder);
182
183 TCollection_AsciiString Message("\
184gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));\n\
185C = new User_Cylinder(CylAx2, 80.,200.);;\n\
186 ");
187
188 UpdateResultMessageDlg("Create Cylinder",Message);
189
190 }
191}
192
193void CViewer3dDoc::OnSphere()
194{
195 if(mySphere.IsNull()){
196 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
197
198 mySphere = new AIS_Shape(S.Shape());
199
200 myAISContext->SetMaterial(mySphere,Graphic3d_NOM_BRONZE);
201 myAISContext->SetDisplayMode(mySphere,1);
202
203 myAISContext->Display(mySphere);
204 TCollection_AsciiString Message("\
205BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);\n\
206 ");
207 UpdateResultMessageDlg("Create Sphere",Message);
208 }
209}
210
211void CViewer3dDoc::OnRemoveAll()
212
213{
214 AIS_ListOfInteractive aListOfObjects;
215 myAISContext->ObjectsInside(aListOfObjects,AIS_KOI_Shape);
216
217 AIS_ListIteratorOfListOfInteractive aListIterator;
218 for(aListIterator.Initialize(aListOfObjects);aListIterator.More();aListIterator.Next()){
219 myAISContext->Remove(aListIterator.Value());
220 }
221
222 myAISContext->Remove(myCylinder);
223
224
225 myCylinder.Nullify();
226 mySphere.Nullify();
227 myBox.Nullify();
228 myOverlappedCylinder.Nullify();
229 myOverlappedSphere.Nullify();
230 myOverlappedBox.Nullify();
231 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
232 myOffsetDlg->UpdateValues();
233}
234
235void CViewer3dDoc::OnOverlappedBox()
236{
237 OnBox();
238 if(myOverlappedBox.IsNull()){
239 BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
240
241 BRepBuilderAPI_NurbsConvert aNurbsConvert(B.Shape());
242 TopoDS_Shape aBoxShape2 = aNurbsConvert.Shape();
243
244
245 myOverlappedBox = new AIS_Shape(aBoxShape2);
246
247 myAISContext->SetMaterial(myOverlappedBox,Graphic3d_NOM_GOLD);
248 myAISContext->SetDisplayMode(myOverlappedBox,1);
249
250 myAISContext->Display(myOverlappedBox);
251 TCollection_AsciiString Message("\
252BRepPrimAPI_MakeBox Box1(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
253\n\
254BRepPrimAPI_MakeBox Box2(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
255BRepBuilderAPI_NurbsConvert aNurbsConvert(Box2.Shape());\n\
256 ");
257 UpdateResultMessageDlg("Create overlapped boxes",Message);
258 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
259 myOffsetDlg->UpdateValues();
260
261
262 }
263}
264
265void CViewer3dDoc::OnOverlappedCylinder()
266{
267 OnCylinder();
268
269 if(myOverlappedCylinder.IsNull()){
270 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
271 BRepPrimAPI_MakeCylinder C(CylAx2, 80.,200.);
272
273 BRepBuilderAPI_NurbsConvert aNurbsConvert(C.Shape());
274 TopoDS_Shape aCylShape2 = aNurbsConvert.Shape();
275
276 myOverlappedCylinder = new AIS_Shape(aCylShape2);
277
278
279 myAISContext->SetMaterial(myOverlappedCylinder,Graphic3d_NOM_GOLD);
280 myAISContext->SetDisplayMode(myOverlappedCylinder,1);
281
282 myAISContext->Display(myOverlappedCylinder);
283
284 TCollection_AsciiString Message("\
285gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));\n\
286Cylinder1 = new User_Cylinder(CylAx2, 80.,200.);\n\
287\n\
288BRepPrimAPI_MakeCylinder Cylinder2(CylAx2, 80.,200.);\n\
289BRepBuilderAPI_NurbsConvert aNurbsConvert(Cylinder2.Shape());\n\
290 ");
291 UpdateResultMessageDlg("Create overlapped cylinders",Message);
292 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
293 myOffsetDlg->UpdateValues();
294
295 }
296}
297
298void CViewer3dDoc::OnOverlappedSphere()
299{
300 OnSphere();
301 if(myOverlappedSphere.IsNull()){
302 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
303
304 BRepBuilderAPI_NurbsConvert aNurbsConvert(S.Shape());
305 TopoDS_Shape aSphereShape2 = aNurbsConvert.Shape();
306
307 myOverlappedSphere = new AIS_Shape(aSphereShape2);
308
309 myAISContext->SetMaterial(myOverlappedSphere,Graphic3d_NOM_GOLD);
310
311 myAISContext->SetDisplayMode(myOverlappedSphere,1);
312
313 myAISContext->Display(myOverlappedSphere);
314
315 TCollection_AsciiString Message("\
316BRepPrimAPI_MakeSphere Sphere1(gp_Pnt(0,300,0), 100.);\n\
317\n\
318BRepPrimAPI_MakeSphere Sphere2(gp_Pnt(0,300,0), 100.);\n\
319BRepBuilderAPI_NurbsConvert aNurbsConvert(Sphere2.Shape());\n\
320 ");
321 UpdateResultMessageDlg("Create overlapped spheres",Message);
322 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
323 myOffsetDlg->UpdateValues();
324
325 }
326}
327
328void CViewer3dDoc::OnPolygonOffsets()
329{
330
331 myOffsetDlg = new COffsetDlg(this);
332 myOffsetDlg->Create(COffsetDlg::IDD,NULL);
333 myAISContext->UpdateCurrentViewer();
334
335}
336
337void CViewer3dDoc::OnUpdatePolygonOffsets(CCmdUI* pCmdUI)
338{
339 Standard_Integer aOffsetMode;
e145d04c
PK
340 Standard_ShortReal aFactor;
341 Standard_ShortReal aCylUnits = 0;
342 Standard_ShortReal aSphereUnits = 0;
343 Standard_ShortReal aBoxUnits = 0;
7fd59977 344
345 BOOL IsOverlappedCylinderDisplayed = myAISContext->IsDisplayed(myOverlappedCylinder);
346 BOOL IsOverlappedSphereDisplayed = myAISContext->IsDisplayed(myOverlappedSphere);
347 BOOL IsOverlappedBoxDisplayed = myAISContext->IsDisplayed(myOverlappedBox);
348 BOOL IsAnyOverlappedObjectDisplayed =
349 IsOverlappedCylinderDisplayed || IsOverlappedSphereDisplayed || IsOverlappedBoxDisplayed;
350
351 if(!myOverlappedCylinder.IsNull() && IsOverlappedCylinderDisplayed){
352 myOverlappedCylinder->PolygonOffsets(aOffsetMode,aFactor,aCylUnits);
353 }
354
355 if(!myOverlappedSphere.IsNull() && IsOverlappedSphereDisplayed){
356 myOverlappedSphere->PolygonOffsets(aOffsetMode,aFactor,aSphereUnits);
357 }
358
359 if(!myOverlappedBox.IsNull() && IsOverlappedBoxDisplayed){
360 myOverlappedBox->PolygonOffsets(aOffsetMode,aFactor,aBoxUnits);
361 }
362
363 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
364 pCmdUI->SetCheck(TRUE);
365 else
366 pCmdUI->SetCheck(FALSE);
367 if (IsAnyOverlappedObjectDisplayed)
368 if(myOffsetDlg)
369 pCmdUI->Enable(!myOffsetDlg->IsWindowVisible());
370 else
371 pCmdUI->Enable(TRUE);
372 else
373 pCmdUI->Enable(FALSE);
374
375
376}
377
378void CViewer3dDoc::OnUpdateCylinder(CCmdUI* pCmdUI)
379{
380 pCmdUI->Enable(myCylinder.IsNull());
381
382}
383
384void CViewer3dDoc::OnUpdateSphere(CCmdUI* pCmdUI)
385{
386 pCmdUI->Enable(mySphere.IsNull());
387
388}
389
390void CViewer3dDoc::OnUpdateBox(CCmdUI* pCmdUI)
391{
392 pCmdUI->Enable(myBox.IsNull());
393
394}
395
396void CViewer3dDoc::OnUpdateOverlappedCylinder(CCmdUI* pCmdUI)
397{
398 pCmdUI->Enable (myOverlappedCylinder.IsNull()
399 || myCylinder.IsNull());
400
401}
402
403void CViewer3dDoc::OnUpdateOverlappedSphere(CCmdUI* pCmdUI)
404{
405 pCmdUI->Enable (myOverlappedSphere.IsNull()
406 || mySphere.IsNull());
407}
408
409void CViewer3dDoc::OnUpdateOverlappedBox(CCmdUI* pCmdUI)
410{
411 pCmdUI->Enable (myOverlappedBox.IsNull()
412 || myBox.IsNull());
413}
414
415void CViewer3dDoc::OnObjectRemove()
416
417{
418
419 if(myAISContext->IsCurrent(myBox))
420 myBox.Nullify();
421
422 if(myAISContext->IsCurrent(myCylinder))
423 myCylinder.Nullify();
424
425 if(myAISContext->IsCurrent(mySphere))
426 mySphere.Nullify();
427
428 if(myAISContext->IsCurrent(myOverlappedBox))
429 myOverlappedBox.Nullify();
430
431 if(myAISContext->IsCurrent(myOverlappedCylinder))
432 myOverlappedCylinder.Nullify();
433
434 if(myAISContext->IsCurrent(myOverlappedSphere))
435 myOverlappedSphere.Nullify();
436
437
438 for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->InitCurrent())
439 myAISContext->Remove(myAISContext->Current(),Standard_True);
440
441 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
442 myOffsetDlg->UpdateValues();
443
444}
445
446void CViewer3dDoc::OnObjectErase()
447
448{
449 OCC_3dBaseDoc::OnObjectErase();
450 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
451 myOffsetDlg->UpdateValues();
7fd59977 452}
453
454void CViewer3dDoc::OnObjectDisplayall()
455
456{
457 OCC_3dBaseDoc::OnObjectDisplayall();
458 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
459 myOffsetDlg->UpdateValues();
7fd59977 460}
461
462Handle_User_Cylinder CViewer3dDoc::GetCylinder()
463{
464 return myCylinder;
465}
466
467
468Handle_AIS_Shape CViewer3dDoc::GetSphere()
469{
470 return mySphere;
471}
472
473Handle_AIS_Shape CViewer3dDoc::GetBox()
474{
475 return myBox;
476}
477
478Handle_AIS_Shape CViewer3dDoc::GetOverlappedCylinder()
479{
480 return myOverlappedCylinder;
481}
482
483
484Handle_AIS_Shape CViewer3dDoc::GetOverlappedSphere()
485{
486 return myOverlappedSphere;
487}
488
489Handle_AIS_Shape CViewer3dDoc::GetOverlappedBox()
490{
491 return myOverlappedBox;
492}
493
494void CViewer3dDoc::DragEvent(const Standard_Integer x ,
495 const Standard_Integer y ,
496 const Standard_Integer TheState ,
497 const Handle(V3d_View)& aView )
498{
499 OCC_3dBaseDoc::DragEvent(x,y, TheState,aView);
500 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
501 myOffsetDlg->UpdateValues();
502}
503
504//-----------------------------------------------------------------------------------------
505//
506//-----------------------------------------------------------------------------------------
507void CViewer3dDoc::InputEvent(const Standard_Integer x ,
508 const Standard_Integer y ,
509 const Handle(V3d_View)& aView )
510{
5c1f974e 511 if (myOffsetDlg && myOffsetDlg->IsWindowVisible())
512 myOffsetDlg->UpdateValues();
7fd59977 513
5c1f974e 514 Quantity_Color CSFColor;
515 COLORREF MSColor;
516 myAISContext->Select();
7fd59977 517
5c1f974e 518 // Change the color of a selected face in a user cylinder
519 if (myState == FACE_COLOR)
520 {
521 myAISContext->InitSelected();
522 if (myAISContext->MoreSelected())
523 {
524 Handle_AIS_InteractiveObject Current = myAISContext->SelectedInteractive();
525 if (Current->HasColor())
526 {
527 CSFColor = myAISContext->Color (Current);
528 MSColor = RGB (CSFColor.Red()*255.0, CSFColor.Green()*255.0, CSFColor.Blue()*255.0);
529 }
530 else
531 {
532 MSColor = RGB (255, 255, 255);
533 }
534
535 CColorDialog dlgColor(MSColor);
536 if (dlgColor.DoModal() == IDOK)
537 {
538 MSColor = dlgColor.GetColor();
539 CSFColor = Quantity_Color (GetRValue (MSColor)/255.0,
540 GetGValue (MSColor)/255.0,
541 GetBValue (MSColor)/255.0,
542 Quantity_TOC_RGB);
543
544 TopoDS_Shape S = myAISContext->SelectedShape();
545 Handle(Geom_Surface) Surface = BRep_Tool::Surface (TopoDS::Face(S));
546 if (Surface->IsKind (STANDARD_TYPE (Geom_Plane)))
547 {
548 Handle(User_Cylinder)::DownCast (myAISContext->SelectedInteractive())
549 ->SetPlanarFaceColor (CSFColor.Name());
550 }
551 else
552 {
553 Handle(User_Cylinder)::DownCast (myAISContext->SelectedInteractive())
554 ->SetCylindricalFaceColor (CSFColor.Name());
555 }
556
557 myAISContext->Redisplay (myAISContext->SelectedInteractive());
558 myState = -1;
559 myAISContext->CloseLocalContext();
560 }
561 }
562
563 TCollection_AsciiString aMessage (" TopoDS_Shape S = myAISContext->SelectedShape(); \n"
564 " \n"
565 " Handle(Geom_Surface) Surface = BRep_Tool::Surface(TopoDS::Face(S));"
566 " if (Surface->IsKind(STANDARD_TYPE(Geom_Plane))) \n"
567 " Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetPlanarFaceColor(CSFColor.Name()); \n"
568 " else \n"
569 " Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetCylindricalFaceColor(CSFColor.Name()); \n"
570 " \n"
571 " myAISContext->Redisplay(myAISContext->Current()); \n"
572 " \n"
573 " myAISContext->CloseLocalContext(); \n"
574 " \n"
575 " \n"
576 " NOTE: a User_Cylinder is an object defined by the user. \n"
577 " The User_Cylinder class inherit from the AIS_InteractiveObject \n"
578 " Cascade class, it's use is the same as an AIS_InteractiveObject. \n"
579 " Methods SetPlanarFaceColor and SetCylindricalFaceColor are also \n"
580 " defined in the User_Cylinder class. \n"
581 " \n");
582
583 CString aMsgStr (aMessage.ToCString());
584 myCResultDialog.SetTitle (CString ("Change face color"));
585 myCResultDialog.SetText (aMsgStr);
586 SetTitle (CString ("Change face color"));
587 }
588}
7fd59977 589
590//-----------------------------------------------------------------------------------------
591//
592//-----------------------------------------------------------------------------------------
593void CViewer3dDoc::ShiftDragEvent(const Standard_Integer x ,
594 const Standard_Integer y ,
595 const Standard_Integer TheState ,
596 const Handle(V3d_View)& aView )
597{
5c1f974e 598 OCC_3dBaseDoc::ShiftDragEvent(x,y,TheState,aView);
599 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
600 myOffsetDlg->UpdateValues();
7fd59977 601}
602
603
604//-----------------------------------------------------------------------------------------
605//
606//-----------------------------------------------------------------------------------------
607
608void CViewer3dDoc::ShiftInputEvent(const Standard_Integer x ,
609 const Standard_Integer y ,
610 const Handle(V3d_View)& aView )
611{
5c1f974e 612 OCC_3dBaseDoc::ShiftInputEvent(x,y,aView);
613 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
614 myOffsetDlg->UpdateValues();
7fd59977 615}
616
617void CViewer3dDoc::OnObjectColoredMesh()
618{
619 for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->NextCurrent())
5c1f974e 620 if (myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
621 {
622 myAISContext->ClearPrs(myAISContext->Current(),6,Standard_False);
623 myAISContext->RecomputePrsOnly(myAISContext->Current(),Standard_False);
624 myAISContext->SetDisplayMode(myAISContext->Current(),6);
625 }
7fd59977 626}
627
628void CViewer3dDoc::OnUpdateObjectColoredMesh(CCmdUI* pCmdUI)
629{
630 bool CylinderIsCurrentAndDisplayed = false;
631 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
7fd59977 632 if(myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
633 CylinderIsCurrentAndDisplayed=true;
634 pCmdUI->Enable (CylinderIsCurrentAndDisplayed);
7fd59977 635}
636
637void CViewer3dDoc::OnUpdateObjectWireframe(CCmdUI* pCmdUI)
638{
639 bool OneOrMoreInShadingOrColoredMesh = false;
640 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
641 if (myAISContext->IsDisplayed(myAISContext->Current(),1) || myAISContext->IsDisplayed(myAISContext->Current(),6))
642 OneOrMoreInShadingOrColoredMesh=true;
643 pCmdUI->Enable (OneOrMoreInShadingOrColoredMesh);
644}
645
646
647void CViewer3dDoc::OnUpdateObjectShading(CCmdUI* pCmdUI)
648{
649 bool OneOrMoreInWireframeOrColoredMesh = false;
650 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
651 if (myAISContext->IsDisplayed(myAISContext->Current(),0) || myAISContext->IsDisplayed(myAISContext->Current(),6))
652 OneOrMoreInWireframeOrColoredMesh=true;
653 pCmdUI->Enable (OneOrMoreInWireframeOrColoredMesh);
654}
655
656
657void CViewer3dDoc::OnOptionsTrihedronDynamicTrihedron()
658{
659 if (myAISContext -> IsDisplayed(myTrihedron))
660 {
661 myAISContext->Remove(myTrihedron);
662 }
663 else
664 {
665 Handle(Geom_Axis2Placement) myTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
666 myTrihedron=new AIS_Trihedron(myTrihedronAxis);
667 myAISContext->SetTrihedronSize(200, Standard_True);
668 myAISContext->Display(myTrihedron);
669 }
670}
671
672void CViewer3dDoc::OnUpdateOptionsTrihedronDynamicTrihedron(CCmdUI* pCmdUI)
673{
674 if (myAISContext->IsDisplayed(myTrihedron))
675 pCmdUI->SetCheck(1);
676 else
677 pCmdUI->SetCheck(0);
678}
679
680void CViewer3dDoc::SetMyStaticTrihedronAxisIsDisplayed(BOOL IsDisplayed)
681{
682 myStaticTrihedronAxisIsDisplayed = IsDisplayed;
683}
684
685void CViewer3dDoc::OnUpdateOptionsTrihedronStaticTrihedron(CCmdUI* pCmdUI)
686{
687 if (myStaticTrihedronAxisIsDisplayed)
688 pCmdUI->SetCheck(1);
689 else
690 pCmdUI->SetCheck(0);
691
692}
693
a6eb515f 694void CViewer3dDoc::Popup (const Standard_Integer x,
695 const Standard_Integer y ,
696 const Handle(V3d_View)& aView)
7fd59977 697{
a6eb515f 698 myPopupMenuNumber=0;
699 // Specified check for context menu number to call
700 myAISContext->InitCurrent();
701 if (myAISContext->MoreCurrent())
7fd59977 702 {
a6eb515f 703 if (myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
704 {
705 myPopupMenuNumber = 2;
706 //return;
707 }
708 }
709 OCC_3dBaseDoc::Popup(x,y, aView);
7fd59977 710}
5c1f974e 711
7fd59977 712//Set faces selection mode
713void CViewer3dDoc::OnFaces()
714{
5c1f974e 715 myAISContext->CloseAllContexts();
716 myAISContext->OpenLocalContext();
717 myAISContext->ActivateStandardMode (TopAbs_FACE);
7fd59977 718
5c1f974e 719 TCollection_AsciiString aMessage (" myAISContext->OpenLocalContext(); \n"
720 " \n"
721 " myAISContext->ActivateStandardMode(TopAbs_FACE); \n"
722 " \n");
7fd59977 723
5c1f974e 724 CString aMsgStr (aMessage.ToCString());
725 myCResultDialog.SetTitle (CString("Standard mode: TopAbs_FACE"));
726 myCResultDialog.SetText (aMsgStr);
727 SetTitle (CString ("Standard mode: TopAbs_FACE"));
7fd59977 728}
729
730//Set edges selection mode
731void CViewer3dDoc::OnEdges()
732{
5c1f974e 733 myAISContext->CloseAllContexts();
734 myAISContext->OpenLocalContext();
735 myAISContext->ActivateStandardMode(TopAbs_EDGE);
7fd59977 736
5c1f974e 737 TCollection_AsciiString aMessage (" myAISContext->OpenLocalContext(); \n"
738 " \n"
739 " myAISContext->ActivateStandardMode(TopAbs_EDGE); \n"
740 " \n");
7fd59977 741
5c1f974e 742 CString aMsgStr (aMessage.ToCString());
743 myCResultDialog.SetTitle (CString ("Standard mode: TopAbs_EDGE"));
744 myCResultDialog.SetText (aMsgStr);
745 SetTitle (CString ("Standard mode: TopAbs_EDGE"));
7fd59977 746}
747
748// Set vertices selection mode
749void CViewer3dDoc::OnVertices()
750{
5c1f974e 751 myAISContext->CloseAllContexts();
752 myAISContext->OpenLocalContext();
753 myAISContext->ActivateStandardMode (TopAbs_VERTEX);
7fd59977 754
5c1f974e 755 TCollection_AsciiString aMessage (" myAISContext->OpenLocalContext(); \n"
756 " \n"
757 " myAISContext->ActivateStandardMode(TopAbs_VERTEX); \n"
758 " \n");
7fd59977 759
5c1f974e 760 CString aMsgStr (aMessage.ToCString());
761 myCResultDialog.SetTitle (CString ("Standard mode: TopAbs_VERTEX"));
762 myCResultDialog.SetText (aMsgStr);
763 SetTitle (CString ("Standard mode: TopAbs_VERTEX"));
7fd59977 764}
765
766//Neutral selection mode
767void CViewer3dDoc::OnNeutral()
768{
5c1f974e 769 myAISContext->CloseAllContexts();
7fd59977 770
5c1f974e 771 TCollection_AsciiString aMessage (" myAISContext->CloseAllContexts(); \n"
772 " \n");
7fd59977 773
5c1f974e 774 CString aMsgStr (aMessage.ToCString());
775 myCResultDialog.SetTitle (CString ("Standard mode: Neutral"));
776 myCResultDialog.SetText (aMsgStr);
777 SetTitle (CString ("Standard mode: Neutral"));
7fd59977 778}
779
780// Change the color of faces on a user cylinder
781void CViewer3dDoc::OnUsercylinderChangefacecolor()
782{
5c1f974e 783 myAISContext->OpenLocalContext();
784 myAISContext->Activate(myAISContext->Current(),4);
785 myState = FACE_COLOR;
786 // see the following of treatment in inputevent
7fd59977 787}
788
789// Make 3d fillets on solids
790// It is necessary to activate the edges selection mode and select edges on an object
791// before running this function
792void CViewer3dDoc::OnFillet3d()
793{
5c1f974e 794 if (!myAISContext->HasOpenedContext())
795 {
796 AfxMessageBox("It is necessary to activate the edges selection mode\n"
797 "and select edges on an object before \nrunning this function");
798 return;
799 }
800
801 myAISContext->InitSelected();
802 if (myAISContext->MoreSelected())
803 {
804 Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast (myAISContext->SelectedInteractive());
805
806 if (S.IsNull())
807 {
808 AfxMessageBox("It is necessary to activate the edges selection mode\n"
809 "and select edges on an object before \nrunning this function");
810 return;
811 }
812
813 TopoDS_Shape Sh=S->Shape();
814
815 BRepFilletAPI_MakeFillet aFillet(Sh);
816
817 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
7fd59977 818 {
5c1f974e 819 TopoDS_Shape aSelShape = myAISContext->SelectedShape();
820 if (aSelShape.ShapeType() != TopAbs_EDGE)
821 {
7fd59977 822 AfxMessageBox("It is necessary to activate the edges selection mode\n\
5c1f974e 823 and select edges on an object before \nrunning this function");
7fd59977 824 return;
5c1f974e 825 }
7fd59977 826 }
7fd59977 827
5c1f974e 828 BoxRadius dlg(NULL,10.);
829 if (dlg.DoModal() == IDOK)
830 {
831 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
832 {
833 TopoDS_Edge anEdge = TopoDS::Edge(myAISContext->SelectedShape());
834 aFillet.Add(dlg.m_radius,anEdge);
835 }
836 }
837 else
838 {
839 return;
840 }
841
842 TopoDS_Shape aNewShape;
843 try
844 {
845 aNewShape = aFillet.Shape();
846 }
847 catch (Standard_Failure)
848 {
849 AfxMessageBox("Error During Fillet computation");
850 return;
851 }
852
853 S ->Set (aNewShape);
854 myAISContext->Redisplay (S);
855 }
856
857 TCollection_AsciiString aMessage (" Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast(myAISContext->Interactive()); \n"
858 " \n"
859 " BRepAPI_MakeFillet aFillet(S->Shape()); \n"
860 " \n"
861 " TopoDS_Edge anEdge=TopoDS::Edge(myAISContext->SelectedShape()); \n"
862 " \n"
863 " aFillet.Add(dlg.m_radius,anEdge); \n"
864 " \n"
865 " TopoDS_Shape aNewShape = aFillet.Shape(); \n"
866 " \n"
867 " S->Set(aNewShape); \n"
868 " \n"
869 " myAISContext->Redisplay(S); \n"
870 " \n");
871
872 CString aMsgStr (aMessage.ToCString());
873 myCResultDialog.SetTitle (CString ("Make a fillet"));
874 myCResultDialog.SetText (aMsgStr);
875 SetTitle (CString ("Make a fillet"));
7fd59977 876}
5c1f974e 877
7fd59977 878// Create and display a circle with standard tools
879void CViewer3dDoc::OnCircle()
880{
5c1f974e 881 gp_Ax2 anAx2 (gp_Pnt (0., 0., 0.), gp_Dir(0., 0., -1.));
882 Handle(Geom_Circle) aGeomCircle = new Geom_Circle (anAx2, 300);
7fd59977 883
5c1f974e 884 // the lines above substitute
885 // GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.));
886 // Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value());
887
888 Handle(AIS_Circle) anAISCirc = new AIS_Circle(aGeomCircle);
889 myAISContext->Display (anAISCirc);
7fd59977 890
5c1f974e 891 TCollection_AsciiString aMessage (" GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.)); \n"
892 " \n"
893 " Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value()); \n"
894 " \n"
895 " myAISContext->Display(anAISCirc); \n"
896 " \n");
897
898 CString aMsgStr (aMessage.ToCString());
899 myCResultDialog.SetTitle (CString ("Create a circle"));
900 myCResultDialog.SetText (aMsgStr);
901 SetTitle (CString ("Create a circle"));
7fd59977 902}
903
904void CViewer3dDoc::OnLine()
905{
5c1f974e 906 // TODO: Add your command handler code here
907 gp_Lin aGpLin (gp_Pnt (0., 0., 0.), gp_Dir(1., 0., 0.));
908 Handle(Geom_Line) aGeomLin = new Geom_Line (aGpLin);
909 Handle(AIS_Line) anAISLine = new AIS_Line (aGeomLin);
910 myAISContext->Display (anAISLine);
7fd59977 911
5c1f974e 912 TCollection_AsciiString aMessage (" gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.)); \n"
913 " \n"
914 " Handle(Geom_Line) aLine = new Geom_Line(L); \n"
915 " \n"
916 " Handle(AIS_Line) anAISLine = new AIS_Line(aLine); \n"
917 " \n"
918 " myAISContext->Display(anAISLine); \n"
919 " \n");
7fd59977 920
5c1f974e 921 CString aMsgStr (aMessage.ToCString());
922 myCResultDialog.SetTitle (CString("Create a line"));
923 myCResultDialog.SetText (aMsgStr);
924 SetTitle (CString ("Create a line"));
7fd59977 925}
926
927void CViewer3dDoc::OnNbisos()
928{
5c1f974e 929 int aNumU = myAISContext->DefaultDrawer()->UIsoAspect()->Number();
930 int aNumV = myAISContext->DefaultDrawer()->VIsoAspect()->Number();
7fd59977 931
5c1f974e 932 DlgIsos aDlg (NULL, aNumU, aNumV);
7fd59977 933
5c1f974e 934 if (aDlg.DoModal() == IDOK)
935 {
936 myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber (aDlg.m_isou);
937 myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber (aDlg.m_isov);
938
939 TCollection_AsciiString aMessage (" myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(dlg.m_isou); \n"
940 " \n"
941 " myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(dlg.m_isov); \n"
942 " \n");
943
944 CString aMsgStr (aMessage.ToCString());
945 myCResultDialog.SetTitle (CString("Iso Aspect"));
946 myCResultDialog.SetText (aMsgStr);
947 SetTitle (CString ("Iso Aspect"));
948 }
7fd59977 949}
950
951BOOL CViewer3dDoc::OnNewDocument()
952{
5c1f974e 953 if (!CDocument::OnNewDocument())
954 return FALSE;
7fd59977 955
5c1f974e 956 // TODO: add reinitialization code here
957 // (SDI documents will reuse this document)
7fd59977 958 SetTitle(myPresentation->GetName());
959
eb4320f2 960 myAISContext->EraseAll();
7fd59977 961 myAISContext->SetDisplayMode(AIS_Shaded);
962
963 POSITION pos = GetFirstViewPosition();
964 while (pos != NULL)
965 {
966 CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
967 pView->Reset();
968 }
969
5c1f974e 970 return TRUE;
7fd59977 971}
972
973void CViewer3dDoc::OnFileNew()
974{
975 OnNewDocument();
976}
977
978void CViewer3dDoc::InitViewButtons()
979{
980 POSITION pos = GetFirstViewPosition();
981 while (pos != NULL)
982 {
983 CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
984 pView->InitButtons();
985 }
986}
987
988void CViewer3dDoc::OnTextureOn()
989{
990 isTextureSampleStarted = TRUE;
991 Start();
992}
993
994void CViewer3dDoc::DoSample()
995{
996 InitViewButtons();
997
998 HCURSOR hOldCursor = ::GetCursor();
999 HCURSOR hNewCursor = AfxGetApp()->LoadStandardCursor(IDC_APPSTARTING);
1000
1001 SetCursor(hNewCursor);
1002 {
1003 try
1004 {
1005 myPresentation->DoSample();
1006 }
1007 catch (Standard_Failure)
1008 {
1009 Standard_SStream aSStream;
1010 aSStream << "An exception was caught: " << Standard_Failure::Caught() << ends;
1011 Standard_CString aMsg = aSStream.str().c_str();
5c1f974e 1012 // aSStream.rdbuf()->freeze(0); // allow deletion of dynamic array
7fd59977 1013 AfxMessageBox (aMsg);
1014 }
1015 }
1016 SetCursor(hOldCursor);
1017}
1018
1019void CViewer3dDoc::OnBUTTONStart()
1020{
eb4320f2 1021 myAISContext->EraseAll();
7fd59977 1022 myPresentation->FirstSample();
1023 DoSample();
1024}
1025
1026void CViewer3dDoc::OnBUTTONEnd()
1027{
eb4320f2 1028 myAISContext->EraseAll();
7fd59977 1029 myPresentation->LastSample();
1030 DoSample();
1031}
1032
1033void CViewer3dDoc::OnBUTTONRepeat()
1034{
1035 DoSample();
1036}
1037
1038void CViewer3dDoc::OnBUTTONNext()
1039{
1040 if (!myPresentation->AtLastSample())
1041 {
1042 myPresentation->NextSample();
1043 DoSample();
1044 }
1045}
1046
1047void CViewer3dDoc::OnBUTTONPrev()
1048{
1049 if (!myPresentation->AtFirstSample())
1050 {
1051 myPresentation->PrevSample();
1052 DoSample();
1053 }
1054}
1055
1056void CViewer3dDoc::OnUpdateBUTTONNext(CCmdUI* pCmdUI)
1057{
1058 if ( isTextureSampleStarted )
1059 pCmdUI->Enable (!myPresentation->AtLastSample());
1060 else
1061 pCmdUI->Enable (FALSE);
1062}
1063
1064void CViewer3dDoc::OnUpdateBUTTONPrev(CCmdUI* pCmdUI)
1065{
1066 if ( isTextureSampleStarted )
1067 pCmdUI->Enable (!myPresentation->AtFirstSample());
1068 else
1069 pCmdUI->Enable (FALSE);
1070}
1071
1072void CViewer3dDoc::OnUpdateBUTTONStart(CCmdUI* pCmdUI)
1073{
1074 pCmdUI->Enable (isTextureSampleStarted);
1075}
1076
1077void CViewer3dDoc::OnUpdateBUTTONRepeat(CCmdUI* pCmdUI)
1078{
1079 pCmdUI->Enable (isTextureSampleStarted);
1080}
1081
1082void CViewer3dDoc::OnUpdateBUTTONEnd(CCmdUI* pCmdUI)
1083{
1084 pCmdUI->Enable (isTextureSampleStarted);
1085}
1086
1087void CViewer3dDoc::OnDumpView()
1088{
5c1f974e 1089 CFileDialog aDlg (false, "gif", "OCCView.gif", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
1090 "GIF Files (*.GIF)|*.gif|"
1091 "BMP Files (*.BMP)|*.bmp|"
1092 "PNG Files (*.PNG)|*.png|"
1093 "JPEG Files (*.JPG)|*.jpg|"
1094 "PPM Files (*.PPM)|*.ppm|"
1095 "TIFF Files (*.TIFF)|*.tiff|"
1096 "TGA Files (*.TGA)|*.tga|"
1097 "EXR Files (*.EXR)|*.exr||", NULL);
1098 if (aDlg.DoModal() != IDOK)
7fd59977 1099 {
5c1f974e 1100 return;
1101 }
7fd59977 1102
5c1f974e 1103 for (POSITION aPos = GetFirstViewPosition(); aPos != NULL;)
1104 {
1105 CViewer3dView* pView = (CViewer3dView* )GetNextView (aPos);
1106 pView->UpdateWindow();
7fd59977 1107 }
5c1f974e 1108 myViewer->InitActiveViews();
1109 Handle(V3d_View) aView = myViewer->ActiveView();
1110 aView->Dump (aDlg.GetPathName());
7fd59977 1111}
1112
1113void CViewer3dDoc::Start()
1114{
1115 myPresentation->Init();
1116 OnBUTTONStart();
1117}
1118
1119void CViewer3dDoc::Fit()
1120{
1121 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
1122 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
1123 CViewer3dView *pView = (CViewer3dView *) pChild->GetActiveView();
1124 pView->FitAll();
1125}