1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Standard_Stream.hxx>
19 #include <ViewerTest.hxx>
20 #include <ViewerTest_CmdParser.hxx>
23 #include <TopLoc_Location.hxx>
24 #include <TopTools_HArray1OfShape.hxx>
25 #include <TColStd_HArray1OfTransient.hxx>
26 #include <TColStd_SequenceOfAsciiString.hxx>
27 #include <TColStd_HSequenceOfAsciiString.hxx>
28 #include <TColStd_MapOfTransient.hxx>
29 #include <OSD_Timer.hxx>
30 #include <Geom_Axis2Placement.hxx>
31 #include <Geom_Axis1Placement.hxx>
32 #include <gp_Trsf.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include <StdSelect_ShapeTypeFilter.hxx>
37 #include <AIS_ColoredShape.hxx>
38 #include <AIS_InteractiveObject.hxx>
39 #include <AIS_Trihedron.hxx>
40 #include <AIS_Axis.hxx>
41 #include <AIS_Relation.hxx>
42 #include <AIS_TypeFilter.hxx>
43 #include <AIS_SignatureFilter.hxx>
44 #include <AIS_ListOfInteractive.hxx>
45 #include <AIS_ListIteratorOfListOfInteractive.hxx>
46 #include <Aspect_InteriorStyle.hxx>
47 #include <Aspect_Window.hxx>
48 #include <Graphic3d_AspectFillArea3d.hxx>
49 #include <Graphic3d_AspectLine3d.hxx>
50 #include <Graphic3d_CStructure.hxx>
51 #include <Graphic3d_Texture2Dmanual.hxx>
52 #include <Graphic3d_GraphicDriver.hxx>
53 #include <Image_AlienPixMap.hxx>
54 #include <OSD_File.hxx>
55 #include <Prs3d_Drawer.hxx>
56 #include <Prs3d_ShadingAspect.hxx>
57 #include <Prs3d_IsoAspect.hxx>
58 #include <Prs3d_PointAspect.hxx>
59 #include <Select3D_SensitiveWire.hxx>
60 #include <Select3D_SensitivePrimitiveArray.hxx>
61 #include <SelectMgr_EntityOwner.hxx>
62 #include <StdSelect_BRepOwner.hxx>
63 #include <StdSelect_ViewerSelector3d.hxx>
64 #include <TopTools_MapOfShape.hxx>
65 #include <ViewerTest_AutoUpdater.hxx>
69 #include <Draw_Interpretor.hxx>
70 #include <TCollection_AsciiString.hxx>
71 #include <Draw_PluginMacro.hxx>
73 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
75 #include <Quantity_Color.hxx>
76 #include <Quantity_NameOfColor.hxx>
78 #include <Graphic3d_NameOfMaterial.hxx>
80 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
81 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
82 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
84 //=======================================================================
85 //function : GetColorFromName
86 //purpose : get the Quantity_NameOfColor from a string
87 //=======================================================================
89 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
91 Quantity_NameOfColor aColor = DEFAULT_COLOR;
92 Quantity_Color::ColorFromName (theName, aColor);
96 //=======================================================================
97 //function : ParseColor
99 //=======================================================================
101 Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
102 const char** theArgVec,
103 Quantity_Color& theColor)
105 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
107 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
112 else if (theArgNb >= 3)
114 const TCollection_AsciiString anRgbStr[3] =
120 if (!anRgbStr[0].IsRealValue()
121 || !anRgbStr[1].IsRealValue()
122 || !anRgbStr[2].IsRealValue())
127 Graphic3d_Vec4d anRgb;
128 anRgb.x() = anRgbStr[0].RealValue();
129 anRgb.y() = anRgbStr[1].RealValue();
130 anRgb.z() = anRgbStr[2].RealValue();
131 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
132 || anRgb.y() < 0.0 || anRgb.y() > 1.0
133 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
135 std::cout << "Error: RGB color values should be within range 0..1!\n";
139 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
146 //=======================================================================
147 //function : ParseOnOff
149 //=======================================================================
150 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
151 Standard_Boolean& theIsOn)
153 TCollection_AsciiString aFlag(theArg);
158 theIsOn = Standard_True;
159 return Standard_True;
161 else if (aFlag == "off"
164 theIsOn = Standard_False;
165 return Standard_True;
167 return Standard_False;
170 //=======================================================================
171 //function : GetSelectedShapes
173 //=======================================================================
174 void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
176 for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
178 TopoDS_Shape aShape = GetAISContext()->SelectedShape();
179 if (!aShape.IsNull())
181 theSelectedShapes.Append (aShape);
186 //=======================================================================
187 //function : ParseLineType
189 //=======================================================================
190 Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
191 Aspect_TypeOfLine& theType)
193 TCollection_AsciiString aTypeStr (theArg);
194 aTypeStr.LowerCase();
195 if (aTypeStr == "empty")
197 theType = Aspect_TOL_EMPTY;
199 else if (aTypeStr == "solid")
201 theType = Aspect_TOL_SOLID;
203 else if (aTypeStr == "dot")
205 theType = Aspect_TOL_DOT;
207 else if (aTypeStr == "dash")
209 theType = Aspect_TOL_DASH;
211 else if (aTypeStr == "dotdash")
213 theType = Aspect_TOL_DOTDASH;
217 const int aTypeInt = Draw::Atoi (theArg);
218 if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
220 return Standard_False;
222 theType = (Aspect_TypeOfLine )aTypeInt;
224 return Standard_True;
227 //=======================================================================
228 //function : ParseMarkerType
230 //=======================================================================
231 Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
232 Aspect_TypeOfMarker& theType,
233 Handle(Image_PixMap)& theImage)
236 TCollection_AsciiString aTypeStr (theArg);
237 aTypeStr.LowerCase();
238 if (aTypeStr == "empty")
240 theType = Aspect_TOM_EMPTY;
242 else if (aTypeStr == "point"
246 theType = Aspect_TOM_POINT;
248 else if (aTypeStr == "plus"
251 theType = Aspect_TOM_PLUS;
253 else if (aTypeStr == "star"
256 theType = Aspect_TOM_STAR;
258 else if (aTypeStr == "cross"
261 theType = Aspect_TOM_X;
263 else if (aTypeStr == "circle"
266 theType = Aspect_TOM_O;
268 else if (aTypeStr == "pointincircle")
270 theType = Aspect_TOM_O_POINT;
272 else if (aTypeStr == "plusincircle")
274 theType = Aspect_TOM_O_PLUS;
276 else if (aTypeStr == "starincircle")
278 theType = Aspect_TOM_O_STAR;
280 else if (aTypeStr == "crossincircle"
281 || aTypeStr == "xcircle")
283 theType = Aspect_TOM_O_X;
285 else if (aTypeStr == "ring1")
287 theType = Aspect_TOM_RING1;
289 else if (aTypeStr == "ring2")
291 theType = Aspect_TOM_RING2;
293 else if (aTypeStr == "ring"
294 || aTypeStr == "ring3")
296 theType = Aspect_TOM_RING3;
298 else if (aTypeStr == "ball")
300 theType = Aspect_TOM_BALL;
302 else if (aTypeStr.IsIntegerValue())
304 const int aTypeInt = aTypeStr.IntegerValue();
305 if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED)
307 return Standard_False;
309 theType = (Aspect_TypeOfMarker )aTypeInt;
313 theType = Aspect_TOM_USERDEFINED;
314 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
315 if (!anImage->Load (theArg))
317 return Standard_False;
319 if (anImage->Format() == Image_Format_Gray)
321 anImage->SetFormat (Image_Format_Alpha);
323 else if (anImage->Format() == Image_Format_GrayF)
325 anImage->SetFormat (Image_Format_AlphaF);
329 return Standard_True;
332 //=======================================================================
333 //function : ParseShadingModel
335 //=======================================================================
336 Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg,
337 Graphic3d_TypeOfShadingModel& theModel)
339 TCollection_AsciiString aTypeStr (theArg);
340 aTypeStr.LowerCase();
341 if (aTypeStr == "unlit"
342 || aTypeStr == "color"
343 || aTypeStr == "none")
345 theModel = Graphic3d_TOSM_UNLIT;
347 else if (aTypeStr == "flat"
348 || aTypeStr == "facet")
350 theModel = Graphic3d_TOSM_FACET;
352 else if (aTypeStr == "gouraud"
353 || aTypeStr == "vertex"
354 || aTypeStr == "vert")
356 theModel = Graphic3d_TOSM_VERTEX;
358 else if (aTypeStr == "phong"
359 || aTypeStr == "fragment"
360 || aTypeStr == "frag"
361 || aTypeStr == "pixel")
363 theModel = Graphic3d_TOSM_FRAGMENT;
365 else if (aTypeStr == "default"
366 || aTypeStr == "def")
368 theModel = Graphic3d_TOSM_DEFAULT;
370 else if (aTypeStr.IsIntegerValue())
372 const int aTypeInt = aTypeStr.IntegerValue();
373 if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
375 return Standard_False;
377 theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
381 return Standard_False;
383 return Standard_True;
386 //=======================================================================
387 //function : GetTypeNames
389 //=======================================================================
390 static const char** GetTypeNames()
392 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
393 "Shape","ConnectedShape","MultiConn.Shape",
394 "ConnectedInter.","MultiConn.",
395 "Constraint","Dimension"};
396 static const char** ThePointer = names;
400 //=======================================================================
401 //function : GetTypeAndSignfromString
403 //=======================================================================
404 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
406 const char ** thefullnames = GetTypeNames();
407 Standard_Integer index(-1);
409 for(Standard_Integer i=0;i<=13 && index==-1;i++)
410 if(!strcasecmp(name,thefullnames[i]))
414 TheType = AIS_KOI_None;
420 TheType = AIS_KOI_Datum;
424 TheType = AIS_KOI_Shape;
428 TheType = AIS_KOI_Object;
432 TheType = AIS_KOI_Relation;
441 #include <Draw_Interpretor.hxx>
443 #include <Draw_Appli.hxx>
447 #include <TCollection_AsciiString.hxx>
448 #include <V3d_Viewer.hxx>
449 #include <V3d_View.hxx>
452 #include <AIS_InteractiveContext.hxx>
453 #include <AIS_Shape.hxx>
454 #include <AIS_DisplayMode.hxx>
455 #include <TColStd_MapOfInteger.hxx>
456 #include <AIS_MapOfInteractive.hxx>
457 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
458 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
459 #include <ViewerTest_EventManager.hxx>
461 #include <TopoDS_Solid.hxx>
462 #include <BRepTools.hxx>
463 #include <BRep_Builder.hxx>
464 #include <TopAbs_ShapeEnum.hxx>
466 #include <TopoDS.hxx>
467 #include <BRep_Tool.hxx>
470 #include <Draw_Window.hxx>
471 #include <AIS_ListIteratorOfListOfInteractive.hxx>
472 #include <AIS_ListOfInteractive.hxx>
473 #include <AIS_DisplayMode.hxx>
474 #include <TopTools_ListOfShape.hxx>
475 #include <BRepOffsetAPI_MakeThickSolid.hxx>
477 //==============================================================================
478 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
479 //==============================================================================
480 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
481 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
485 //=======================================================================
488 //=======================================================================
489 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
490 const Handle(AIS_InteractiveObject)& theObject,
491 const Standard_Boolean theToUpdate,
492 const Standard_Boolean theReplaceIfExists)
494 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
495 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
498 std::cout << "Error: AIS context is not available.\n";
499 return Standard_False;
502 if (aMap.IsBound2 (theName))
504 if (!theReplaceIfExists)
506 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
507 << "Please use another name.\n";
508 return Standard_False;
511 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
512 if (!anOldObj.IsNull())
514 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
516 aMap.UnBind2 (theName);
519 if (theObject.IsNull())
521 // object with specified name has been already unbound
522 return Standard_True;
525 // unbind AIS object if it was bound with another name
526 aMap.UnBind1 (theObject);
528 // can be registered without rebinding
529 aMap.Bind (theObject, theName);
530 aCtx->Display (theObject, theToUpdate);
531 return Standard_True;
534 //! Alias for ViewerTest::Display(), compatibility with old code.
535 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
536 const Handle(AIS_InteractiveObject)& theObject,
537 Standard_Boolean theReplaceIfExists = Standard_True)
539 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
542 static TColStd_MapOfInteger theactivatedmodes(8);
543 static TColStd_ListOfTransient theEventMgrs;
545 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
546 const Handle(AIS_InteractiveContext)& Ctx)
548 theEventMgrs.Clear();
549 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
552 static Handle(V3d_View)& a3DView()
554 static Handle(V3d_View) Viou;
559 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
560 static Handle(AIS_InteractiveContext) aContext;
564 const Handle(V3d_View)& ViewerTest::CurrentView()
568 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
573 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
575 return TheAISContext();
578 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
580 TheAISContext() = aCtx;
581 ViewerTest::ResetEventManager();
584 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
586 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
589 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
591 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
595 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
596 theEventMgrs.Prepend(EM);
599 void ViewerTest::UnsetEventManager()
601 theEventMgrs.RemoveFirst();
605 void ViewerTest::ResetEventManager()
607 const Handle(V3d_View) aView = ViewerTest::CurrentView();
608 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
611 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
613 Handle(ViewerTest_EventManager) EM;
614 if(theEventMgrs.IsEmpty()) return EM;
615 Handle(Standard_Transient) Tr = theEventMgrs.First();
616 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
620 //=======================================================================
621 //function : Get Context and active view
623 //=======================================================================
624 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
625 Handle(V3d_View)& theView)
627 theCtx = ViewerTest::GetAISContext();
628 theView = ViewerTest::CurrentView();
632 std::cout << "Error: cannot find an active view!\n";
633 return Standard_False;
635 return Standard_True;
638 //==============================================================================
639 //function : GetShapeFromName
640 //purpose : Compute an Shape from a draw variable or a file name
641 //==============================================================================
643 static TopoDS_Shape GetShapeFromName(const char* name)
645 TopoDS_Shape S = DBRep::Get(name);
648 BRep_Builder aBuilder;
649 BRepTools::Read( S, name, aBuilder);
655 //==============================================================================
656 //function : GetAISShapeFromName
657 //purpose : Compute an AIS_Shape from a draw variable or a file name
658 //==============================================================================
659 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
661 Handle(AIS_Shape) retsh;
663 if(GetMapOfAIS().IsBound2(name)){
664 const Handle(AIS_InteractiveObject) IO =
665 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
667 if(IO->Type()==AIS_KOI_Shape) {
668 if(IO->Signature()==0){
669 retsh = Handle(AIS_Shape)::DownCast (IO);
672 cout << "an Object which is not an AIS_Shape "
673 "already has this name!!!"<<endl;
680 TopoDS_Shape S = GetShapeFromName(name);
682 retsh = new AIS_Shape(S);
688 //==============================================================================
690 //purpose : Remove all the object from the viewer
691 //==============================================================================
692 void ViewerTest::Clear()
694 if (a3DView().IsNull())
699 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
700 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
702 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
703 if (anObj->GetContext() != TheAISContext())
708 std::cout << "Remove " << anObjIter.Key2() << std::endl;
709 TheAISContext()->Remove (anObj, Standard_False);
710 aListRemoved.Append (anObj);
713 TheAISContext()->RebuildSelectionStructs();
714 TheAISContext()->UpdateCurrentViewer();
715 if (aListRemoved.Size() == GetMapOfAIS().Extent())
717 GetMapOfAIS().Clear();
721 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
723 GetMapOfAIS().UnBind1 (anObjIter.Value());
728 //==============================================================================
729 //function : CopyIsoAspect
730 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
731 //==============================================================================
732 static Handle(Prs3d_IsoAspect) CopyIsoAspect
733 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
734 const Standard_Integer theNbIsos)
736 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
737 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
738 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
740 Handle(Prs3d_IsoAspect) aResult =
741 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
746 //==============================================================================
748 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
749 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
750 //==============================================================================
751 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
753 if (TheAISContext().IsNull()) {
754 di << argv[0] << " Call 'vinit' before!\n";
759 di << "Current number of isos : " <<
760 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
761 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
762 di << "IsoOnPlane mode is " <<
763 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
764 di << "IsoOnTriangulation mode is " <<
765 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
769 Standard_Integer aLastInd = argc - 1;
770 Standard_Boolean isChanged = Standard_False;
771 Standard_Integer aNbUIsos = 0;
772 Standard_Integer aNbVIsos = 0;
775 Standard_Boolean isIsoOnPlane = Standard_False;
777 if (strcmp(argv[aLastInd], "1") == 0) {
778 isIsoOnPlane = Standard_True;
779 isChanged = Standard_True;
780 } else if (strcmp(argv[aLastInd], "0") == 0) {
781 isIsoOnPlane = Standard_False;
782 isChanged = Standard_True;
786 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
787 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
790 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
791 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
793 TheAISContext()->IsoOnPlane(isIsoOnPlane);
796 // If there are no shapes provided set the default numbers.
797 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
798 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
805 for (i = 1; i <= aLastInd; i++) {
806 TCollection_AsciiString name(argv[i]);
807 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
810 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
811 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
812 const Handle(AIS_InteractiveObject) aShape =
813 Handle(AIS_InteractiveObject)::DownCast (anObj);
814 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
815 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
816 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
819 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
820 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
821 TheAISContext()->SetLocalAttributes
822 (aShape, CurDrawer, Standard_False);
823 TheAISContext()->Redisplay (aShape, Standard_False);
825 di << "Number of isos for " << argv[i] << " : "
826 << aUIso->Number() << " " << aVIso->Number() << "\n";
829 di << argv[i] << ": Not an AIS interactive object!\n";
832 di << argv[i] << ": Use 'vdisplay' before\n";
837 TheAISContext()->UpdateCurrentViewer();
843 static Standard_Integer VDispSensi (Draw_Interpretor& ,
844 Standard_Integer theArgNb,
849 std::cout << "Error: wrong syntax!\n";
853 Handle(AIS_InteractiveContext) aCtx;
854 Handle(V3d_View) aView;
855 if (!getCtxAndView (aCtx, aView))
860 aCtx->DisplayActiveSensitive (aView);
865 static Standard_Integer VClearSensi (Draw_Interpretor& ,
866 Standard_Integer theArgNb,
871 std::cout << "Error: wrong syntax!\n";
875 Handle(AIS_InteractiveContext) aCtx;
876 Handle(V3d_View) aView;
877 if (!getCtxAndView (aCtx, aView))
881 aCtx->ClearActiveSensitive (aView);
885 //==============================================================================
887 //purpose : To list the displayed object with their attributes
888 //==============================================================================
889 static int VDir (Draw_Interpretor& theDI,
893 if (!a3DView().IsNull())
898 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
899 anIter.More(); anIter.Next())
901 theDI << "\t" << anIter.Key2().ToCString() << "\n";
906 //! Auxiliary enumeration
907 enum ViewerTest_StereoPair
909 ViewerTest_SP_Single,
910 ViewerTest_SP_SideBySide,
911 ViewerTest_SP_OverUnder
914 //==============================================================================
916 //purpose : To dump the active view snapshot to image file
917 //==============================================================================
918 static Standard_Integer VDump (Draw_Interpretor& theDI,
919 Standard_Integer theArgNb,
920 Standard_CString* theArgVec)
924 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
928 Standard_Integer anArgIter = 1;
929 Standard_CString aFilePath = theArgVec[anArgIter++];
930 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
931 V3d_ImageDumpOptions aParams;
932 aParams.BufferType = Graphic3d_BT_RGB;
933 aParams.StereoOptions = V3d_SDO_MONO;
934 for (; anArgIter < theArgNb; ++anArgIter)
936 TCollection_AsciiString anArg (theArgVec[anArgIter]);
938 if (anArg == "-buffer")
940 if (++anArgIter >= theArgNb)
942 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
946 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
948 if (aBufArg == "rgba")
950 aParams.BufferType = Graphic3d_BT_RGBA;
952 else if (aBufArg == "rgb")
954 aParams.BufferType = Graphic3d_BT_RGB;
956 else if (aBufArg == "depth")
958 aParams.BufferType = Graphic3d_BT_Depth;
962 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
966 else if (anArg == "-stereo")
968 if (++anArgIter >= theArgNb)
970 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
974 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
975 aStereoArg.LowerCase();
976 if (aStereoArg == "l"
977 || aStereoArg == "left")
979 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
981 else if (aStereoArg == "r"
982 || aStereoArg == "right")
984 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
986 else if (aStereoArg == "mono")
988 aParams.StereoOptions = V3d_SDO_MONO;
990 else if (aStereoArg == "blended"
991 || aStereoArg == "blend"
992 || aStereoArg == "stereo")
994 aParams.StereoOptions = V3d_SDO_BLENDED;
996 else if (aStereoArg == "sbs"
997 || aStereoArg == "sidebyside")
999 aStereoPair = ViewerTest_SP_SideBySide;
1001 else if (aStereoArg == "ou"
1002 || aStereoArg == "overunder")
1004 aStereoPair = ViewerTest_SP_OverUnder;
1008 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
1012 else if (anArg == "-rgba"
1015 aParams.BufferType = Graphic3d_BT_RGBA;
1017 else if (anArg == "-rgb"
1020 aParams.BufferType = Graphic3d_BT_RGB;
1022 else if (anArg == "-depth"
1023 || anArg == "depth")
1025 aParams.BufferType = Graphic3d_BT_Depth;
1027 else if (anArg == "-width"
1029 || anArg == "sizex")
1031 if (aParams.Width != 0)
1033 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1036 else if (++anArgIter >= theArgNb)
1038 std::cout << "Error: integer value is expected right after 'width'\n";
1041 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1043 else if (anArg == "-height"
1044 || anArg == "height"
1045 || anArg == "-sizey")
1047 if (aParams.Height != 0)
1049 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1052 else if (++anArgIter >= theArgNb)
1054 std::cout << "Error: integer value is expected right after 'height'\n";
1057 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1059 else if (anArg == "-tile"
1060 || anArg == "-tilesize")
1062 if (++anArgIter >= theArgNb)
1064 std::cout << "Error: integer value is expected right after 'tileSize'\n";
1067 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1071 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
1075 if ((aParams.Width <= 0 && aParams.Height > 0)
1076 || (aParams.Width > 0 && aParams.Height <= 0))
1078 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
1082 Handle(V3d_View) aView = ViewerTest::CurrentView();
1085 std::cout << "Error: cannot find an active view!\n";
1089 if (aParams.Width <= 0 || aParams.Height <= 0)
1091 aView->Window()->Size (aParams.Width, aParams.Height);
1094 Image_AlienPixMap aPixMap;
1095 Image_Format aFormat = Image_Format_UNKNOWN;
1096 switch (aParams.BufferType)
1098 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1099 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1100 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1101 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1104 switch (aStereoPair)
1106 case ViewerTest_SP_Single:
1108 if (!aView->ToPixMap (aPixMap, aParams))
1110 theDI << "Fail: view dump failed!\n";
1113 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1114 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1116 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1117 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1121 case ViewerTest_SP_SideBySide:
1123 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1125 theDI << "Fail: not enough memory for image allocation!\n";
1129 Image_PixMap aPixMapL, aPixMapR;
1130 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1131 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1132 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1133 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1135 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1136 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1137 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1138 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1141 theDI << "Fail: view dump failed!\n";
1146 case ViewerTest_SP_OverUnder:
1148 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1150 theDI << "Fail: not enough memory for image allocation!\n";
1154 Image_PixMap aPixMapL, aPixMapR;
1155 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1156 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1157 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1158 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1160 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1161 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1162 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1163 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1166 theDI << "Fail: view dump failed!\n";
1173 if (!aPixMap.Save (aFilePath))
1175 theDI << "Fail: image can not be saved!\n";
1180 enum TypeOfDispOperation
1182 TypeOfDispOperation_SetDispMode,
1183 TypeOfDispOperation_UnsetDispMode
1186 //! Displays,Erase...
1187 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1188 const Standard_Integer theMode,
1189 const TypeOfDispOperation theType,
1190 const Standard_Boolean theToUpdate)
1192 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1195 case TypeOfDispOperation_SetDispMode:
1197 if (!thePrs.IsNull())
1199 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1203 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1207 case TypeOfDispOperation_UnsetDispMode:
1209 if (!thePrs.IsNull())
1211 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1215 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1222 //=======================================================================
1225 //=======================================================================
1226 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1231 std::cout << "Syntax error: wrong number of arguments\n";
1235 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1236 ? TypeOfDispOperation_UnsetDispMode
1237 : TypeOfDispOperation_SetDispMode;
1238 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1239 if (aType == TypeOfDispOperation_UnsetDispMode)
1243 if (aCtx->NbSelected() == 0)
1245 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1249 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1251 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1254 aCtx->UpdateCurrentViewer();
1258 TCollection_AsciiString aName = argv[1];
1259 if (GetMapOfAIS().IsBound2 (aName))
1261 Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1264 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1271 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1272 if (aCtx->NbSelected() == 0
1273 && aType == TypeOfDispOperation_SetDispMode)
1275 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1277 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1279 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1281 aCtx->UpdateCurrentViewer();
1285 Handle(AIS_InteractiveObject) aPrs;
1286 TCollection_AsciiString aName (argv[1]);
1287 if (GetMapOfAIS().IsBound2 (aName))
1289 aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1293 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1300 //=======================================================================
1303 //=======================================================================
1304 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1306 if(argc==1) return 1;
1307 Standard_Integer On = Draw::Atoi(argv[1]);
1308 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1312 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1313 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1314 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1318 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1322 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1326 Ctx->UpdateCurrentViewer();
1329 Handle(AIS_InteractiveObject) IO;
1330 TCollection_AsciiString name = argv[2];
1331 if(GetMapOfAIS().IsBound2(name)){
1332 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1335 Ctx->SubIntensityOn(IO, Standard_True);
1337 Ctx->SubIntensityOff(IO, Standard_True);
1345 //! Auxiliary class to iterate presentations from different collections.
1346 class ViewTest_PrsIter
1350 //! Create and initialize iterator object.
1351 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1352 : mySource (IterSource_All)
1354 NCollection_Sequence<TCollection_AsciiString> aNames;
1355 if (!theName.IsEmpty())
1356 aNames.Append (theName);
1360 //! Create and initialize iterator object.
1361 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1362 : mySource (IterSource_All)
1367 //! Initialize the iterator.
1368 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1370 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1372 mySelIter.Nullify();
1373 myCurrent.Nullify();
1374 myCurrentTrs.Nullify();
1375 if (!mySeq.IsEmpty())
1377 mySource = IterSource_List;
1378 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1380 else if (aCtx->NbSelected() > 0)
1382 mySource = IterSource_Selected;
1384 mySelIter->InitSelected();
1388 mySource = IterSource_All;
1389 myMapIter.Initialize (GetMapOfAIS());
1394 const TCollection_AsciiString& CurrentName() const
1396 return myCurrentName;
1399 const Handle(AIS_InteractiveObject)& Current() const
1404 const Handle(Standard_Transient)& CurrentTrs() const
1406 return myCurrentTrs;
1409 //! @return true if iterator points to valid object within collection
1410 Standard_Boolean More() const
1414 case IterSource_All: return myMapIter.More();
1415 case IterSource_List: return mySeqIter.More();
1416 case IterSource_Selected: return mySelIter->MoreSelected();
1418 return Standard_False;
1421 //! Go to the next item.
1424 myCurrentName.Clear();
1425 myCurrentTrs.Nullify();
1426 myCurrent.Nullify();
1429 case IterSource_All:
1434 case IterSource_List:
1439 case IterSource_Selected:
1441 mySelIter->NextSelected();
1454 case IterSource_All:
1456 if (myMapIter.More())
1458 myCurrentName = myMapIter.Key2();
1459 myCurrentTrs = myMapIter.Key1();
1460 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1464 case IterSource_List:
1466 if (mySeqIter.More())
1468 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1470 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1473 myCurrentName = mySeqIter.Value();
1474 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1475 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1479 case IterSource_Selected:
1481 if (mySelIter->MoreSelected())
1483 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1484 myCurrent = mySelIter->SelectedInteractive();
1502 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1503 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1504 NCollection_Sequence<TCollection_AsciiString> mySeq;
1505 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1507 TCollection_AsciiString myCurrentName;//!< current item name
1508 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1509 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1511 IterSource mySource; //!< iterated collection
1515 //==============================================================================
1516 //function : VInteriorStyle
1517 //purpose : sets interior style of the a selected or named or displayed shape
1518 //==============================================================================
1519 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1520 Standard_Integer theArgNb,
1521 const char** theArgVec)
1523 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1524 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1527 std::cerr << "Error: no active view!\n";
1531 Standard_Integer anArgIter = 1;
1532 for (; anArgIter < theArgNb; ++anArgIter)
1534 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1539 TCollection_AsciiString aName;
1540 if (theArgNb - anArgIter == 2)
1542 aName = theArgVec[anArgIter++];
1544 else if (theArgNb - anArgIter != 1)
1546 std::cout << "Error: wrong number of arguments! See usage:\n";
1547 theDI.PrintHelp (theArgVec[0]);
1550 Aspect_InteriorStyle anInterStyle = Aspect_IS_SOLID;
1551 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1552 aStyleArg.LowerCase();
1553 if (aStyleArg == "empty")
1555 anInterStyle = Aspect_IS_EMPTY;
1557 else if (aStyleArg == "hollow")
1559 anInterStyle = Aspect_IS_HOLLOW;
1561 else if (aStyleArg == "hatch")
1563 anInterStyle = Aspect_IS_HATCH;
1565 else if (aStyleArg == "solid")
1567 anInterStyle = Aspect_IS_SOLID;
1569 else if (aStyleArg == "hiddenline")
1571 anInterStyle = Aspect_IS_HIDDENLINE;
1573 else if (aStyleArg == "point")
1575 anInterStyle = Aspect_IS_POINT;
1579 const Standard_Integer anIntStyle = aStyleArg.IntegerValue();
1580 if (anIntStyle < Aspect_IS_EMPTY
1581 || anIntStyle > Aspect_IS_POINT)
1583 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1584 << Aspect_IS_POINT << " (Aspect_IS_POINT)]\n";
1587 anInterStyle = (Aspect_InteriorStyle )anIntStyle;
1590 if (!aName.IsEmpty()
1591 && !GetMapOfAIS().IsBound2 (aName))
1593 std::cout << "Error: object " << aName << " is not displayed!\n";
1597 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1599 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1602 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1603 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1604 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1605 aFillAspect->SetInteriorStyle (anInterStyle);
1606 if (anInterStyle == Aspect_IS_HATCH
1607 && aFillAspect->HatchStyle().IsNull())
1609 aFillAspect->SetHatchStyle (Aspect_HS_VERTICAL);
1611 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1617 //! Auxiliary structure for VAspects
1618 struct ViewerTest_AspectsChangeSet
1620 Standard_Integer ToSetVisibility;
1621 Standard_Integer Visibility;
1623 Standard_Integer ToSetColor;
1624 Quantity_Color Color;
1626 Standard_Integer ToSetLineWidth;
1627 Standard_Real LineWidth;
1629 Standard_Integer ToSetTypeOfLine;
1630 Aspect_TypeOfLine TypeOfLine;
1632 Standard_Integer ToSetTypeOfMarker;
1633 Aspect_TypeOfMarker TypeOfMarker;
1634 Handle(Image_PixMap) MarkerImage;
1636 Standard_Integer ToSetMarkerSize;
1637 Standard_Real MarkerSize;
1639 Standard_Integer ToSetTransparency;
1640 Standard_Real Transparency;
1642 Standard_Integer ToSetAlphaMode;
1643 Graphic3d_AlphaMode AlphaMode;
1644 Standard_ShortReal AlphaCutoff;
1646 Standard_Integer ToSetMaterial;
1647 Graphic3d_NameOfMaterial Material;
1648 TCollection_AsciiString MatName;
1650 NCollection_Sequence<TopoDS_Shape> SubShapes;
1652 Standard_Integer ToSetShowFreeBoundary;
1653 Standard_Integer ToSetFreeBoundaryWidth;
1654 Standard_Real FreeBoundaryWidth;
1655 Standard_Integer ToSetFreeBoundaryColor;
1656 Quantity_Color FreeBoundaryColor;
1658 Standard_Integer ToEnableIsoOnTriangulation;
1660 Standard_Integer ToSetMaxParamValue;
1661 Standard_Real MaxParamValue;
1663 Standard_Integer ToSetSensitivity;
1664 Standard_Integer SelectionMode;
1665 Standard_Integer Sensitivity;
1667 Standard_Integer ToSetHatch;
1668 Standard_Integer StdHatchStyle;
1669 TCollection_AsciiString PathToHatchPattern;
1671 Standard_Integer ToSetShadingModel;
1672 Graphic3d_TypeOfShadingModel ShadingModel;
1673 TCollection_AsciiString ShadingModelName;
1675 //! Empty constructor
1676 ViewerTest_AspectsChangeSet()
1677 : ToSetVisibility (0),
1680 Color (DEFAULT_COLOR),
1683 ToSetTypeOfLine (0),
1684 TypeOfLine (Aspect_TOL_SOLID),
1685 ToSetTypeOfMarker (0),
1686 TypeOfMarker (Aspect_TOM_PLUS),
1687 ToSetMarkerSize (0),
1689 ToSetTransparency (0),
1692 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1695 Material (Graphic3d_NOM_DEFAULT),
1696 ToSetShowFreeBoundary (0),
1697 ToSetFreeBoundaryWidth (0),
1698 FreeBoundaryWidth (1.0),
1699 ToSetFreeBoundaryColor (0),
1700 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1701 ToEnableIsoOnTriangulation (-1),
1702 ToSetMaxParamValue (0),
1703 MaxParamValue (500000),
1704 ToSetSensitivity (0),
1709 ToSetShadingModel (0),
1710 ShadingModel (Graphic3d_TOSM_DEFAULT)
1713 //! @return true if no changes have been requested
1714 Standard_Boolean IsEmpty() const
1716 return ToSetVisibility == 0
1717 && ToSetLineWidth == 0
1718 && ToSetTransparency == 0
1719 && ToSetAlphaMode == 0
1721 && ToSetMaterial == 0
1722 && ToSetShowFreeBoundary == 0
1723 && ToSetFreeBoundaryColor == 0
1724 && ToSetFreeBoundaryWidth == 0
1725 && ToSetMaxParamValue == 0
1726 && ToSetSensitivity == 0
1728 && ToSetShadingModel == 0;
1731 //! @return true if properties are valid
1732 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1734 Standard_Boolean isOk = Standard_True;
1735 if (Visibility != 0 && Visibility != 1)
1737 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1738 isOk = Standard_False;
1740 if (LineWidth <= 0.0
1741 || LineWidth > 10.0)
1743 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1744 isOk = Standard_False;
1746 if (Transparency < 0.0
1747 || Transparency > 1.0)
1749 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1750 isOk = Standard_False;
1753 && ToSetTransparency != 0)
1755 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1756 isOk = Standard_False;
1758 if (ToSetAlphaMode == 1
1759 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1761 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1762 isOk = Standard_False;
1764 if (ToSetMaterial == 1
1765 && Material == Graphic3d_NOM_DEFAULT)
1767 std::cout << "Error: unknown material " << MatName << ".\n";
1768 isOk = Standard_False;
1770 if (FreeBoundaryWidth <= 0.0
1771 || FreeBoundaryWidth > 10.0)
1773 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1774 isOk = Standard_False;
1776 if (MaxParamValue < 0.0)
1778 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1779 isOk = Standard_False;
1781 if (Sensitivity <= 0 && ToSetSensitivity)
1783 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1784 isOk = Standard_False;
1786 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1788 std::cout << "Error: hatch style must be specified\n";
1789 isOk = Standard_False;
1791 if (ToSetShadingModel == 1
1792 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
1794 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1795 isOk = Standard_False;
1802 //==============================================================================
1803 //function : VAspects
1805 //==============================================================================
1806 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1807 Standard_Integer theArgNb,
1808 const char** theArgVec)
1810 TCollection_AsciiString aCmdName (theArgVec[0]);
1811 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1812 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1815 std::cerr << "Error: no active view!\n";
1819 Standard_Integer anArgIter = 1;
1820 Standard_Boolean isDefaults = Standard_False;
1821 NCollection_Sequence<TCollection_AsciiString> aNames;
1822 for (; anArgIter < theArgNb; ++anArgIter)
1824 TCollection_AsciiString anArg = theArgVec[anArgIter];
1825 if (anUpdateTool.parseRedrawMode (anArg))
1829 else if (!anArg.IsEmpty()
1830 && anArg.Value (1) != '-')
1832 aNames.Append (anArg);
1836 if (anArg == "-defaults")
1838 isDefaults = Standard_True;
1845 if (!aNames.IsEmpty() && isDefaults)
1847 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1851 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1852 aChanges.Append (ViewerTest_AspectsChangeSet());
1853 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1855 // parse syntax of legacy commands
1856 if (aCmdName == "vsetwidth")
1858 if (aNames.IsEmpty()
1859 || !aNames.Last().IsRealValue())
1861 std::cout << "Error: not enough arguments!\n";
1864 aChangeSet->ToSetLineWidth = 1;
1865 aChangeSet->LineWidth = aNames.Last().RealValue();
1866 aNames.Remove (aNames.Length());
1868 else if (aCmdName == "vunsetwidth")
1870 aChangeSet->ToSetLineWidth = -1;
1872 else if (aCmdName == "vsetcolor")
1874 if (aNames.IsEmpty())
1876 std::cout << "Error: not enough arguments!\n";
1879 aChangeSet->ToSetColor = 1;
1881 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1882 Standard_Boolean isOk = Standard_False;
1883 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1885 aChangeSet->Color = aColor;
1886 aNames.Remove (aNames.Length());
1887 isOk = Standard_True;
1889 else if (aNames.Length() >= 3)
1891 const TCollection_AsciiString anRgbStr[3] =
1893 aNames.Value (aNames.Upper() - 2),
1894 aNames.Value (aNames.Upper() - 1),
1895 aNames.Value (aNames.Upper() - 0)
1897 isOk = anRgbStr[0].IsRealValue()
1898 && anRgbStr[1].IsRealValue()
1899 && anRgbStr[2].IsRealValue();
1902 Graphic3d_Vec4d anRgb;
1903 anRgb.x() = anRgbStr[0].RealValue();
1904 anRgb.y() = anRgbStr[1].RealValue();
1905 anRgb.z() = anRgbStr[2].RealValue();
1906 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1907 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1908 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1910 std::cout << "Error: RGB color values should be within range 0..1!\n";
1913 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1914 aNames.Remove (aNames.Length());
1915 aNames.Remove (aNames.Length());
1916 aNames.Remove (aNames.Length());
1921 std::cout << "Error: not enough arguments!\n";
1925 else if (aCmdName == "vunsetcolor")
1927 aChangeSet->ToSetColor = -1;
1929 else if (aCmdName == "vsettransparency")
1931 if (aNames.IsEmpty()
1932 || !aNames.Last().IsRealValue())
1934 std::cout << "Error: not enough arguments!\n";
1937 aChangeSet->ToSetTransparency = 1;
1938 aChangeSet->Transparency = aNames.Last().RealValue();
1939 aNames.Remove (aNames.Length());
1941 else if (aCmdName == "vunsettransparency")
1943 aChangeSet->ToSetTransparency = -1;
1945 else if (aCmdName == "vsetmaterial")
1947 if (aNames.IsEmpty())
1949 std::cout << "Error: not enough arguments!\n";
1952 aChangeSet->ToSetMaterial = 1;
1953 aChangeSet->MatName = aNames.Last();
1954 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1955 aNames.Remove (aNames.Length());
1957 else if (aCmdName == "vunsetmaterial")
1959 aChangeSet->ToSetMaterial = -1;
1961 else if (anArgIter >= theArgNb)
1963 std::cout << "Error: not enough arguments!\n";
1967 if (!aChangeSet->IsEmpty())
1969 anArgIter = theArgNb;
1971 for (; anArgIter < theArgNb; ++anArgIter)
1973 TCollection_AsciiString anArg = theArgVec[anArgIter];
1975 if (anArg == "-setwidth"
1976 || anArg == "-setlinewidth")
1978 if (++anArgIter >= theArgNb)
1980 std::cout << "Error: wrong syntax at " << anArg << "\n";
1983 aChangeSet->ToSetLineWidth = 1;
1984 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1986 else if (anArg == "-unsetwidth"
1987 || anArg == "-unsetlinewidth")
1989 aChangeSet->ToSetLineWidth = -1;
1990 aChangeSet->LineWidth = 1.0;
1992 else if (anArg == "-settransp"
1993 || anArg == "-settransparency")
1995 if (++anArgIter >= theArgNb)
1997 std::cout << "Error: wrong syntax at " << anArg << "\n";
2000 aChangeSet->ToSetTransparency = 1;
2001 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2002 if (aChangeSet->Transparency >= 0.0
2003 && aChangeSet->Transparency <= Precision::Confusion())
2005 aChangeSet->ToSetTransparency = -1;
2006 aChangeSet->Transparency = 0.0;
2009 else if (anArg == "-setalphamode")
2011 if (++anArgIter >= theArgNb)
2013 std::cout << "Error: wrong syntax at " << anArg << "\n";
2016 aChangeSet->ToSetAlphaMode = 1;
2017 aChangeSet->AlphaCutoff = 0.5f;
2019 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2021 if (aParam == "opaque")
2023 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2025 else if (aParam == "mask")
2027 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2029 else if (aParam == "blend")
2031 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2033 else if (aParam == "blendauto"
2034 || aParam == "auto")
2036 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2040 std::cout << "Error: wrong syntax at " << aParam << "\n";
2045 if (anArgIter + 1 < theArgNb
2046 && theArgVec[anArgIter + 1][0] != '-')
2048 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2049 if (aParam2.IsRealValue())
2051 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2056 else if (anArg == "-setvis"
2057 || anArg == "-setvisibility")
2059 if (++anArgIter >= theArgNb)
2061 std::cout << "Error: wrong syntax at " << anArg << "\n";
2065 aChangeSet->ToSetVisibility = 1;
2066 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2068 else if (anArg == "-setalpha")
2070 if (++anArgIter >= theArgNb)
2072 std::cout << "Error: wrong syntax at " << anArg << "\n";
2075 aChangeSet->ToSetTransparency = 1;
2076 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2077 if (aChangeSet->Transparency < 0.0
2078 || aChangeSet->Transparency > 1.0)
2080 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2083 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2084 if (aChangeSet->Transparency >= 0.0
2085 && aChangeSet->Transparency <= Precision::Confusion())
2087 aChangeSet->ToSetTransparency = -1;
2088 aChangeSet->Transparency = 0.0;
2091 else if (anArg == "-unsettransp"
2092 || anArg == "-unsettransparency"
2093 || anArg == "-unsetalpha"
2094 || anArg == "-opaque")
2096 aChangeSet->ToSetTransparency = -1;
2097 aChangeSet->Transparency = 0.0;
2099 else if (anArg == "-setcolor")
2101 Standard_Integer aNbComps = 0;
2102 Standard_Integer aCompIter = anArgIter + 1;
2103 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2105 if (theArgVec[aCompIter][0] == '-')
2114 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2115 Standard_CString aName = theArgVec[anArgIter + 1];
2116 if (!Quantity_Color::ColorFromName (aName, aColor))
2118 std::cout << "Error: unknown color name '" << aName << "'\n";
2121 aChangeSet->Color = aColor;
2126 Graphic3d_Vec3d anRgb;
2127 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2128 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2129 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2130 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2131 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2132 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2134 std::cout << "Error: RGB color values should be within range 0..1!\n";
2137 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2142 std::cout << "Error: wrong syntax at " << anArg << "\n";
2146 aChangeSet->ToSetColor = 1;
2147 anArgIter += aNbComps;
2149 else if (anArg == "-setlinetype")
2151 if (++anArgIter >= theArgNb)
2153 std::cout << "Error: wrong syntax at " << anArg << "\n";
2156 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aChangeSet->TypeOfLine))
2158 std::cout << "Error: wrong syntax at " << anArg << "\n";
2162 aChangeSet->ToSetTypeOfLine = 1;
2164 else if (anArg == "-unsetlinetype")
2166 aChangeSet->ToSetTypeOfLine = -1;
2168 else if (anArg == "-setmarkertype"
2169 || anArg == "-setpointtype")
2171 if (++anArgIter >= theArgNb)
2173 std::cout << "Error: wrong syntax at " << anArg << "\n";
2176 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2178 std::cout << "Error: wrong syntax at " << anArg << "\n";
2182 aChangeSet->ToSetTypeOfMarker = 1;
2184 else if (anArg == "-unsetmarkertype"
2185 || anArg == "-unsetpointtype")
2187 aChangeSet->ToSetTypeOfMarker = -1;
2189 else if (anArg == "-setmarkersize"
2190 || anArg == "-setpointsize")
2192 if (++anArgIter >= theArgNb)
2194 std::cout << "Error: wrong syntax at " << anArg << "\n";
2197 aChangeSet->ToSetMarkerSize = 1;
2198 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2200 else if (anArg == "-unsetmarkersize"
2201 || anArg == "-unsetpointsize")
2203 aChangeSet->ToSetMarkerSize = -1;
2204 aChangeSet->MarkerSize = 1.0;
2206 else if (anArg == "-unsetcolor")
2208 aChangeSet->ToSetColor = -1;
2209 aChangeSet->Color = DEFAULT_COLOR;
2211 else if (anArg == "-setmat"
2212 || anArg == "-setmaterial")
2214 if (++anArgIter >= theArgNb)
2216 std::cout << "Error: wrong syntax at " << anArg << "\n";
2219 aChangeSet->ToSetMaterial = 1;
2220 aChangeSet->MatName = theArgVec[anArgIter];
2221 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2223 else if (anArg == "-unsetmat"
2224 || anArg == "-unsetmaterial")
2226 aChangeSet->ToSetMaterial = -1;
2227 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2229 else if (anArg == "-subshape"
2230 || anArg == "-subshapes")
2234 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2238 if (aNames.IsEmpty())
2240 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2244 aChanges.Append (ViewerTest_AspectsChangeSet());
2245 aChangeSet = &aChanges.ChangeLast();
2247 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2249 Standard_CString aSubShapeName = theArgVec[anArgIter];
2250 if (*aSubShapeName == '-')
2256 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2257 if (aSubShape.IsNull())
2259 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2262 aChangeSet->SubShapes.Append (aSubShape);
2265 if (aChangeSet->SubShapes.IsEmpty())
2267 std::cerr << "Error: empty list is specified after -subshapes!\n";
2271 else if (anArg == "-freeboundary"
2274 if (++anArgIter >= theArgNb)
2276 std::cout << "Error: wrong syntax at " << anArg << "\n";
2279 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2284 aChangeSet->ToSetShowFreeBoundary = 1;
2286 else if (aValue == "off"
2289 aChangeSet->ToSetShowFreeBoundary = -1;
2293 std::cout << "Error: wrong syntax at " << anArg << "\n";
2297 else if (anArg == "-setfreeboundarywidth"
2298 || anArg == "-setfbwidth")
2300 if (++anArgIter >= theArgNb)
2302 std::cout << "Error: wrong syntax at " << anArg << "\n";
2305 aChangeSet->ToSetFreeBoundaryWidth = 1;
2306 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2308 else if (anArg == "-unsetfreeboundarywidth"
2309 || anArg == "-unsetfbwidth")
2311 aChangeSet->ToSetFreeBoundaryWidth = -1;
2312 aChangeSet->FreeBoundaryWidth = 1.0;
2314 else if (anArg == "-setfreeboundarycolor"
2315 || anArg == "-setfbcolor")
2317 Standard_Integer aNbComps = 0;
2318 Standard_Integer aCompIter = anArgIter + 1;
2319 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2321 if (theArgVec[aCompIter][0] == '-')
2330 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2331 Standard_CString aName = theArgVec[anArgIter + 1];
2332 if (!Quantity_Color::ColorFromName (aName, aColor))
2334 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2337 aChangeSet->FreeBoundaryColor = aColor;
2342 Graphic3d_Vec3d anRgb;
2343 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2344 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2345 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2346 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2347 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2348 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2350 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2353 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2358 std::cout << "Error: wrong syntax at " << anArg << "\n";
2362 aChangeSet->ToSetFreeBoundaryColor = 1;
2363 anArgIter += aNbComps;
2365 else if (anArg == "-unsetfreeboundarycolor"
2366 || anArg == "-unsetfbcolor")
2368 aChangeSet->ToSetFreeBoundaryColor = -1;
2369 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2371 else if (anArg == "-unset")
2373 aChangeSet->ToSetVisibility = 1;
2374 aChangeSet->Visibility = 1;
2375 aChangeSet->ToSetLineWidth = -1;
2376 aChangeSet->LineWidth = 1.0;
2377 aChangeSet->ToSetTypeOfLine = -1;
2378 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2379 aChangeSet->ToSetTypeOfMarker = -1;
2380 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
2381 aChangeSet->ToSetMarkerSize = -1;
2382 aChangeSet->MarkerSize = 1.0;
2383 aChangeSet->ToSetTransparency = -1;
2384 aChangeSet->Transparency = 0.0;
2385 aChangeSet->ToSetAlphaMode = -1;
2386 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2387 aChangeSet->AlphaCutoff = 0.5f;
2388 aChangeSet->ToSetColor = -1;
2389 aChangeSet->Color = DEFAULT_COLOR;
2390 aChangeSet->ToSetMaterial = -1;
2391 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2392 aChangeSet->ToSetShowFreeBoundary = -1;
2393 aChangeSet->ToSetFreeBoundaryColor = -1;
2394 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2395 aChangeSet->ToSetFreeBoundaryWidth = -1;
2396 aChangeSet->FreeBoundaryWidth = 1.0;
2397 aChangeSet->ToSetHatch = -1;
2398 aChangeSet->StdHatchStyle = -1;
2399 aChangeSet->PathToHatchPattern.Clear();
2400 aChangeSet->ToSetShadingModel = -1;
2401 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2403 else if (anArg == "-isoontriangulation"
2404 || anArg == "-isoontriang")
2406 if (++anArgIter >= theArgNb)
2408 std::cout << "Error: wrong syntax at " << anArg << "\n";
2411 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2416 aChangeSet->ToEnableIsoOnTriangulation = 1;
2418 else if (aValue == "off"
2421 aChangeSet->ToEnableIsoOnTriangulation = 0;
2425 std::cout << "Error: wrong syntax at " << anArg << "\n";
2429 else if (anArg == "-setmaxparamvalue")
2431 if (++anArgIter >= theArgNb)
2433 std::cout << "Error: wrong syntax at " << anArg << "\n";
2436 aChangeSet->ToSetMaxParamValue = 1;
2437 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2439 else if (anArg == "-setsensitivity")
2443 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2447 if (aNames.IsEmpty())
2449 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2453 if (anArgIter + 2 >= theArgNb)
2455 std::cout << "Error: wrong syntax at " << anArg << "\n";
2458 aChangeSet->ToSetSensitivity = 1;
2459 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2460 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2462 else if (anArg == "-sethatch")
2466 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2470 if (aNames.IsEmpty())
2472 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2476 aChangeSet->ToSetHatch = 1;
2477 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
2478 if (anArgHatch.Length() <= 2)
2480 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
2482 || anIntStyle >= Aspect_HS_NB)
2484 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
2487 aChangeSet->StdHatchStyle = anIntStyle;
2491 aChangeSet->PathToHatchPattern = anArgHatch;
2494 else if (anArg == "-setshadingmodel")
2496 if (++anArgIter >= theArgNb)
2498 std::cout << "Error: wrong syntax at " << anArg << "\n";
2501 aChangeSet->ToSetShadingModel = 1;
2502 aChangeSet->ShadingModelName = theArgVec[anArgIter];
2503 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
2505 std::cout << "Error: wrong syntax at " << anArg << "\n";
2509 else if (anArg == "-unsetshadingmodel")
2511 aChangeSet->ToSetShadingModel = -1;
2512 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2516 std::cout << "Error: wrong syntax at " << anArg << "\n";
2521 Standard_Boolean isFirst = Standard_True;
2522 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2523 aChangesIter.More(); aChangesIter.Next())
2525 if (!aChangesIter.Value().Validate (!isFirst))
2529 isFirst = Standard_False;
2532 // special case for -defaults parameter.
2533 // all changed values will be set to DefaultDrawer.
2536 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2538 if (aChangeSet->ToSetLineWidth != 0)
2540 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2541 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2542 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2543 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2545 if (aChangeSet->ToSetColor != 0)
2547 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2548 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2549 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2550 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2551 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2552 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2554 if (aChangeSet->ToSetTypeOfLine != 0)
2556 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2557 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2558 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2559 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2560 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2562 if (aChangeSet->ToSetTypeOfMarker != 0)
2564 aDrawer->PointAspect()->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2565 aDrawer->PointAspect()->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2566 ? Handle(Graphic3d_MarkerImage)()
2567 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2569 if (aChangeSet->ToSetMarkerSize != 0)
2571 aDrawer->PointAspect()->SetScale (aChangeSet->MarkerSize);
2573 if (aChangeSet->ToSetTransparency != 0)
2575 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2577 if (aChangeSet->ToSetAlphaMode != 0)
2579 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2581 if (aChangeSet->ToSetMaterial != 0)
2583 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2585 if (aChangeSet->ToSetShowFreeBoundary == 1)
2587 aDrawer->SetFreeBoundaryDraw (Standard_True);
2589 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2591 aDrawer->SetFreeBoundaryDraw (Standard_False);
2593 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2595 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2597 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2599 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2601 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2603 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2605 if (aChangeSet->ToSetMaxParamValue != 0)
2607 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2609 if (aChangeSet->ToSetShadingModel == 1)
2611 aDrawer->ShadingAspect()->Aspect()->SetShadingModel (aChangeSet->ShadingModel);
2614 // redisplay all objects in context
2615 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2617 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2620 aCtx->Redisplay (aPrs, Standard_False);
2626 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2628 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2629 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2635 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2636 Handle(AIS_ColoredShape) aColoredPrs;
2637 Standard_Boolean toDisplay = Standard_False;
2638 Standard_Boolean toRedisplay = Standard_False;
2639 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2641 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2642 if (aShapePrs.IsNull())
2644 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2647 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2648 if (aColoredPrs.IsNull())
2650 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2651 if (aShapePrs->HasDisplayMode())
2653 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2655 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2656 aCtx->Remove (aShapePrs, Standard_False);
2657 GetMapOfAIS().UnBind2 (aName);
2658 GetMapOfAIS().Bind (aColoredPrs, aName);
2659 toDisplay = Standard_True;
2660 aShapePrs = aColoredPrs;
2667 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2668 aChangeSet = &aChangesIter.ChangeValue();
2669 if (aChangeSet->ToSetVisibility == 1)
2671 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2672 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2674 else if (aChangeSet->ToSetMaterial == 1)
2676 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2678 else if (aChangeSet->ToSetMaterial == -1)
2680 aCtx->UnsetMaterial (aPrs, Standard_False);
2682 if (aChangeSet->ToSetColor == 1)
2684 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2686 else if (aChangeSet->ToSetColor == -1)
2688 aCtx->UnsetColor (aPrs, Standard_False);
2690 if (aChangeSet->ToSetTransparency == 1)
2692 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2694 else if (aChangeSet->ToSetTransparency == -1)
2696 aCtx->UnsetTransparency (aPrs, Standard_False);
2698 if (aChangeSet->ToSetLineWidth == 1)
2700 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2702 else if (aChangeSet->ToSetLineWidth == -1)
2704 aCtx->UnsetWidth (aPrs, Standard_False);
2706 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2708 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2709 toRedisplay = Standard_True;
2711 else if (aChangeSet->ToSetSensitivity != 0)
2713 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2715 if (!aDrawer.IsNull())
2717 if (aChangeSet->ToSetShowFreeBoundary == 1)
2719 aDrawer->SetFreeBoundaryDraw (Standard_True);
2720 toRedisplay = Standard_True;
2722 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2724 aDrawer->SetFreeBoundaryDraw (Standard_False);
2725 toRedisplay = Standard_True;
2727 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2729 Handle(Prs3d_LineAspect) aBoundaryAspect =
2730 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2731 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2732 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2733 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2734 toRedisplay = Standard_True;
2736 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2738 Handle(Prs3d_LineAspect) aBoundaryAspect =
2739 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2740 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2741 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2742 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2743 toRedisplay = Standard_True;
2745 if (aChangeSet->ToSetTypeOfLine != 0)
2747 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2748 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2749 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2750 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2751 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2752 toRedisplay = Standard_True;
2754 if (aChangeSet->ToSetTypeOfMarker != 0)
2756 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2757 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2758 aMarkerAspect->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2759 aMarkerAspect->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2760 ? Handle(Graphic3d_MarkerImage)()
2761 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2762 aDrawer->SetPointAspect (aMarkerAspect);
2763 toRedisplay = Standard_True;
2765 if (aChangeSet->ToSetMarkerSize != 0)
2767 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2768 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2769 aMarkerAspect->SetScale (aChangeSet->MarkerSize);
2770 aDrawer->SetPointAspect (aMarkerAspect);
2771 toRedisplay = Standard_True;
2773 if (aChangeSet->ToSetMaxParamValue != 0)
2775 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2777 if (aChangeSet->ToSetHatch != 0)
2779 if (!aDrawer->HasOwnShadingAspect())
2781 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2782 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2785 Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
2786 if (aChangeSet->ToSetHatch == -1)
2788 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2792 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2793 if (!aChangeSet->PathToHatchPattern.IsEmpty())
2795 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2796 if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
2798 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2802 std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
2806 else if (aChangeSet->StdHatchStyle != -1)
2808 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
2811 toRedisplay = Standard_True;
2813 if (aChangeSet->ToSetShadingModel != 0)
2815 aDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2816 toRedisplay = Standard_True;
2818 if (aChangeSet->ToSetAlphaMode != 0)
2820 if (!aDrawer->HasOwnShadingAspect())
2822 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2823 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2825 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2826 toRedisplay = Standard_True;
2830 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2832 aChangeSet = &aChangesIter.ChangeValue();
2833 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2834 aSubShapeIter.More(); aSubShapeIter.Next())
2836 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2837 if (aChangeSet->ToSetVisibility == 1)
2839 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2840 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2842 if (aChangeSet->ToSetColor == 1)
2844 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2846 if (aChangeSet->ToSetLineWidth == 1)
2848 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2850 if (aChangeSet->ToSetColor == -1
2851 || aChangeSet->ToSetLineWidth == -1)
2853 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2855 if (aChangeSet->ToSetMaxParamValue != 0)
2857 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2858 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2860 if (aChangeSet->ToSetSensitivity != 0)
2862 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2864 if (aChangeSet->ToSetShadingModel != 0)
2866 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2867 aCurColDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2873 aCtx->Display (aPrs, Standard_False);
2877 aCtx->Redisplay (aPrs, Standard_False);
2879 else if (!aColoredPrs.IsNull())
2881 aCtx->Redisplay (aColoredPrs, Standard_False);
2888 //==============================================================================
2889 //function : VDonly2
2891 //purpose : Display only a selected or named object
2892 // if there is no selected or named object s, nothing is done
2893 //==============================================================================
2894 static int VDonly2 (Draw_Interpretor& ,
2895 Standard_Integer theArgNb,
2896 const char** theArgVec)
2898 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2899 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2902 std::cerr << "Error: no active view!\n";
2906 Standard_Integer anArgIter = 1;
2907 for (; anArgIter < theArgNb; ++anArgIter)
2909 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2915 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2916 if (anArgIter >= theArgNb)
2918 // display only selected objects
2919 if (aCtx->NbSelected() < 1)
2924 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2926 aDispSet.Add (aCtx->SelectedInteractive());
2931 // display only specified objects
2932 for (; anArgIter < theArgNb; ++anArgIter)
2934 TCollection_AsciiString aName = theArgVec[anArgIter];
2935 if (GetMapOfAIS().IsBound2 (aName))
2937 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2938 if (!aShape.IsNull())
2940 aCtx->Display (aShape, Standard_False);
2941 aDispSet.Add (aShape);
2947 // weed out other objects
2948 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2950 if (aDispSet.Contains (anIter.Key1()))
2955 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2956 if (!aShape.IsNull())
2958 aCtx->Erase (aShape, Standard_False);
2964 //==============================================================================
2965 //function : VRemove
2966 //purpose : Removes selected or named objects.
2967 // If there is no selected or named objects,
2968 // all objects in the viewer can be removed with argument -all.
2969 // If -context is in arguments, the object is not deleted from the map of
2970 // objects (deleted only from the current context).
2971 //==============================================================================
2972 int VRemove (Draw_Interpretor& theDI,
2973 Standard_Integer theArgNb,
2974 const char** theArgVec)
2976 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2977 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2980 std::cerr << "Error: no active view!\n";
2984 Standard_Boolean isContextOnly = Standard_False;
2985 Standard_Boolean toRemoveAll = Standard_False;
2986 Standard_Boolean toPrintInfo = Standard_True;
2988 Standard_Integer anArgIter = 1;
2989 for (; anArgIter < theArgNb; ++anArgIter)
2991 TCollection_AsciiString anArg = theArgVec[anArgIter];
2993 if (anArg == "-context")
2995 isContextOnly = Standard_True;
2997 else if (anArg == "-all")
2999 toRemoveAll = Standard_True;
3001 else if (anArg == "-noinfo")
3003 toPrintInfo = Standard_False;
3005 else if (anUpdateTool.parseRedrawMode (anArg))
3015 && anArgIter < theArgNb)
3017 std::cerr << "Error: wrong syntax!\n";
3021 NCollection_List<TCollection_AsciiString> anIONameList;
3024 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3025 anIter.More(); anIter.Next())
3027 anIONameList.Append (anIter.Key2());
3030 else if (anArgIter < theArgNb) // removed objects names are in argument list
3032 for (; anArgIter < theArgNb; ++anArgIter)
3034 TCollection_AsciiString aName = theArgVec[anArgIter];
3035 if (!GetMapOfAIS().IsBound2 (aName))
3037 theDI << aName.ToCString() << " was not bound to some object.\n";
3041 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3042 if (anIO->GetContext() != aCtx)
3044 theDI << aName.ToCString() << " was not displayed in current context.\n";
3045 theDI << "Please activate view with this object displayed and try again.\n";
3049 anIONameList.Append (aName);
3053 else if (aCtx->NbSelected() > 0)
3055 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3056 anIter.More(); anIter.Next())
3058 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3059 if (!aCtx->IsSelected (anIO))
3064 anIONameList.Append (anIter.Key2());
3069 // Unbind all removed objects from the map of displayed IO.
3070 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3071 anIter.More(); anIter.Next())
3073 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
3074 aCtx->Remove (anIO, Standard_False);
3077 theDI << anIter.Value().ToCString() << " was removed\n";
3081 GetMapOfAIS().UnBind2 (anIter.Value());
3087 //==============================================================================
3089 //purpose : Erase some selected or named objects
3090 // if there is no selected or named objects, the whole viewer is erased
3091 //==============================================================================
3092 int VErase (Draw_Interpretor& theDI,
3093 Standard_Integer theArgNb,
3094 const char** theArgVec)
3096 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3097 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3098 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3101 std::cerr << "Error: no active view!\n";
3105 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3107 Standard_Integer anArgIter = 1;
3108 Standard_Boolean toEraseInView = Standard_False;
3109 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3110 for (; anArgIter < theArgNb; ++anArgIter)
3112 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3113 anArgCase.LowerCase();
3114 if (anUpdateTool.parseRedrawMode (anArgCase))
3118 else if (anArgCase == "-view"
3119 || anArgCase == "-inview")
3121 toEraseInView = Standard_True;
3125 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3129 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3131 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3135 if (!aNamesOfEraseIO.IsEmpty())
3137 // Erase named objects
3138 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
3140 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
3141 if (!GetMapOfAIS().IsBound2 (aName))
3146 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
3147 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
3148 theDI << aName.ToCString() << " ";
3153 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3157 aCtx->Erase (anIO, Standard_False);
3162 else if (!toEraseAll && aCtx->NbSelected() > 0)
3164 // Erase selected objects
3165 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3166 anIter.More(); anIter.Next())
3168 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3170 && aCtx->IsSelected (anIO))
3172 theDI << anIter.Key2().ToCString() << " ";
3175 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3182 aCtx->EraseSelected (Standard_False);
3187 // Erase all objects
3188 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3189 anIter.More(); anIter.Next())
3191 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3196 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3200 aCtx->Erase (anIO, Standard_False);
3209 //==============================================================================
3210 //function : VDisplayAll
3211 //purpose : Display all the objects of the Map
3212 //==============================================================================
3213 static int VDisplayAll (Draw_Interpretor& ,
3214 Standard_Integer theArgNb,
3215 const char** theArgVec)
3218 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3219 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3222 std::cerr << "Error: no active view!\n";
3226 Standard_Integer anArgIter = 1;
3227 for (; anArgIter < theArgNb; ++anArgIter)
3229 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3230 anArgCase.LowerCase();
3231 if (anUpdateTool.parseRedrawMode (anArgCase))
3240 if (anArgIter < theArgNb)
3242 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3246 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3247 anIter.More(); anIter.Next())
3249 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3250 aCtx->Erase (aShape, Standard_False);
3253 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3254 anIter.More(); anIter.Next())
3256 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3257 aCtx->Display (aShape, Standard_False);
3262 //! Auxiliary method to check if presentation exists
3263 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3264 const Handle(AIS_InteractiveObject)& theIO,
3265 const Standard_Integer theMode)
3267 if (theIO.IsNull() || theCtx.IsNull())
3274 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3279 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3281 return theIO->DisplayMode();
3283 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3285 return theCtx->DisplayMode();
3291 enum ViewerTest_BndAction
3298 //! Auxiliary method to print bounding box of presentation
3299 inline void bndPresentation (Draw_Interpretor& theDI,
3300 const Handle(PrsMgr_PresentationManager)& theMgr,
3301 const Handle(AIS_InteractiveObject)& theObj,
3302 const Standard_Integer theDispMode,
3303 const TCollection_AsciiString& theName,
3304 const ViewerTest_BndAction theAction,
3305 const Handle(Prs3d_Drawer)& theStyle)
3309 case BndAction_Hide:
3311 theMgr->Unhighlight (theObj);
3314 case BndAction_Show:
3316 theMgr->Color (theObj, theStyle, theDispMode);
3319 case BndAction_Print:
3322 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3324 if (aPrsIter.Value().Mode() != theDispMode)
3327 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3329 gp_Pnt aMin = aBox.CornerMin();
3330 gp_Pnt aMax = aBox.CornerMax();
3331 theDI << theName << "\n"
3332 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3333 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
3339 //==============================================================================
3340 //function : VBounding
3342 //==============================================================================
3343 int VBounding (Draw_Interpretor& theDI,
3344 Standard_Integer theArgNb,
3345 const char** theArgVec)
3347 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3348 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3351 std::cout << "Error: no active view!\n";
3355 ViewerTest_BndAction anAction = BndAction_Show;
3356 Standard_Integer aMode = -1;
3358 Handle(Prs3d_Drawer) aStyle;
3360 Standard_Integer anArgIter = 1;
3361 for (; anArgIter < theArgNb; ++anArgIter)
3363 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3365 if (anArg == "-print")
3367 anAction = BndAction_Print;
3369 else if (anArg == "-show")
3371 anAction = BndAction_Show;
3373 else if (anArg == "-hide")
3375 anAction = BndAction_Hide;
3377 else if (anArg == "-mode")
3379 if (++anArgIter >= theArgNb)
3381 std::cout << "Error: wrong syntax at " << anArg << "\n";
3384 aMode = Draw::Atoi (theArgVec[anArgIter]);
3386 else if (!anUpdateTool.parseRedrawMode (anArg))
3392 if (anAction == BndAction_Show)
3394 aStyle = new Prs3d_Drawer();
3395 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3396 aStyle->SetColor (Quantity_NOC_GRAY99);
3399 Standard_Integer aHighlightedMode = -1;
3400 if (anArgIter < theArgNb)
3402 // has a list of names
3403 for (; anArgIter < theArgNb; ++anArgIter)
3405 TCollection_AsciiString aName = theArgVec[anArgIter];
3406 if (!GetMapOfAIS().IsBound2 (aName))
3408 std::cout << "Error: presentation " << aName << " does not exist\n";
3412 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3413 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3414 if (aHighlightedMode == -1)
3416 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3419 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3422 else if (aCtx->NbSelected() > 0)
3424 // remove all currently selected objects
3425 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3427 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3428 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3429 if (aHighlightedMode != -1)
3431 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3432 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3439 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3440 anIter.More(); anIter.Next())
3442 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3443 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3444 if (aHighlightedMode != -1)
3446 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3453 //==============================================================================
3454 //function : VTexture
3456 //==============================================================================
3457 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
3459 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3462 std::cout << "Error: no active view!\n";
3466 int toModulate = -1;
3467 bool toSetFilter = false;
3468 bool toSetAniso = false;
3469 bool toSetTrsfAngle = false;
3470 bool toSetTrsfTrans = false;
3471 bool toSetTrsfScale = false;
3472 Standard_ShortReal aTrsfRotAngle = 0.0f;
3473 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
3474 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
3475 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
3476 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
3478 Handle(AIS_Shape) aTexturedIO;
3479 Handle(Graphic3d_TextureSet) aTextureSetOld;
3480 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
3481 bool toSetGenRepeat = false;
3482 bool toSetGenScale = false;
3483 bool toSetGenOrigin = false;
3484 bool toSetImage = false;
3485 bool toComputeUV = false;
3487 const TCollection_AsciiString aCommandName (theArgVec[0]);
3488 bool toSetDefaults = aCommandName == "vtexdefault";
3490 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3491 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
3493 const TCollection_AsciiString aName = theArgVec[anArgIter];
3494 TCollection_AsciiString aNameCase = aName;
3495 aNameCase.LowerCase();
3496 if (anUpdateTool.parseRedrawMode (aName))
3500 else if (aTexturedIO.IsNull())
3502 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3503 if (aMapOfIO.IsBound2 (aName))
3505 aTexturedIO = Handle(AIS_Shape)::DownCast (aMapOfIO.Find2 (aName));
3507 if (aTexturedIO.IsNull())
3509 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
3513 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
3515 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
3518 else if (aNameCase == "-scale"
3519 || aNameCase == "-setscale"
3520 || aCommandName == "vtexscale")
3522 if (aCommandName != "vtexscale")
3526 if (anArgIter < theArgsNb)
3528 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3529 TCollection_AsciiString aValUCase = aValU;
3530 aValUCase.LowerCase();
3531 toSetGenScale = true;
3532 if (aValUCase == "off")
3534 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3537 else if (anArgIter + 1 < theArgsNb)
3539 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3540 if (aValU.IsRealValue()
3541 && aValV.IsRealValue())
3543 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3549 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3552 else if (aNameCase == "-origin"
3553 || aNameCase == "-setorigin"
3554 || aCommandName == "vtexorigin")
3556 if (aCommandName != "vtexorigin")
3560 if (anArgIter < theArgsNb)
3562 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3563 TCollection_AsciiString aValUCase = aValU;
3564 aValUCase.LowerCase();
3565 toSetGenOrigin = true;
3566 if (aValUCase == "off")
3568 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3571 else if (anArgIter + 1 < theArgsNb)
3573 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3574 if (aValU.IsRealValue()
3575 && aValV.IsRealValue())
3577 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3583 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3586 else if (aNameCase == "-repeat"
3587 || aNameCase == "-setrepeat"
3588 || aCommandName == "vtexrepeat")
3590 if (aCommandName != "vtexrepeat")
3594 if (anArgIter < theArgsNb)
3596 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3597 TCollection_AsciiString aValUCase = aValU;
3598 aValUCase.LowerCase();
3599 toSetGenRepeat = true;
3600 if (aValUCase == "off")
3602 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3605 else if (anArgIter + 1 < theArgsNb)
3607 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3608 if (aValU.IsRealValue()
3609 && aValV.IsRealValue())
3611 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3617 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3620 else if (aNameCase == "-modulate")
3622 bool toModulateBool = true;
3623 if (anArgIter + 1 < theArgsNb
3624 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
3628 toModulate = toModulateBool ? 1 : 0;
3630 else if ((aNameCase == "-setfilter"
3631 || aNameCase == "-filter")
3632 && anArgIter + 1 < theArgsNb)
3634 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3638 if (aValue == "nearest")
3640 aFilter = Graphic3d_TOTF_NEAREST;
3642 else if (aValue == "bilinear")
3644 aFilter = Graphic3d_TOTF_BILINEAR;
3646 else if (aValue == "trilinear")
3648 aFilter = Graphic3d_TOTF_TRILINEAR;
3652 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3656 else if ((aNameCase == "-setaniso"
3657 || aNameCase == "-setanisofilter"
3658 || aNameCase == "-aniso"
3659 || aNameCase == "-anisofilter")
3660 && anArgIter + 1 < theArgsNb)
3662 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3666 if (aValue == "off")
3668 anAnisoFilter = Graphic3d_LOTA_OFF;
3670 else if (aValue == "fast")
3672 anAnisoFilter = Graphic3d_LOTA_FAST;
3674 else if (aValue == "middle")
3676 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
3678 else if (aValue == "quality"
3679 || aValue == "high")
3681 anAnisoFilter = Graphic3d_LOTA_QUALITY;
3685 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3689 else if ((aNameCase == "-rotateangle"
3690 || aNameCase == "-rotangle"
3691 || aNameCase == "-rotate"
3692 || aNameCase == "-angle"
3693 || aNameCase == "-trsfangle")
3694 && anArgIter + 1 < theArgsNb)
3696 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3697 toSetTrsfAngle = true;
3700 else if ((aNameCase == "-trsftrans"
3701 || aNameCase == "-trsftranslate"
3702 || aNameCase == "-translate"
3703 || aNameCase == "-translation")
3704 && anArgIter + 2 < theArgsNb)
3706 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3707 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3708 toSetTrsfTrans = true;
3711 else if ((aNameCase == "-trsfscale")
3712 && anArgIter + 2 < theArgsNb)
3714 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3715 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3716 toSetTrsfScale = true;
3719 else if (aNameCase == "-default"
3720 || aNameCase == "-defaults")
3722 toSetDefaults = true;
3724 else if (aCommandName == "vtexture"
3725 && (aTextureVecNew.IsEmpty()
3726 || aNameCase.StartsWith ("-tex")))
3728 Standard_Integer aTexIndex = 0;
3729 TCollection_AsciiString aTexName = aName;
3730 if (aNameCase.StartsWith ("-tex"))
3732 if (anArgIter + 1 >= theArgsNb
3733 || aNameCase.Length() < 5)
3735 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3739 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
3740 if (!aTexIndexStr.IsIntegerValue())
3742 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3746 aTexIndex = aTexIndexStr.IntegerValue();
3747 aTexName = theArgVec[anArgIter + 1];
3750 if (aTexIndex >= Graphic3d_TextureUnit_NB
3751 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
3753 std::cout << "Error: too many textures specified\n";
3758 if (aTexName.IsIntegerValue())
3760 const Standard_Integer aValue = aTexName.IntegerValue();
3761 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
3763 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
3766 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
3768 else if (aTexName == "?")
3770 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3772 theDi << "\n Files in current directory : \n\n";
3773 theDi.Eval ("glob -nocomplain *");
3775 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3776 aCmnd += aTextureFolder;
3779 theDi << "Files in " << aTextureFolder << " : \n\n";
3780 theDi.Eval (aCmnd.ToCString());
3783 else if (aTexName != "off")
3785 if (!OSD_File (aTexName).Exists())
3787 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
3790 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
3794 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
3797 if (aTextureVecNew.Value (aTexIndex))
3799 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
3804 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3811 // check if new image set is equal to already set one
3812 Standard_Integer aNbChanged = 0;
3813 Handle(Graphic3d_TextureSet) aTextureSetNew;
3814 if (!aTextureVecNew.IsEmpty())
3816 aNbChanged = aTextureVecNew.Size();
3817 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
3818 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
3820 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
3821 Handle(Graphic3d_TextureRoot) aTextureOld;
3822 if (!aTextureSetOld.IsNull()
3823 && aTexIter < aTextureSetOld->Size())
3825 aTextureOld = aTextureSetOld->Value (aTexIter);
3828 if (!aTextureOld.IsNull()
3829 && !aTextureNew.IsNull())
3831 *aTextureNew->GetParams() = *aTextureOld->GetParams();
3832 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
3834 TCollection_AsciiString aFilePathOld, aFilePathNew;
3835 aTextureOld->Path().SystemName (aFilePathOld);
3836 aTextureNew->Path().SystemName (aFilePathNew);
3837 if (aTextureNew->Name() == anOldManualTex->Name()
3838 && aFilePathOld == aFilePathNew
3839 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
3842 aTextureNew = anOldManualTex;
3846 aTextureSetNew->SetValue (aTexIter, aTextureNew);
3850 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
3851 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
3853 aTextureSetNew = aTextureSetOld;
3856 if (!aTexturedIO->Attributes()->HasOwnShadingAspect())
3858 aTexturedIO->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
3859 *aTexturedIO->Attributes()->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
3862 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
3863 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
3864 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
3865 aTextureSetOld.Nullify();
3870 if (toModulate != -1)
3877 aFilter = Graphic3d_TOTF_BILINEAR;
3882 anAnisoFilter = Graphic3d_LOTA_OFF;
3884 if (!toSetTrsfAngle)
3886 toSetTrsfAngle = true;
3887 aTrsfRotAngle = 0.0f;
3889 if (!toSetTrsfTrans)
3891 toSetTrsfTrans = true;
3892 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
3894 if (!toSetTrsfScale)
3896 toSetTrsfScale = true;
3897 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
3901 if (aCommandName == "vtexture"
3904 if (!aTextureSetOld.IsNull())
3906 //toComputeUV = true; // we can keep UV vertex attributes
3907 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
3908 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
3909 aTextureSetOld.Nullify();
3913 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
3914 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
3916 if (toModulate != -1)
3918 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
3922 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
3926 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
3930 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
3934 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
3938 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
3942 // set default values if requested
3944 && (aCommandName == "vtexrepeat"
3947 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3948 toSetGenRepeat = true;
3951 && (aCommandName == "vtexorigin"
3954 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3955 toSetGenOrigin = true;
3958 && (aCommandName == "vtexscale"
3961 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3962 toSetGenScale = true;
3965 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
3967 aTexturedIO->SetToUpdate (AIS_Shaded);
3970 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
3971 || aCtx->DisplayMode() != AIS_Shaded)
3973 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
3977 aCtx->Display (aTexturedIO, false);
3978 aTexturedIO->SynchronizeAspects();
3982 //! Auxiliary method to parse transformation persistence flags
3983 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3984 Graphic3d_TransModeFlags& theFlags)
3986 if (theFlagString == "zoom")
3988 theFlags = Graphic3d_TMF_ZoomPers;
3990 else if (theFlagString == "rotate")
3992 theFlags = Graphic3d_TMF_RotatePers;
3994 else if (theFlagString == "zoomrotate")
3996 theFlags = Graphic3d_TMF_ZoomRotatePers;
3998 else if (theFlagString == "trihedron"
3999 || theFlagString == "triedron")
4001 theFlags = Graphic3d_TMF_TriedronPers;
4003 else if (theFlagString == "none")
4005 theFlags = Graphic3d_TMF_None;
4009 return Standard_False;
4012 return Standard_True;
4015 //! Auxiliary method to parse transformation persistence flags
4016 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4017 Aspect_TypeOfTriedronPosition& theCorner)
4019 TCollection_AsciiString aString (theString);
4020 aString.LowerCase();
4021 if (aString == "center")
4023 theCorner = Aspect_TOTP_CENTER;
4025 else if (aString == "top"
4026 || aString == "upper")
4028 theCorner = Aspect_TOTP_TOP;
4030 else if (aString == "bottom"
4031 || aString == "lower")
4033 theCorner = Aspect_TOTP_BOTTOM;
4035 else if (aString == "left")
4037 theCorner = Aspect_TOTP_LEFT;
4039 else if (aString == "right")
4041 theCorner = Aspect_TOTP_RIGHT;
4043 else if (aString == "topleft"
4044 || aString == "leftupper"
4045 || aString == "upperleft")
4047 theCorner = Aspect_TOTP_LEFT_UPPER;
4049 else if (aString == "bottomleft"
4050 || aString == "leftlower"
4051 || aString == "lowerleft")
4053 theCorner = Aspect_TOTP_LEFT_LOWER;
4055 else if (aString == "topright"
4056 || aString == "rightupper"
4057 || aString == "upperright")
4059 theCorner = Aspect_TOTP_RIGHT_UPPER;
4061 else if (aString == "bottomright"
4062 || aString == "lowerright"
4063 || aString == "rightlower")
4065 theCorner = Aspect_TOTP_RIGHT_LOWER;
4069 return Standard_False;
4072 return Standard_True;
4075 //==============================================================================
4076 //function : VDisplay2
4078 //purpose : Display an object from its name
4079 //==============================================================================
4080 static int VDisplay2 (Draw_Interpretor& theDI,
4081 Standard_Integer theArgNb,
4082 const char** theArgVec)
4086 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4090 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4093 ViewerTest::ViewerInit();
4094 aCtx = ViewerTest::GetAISContext();
4097 // Parse input arguments
4098 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4099 Standard_Integer isMutable = -1;
4100 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4101 Standard_Boolean toReDisplay = Standard_False;
4102 Standard_Integer isSelectable = -1;
4103 Standard_Integer anObjDispMode = -2;
4104 Standard_Integer anObjHighMode = -2;
4105 Standard_Boolean toSetTrsfPers = Standard_False;
4106 Handle(Graphic3d_TransformPers) aTrsfPers;
4107 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4108 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4109 Standard_Integer toDisplayInView = Standard_False;
4110 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4112 const TCollection_AsciiString aName = theArgVec[anArgIter];
4113 TCollection_AsciiString aNameCase = aName;
4114 aNameCase.LowerCase();
4115 if (anUpdateTool.parseRedrawMode (aName))
4119 else if (aNameCase == "-mutable")
4123 else if (aNameCase == "-neutral")
4125 aDispStatus = AIS_DS_Displayed;
4127 else if (aNameCase == "-immediate"
4128 || aNameCase == "-top")
4130 aZLayer = Graphic3d_ZLayerId_Top;
4132 else if (aNameCase == "-topmost")
4134 aZLayer = Graphic3d_ZLayerId_Topmost;
4136 else if (aNameCase == "-osd"
4137 || aNameCase == "-toposd"
4138 || aNameCase == "-overlay")
4140 aZLayer = Graphic3d_ZLayerId_TopOSD;
4142 else if (aNameCase == "-botosd"
4143 || aNameCase == "-underlay")
4145 aZLayer = Graphic3d_ZLayerId_BotOSD;
4147 else if (aNameCase == "-select"
4148 || aNameCase == "-selectable")
4152 else if (aNameCase == "-noselect"
4153 || aNameCase == "-noselection")
4157 else if (aNameCase == "-dispmode"
4158 || aNameCase == "-displaymode")
4160 if (++anArgIter >= theArgNb)
4162 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4166 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4168 else if (aNameCase == "-highmode"
4169 || aNameCase == "-highlightmode")
4171 if (++anArgIter >= theArgNb)
4173 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4177 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4179 else if (aNameCase == "-3d")
4181 toSetTrsfPers = Standard_True;
4182 aTrsfPers.Nullify();
4184 else if (aNameCase == "-2d"
4185 || aNameCase == "-trihedron"
4186 || aNameCase == "-triedron")
4188 toSetTrsfPers = Standard_True;
4189 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4191 if (anArgIter + 1 < theArgNb)
4193 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4194 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4197 aTrsfPers->SetCorner2d (aCorner);
4199 if (anArgIter + 2 < theArgNb)
4201 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4202 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4203 if (anX.IsIntegerValue()
4204 && anY.IsIntegerValue())
4207 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4213 else if (aNameCase == "-trsfpers"
4214 || aNameCase == "-pers")
4216 if (++anArgIter >= theArgNb
4217 || !aTrsfPers.IsNull())
4219 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4223 toSetTrsfPers = Standard_True;
4224 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4225 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4226 aPersFlags.LowerCase();
4227 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
4229 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
4233 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4235 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4237 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4239 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
4242 else if (aNameCase == "-trsfperspos"
4243 || aNameCase == "-perspos")
4245 if (anArgIter + 2 >= theArgNb
4246 || aTrsfPers.IsNull())
4248 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4252 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4253 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4254 TCollection_AsciiString aZ = "0";
4255 if (!aX.IsRealValue()
4256 || !aY.IsRealValue())
4258 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4261 if (anArgIter + 1 < theArgNb)
4263 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
4264 if (aTemp.IsRealValue())
4271 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
4272 if (aTrsfPers->IsZoomOrRotate())
4274 aTrsfPers->SetAnchorPoint (aPnt);
4276 else if (aTrsfPers->IsTrihedronOr2d())
4278 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
4281 else if (aNameCase == "-layer")
4283 if (++anArgIter >= theArgNb)
4285 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4289 TCollection_AsciiString aValue (theArgVec[anArgIter]);
4290 if (!aValue.IsIntegerValue())
4292 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4296 aZLayer = aValue.IntegerValue();
4298 else if (aNameCase == "-view"
4299 || aNameCase == "-inview")
4301 toDisplayInView = Standard_True;
4303 else if (aNameCase == "-redisplay")
4305 toReDisplay = Standard_True;
4307 else if (aNameCase == "-erased"
4308 || aNameCase == "-load")
4310 aDispStatus = AIS_DS_Erased;
4314 aNamesOfDisplayIO.Append (aName);
4318 if (aNamesOfDisplayIO.IsEmpty())
4320 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4324 // Display interactive objects
4325 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
4327 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
4329 if (!GetMapOfAIS().IsBound2 (aName))
4331 // create the AIS_Shape from a name
4332 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
4333 if (!aShape.IsNull())
4335 if (isMutable != -1)
4337 aShape->SetMutable (isMutable == 1);
4339 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4341 aShape->SetZLayer (aZLayer);
4345 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4347 if (anObjDispMode != -2)
4349 aShape->SetDisplayMode (anObjDispMode);
4351 if (anObjHighMode != -2)
4353 aShape->SetHilightMode (anObjHighMode);
4356 GetMapOfAIS().Bind (aShape, aName);
4357 Standard_Integer aDispMode = aShape->HasDisplayMode()
4358 ? aShape->DisplayMode()
4359 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4360 ? aCtx->DisplayMode()
4362 Standard_Integer aSelMode = -1;
4363 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4365 aSelMode = aShape->GlobalSelectionMode();
4368 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
4369 if (toDisplayInView)
4371 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
4373 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
4375 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4380 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
4385 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
4386 if (isMutable != -1)
4388 aShape->SetMutable (isMutable == 1);
4390 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4392 aShape->SetZLayer (aZLayer);
4396 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4398 if (anObjDispMode != -2)
4400 aShape->SetDisplayMode (anObjDispMode);
4402 if (anObjHighMode != -2)
4404 aShape->SetHilightMode (anObjHighMode);
4406 Standard_Integer aDispMode = aShape->HasDisplayMode()
4407 ? aShape->DisplayMode()
4408 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4409 ? aCtx->DisplayMode()
4411 Standard_Integer aSelMode = -1;
4412 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4414 aSelMode = aShape->GlobalSelectionMode();
4417 if (aShape->Type() == AIS_KOI_Datum)
4419 aCtx->Display (aShape, Standard_False);
4423 theDI << "Display " << aName.ToCString() << "\n";
4425 // update the Shape in the AIS_Shape
4426 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
4427 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
4428 if (!aShapePrs.IsNull())
4430 if (!aShapePrs->Shape().IsEqual (aNewShape))
4432 toReDisplay = Standard_True;
4434 aShapePrs->Set (aNewShape);
4438 aCtx->Redisplay (aShape, Standard_False);
4443 aCtx->Erase (aShape, Standard_False);
4445 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
4446 if (toDisplayInView)
4448 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4456 //=======================================================================
4457 //function : VNbDisplayed
4458 //purpose : Returns number of displayed objects
4459 //=======================================================================
4460 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
4461 Standard_Integer theArgsNb,
4462 const char** theArgVec)
4466 theDi << "Usage : " << theArgVec[0] << "\n";
4470 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4471 if (aContextAIS.IsNull())
4473 std::cout << theArgVec[0] << "AIS context is not available.\n";
4477 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4478 if(aContext.IsNull())
4480 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
4484 AIS_ListOfInteractive aListOfIO;
4485 aContextAIS->DisplayedObjects (aListOfIO);
4487 theDi << aListOfIO.Extent() << "\n";
4491 //===============================================================================================
4492 //function : VUpdate
4494 //===============================================================================================
4495 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
4497 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4498 if (aContextAIS.IsNull())
4500 std::cout << theArgVec[0] << "AIS context is not available.\n";
4506 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
4510 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
4512 AIS_ListOfInteractive aListOfIO;
4514 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4516 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
4518 Handle(AIS_InteractiveObject) anAISObj;
4519 if (anAISMap.IsBound2 (aName))
4521 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
4524 if (anAISObj.IsNull())
4526 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
4530 aListOfIO.Append (anAISObj);
4533 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
4534 for (; anIOIt.More(); anIOIt.Next())
4536 aContextAIS->Update (anIOIt.Value(), Standard_False);
4539 aContextAIS->UpdateCurrentViewer();
4544 //==============================================================================
4545 //function : VShading
4546 //purpose : Sharpen or roughten the quality of the shading
4547 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4548 //==============================================================================
4549 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4551 Standard_Real myDevCoef;
4552 Handle(AIS_InteractiveObject) TheAisIO;
4555 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4559 myDevCoef =Draw::Atof(argv[2]);
4562 TCollection_AsciiString name=argv[1];
4563 if (GetMapOfAIS().IsBound2(name ))
4564 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4565 if (TheAisIO.IsNull())
4566 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4569 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4571 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4573 TheAISContext()->Redisplay (TheAisIO, Standard_True);
4577 //! Auxiliary method to print Interactive Object information
4578 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4579 const Handle(Standard_Transient)& theObject,
4580 Draw_Interpretor& theDI)
4582 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4585 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4589 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4590 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4591 << (theDetected.Contains (anObj) ? " Detected" : " ")
4593 if (anObj->Type() == AIS_KOI_Datum)
4596 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4597 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4598 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4599 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4600 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4601 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4602 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4605 else if (anObj->Type() == AIS_KOI_Shape
4606 && anObj->Signature() == 0)
4608 theDI << " AIS_Shape";
4610 else if (anObj->Type() == AIS_KOI_Relation)
4612 // AIS_Dimention and AIS_Relation
4613 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4614 switch (aRelation->KindOfDimension())
4616 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4617 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4618 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4619 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4620 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4621 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4622 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4623 default: theDI << " UNKNOWN dimension"; break;
4628 theDI << " UserPrs";
4630 theDI << " (" << theObject->DynamicType()->Name() << ")";
4633 //! Print information about locally selected sub-shapes
4634 template <typename T>
4635 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4637 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4638 TCollection_AsciiString aPrevName;
4639 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4641 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4642 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4643 if (aShapeIO.IsNull() || anOwner.IsNull())
4647 if (anOwner == aShapeIO->GlobalSelOwner())
4650 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4651 if (aSubShape.IsNull()
4652 || aShapeIO.IsNull()
4653 || !GetMapOfAIS().IsBound1 (aShapeIO))
4658 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4659 TopTools_MapOfShape aFilter;
4660 Standard_Integer aNumber = 0;
4661 const TopoDS_Shape aShape = aShapeIO->Shape();
4662 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4663 anIter.More(); anIter.Next())
4665 if (!aFilter.Add (anIter.Current()))
4667 continue; // filter duplicates
4671 if (!anIter.Current().IsSame (aSubShape))
4676 Standard_CString aShapeName = NULL;
4677 switch (aSubShape.ShapeType())
4679 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4680 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4681 case TopAbs_SOLID: aShapeName = " Solid"; break;
4682 case TopAbs_SHELL: aShapeName = " Shell"; break;
4683 case TopAbs_FACE: aShapeName = " Face"; break;
4684 case TopAbs_WIRE: aShapeName = " Wire"; break;
4685 case TopAbs_EDGE: aShapeName = " Edge"; break;
4686 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4688 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4691 if (aParentName != aPrevName)
4693 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4694 aPrevName = aParentName;
4696 theDI << " " << aShapeName << " #" << aNumber << "\n";
4702 //==============================================================================
4705 //==============================================================================
4706 static Standard_Integer VState (Draw_Interpretor& theDI,
4707 Standard_Integer theArgNb,
4708 Standard_CString* theArgVec)
4710 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4713 std::cerr << "Error: No opened viewer!\n";
4717 Standard_Boolean toPrintEntities = Standard_False;
4718 Standard_Boolean toCheckSelected = Standard_False;
4720 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4722 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4723 anOption.LowerCase();
4724 if (anOption == "-detectedentities"
4725 || anOption == "-entities")
4727 toPrintEntities = Standard_True;
4729 else if (anOption == "-hasselected")
4731 toCheckSelected = Standard_True;
4735 if (toCheckSelected)
4737 aCtx->InitSelected();
4738 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4739 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4744 if (toPrintEntities)
4746 theDI << "Detected entities:\n";
4747 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
4749 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4750 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4752 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4753 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4754 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4755 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4756 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4757 aName.LeftJustify (20, ' ');
4758 char anInfoStr[512];
4760 " Depth: %g Distance: %g Point: %g %g %g",
4763 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4764 theDI << " " << aName
4766 << " (" << anEntity->DynamicType()->Name() << ")"
4769 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4770 if (!aBRepOwner.IsNull())
4772 theDI << " Detected Shape: "
4773 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4777 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4778 if (!aWire.IsNull())
4780 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4781 theDI << " Detected Child: "
4782 << aSen->DynamicType()->Name()
4786 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4787 if (!aPrimArr.IsNull())
4789 theDI << " Detected Element: "
4790 << aPrimArr->LastDetectedElement()
4797 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4798 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4800 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
4803 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4807 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4809 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4810 if (!GetMapOfAIS().IsBound2 (anObjName))
4812 theDI << anObjName << " doesn't exist!\n";
4816 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4817 TCollection_AsciiString aName = anObjName;
4818 aName.LeftJustify (20, ' ');
4819 theDI << " " << aName << " ";
4820 objInfo (aDetected, anObjTrans, theDI);
4826 if (aCtx->NbSelected() > 0 && !toShowAll)
4828 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4829 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4831 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4832 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4833 // handle whole object selection
4834 if (anOwner == anObj->GlobalSelOwner())
4836 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4837 aName.LeftJustify (20, ' ');
4838 theDI << aName << " ";
4839 objInfo (aDetected, anObj, theDI);
4844 // process selected sub-shapes
4845 printLocalSelectionInfo (aCtx, theDI);
4850 theDI << "Neutral-point state:\n";
4851 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4852 anObjIter.More(); anObjIter.Next())
4854 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4860 TCollection_AsciiString aName = anObjIter.Key2();
4861 aName.LeftJustify (20, ' ');
4862 theDI << " " << aName << " ";
4863 objInfo (aDetected, anObj, theDI);
4866 printLocalSelectionInfo (aCtx, theDI);
4870 //=======================================================================
4871 //function : PickShape
4872 //purpose : First Activate the rightmode + Put Filters to be able to
4873 // pick objets that are of type <TheType>...
4874 //=======================================================================
4876 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
4877 const Standard_Integer theMaxPick)
4879 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
4880 PickShapes (theShapeType, aResArray, theMaxPick);
4881 return aResArray->First();
4884 //=======================================================================
4885 //function : PickShapes
4887 //=======================================================================
4888 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
4889 Handle(TopTools_HArray1OfShape)& theResArray,
4890 const Standard_Integer theMaxPick)
4892 const Standard_Integer aNbToReach = theResArray->Length();
4895 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4898 // step 1: prepare the data
4899 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4900 aCtx->RemoveFilters();
4901 AIS_ListOfInteractive aDispObjects;
4902 aCtx->DisplayedObjects (aDispObjects);
4903 if (theShapeType == TopAbs_SHAPE)
4905 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
4909 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
4912 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
4913 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
4915 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
4917 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
4921 // step 2 : wait for the selection...
4922 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
4923 Standard_Integer argccc = 5;
4924 const char *bufff[] = { "A", "B", "C", "D", "E" };
4925 const char **argvvv = (const char** )bufff;
4926 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
4928 while (ViewerMainLoop (argccc, argvvv)) {}
4929 Standard_Integer aNbStored = aCtx->NbSelected();
4930 if (aNbStored != aNbPickGood)
4932 aNbPickGood = aNbStored;
4938 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
4941 // step3 get result.
4942 if (aNbPickFail >= aNbToReach)
4944 return Standard_False;
4947 Standard_Integer anIndex = theResArray->Lower();
4948 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
4950 if (aCtx->HasSelectedShape())
4952 theResArray->SetValue (anIndex, aCtx->SelectedShape());
4956 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
4957 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
4961 aCtx->RemoveFilters();
4962 if (theShapeType != TopAbs_SHAPE)
4964 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
4966 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
4968 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
4972 return Standard_True;
4975 //=======================================================================
4976 //function : VPickShape
4978 //=======================================================================
4979 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4981 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4984 TCollection_AsciiString aShapeArg (argv[1]);
4985 aShapeArg.LowerCase();
4986 aShapeType = TopAbs_COMPOUND;
4987 if (aShapeArg == "v"
4988 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
4989 else if (aShapeArg == "e"
4990 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
4991 else if (aShapeArg == "w"
4992 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
4993 else if (aShapeArg == "f"
4994 || aShapeArg == "face") aShapeType = TopAbs_FACE;
4995 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
4996 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
4997 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
5000 std::cout << "Syntax error at '" << argv[1] << "'\n";
5005 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5006 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
5008 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
5011 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
5012 if (aPickedShape.IsNull())
5017 TCollection_AsciiString aName;
5024 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5025 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5028 DBRep::Set (aName.ToCString(), aPickedShape);
5029 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5030 ViewerTest::Display (aName, aShapePrs, false, true);
5031 di << "Name of picked shape: " << aName <<"\n";
5035 TCollection_AsciiString aName (argv[2]);
5037 const Standard_Boolean isAutoNaming = aName == ".";
5038 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5039 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5041 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5043 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5045 if (!aPickedShape.IsNull()
5048 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5049 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5053 aName = argv[1 + aPickedIter];
5056 DBRep::Set (aName.ToCString(), aPickedShape);
5057 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5058 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5059 ViewerTest::Display (aName, aShapePrs, false, true);
5063 TheAISContext()->UpdateCurrentViewer();
5067 //=======================================================================
5068 //function : VSelFilter
5070 //=======================================================================
5071 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5072 const char** theArgv)
5074 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5075 if (aContext.IsNull())
5077 std::cout << "Error: AIS context is not available.\n";
5081 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5083 TCollection_AsciiString anArg (theArgv[anArgIter]);
5085 if (anArg == "-clear")
5087 aContext->RemoveFilters();
5089 else if (anArg == "-type"
5090 && anArgIter + 1 < theArgc)
5092 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5093 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5094 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5096 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5100 Handle(SelectMgr_Filter) aFilter;
5101 if (aShapeType == TopAbs_SHAPE)
5103 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5107 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5109 aContext->AddFilter (aFilter);
5113 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5120 //=======================================================================
5121 //function : VPickSelected
5123 //=======================================================================
5124 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5126 static Standard_Integer aCount = 0;
5127 TCollection_AsciiString aName = "PickedShape_";
5135 aName = aName + aCount++ + "_";
5138 Standard_Integer anIdx = 0;
5139 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5141 TopoDS_Shape aShape;
5142 if (TheAISContext()->HasSelectedShape())
5144 aShape = TheAISContext()->SelectedShape();
5148 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5149 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5152 TCollection_AsciiString aCurrentName = aName;
5155 aCurrentName += anIdx;
5158 DBRep::Set ((aCurrentName).ToCString(), aShape);
5160 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5161 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5162 TheAISContext()->Display (aNewShape, Standard_False);
5165 TheAISContext()->UpdateCurrentViewer();
5170 //=======================================================================
5171 //function : list of known objects
5173 //=======================================================================
5174 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5176 // 1234567890 12345678901234567 123456789
5177 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5178 TCollection_AsciiString BlankLine(64,'_');
5179 Standard_Integer i ;
5181 di<<"/n"<<BlankLine.ToCString()<<"\n";
5184 Colum[i].Center(20,' ');
5186 di<<"|"<<Colum[i].ToCString();
5189 di<<BlankLine.ToCString()<<"\n";
5191 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5192 const char ** names = GetTypeNames();
5194 TCollection_AsciiString curstring;
5195 TCollection_AsciiString curcolum[3];
5198 // les objets de type Datum..
5199 curcolum[1]+="Datum";
5201 curcolum[0].Clear();
5202 curcolum[0] += names[i];
5204 curcolum[2].Clear();
5205 curcolum[2]+=TCollection_AsciiString(i+1);
5207 for(Standard_Integer j =0;j<=2;j++){
5208 curcolum[j].Center(20,' ');
5209 di<<"|"<<curcolum[j].ToCString();
5213 di<<BlankLine.ToCString()<<"\n";
5215 // les objets de type shape
5216 curcolum[1].Clear();
5217 curcolum[1]+="Shape";
5218 curcolum[1].Center(20,' ');
5221 curcolum[0].Clear();
5222 curcolum[0] += names[7+i];
5223 curcolum[2].Clear();
5224 curcolum[2]+=TCollection_AsciiString(i);
5226 for(Standard_Integer j =0;j<=2;j++){
5227 curcolum[j].Center(20,' ');
5228 di<<"|"<<curcolum[j].ToCString();
5232 di<<BlankLine.ToCString()<<"\n";
5233 // les IO de type objet...
5234 curcolum[1].Clear();
5235 curcolum[1]+="Object";
5236 curcolum[1].Center(20,' ');
5238 curcolum[0].Clear();
5239 curcolum[0] += names[10+i];
5240 curcolum[2].Clear();
5241 curcolum[2]+=TCollection_AsciiString(i);
5243 for(Standard_Integer j =0;j<=2;j++){
5244 curcolum[j].Center(20,' ');
5245 di<<"|"<<curcolum[j].ToCString();
5249 di<<BlankLine.ToCString()<<"\n";
5250 // les contraintes et dimensions.
5251 // pour l'instant on separe juste contraintes et dimensions...
5252 // plus tard, on detaillera toutes les sortes...
5253 curcolum[1].Clear();
5254 curcolum[1]+="Relation";
5255 curcolum[1].Center(20,' ');
5257 curcolum[0].Clear();
5258 curcolum[0] += names[12+i];
5259 curcolum[2].Clear();
5260 curcolum[2]+=TCollection_AsciiString(i);
5262 for(Standard_Integer j =0;j<=2;j++){
5263 curcolum[j].Center(20,' ');
5264 di<<"|"<<curcolum[j].ToCString();
5268 di<<BlankLine.ToCString()<<"\n";
5275 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5277 if(argc!=2) return 1;
5279 AIS_KindOfInteractive TheType;
5280 Standard_Integer TheSign(-1);
5281 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5284 AIS_ListOfInteractive LIO;
5286 // en attendant l'amelioration ais pour les dimensions...
5288 Standard_Integer dimension_status(-1);
5289 if(TheType==AIS_KOI_Relation){
5290 dimension_status = TheSign ==1 ? 1 : 0;
5294 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5295 Handle(AIS_InteractiveObject) curio;
5296 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5299 if(dimension_status == -1)
5300 TheAISContext()->Erase(curio,Standard_False);
5302 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5303 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5304 (dimension_status==1 && KOD != AIS_KOD_NONE))
5305 TheAISContext()->Erase(curio,Standard_False);
5308 TheAISContext()->UpdateCurrentViewer();
5311 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5313 if(argc!=2) return 1;
5315 AIS_KindOfInteractive TheType;
5316 Standard_Integer TheSign(-1);
5317 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5319 // en attendant l'amelioration ais pour les dimensions...
5321 Standard_Integer dimension_status(-1);
5322 if(TheType==AIS_KOI_Relation){
5323 dimension_status = TheSign ==1 ? 1 : 0;
5327 AIS_ListOfInteractive LIO;
5328 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5329 Handle(AIS_InteractiveObject) curio;
5330 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5332 if(dimension_status == -1)
5333 TheAISContext()->Display(curio,Standard_False);
5335 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5336 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5337 (dimension_status==1 && KOD != AIS_KOD_NONE))
5338 TheAISContext()->Display(curio,Standard_False);
5343 TheAISContext()->UpdateCurrentViewer();
5347 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5350 BRep_Builder builder;
5352 BRepTools::Read(shape, s, builder);
5353 DBRep::Set(a[1], shape);
5354 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5355 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5356 Ctx->Display (ais, Standard_True);
5360 //===============================================================================================
5363 //===============================================================================================
5364 static int VBsdf (Draw_Interpretor& theDI,
5365 Standard_Integer theArgsNb,
5366 const char** theArgVec)
5368 Handle(V3d_View) aView = ViewerTest::CurrentView();
5369 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5371 || aViewer.IsNull())
5373 std::cerr << "No active viewer!\n";
5377 ViewerTest_CmdParser aCmd;
5379 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5381 aCmd.AddOption ("print|echo|p", "Prints BSDF");
5383 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
5385 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
5386 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
5387 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
5388 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
5389 aCmd.AddOption ("le", "Radiance emitted by surface");
5391 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5392 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5394 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
5395 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
5397 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
5398 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
5400 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
5402 aCmd.Parse (theArgsNb, theArgVec);
5404 if (aCmd.HasOption ("help"))
5406 theDI.PrintHelp (theArgVec[0]);
5410 // check viewer update mode
5411 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
5413 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5415 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5421 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5424 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5425 if (!aMap.IsBound2 (aName) )
5427 std::cerr << "Use 'vdisplay' before\n";
5431 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5432 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5433 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5435 if (aCmd.HasOption ("print"))
5438 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
5439 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5440 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5441 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5442 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
5444 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5446 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
5447 : aBSDF.FresnelBase.Serialize();
5449 theDI << (aLayerID < 1 ? "Coat Fresnel: "
5450 : "Base Fresnel: ");
5452 if (aFresnel.x() >= 0.f)
5454 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
5455 << "G = " << aFresnel.g() << ", "
5456 << "B = " << aFresnel.b() << "\n";
5458 else if (aFresnel.x() >= -1.5f)
5460 theDI << "Constant " << aFresnel.z() << "\n";
5462 else if (aFresnel.x() >= -2.5f)
5464 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
5465 << "K = " << aFresnel.z() << "\n";
5469 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
5473 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
5474 << "Base roughness: " << aBSDF.Ks.w() << "\n"
5475 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
5476 << "Absorption color: " << aBSDF.Absorption.r() << ", "
5477 << aBSDF.Absorption.g() << ", "
5478 << aBSDF.Absorption.b() << "\n";
5483 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
5485 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
5488 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
5490 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
5493 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5495 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
5498 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5500 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
5502 aBSDF.Absorption.r() = aRGB.r();
5503 aBSDF.Absorption.g() = aRGB.g();
5504 aBSDF.Absorption.b() = aRGB.b();
5507 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
5511 if (aCmd.HasOption ("kc", 3))
5513 aKc = aCmd.ArgVec3f ("kc");
5517 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
5520 aBSDF.Kc.r() = aKc.r();
5521 aBSDF.Kc.g() = aKc.g();
5522 aBSDF.Kc.b() = aKc.b();
5525 if (aCmd.HasOption ("kd", 3))
5527 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5529 else if (aCmd.HasOption ("kd", 1, Standard_True))
5531 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5534 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
5538 if (aCmd.HasOption ("ks", 3))
5540 aKs = aCmd.ArgVec3f ("ks");
5544 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5547 aBSDF.Ks.r() = aKs.r();
5548 aBSDF.Ks.g() = aKs.g();
5549 aBSDF.Ks.b() = aKs.b();
5552 if (aCmd.HasOption ("kt", 3))
5554 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5556 else if (aCmd.HasOption ("kt", 1, Standard_True))
5558 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5561 if (aCmd.HasOption ("le", 3))
5563 aBSDF.Le = aCmd.ArgVec3f ("le");
5565 else if (aCmd.HasOption ("le", 1, Standard_True))
5567 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5570 const std::string aFresnelErrorMessage =
5571 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
5573 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5575 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
5578 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
5580 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5581 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5583 if (aFresnelType == "schlick")
5585 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
5586 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
5587 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
5589 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
5590 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
5591 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
5593 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
5597 theDI << aFresnelErrorMessage.c_str() << "\n";
5600 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
5602 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5603 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5605 if (aFresnelType == "conductor")
5607 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5608 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
5610 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
5614 theDI << aFresnelErrorMessage.c_str() << "\n";
5617 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
5619 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5620 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5622 if (aFresnelType == "constant")
5624 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5626 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
5628 else if (aFresnelType == "dielectric")
5630 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5632 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
5636 theDI << aFresnelErrorMessage.c_str() << "\n";
5641 if (aCmd.HasOption ("normalize"))
5646 aMaterial.SetBSDF (aBSDF);
5647 anIObj->SetMaterial (aMaterial);
5652 //==============================================================================
5653 //function : VLoadSelection
5654 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5655 //==============================================================================
5656 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5657 Standard_Integer theArgNb,
5658 const char** theArgVec)
5662 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5666 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5669 ViewerTest::ViewerInit();
5670 aCtx = ViewerTest::GetAISContext();
5673 // Parse input arguments
5674 TColStd_SequenceOfAsciiString aNamesOfIO;
5675 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5677 const TCollection_AsciiString aName = theArgVec[anArgIter];
5678 aNamesOfIO.Append (aName);
5681 if (aNamesOfIO.IsEmpty())
5683 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5687 // Load selection of interactive objects
5688 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5690 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5692 Handle(AIS_InteractiveObject) aShape;
5693 if (GetMapOfAIS().IsBound2 (aName))
5694 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5696 aShape = GetAISShapeFromName (aName.ToCString());
5698 if (!aShape.IsNull())
5700 if (!GetMapOfAIS().IsBound2 (aName))
5702 GetMapOfAIS().Bind (aShape, aName);
5705 aCtx->Load (aShape, -1);
5706 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5713 //==============================================================================
5714 //function : ViewerTest::Commands
5715 //purpose : Add all the viewer command in the Draw_Interpretor
5716 //==============================================================================
5718 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5720 ViewerTest::ViewerCommands(theCommands);
5721 ViewerTest::RelationCommands(theCommands);
5722 ViewerTest::ObjectCommands(theCommands);
5723 ViewerTest::FilletCommands(theCommands);
5724 ViewerTest::OpenGlCommands(theCommands);
5726 const char *group = "AIS_Display";
5729 theCommands.Add("visos",
5730 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5731 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5732 __FILE__, visos, group);
5734 theCommands.Add("vdisplay",
5735 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5736 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5737 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5738 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5739 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5740 "\n\t\t: [offsetX offsetY]]]"
5741 "\n\t\t: [-dispMode mode] [-highMode mode]"
5742 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5743 "\n\t\t: [-redisplay] [-erased]"
5744 "\n\t\t: name1 [name2] ... [name n]"
5745 "\n\t\t: Displays named objects."
5746 "\n\t\t: Option -local enables displaying of objects in local"
5747 "\n\t\t: selection context. Local selection context will be opened"
5748 "\n\t\t: if there is not any."
5749 "\n\t\t: -noupdate Suppresses viewer redraw call."
5750 "\n\t\t: -mutable Enables optimizations for mutable objects."
5751 "\n\t\t: -neutral Draws objects in main viewer."
5752 "\n\t\t: -erased Loads the object into context, but does not display it."
5753 "\n\t\t: -layer Sets z-layer for objects."
5754 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5755 "\n\t\t: options can be used for the default z-layers."
5756 "\n\t\t: -top Draws object on top of main presentations"
5757 "\n\t\t: but below topmost."
5758 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5759 "\n\t\t: with independent Depth."
5760 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5761 "\n\t\t: (On-Screen-Display)"
5762 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5763 "\n\t\t: (On-Screen-Display)"
5764 "\n\t\t: -selectable|-noselect Controls selection of objects."
5765 "\n\t\t: -trsfPers Sets a transform persistence flags."
5766 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5767 "\n\t\t: -2d Displays object in screen coordinates."
5768 "\n\t\t: (DY looks up)"
5769 "\n\t\t: -dispmode Sets display mode for objects."
5770 "\n\t\t: -highmode Sets hilight mode for objects."
5771 "\n\t\t: -redisplay Recomputes presentation of objects.",
5772 __FILE__, VDisplay2, group);
5774 theCommands.Add ("vnbdisplayed",
5776 "\n\t\t: Returns number of displayed objects",
5777 __FILE__, VNbDisplayed, group);
5779 theCommands.Add ("vupdate",
5780 "vupdate name1 [name2] ... [name n]"
5781 "\n\t\t: Updates named objects in interactive context",
5782 __FILE__, VUpdate, group);
5784 theCommands.Add("verase",
5785 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5786 "\n\t\t: Erases selected or named objects."
5787 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5788 "\n\t\t: Option -local enables erasing of selected or named objects without"
5789 "\n\t\t: closing local selection context.",
5790 __FILE__, VErase, group);
5792 theCommands.Add("vremove",
5793 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5794 "or vremove [-context] -all to remove all objects"
5795 "\n\t\t: Removes selected or named objects."
5796 "\n\t\t If -context is in arguments, the objects are not deleted"
5797 "\n\t\t from the map of objects and names."
5798 "\n\t\t: Option -local enables removing of selected or named objects without"
5799 "\n\t\t: closing local selection context. Empty local selection context will be"
5801 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5802 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5803 __FILE__, VRemove, group);
5805 theCommands.Add("vdonly",
5806 "vdonly [-noupdate|-update] [name1] ... [name n]"
5807 "\n\t\t: Displays only selected or named objects",
5808 __FILE__,VDonly2,group);
5810 theCommands.Add("vdisplayall",
5812 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
5813 __FILE__, VDisplayAll, group);
5815 theCommands.Add("veraseall",
5817 "\n\t\t: Erases all objects displayed in the viewer.",
5818 __FILE__, VErase, group);
5820 theCommands.Add("verasetype",
5822 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5823 __FILE__, VEraseType, group);
5824 theCommands.Add("vbounding",
5825 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5826 "\n\t\t: [-print] [-hide]"
5827 "\n\t\t: Temporarily display bounding box of specified Interactive"
5828 "\n\t\t: Objects, or print it to console if -print is specified."
5829 "\n\t\t: Already displayed box might be hidden by -hide option.",
5830 __FILE__,VBounding,group);
5832 theCommands.Add("vdisplaytype",
5833 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5834 __FILE__,VDisplayType,group);
5836 theCommands.Add("vsetdispmode",
5837 "vsetdispmode [name] mode(1,2,..)"
5838 "\n\t\t: Sets display mode for all, selected or named objects.",
5839 __FILE__,VDispMode,group);
5841 theCommands.Add("vunsetdispmode",
5842 "vunsetdispmode [name]"
5843 "\n\t\t: Unsets custom display mode for selected or named objects.",
5844 __FILE__,VDispMode,group);
5846 theCommands.Add("vdir",
5847 "Lists all objects displayed in 3D viewer",
5848 __FILE__,VDir,group);
5850 #ifdef HAVE_FREEIMAGE
5851 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5853 #define DUMP_FORMATS "{ppm}"
5855 theCommands.Add("vdump",
5856 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5857 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5858 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5859 "\n\t\t: [-tileSize Size=0]"
5860 "\n\t\t: Dumps content of the active view into image file",
5861 __FILE__,VDump,group);
5863 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5864 __FILE__,VSubInt,group);
5866 theCommands.Add("vaspects",
5867 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5868 "\n\t\t: [-setVisibility 0|1]"
5869 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5870 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5871 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5872 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5873 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5874 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
5875 "\n\t\t: [-unsetMarkerType]"
5876 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
5877 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5878 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5879 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5880 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5881 "\n\t\t: [-isoontriangulation 0|1]"
5882 "\n\t\t: [-setMaxParamValue {value}]"
5883 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5884 "\n\t\t: [-setHatch HatchStyle]"
5885 "\n\t\t: [-setShadingModel {color|flat|gouraud|phong}]"
5886 "\n\t\t: [-unsetShadingModel]"
5887 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
5888 "\n\t\t: Manage presentation properties of all, selected or named objects."
5889 "\n\t\t: When -subshapes is specified than following properties will be"
5890 "\n\t\t: assigned to specified sub-shapes."
5891 "\n\t\t: When -defaults is specified than presentation properties will be"
5892 "\n\t\t: assigned to all objects that have not their own specified properties"
5893 "\n\t\t: and to all objects to be displayed in the future."
5894 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5895 __FILE__,VAspects,group);
5897 theCommands.Add("vsetcolor",
5898 "vsetcolor [-noupdate|-update] [name] ColorName"
5899 "\n\t\t: Sets color for all, selected or named objects."
5900 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5901 __FILE__,VAspects,group);
5903 theCommands.Add("vunsetcolor",
5904 "vunsetcolor [-noupdate|-update] [name]"
5905 "\n\t\t: Resets color for all, selected or named objects."
5906 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5907 __FILE__,VAspects,group);
5909 theCommands.Add("vsettransparency",
5910 "vsettransparency [-noupdate|-update] [name] Coefficient"
5911 "\n\t\t: Sets transparency for all, selected or named objects."
5912 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5913 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5914 __FILE__,VAspects,group);
5916 theCommands.Add("vunsettransparency",
5917 "vunsettransparency [-noupdate|-update] [name]"
5918 "\n\t\t: Resets transparency for all, selected or named objects."
5919 "\n\t\t: Alias for vaspects -unsettransp [name].",
5920 __FILE__,VAspects,group);
5922 theCommands.Add("vsetmaterial",
5923 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5924 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5925 __FILE__,VAspects,group);
5927 theCommands.Add("vunsetmaterial",
5928 "vunsetmaterial [-noupdate|-update] [name]"
5929 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5930 __FILE__,VAspects,group);
5932 theCommands.Add("vsetwidth",
5933 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5934 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5935 __FILE__,VAspects,group);
5937 theCommands.Add("vunsetwidth",
5938 "vunsetwidth [-noupdate|-update] [name]"
5939 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5940 __FILE__,VAspects,group);
5942 theCommands.Add("vsetinteriorstyle",
5943 "vsetinteriorstyle [-noupdate|-update] [name] style"
5944 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5945 __FILE__,VSetInteriorStyle,group);
5947 theCommands.Add("vsensdis",
5948 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5949 "\n\t\t: Standard entity types are those defined in Select3D package:"
5950 "\n\t\t: - sensitive box"
5951 "\n\t\t: - sensitive face"
5952 "\n\t\t: - sensitive curve"
5953 "\n\t\t: - sensitive segment"
5954 "\n\t\t: - sensitive circle"
5955 "\n\t\t: - sensitive point"
5956 "\n\t\t: - sensitive triangulation"
5957 "\n\t\t: - sensitive triangle"
5958 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5959 __FILE__,VDispSensi,group);
5961 theCommands.Add("vsensera",
5962 "vsensera : erase active entities",
5963 __FILE__,VClearSensi,group);
5965 theCommands.Add("vsetshading",
5966 "vsetshading : vsetshading name Quality(default=0.0008) "
5967 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5968 __FILE__,VShading,group);
5970 theCommands.Add("vunsetshading",
5971 "vunsetshading :vunsetshading name "
5972 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5973 __FILE__,VShading,group);
5975 theCommands.Add ("vtexture",
5976 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
5977 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
5978 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
5979 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
5980 "\n\t\t: [-modulate {on|off}]"
5981 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
5982 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
5983 "\n\t\t: [-default]"
5984 "\n\t\t: The texture can be specified by filepath"
5985 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
5986 "\n\t\t: The options are:"
5987 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
5988 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
5989 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
5990 "\n\t\t: -modulate Enable or disable texture color modulation"
5991 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
5992 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
5993 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
5994 "\n\t\t: -setFilter Setup texture filter"
5995 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
5996 "\n\t\t: -default Sets texture mapping default parameters",
5997 __FILE__, VTexture, group);
5999 theCommands.Add("vtexscale",
6000 "vtexscale name ScaleU ScaleV"
6001 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
6002 __FILE__,VTexture,group);
6004 theCommands.Add("vtexorigin",
6005 "vtexorigin name OriginU OriginV"
6006 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
6007 __FILE__,VTexture,group);
6009 theCommands.Add("vtexrepeat",
6010 "vtexrepeat name RepeatU RepeatV"
6011 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
6014 theCommands.Add("vtexdefault",
6016 "\n\t\t: Alias for vtexture name -default.",
6019 theCommands.Add("vstate",
6020 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6021 "\n\t\t: Reports show/hidden state for selected or named objects"
6022 "\n\t\t: -entities - print low-level information about detected entities"
6023 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6024 __FILE__,VState,group);
6026 theCommands.Add("vpickshapes",
6027 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6028 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6029 "\n\t\t: Hold also Shift for multiple selection.",
6030 __FILE__, VPickShape, group);
6032 theCommands.Add("vtypes",
6033 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6036 theCommands.Add("vr",
6038 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6039 __FILE__,vr, group);
6041 theCommands.Add("vselfilter",
6042 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6043 "\nSets selection shape type filter in context or remove all filters."
6044 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6045 "\n : Option -clear remove all filters in context",
6046 __FILE__,VSelFilter,group);
6048 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6049 __FILE__, VPickSelected, group);
6051 theCommands.Add ("vloadselection",
6052 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6053 "\n\t\t: primitives for the shapes with names given without displaying them.",
6054 __FILE__, VLoadSelection, group);
6056 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6057 "\nAdjusts parameters of material BSDF:"
6058 "\n -help : Shows this message"
6059 "\n -print : Print BSDF"
6060 "\n -kd : Weight of the Lambertian BRDF"
6061 "\n -kr : Weight of the reflection BRDF"
6062 "\n -kt : Weight of the transmission BTDF"
6063 "\n -ks : Weight of the glossy Blinn BRDF"
6064 "\n -le : Self-emitted radiance"
6065 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6066 "\n Schlick x y z, Dielectric x, Conductor x y"
6067 "\n -roughness : Roughness of material (Blinn's exponent)"
6068 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6069 "\n -absorpcolor : Absorption color (only for transparent material)"
6070 "\n -normalize : Normalize BSDF coefficients",
6071 __FILE__, VBsdf, group);
6075 //=====================================================================
6076 //========================= for testing Draft and Rib =================
6077 //=====================================================================
6078 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6079 #include <DBRep.hxx>
6080 #include <TopoDS_Face.hxx>
6081 #include <gp_Pln.hxx>
6082 #include <AIS_KindOfSurface.hxx>
6083 #include <BRepOffsetAPI_DraftAngle.hxx>
6084 #include <Precision.hxx>
6085 #include <BRepAlgo.hxx>
6086 #include <OSD_Environment.hxx>
6087 #include <DrawTrSurf.hxx>
6088 //#include <DbgTools.hxx>
6089 //#include <FeatAlgo_MakeLinearForm.hxx>
6094 //=======================================================================
6095 //function : IsValid
6097 //=======================================================================
6098 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6099 const TopoDS_Shape& theResult,
6100 const Standard_Boolean closedSolid,
6101 const Standard_Boolean GeomCtrl)
6103 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6104 TCollection_AsciiString checkValid = check.Value();
6105 Standard_Boolean ToCheck = Standard_True;
6106 if (!checkValid.IsEmpty()) {
6108 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6110 if ( checkValid=="true" || checkValid=="TRUE" ) {
6111 ToCheck= Standard_False;
6115 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6118 Standard_Boolean IsValid = Standard_True;
6120 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6125 //===============================================================================
6126 // TDraft : test draft, uses AIS Viewer
6127 // Solid Face Plane Angle Reverse
6128 //===============================================================================
6129 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6131 if (argc < 5) return 1;
6132 // argv[1] - TopoDS_Shape Solid
6133 // argv[2] - TopoDS_Shape Face
6134 // argv[3] - TopoDS_Shape Plane
6135 // argv[4] - Standard_Real Angle
6136 // argv[5] - Standard_Integer Reverse
6138 // Sprintf(prefix, argv[1]);
6139 Standard_Real anAngle = 0;
6140 Standard_Boolean Rev = Standard_False;
6141 Standard_Integer rev = 0;
6142 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
6143 TopoDS_Shape face = GetShapeFromName(argv[2]);
6144 TopoDS_Face Face = TopoDS::Face(face);
6145 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
6146 if (Plane.IsNull ()) {
6147 di << "TEST : Plane is NULL\n";
6150 anAngle = Draw::Atof(argv[4]);
6151 anAngle = 2*M_PI * anAngle / 360.0;
6153 Handle( Geom_Surface )aSurf;
6154 AIS_KindOfSurface aSurfType;
6155 Standard_Real Offset;
6157 if(argc > 4) { // == 5
6158 rev = Draw::Atoi(argv[5]);
6159 Rev = (rev)? Standard_True : Standard_False;
6162 TopoDS_Face face2 = TopoDS::Face(Plane);
6163 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6165 di << "TEST : Can't find plane\n";
6169 aDir = aPln.Axis().Direction();
6172 if (Plane.Orientation() == TopAbs_REVERSED)
6174 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6176 BRepOffsetAPI_DraftAngle Draft (Solid);
6178 if(Abs(anAngle)< Precision::Angular()) {
6179 di << "TEST : NULL angle\n";
6182 if(Rev) anAngle = - anAngle;
6183 Draft.Add (Face, aDir, anAngle, aPln);
6185 if (!Draft.IsDone()) {
6186 di << "TEST : Draft Not DONE \n";
6189 TopTools_ListOfShape Larg;
6191 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6192 di << "TEST : DesignAlgo returns Not valid\n";
6196 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6197 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6199 if ( !ais.IsNull() ) {
6200 ais->SetColor(DEFAULT_COLOR);
6201 ais->SetMaterial(DEFAULT_MATERIAL);
6202 // Display the AIS_Shape without redraw
6203 Ctx->Display(ais, Standard_False);
6205 const char *Name = "draft1";
6206 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6208 Handle(AIS_InteractiveObject) an_object =
6209 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6210 if (!an_object.IsNull()) {
6211 Ctx->Remove(an_object,
6213 GetMapOfAIS().UnBind2(Name) ;
6216 GetMapOfAIS().Bind(ais, Name);
6217 // DBRep::Set("draft", ais->Shape());
6219 Ctx->Display(ais, Standard_True);
6223 //==============================================================================
6224 //function : splitParameter
6225 //purpose : Split parameter string to parameter name and parameter value
6226 //==============================================================================
6227 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6228 TCollection_AsciiString& theName,
6229 TCollection_AsciiString& theValue)
6231 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6233 if (aParamNameEnd == 0)
6235 return Standard_False;
6238 TCollection_AsciiString aString (theString);
6239 if (aParamNameEnd != 0)
6241 theValue = aString.Split (aParamNameEnd);
6242 aString.Split (aString.Length() - 1);
6246 return Standard_True;
6249 //============================================================================
6251 //============================================================================
6252 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6255 DrawTrSurf::BasicCommands(theCommands);
6256 const char* group = "Check Features Operations commands";
6258 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6260 &TDraft,group); //Draft_Modification
6263 //==============================================================================
6264 // ViewerTest::Factory
6265 //==============================================================================
6266 void ViewerTest::Factory(Draw_Interpretor& theDI)
6268 // definition of Viewer Command
6269 ViewerTest::Commands(theDI);
6272 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6276 // Declare entry point PLUGINFACTORY