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_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)
76 /////////////////////////////////////////////////////////////////////////////
77 // CViewer3dDoc construction/destruction
79 CViewer3dDoc::CViewer3dDoc()
84 myOverlappedCylinder.Nullify();
85 myOverlappedSphere.Nullify();
86 myOverlappedBox.Nullify();
88 myStaticTrihedronAxisIsDisplayed = FALSE;
92 isTextureSampleStarted = FALSE;
94 // TODO: add one-time construction code here
95 Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice =
96 ((CViewer3dApp*)AfxGetApp())->GetGraphicDevice();
98 myViewer = new V3d_Viewer(theGraphicDevice,(short *) "Visu3D");
99 myViewer->SetDefaultLights();
100 myViewer->SetLightOn();
103 // myViewer->SetDefaultBackgroundColor(Quantity_TOC_RGB, 0.,0.,0.);
105 myPresentation = OCCDemo_Presentation::Current;
106 myPresentation->SetDocument(this);
109 myAISContext->DefaultDrawer()->ShadingAspect()->SetColor(Quantity_NOC_CHARTREUSE1);
110 myAISContext->DefaultDrawer()->ShadingAspect()->SetMaterial(Graphic3d_NOM_SILVER);
112 strcpy_s(myDataDir, "Data");
113 strcpy_s(myLastPath, ".");
116 Handle(AIS_Trihedron) myTrihedron;
117 Handle(Geom_Axis2Placement) myTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
118 myTrihedron=new AIS_Trihedron(myTrihedronAxis);
119 myAISContext->Display(myTrihedron);
123 CViewer3dDoc::~CViewer3dDoc()
127 /////////////////////////////////////////////////////////////////////////////
128 // CViewer3dDoc diagnostics
131 void CViewer3dDoc::AssertValid() const
133 CDocument::AssertValid();
136 void CViewer3dDoc::Dump(CDumpContext& dc) const
142 /////////////////////////////////////////////////////////////////////////////
143 // CViewer3dDoc commands
145 void CViewer3dDoc::UpdateResultMessageDlg(CString Title, TCollection_AsciiString aMessage)
147 CString text(aMessage.ToCString());
148 myCResultDialog.SetText(text);
150 myCResultDialog.SetTitle(Title);
153 void CViewer3dDoc::OnBox()
156 BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
159 myBox = new AIS_Shape(B.Shape());
161 myAISContext->SetMaterial(myBox,Graphic3d_NOM_PEWTER);
162 myAISContext->SetDisplayMode(myBox,1);
164 myAISContext->Display(myBox);
165 TCollection_AsciiString Message("\
166 BRepPrimAPI_MakeBox Box1(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
169 UpdateResultMessageDlg("Create Box",Message);
174 void CViewer3dDoc::OnCylinder()
176 if(myCylinder.IsNull()) {
177 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
179 //BRepPrimAPI_MakeCylinder C(CylAx2, 80.,200.);
181 myCylinder = new User_Cylinder(CylAx2, 80.,200.);
183 // myCylinder = new AIS_Shape(C.Shape());
185 myCylinder->SetTransparency(0.5);
187 myAISContext->SetColor(myCylinder,Quantity_NOC_WHITE);
188 myAISContext->SetMaterial(myCylinder,Graphic3d_NOM_SHINY_PLASTIC);
190 myAISContext->SetDisplayMode(myCylinder,1);
192 myAISContext->Display(myCylinder);
194 TCollection_AsciiString Message("\
195 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));\n\
196 C = new User_Cylinder(CylAx2, 80.,200.);;\n\
199 UpdateResultMessageDlg("Create Cylinder",Message);
204 void CViewer3dDoc::OnSphere()
206 if(mySphere.IsNull()){
207 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
209 mySphere = new AIS_Shape(S.Shape());
211 myAISContext->SetMaterial(mySphere,Graphic3d_NOM_BRONZE);
212 myAISContext->SetDisplayMode(mySphere,1);
214 myAISContext->Display(mySphere);
215 TCollection_AsciiString Message("\
216 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);\n\
218 UpdateResultMessageDlg("Create Sphere",Message);
222 void CViewer3dDoc::OnRemoveAll()
225 AIS_ListOfInteractive aListOfObjects;
226 myAISContext->ObjectsInside(aListOfObjects,AIS_KOI_Shape);
228 AIS_ListIteratorOfListOfInteractive aListIterator;
229 for(aListIterator.Initialize(aListOfObjects);aListIterator.More();aListIterator.Next()){
230 myAISContext->Remove(aListIterator.Value());
233 myAISContext->Remove(myCylinder);
236 myCylinder.Nullify();
239 myOverlappedCylinder.Nullify();
240 myOverlappedSphere.Nullify();
241 myOverlappedBox.Nullify();
242 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
243 myOffsetDlg->UpdateValues();
246 void CViewer3dDoc::OnOverlappedBox()
249 if(myOverlappedBox.IsNull()){
250 BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
252 BRepBuilderAPI_NurbsConvert aNurbsConvert(B.Shape());
253 TopoDS_Shape aBoxShape2 = aNurbsConvert.Shape();
256 myOverlappedBox = new AIS_Shape(aBoxShape2);
258 myAISContext->SetMaterial(myOverlappedBox,Graphic3d_NOM_GOLD);
259 myAISContext->SetDisplayMode(myOverlappedBox,1);
261 myAISContext->Display(myOverlappedBox);
262 TCollection_AsciiString Message("\
263 BRepPrimAPI_MakeBox Box1(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
265 BRepPrimAPI_MakeBox Box2(gp_Pnt(0,-400,-100), 200.,150.,100.);\n\
266 BRepBuilderAPI_NurbsConvert aNurbsConvert(Box2.Shape());\n\
268 UpdateResultMessageDlg("Create overlapped boxes",Message);
269 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
270 myOffsetDlg->UpdateValues();
276 void CViewer3dDoc::OnOverlappedCylinder()
280 if(myOverlappedCylinder.IsNull()){
281 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
282 BRepPrimAPI_MakeCylinder C(CylAx2, 80.,200.);
284 BRepBuilderAPI_NurbsConvert aNurbsConvert(C.Shape());
285 TopoDS_Shape aCylShape2 = aNurbsConvert.Shape();
287 myOverlappedCylinder = new AIS_Shape(aCylShape2);
290 myAISContext->SetMaterial(myOverlappedCylinder,Graphic3d_NOM_GOLD);
291 myAISContext->SetDisplayMode(myOverlappedCylinder,1);
293 myAISContext->Display(myOverlappedCylinder);
295 TCollection_AsciiString Message("\
296 gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));\n\
297 Cylinder1 = new User_Cylinder(CylAx2, 80.,200.);\n\
299 BRepPrimAPI_MakeCylinder Cylinder2(CylAx2, 80.,200.);\n\
300 BRepBuilderAPI_NurbsConvert aNurbsConvert(Cylinder2.Shape());\n\
302 UpdateResultMessageDlg("Create overlapped cylinders",Message);
303 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
304 myOffsetDlg->UpdateValues();
309 void CViewer3dDoc::OnOverlappedSphere()
312 if(myOverlappedSphere.IsNull()){
313 BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
315 BRepBuilderAPI_NurbsConvert aNurbsConvert(S.Shape());
316 TopoDS_Shape aSphereShape2 = aNurbsConvert.Shape();
318 myOverlappedSphere = new AIS_Shape(aSphereShape2);
320 myAISContext->SetMaterial(myOverlappedSphere,Graphic3d_NOM_GOLD);
322 myAISContext->SetDisplayMode(myOverlappedSphere,1);
324 myAISContext->Display(myOverlappedSphere);
326 TCollection_AsciiString Message("\
327 BRepPrimAPI_MakeSphere Sphere1(gp_Pnt(0,300,0), 100.);\n\
329 BRepPrimAPI_MakeSphere Sphere2(gp_Pnt(0,300,0), 100.);\n\
330 BRepBuilderAPI_NurbsConvert aNurbsConvert(Sphere2.Shape());\n\
332 UpdateResultMessageDlg("Create overlapped spheres",Message);
333 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
334 myOffsetDlg->UpdateValues();
339 void CViewer3dDoc::OnPolygonOffsets()
342 myOffsetDlg = new COffsetDlg(this);
343 myOffsetDlg->Create(COffsetDlg::IDD,NULL);
344 myAISContext->UpdateCurrentViewer();
348 void CViewer3dDoc::OnUpdatePolygonOffsets(CCmdUI* pCmdUI)
350 Standard_Integer aOffsetMode;
351 Standard_ShortReal aFactor;
352 Standard_ShortReal aCylUnits = 0;
353 Standard_ShortReal aSphereUnits = 0;
354 Standard_ShortReal aBoxUnits = 0;
356 BOOL IsOverlappedCylinderDisplayed = myAISContext->IsDisplayed(myOverlappedCylinder);
357 BOOL IsOverlappedSphereDisplayed = myAISContext->IsDisplayed(myOverlappedSphere);
358 BOOL IsOverlappedBoxDisplayed = myAISContext->IsDisplayed(myOverlappedBox);
359 BOOL IsAnyOverlappedObjectDisplayed =
360 IsOverlappedCylinderDisplayed || IsOverlappedSphereDisplayed || IsOverlappedBoxDisplayed;
362 if(!myOverlappedCylinder.IsNull() && IsOverlappedCylinderDisplayed){
363 myOverlappedCylinder->PolygonOffsets(aOffsetMode,aFactor,aCylUnits);
366 if(!myOverlappedSphere.IsNull() && IsOverlappedSphereDisplayed){
367 myOverlappedSphere->PolygonOffsets(aOffsetMode,aFactor,aSphereUnits);
370 if(!myOverlappedBox.IsNull() && IsOverlappedBoxDisplayed){
371 myOverlappedBox->PolygonOffsets(aOffsetMode,aFactor,aBoxUnits);
374 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
375 pCmdUI->SetCheck(TRUE);
377 pCmdUI->SetCheck(FALSE);
378 if (IsAnyOverlappedObjectDisplayed)
380 pCmdUI->Enable(!myOffsetDlg->IsWindowVisible());
382 pCmdUI->Enable(TRUE);
384 pCmdUI->Enable(FALSE);
389 void CViewer3dDoc::OnUpdateCylinder(CCmdUI* pCmdUI)
391 pCmdUI->Enable(myCylinder.IsNull());
395 void CViewer3dDoc::OnUpdateSphere(CCmdUI* pCmdUI)
397 pCmdUI->Enable(mySphere.IsNull());
401 void CViewer3dDoc::OnUpdateBox(CCmdUI* pCmdUI)
403 pCmdUI->Enable(myBox.IsNull());
407 void CViewer3dDoc::OnUpdateOverlappedCylinder(CCmdUI* pCmdUI)
409 pCmdUI->Enable (myOverlappedCylinder.IsNull()
410 || myCylinder.IsNull());
414 void CViewer3dDoc::OnUpdateOverlappedSphere(CCmdUI* pCmdUI)
416 pCmdUI->Enable (myOverlappedSphere.IsNull()
417 || mySphere.IsNull());
420 void CViewer3dDoc::OnUpdateOverlappedBox(CCmdUI* pCmdUI)
422 pCmdUI->Enable (myOverlappedBox.IsNull()
426 void CViewer3dDoc::OnObjectRemove()
430 if(myAISContext->IsCurrent(myBox))
433 if(myAISContext->IsCurrent(myCylinder))
434 myCylinder.Nullify();
436 if(myAISContext->IsCurrent(mySphere))
439 if(myAISContext->IsCurrent(myOverlappedBox))
440 myOverlappedBox.Nullify();
442 if(myAISContext->IsCurrent(myOverlappedCylinder))
443 myOverlappedCylinder.Nullify();
445 if(myAISContext->IsCurrent(myOverlappedSphere))
446 myOverlappedSphere.Nullify();
449 for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->InitCurrent())
450 myAISContext->Remove(myAISContext->Current(),Standard_True);
452 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
453 myOffsetDlg->UpdateValues();
457 void CViewer3dDoc::OnObjectErase()
460 OCC_3dBaseDoc::OnObjectErase();
461 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
462 myOffsetDlg->UpdateValues();
465 void CViewer3dDoc::OnObjectDisplayall()
468 OCC_3dBaseDoc::OnObjectDisplayall();
469 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
470 myOffsetDlg->UpdateValues();
473 Handle_User_Cylinder CViewer3dDoc::GetCylinder()
479 Handle_AIS_Shape CViewer3dDoc::GetSphere()
484 Handle_AIS_Shape CViewer3dDoc::GetBox()
489 Handle_AIS_Shape CViewer3dDoc::GetOverlappedCylinder()
491 return myOverlappedCylinder;
495 Handle_AIS_Shape CViewer3dDoc::GetOverlappedSphere()
497 return myOverlappedSphere;
500 Handle_AIS_Shape CViewer3dDoc::GetOverlappedBox()
502 return myOverlappedBox;
505 void CViewer3dDoc::DragEvent(const Standard_Integer x ,
506 const Standard_Integer y ,
507 const Standard_Integer TheState ,
508 const Handle(V3d_View)& aView )
510 OCC_3dBaseDoc::DragEvent(x,y, TheState,aView);
511 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
512 myOffsetDlg->UpdateValues();
515 //-----------------------------------------------------------------------------------------
517 //-----------------------------------------------------------------------------------------
518 void CViewer3dDoc::InputEvent(const Standard_Integer x ,
519 const Standard_Integer y ,
520 const Handle(V3d_View)& aView )
522 if (myOffsetDlg && myOffsetDlg->IsWindowVisible())
523 myOffsetDlg->UpdateValues();
525 Quantity_Color CSFColor;
527 myAISContext->Select();
529 // Change the color of a selected face in a user cylinder
530 if (myState == FACE_COLOR)
532 myAISContext->InitSelected();
533 if (myAISContext->MoreSelected())
535 Handle_AIS_InteractiveObject Current = myAISContext->SelectedInteractive();
536 if (Current->HasColor())
538 CSFColor = myAISContext->Color (Current);
539 MSColor = RGB (CSFColor.Red()*255.0, CSFColor.Green()*255.0, CSFColor.Blue()*255.0);
543 MSColor = RGB (255, 255, 255);
546 CColorDialog dlgColor(MSColor);
547 if (dlgColor.DoModal() == IDOK)
549 MSColor = dlgColor.GetColor();
550 CSFColor = Quantity_Color (GetRValue (MSColor)/255.0,
551 GetGValue (MSColor)/255.0,
552 GetBValue (MSColor)/255.0,
555 TopoDS_Shape S = myAISContext->SelectedShape();
556 Handle(Geom_Surface) Surface = BRep_Tool::Surface (TopoDS::Face(S));
557 if (Surface->IsKind (STANDARD_TYPE (Geom_Plane)))
559 Handle(User_Cylinder)::DownCast (myAISContext->SelectedInteractive())
560 ->SetPlanarFaceColor (CSFColor.Name());
564 Handle(User_Cylinder)::DownCast (myAISContext->SelectedInteractive())
565 ->SetCylindricalFaceColor (CSFColor.Name());
568 myAISContext->Redisplay (myAISContext->SelectedInteractive());
570 myAISContext->CloseLocalContext();
574 TCollection_AsciiString aMessage (" TopoDS_Shape S = myAISContext->SelectedShape(); \n"
576 " Handle(Geom_Surface) Surface = BRep_Tool::Surface(TopoDS::Face(S));"
577 " if (Surface->IsKind(STANDARD_TYPE(Geom_Plane))) \n"
578 " Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetPlanarFaceColor(CSFColor.Name()); \n"
580 " Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetCylindricalFaceColor(CSFColor.Name()); \n"
582 " myAISContext->Redisplay(myAISContext->Current()); \n"
584 " myAISContext->CloseLocalContext(); \n"
587 " NOTE: a User_Cylinder is an object defined by the user. \n"
588 " The User_Cylinder class inherit from the AIS_InteractiveObject \n"
589 " Cascade class, it's use is the same as an AIS_InteractiveObject. \n"
590 " Methods SetPlanarFaceColor and SetCylindricalFaceColor are also \n"
591 " defined in the User_Cylinder class. \n"
594 CString aMsgStr (aMessage.ToCString());
595 myCResultDialog.SetTitle (CString ("Change face color"));
596 myCResultDialog.SetText (aMsgStr);
597 SetTitle (CString ("Change face color"));
601 //-----------------------------------------------------------------------------------------
603 //-----------------------------------------------------------------------------------------
604 void CViewer3dDoc::ShiftDragEvent(const Standard_Integer x ,
605 const Standard_Integer y ,
606 const Standard_Integer TheState ,
607 const Handle(V3d_View)& aView )
609 OCC_3dBaseDoc::ShiftDragEvent(x,y,TheState,aView);
610 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
611 myOffsetDlg->UpdateValues();
615 //-----------------------------------------------------------------------------------------
617 //-----------------------------------------------------------------------------------------
619 void CViewer3dDoc::ShiftInputEvent(const Standard_Integer x ,
620 const Standard_Integer y ,
621 const Handle(V3d_View)& aView )
623 OCC_3dBaseDoc::ShiftInputEvent(x,y,aView);
624 if(myOffsetDlg && myOffsetDlg->IsWindowVisible())
625 myOffsetDlg->UpdateValues();
628 void CViewer3dDoc::OnObjectColoredMesh()
630 for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->NextCurrent())
631 if (myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
633 myAISContext->ClearPrs(myAISContext->Current(),6,Standard_False);
634 myAISContext->RecomputePrsOnly(myAISContext->Current(),Standard_False);
635 myAISContext->SetDisplayMode(myAISContext->Current(),6);
639 void CViewer3dDoc::OnUpdateObjectColoredMesh(CCmdUI* pCmdUI)
641 bool CylinderIsCurrentAndDisplayed = false;
642 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
643 if(myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
644 CylinderIsCurrentAndDisplayed=true;
645 pCmdUI->Enable (CylinderIsCurrentAndDisplayed);
648 void CViewer3dDoc::OnUpdateObjectWireframe(CCmdUI* pCmdUI)
650 bool OneOrMoreInShadingOrColoredMesh = false;
651 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
652 if (myAISContext->IsDisplayed(myAISContext->Current(),1) || myAISContext->IsDisplayed(myAISContext->Current(),6))
653 OneOrMoreInShadingOrColoredMesh=true;
654 pCmdUI->Enable (OneOrMoreInShadingOrColoredMesh);
658 void CViewer3dDoc::OnUpdateObjectShading(CCmdUI* pCmdUI)
660 bool OneOrMoreInWireframeOrColoredMesh = false;
661 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
662 if (myAISContext->IsDisplayed(myAISContext->Current(),0) || myAISContext->IsDisplayed(myAISContext->Current(),6))
663 OneOrMoreInWireframeOrColoredMesh=true;
664 pCmdUI->Enable (OneOrMoreInWireframeOrColoredMesh);
668 void CViewer3dDoc::OnOptionsTrihedronDynamicTrihedron()
670 if (myAISContext -> IsDisplayed(myTrihedron))
672 myAISContext->Remove(myTrihedron);
676 Handle(Geom_Axis2Placement) myTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
677 myTrihedron=new AIS_Trihedron(myTrihedronAxis);
678 myAISContext->SetTrihedronSize(200, Standard_True);
679 myAISContext->Display(myTrihedron);
683 void CViewer3dDoc::OnUpdateOptionsTrihedronDynamicTrihedron(CCmdUI* pCmdUI)
685 if (myAISContext->IsDisplayed(myTrihedron))
691 void CViewer3dDoc::SetMyStaticTrihedronAxisIsDisplayed(BOOL IsDisplayed)
693 myStaticTrihedronAxisIsDisplayed = IsDisplayed;
696 void CViewer3dDoc::OnUpdateOptionsTrihedronStaticTrihedron(CCmdUI* pCmdUI)
698 if (myStaticTrihedronAxisIsDisplayed)
705 void CViewer3dDoc::Popup( const Standard_Integer x,
706 const Standard_Integer y ,
707 const Handle(V3d_View)& aView )
709 Standard_Integer PopupMenuNumber=0;
710 myAISContext->InitCurrent();
711 if (myAISContext->MoreCurrent()) {
712 if (myAISContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
719 VERIFY(menu.LoadMenu(IDR_Popup3D));
720 CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
722 ASSERT(pPopup != NULL);
723 if (PopupMenuNumber == 1) // more than 1 object.
725 bool OneOrMoreInShading = false;
726 for (myAISContext->InitCurrent();myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
727 if (myAISContext->IsDisplayed(myAISContext->Current(),1)) OneOrMoreInShading=true;
728 if(!OneOrMoreInShading)
729 pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
732 POINT winCoord = { x , y };
733 Handle(WNT_Window) aWNTWindow=
734 Handle(WNT_Window)::DownCast(aView->Window());
735 ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
736 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,
740 //Set faces selection mode
741 void CViewer3dDoc::OnFaces()
743 myAISContext->CloseAllContexts();
744 myAISContext->OpenLocalContext();
745 myAISContext->ActivateStandardMode (TopAbs_FACE);
747 TCollection_AsciiString aMessage (" myAISContext->OpenLocalContext(); \n"
749 " myAISContext->ActivateStandardMode(TopAbs_FACE); \n"
752 CString aMsgStr (aMessage.ToCString());
753 myCResultDialog.SetTitle (CString("Standard mode: TopAbs_FACE"));
754 myCResultDialog.SetText (aMsgStr);
755 SetTitle (CString ("Standard mode: TopAbs_FACE"));
758 //Set edges selection mode
759 void CViewer3dDoc::OnEdges()
761 myAISContext->CloseAllContexts();
762 myAISContext->OpenLocalContext();
763 myAISContext->ActivateStandardMode(TopAbs_EDGE);
765 TCollection_AsciiString aMessage (" myAISContext->OpenLocalContext(); \n"
767 " myAISContext->ActivateStandardMode(TopAbs_EDGE); \n"
770 CString aMsgStr (aMessage.ToCString());
771 myCResultDialog.SetTitle (CString ("Standard mode: TopAbs_EDGE"));
772 myCResultDialog.SetText (aMsgStr);
773 SetTitle (CString ("Standard mode: TopAbs_EDGE"));
776 // Set vertices selection mode
777 void CViewer3dDoc::OnVertices()
779 myAISContext->CloseAllContexts();
780 myAISContext->OpenLocalContext();
781 myAISContext->ActivateStandardMode (TopAbs_VERTEX);
783 TCollection_AsciiString aMessage (" myAISContext->OpenLocalContext(); \n"
785 " myAISContext->ActivateStandardMode(TopAbs_VERTEX); \n"
788 CString aMsgStr (aMessage.ToCString());
789 myCResultDialog.SetTitle (CString ("Standard mode: TopAbs_VERTEX"));
790 myCResultDialog.SetText (aMsgStr);
791 SetTitle (CString ("Standard mode: TopAbs_VERTEX"));
794 //Neutral selection mode
795 void CViewer3dDoc::OnNeutral()
797 myAISContext->CloseAllContexts();
799 TCollection_AsciiString aMessage (" myAISContext->CloseAllContexts(); \n"
802 CString aMsgStr (aMessage.ToCString());
803 myCResultDialog.SetTitle (CString ("Standard mode: Neutral"));
804 myCResultDialog.SetText (aMsgStr);
805 SetTitle (CString ("Standard mode: Neutral"));
808 // Change the color of faces on a user cylinder
809 void CViewer3dDoc::OnUsercylinderChangefacecolor()
811 myAISContext->OpenLocalContext();
812 myAISContext->Activate(myAISContext->Current(),4);
813 myState = FACE_COLOR;
814 // see the following of treatment in inputevent
817 // Make 3d fillets on solids
818 // It is necessary to activate the edges selection mode and select edges on an object
819 // before running this function
820 void CViewer3dDoc::OnFillet3d()
822 if (!myAISContext->HasOpenedContext())
824 AfxMessageBox("It is necessary to activate the edges selection mode\n"
825 "and select edges on an object before \nrunning this function");
829 myAISContext->InitSelected();
830 if (myAISContext->MoreSelected())
832 Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast (myAISContext->SelectedInteractive());
836 AfxMessageBox("It is necessary to activate the edges selection mode\n"
837 "and select edges on an object before \nrunning this function");
841 TopoDS_Shape Sh=S->Shape();
843 BRepFilletAPI_MakeFillet aFillet(Sh);
845 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
847 TopoDS_Shape aSelShape = myAISContext->SelectedShape();
848 if (aSelShape.ShapeType() != TopAbs_EDGE)
850 AfxMessageBox("It is necessary to activate the edges selection mode\n\
851 and select edges on an object before \nrunning this function");
856 BoxRadius dlg(NULL,10.);
857 if (dlg.DoModal() == IDOK)
859 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
861 TopoDS_Edge anEdge = TopoDS::Edge(myAISContext->SelectedShape());
862 aFillet.Add(dlg.m_radius,anEdge);
870 TopoDS_Shape aNewShape;
873 aNewShape = aFillet.Shape();
875 catch (Standard_Failure)
877 AfxMessageBox("Error During Fillet computation");
882 myAISContext->Redisplay (S);
885 TCollection_AsciiString aMessage (" Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast(myAISContext->Interactive()); \n"
887 " BRepAPI_MakeFillet aFillet(S->Shape()); \n"
889 " TopoDS_Edge anEdge=TopoDS::Edge(myAISContext->SelectedShape()); \n"
891 " aFillet.Add(dlg.m_radius,anEdge); \n"
893 " TopoDS_Shape aNewShape = aFillet.Shape(); \n"
895 " S->Set(aNewShape); \n"
897 " myAISContext->Redisplay(S); \n"
900 CString aMsgStr (aMessage.ToCString());
901 myCResultDialog.SetTitle (CString ("Make a fillet"));
902 myCResultDialog.SetText (aMsgStr);
903 SetTitle (CString ("Make a fillet"));
906 // Create and display a circle with standard tools
907 void CViewer3dDoc::OnCircle()
909 gp_Ax2 anAx2 (gp_Pnt (0., 0., 0.), gp_Dir(0., 0., -1.));
910 Handle(Geom_Circle) aGeomCircle = new Geom_Circle (anAx2, 300);
912 // the lines above substitute
913 // GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.));
914 // Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value());
916 Handle(AIS_Circle) anAISCirc = new AIS_Circle(aGeomCircle);
917 myAISContext->Display (anAISCirc);
919 TCollection_AsciiString aMessage (" GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.)); \n"
921 " Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value()); \n"
923 " myAISContext->Display(anAISCirc); \n"
926 CString aMsgStr (aMessage.ToCString());
927 myCResultDialog.SetTitle (CString ("Create a circle"));
928 myCResultDialog.SetText (aMsgStr);
929 SetTitle (CString ("Create a circle"));
932 void CViewer3dDoc::OnLine()
934 // TODO: Add your command handler code here
935 gp_Lin aGpLin (gp_Pnt (0., 0., 0.), gp_Dir(1., 0., 0.));
936 Handle(Geom_Line) aGeomLin = new Geom_Line (aGpLin);
937 Handle(AIS_Line) anAISLine = new AIS_Line (aGeomLin);
938 myAISContext->Display (anAISLine);
940 TCollection_AsciiString aMessage (" gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.)); \n"
942 " Handle(Geom_Line) aLine = new Geom_Line(L); \n"
944 " Handle(AIS_Line) anAISLine = new AIS_Line(aLine); \n"
946 " myAISContext->Display(anAISLine); \n"
949 CString aMsgStr (aMessage.ToCString());
950 myCResultDialog.SetTitle (CString("Create a line"));
951 myCResultDialog.SetText (aMsgStr);
952 SetTitle (CString ("Create a line"));
955 void CViewer3dDoc::OnNbisos()
957 int aNumU = myAISContext->DefaultDrawer()->UIsoAspect()->Number();
958 int aNumV = myAISContext->DefaultDrawer()->VIsoAspect()->Number();
960 DlgIsos aDlg (NULL, aNumU, aNumV);
962 if (aDlg.DoModal() == IDOK)
964 myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber (aDlg.m_isou);
965 myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber (aDlg.m_isov);
967 TCollection_AsciiString aMessage (" myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(dlg.m_isou); \n"
969 " myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(dlg.m_isov); \n"
972 CString aMsgStr (aMessage.ToCString());
973 myCResultDialog.SetTitle (CString("Iso Aspect"));
974 myCResultDialog.SetText (aMsgStr);
975 SetTitle (CString ("Iso Aspect"));
979 BOOL CViewer3dDoc::OnNewDocument()
981 if (!CDocument::OnNewDocument())
984 // TODO: add reinitialization code here
985 // (SDI documents will reuse this document)
986 SetTitle(myPresentation->GetName());
988 myAISContext->EraseAll();
989 myAISContext->SetDisplayMode(AIS_Shaded);
991 POSITION pos = GetFirstViewPosition();
994 CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
1001 void CViewer3dDoc::OnFileNew()
1006 void CViewer3dDoc::InitViewButtons()
1008 POSITION pos = GetFirstViewPosition();
1011 CViewer3dView* pView = (CViewer3dView*) GetNextView(pos);
1012 pView->InitButtons();
1016 void CViewer3dDoc::OnTextureOn()
1018 isTextureSampleStarted = TRUE;
1022 void CViewer3dDoc::DoSample()
1026 HCURSOR hOldCursor = ::GetCursor();
1027 HCURSOR hNewCursor = AfxGetApp()->LoadStandardCursor(IDC_APPSTARTING);
1029 SetCursor(hNewCursor);
1033 myPresentation->DoSample();
1035 catch (Standard_Failure)
1037 Standard_SStream aSStream;
1038 aSStream << "An exception was caught: " << Standard_Failure::Caught() << ends;
1039 Standard_CString aMsg = aSStream.str().c_str();
1040 // aSStream.rdbuf()->freeze(0); // allow deletion of dynamic array
1041 AfxMessageBox (aMsg);
1044 SetCursor(hOldCursor);
1047 void CViewer3dDoc::OnBUTTONStart()
1049 myAISContext->EraseAll();
1050 myPresentation->FirstSample();
1054 void CViewer3dDoc::OnBUTTONEnd()
1056 myAISContext->EraseAll();
1057 myPresentation->LastSample();
1061 void CViewer3dDoc::OnBUTTONRepeat()
1066 void CViewer3dDoc::OnBUTTONNext()
1068 if (!myPresentation->AtLastSample())
1070 myPresentation->NextSample();
1075 void CViewer3dDoc::OnBUTTONPrev()
1077 if (!myPresentation->AtFirstSample())
1079 myPresentation->PrevSample();
1084 void CViewer3dDoc::OnUpdateBUTTONNext(CCmdUI* pCmdUI)
1086 if ( isTextureSampleStarted )
1087 pCmdUI->Enable (!myPresentation->AtLastSample());
1089 pCmdUI->Enable (FALSE);
1092 void CViewer3dDoc::OnUpdateBUTTONPrev(CCmdUI* pCmdUI)
1094 if ( isTextureSampleStarted )
1095 pCmdUI->Enable (!myPresentation->AtFirstSample());
1097 pCmdUI->Enable (FALSE);
1100 void CViewer3dDoc::OnUpdateBUTTONStart(CCmdUI* pCmdUI)
1102 pCmdUI->Enable (isTextureSampleStarted);
1105 void CViewer3dDoc::OnUpdateBUTTONRepeat(CCmdUI* pCmdUI)
1107 pCmdUI->Enable (isTextureSampleStarted);
1110 void CViewer3dDoc::OnUpdateBUTTONEnd(CCmdUI* pCmdUI)
1112 pCmdUI->Enable (isTextureSampleStarted);
1115 void CViewer3dDoc::OnDumpView()
1117 CFileDialog aDlg (false, "gif", "OCCView.gif", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
1118 "GIF Files (*.GIF)|*.gif|"
1119 "BMP Files (*.BMP)|*.bmp|"
1120 "PNG Files (*.PNG)|*.png|"
1121 "JPEG Files (*.JPG)|*.jpg|"
1122 "PPM Files (*.PPM)|*.ppm|"
1123 "TIFF Files (*.TIFF)|*.tiff|"
1124 "TGA Files (*.TGA)|*.tga|"
1125 "EXR Files (*.EXR)|*.exr||", NULL);
1126 if (aDlg.DoModal() != IDOK)
1131 for (POSITION aPos = GetFirstViewPosition(); aPos != NULL;)
1133 CViewer3dView* pView = (CViewer3dView* )GetNextView (aPos);
1134 pView->UpdateWindow();
1136 myViewer->InitActiveViews();
1137 Handle(V3d_View) aView = myViewer->ActiveView();
1138 aView->Dump (aDlg.GetPathName());
1141 void CViewer3dDoc::Start()
1143 myPresentation->Init();
1147 void CViewer3dDoc::Fit()
1149 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
1150 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
1151 CViewer3dView *pView = (CViewer3dView *) pChild->GetActiveView();