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_LocalContext.hxx>
45 #include <AIS_ListOfInteractive.hxx>
46 #include <AIS_ListIteratorOfListOfInteractive.hxx>
47 #include <Aspect_InteriorStyle.hxx>
48 #include <Aspect_Window.hxx>
49 #include <Graphic3d_AspectFillArea3d.hxx>
50 #include <Graphic3d_AspectLine3d.hxx>
51 #include <Graphic3d_CStructure.hxx>
52 #include <Graphic3d_Texture2Dmanual.hxx>
53 #include <Graphic3d_GraphicDriver.hxx>
54 #include <Image_AlienPixMap.hxx>
55 #include <OSD_File.hxx>
56 #include <Prs3d_Drawer.hxx>
57 #include <Prs3d_ShadingAspect.hxx>
58 #include <Prs3d_IsoAspect.hxx>
59 #include <Prs3d_PointAspect.hxx>
60 #include <Select3D_SensitiveWire.hxx>
61 #include <Select3D_SensitivePrimitiveArray.hxx>
62 #include <SelectMgr_EntityOwner.hxx>
63 #include <StdSelect_BRepOwner.hxx>
64 #include <StdSelect_ViewerSelector3d.hxx>
65 #include <TopTools_MapOfShape.hxx>
66 #include <ViewerTest_AutoUpdater.hxx>
70 #include <Draw_Interpretor.hxx>
71 #include <TCollection_AsciiString.hxx>
72 #include <Draw_PluginMacro.hxx>
74 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
76 #include <Quantity_Color.hxx>
77 #include <Quantity_NameOfColor.hxx>
79 #include <Graphic3d_NameOfMaterial.hxx>
81 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
82 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
83 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
85 //=======================================================================
86 //function : GetColorFromName
87 //purpose : get the Quantity_NameOfColor from a string
88 //=======================================================================
90 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
92 Quantity_NameOfColor aColor = DEFAULT_COLOR;
93 Quantity_Color::ColorFromName (theName, aColor);
97 //=======================================================================
98 //function : ParseColor
100 //=======================================================================
102 Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
103 const char** theArgVec,
104 Quantity_Color& theColor)
106 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
108 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
113 else if (theArgNb >= 3)
115 const TCollection_AsciiString anRgbStr[3] =
121 if (!anRgbStr[0].IsRealValue()
122 || !anRgbStr[1].IsRealValue()
123 || !anRgbStr[2].IsRealValue())
128 Graphic3d_Vec4d anRgb;
129 anRgb.x() = anRgbStr[0].RealValue();
130 anRgb.y() = anRgbStr[1].RealValue();
131 anRgb.z() = anRgbStr[2].RealValue();
132 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
133 || anRgb.y() < 0.0 || anRgb.y() > 1.0
134 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
136 std::cout << "Error: RGB color values should be within range 0..1!\n";
140 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
147 //=======================================================================
148 //function : ParseOnOff
150 //=======================================================================
151 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
152 Standard_Boolean& theIsOn)
154 TCollection_AsciiString aFlag(theArg);
159 theIsOn = Standard_True;
160 return Standard_True;
162 else if (aFlag == "off"
165 theIsOn = Standard_False;
166 return Standard_True;
168 return Standard_False;
171 //=======================================================================
172 //function : GetSelectedShapes
174 //=======================================================================
175 void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
177 for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
179 TopoDS_Shape aShape = GetAISContext()->SelectedShape();
180 if (!aShape.IsNull())
182 theSelectedShapes.Append (aShape);
187 //=======================================================================
188 //function : ParseLineType
190 //=======================================================================
191 Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
192 Aspect_TypeOfLine& theType)
194 TCollection_AsciiString aTypeStr (theArg);
195 aTypeStr.LowerCase();
196 if (aTypeStr == "empty")
198 theType = Aspect_TOL_EMPTY;
200 else if (aTypeStr == "solid")
202 theType = Aspect_TOL_SOLID;
204 else if (aTypeStr == "dot")
206 theType = Aspect_TOL_DOT;
208 else if (aTypeStr == "dash")
210 theType = Aspect_TOL_DASH;
212 else if (aTypeStr == "dotdash")
214 theType = Aspect_TOL_DOTDASH;
218 const int aTypeInt = Draw::Atoi (theArg);
219 if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
221 return Standard_False;
223 theType = (Aspect_TypeOfLine )aTypeInt;
225 return Standard_True;
228 //=======================================================================
229 //function : ParseMarkerType
231 //=======================================================================
232 Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
233 Aspect_TypeOfMarker& theType,
234 Handle(Image_PixMap)& theImage)
237 TCollection_AsciiString aTypeStr (theArg);
238 aTypeStr.LowerCase();
239 if (aTypeStr == "empty")
241 theType = Aspect_TOM_EMPTY;
243 else if (aTypeStr == "point"
247 theType = Aspect_TOM_POINT;
249 else if (aTypeStr == "plus"
252 theType = Aspect_TOM_PLUS;
254 else if (aTypeStr == "star"
257 theType = Aspect_TOM_STAR;
259 else if (aTypeStr == "cross"
262 theType = Aspect_TOM_X;
264 else if (aTypeStr == "circle"
267 theType = Aspect_TOM_O;
269 else if (aTypeStr == "pointincircle")
271 theType = Aspect_TOM_O_POINT;
273 else if (aTypeStr == "plusincircle")
275 theType = Aspect_TOM_O_PLUS;
277 else if (aTypeStr == "starincircle")
279 theType = Aspect_TOM_O_STAR;
281 else if (aTypeStr == "crossincircle"
282 || aTypeStr == "xcircle")
284 theType = Aspect_TOM_O_X;
286 else if (aTypeStr == "ring1")
288 theType = Aspect_TOM_RING1;
290 else if (aTypeStr == "ring2")
292 theType = Aspect_TOM_RING2;
294 else if (aTypeStr == "ring"
295 || aTypeStr == "ring3")
297 theType = Aspect_TOM_RING3;
299 else if (aTypeStr == "ball")
301 theType = Aspect_TOM_BALL;
303 else if (aTypeStr.IsIntegerValue())
305 const int aTypeInt = aTypeStr.IntegerValue();
306 if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED)
308 return Standard_False;
310 theType = (Aspect_TypeOfMarker )aTypeInt;
314 theType = Aspect_TOM_USERDEFINED;
315 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
316 if (!anImage->Load (theArg))
318 return Standard_False;
320 if (anImage->Format() == Image_Format_Gray)
322 anImage->SetFormat (Image_Format_Alpha);
324 else if (anImage->Format() == Image_Format_GrayF)
326 anImage->SetFormat (Image_Format_AlphaF);
330 return Standard_True;
333 //=======================================================================
334 //function : ParseShadingModel
336 //=======================================================================
337 Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg,
338 Graphic3d_TypeOfShadingModel& theModel)
340 TCollection_AsciiString aTypeStr (theArg);
341 aTypeStr.LowerCase();
342 if (aTypeStr == "unlit"
343 || aTypeStr == "color"
344 || aTypeStr == "none")
346 theModel = Graphic3d_TOSM_UNLIT;
348 else if (aTypeStr == "flat"
349 || aTypeStr == "facet")
351 theModel = Graphic3d_TOSM_FACET;
353 else if (aTypeStr == "gouraud"
354 || aTypeStr == "vertex"
355 || aTypeStr == "vert")
357 theModel = Graphic3d_TOSM_VERTEX;
359 else if (aTypeStr == "phong"
360 || aTypeStr == "fragment"
361 || aTypeStr == "frag"
362 || aTypeStr == "pixel")
364 theModel = Graphic3d_TOSM_FRAGMENT;
366 else if (aTypeStr == "default"
367 || aTypeStr == "def")
369 theModel = Graphic3d_TOSM_DEFAULT;
371 else if (aTypeStr.IsIntegerValue())
373 const int aTypeInt = aTypeStr.IntegerValue();
374 if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
376 return Standard_False;
378 theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
382 return Standard_False;
384 return Standard_True;
387 //=======================================================================
388 //function : GetTypeNames
390 //=======================================================================
391 static const char** GetTypeNames()
393 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
394 "Shape","ConnectedShape","MultiConn.Shape",
395 "ConnectedInter.","MultiConn.",
396 "Constraint","Dimension"};
397 static const char** ThePointer = names;
401 //=======================================================================
402 //function : GetTypeAndSignfromString
404 //=======================================================================
405 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
407 const char ** thefullnames = GetTypeNames();
408 Standard_Integer index(-1);
410 for(Standard_Integer i=0;i<=13 && index==-1;i++)
411 if(!strcasecmp(name,thefullnames[i]))
415 TheType = AIS_KOI_None;
421 TheType = AIS_KOI_Datum;
425 TheType = AIS_KOI_Shape;
429 TheType = AIS_KOI_Object;
433 TheType = AIS_KOI_Relation;
442 #include <Draw_Interpretor.hxx>
444 #include <Draw_Appli.hxx>
448 #include <TCollection_AsciiString.hxx>
449 #include <V3d_Viewer.hxx>
450 #include <V3d_View.hxx>
453 #include <AIS_InteractiveContext.hxx>
454 #include <AIS_Shape.hxx>
455 #include <AIS_DisplayMode.hxx>
456 #include <TColStd_MapOfInteger.hxx>
457 #include <AIS_MapOfInteractive.hxx>
458 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
459 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
460 #include <ViewerTest_EventManager.hxx>
462 #include <TopoDS_Solid.hxx>
463 #include <BRepTools.hxx>
464 #include <BRep_Builder.hxx>
465 #include <TopAbs_ShapeEnum.hxx>
467 #include <TopoDS.hxx>
468 #include <BRep_Tool.hxx>
471 #include <Draw_Window.hxx>
472 #include <AIS_ListIteratorOfListOfInteractive.hxx>
473 #include <AIS_ListOfInteractive.hxx>
474 #include <AIS_DisplayMode.hxx>
475 #include <TopTools_ListOfShape.hxx>
476 #include <BRepOffsetAPI_MakeThickSolid.hxx>
478 //==============================================================================
479 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
480 //==============================================================================
481 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
482 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
486 //=======================================================================
489 //=======================================================================
490 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
491 const Handle(AIS_InteractiveObject)& theObject,
492 const Standard_Boolean theToUpdate,
493 const Standard_Boolean theReplaceIfExists)
495 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
496 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
499 std::cout << "Error: AIS context is not available.\n";
500 return Standard_False;
503 if (aMap.IsBound2 (theName))
505 if (!theReplaceIfExists)
507 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
508 << "Please use another name.\n";
509 return Standard_False;
512 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
513 if (!anOldObj.IsNull())
515 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
517 aMap.UnBind2 (theName);
520 if (theObject.IsNull())
522 // object with specified name has been already unbound
523 return Standard_True;
526 // unbind AIS object if it was bound with another name
527 aMap.UnBind1 (theObject);
529 // can be registered without rebinding
530 aMap.Bind (theObject, theName);
531 aCtx->Display (theObject, theToUpdate);
532 return Standard_True;
535 //! Alias for ViewerTest::Display(), compatibility with old code.
536 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
537 const Handle(AIS_InteractiveObject)& theObject,
538 Standard_Boolean theReplaceIfExists = Standard_True)
540 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
543 static TColStd_MapOfInteger theactivatedmodes(8);
544 static TColStd_ListOfTransient theEventMgrs;
546 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
547 const Handle(AIS_InteractiveContext)& Ctx)
549 theEventMgrs.Clear();
550 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
553 static Handle(V3d_View)& a3DView()
555 static Handle(V3d_View) Viou;
560 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
561 static Handle(AIS_InteractiveContext) aContext;
565 const Handle(V3d_View)& ViewerTest::CurrentView()
569 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
574 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
576 return TheAISContext();
579 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
581 TheAISContext() = aCtx;
582 ViewerTest::ResetEventManager();
585 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
587 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
590 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
592 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
596 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
597 theEventMgrs.Prepend(EM);
600 void ViewerTest::UnsetEventManager()
602 theEventMgrs.RemoveFirst();
606 void ViewerTest::ResetEventManager()
608 const Handle(V3d_View) aView = ViewerTest::CurrentView();
609 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
612 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
614 Handle(ViewerTest_EventManager) EM;
615 if(theEventMgrs.IsEmpty()) return EM;
616 Handle(Standard_Transient) Tr = theEventMgrs.First();
617 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
621 //=======================================================================
622 //function : Get Context and active view
624 //=======================================================================
625 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
626 Handle(V3d_View)& theView)
628 theCtx = ViewerTest::GetAISContext();
629 theView = ViewerTest::CurrentView();
633 std::cout << "Error: cannot find an active view!\n";
634 return Standard_False;
636 return Standard_True;
639 //==============================================================================
640 //function : GetShapeFromName
641 //purpose : Compute an Shape from a draw variable or a file name
642 //==============================================================================
644 static TopoDS_Shape GetShapeFromName(const char* name)
646 TopoDS_Shape S = DBRep::Get(name);
649 BRep_Builder aBuilder;
650 BRepTools::Read( S, name, aBuilder);
656 //==============================================================================
657 //function : GetAISShapeFromName
658 //purpose : Compute an AIS_Shape from a draw variable or a file name
659 //==============================================================================
660 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
662 Handle(AIS_Shape) retsh;
664 if(GetMapOfAIS().IsBound2(name)){
665 const Handle(AIS_InteractiveObject) IO =
666 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
668 if(IO->Type()==AIS_KOI_Shape) {
669 if(IO->Signature()==0){
670 retsh = Handle(AIS_Shape)::DownCast (IO);
673 cout << "an Object which is not an AIS_Shape "
674 "already has this name!!!"<<endl;
681 TopoDS_Shape S = GetShapeFromName(name);
683 retsh = new AIS_Shape(S);
689 //==============================================================================
691 //purpose : Remove all the object from the viewer
692 //==============================================================================
693 void ViewerTest::Clear()
695 if (a3DView().IsNull())
700 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
701 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
703 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
704 if (anObj->GetContext() != TheAISContext())
709 std::cout << "Remove " << anObjIter.Key2() << std::endl;
710 TheAISContext()->Remove (anObj, Standard_False);
711 aListRemoved.Append (anObj);
714 TheAISContext()->RebuildSelectionStructs();
715 TheAISContext()->UpdateCurrentViewer();
716 if (aListRemoved.Size() == GetMapOfAIS().Extent())
718 GetMapOfAIS().Clear();
722 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
724 GetMapOfAIS().UnBind1 (anObjIter.Value());
729 //==============================================================================
730 //function : CopyIsoAspect
731 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
732 //==============================================================================
733 static Handle(Prs3d_IsoAspect) CopyIsoAspect
734 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
735 const Standard_Integer theNbIsos)
737 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
738 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
739 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
741 Handle(Prs3d_IsoAspect) aResult =
742 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
747 //==============================================================================
749 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
750 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
751 //==============================================================================
752 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
754 if (TheAISContext().IsNull()) {
755 di << argv[0] << " Call 'vinit' before!\n";
760 di << "Current number of isos : " <<
761 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
762 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
763 di << "IsoOnPlane mode is " <<
764 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
765 di << "IsoOnTriangulation mode is " <<
766 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
770 Standard_Integer aLastInd = argc - 1;
771 Standard_Boolean isChanged = Standard_False;
772 Standard_Integer aNbUIsos = 0;
773 Standard_Integer aNbVIsos = 0;
776 Standard_Boolean isIsoOnPlane = Standard_False;
778 if (strcmp(argv[aLastInd], "1") == 0) {
779 isIsoOnPlane = Standard_True;
780 isChanged = Standard_True;
781 } else if (strcmp(argv[aLastInd], "0") == 0) {
782 isIsoOnPlane = Standard_False;
783 isChanged = Standard_True;
787 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
788 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
791 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
792 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
794 TheAISContext()->IsoOnPlane(isIsoOnPlane);
797 // If there are no shapes provided set the default numbers.
798 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
799 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
806 for (i = 1; i <= aLastInd; i++) {
807 TCollection_AsciiString name(argv[i]);
808 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
811 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
812 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
813 const Handle(AIS_InteractiveObject) aShape =
814 Handle(AIS_InteractiveObject)::DownCast (anObj);
815 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
816 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
817 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
820 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
821 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
822 TheAISContext()->SetLocalAttributes
823 (aShape, CurDrawer, Standard_False);
824 TheAISContext()->Redisplay (aShape, Standard_False);
826 di << "Number of isos for " << argv[i] << " : "
827 << aUIso->Number() << " " << aVIso->Number() << "\n";
830 di << argv[i] << ": Not an AIS interactive object!\n";
833 di << argv[i] << ": Use 'vdisplay' before\n";
838 TheAISContext()->UpdateCurrentViewer();
844 static Standard_Integer VDispSensi (Draw_Interpretor& ,
845 Standard_Integer theArgNb,
850 std::cout << "Error: wrong syntax!\n";
854 Handle(AIS_InteractiveContext) aCtx;
855 Handle(V3d_View) aView;
856 if (!getCtxAndView (aCtx, aView))
861 aCtx->DisplayActiveSensitive (aView);
866 static Standard_Integer VClearSensi (Draw_Interpretor& ,
867 Standard_Integer theArgNb,
872 std::cout << "Error: wrong syntax!\n";
876 Handle(AIS_InteractiveContext) aCtx;
877 Handle(V3d_View) aView;
878 if (!getCtxAndView (aCtx, aView))
882 aCtx->ClearActiveSensitive (aView);
886 //==============================================================================
888 //purpose : To list the displayed object with their attributes
889 //==============================================================================
890 static int VDir (Draw_Interpretor& theDI,
894 if (!a3DView().IsNull())
899 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
900 anIter.More(); anIter.Next())
902 theDI << "\t" << anIter.Key2().ToCString() << "\n";
907 //! Auxiliary enumeration
908 enum ViewerTest_StereoPair
910 ViewerTest_SP_Single,
911 ViewerTest_SP_SideBySide,
912 ViewerTest_SP_OverUnder
915 //==============================================================================
917 //purpose : To dump the active view snapshot to image file
918 //==============================================================================
919 static Standard_Integer VDump (Draw_Interpretor& theDI,
920 Standard_Integer theArgNb,
921 Standard_CString* theArgVec)
925 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
929 Standard_Integer anArgIter = 1;
930 Standard_CString aFilePath = theArgVec[anArgIter++];
931 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
932 V3d_ImageDumpOptions aParams;
933 aParams.BufferType = Graphic3d_BT_RGB;
934 aParams.StereoOptions = V3d_SDO_MONO;
935 for (; anArgIter < theArgNb; ++anArgIter)
937 TCollection_AsciiString anArg (theArgVec[anArgIter]);
939 if (anArg == "-buffer")
941 if (++anArgIter >= theArgNb)
943 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
947 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
949 if (aBufArg == "rgba")
951 aParams.BufferType = Graphic3d_BT_RGBA;
953 else if (aBufArg == "rgb")
955 aParams.BufferType = Graphic3d_BT_RGB;
957 else if (aBufArg == "depth")
959 aParams.BufferType = Graphic3d_BT_Depth;
963 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
967 else if (anArg == "-stereo")
969 if (++anArgIter >= theArgNb)
971 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
975 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
976 aStereoArg.LowerCase();
977 if (aStereoArg == "l"
978 || aStereoArg == "left")
980 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
982 else if (aStereoArg == "r"
983 || aStereoArg == "right")
985 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
987 else if (aStereoArg == "mono")
989 aParams.StereoOptions = V3d_SDO_MONO;
991 else if (aStereoArg == "blended"
992 || aStereoArg == "blend"
993 || aStereoArg == "stereo")
995 aParams.StereoOptions = V3d_SDO_BLENDED;
997 else if (aStereoArg == "sbs"
998 || aStereoArg == "sidebyside")
1000 aStereoPair = ViewerTest_SP_SideBySide;
1002 else if (aStereoArg == "ou"
1003 || aStereoArg == "overunder")
1005 aStereoPair = ViewerTest_SP_OverUnder;
1009 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
1013 else if (anArg == "-rgba"
1016 aParams.BufferType = Graphic3d_BT_RGBA;
1018 else if (anArg == "-rgb"
1021 aParams.BufferType = Graphic3d_BT_RGB;
1023 else if (anArg == "-depth"
1024 || anArg == "depth")
1026 aParams.BufferType = Graphic3d_BT_Depth;
1028 else if (anArg == "-width"
1030 || anArg == "sizex")
1032 if (aParams.Width != 0)
1034 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1037 else if (++anArgIter >= theArgNb)
1039 std::cout << "Error: integer value is expected right after 'width'\n";
1042 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1044 else if (anArg == "-height"
1045 || anArg == "height"
1046 || anArg == "-sizey")
1048 if (aParams.Height != 0)
1050 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1053 else if (++anArgIter >= theArgNb)
1055 std::cout << "Error: integer value is expected right after 'height'\n";
1058 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1060 else if (anArg == "-tile"
1061 || anArg == "-tilesize")
1063 if (++anArgIter >= theArgNb)
1065 std::cout << "Error: integer value is expected right after 'tileSize'\n";
1068 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1072 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
1076 if ((aParams.Width <= 0 && aParams.Height > 0)
1077 || (aParams.Width > 0 && aParams.Height <= 0))
1079 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
1083 Handle(V3d_View) aView = ViewerTest::CurrentView();
1086 std::cout << "Error: cannot find an active view!\n";
1090 if (aParams.Width <= 0 || aParams.Height <= 0)
1092 aView->Window()->Size (aParams.Width, aParams.Height);
1095 Image_AlienPixMap aPixMap;
1096 Image_Format aFormat = Image_Format_UNKNOWN;
1097 switch (aParams.BufferType)
1099 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1100 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1101 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1102 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1105 switch (aStereoPair)
1107 case ViewerTest_SP_Single:
1109 if (!aView->ToPixMap (aPixMap, aParams))
1111 theDI << "Fail: view dump failed!\n";
1114 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1115 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1117 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1118 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1122 case ViewerTest_SP_SideBySide:
1124 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1126 theDI << "Fail: not enough memory for image allocation!\n";
1130 Image_PixMap aPixMapL, aPixMapR;
1131 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1132 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1133 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1134 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1136 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1137 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1138 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1139 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1142 theDI << "Fail: view dump failed!\n";
1147 case ViewerTest_SP_OverUnder:
1149 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1151 theDI << "Fail: not enough memory for image allocation!\n";
1155 Image_PixMap aPixMapL, aPixMapR;
1156 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1157 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1158 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1159 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1161 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1162 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1163 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1164 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1167 theDI << "Fail: view dump failed!\n";
1174 if (!aPixMap.Save (aFilePath))
1176 theDI << "Fail: image can not be saved!\n";
1181 enum TypeOfDispOperation
1183 TypeOfDispOperation_SetDispMode,
1184 TypeOfDispOperation_UnsetDispMode
1187 //! Displays,Erase...
1188 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1189 const Standard_Integer theMode,
1190 const TypeOfDispOperation theType,
1191 const Standard_Boolean theToUpdate)
1193 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1196 case TypeOfDispOperation_SetDispMode:
1198 if (!thePrs.IsNull())
1200 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1204 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1208 case TypeOfDispOperation_UnsetDispMode:
1210 if (!thePrs.IsNull())
1212 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1216 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1223 //=======================================================================
1226 //=======================================================================
1227 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1232 std::cout << "Syntax error: wrong number of arguments\n";
1236 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1237 ? TypeOfDispOperation_UnsetDispMode
1238 : TypeOfDispOperation_SetDispMode;
1239 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1240 if (aType == TypeOfDispOperation_UnsetDispMode)
1244 if (aCtx->NbSelected() == 0)
1246 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1250 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1252 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1255 aCtx->UpdateCurrentViewer();
1259 TCollection_AsciiString aName = argv[1];
1260 if (GetMapOfAIS().IsBound2 (aName))
1262 Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1265 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1272 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1273 if (aCtx->NbSelected() == 0
1274 && aType == TypeOfDispOperation_SetDispMode)
1276 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1278 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1280 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1282 aCtx->UpdateCurrentViewer();
1286 Handle(AIS_InteractiveObject) aPrs;
1287 TCollection_AsciiString aName (argv[1]);
1288 if (GetMapOfAIS().IsBound2 (aName))
1290 aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1294 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1301 //=======================================================================
1304 //=======================================================================
1305 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1307 if(argc==1) return 1;
1308 Standard_Integer On = Draw::Atoi(argv[1]);
1309 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1313 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1314 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1315 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1319 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1323 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1327 Ctx->UpdateCurrentViewer();
1330 Handle(AIS_InteractiveObject) IO;
1331 TCollection_AsciiString name = argv[2];
1332 if(GetMapOfAIS().IsBound2(name)){
1333 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1336 Ctx->SubIntensityOn(IO, Standard_True);
1338 Ctx->SubIntensityOff(IO, Standard_True);
1346 //! Auxiliary class to iterate presentations from different collections.
1347 class ViewTest_PrsIter
1351 //! Create and initialize iterator object.
1352 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1353 : mySource (IterSource_All)
1355 NCollection_Sequence<TCollection_AsciiString> aNames;
1356 if (!theName.IsEmpty())
1357 aNames.Append (theName);
1361 //! Create and initialize iterator object.
1362 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1363 : mySource (IterSource_All)
1368 //! Initialize the iterator.
1369 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1371 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1373 mySelIter.Nullify();
1374 myCurrent.Nullify();
1375 myCurrentTrs.Nullify();
1376 if (!mySeq.IsEmpty())
1378 mySource = IterSource_List;
1379 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1381 else if (aCtx->NbSelected() > 0)
1383 mySource = IterSource_Selected;
1385 mySelIter->InitSelected();
1389 mySource = IterSource_All;
1390 myMapIter.Initialize (GetMapOfAIS());
1395 const TCollection_AsciiString& CurrentName() const
1397 return myCurrentName;
1400 const Handle(AIS_InteractiveObject)& Current() const
1405 const Handle(Standard_Transient)& CurrentTrs() const
1407 return myCurrentTrs;
1410 //! @return true if iterator points to valid object within collection
1411 Standard_Boolean More() const
1415 case IterSource_All: return myMapIter.More();
1416 case IterSource_List: return mySeqIter.More();
1417 case IterSource_Selected: return mySelIter->MoreSelected();
1419 return Standard_False;
1422 //! Go to the next item.
1425 myCurrentName.Clear();
1426 myCurrentTrs.Nullify();
1427 myCurrent.Nullify();
1430 case IterSource_All:
1435 case IterSource_List:
1440 case IterSource_Selected:
1442 mySelIter->NextSelected();
1455 case IterSource_All:
1457 if (myMapIter.More())
1459 myCurrentName = myMapIter.Key2();
1460 myCurrentTrs = myMapIter.Key1();
1461 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1465 case IterSource_List:
1467 if (mySeqIter.More())
1469 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1471 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1474 myCurrentName = mySeqIter.Value();
1475 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1476 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1480 case IterSource_Selected:
1482 if (mySelIter->MoreSelected())
1484 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1485 myCurrent = mySelIter->SelectedInteractive();
1503 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1504 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1505 NCollection_Sequence<TCollection_AsciiString> mySeq;
1506 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1508 TCollection_AsciiString myCurrentName;//!< current item name
1509 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1510 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1512 IterSource mySource; //!< iterated collection
1516 //==============================================================================
1517 //function : VInteriorStyle
1518 //purpose : sets interior style of the a selected or named or displayed shape
1519 //==============================================================================
1520 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1521 Standard_Integer theArgNb,
1522 const char** theArgVec)
1524 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1525 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1528 std::cerr << "Error: no active view!\n";
1532 Standard_Integer anArgIter = 1;
1533 for (; anArgIter < theArgNb; ++anArgIter)
1535 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1540 TCollection_AsciiString aName;
1541 if (theArgNb - anArgIter == 2)
1543 aName = theArgVec[anArgIter++];
1545 else if (theArgNb - anArgIter != 1)
1547 std::cout << "Error: wrong number of arguments! See usage:\n";
1548 theDI.PrintHelp (theArgVec[0]);
1551 Aspect_InteriorStyle anInterStyle = Aspect_IS_SOLID;
1552 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1553 aStyleArg.LowerCase();
1554 if (aStyleArg == "empty")
1556 anInterStyle = Aspect_IS_EMPTY;
1558 else if (aStyleArg == "hollow")
1560 anInterStyle = Aspect_IS_HOLLOW;
1562 else if (aStyleArg == "hatch")
1564 anInterStyle = Aspect_IS_HATCH;
1566 else if (aStyleArg == "solid")
1568 anInterStyle = Aspect_IS_SOLID;
1570 else if (aStyleArg == "hiddenline")
1572 anInterStyle = Aspect_IS_HIDDENLINE;
1574 else if (aStyleArg == "point")
1576 anInterStyle = Aspect_IS_POINT;
1580 const Standard_Integer anIntStyle = aStyleArg.IntegerValue();
1581 if (anIntStyle < Aspect_IS_EMPTY
1582 || anIntStyle > Aspect_IS_POINT)
1584 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1585 << Aspect_IS_POINT << " (Aspect_IS_POINT)]\n";
1588 anInterStyle = (Aspect_InteriorStyle )anIntStyle;
1591 if (!aName.IsEmpty()
1592 && !GetMapOfAIS().IsBound2 (aName))
1594 std::cout << "Error: object " << aName << " is not displayed!\n";
1598 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1600 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1603 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1604 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1605 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1606 aFillAspect->SetInteriorStyle (anInterStyle);
1607 if (anInterStyle == Aspect_IS_HATCH
1608 && aFillAspect->HatchStyle().IsNull())
1610 aFillAspect->SetHatchStyle (Aspect_HS_VERTICAL);
1612 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1618 //! Auxiliary structure for VAspects
1619 struct ViewerTest_AspectsChangeSet
1621 Standard_Integer ToSetVisibility;
1622 Standard_Integer Visibility;
1624 Standard_Integer ToSetColor;
1625 Quantity_Color Color;
1627 Standard_Integer ToSetLineWidth;
1628 Standard_Real LineWidth;
1630 Standard_Integer ToSetTypeOfLine;
1631 Aspect_TypeOfLine TypeOfLine;
1633 Standard_Integer ToSetTypeOfMarker;
1634 Aspect_TypeOfMarker TypeOfMarker;
1635 Handle(Image_PixMap) MarkerImage;
1637 Standard_Integer ToSetMarkerSize;
1638 Standard_Real MarkerSize;
1640 Standard_Integer ToSetTransparency;
1641 Standard_Real Transparency;
1643 Standard_Integer ToSetAlphaMode;
1644 Graphic3d_AlphaMode AlphaMode;
1645 Standard_ShortReal AlphaCutoff;
1647 Standard_Integer ToSetMaterial;
1648 Graphic3d_NameOfMaterial Material;
1649 TCollection_AsciiString MatName;
1651 NCollection_Sequence<TopoDS_Shape> SubShapes;
1653 Standard_Integer ToSetShowFreeBoundary;
1654 Standard_Integer ToSetFreeBoundaryWidth;
1655 Standard_Real FreeBoundaryWidth;
1656 Standard_Integer ToSetFreeBoundaryColor;
1657 Quantity_Color FreeBoundaryColor;
1659 Standard_Integer ToEnableIsoOnTriangulation;
1661 Standard_Integer ToSetMaxParamValue;
1662 Standard_Real MaxParamValue;
1664 Standard_Integer ToSetSensitivity;
1665 Standard_Integer SelectionMode;
1666 Standard_Integer Sensitivity;
1668 Standard_Integer ToSetHatch;
1669 Standard_Integer StdHatchStyle;
1670 TCollection_AsciiString PathToHatchPattern;
1672 Standard_Integer ToSetShadingModel;
1673 Graphic3d_TypeOfShadingModel ShadingModel;
1674 TCollection_AsciiString ShadingModelName;
1676 //! Empty constructor
1677 ViewerTest_AspectsChangeSet()
1678 : ToSetVisibility (0),
1681 Color (DEFAULT_COLOR),
1684 ToSetTypeOfLine (0),
1685 TypeOfLine (Aspect_TOL_SOLID),
1686 ToSetTypeOfMarker (0),
1687 TypeOfMarker (Aspect_TOM_PLUS),
1688 ToSetMarkerSize (0),
1690 ToSetTransparency (0),
1693 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1696 Material (Graphic3d_NOM_DEFAULT),
1697 ToSetShowFreeBoundary (0),
1698 ToSetFreeBoundaryWidth (0),
1699 FreeBoundaryWidth (1.0),
1700 ToSetFreeBoundaryColor (0),
1701 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1702 ToEnableIsoOnTriangulation (-1),
1703 ToSetMaxParamValue (0),
1704 MaxParamValue (500000),
1705 ToSetSensitivity (0),
1710 ToSetShadingModel (0),
1711 ShadingModel (Graphic3d_TOSM_DEFAULT)
1714 //! @return true if no changes have been requested
1715 Standard_Boolean IsEmpty() const
1717 return ToSetVisibility == 0
1718 && ToSetLineWidth == 0
1719 && ToSetTransparency == 0
1720 && ToSetAlphaMode == 0
1722 && ToSetMaterial == 0
1723 && ToSetShowFreeBoundary == 0
1724 && ToSetFreeBoundaryColor == 0
1725 && ToSetFreeBoundaryWidth == 0
1726 && ToSetMaxParamValue == 0
1727 && ToSetSensitivity == 0
1729 && ToSetShadingModel == 0;
1732 //! @return true if properties are valid
1733 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1735 Standard_Boolean isOk = Standard_True;
1736 if (Visibility != 0 && Visibility != 1)
1738 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1739 isOk = Standard_False;
1741 if (LineWidth <= 0.0
1742 || LineWidth > 10.0)
1744 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1745 isOk = Standard_False;
1747 if (Transparency < 0.0
1748 || Transparency > 1.0)
1750 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1751 isOk = Standard_False;
1754 && ToSetTransparency != 0)
1756 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1757 isOk = Standard_False;
1759 if (ToSetAlphaMode == 1
1760 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1762 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1763 isOk = Standard_False;
1765 if (ToSetMaterial == 1
1766 && Material == Graphic3d_NOM_DEFAULT)
1768 std::cout << "Error: unknown material " << MatName << ".\n";
1769 isOk = Standard_False;
1771 if (FreeBoundaryWidth <= 0.0
1772 || FreeBoundaryWidth > 10.0)
1774 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1775 isOk = Standard_False;
1777 if (MaxParamValue < 0.0)
1779 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1780 isOk = Standard_False;
1782 if (Sensitivity <= 0 && ToSetSensitivity)
1784 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1785 isOk = Standard_False;
1787 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1789 std::cout << "Error: hatch style must be specified\n";
1790 isOk = Standard_False;
1792 if (ToSetShadingModel == 1
1793 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
1795 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1796 isOk = Standard_False;
1803 //==============================================================================
1804 //function : VAspects
1806 //==============================================================================
1807 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1808 Standard_Integer theArgNb,
1809 const char** theArgVec)
1811 TCollection_AsciiString aCmdName (theArgVec[0]);
1812 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1813 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1816 std::cerr << "Error: no active view!\n";
1820 Standard_Integer anArgIter = 1;
1821 Standard_Boolean isDefaults = Standard_False;
1822 NCollection_Sequence<TCollection_AsciiString> aNames;
1823 for (; anArgIter < theArgNb; ++anArgIter)
1825 TCollection_AsciiString anArg = theArgVec[anArgIter];
1826 if (anUpdateTool.parseRedrawMode (anArg))
1830 else if (!anArg.IsEmpty()
1831 && anArg.Value (1) != '-')
1833 aNames.Append (anArg);
1837 if (anArg == "-defaults")
1839 isDefaults = Standard_True;
1846 if (!aNames.IsEmpty() && isDefaults)
1848 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1852 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1853 aChanges.Append (ViewerTest_AspectsChangeSet());
1854 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1856 // parse syntax of legacy commands
1857 if (aCmdName == "vsetwidth")
1859 if (aNames.IsEmpty()
1860 || !aNames.Last().IsRealValue())
1862 std::cout << "Error: not enough arguments!\n";
1865 aChangeSet->ToSetLineWidth = 1;
1866 aChangeSet->LineWidth = aNames.Last().RealValue();
1867 aNames.Remove (aNames.Length());
1869 else if (aCmdName == "vunsetwidth")
1871 aChangeSet->ToSetLineWidth = -1;
1873 else if (aCmdName == "vsetcolor")
1875 if (aNames.IsEmpty())
1877 std::cout << "Error: not enough arguments!\n";
1880 aChangeSet->ToSetColor = 1;
1882 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1883 Standard_Boolean isOk = Standard_False;
1884 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1886 aChangeSet->Color = aColor;
1887 aNames.Remove (aNames.Length());
1888 isOk = Standard_True;
1890 else if (aNames.Length() >= 3)
1892 const TCollection_AsciiString anRgbStr[3] =
1894 aNames.Value (aNames.Upper() - 2),
1895 aNames.Value (aNames.Upper() - 1),
1896 aNames.Value (aNames.Upper() - 0)
1898 isOk = anRgbStr[0].IsRealValue()
1899 && anRgbStr[1].IsRealValue()
1900 && anRgbStr[2].IsRealValue();
1903 Graphic3d_Vec4d anRgb;
1904 anRgb.x() = anRgbStr[0].RealValue();
1905 anRgb.y() = anRgbStr[1].RealValue();
1906 anRgb.z() = anRgbStr[2].RealValue();
1907 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1908 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1909 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1911 std::cout << "Error: RGB color values should be within range 0..1!\n";
1914 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1915 aNames.Remove (aNames.Length());
1916 aNames.Remove (aNames.Length());
1917 aNames.Remove (aNames.Length());
1922 std::cout << "Error: not enough arguments!\n";
1926 else if (aCmdName == "vunsetcolor")
1928 aChangeSet->ToSetColor = -1;
1930 else if (aCmdName == "vsettransparency")
1932 if (aNames.IsEmpty()
1933 || !aNames.Last().IsRealValue())
1935 std::cout << "Error: not enough arguments!\n";
1938 aChangeSet->ToSetTransparency = 1;
1939 aChangeSet->Transparency = aNames.Last().RealValue();
1940 aNames.Remove (aNames.Length());
1942 else if (aCmdName == "vunsettransparency")
1944 aChangeSet->ToSetTransparency = -1;
1946 else if (aCmdName == "vsetmaterial")
1948 if (aNames.IsEmpty())
1950 std::cout << "Error: not enough arguments!\n";
1953 aChangeSet->ToSetMaterial = 1;
1954 aChangeSet->MatName = aNames.Last();
1955 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1956 aNames.Remove (aNames.Length());
1958 else if (aCmdName == "vunsetmaterial")
1960 aChangeSet->ToSetMaterial = -1;
1962 else if (anArgIter >= theArgNb)
1964 std::cout << "Error: not enough arguments!\n";
1968 if (!aChangeSet->IsEmpty())
1970 anArgIter = theArgNb;
1972 for (; anArgIter < theArgNb; ++anArgIter)
1974 TCollection_AsciiString anArg = theArgVec[anArgIter];
1976 if (anArg == "-setwidth"
1977 || anArg == "-setlinewidth")
1979 if (++anArgIter >= theArgNb)
1981 std::cout << "Error: wrong syntax at " << anArg << "\n";
1984 aChangeSet->ToSetLineWidth = 1;
1985 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1987 else if (anArg == "-unsetwidth"
1988 || anArg == "-unsetlinewidth")
1990 aChangeSet->ToSetLineWidth = -1;
1991 aChangeSet->LineWidth = 1.0;
1993 else if (anArg == "-settransp"
1994 || anArg == "-settransparency")
1996 if (++anArgIter >= theArgNb)
1998 std::cout << "Error: wrong syntax at " << anArg << "\n";
2001 aChangeSet->ToSetTransparency = 1;
2002 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2003 if (aChangeSet->Transparency >= 0.0
2004 && aChangeSet->Transparency <= Precision::Confusion())
2006 aChangeSet->ToSetTransparency = -1;
2007 aChangeSet->Transparency = 0.0;
2010 else if (anArg == "-setalphamode")
2012 if (++anArgIter >= theArgNb)
2014 std::cout << "Error: wrong syntax at " << anArg << "\n";
2017 aChangeSet->ToSetAlphaMode = 1;
2018 aChangeSet->AlphaCutoff = 0.5f;
2020 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2022 if (aParam == "opaque")
2024 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2026 else if (aParam == "mask")
2028 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2030 else if (aParam == "blend")
2032 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2034 else if (aParam == "blendauto"
2035 || aParam == "auto")
2037 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2041 std::cout << "Error: wrong syntax at " << aParam << "\n";
2046 if (anArgIter + 1 < theArgNb
2047 && theArgVec[anArgIter + 1][0] != '-')
2049 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2050 if (aParam2.IsRealValue())
2052 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2057 else if (anArg == "-setvis"
2058 || anArg == "-setvisibility")
2060 if (++anArgIter >= theArgNb)
2062 std::cout << "Error: wrong syntax at " << anArg << "\n";
2066 aChangeSet->ToSetVisibility = 1;
2067 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2069 else if (anArg == "-setalpha")
2071 if (++anArgIter >= theArgNb)
2073 std::cout << "Error: wrong syntax at " << anArg << "\n";
2076 aChangeSet->ToSetTransparency = 1;
2077 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2078 if (aChangeSet->Transparency < 0.0
2079 || aChangeSet->Transparency > 1.0)
2081 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2084 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2085 if (aChangeSet->Transparency >= 0.0
2086 && aChangeSet->Transparency <= Precision::Confusion())
2088 aChangeSet->ToSetTransparency = -1;
2089 aChangeSet->Transparency = 0.0;
2092 else if (anArg == "-unsettransp"
2093 || anArg == "-unsettransparency"
2094 || anArg == "-unsetalpha"
2095 || anArg == "-opaque")
2097 aChangeSet->ToSetTransparency = -1;
2098 aChangeSet->Transparency = 0.0;
2100 else if (anArg == "-setcolor")
2102 Standard_Integer aNbComps = 0;
2103 Standard_Integer aCompIter = anArgIter + 1;
2104 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2106 if (theArgVec[aCompIter][0] == '-')
2115 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2116 Standard_CString aName = theArgVec[anArgIter + 1];
2117 if (!Quantity_Color::ColorFromName (aName, aColor))
2119 std::cout << "Error: unknown color name '" << aName << "'\n";
2122 aChangeSet->Color = aColor;
2127 Graphic3d_Vec3d anRgb;
2128 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2129 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2130 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2131 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2132 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2133 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2135 std::cout << "Error: RGB color values should be within range 0..1!\n";
2138 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2143 std::cout << "Error: wrong syntax at " << anArg << "\n";
2147 aChangeSet->ToSetColor = 1;
2148 anArgIter += aNbComps;
2150 else if (anArg == "-setlinetype")
2152 if (++anArgIter >= theArgNb)
2154 std::cout << "Error: wrong syntax at " << anArg << "\n";
2157 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aChangeSet->TypeOfLine))
2159 std::cout << "Error: wrong syntax at " << anArg << "\n";
2163 aChangeSet->ToSetTypeOfLine = 1;
2165 else if (anArg == "-unsetlinetype")
2167 aChangeSet->ToSetTypeOfLine = -1;
2169 else if (anArg == "-setmarkertype"
2170 || anArg == "-setpointtype")
2172 if (++anArgIter >= theArgNb)
2174 std::cout << "Error: wrong syntax at " << anArg << "\n";
2177 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2179 std::cout << "Error: wrong syntax at " << anArg << "\n";
2183 aChangeSet->ToSetTypeOfMarker = 1;
2185 else if (anArg == "-unsetmarkertype"
2186 || anArg == "-unsetpointtype")
2188 aChangeSet->ToSetTypeOfMarker = -1;
2190 else if (anArg == "-setmarkersize"
2191 || anArg == "-setpointsize")
2193 if (++anArgIter >= theArgNb)
2195 std::cout << "Error: wrong syntax at " << anArg << "\n";
2198 aChangeSet->ToSetMarkerSize = 1;
2199 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2201 else if (anArg == "-unsetmarkersize"
2202 || anArg == "-unsetpointsize")
2204 aChangeSet->ToSetMarkerSize = -1;
2205 aChangeSet->MarkerSize = 1.0;
2207 else if (anArg == "-unsetcolor")
2209 aChangeSet->ToSetColor = -1;
2210 aChangeSet->Color = DEFAULT_COLOR;
2212 else if (anArg == "-setmat"
2213 || anArg == "-setmaterial")
2215 if (++anArgIter >= theArgNb)
2217 std::cout << "Error: wrong syntax at " << anArg << "\n";
2220 aChangeSet->ToSetMaterial = 1;
2221 aChangeSet->MatName = theArgVec[anArgIter];
2222 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2224 else if (anArg == "-unsetmat"
2225 || anArg == "-unsetmaterial")
2227 aChangeSet->ToSetMaterial = -1;
2228 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2230 else if (anArg == "-subshape"
2231 || anArg == "-subshapes")
2235 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2239 if (aNames.IsEmpty())
2241 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2245 aChanges.Append (ViewerTest_AspectsChangeSet());
2246 aChangeSet = &aChanges.ChangeLast();
2248 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2250 Standard_CString aSubShapeName = theArgVec[anArgIter];
2251 if (*aSubShapeName == '-')
2257 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2258 if (aSubShape.IsNull())
2260 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2263 aChangeSet->SubShapes.Append (aSubShape);
2266 if (aChangeSet->SubShapes.IsEmpty())
2268 std::cerr << "Error: empty list is specified after -subshapes!\n";
2272 else if (anArg == "-freeboundary"
2275 if (++anArgIter >= theArgNb)
2277 std::cout << "Error: wrong syntax at " << anArg << "\n";
2280 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2285 aChangeSet->ToSetShowFreeBoundary = 1;
2287 else if (aValue == "off"
2290 aChangeSet->ToSetShowFreeBoundary = -1;
2294 std::cout << "Error: wrong syntax at " << anArg << "\n";
2298 else if (anArg == "-setfreeboundarywidth"
2299 || anArg == "-setfbwidth")
2301 if (++anArgIter >= theArgNb)
2303 std::cout << "Error: wrong syntax at " << anArg << "\n";
2306 aChangeSet->ToSetFreeBoundaryWidth = 1;
2307 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2309 else if (anArg == "-unsetfreeboundarywidth"
2310 || anArg == "-unsetfbwidth")
2312 aChangeSet->ToSetFreeBoundaryWidth = -1;
2313 aChangeSet->FreeBoundaryWidth = 1.0;
2315 else if (anArg == "-setfreeboundarycolor"
2316 || anArg == "-setfbcolor")
2318 Standard_Integer aNbComps = 0;
2319 Standard_Integer aCompIter = anArgIter + 1;
2320 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2322 if (theArgVec[aCompIter][0] == '-')
2331 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2332 Standard_CString aName = theArgVec[anArgIter + 1];
2333 if (!Quantity_Color::ColorFromName (aName, aColor))
2335 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2338 aChangeSet->FreeBoundaryColor = aColor;
2343 Graphic3d_Vec3d anRgb;
2344 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2345 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2346 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2347 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2348 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2349 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2351 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2354 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2359 std::cout << "Error: wrong syntax at " << anArg << "\n";
2363 aChangeSet->ToSetFreeBoundaryColor = 1;
2364 anArgIter += aNbComps;
2366 else if (anArg == "-unsetfreeboundarycolor"
2367 || anArg == "-unsetfbcolor")
2369 aChangeSet->ToSetFreeBoundaryColor = -1;
2370 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2372 else if (anArg == "-unset")
2374 aChangeSet->ToSetVisibility = 1;
2375 aChangeSet->Visibility = 1;
2376 aChangeSet->ToSetLineWidth = -1;
2377 aChangeSet->LineWidth = 1.0;
2378 aChangeSet->ToSetTypeOfLine = -1;
2379 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2380 aChangeSet->ToSetTypeOfMarker = -1;
2381 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
2382 aChangeSet->ToSetMarkerSize = -1;
2383 aChangeSet->MarkerSize = 1.0;
2384 aChangeSet->ToSetTransparency = -1;
2385 aChangeSet->Transparency = 0.0;
2386 aChangeSet->ToSetAlphaMode = -1;
2387 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2388 aChangeSet->AlphaCutoff = 0.5f;
2389 aChangeSet->ToSetColor = -1;
2390 aChangeSet->Color = DEFAULT_COLOR;
2391 aChangeSet->ToSetMaterial = -1;
2392 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2393 aChangeSet->ToSetShowFreeBoundary = -1;
2394 aChangeSet->ToSetFreeBoundaryColor = -1;
2395 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2396 aChangeSet->ToSetFreeBoundaryWidth = -1;
2397 aChangeSet->FreeBoundaryWidth = 1.0;
2398 aChangeSet->ToSetHatch = -1;
2399 aChangeSet->StdHatchStyle = -1;
2400 aChangeSet->PathToHatchPattern.Clear();
2401 aChangeSet->ToSetShadingModel = -1;
2402 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2404 else if (anArg == "-isoontriangulation"
2405 || anArg == "-isoontriang")
2407 if (++anArgIter >= theArgNb)
2409 std::cout << "Error: wrong syntax at " << anArg << "\n";
2412 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2417 aChangeSet->ToEnableIsoOnTriangulation = 1;
2419 else if (aValue == "off"
2422 aChangeSet->ToEnableIsoOnTriangulation = 0;
2426 std::cout << "Error: wrong syntax at " << anArg << "\n";
2430 else if (anArg == "-setmaxparamvalue")
2432 if (++anArgIter >= theArgNb)
2434 std::cout << "Error: wrong syntax at " << anArg << "\n";
2437 aChangeSet->ToSetMaxParamValue = 1;
2438 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2440 else if (anArg == "-setsensitivity")
2444 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2448 if (aNames.IsEmpty())
2450 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2454 if (anArgIter + 2 >= theArgNb)
2456 std::cout << "Error: wrong syntax at " << anArg << "\n";
2459 aChangeSet->ToSetSensitivity = 1;
2460 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2461 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2463 else if (anArg == "-sethatch")
2467 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2471 if (aNames.IsEmpty())
2473 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2477 aChangeSet->ToSetHatch = 1;
2478 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
2479 if (anArgHatch.Length() <= 2)
2481 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
2483 || anIntStyle >= Aspect_HS_NB)
2485 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
2488 aChangeSet->StdHatchStyle = anIntStyle;
2492 aChangeSet->PathToHatchPattern = anArgHatch;
2495 else if (anArg == "-setshadingmodel")
2497 if (++anArgIter >= theArgNb)
2499 std::cout << "Error: wrong syntax at " << anArg << "\n";
2502 aChangeSet->ToSetShadingModel = 1;
2503 aChangeSet->ShadingModelName = theArgVec[anArgIter];
2504 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
2506 std::cout << "Error: wrong syntax at " << anArg << "\n";
2510 else if (anArg == "-unsetshadingmodel")
2512 aChangeSet->ToSetShadingModel = -1;
2513 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2517 std::cout << "Error: wrong syntax at " << anArg << "\n";
2522 Standard_Boolean isFirst = Standard_True;
2523 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2524 aChangesIter.More(); aChangesIter.Next())
2526 if (!aChangesIter.Value().Validate (!isFirst))
2530 isFirst = Standard_False;
2533 // special case for -defaults parameter.
2534 // all changed values will be set to DefaultDrawer.
2537 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2539 if (aChangeSet->ToSetLineWidth != 0)
2541 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2542 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2543 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2544 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2546 if (aChangeSet->ToSetColor != 0)
2548 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2549 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2550 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2551 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2552 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2553 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2555 if (aChangeSet->ToSetTypeOfLine != 0)
2557 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2558 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2559 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2560 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2561 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2563 if (aChangeSet->ToSetTypeOfMarker != 0)
2565 aDrawer->PointAspect()->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2566 aDrawer->PointAspect()->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2567 ? Handle(Graphic3d_MarkerImage)()
2568 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2570 if (aChangeSet->ToSetMarkerSize != 0)
2572 aDrawer->PointAspect()->SetScale (aChangeSet->MarkerSize);
2574 if (aChangeSet->ToSetTransparency != 0)
2576 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2578 if (aChangeSet->ToSetAlphaMode != 0)
2580 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2582 if (aChangeSet->ToSetMaterial != 0)
2584 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2586 if (aChangeSet->ToSetShowFreeBoundary == 1)
2588 aDrawer->SetFreeBoundaryDraw (Standard_True);
2590 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2592 aDrawer->SetFreeBoundaryDraw (Standard_False);
2594 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2596 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2598 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2600 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2602 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2604 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2606 if (aChangeSet->ToSetMaxParamValue != 0)
2608 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2610 if (aChangeSet->ToSetShadingModel == 1)
2612 aDrawer->ShadingAspect()->Aspect()->SetShadingModel (aChangeSet->ShadingModel);
2615 // redisplay all objects in context
2616 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2618 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2621 aCtx->Redisplay (aPrs, Standard_False);
2627 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2629 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2630 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2631 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2632 Handle(AIS_ColoredShape) aColoredPrs;
2633 Standard_Boolean toDisplay = Standard_False;
2634 Standard_Boolean toRedisplay = Standard_False;
2635 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2637 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2638 if (aShapePrs.IsNull())
2640 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2643 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2644 if (aColoredPrs.IsNull())
2646 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2647 if (aShapePrs->HasDisplayMode())
2649 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2651 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2652 aCtx->Remove (aShapePrs, Standard_False);
2653 GetMapOfAIS().UnBind2 (aName);
2654 GetMapOfAIS().Bind (aColoredPrs, aName);
2655 toDisplay = Standard_True;
2656 aShapePrs = aColoredPrs;
2663 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2664 aChangeSet = &aChangesIter.ChangeValue();
2665 if (aChangeSet->ToSetVisibility == 1)
2667 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2668 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2670 else if (aChangeSet->ToSetMaterial == 1)
2672 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2674 else if (aChangeSet->ToSetMaterial == -1)
2676 aCtx->UnsetMaterial (aPrs, Standard_False);
2678 if (aChangeSet->ToSetColor == 1)
2680 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2682 else if (aChangeSet->ToSetColor == -1)
2684 aCtx->UnsetColor (aPrs, Standard_False);
2686 if (aChangeSet->ToSetTransparency == 1)
2688 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2690 else if (aChangeSet->ToSetTransparency == -1)
2692 aCtx->UnsetTransparency (aPrs, Standard_False);
2694 if (aChangeSet->ToSetLineWidth == 1)
2696 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2698 else if (aChangeSet->ToSetLineWidth == -1)
2700 aCtx->UnsetWidth (aPrs, Standard_False);
2702 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2704 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2705 toRedisplay = Standard_True;
2707 else if (aChangeSet->ToSetSensitivity != 0)
2709 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2711 if (!aDrawer.IsNull())
2713 if (aChangeSet->ToSetShowFreeBoundary == 1)
2715 aDrawer->SetFreeBoundaryDraw (Standard_True);
2716 toRedisplay = Standard_True;
2718 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2720 aDrawer->SetFreeBoundaryDraw (Standard_False);
2721 toRedisplay = Standard_True;
2723 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2725 Handle(Prs3d_LineAspect) aBoundaryAspect =
2726 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2727 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2728 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2729 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2730 toRedisplay = Standard_True;
2732 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2734 Handle(Prs3d_LineAspect) aBoundaryAspect =
2735 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2736 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2737 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2738 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2739 toRedisplay = Standard_True;
2741 if (aChangeSet->ToSetTypeOfLine != 0)
2743 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2744 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2745 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2746 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2747 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2748 toRedisplay = Standard_True;
2750 if (aChangeSet->ToSetTypeOfMarker != 0)
2752 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2753 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2754 aMarkerAspect->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2755 aMarkerAspect->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2756 ? Handle(Graphic3d_MarkerImage)()
2757 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2758 aDrawer->SetPointAspect (aMarkerAspect);
2759 toRedisplay = Standard_True;
2761 if (aChangeSet->ToSetMarkerSize != 0)
2763 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2764 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2765 aMarkerAspect->SetScale (aChangeSet->MarkerSize);
2766 aDrawer->SetPointAspect (aMarkerAspect);
2767 toRedisplay = Standard_True;
2769 if (aChangeSet->ToSetMaxParamValue != 0)
2771 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2773 if (aChangeSet->ToSetHatch != 0)
2775 if (!aDrawer->HasOwnShadingAspect())
2777 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2778 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2781 Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
2782 if (aChangeSet->ToSetHatch == -1)
2784 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2788 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2789 if (!aChangeSet->PathToHatchPattern.IsEmpty())
2791 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2792 if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
2794 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2798 std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
2802 else if (aChangeSet->StdHatchStyle != -1)
2804 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
2807 toRedisplay = Standard_True;
2809 if (aChangeSet->ToSetShadingModel != 0)
2811 aDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2812 toRedisplay = Standard_True;
2814 if (aChangeSet->ToSetAlphaMode != 0)
2816 if (!aDrawer->HasOwnShadingAspect())
2818 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2819 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2821 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2822 toRedisplay = Standard_True;
2826 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2828 aChangeSet = &aChangesIter.ChangeValue();
2829 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2830 aSubShapeIter.More(); aSubShapeIter.Next())
2832 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2833 if (aChangeSet->ToSetVisibility == 1)
2835 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2836 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2838 if (aChangeSet->ToSetColor == 1)
2840 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2842 if (aChangeSet->ToSetLineWidth == 1)
2844 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2846 if (aChangeSet->ToSetColor == -1
2847 || aChangeSet->ToSetLineWidth == -1)
2849 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2851 if (aChangeSet->ToSetMaxParamValue != 0)
2853 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2854 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2856 if (aChangeSet->ToSetSensitivity != 0)
2858 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2860 if (aChangeSet->ToSetShadingModel != 0)
2862 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2863 aCurColDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2869 aCtx->Display (aPrs, Standard_False);
2873 aCtx->Redisplay (aPrs, Standard_False);
2875 else if (!aColoredPrs.IsNull())
2877 aCtx->Redisplay (aColoredPrs, Standard_False);
2884 //==============================================================================
2885 //function : VDonly2
2887 //purpose : Display only a selected or named object
2888 // if there is no selected or named object s, nothing is done
2889 //==============================================================================
2890 static int VDonly2 (Draw_Interpretor& ,
2891 Standard_Integer theArgNb,
2892 const char** theArgVec)
2894 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2895 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2898 std::cerr << "Error: no active view!\n";
2902 Standard_DISABLE_DEPRECATION_WARNINGS
2903 if (aCtx->HasOpenedContext())
2905 aCtx->CloseLocalContext();
2907 Standard_ENABLE_DEPRECATION_WARNINGS
2909 Standard_Integer anArgIter = 1;
2910 for (; anArgIter < theArgNb; ++anArgIter)
2912 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2918 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2919 if (anArgIter >= theArgNb)
2921 // display only selected objects
2922 if (aCtx->NbSelected() < 1)
2927 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2929 aDispSet.Add (aCtx->SelectedInteractive());
2934 // display only specified objects
2935 for (; anArgIter < theArgNb; ++anArgIter)
2937 TCollection_AsciiString aName = theArgVec[anArgIter];
2938 if (GetMapOfAIS().IsBound2 (aName))
2940 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2941 if (!aShape.IsNull())
2943 aCtx->Display (aShape, Standard_False);
2944 aDispSet.Add (aShape);
2950 // weed out other objects
2951 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2953 if (aDispSet.Contains (anIter.Key1()))
2958 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2959 if (aShape.IsNull())
2961 aCtx->Erase (aShape, Standard_False);
2967 //==============================================================================
2968 //function : VRemove
2969 //purpose : Removes selected or named objects.
2970 // If there is no selected or named objects,
2971 // all objects in the viewer can be removed with argument -all.
2972 // If -context is in arguments, the object is not deleted from the map of
2973 // objects (deleted only from the current context).
2974 //==============================================================================
2975 int VRemove (Draw_Interpretor& theDI,
2976 Standard_Integer theArgNb,
2977 const char** theArgVec)
2979 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2980 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2983 std::cerr << "Error: no active view!\n";
2987 Standard_Boolean isContextOnly = Standard_False;
2988 Standard_Boolean toRemoveAll = Standard_False;
2989 Standard_Boolean toPrintInfo = Standard_True;
2990 Standard_Boolean toRemoveLocal = Standard_False;
2992 Standard_Integer anArgIter = 1;
2993 for (; anArgIter < theArgNb; ++anArgIter)
2995 TCollection_AsciiString anArg = theArgVec[anArgIter];
2997 if (anArg == "-context")
2999 isContextOnly = Standard_True;
3001 else if (anArg == "-all")
3003 toRemoveAll = Standard_True;
3005 else if (anArg == "-noinfo")
3007 toPrintInfo = Standard_False;
3009 else if (anArg == "-local")
3011 toRemoveLocal = Standard_True;
3013 else if (anUpdateTool.parseRedrawMode (anArg))
3023 && anArgIter < theArgNb)
3025 std::cerr << "Error: wrong syntax!\n";
3029 Standard_DISABLE_DEPRECATION_WARNINGS
3030 if (toRemoveLocal && !aCtx->HasOpenedContext())
3032 std::cerr << "Error: local selection context is not open.\n";
3035 else if (!toRemoveLocal && aCtx->HasOpenedContext())
3037 aCtx->CloseAllContexts (Standard_False);
3039 Standard_ENABLE_DEPRECATION_WARNINGS
3041 NCollection_List<TCollection_AsciiString> anIONameList;
3044 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3045 anIter.More(); anIter.Next())
3047 anIONameList.Append (anIter.Key2());
3050 else if (anArgIter < theArgNb) // removed objects names are in argument list
3052 for (; anArgIter < theArgNb; ++anArgIter)
3054 TCollection_AsciiString aName = theArgVec[anArgIter];
3055 if (!GetMapOfAIS().IsBound2 (aName))
3057 theDI << aName.ToCString() << " was not bound to some object.\n";
3061 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3062 if (anIO->GetContext() != aCtx)
3064 theDI << aName.ToCString() << " was not displayed in current context.\n";
3065 theDI << "Please activate view with this object displayed and try again.\n";
3069 anIONameList.Append (aName);
3073 else if (aCtx->NbSelected() > 0)
3075 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3076 anIter.More(); anIter.Next())
3078 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3079 if (!aCtx->IsSelected (anIO))
3084 anIONameList.Append (anIter.Key2());
3089 // Unbind all removed objects from the map of displayed IO.
3090 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3091 anIter.More(); anIter.Next())
3093 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
3094 aCtx->Remove (anIO, Standard_False);
3097 theDI << anIter.Value().ToCString() << " was removed\n";
3101 GetMapOfAIS().UnBind2 (anIter.Value());
3105 // Close local context if it is empty
3106 TColStd_MapOfTransient aLocalIO;
3107 Standard_DISABLE_DEPRECATION_WARNINGS
3108 if (aCtx->HasOpenedContext()
3109 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
3111 aCtx->CloseAllContexts (Standard_False);
3113 Standard_ENABLE_DEPRECATION_WARNINGS
3118 //==============================================================================
3120 //purpose : Erase some selected or named objects
3121 // if there is no selected or named objects, the whole viewer is erased
3122 //==============================================================================
3123 int VErase (Draw_Interpretor& theDI,
3124 Standard_Integer theArgNb,
3125 const char** theArgVec)
3127 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3128 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3129 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3132 std::cerr << "Error: no active view!\n";
3136 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3138 Standard_Integer anArgIter = 1;
3139 Standard_Boolean toEraseLocal = Standard_False;
3140 Standard_Boolean toEraseInView = Standard_False;
3141 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3142 for (; anArgIter < theArgNb; ++anArgIter)
3144 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3145 anArgCase.LowerCase();
3146 if (anUpdateTool.parseRedrawMode (anArgCase))
3150 else if (anArgCase == "-local")
3152 toEraseLocal = Standard_True;
3154 else if (anArgCase == "-view"
3155 || anArgCase == "-inview")
3157 toEraseInView = Standard_True;
3161 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3165 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3167 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3171 Standard_DISABLE_DEPRECATION_WARNINGS
3172 if (toEraseLocal && !aCtx->HasOpenedContext())
3174 std::cerr << "Error: local selection context is not open.\n";
3177 else if (!toEraseLocal && aCtx->HasOpenedContext())
3179 aCtx->CloseAllContexts (Standard_False);
3181 Standard_ENABLE_DEPRECATION_WARNINGS
3183 if (!aNamesOfEraseIO.IsEmpty())
3185 // Erase named objects
3186 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
3188 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
3189 if (!GetMapOfAIS().IsBound2 (aName))
3194 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
3195 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
3196 theDI << aName.ToCString() << " ";
3201 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3205 aCtx->Erase (anIO, Standard_False);
3210 else if (!toEraseAll && aCtx->NbSelected() > 0)
3212 // Erase selected objects
3213 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
3214 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3215 anIter.More(); anIter.Next())
3217 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3219 && aCtx->IsSelected (anIO))
3221 theDI << anIter.Key2().ToCString() << " ";
3224 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3226 else if (aHasOpenedContext)
3228 aCtx->Erase (anIO, Standard_False);
3235 aCtx->EraseSelected (Standard_False);
3240 // Erase all objects
3241 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3242 anIter.More(); anIter.Next())
3244 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3249 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3253 aCtx->Erase (anIO, Standard_False);
3262 //==============================================================================
3263 //function : VDisplayAll
3264 //purpose : Display all the objects of the Map
3265 //==============================================================================
3266 static int VDisplayAll (Draw_Interpretor& ,
3267 Standard_Integer theArgNb,
3268 const char** theArgVec)
3271 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3272 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3275 std::cerr << "Error: no active view!\n";
3279 Standard_Integer anArgIter = 1;
3280 Standard_Boolean toDisplayLocal = Standard_False;
3281 for (; anArgIter < theArgNb; ++anArgIter)
3283 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3284 anArgCase.LowerCase();
3285 if (anArgCase == "-local")
3287 toDisplayLocal = Standard_True;
3289 else if (anUpdateTool.parseRedrawMode (anArgCase))
3298 if (anArgIter < theArgNb)
3300 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3304 Standard_DISABLE_DEPRECATION_WARNINGS
3305 if (toDisplayLocal && !aCtx->HasOpenedContext())
3307 std::cerr << "Error: local selection context is not open.\n";
3310 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3312 aCtx->CloseLocalContext (Standard_False);
3314 Standard_ENABLE_DEPRECATION_WARNINGS
3316 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3317 anIter.More(); anIter.Next())
3319 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3320 aCtx->Erase (aShape, Standard_False);
3323 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3324 anIter.More(); anIter.Next())
3326 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3327 aCtx->Display (aShape, Standard_False);
3332 //! Auxiliary method to check if presentation exists
3333 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3334 const Handle(AIS_InteractiveObject)& theIO,
3335 const Standard_Integer theMode)
3337 if (theIO.IsNull() || theCtx.IsNull())
3344 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3349 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3351 return theIO->DisplayMode();
3353 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3355 return theCtx->DisplayMode();
3361 enum ViewerTest_BndAction
3368 //! Auxiliary method to print bounding box of presentation
3369 inline void bndPresentation (Draw_Interpretor& theDI,
3370 const Handle(PrsMgr_PresentationManager)& theMgr,
3371 const Handle(AIS_InteractiveObject)& theObj,
3372 const Standard_Integer theDispMode,
3373 const TCollection_AsciiString& theName,
3374 const ViewerTest_BndAction theAction,
3375 const Handle(Prs3d_Drawer)& theStyle)
3379 case BndAction_Hide:
3381 theMgr->Unhighlight (theObj);
3384 case BndAction_Show:
3386 theMgr->Color (theObj, theStyle, theDispMode);
3389 case BndAction_Print:
3392 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3394 if (aPrsIter.Value().Mode() != theDispMode)
3397 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3399 gp_Pnt aMin = aBox.CornerMin();
3400 gp_Pnt aMax = aBox.CornerMax();
3401 theDI << theName << "\n"
3402 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3403 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
3409 //==============================================================================
3410 //function : VBounding
3412 //==============================================================================
3413 int VBounding (Draw_Interpretor& theDI,
3414 Standard_Integer theArgNb,
3415 const char** theArgVec)
3417 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3418 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3421 std::cout << "Error: no active view!\n";
3425 ViewerTest_BndAction anAction = BndAction_Show;
3426 Standard_Integer aMode = -1;
3428 Handle(Prs3d_Drawer) aStyle;
3430 Standard_Integer anArgIter = 1;
3431 for (; anArgIter < theArgNb; ++anArgIter)
3433 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3435 if (anArg == "-print")
3437 anAction = BndAction_Print;
3439 else if (anArg == "-show")
3441 anAction = BndAction_Show;
3443 else if (anArg == "-hide")
3445 anAction = BndAction_Hide;
3447 else if (anArg == "-mode")
3449 if (++anArgIter >= theArgNb)
3451 std::cout << "Error: wrong syntax at " << anArg << "\n";
3454 aMode = Draw::Atoi (theArgVec[anArgIter]);
3456 else if (!anUpdateTool.parseRedrawMode (anArg))
3462 if (anAction == BndAction_Show)
3464 aStyle = new Prs3d_Drawer();
3465 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3466 aStyle->SetColor (Quantity_NOC_GRAY99);
3469 Standard_Integer aHighlightedMode = -1;
3470 if (anArgIter < theArgNb)
3472 // has a list of names
3473 for (; anArgIter < theArgNb; ++anArgIter)
3475 TCollection_AsciiString aName = theArgVec[anArgIter];
3476 if (!GetMapOfAIS().IsBound2 (aName))
3478 std::cout << "Error: presentation " << aName << " does not exist\n";
3482 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3483 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3484 if (aHighlightedMode == -1)
3486 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3489 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3492 else if (aCtx->NbSelected() > 0)
3494 // remove all currently selected objects
3495 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3497 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3498 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3499 if (aHighlightedMode != -1)
3501 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3502 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3509 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3510 anIter.More(); anIter.Next())
3512 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3513 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3514 if (aHighlightedMode != -1)
3516 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3523 //==============================================================================
3524 //function : VTexture
3526 //==============================================================================
3527 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
3529 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3532 std::cout << "Error: no active view!\n";
3536 int toModulate = -1;
3537 bool toSetFilter = false;
3538 bool toSetAniso = false;
3539 bool toSetTrsfAngle = false;
3540 bool toSetTrsfTrans = false;
3541 bool toSetTrsfScale = false;
3542 Standard_ShortReal aTrsfRotAngle = 0.0f;
3543 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
3544 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
3545 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
3546 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
3548 Handle(AIS_Shape) aTexturedIO;
3549 Handle(Graphic3d_TextureSet) aTextureSetOld;
3550 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
3551 bool toSetGenRepeat = false;
3552 bool toSetGenScale = false;
3553 bool toSetGenOrigin = false;
3554 bool toSetImage = false;
3555 bool toComputeUV = false;
3557 const TCollection_AsciiString aCommandName (theArgVec[0]);
3558 bool toSetDefaults = aCommandName == "vtexdefault";
3560 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3561 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
3563 const TCollection_AsciiString aName = theArgVec[anArgIter];
3564 TCollection_AsciiString aNameCase = aName;
3565 aNameCase.LowerCase();
3566 if (anUpdateTool.parseRedrawMode (aName))
3570 else if (aTexturedIO.IsNull())
3572 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3573 if (aMapOfIO.IsBound2 (aName))
3575 aTexturedIO = Handle(AIS_Shape)::DownCast (aMapOfIO.Find2 (aName));
3577 if (aTexturedIO.IsNull())
3579 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
3583 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
3585 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
3588 else if (aNameCase == "-scale"
3589 || aNameCase == "-setscale"
3590 || aCommandName == "vtexscale")
3592 if (aCommandName != "vtexscale")
3596 if (anArgIter < theArgsNb)
3598 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3599 TCollection_AsciiString aValUCase = aValU;
3600 aValUCase.LowerCase();
3601 toSetGenScale = true;
3602 if (aValUCase == "off")
3604 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3607 else if (anArgIter + 1 < theArgsNb)
3609 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3610 if (aValU.IsRealValue()
3611 && aValV.IsRealValue())
3613 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3619 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3622 else if (aNameCase == "-origin"
3623 || aNameCase == "-setorigin"
3624 || aCommandName == "vtexorigin")
3626 if (aCommandName != "vtexorigin")
3630 if (anArgIter < theArgsNb)
3632 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3633 TCollection_AsciiString aValUCase = aValU;
3634 aValUCase.LowerCase();
3635 toSetGenOrigin = true;
3636 if (aValUCase == "off")
3638 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));