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, Standard_False);
157 myAISContext->SetDisplayMode (myBox, 1, Standard_False);
159 myAISContext->Display (myBox, Standard_True);
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, Standard_False);
177 myAISContext->Display (myCylinder, Standard_True);
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, Standard_False);
197 myAISContext->SetDisplayMode (mySphere, 1, Standard_False);
199 myAISContext->Display (mySphere, Standard_False);
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(), Standard_False);
218 myAISContext->Remove (myCylinder, Standard_True);
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, Standard_False);
244 myAISContext->SetDisplayMode (myOverlappedBox, 1, Standard_False);
246 myAISContext->Display (myOverlappedBox, Standard_True);
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, Standard_False);
274 myAISContext->SetDisplayMode (myOverlappedCylinder, 1, Standard_False);
276 myAISContext->Display (myOverlappedCylinder, Standard_True);
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, Standard_False);
306 myAISContext->SetDisplayMode (myOverlappedSphere, 1, Standard_False);
308 myAISContext->Display (myOverlappedSphere, Standard_True);
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 // A small trick to avoid complier error (C2668).
407 const Handle(AIS_InteractiveObject)& aBox = myBox;
408 if(myAISContext->IsSelected (aBox))
411 const Handle(AIS_InteractiveObject)& aCylinder = myCylinder;
412 if(myAISContext->IsSelected (aCylinder))
413 myCylinder.Nullify();
415 const Handle(AIS_InteractiveObject)& aSphere = mySphere;
416 if(myAISContext->IsSelected (aSphere))
419 const Handle(AIS_InteractiveObject)& anOverlappedBox = myOverlappedBox;
420 if(myAISContext->IsSelected (anOverlappedBox))
421 myOverlappedBox.Nullify();
423 const Handle(AIS_InteractiveObject)& anOverlappedCylinder = myOverlappedCylinder;
424 if(myAISContext->IsSelected (anOverlappedCylinder))
425 myOverlappedCylinder.Nullify();
427 const Handle(AIS_InteractiveObject)& anOverlappedSphere = myOverlappedSphere;
428 if(myAISContext->IsSelected (anOverlappedSphere))
429 myOverlappedSphere.Nullify();
432 for(myAISContext->InitSelected();myAISContext->MoreSelected();myAISContext->InitSelected())
433 myAISContext->Remove(myAISContext->SelectedInteractive(),Standard_True);
435 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
436 myOffsetDlg->UpdateValues();
439 void CViewer3dDoc::OnObjectErase()
442 OCC_3dBaseDoc::OnObjectErase();
443 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
444 myOffsetDlg->UpdateValues();
447 void CViewer3dDoc::OnObjectDisplayall()
450 OCC_3dBaseDoc::OnObjectDisplayall();
451 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
452 myOffsetDlg->UpdateValues();
455 Handle(User_Cylinder) CViewer3dDoc::GetCylinder()
461 Handle(AIS_Shape) CViewer3dDoc::GetSphere()
466 Handle(AIS_Shape) CViewer3dDoc::GetBox()
471 Handle(AIS_Shape) CViewer3dDoc::GetOverlappedCylinder()
473 return myOverlappedCylinder;
477 Handle(AIS_Shape) CViewer3dDoc::GetOverlappedSphere()
479 return myOverlappedSphere;
482 Handle(AIS_Shape) CViewer3dDoc::GetOverlappedBox()
484 return myOverlappedBox;
487 void CViewer3dDoc::DragEvent (const Standard_Integer theX,
488 const Standard_Integer theY,
489 const Standard_Integer theState,
490 const Handle(V3d_View)& theView)
492 OCC_3dBaseDoc::DragEvent (theX, theY, theState, theView);
493 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
494 myOffsetDlg->UpdateValues();
497 //-----------------------------------------------------------------------------------------
499 //-----------------------------------------------------------------------------------------
500 void CViewer3dDoc::InputEvent(const Standard_Integer /*x*/,
501 const Standard_Integer /*y*/,
502 const Handle(V3d_View)& /*aView*/ )
504 if (myOffsetDlg && myOffsetDlg->IsWindowVisible())
505 myOffsetDlg->UpdateValues();
507 Quantity_Color CSFColor;
509 myAISContext->Select (Standard_True);
511 // Change the color of a selected face in a user cylinder
512 if (myState == FACE_COLOR)
514 myAISContext->InitSelected();
515 if (myAISContext->MoreSelected())
517 Handle(AIS_InteractiveObject) Current = myAISContext->SelectedInteractive();
518 if (Current->HasColor())
520 myAISContext->Color (Current, CSFColor);
521 MSColor = RGB (CSFColor.Red()*255.0, CSFColor.Green()*255.0, CSFColor.Blue()*255.0);
525 MSColor = RGB (255, 255, 255);
528 CColorDialog dlgColor(MSColor);
529 if (dlgColor.DoModal() == IDOK)
531 MSColor = dlgColor.GetColor();
532 CSFColor = Quantity_Color (GetRValue (MSColor)/255.0,
533 GetGValue (MSColor)/255.0,
534 GetBValue (MSColor)/255.0,
537 Handle(AIS_InteractiveObject) aSelectedObject = myAISContext->SelectedInteractive();
538 Handle(User_Cylinder)::DownCast (aSelectedObject)->SetColor (CSFColor);
540 myAISContext->Redisplay (aSelectedObject, Standard_True);
545 myCResultDialog.SetTitle("Change face color");
546 myCResultDialog.SetText( " Handle(AIS_InteractiveObject) aSelectedObject = myAISContext->SelectedInteractive(); \n"
547 " Handle(User_Cylinder)::DownCast(aSelectedObject)->SetColor (CSFColor); \n"
548 " myAISContext->Redisplay (myAISContext->Current(), Standard_True); \n"
551 " NOTE: a User_Cylinder is an object defined by the user. \n"
552 " The User_Cylinder class inherit from the AIS_InteractiveObject \n"
553 " Cascade class, it's use is the same as an AIS_InteractiveObject. \n"
555 SetTitle (L"Change face color");
559 //-----------------------------------------------------------------------------------------
561 //-----------------------------------------------------------------------------------------
562 void CViewer3dDoc::ShiftDragEvent (const Standard_Integer theX,
563 const Standard_Integer theY,
564 const Standard_Integer theState,
565 const Handle(V3d_View)& theView)
567 OCC_3dBaseDoc::ShiftDragEvent(theX, theY, theState, theView);
568 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
569 myOffsetDlg->UpdateValues();
573 //-----------------------------------------------------------------------------------------
575 //-----------------------------------------------------------------------------------------
576 void CViewer3dDoc::ShiftInputEvent (const Standard_Integer theX,
577 const Standard_Integer theY,
578 const Handle(V3d_View)& theView)
580 OCC_3dBaseDoc::ShiftInputEvent (theX, theY, theView);
581 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
582 myOffsetDlg->UpdateValues();
585 void CViewer3dDoc::OnObjectColoredMesh()
587 for(myAISContext->InitSelected();myAISContext->MoreSelected();myAISContext->NextSelected())
588 if (myAISContext->SelectedInteractive()->IsKind(STANDARD_TYPE(User_Cylinder)))
590 myAISContext->ClearPrs(myAISContext->SelectedInteractive(),6,Standard_False);
591 myAISContext->RecomputePrsOnly(myAISContext->SelectedInteractive(), Standard_False);
592 myAISContext->SetDisplayMode(myAISContext->SelectedInteractive(), 6, Standard_False);
595 myAISContext->UpdateCurrentViewer();
598 void CViewer3dDoc::OnUpdateObjectColoredMesh(CCmdUI* pCmdUI)
600 bool CylinderIsCurrentAndDisplayed = false;
601 for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ())
602 if(myAISContext->SelectedInteractive()->IsKind(STANDARD_TYPE(User_Cylinder)))
603 CylinderIsCurrentAndDisplayed=true;
604 pCmdUI->Enable (CylinderIsCurrentAndDisplayed);
607 void CViewer3dDoc::OnUpdateObjectWireframe(CCmdUI* pCmdUI)
609 bool OneOrMoreInShadingOrColoredMesh = false;
610 for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ())
611 if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(), 1) || myAISContext->IsDisplayed(myAISContext->SelectedInteractive(), 6))
612 OneOrMoreInShadingOrColoredMesh=true;
613 pCmdUI->Enable (OneOrMoreInShadingOrColoredMesh);
617 void CViewer3dDoc::OnUpdateObjectShading(CCmdUI* pCmdUI)
619 bool OneOrMoreInWireframeOrColoredMesh = false;
620 for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ())
621 if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),0) || myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),6))
622 OneOrMoreInWireframeOrColoredMesh=true;
623 pCmdUI->Enable (OneOrMoreInWireframeOrColoredMesh);
626 void CViewer3dDoc::OnOptionsTrihedronDynamicTrihedron()
628 if (myAISContext -> IsDisplayed(myTrihedron))
630 myAISContext->Remove(myTrihedron, Standard_True);
634 Handle(Geom_Axis2Placement) myTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
635 myTrihedron=new AIS_Trihedron(myTrihedronAxis);
636 myAISContext->SetTrihedronSize(200, Standard_False);
637 myAISContext->Display(myTrihedron, Standard_True);
641 void CViewer3dDoc::OnUpdateOptionsTrihedronDynamicTrihedron(CCmdUI* pCmdUI)
643 if (myAISContext->IsDisplayed(myTrihedron))
649 void CViewer3dDoc::SetMyStaticTrihedronAxisIsDisplayed(BOOL IsDisplayed)
651 myStaticTrihedronAxisIsDisplayed = IsDisplayed;
654 void CViewer3dDoc::OnUpdateOptionsTrihedronStaticTrihedron(CCmdUI* pCmdUI)
656 if (myStaticTrihedronAxisIsDisplayed)
663 void CViewer3dDoc::Popup (const Standard_Integer x,
664 const Standard_Integer y ,
665 const Handle(V3d_View)& aView)
668 // Specified check for context menu number to call
669 myAISContext->InitSelected();
670 if (myAISContext->MoreSelected())
672 if (myAISContext->SelectedInteractive()->IsKind(STANDARD_TYPE(User_Cylinder)))
674 myPopupMenuNumber = 2;
678 OCC_3dBaseDoc::Popup(x,y, aView);
681 //Set faces selection mode
682 void CViewer3dDoc::OnFaces()
684 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_FACE));
686 myCResultDialog.SetTitle("Standard mode: TopAbs_FACE");
687 myCResultDialog.SetText(" myAISContext->OpenLocalContext(); \n"
689 " myAISContext->ActivateStandardMode(TopAbs_FACE); \n"
691 SetTitle (L"Standard mode: TopAbs_FACE");
694 //Set edges selection mode
695 void CViewer3dDoc::OnEdges()
697 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));
699 myCResultDialog.SetTitle("Standard mode: TopAbs_EDGE");
700 myCResultDialog.SetText(" myAISContext->OpenLocalContext(); \n"
702 " myAISContext->ActivateStandardMode(TopAbs_EDGE); \n"
704 SetTitle (L"Standard mode: TopAbs_EDGE");
707 // Set vertices selection mode
708 void CViewer3dDoc::OnVertices()
710 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
712 myCResultDialog.SetTitle("Standard mode: TopAbs_VERTEX");
713 myCResultDialog.SetText(" myAISContext->OpenLocalContext(); \n"
715 " myAISContext->ActivateStandardMode(TopAbs_VERTEX); \n"
717 SetTitle (L"Standard mode: TopAbs_VERTEX");
720 //Neutral selection mode
721 void CViewer3dDoc::OnNeutral()
723 myCResultDialog.SetTitle("Standard mode: Neutral");
724 myCResultDialog.SetText(" myAISContext->CloseAllContexts(); \n"
726 SetTitle (L"Standard mode: Neutral");
729 // Change the color of faces on a user cylinder
730 void CViewer3dDoc::OnUsercylinderChangefacecolor()
732 myAISContext->Activate(myAISContext->SelectedInteractive(), 4);
733 myState = FACE_COLOR;
734 // see the following of treatment in inputevent
737 // Make 3d fillets on solids
738 // It is necessary to activate the edges selection mode and select edges on an object
739 // before running this function
740 void CViewer3dDoc::OnFillet3d()
742 myAISContext->InitSelected();
743 if (myAISContext->MoreSelected())
745 Handle(AIS_Shape) aSelInteractive (Handle(AIS_Shape)::DownCast (myAISContext->SelectedInteractive()));
746 if (aSelInteractive.IsNull())
748 AfxMessageBox (L"It is necessary to activate the edges selection mode\n"
749 L"and select edges on an object before \nrunning this function");
753 BRepFilletAPI_MakeFillet aFillet (aSelInteractive->Shape());
755 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
757 const TopoDS_Shape& aSelShape = myAISContext->SelectedShape();
758 if (aSelShape.ShapeType() != TopAbs_EDGE)
760 AfxMessageBox (L"It is necessary to activate the edges selection mode\n"
761 L"and select edges on an object before \nrunning this function");
766 BoxRadius aDialog (NULL,10.);
767 if (aDialog.DoModal() == IDOK)
769 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
771 // Selected shape has its own location, and sub-shapes in the solid shape for fillet building
772 // don't have own locations. Fillet builder needs to know that input edge is just the same one as
773 // some sub-shape in our target solid shape, so no location is to be in input edge for fillet builder.
774 TopoDS_Shape aSelShape = myAISContext->SelectedShape().Located (TopLoc_Location());
775 aFillet.Add (aDialog.m_radius, TopoDS::Edge (aSelShape) );
783 TopoDS_Shape aNewShape;
786 aNewShape = aFillet.Shape();
788 catch (Standard_Failure)
790 AfxMessageBox (L"Error During Fillet computation");
794 aSelInteractive ->Set (aNewShape);
795 myAISContext->Redisplay (aSelInteractive, Standard_True);
798 myCResultDialog.SetTitle("Make a fillet");
799 myCResultDialog.SetText(" Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast(myAISContext->Interactive()); \n"
801 " BRepAPI_MakeFillet aFillet(S->Shape()); \n"
803 " TopoDS_Edge anEdge=TopoDS::Edge(myAISContext->SelectedShape()); \n"
805 " aFillet.Add(dlg.m_radius,anEdge); \n"
807 " TopoDS_Shape aNewShape = aFillet.Shape(); \n"
809 " S->Set(aNewShape); \n"
811 " myAISContext->Redisplay(S); \n"
813 SetTitle (L"Make a fillet");
816 // Create and display a circle with standard tools
817 void CViewer3dDoc::OnCircle()
819 gp_Ax2 anAx2 (gp_Pnt (0., 0., 0.), gp_Dir(0., 0., -1.));
820 Handle(Geom_Circle) aGeomCircle = new Geom_Circle (anAx2, 300);
822 // the lines above substitute
823 // GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.));
824 // Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value());
826 Handle(AIS_Circle) anAISCirc = new AIS_Circle(aGeomCircle);
827 myAISContext->Display (anAISCirc, Standard_True);
829 myCResultDialog.SetTitle("Create a circle");
830 myCResultDialog.SetText(" GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.)); \n"
832 " Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value()); \n"
834 " myAISContext->Display(anAISCirc); \n"
836 SetTitle (L"Create a circle");
839 void CViewer3dDoc::OnLine()
841 // TODO: Add your command handler code here
842 gp_Lin aGpLin (gp_Pnt (0., 0., 0.), gp_Dir(1., 0., 0.));
843 Handle(Geom_Line) aGeomLin = new Geom_Line (aGpLin);
844 Handle(AIS_Line) anAISLine = new AIS_Line (aGeomLin);
845 myAISContext->Display (anAISLine, Standard_True);
847 myCResultDialog.SetTitle("Create a line");
848 myCResultDialog.SetText(" gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.)); \n"
850 " Handle(Geom_Line) aLine = new Geom_Line(L); \n"
852 " Handle(AIS_Line) anAISLine = new AIS_Line(aLine); \n"
854 " myAISContext->Display(anAISLine); \n"
856 SetTitle (L"Create a line");
859 void CViewer3dDoc::OnNbisos()
861 int aNumU = myAISContext->DefaultDrawer()->UIsoAspect()->Number();
862 int aNumV = myAISContext->DefaultDrawer()->VIsoAspect()->Number();
864 DlgIsos aDlg (NULL, aNumU, aNumV);
866 if (aDlg.DoModal() == IDOK)
868 myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber (aDlg.m_isou);
869 myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber (aDlg.m_isov);
871 myCResultDialog.SetTitle("Iso Aspect");
872 myCResultDialog.SetText(" myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(dlg.m_isou); \n"
874 " myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(dlg.m_isov); \n"
876 SetTitle (L"Iso Aspect");
880 BOOL CViewer3dDoc::OnNewDocument()
882 if (!CDocument::OnNewDocument())
885 // TODO: add reinitialization code here
886 // (SDI documents will reuse this document)
887 SetTitle(myPresentation->GetName());
889 myAISContext->EraseAll (Standard_False);
890 myAISContext->SetDisplayMode(AIS_Shaded, Standard_True);
892 POSITION pos = GetFirstViewPosition();
895 CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
902 void CViewer3dDoc::OnFileNew()
907 void CViewer3dDoc::InitViewButtons()
909 POSITION pos = GetFirstViewPosition();
912 CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
913 pView->InitButtons();
917 void CViewer3dDoc::OnTextureOn()
919 isTextureSampleStarted = TRUE;
923 void CViewer3dDoc::DoSample()
927 HCURSOR hOldCursor = ::GetCursor();
928 HCURSOR hNewCursor = AfxGetApp()->LoadStandardCursor(IDC_APPSTARTING);
930 SetCursor(hNewCursor);
934 myPresentation->DoSample();
936 catch (Standard_Failure const& anException)
938 Standard_SStream aSStream;
939 aSStream << "An exception was caught: " << anException << ends;
940 CString aMsg = aSStream.str().c_str();
941 AfxMessageBox (aMsg);
944 SetCursor(hOldCursor);
947 void CViewer3dDoc::OnBUTTONStart()
949 myAISContext->EraseAll (Standard_True);
950 myPresentation->FirstSample();
954 void CViewer3dDoc::OnBUTTONEnd()
956 myAISContext->EraseAll (Standard_True);
957 myPresentation->LastSample();
961 void CViewer3dDoc::OnBUTTONRepeat()
966 void CViewer3dDoc::OnBUTTONNext()
968 if (!myPresentation->AtLastSample())
970 myPresentation->NextSample();
975 void CViewer3dDoc::OnBUTTONPrev()
977 if (!myPresentation->AtFirstSample())
979 myPresentation->PrevSample();
984 void CViewer3dDoc::OnUpdateBUTTONNext(CCmdUI* pCmdUI)
986 if ( isTextureSampleStarted )
987 pCmdUI->Enable (!myPresentation->AtLastSample());
989 pCmdUI->Enable (FALSE);
992 void CViewer3dDoc::OnUpdateBUTTONPrev(CCmdUI* pCmdUI)
994 if ( isTextureSampleStarted )
995 pCmdUI->Enable (!myPresentation->AtFirstSample());
997 pCmdUI->Enable (FALSE);
1000 void CViewer3dDoc::OnUpdateBUTTONStart(CCmdUI* pCmdUI)
1002 pCmdUI->Enable (isTextureSampleStarted);
1005 void CViewer3dDoc::OnUpdateBUTTONRepeat(CCmdUI* pCmdUI)
1007 pCmdUI->Enable (isTextureSampleStarted);
1010 void CViewer3dDoc::OnUpdateBUTTONEnd(CCmdUI* pCmdUI)
1012 pCmdUI->Enable (isTextureSampleStarted);
1015 void CViewer3dDoc::OnDumpView()
1017 for (POSITION aPos = GetFirstViewPosition(); aPos != NULL;)
1019 CViewer3dView* pView = (CViewer3dView* )GetNextView (aPos);
1020 pView->UpdateWindow();
1023 myViewer->InitActiveViews();
1024 Handle(V3d_View) aView = myViewer->ActiveView();
1028 void CViewer3dDoc::Start()
1030 myPresentation->Init();
1034 void CViewer3dDoc::Fit()
1036 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
1037 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
1038 CViewer3dView *pView = (CViewer3dView *) pChild->GetActiveView();