1 // Viewer3dDoc.cpp : implementation of the CViewer3dDoc class
5 #include "Viewer3dApp.h"
9 #include "Viewer3dDoc.h"
10 #include "Viewer3dView.h"
11 #include "OffsetDlg.h"
12 #include "ResultDialog.h"
13 #include "User_Cylinder.hxx"
15 #include "AIS_Trihedron.hxx"
16 #include "Geom_Axis2Placement.hxx"
18 /////////////////////////////////////////////////////////////////////////////
21 IMPLEMENT_DYNCREATE(CViewer3dDoc, CDocument)
23 BEGIN_MESSAGE_MAP(CViewer3dDoc, OCC_3dDoc)
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)
76 /////////////////////////////////////////////////////////////////////////////
77 // CViewer3dDoc construction/destruction
79 CViewer3dDoc::CViewer3dDoc()
85 myOverlappedCylinder.Nullify();
86 myOverlappedSphere.Nullify();
87 myOverlappedBox.Nullify();
89 myStaticTrihedronAxisIsDisplayed = FALSE;
92 isTextureSampleStarted = FALSE;
94 myPresentation = OCCDemo_Presentation::Current;
95 myPresentation->SetDocument(this);
98 myAISContext->DefaultDrawer()->ShadingAspect()->SetColor(Quantity_NOC_CHARTREUSE1);
99 myAISContext->DefaultDrawer()->ShadingAspect()->SetMaterial(Graphic3d_NOM_SILVER);
101 strcpy_s(myDataDir, "Data");
102 strcpy_s(myLastPath, ".");
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);
112 CViewer3dDoc::~CViewer3dDoc()
116 /////////////////////////////////////////////////////////////////////////////
117 // CViewer3dDoc diagnostics
120 void CViewer3dDoc::AssertValid() const
122 CDocument::AssertValid();
125 void CViewer3dDoc::Dump(CDumpContext& dc) const
131 /////////////////////////////////////////////////////////////////////////////
132 // CViewer3dDoc commands
134 void CViewer3dDoc::UpdateResultMessageDlg (CString theTitle, const TCollection_AsciiString& theMessage)
136 CString aText (theMessage.ToCString());
137 myCResultDialog.SetText (aText);
138 myCResultDialog.SetTitle(theTitle);
141 void CViewer3dDoc::UpdateResultMessageDlg(CString theTitle, CString theMessage)
143 myCResultDialog.SetText (theMessage);
144 myCResultDialog.SetTitle(theTitle);
147 void CViewer3dDoc::OnBox()
151 BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
154 myBox = new AIS_Shape(B.Shape());
156 myAISContext->SetMaterial(myBox,Graphic3d_NOM_PEWTER);
157 myAISContext->SetDisplayMode(myBox,1);
159 myAISContext->Display(myBox);
160 TCollection_AsciiString Message("\
161 BRepPrimAPI_MakeBox Box1(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
164 UpdateResultMessageDlg("Create Box",Message);
168 void CViewer3dDoc::OnCylinder()
170 if(myCylinder.IsNull())
172 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
173 myCylinder = new User_Cylinder(CylAx2, 80.,200.);
175 myAISContext->SetDisplayMode(myCylinder,1);
177 myAISContext->Display(myCylinder);
179 TCollection_AsciiString Message("\
180 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));\n\
181 C = new User_Cylinder(CylAx2, 80.,200.);;\n\
184 UpdateResultMessageDlg("Create Cylinder",Message);
188 void CViewer3dDoc::OnSphere()
190 if(mySphere.IsNull())
192 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
194 mySphere = new AIS_Shape(S.Shape());
196 myAISContext->SetMaterial(mySphere,Graphic3d_NOM_BRONZE);
197 myAISContext->SetDisplayMode(mySphere,1);
199 myAISContext->Display(mySphere);
200 TCollection_AsciiString Message("\
201 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);\n\
203 UpdateResultMessageDlg("Create Sphere",Message);
207 void CViewer3dDoc::OnRemoveAll()
210 AIS_ListOfInteractive aListOfObjects;
211 myAISContext->ObjectsInside(aListOfObjects,AIS_KOI_Shape);
213 AIS_ListIteratorOfListOfInteractive aListIterator;
214 for(aListIterator.Initialize(aListOfObjects);aListIterator.More();aListIterator.Next()){
215 myAISContext->Remove(aListIterator.Value());
218 myAISContext->Remove(myCylinder);
221 myCylinder.Nullify();
224 myOverlappedCylinder.Nullify();
225 myOverlappedSphere.Nullify();
226 myOverlappedBox.Nullify();
227 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
228 myOffsetDlg->UpdateValues();
231 void CViewer3dDoc::OnOverlappedBox()
234 if(myOverlappedBox.IsNull()){
235 BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
237 BRepBuilderAPI_NurbsConvert aNurbsConvert(B.Shape());
238 TopoDS_Shape aBoxShape2 = aNurbsConvert.Shape();
241 myOverlappedBox = new AIS_Shape(aBoxShape2);
243 myAISContext->SetMaterial(myOverlappedBox,Graphic3d_NOM_GOLD);
244 myAISContext->SetDisplayMode(myOverlappedBox,1);
246 myAISContext->Display(myOverlappedBox);
247 TCollection_AsciiString Message("\
248 BRepPrimAPI_MakeBox Box1(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
250 BRepPrimAPI_MakeBox Box2(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
251 BRepBuilderAPI_NurbsConvert aNurbsConvert(Box2.Shape());\n\
253 UpdateResultMessageDlg("Create overlapped boxes",Message);
254 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
255 myOffsetDlg->UpdateValues();
259 void CViewer3dDoc::OnOverlappedCylinder()
263 if(myOverlappedCylinder.IsNull()){
264 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
265 BRepPrimAPI_MakeCylinder C(CylAx2, 80.,200.);
267 BRepBuilderAPI_NurbsConvert aNurbsConvert(C.Shape());
268 TopoDS_Shape aCylShape2 = aNurbsConvert.Shape();
270 myOverlappedCylinder = new AIS_Shape(aCylShape2);
273 myAISContext->SetMaterial(myOverlappedCylinder,Graphic3d_NOM_GOLD);
274 myAISContext->SetDisplayMode(myOverlappedCylinder,1);
276 myAISContext->Display(myOverlappedCylinder);
278 TCollection_AsciiString Message("\
279 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));\n\
280 Cylinder1 = new User_Cylinder(CylAx2, 80.,200.);\n\
282 BRepPrimAPI_MakeCylinder Cylinder2(CylAx2, 80.,200.);\n\
283 BRepBuilderAPI_NurbsConvert aNurbsConvert(Cylinder2.Shape());\n\
285 UpdateResultMessageDlg("Create overlapped cylinders",Message);
286 if (myOffsetDlg && myOffsetDlg->IsWindowVisible())
288 myOffsetDlg->UpdateValues();
293 void CViewer3dDoc::OnOverlappedSphere()
296 if(myOverlappedSphere.IsNull()){
297 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
299 BRepBuilderAPI_NurbsConvert aNurbsConvert(S.Shape());
300 TopoDS_Shape aSphereShape2 = aNurbsConvert.Shape();
302 myOverlappedSphere = new AIS_Shape(aSphereShape2);
304 myAISContext->SetMaterial(myOverlappedSphere,Graphic3d_NOM_GOLD);
306 myAISContext->SetDisplayMode(myOverlappedSphere,1);
308 myAISContext->Display(myOverlappedSphere);
310 TCollection_AsciiString Message("\
311 BRepPrimAPI_MakeSphere Sphere1(gp_Pnt(0,300,0), 100.);\n\
313 BRepPrimAPI_MakeSphere Sphere2(gp_Pnt(0,300,0), 100.);\n\
314 BRepBuilderAPI_NurbsConvert aNurbsConvert(Sphere2.Shape());\n\
316 UpdateResultMessageDlg("Create overlapped spheres",Message);
317 if (myOffsetDlg && myOffsetDlg->IsWindowVisible())
319 myOffsetDlg->UpdateValues();
324 void CViewer3dDoc::OnPolygonOffsets()
326 myOffsetDlg = new COffsetDlg(this);
327 myOffsetDlg->Create(COffsetDlg::IDD,NULL);
328 myAISContext->UpdateCurrentViewer();
331 void CViewer3dDoc::OnUpdatePolygonOffsets(CCmdUI* pCmdUI)
333 Standard_Integer aOffsetMode;
334 Standard_ShortReal aFactor;
335 Standard_ShortReal aCylUnits = 0;
336 Standard_ShortReal aSphereUnits = 0;
337 Standard_ShortReal aBoxUnits = 0;
339 BOOL IsOverlappedCylinderDisplayed = myAISContext->IsDisplayed(myOverlappedCylinder);
340 BOOL IsOverlappedSphereDisplayed = myAISContext->IsDisplayed(myOverlappedSphere);
341 BOOL IsOverlappedBoxDisplayed = myAISContext->IsDisplayed(myOverlappedBox);
342 BOOL IsAnyOverlappedObjectDisplayed =
343 IsOverlappedCylinderDisplayed || IsOverlappedSphereDisplayed || IsOverlappedBoxDisplayed;
345 if(!myOverlappedCylinder.IsNull() && IsOverlappedCylinderDisplayed){
346 myOverlappedCylinder->PolygonOffsets(aOffsetMode,aFactor,aCylUnits);
349 if(!myOverlappedSphere.IsNull() && IsOverlappedSphereDisplayed){
350 myOverlappedSphere->PolygonOffsets(aOffsetMode,aFactor,aSphereUnits);
353 if(!myOverlappedBox.IsNull() && IsOverlappedBoxDisplayed){
354 myOverlappedBox->PolygonOffsets(aOffsetMode,aFactor,aBoxUnits);
357 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
358 pCmdUI->SetCheck(TRUE);
360 pCmdUI->SetCheck(FALSE);
361 if (IsAnyOverlappedObjectDisplayed)
363 pCmdUI->Enable(!myOffsetDlg->IsWindowVisible());
365 pCmdUI->Enable(TRUE);
367 pCmdUI->Enable(FALSE);
370 void CViewer3dDoc::OnUpdateCylinder(CCmdUI* pCmdUI)
372 pCmdUI->Enable(myCylinder.IsNull());
375 void CViewer3dDoc::OnUpdateSphere(CCmdUI* pCmdUI)
377 pCmdUI->Enable(mySphere.IsNull());
380 void CViewer3dDoc::OnUpdateBox(CCmdUI* pCmdUI)
382 pCmdUI->Enable(myBox.IsNull());
385 void CViewer3dDoc::OnUpdateOverlappedCylinder(CCmdUI* pCmdUI)
387 pCmdUI->Enable (myOverlappedCylinder.IsNull()
388 || myCylinder.IsNull());
392 void CViewer3dDoc::OnUpdateOverlappedSphere(CCmdUI* pCmdUI)
394 pCmdUI->Enable (myOverlappedSphere.IsNull()
395 || mySphere.IsNull());
398 void CViewer3dDoc::OnUpdateOverlappedBox(CCmdUI* pCmdUI)
400 pCmdUI->Enable (myOverlappedBox.IsNull()
404 void CViewer3dDoc::OnObjectRemove()
406 if(myAISContext->IsCurrent(myBox))
409 if(myAISContext->IsCurrent(myCylinder))
410 myCylinder.Nullify();
412 if(myAISContext->IsCurrent(mySphere))
415 if(myAISContext->IsCurrent(myOverlappedBox))
416 myOverlappedBox.Nullify();
418 if(myAISContext->IsCurrent(myOverlappedCylinder))
419 myOverlappedCylinder.Nullify();
421 if(myAISContext->IsCurrent(myOverlappedSphere))
422 myOverlappedSphere.Nullify();
425 for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->InitCurrent())
426 myAISContext->Remove(myAISContext->Current(),Standard_True);
428 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
429 myOffsetDlg->UpdateValues();
432 void CViewer3dDoc::OnObjectErase()
435 OCC_3dBaseDoc::OnObjectErase();
436 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
437 myOffsetDlg->UpdateValues();
440 void CViewer3dDoc::OnObjectDisplayall()
443 OCC_3dBaseDoc::OnObjectDisplayall();
444 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
445 myOffsetDlg->UpdateValues();
448 Handle(User_Cylinder) CViewer3dDoc::GetCylinder()
454 Handle(AIS_Shape) CViewer3dDoc::GetSphere()
459 Handle(AIS_Shape) CViewer3dDoc::GetBox()
464 Handle(AIS_Shape) CViewer3dDoc::GetOverlappedCylinder()
466 return myOverlappedCylinder;
470 Handle(AIS_Shape) CViewer3dDoc::GetOverlappedSphere()
472 return myOverlappedSphere;
475 Handle(AIS_Shape) CViewer3dDoc::GetOverlappedBox()
477 return myOverlappedBox;
480 void CViewer3dDoc::DragEvent (const Standard_Integer theX,
481 const Standard_Integer theY,
482 const Standard_Integer theState,
483 const Handle(V3d_View)& theView)
485 OCC_3dBaseDoc::DragEvent (theX, theY, theState, theView);
486 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
487 myOffsetDlg->UpdateValues();
490 //-----------------------------------------------------------------------------------------
492 //-----------------------------------------------------------------------------------------
493 void CViewer3dDoc::InputEvent(const Standard_Integer /*x*/,
494 const Standard_Integer /*y*/,
495 const Handle(V3d_View)& /*aView*/ )
497 if (myOffsetDlg && myOffsetDlg->IsWindowVisible())
498 myOffsetDlg->UpdateValues();
500 Quantity_Color CSFColor;
502 myAISContext->Select();
504 // Change the color of a selected face in a user cylinder
505 if (myState == FACE_COLOR)
507 myAISContext->InitSelected();
508 if (myAISContext->MoreSelected())
510 Handle(AIS_InteractiveObject) Current = myAISContext->SelectedInteractive();
511 if (Current->HasColor())
513 CSFColor = myAISContext->Color (Current);
514 MSColor = RGB (CSFColor.Red()*255.0, CSFColor.Green()*255.0, CSFColor.Blue()*255.0);
518 MSColor = RGB (255, 255, 255);
521 CColorDialog dlgColor(MSColor);
522 if (dlgColor.DoModal() == IDOK)
524 MSColor = dlgColor.GetColor();
525 CSFColor = Quantity_Color (GetRValue (MSColor)/255.0,
526 GetGValue (MSColor)/255.0,
527 GetBValue (MSColor)/255.0,
530 TopoDS_Shape S = myAISContext->SelectedShape();
531 Handle(Geom_Surface) Surface = BRep_Tool::Surface (TopoDS::Face(S));
532 if (Surface->IsKind (STANDARD_TYPE (Geom_Plane)))
534 Handle(User_Cylinder)::DownCast (myAISContext->SelectedInteractive())
535 ->SetPlanarFaceColor (CSFColor.Name());
539 Handle(User_Cylinder)::DownCast (myAISContext->SelectedInteractive())
540 ->SetCylindricalFaceColor (CSFColor.Name());
543 myAISContext->Redisplay (myAISContext->SelectedInteractive());
545 myAISContext->CloseLocalContext();
549 myCResultDialog.SetTitle("Change face color");
550 myCResultDialog.SetText(" TopoDS_Shape S = myAISContext->SelectedShape(); \n"
552 " Handle(Geom_Surface) Surface = BRep_Tool::Surface(TopoDS::Face(S));"
553 " if (Surface->IsKind(STANDARD_TYPE(Geom_Plane))) \n"
554 " Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetPlanarFaceColor(CSFColor.Name()); \n"
556 " Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetCylindricalFaceColor(CSFColor.Name()); \n"
558 " myAISContext->Redisplay(myAISContext->Current()); \n"
560 " myAISContext->CloseLocalContext(); \n"
563 " NOTE: a User_Cylinder is an object defined by the user. \n"
564 " The User_Cylinder class inherit from the AIS_InteractiveObject \n"
565 " Cascade class, it's use is the same as an AIS_InteractiveObject. \n"
566 " Methods SetPlanarFaceColor and SetCylindricalFaceColor are also \n"
567 " defined in the User_Cylinder class. \n"
569 SetTitle (L"Change face color");
573 //-----------------------------------------------------------------------------------------
575 //-----------------------------------------------------------------------------------------
576 void CViewer3dDoc::ShiftDragEvent (const Standard_Integer theX,
577 const Standard_Integer theY,
578 const Standard_Integer theState,
579 const Handle(V3d_View)& theView)
581 OCC_3dBaseDoc::ShiftDragEvent(theX, theY, theState, theView);
582 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
583 myOffsetDlg->UpdateValues();
587 //-----------------------------------------------------------------------------------------
589 //-----------------------------------------------------------------------------------------
590 void CViewer3dDoc::ShiftInputEvent (const Standard_Integer theX,
591 const Standard_Integer theY,
592 const Handle(V3d_View)& theView)
594 OCC_3dBaseDoc::ShiftInputEvent (theX, theY, theView);
595 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
596 myOffsetDlg->UpdateValues();
599 void CViewer3dDoc::OnObjectColoredMesh()
601 for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->NextCurrent())
602 if (myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
604 myAISContext->ClearPrs(myAISContext->Current(),6,Standard_False);
605 myAISContext->RecomputePrsOnly(myAISContext->Current(),Standard_False);
606 myAISContext->SetDisplayMode(myAISContext->Current(),6);
610 void CViewer3dDoc::OnUpdateObjectColoredMesh(CCmdUI* pCmdUI)
612 bool CylinderIsCurrentAndDisplayed = false;
613 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
614 if(myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
615 CylinderIsCurrentAndDisplayed=true;
616 pCmdUI->Enable (CylinderIsCurrentAndDisplayed);
619 void CViewer3dDoc::OnUpdateObjectWireframe(CCmdUI* pCmdUI)
621 bool OneOrMoreInShadingOrColoredMesh = false;
622 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
623 if (myAISContext->IsDisplayed(myAISContext->Current(),1) || myAISContext->IsDisplayed(myAISContext->Current(),6))
624 OneOrMoreInShadingOrColoredMesh=true;
625 pCmdUI->Enable (OneOrMoreInShadingOrColoredMesh);
629 void CViewer3dDoc::OnUpdateObjectShading(CCmdUI* pCmdUI)
631 bool OneOrMoreInWireframeOrColoredMesh = false;
632 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
633 if (myAISContext->IsDisplayed(myAISContext->Current(),0) || myAISContext->IsDisplayed(myAISContext->Current(),6))
634 OneOrMoreInWireframeOrColoredMesh=true;
635 pCmdUI->Enable (OneOrMoreInWireframeOrColoredMesh);
638 void CViewer3dDoc::OnOptionsTrihedronDynamicTrihedron()
640 if (myAISContext -> IsDisplayed(myTrihedron))
642 myAISContext->Remove(myTrihedron);
646 Handle(Geom_Axis2Placement) myTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
647 myTrihedron=new AIS_Trihedron(myTrihedronAxis);
648 myAISContext->SetTrihedronSize(200, Standard_True);
649 myAISContext->Display(myTrihedron);
653 void CViewer3dDoc::OnUpdateOptionsTrihedronDynamicTrihedron(CCmdUI* pCmdUI)
655 if (myAISContext->IsDisplayed(myTrihedron))
661 void CViewer3dDoc::SetMyStaticTrihedronAxisIsDisplayed(BOOL IsDisplayed)
663 myStaticTrihedronAxisIsDisplayed = IsDisplayed;
666 void CViewer3dDoc::OnUpdateOptionsTrihedronStaticTrihedron(CCmdUI* pCmdUI)
668 if (myStaticTrihedronAxisIsDisplayed)
675 void CViewer3dDoc::Popup (const Standard_Integer x,
676 const Standard_Integer y ,
677 const Handle(V3d_View)& aView)
680 // Specified check for context menu number to call
681 myAISContext->InitCurrent();
682 if (myAISContext->MoreCurrent())
684 if (myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
686 myPopupMenuNumber = 2;
690 OCC_3dBaseDoc::Popup(x,y, aView);
693 //Set faces selection mode
694 void CViewer3dDoc::OnFaces()
696 myAISContext->CloseAllContexts();
697 myAISContext->OpenLocalContext();
698 myAISContext->ActivateStandardMode (TopAbs_FACE);
700 myCResultDialog.SetTitle("Standard mode: TopAbs_FACE");
701 myCResultDialog.SetText(" myAISContext->OpenLocalContext(); \n"
703 " myAISContext->ActivateStandardMode(TopAbs_FACE); \n"
705 SetTitle (L"Standard mode: TopAbs_FACE");
708 //Set edges selection mode
709 void CViewer3dDoc::OnEdges()
711 myAISContext->CloseAllContexts();
712 myAISContext->OpenLocalContext();
713 myAISContext->ActivateStandardMode(TopAbs_EDGE);
715 myCResultDialog.SetTitle("Standard mode: TopAbs_EDGE");
716 myCResultDialog.SetText(" myAISContext->OpenLocalContext(); \n"
718 " myAISContext->ActivateStandardMode(TopAbs_EDGE); \n"
720 SetTitle (L"Standard mode: TopAbs_EDGE");
723 // Set vertices selection mode
724 void CViewer3dDoc::OnVertices()
726 myAISContext->CloseAllContexts();
727 myAISContext->OpenLocalContext();
728 myAISContext->ActivateStandardMode (TopAbs_VERTEX);
730 myCResultDialog.SetTitle("Standard mode: TopAbs_VERTEX");
731 myCResultDialog.SetText(" myAISContext->OpenLocalContext(); \n"
733 " myAISContext->ActivateStandardMode(TopAbs_VERTEX); \n"
735 SetTitle (L"Standard mode: TopAbs_VERTEX");
738 //Neutral selection mode
739 void CViewer3dDoc::OnNeutral()
741 myAISContext->CloseAllContexts();
743 myCResultDialog.SetTitle("Standard mode: Neutral");
744 myCResultDialog.SetText(" myAISContext->CloseAllContexts(); \n"
746 SetTitle (L"Standard mode: Neutral");
749 // Change the color of faces on a user cylinder
750 void CViewer3dDoc::OnUsercylinderChangefacecolor()
752 myAISContext->OpenLocalContext();
753 myAISContext->Activate(myAISContext->Current(),4);
754 myState = FACE_COLOR;
755 // see the following of treatment in inputevent
758 // Make 3d fillets on solids
759 // It is necessary to activate the edges selection mode and select edges on an object
760 // before running this function
761 void CViewer3dDoc::OnFillet3d()
763 if (!myAISContext->HasOpenedContext())
765 AfxMessageBox (L"It is necessary to activate the edges selection mode\n"
766 L"and select edges on an object before \nrunning this function");
770 myAISContext->InitSelected();
771 if (myAISContext->MoreSelected())
773 Handle(AIS_Shape) aSelInteractive (Handle(AIS_Shape)::DownCast (myAISContext->SelectedInteractive()));
774 if (aSelInteractive.IsNull())
776 AfxMessageBox (L"It is necessary to activate the edges selection mode\n"
777 L"and select edges on an object before \nrunning this function");
781 BRepFilletAPI_MakeFillet aFillet (aSelInteractive->Shape());
783 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
785 const TopoDS_Shape& aSelShape = myAISContext->SelectedShape();
786 if (aSelShape.ShapeType() != TopAbs_EDGE)
788 AfxMessageBox (L"It is necessary to activate the edges selection mode\n"
789 L"and select edges on an object before \nrunning this function");
794 BoxRadius aDialog (NULL,10.);
795 if (aDialog.DoModal() == IDOK)
797 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
799 // Selected shape has its own location, and sub-shapes in the solid shape for fillet building
800 // don't have own locations. Fillet builder needs to know that input edge is just the same one as
801 // some sub-shape in our target solid shape, so no location is to be in input edge for fillet builder.
802 TopoDS_Shape aSelShape = myAISContext->SelectedShape().Located (TopLoc_Location());
803 aFillet.Add (aDialog.m_radius, TopoDS::Edge (aSelShape) );
811 TopoDS_Shape aNewShape;
814 aNewShape = aFillet.Shape();
816 catch (Standard_Failure)
818 AfxMessageBox (L"Error During Fillet computation");
822 aSelInteractive ->Set (aNewShape);
823 myAISContext->Redisplay (aSelInteractive);
826 myCResultDialog.SetTitle("Make a fillet");
827 myCResultDialog.SetText(" Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast(myAISContext->Interactive()); \n"
829 " BRepAPI_MakeFillet aFillet(S->Shape()); \n"
831 " TopoDS_Edge anEdge=TopoDS::Edge(myAISContext->SelectedShape()); \n"
833 " aFillet.Add(dlg.m_radius,anEdge); \n"
835 " TopoDS_Shape aNewShape = aFillet.Shape(); \n"
837 " S->Set(aNewShape); \n"
839 " myAISContext->Redisplay(S); \n"
841 SetTitle (L"Make a fillet");
844 // Create and display a circle with standard tools
845 void CViewer3dDoc::OnCircle()
847 gp_Ax2 anAx2 (gp_Pnt (0., 0., 0.), gp_Dir(0., 0., -1.));
848 Handle(Geom_Circle) aGeomCircle = new Geom_Circle (anAx2, 300);
850 // the lines above substitute
851 // GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.));
852 // Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value());
854 Handle(AIS_Circle) anAISCirc = new AIS_Circle(aGeomCircle);
855 myAISContext->Display (anAISCirc);
857 myCResultDialog.SetTitle("Create a circle");
858 myCResultDialog.SetText(" GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.)); \n"
860 " Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value()); \n"
862 " myAISContext->Display(anAISCirc); \n"
864 SetTitle (L"Create a circle");
867 void CViewer3dDoc::OnLine()
869 // TODO: Add your command handler code here
870 gp_Lin aGpLin (gp_Pnt (0., 0., 0.), gp_Dir(1., 0., 0.));
871 Handle(Geom_Line) aGeomLin = new Geom_Line (aGpLin);
872 Handle(AIS_Line) anAISLine = new AIS_Line (aGeomLin);
873 myAISContext->Display (anAISLine);
875 myCResultDialog.SetTitle("Create a line");
876 myCResultDialog.SetText(" gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.)); \n"
878 " Handle(Geom_Line) aLine = new Geom_Line(L); \n"
880 " Handle(AIS_Line) anAISLine = new AIS_Line(aLine); \n"
882 " myAISContext->Display(anAISLine); \n"
884 SetTitle (L"Create a line");
887 void CViewer3dDoc::OnNbisos()
889 int aNumU = myAISContext->DefaultDrawer()->UIsoAspect()->Number();
890 int aNumV = myAISContext->DefaultDrawer()->VIsoAspect()->Number();
892 DlgIsos aDlg (NULL, aNumU, aNumV);
894 if (aDlg.DoModal() == IDOK)
896 myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber (aDlg.m_isou);
897 myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber (aDlg.m_isov);
899 myCResultDialog.SetTitle("Iso Aspect");
900 myCResultDialog.SetText(" myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(dlg.m_isou); \n"
902 " myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(dlg.m_isov); \n"
904 SetTitle (L"Iso Aspect");
908 BOOL CViewer3dDoc::OnNewDocument()
910 if (!CDocument::OnNewDocument())
913 // TODO: add reinitialization code here
914 // (SDI documents will reuse this document)
915 SetTitle(myPresentation->GetName());
917 myAISContext->EraseAll();
918 myAISContext->SetDisplayMode(AIS_Shaded);
920 POSITION pos = GetFirstViewPosition();
923 CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
930 void CViewer3dDoc::OnFileNew()
935 void CViewer3dDoc::InitViewButtons()
937 POSITION pos = GetFirstViewPosition();
940 CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
941 pView->InitButtons();
945 void CViewer3dDoc::OnTextureOn()
947 isTextureSampleStarted = TRUE;
951 void CViewer3dDoc::DoSample()
955 HCURSOR hOldCursor = ::GetCursor();
956 HCURSOR hNewCursor = AfxGetApp()->LoadStandardCursor(IDC_APPSTARTING);
958 SetCursor(hNewCursor);
962 myPresentation->DoSample();
964 catch (Standard_Failure)
966 Standard_SStream aSStream;
967 aSStream << "An exception was caught: " << Standard_Failure::Caught() << ends;
968 CString aMsg = aSStream.str().c_str();
969 AfxMessageBox (aMsg);
972 SetCursor(hOldCursor);
975 void CViewer3dDoc::OnBUTTONStart()
977 myAISContext->EraseAll();
978 myPresentation->FirstSample();
982 void CViewer3dDoc::OnBUTTONEnd()
984 myAISContext->EraseAll();
985 myPresentation->LastSample();
989 void CViewer3dDoc::OnBUTTONRepeat()
994 void CViewer3dDoc::OnBUTTONNext()
996 if (!myPresentation->AtLastSample())
998 myPresentation->NextSample();
1003 void CViewer3dDoc::OnBUTTONPrev()
1005 if (!myPresentation->AtFirstSample())
1007 myPresentation->PrevSample();
1012 void CViewer3dDoc::OnUpdateBUTTONNext(CCmdUI* pCmdUI)
1014 if ( isTextureSampleStarted )
1015 pCmdUI->Enable (!myPresentation->AtLastSample());
1017 pCmdUI->Enable (FALSE);
1020 void CViewer3dDoc::OnUpdateBUTTONPrev(CCmdUI* pCmdUI)
1022 if ( isTextureSampleStarted )
1023 pCmdUI->Enable (!myPresentation->AtFirstSample());
1025 pCmdUI->Enable (FALSE);
1028 void CViewer3dDoc::OnUpdateBUTTONStart(CCmdUI* pCmdUI)
1030 pCmdUI->Enable (isTextureSampleStarted);
1033 void CViewer3dDoc::OnUpdateBUTTONRepeat(CCmdUI* pCmdUI)
1035 pCmdUI->Enable (isTextureSampleStarted);
1038 void CViewer3dDoc::OnUpdateBUTTONEnd(CCmdUI* pCmdUI)
1040 pCmdUI->Enable (isTextureSampleStarted);
1043 void CViewer3dDoc::OnDumpView()
1045 for (POSITION aPos = GetFirstViewPosition(); aPos != NULL;)
1047 CViewer3dView* pView = (CViewer3dView* )GetNextView (aPos);
1048 pView->UpdateWindow();
1051 myViewer->InitActiveViews();
1052 Handle(V3d_View) aView = myViewer->ActiveView();
1056 void CViewer3dDoc::Start()
1058 myPresentation->Init();
1062 void CViewer3dDoc::Fit()
1064 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
1065 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
1066 CViewer3dView *pView = (CViewer3dView *) pChild->GetActiveView();