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));
3641 else if (anArgIter + 1 < theArgsNb)
3643 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3644 if (aValU.IsRealValue()
3645 && aValV.IsRealValue())
3647 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3653 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3656 else if (aNameCase == "-repeat"
3657 || aNameCase == "-setrepeat"
3658 || aCommandName == "vtexrepeat")
3660 if (aCommandName != "vtexrepeat")
3664 if (anArgIter < theArgsNb)
3666 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3667 TCollection_AsciiString aValUCase = aValU;
3668 aValUCase.LowerCase();
3669 toSetGenRepeat = true;
3670 if (aValUCase == "off")
3672 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3675 else if (anArgIter + 1 < theArgsNb)
3677 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3678 if (aValU.IsRealValue()
3679 && aValV.IsRealValue())
3681 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3687 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3690 else if (aNameCase == "-modulate")
3692 bool toModulateBool = true;
3693 if (anArgIter + 1 < theArgsNb
3694 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
3698 toModulate = toModulateBool ? 1 : 0;
3700 else if ((aNameCase == "-setfilter"
3701 || aNameCase == "-filter")
3702 && anArgIter + 1 < theArgsNb)
3704 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3708 if (aValue == "nearest")
3710 aFilter = Graphic3d_TOTF_NEAREST;
3712 else if (aValue == "bilinear")
3714 aFilter = Graphic3d_TOTF_BILINEAR;
3716 else if (aValue == "trilinear")
3718 aFilter = Graphic3d_TOTF_TRILINEAR;
3722 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3726 else if ((aNameCase == "-setaniso"
3727 || aNameCase == "-setanisofilter"
3728 || aNameCase == "-aniso"
3729 || aNameCase == "-anisofilter")
3730 && anArgIter + 1 < theArgsNb)
3732 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3736 if (aValue == "off")
3738 anAnisoFilter = Graphic3d_LOTA_OFF;
3740 else if (aValue == "fast")
3742 anAnisoFilter = Graphic3d_LOTA_FAST;
3744 else if (aValue == "middle")
3746 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
3748 else if (aValue == "quality"
3749 || aValue == "high")
3751 anAnisoFilter = Graphic3d_LOTA_QUALITY;
3755 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3759 else if ((aNameCase == "-rotateangle"
3760 || aNameCase == "-rotangle"
3761 || aNameCase == "-rotate"
3762 || aNameCase == "-angle"
3763 || aNameCase == "-trsfangle")
3764 && anArgIter + 1 < theArgsNb)
3766 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3767 toSetTrsfAngle = true;
3770 else if ((aNameCase == "-trsftrans"
3771 || aNameCase == "-trsftranslate"
3772 || aNameCase == "-translate"
3773 || aNameCase == "-translation")
3774 && anArgIter + 2 < theArgsNb)
3776 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3777 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3778 toSetTrsfTrans = true;
3781 else if ((aNameCase == "-trsfscale")
3782 && anArgIter + 2 < theArgsNb)
3784 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3785 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3786 toSetTrsfScale = true;
3789 else if (aNameCase == "-default"
3790 || aNameCase == "-defaults")
3792 toSetDefaults = true;
3794 else if (aCommandName == "vtexture"
3795 && (aTextureVecNew.IsEmpty()
3796 || aNameCase.StartsWith ("-tex")))
3798 Standard_Integer aTexIndex = 0;
3799 TCollection_AsciiString aTexName = aName;
3800 if (aNameCase.StartsWith ("-tex"))
3802 if (anArgIter + 1 >= theArgsNb
3803 || aNameCase.Length() < 5)
3805 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3809 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
3810 if (!aTexIndexStr.IsIntegerValue())
3812 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3816 aTexIndex = aTexIndexStr.IntegerValue();
3817 aTexName = theArgVec[anArgIter + 1];
3820 if (aTexIndex >= Graphic3d_TextureUnit_NB
3821 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
3823 std::cout << "Error: too many textures specified\n";
3828 if (aTexName.IsIntegerValue())
3830 const Standard_Integer aValue = aTexName.IntegerValue();
3831 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
3833 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
3836 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
3838 else if (aTexName == "?")
3840 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3842 theDi << "\n Files in current directory : \n\n";
3843 theDi.Eval ("glob -nocomplain *");
3845 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3846 aCmnd += aTextureFolder;
3849 theDi << "Files in " << aTextureFolder << " : \n\n";
3850 theDi.Eval (aCmnd.ToCString());
3853 else if (aTexName != "off")
3855 if (!OSD_File (aTexName).Exists())
3857 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
3860 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
3864 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
3867 if (aTextureVecNew.Value (aTexIndex))
3869 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
3874 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3881 // check if new image set is equal to already set one
3882 Standard_Integer aNbChanged = 0;
3883 Handle(Graphic3d_TextureSet) aTextureSetNew;
3884 if (!aTextureVecNew.IsEmpty())
3886 aNbChanged = aTextureVecNew.Size();
3887 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
3888 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
3890 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
3891 Handle(Graphic3d_TextureRoot) aTextureOld;
3892 if (!aTextureSetOld.IsNull()
3893 && aTexIter < aTextureSetOld->Size())
3895 aTextureOld = aTextureSetOld->Value (aTexIter);
3898 if (!aTextureOld.IsNull()
3899 && !aTextureNew.IsNull())
3901 *aTextureNew->GetParams() = *aTextureOld->GetParams();
3902 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
3904 TCollection_AsciiString aFilePathOld, aFilePathNew;
3905 aTextureOld->Path().SystemName (aFilePathOld);
3906 aTextureNew->Path().SystemName (aFilePathNew);
3907 if (aTextureNew->Name() == anOldManualTex->Name()
3908 && aFilePathOld == aFilePathNew
3909 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
3912 aTextureNew = anOldManualTex;
3916 aTextureSetNew->SetValue (aTexIter, aTextureNew);
3920 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
3921 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
3923 aTextureSetNew = aTextureSetOld;
3926 if (!aTexturedIO->Attributes()->HasOwnShadingAspect())
3928 aTexturedIO->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
3929 *aTexturedIO->Attributes()->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
3932 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
3933 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
3934 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
3935 aTextureSetOld.Nullify();
3940 if (toModulate != -1)
3947 aFilter = Graphic3d_TOTF_BILINEAR;
3952 anAnisoFilter = Graphic3d_LOTA_OFF;
3954 if (!toSetTrsfAngle)
3956 toSetTrsfAngle = true;
3957 aTrsfRotAngle = 0.0f;
3959 if (!toSetTrsfTrans)
3961 toSetTrsfTrans = true;
3962 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
3964 if (!toSetTrsfScale)
3966 toSetTrsfScale = true;
3967 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
3971 if (aCommandName == "vtexture"
3974 if (!aTextureSetOld.IsNull())
3976 //toComputeUV = true; // we can keep UV vertex attributes
3977 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
3978 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
3979 aTextureSetOld.Nullify();
3983 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
3984 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
3986 if (toModulate != -1)
3988 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
3992 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
3996 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
4000 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
4004 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
4008 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
4012 // set default values if requested
4014 && (aCommandName == "vtexrepeat"
4017 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4018 toSetGenRepeat = true;
4021 && (aCommandName == "vtexorigin"
4024 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4025 toSetGenOrigin = true;
4028 && (aCommandName == "vtexscale"
4031 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4032 toSetGenScale = true;
4035 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
4037 aTexturedIO->SetToUpdate (AIS_Shaded);
4040 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
4041 || aCtx->DisplayMode() != AIS_Shaded)
4043 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
4047 aCtx->Display (aTexturedIO, false);
4048 aTexturedIO->SynchronizeAspects();
4052 //! Auxiliary method to parse transformation persistence flags
4053 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
4054 Graphic3d_TransModeFlags& theFlags)
4056 if (theFlagString == "zoom")
4058 theFlags = Graphic3d_TMF_ZoomPers;
4060 else if (theFlagString == "rotate")
4062 theFlags = Graphic3d_TMF_RotatePers;
4064 else if (theFlagString == "zoomrotate")
4066 theFlags = Graphic3d_TMF_ZoomRotatePers;
4068 else if (theFlagString == "trihedron"
4069 || theFlagString == "triedron")
4071 theFlags = Graphic3d_TMF_TriedronPers;
4073 else if (theFlagString == "none")
4075 theFlags = Graphic3d_TMF_None;
4079 return Standard_False;
4082 return Standard_True;
4085 //! Auxiliary method to parse transformation persistence flags
4086 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4087 Aspect_TypeOfTriedronPosition& theCorner)
4089 TCollection_AsciiString aString (theString);
4090 aString.LowerCase();
4091 if (aString == "center")
4093 theCorner = Aspect_TOTP_CENTER;
4095 else if (aString == "top"
4096 || aString == "upper")
4098 theCorner = Aspect_TOTP_TOP;
4100 else if (aString == "bottom"
4101 || aString == "lower")
4103 theCorner = Aspect_TOTP_BOTTOM;
4105 else if (aString == "left")
4107 theCorner = Aspect_TOTP_LEFT;
4109 else if (aString == "right")
4111 theCorner = Aspect_TOTP_RIGHT;
4113 else if (aString == "topleft"
4114 || aString == "leftupper"
4115 || aString == "upperleft")
4117 theCorner = Aspect_TOTP_LEFT_UPPER;
4119 else if (aString == "bottomleft"
4120 || aString == "leftlower"
4121 || aString == "lowerleft")
4123 theCorner = Aspect_TOTP_LEFT_LOWER;
4125 else if (aString == "topright"
4126 || aString == "rightupper"
4127 || aString == "upperright")
4129 theCorner = Aspect_TOTP_RIGHT_UPPER;
4131 else if (aString == "bottomright"
4132 || aString == "lowerright"
4133 || aString == "rightlower")
4135 theCorner = Aspect_TOTP_RIGHT_LOWER;
4139 return Standard_False;
4142 return Standard_True;
4145 //==============================================================================
4146 //function : VDisplay2
4148 //purpose : Display an object from its name
4149 //==============================================================================
4150 static int VDisplay2 (Draw_Interpretor& theDI,
4151 Standard_Integer theArgNb,
4152 const char** theArgVec)
4156 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4160 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4163 ViewerTest::ViewerInit();
4164 aCtx = ViewerTest::GetAISContext();
4167 // Parse input arguments
4168 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4169 Standard_Integer isMutable = -1;
4170 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4171 Standard_Boolean toDisplayLocal = Standard_False;
4172 Standard_Boolean toReDisplay = Standard_False;
4173 Standard_Integer isSelectable = -1;
4174 Standard_Integer anObjDispMode = -2;
4175 Standard_Integer anObjHighMode = -2;
4176 Standard_Boolean toSetTrsfPers = Standard_False;
4177 Handle(Graphic3d_TransformPers) aTrsfPers;
4178 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4179 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4180 Standard_Integer toDisplayInView = Standard_False;
4181 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4183 const TCollection_AsciiString aName = theArgVec[anArgIter];
4184 TCollection_AsciiString aNameCase = aName;
4185 aNameCase.LowerCase();
4186 if (anUpdateTool.parseRedrawMode (aName))
4190 else if (aNameCase == "-mutable")
4194 else if (aNameCase == "-neutral")
4196 aDispStatus = AIS_DS_Displayed;
4198 else if (aNameCase == "-immediate"
4199 || aNameCase == "-top")
4201 aZLayer = Graphic3d_ZLayerId_Top;
4203 else if (aNameCase == "-topmost")
4205 aZLayer = Graphic3d_ZLayerId_Topmost;
4207 else if (aNameCase == "-osd"
4208 || aNameCase == "-toposd"
4209 || aNameCase == "-overlay")
4211 aZLayer = Graphic3d_ZLayerId_TopOSD;
4213 else if (aNameCase == "-botosd"
4214 || aNameCase == "-underlay")
4216 aZLayer = Graphic3d_ZLayerId_BotOSD;
4218 else if (aNameCase == "-select"
4219 || aNameCase == "-selectable")
4223 else if (aNameCase == "-noselect"
4224 || aNameCase == "-noselection")
4228 else if (aNameCase == "-dispmode"
4229 || aNameCase == "-displaymode")
4231 if (++anArgIter >= theArgNb)
4233 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4237 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4239 else if (aNameCase == "-highmode"
4240 || aNameCase == "-highlightmode")
4242 if (++anArgIter >= theArgNb)
4244 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4248 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4250 else if (aNameCase == "-3d")
4252 toSetTrsfPers = Standard_True;
4253 aTrsfPers.Nullify();
4255 else if (aNameCase == "-2d"
4256 || aNameCase == "-trihedron"
4257 || aNameCase == "-triedron")
4259 toSetTrsfPers = Standard_True;
4260 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4262 if (anArgIter + 1 < theArgNb)
4264 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4265 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4268 aTrsfPers->SetCorner2d (aCorner);
4270 if (anArgIter + 2 < theArgNb)
4272 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4273 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4274 if (anX.IsIntegerValue()
4275 && anY.IsIntegerValue())
4278 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4284 else if (aNameCase == "-trsfpers"
4285 || aNameCase == "-pers")
4287 if (++anArgIter >= theArgNb
4288 || !aTrsfPers.IsNull())
4290 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4294 toSetTrsfPers = Standard_True;
4295 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4296 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4297 aPersFlags.LowerCase();
4298 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
4300 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
4304 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4306 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4308 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4310 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
4313 else if (aNameCase == "-trsfperspos"
4314 || aNameCase == "-perspos")
4316 if (anArgIter + 2 >= theArgNb
4317 || aTrsfPers.IsNull())
4319 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4323 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4324 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4325 TCollection_AsciiString aZ = "0";
4326 if (!aX.IsRealValue()
4327 || !aY.IsRealValue())
4329 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4332 if (anArgIter + 1 < theArgNb)
4334 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
4335 if (aTemp.IsRealValue())
4342 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
4343 if (aTrsfPers->IsZoomOrRotate())
4345 aTrsfPers->SetAnchorPoint (aPnt);
4347 else if (aTrsfPers->IsTrihedronOr2d())
4349 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
4352 else if (aNameCase == "-layer")
4354 if (++anArgIter >= theArgNb)
4356 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4360 TCollection_AsciiString aValue (theArgVec[anArgIter]);
4361 if (!aValue.IsIntegerValue())
4363 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4367 aZLayer = aValue.IntegerValue();
4369 else if (aNameCase == "-view"
4370 || aNameCase == "-inview")
4372 toDisplayInView = Standard_True;
4374 else if (aNameCase == "-local")
4376 aDispStatus = AIS_DS_Temporary;
4377 toDisplayLocal = Standard_True;
4379 else if (aNameCase == "-redisplay")
4381 toReDisplay = Standard_True;
4383 else if (aNameCase == "-erased"
4384 || aNameCase == "-load")
4386 aDispStatus = AIS_DS_Erased;
4390 aNamesOfDisplayIO.Append (aName);
4394 if (aNamesOfDisplayIO.IsEmpty())
4396 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4400 // Prepare context for display
4401 Standard_DISABLE_DEPRECATION_WARNINGS
4402 if (toDisplayLocal && !aCtx->HasOpenedContext())
4404 aCtx->OpenLocalContext (Standard_False);
4406 else if (!toDisplayLocal && aCtx->HasOpenedContext())
4408 aCtx->CloseAllContexts (Standard_False);
4410 Standard_ENABLE_DEPRECATION_WARNINGS
4412 // Display interactive objects
4413 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
4415 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
4417 if (!GetMapOfAIS().IsBound2 (aName))
4419 // create the AIS_Shape from a name
4420 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
4421 if (!aShape.IsNull())
4423 if (isMutable != -1)
4425 aShape->SetMutable (isMutable == 1);
4427 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4429 aShape->SetZLayer (aZLayer);
4433 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4435 if (anObjDispMode != -2)
4437 aShape->SetDisplayMode (anObjDispMode);
4439 if (anObjHighMode != -2)
4441 aShape->SetHilightMode (anObjHighMode);
4443 if (!toDisplayLocal)
4444 GetMapOfAIS().Bind (aShape, aName);
4446 Standard_Integer aDispMode = aShape->HasDisplayMode()
4447 ? aShape->DisplayMode()
4448 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4449 ? aCtx->DisplayMode()
4451 Standard_Integer aSelMode = -1;
4452 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4454 aSelMode = aShape->GlobalSelectionMode();
4457 aCtx->Display (aShape, aDispMode, aSelMode,
4458 Standard_False, aShape->AcceptShapeDecomposition(),
4460 if (toDisplayInView)
4462 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
4464 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
4466 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4471 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
4476 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
4477 if (isMutable != -1)
4479 aShape->SetMutable (isMutable == 1);
4481 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4483 aShape->SetZLayer (aZLayer);
4487 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4489 if (anObjDispMode != -2)
4491 aShape->SetDisplayMode (anObjDispMode);
4493 if (anObjHighMode != -2)
4495 aShape->SetHilightMode (anObjHighMode);
4497 Standard_Integer aDispMode = aShape->HasDisplayMode()
4498 ? aShape->DisplayMode()
4499 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4500 ? aCtx->DisplayMode()
4502 Standard_Integer aSelMode = -1;
4503 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4505 aSelMode = aShape->GlobalSelectionMode();
4508 if (aShape->Type() == AIS_KOI_Datum)
4510 aCtx->Display (aShape, Standard_False);
4514 theDI << "Display " << aName.ToCString() << "\n";
4516 // update the Shape in the AIS_Shape
4517 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
4518 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
4519 if (!aShapePrs.IsNull())
4521 if (!aShapePrs->Shape().IsEqual (aNewShape))
4523 toReDisplay = Standard_True;
4525 aShapePrs->Set (aNewShape);
4529 aCtx->Redisplay (aShape, Standard_False);
4534 aCtx->Erase (aShape, Standard_False);
4536 aCtx->Display (aShape, aDispMode, aSelMode,
4537 Standard_False, aShape->AcceptShapeDecomposition(),
4539 if (toDisplayInView)
4541 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4549 //=======================================================================
4550 //function : VNbDisplayed
4551 //purpose : Returns number of displayed objects
4552 //=======================================================================
4553 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
4554 Standard_Integer theArgsNb,
4555 const char** theArgVec)
4559 theDi << "Usage : " << theArgVec[0] << "\n";
4563 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4564 if (aContextAIS.IsNull())
4566 std::cout << theArgVec[0] << "AIS context is not available.\n";
4570 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4571 if(aContext.IsNull())
4573 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
4577 AIS_ListOfInteractive aListOfIO;
4578 aContextAIS->DisplayedObjects(aListOfIO, false);
4580 theDi << aListOfIO.Extent() << "\n";
4584 //===============================================================================================
4585 //function : VUpdate
4587 //===============================================================================================
4588 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
4590 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4591 if (aContextAIS.IsNull())
4593 std::cout << theArgVec[0] << "AIS context is not available.\n";
4599 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
4603 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
4605 AIS_ListOfInteractive aListOfIO;
4607 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4609 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
4611 Handle(AIS_InteractiveObject) anAISObj;
4612 if (anAISMap.IsBound2 (aName))
4614 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
4617 if (anAISObj.IsNull())
4619 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
4623 aListOfIO.Append (anAISObj);
4626 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
4627 for (; anIOIt.More(); anIOIt.Next())
4629 aContextAIS->Update (anIOIt.Value(), Standard_False);
4632 aContextAIS->UpdateCurrentViewer();
4637 //==============================================================================
4638 //function : VShading
4639 //purpose : Sharpen or roughten the quality of the shading
4640 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4641 //==============================================================================
4642 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4644 Standard_Real myDevCoef;
4645 Handle(AIS_InteractiveObject) TheAisIO;
4648 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4652 myDevCoef =Draw::Atof(argv[2]);
4655 TCollection_AsciiString name=argv[1];
4656 if (GetMapOfAIS().IsBound2(name ))
4657 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4658 if (TheAisIO.IsNull())
4659 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4662 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4664 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4666 TheAISContext()->Redisplay (TheAisIO, Standard_True);
4670 //! Auxiliary method to print Interactive Object information
4671 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4672 const Handle(Standard_Transient)& theObject,
4673 Draw_Interpretor& theDI)
4675 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4678 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4682 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4683 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4684 << (theDetected.Contains (anObj) ? " Detected" : " ")
4686 if (anObj->Type() == AIS_KOI_Datum)
4689 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4690 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4691 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4692 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4693 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4694 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4695 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4698 else if (anObj->Type() == AIS_KOI_Shape
4699 && anObj->Signature() == 0)
4701 theDI << " AIS_Shape";
4703 else if (anObj->Type() == AIS_KOI_Relation)
4705 // AIS_Dimention and AIS_Relation
4706 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4707 switch (aRelation->KindOfDimension())
4709 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4710 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4711 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4712 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4713 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4714 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4715 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4716 default: theDI << " UNKNOWN dimension"; break;
4721 theDI << " UserPrs";
4723 theDI << " (" << theObject->DynamicType()->Name() << ")";
4726 //! Print information about locally selected sub-shapes
4727 template <typename T>
4728 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4730 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4731 TCollection_AsciiString aPrevName;
4732 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4734 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4735 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4736 if (aShapeIO.IsNull() || anOwner.IsNull())
4740 if (anOwner == aShapeIO->GlobalSelOwner())
4743 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4744 if (aSubShape.IsNull()
4745 || aShapeIO.IsNull()
4746 || !GetMapOfAIS().IsBound1 (aShapeIO))
4751 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4752 TopTools_MapOfShape aFilter;
4753 Standard_Integer aNumber = 0;
4754 const TopoDS_Shape aShape = aShapeIO->Shape();
4755 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4756 anIter.More(); anIter.Next())
4758 if (!aFilter.Add (anIter.Current()))
4760 continue; // filter duplicates
4764 if (!anIter.Current().IsSame (aSubShape))
4769 Standard_CString aShapeName = NULL;
4770 switch (aSubShape.ShapeType())
4772 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4773 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4774 case TopAbs_SOLID: aShapeName = " Solid"; break;
4775 case TopAbs_SHELL: aShapeName = " Shell"; break;
4776 case TopAbs_FACE: aShapeName = " Face"; break;
4777 case TopAbs_WIRE: aShapeName = " Wire"; break;
4778 case TopAbs_EDGE: aShapeName = " Edge"; break;
4779 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4781 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4784 if (aParentName != aPrevName)
4786 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4787 aPrevName = aParentName;
4789 theDI << " " << aShapeName << " #" << aNumber << "\n";
4795 //==============================================================================
4798 //==============================================================================
4799 static Standard_Integer VState (Draw_Interpretor& theDI,
4800 Standard_Integer theArgNb,
4801 Standard_CString* theArgVec)
4803 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4806 std::cerr << "Error: No opened viewer!\n";
4810 Standard_Boolean toPrintEntities = Standard_False;
4811 Standard_Boolean toCheckSelected = Standard_False;
4813 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4815 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4816 anOption.LowerCase();
4817 if (anOption == "-detectedentities"
4818 || anOption == "-entities")
4820 toPrintEntities = Standard_True;
4822 else if (anOption == "-hasselected")
4824 toCheckSelected = Standard_True;
4828 if (toCheckSelected)
4830 aCtx->InitSelected();
4831 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4832 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4837 if (toPrintEntities)
4839 theDI << "Detected entities:\n";
4840 Standard_DISABLE_DEPRECATION_WARNINGS
4841 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4842 Standard_ENABLE_DEPRECATION_WARNINGS
4843 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4844 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4846 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4847 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4848 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4849 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4850 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4851 aName.LeftJustify (20, ' ');
4852 char anInfoStr[512];
4854 " Depth: %g Distance: %g Point: %g %g %g",
4857 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4858 theDI << " " << aName
4860 << " (" << anEntity->DynamicType()->Name() << ")"
4863 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4864 if (!aBRepOwner.IsNull())
4866 theDI << " Detected Shape: "
4867 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4871 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4872 if (!aWire.IsNull())
4874 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4875 theDI << " Detected Child: "
4876 << aSen->DynamicType()->Name()
4880 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4881 if (!aPrimArr.IsNull())
4883 theDI << " Detected Element: "
4884 << aPrimArr->LastDetectedElement()
4891 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4892 Standard_DISABLE_DEPRECATION_WARNINGS
4893 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4895 aDetected.Add (aCtx->DetectedCurrentObject());
4897 Standard_ENABLE_DEPRECATION_WARNINGS
4899 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4903 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4905 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4906 if (!GetMapOfAIS().IsBound2 (anObjName))
4908 theDI << anObjName << " doesn't exist!\n";
4912 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4913 TCollection_AsciiString aName = anObjName;
4914 aName.LeftJustify (20, ' ');
4915 theDI << " " << aName << " ";
4916 objInfo (aDetected, anObjTrans, theDI);
4922 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4924 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4925 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4927 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4928 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4929 // handle whole object selection
4930 if (anOwner == anObj->GlobalSelOwner())
4932 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4933 aName.LeftJustify (20, ' ');
4934 theDI << aName << " ";
4935 objInfo (aDetected, anObj, theDI);
4940 // process selected sub-shapes
4941 printLocalSelectionInfo (aCtx, theDI);
4946 theDI << "Neutral-point state:\n";
4947 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4948 anObjIter.More(); anObjIter.Next())
4950 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4956 TCollection_AsciiString aName = anObjIter.Key2();
4957 aName.LeftJustify (20, ' ');
4958 theDI << " " << aName << " ";
4959 objInfo (aDetected, anObj, theDI);
4962 printLocalSelectionInfo (aCtx, theDI);
4963 Standard_DISABLE_DEPRECATION_WARNINGS
4964 if (aCtx->HasOpenedContext())
4965 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
4966 Standard_ENABLE_DEPRECATION_WARNINGS
4970 //=======================================================================
4971 //function : PickShape
4972 //purpose : First Activate the rightmode + Put Filters to be able to
4973 // pick objets that are of type <TheType>...
4974 //=======================================================================
4976 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
4977 const Standard_Integer theMaxPick)
4979 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
4980 PickShapes (theShapeType, aResArray, theMaxPick);
4981 return aResArray->First();
4984 //=======================================================================
4985 //function : PickShapes
4987 //=======================================================================
4988 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
4989 Handle(TopTools_HArray1OfShape)& theResArray,
4990 const Standard_Integer theMaxPick)
4992 const Standard_Integer aNbToReach = theResArray->Length();
4995 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4998 // step 1: prepare the data
4999 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5000 aCtx->RemoveFilters();
5001 AIS_ListOfInteractive aDispObjects;
5002 aCtx->DisplayedObjects (aDispObjects);
5003 if (theShapeType == TopAbs_SHAPE)
5005 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
5009 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
5012 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
5013 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5015 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5017 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5021 // step 2 : wait for the selection...
5022 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
5023 Standard_Integer argccc = 5;
5024 const char *bufff[] = { "A", "B", "C", "D", "E" };
5025 const char **argvvv = (const char** )bufff;
5026 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
5028 while (ViewerMainLoop (argccc, argvvv)) {}
5029 Standard_Integer aNbStored = aCtx->NbSelected();
5030 if (aNbStored != aNbPickGood)
5032 aNbPickGood = aNbStored;
5038 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
5041 // step3 get result.
5042 if (aNbPickFail >= aNbToReach)
5044 return Standard_False;
5047 Standard_Integer anIndex = theResArray->Lower();
5048 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
5050 if (aCtx->HasSelectedShape())
5052 theResArray->SetValue (anIndex, aCtx->SelectedShape());
5056 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
5057 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
5061 aCtx->RemoveFilters();
5062 if (theShapeType != TopAbs_SHAPE)
5064 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5066 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5068 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5072 return Standard_True;
5075 //=======================================================================
5076 //function : VPickShape
5078 //=======================================================================
5079 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5081 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
5084 TCollection_AsciiString aShapeArg (argv[1]);
5085 aShapeArg.LowerCase();
5086 aShapeType = TopAbs_COMPOUND;
5087 if (aShapeArg == "v"
5088 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
5089 else if (aShapeArg == "e"
5090 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
5091 else if (aShapeArg == "w"
5092 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
5093 else if (aShapeArg == "f"
5094 || aShapeArg == "face") aShapeType = TopAbs_FACE;
5095 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
5096 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
5097 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
5100 std::cout << "Syntax error at '" << argv[1] << "'\n";
5105 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5106 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
5108 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
5111 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
5112 if (aPickedShape.IsNull())
5117 TCollection_AsciiString aName;
5124 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5125 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5128 DBRep::Set (aName.ToCString(), aPickedShape);
5129 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5130 ViewerTest::Display (aName, aShapePrs, false, true);
5131 di << "Name of picked shape: " << aName <<"\n";
5135 TCollection_AsciiString aName (argv[2]);
5137 const Standard_Boolean isAutoNaming = aName == ".";
5138 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5139 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5141 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5143 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5145 if (!aPickedShape.IsNull()
5148 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5149 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5153 aName = argv[1 + aPickedIter];
5156 DBRep::Set (aName.ToCString(), aPickedShape);
5157 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5158 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5159 ViewerTest::Display (aName, aShapePrs, false, true);
5163 TheAISContext()->UpdateCurrentViewer();
5167 //=======================================================================
5168 //function : VSelFilter
5170 //=======================================================================
5171 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5172 const char** theArgv)
5174 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5175 if (aContext.IsNull())
5177 std::cout << "Error: AIS context is not available.\n";
5181 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5183 TCollection_AsciiString anArg (theArgv[anArgIter]);
5185 if (anArg == "-clear")
5187 aContext->RemoveFilters();
5189 else if (anArg == "-type"
5190 && anArgIter + 1 < theArgc)
5192 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5193 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5194 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5196 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5200 Handle(SelectMgr_Filter) aFilter;
5201 if (aShapeType == TopAbs_SHAPE)
5203 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5207 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5209 aContext->AddFilter (aFilter);
5213 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5220 //=======================================================================
5221 //function : VPickSelected
5223 //=======================================================================
5224 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5226 static Standard_Integer aCount = 0;
5227 TCollection_AsciiString aName = "PickedShape_";
5235 aName = aName + aCount++ + "_";
5238 Standard_Integer anIdx = 0;
5239 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5241 TopoDS_Shape aShape;
5242 if (TheAISContext()->HasSelectedShape())
5244 aShape = TheAISContext()->SelectedShape();
5248 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5249 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5252 TCollection_AsciiString aCurrentName = aName;
5255 aCurrentName += anIdx;
5258 DBRep::Set ((aCurrentName).ToCString(), aShape);
5260 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5261 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5262 TheAISContext()->Display (aNewShape, Standard_False);
5265 TheAISContext()->UpdateCurrentViewer();
5270 //=======================================================================
5271 //function : list of known objects
5273 //=======================================================================
5274 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5276 // 1234567890 12345678901234567 123456789
5277 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5278 TCollection_AsciiString BlankLine(64,'_');
5279 Standard_Integer i ;
5281 di<<"/n"<<BlankLine.ToCString()<<"\n";
5284 Colum[i].Center(20,' ');
5286 di<<"|"<<Colum[i].ToCString();
5289 di<<BlankLine.ToCString()<<"\n";
5291 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5292 const char ** names = GetTypeNames();
5294 TCollection_AsciiString curstring;
5295 TCollection_AsciiString curcolum[3];
5298 // les objets de type Datum..
5299 curcolum[1]+="Datum";
5301 curcolum[0].Clear();
5302 curcolum[0] += names[i];
5304 curcolum[2].Clear();
5305 curcolum[2]+=TCollection_AsciiString(i+1);
5307 for(Standard_Integer j =0;j<=2;j++){
5308 curcolum[j].Center(20,' ');
5309 di<<"|"<<curcolum[j].ToCString();
5313 di<<BlankLine.ToCString()<<"\n";
5315 // les objets de type shape
5316 curcolum[1].Clear();
5317 curcolum[1]+="Shape";
5318 curcolum[1].Center(20,' ');
5321 curcolum[0].Clear();
5322 curcolum[0] += names[7+i];
5323 curcolum[2].Clear();
5324 curcolum[2]+=TCollection_AsciiString(i);
5326 for(Standard_Integer j =0;j<=2;j++){
5327 curcolum[j].Center(20,' ');
5328 di<<"|"<<curcolum[j].ToCString();
5332 di<<BlankLine.ToCString()<<"\n";
5333 // les IO de type objet...
5334 curcolum[1].Clear();
5335 curcolum[1]+="Object";
5336 curcolum[1].Center(20,' ');
5338 curcolum[0].Clear();
5339 curcolum[0] += names[10+i];
5340 curcolum[2].Clear();
5341 curcolum[2]+=TCollection_AsciiString(i);
5343 for(Standard_Integer j =0;j<=2;j++){
5344 curcolum[j].Center(20,' ');
5345 di<<"|"<<curcolum[j].ToCString();
5349 di<<BlankLine.ToCString()<<"\n";
5350 // les contraintes et dimensions.
5351 // pour l'instant on separe juste contraintes et dimensions...
5352 // plus tard, on detaillera toutes les sortes...
5353 curcolum[1].Clear();
5354 curcolum[1]+="Relation";
5355 curcolum[1].Center(20,' ');
5357 curcolum[0].Clear();
5358 curcolum[0] += names[12+i];
5359 curcolum[2].Clear();
5360 curcolum[2]+=TCollection_AsciiString(i);
5362 for(Standard_Integer j =0;j<=2;j++){
5363 curcolum[j].Center(20,' ');
5364 di<<"|"<<curcolum[j].ToCString();
5368 di<<BlankLine.ToCString()<<"\n";
5375 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5377 if(argc!=2) return 1;
5379 AIS_KindOfInteractive TheType;
5380 Standard_Integer TheSign(-1);
5381 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5384 AIS_ListOfInteractive LIO;
5386 // en attendant l'amelioration ais pour les dimensions...
5388 Standard_Integer dimension_status(-1);
5389 if(TheType==AIS_KOI_Relation){
5390 dimension_status = TheSign ==1 ? 1 : 0;
5394 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5395 Handle(AIS_InteractiveObject) curio;
5396 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5399 if(dimension_status == -1)
5400 TheAISContext()->Erase(curio,Standard_False);
5402 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5403 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5404 (dimension_status==1 && KOD != AIS_KOD_NONE))
5405 TheAISContext()->Erase(curio,Standard_False);
5408 TheAISContext()->UpdateCurrentViewer();
5411 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5413 if(argc!=2) return 1;
5415 AIS_KindOfInteractive TheType;
5416 Standard_Integer TheSign(-1);
5417 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5419 // en attendant l'amelioration ais pour les dimensions...
5421 Standard_Integer dimension_status(-1);
5422 if(TheType==AIS_KOI_Relation){
5423 dimension_status = TheSign ==1 ? 1 : 0;
5427 AIS_ListOfInteractive LIO;
5428 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5429 Handle(AIS_InteractiveObject) curio;
5430 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5432 if(dimension_status == -1)
5433 TheAISContext()->Display(curio,Standard_False);
5435 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5436 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5437 (dimension_status==1 && KOD != AIS_KOD_NONE))
5438 TheAISContext()->Display(curio,Standard_False);
5443 TheAISContext()->UpdateCurrentViewer();
5447 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5450 BRep_Builder builder;
5452 BRepTools::Read(shape, s, builder);
5453 DBRep::Set(a[1], shape);
5454 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5455 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5456 Ctx->Display (ais, Standard_True);
5460 //===============================================================================================
5463 //===============================================================================================
5464 static int VBsdf (Draw_Interpretor& theDI,
5465 Standard_Integer theArgsNb,
5466 const char** theArgVec)
5468 Handle(V3d_View) aView = ViewerTest::CurrentView();
5469 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5471 || aViewer.IsNull())
5473 std::cerr << "No active viewer!\n";
5477 ViewerTest_CmdParser aCmd;
5479 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5481 aCmd.AddOption ("print|echo|p", "Prints BSDF");
5483 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
5485 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
5486 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
5487 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
5488 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
5489 aCmd.AddOption ("le", "Radiance emitted by surface");
5491 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5492 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5494 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
5495 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
5497 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
5498 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
5500 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
5502 aCmd.Parse (theArgsNb, theArgVec);
5504 if (aCmd.HasOption ("help"))
5506 theDI.PrintHelp (theArgVec[0]);
5510 // check viewer update mode
5511 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
5513 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5515 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5521 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5524 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5525 if (!aMap.IsBound2 (aName) )
5527 std::cerr << "Use 'vdisplay' before\n";
5531 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5532 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5533 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5535 if (aCmd.HasOption ("print"))
5538 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
5539 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5540 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5541 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5542 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
5544 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5546 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
5547 : aBSDF.FresnelBase.Serialize();
5549 theDI << (aLayerID < 1 ? "Coat Fresnel: "
5550 : "Base Fresnel: ");
5552 if (aFresnel.x() >= 0.f)
5554 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
5555 << "G = " << aFresnel.g() << ", "
5556 << "B = " << aFresnel.b() << "\n";
5558 else if (aFresnel.x() >= -1.5f)
5560 theDI << "Constant " << aFresnel.z() << "\n";
5562 else if (aFresnel.x() >= -2.5f)
5564 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
5565 << "K = " << aFresnel.z() << "\n";
5569 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
5573 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
5574 << "Base roughness: " << aBSDF.Ks.w() << "\n"
5575 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
5576 << "Absorption color: " << aBSDF.Absorption.r() << ", "
5577 << aBSDF.Absorption.g() << ", "
5578 << aBSDF.Absorption.b() << "\n";
5583 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
5585 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
5588 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
5590 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
5593 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5595 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
5598 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5600 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
5602 aBSDF.Absorption.r() = aRGB.r();
5603 aBSDF.Absorption.g() = aRGB.g();
5604 aBSDF.Absorption.b() = aRGB.b();
5607 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
5611 if (aCmd.HasOption ("kc", 3))
5613 aKc = aCmd.ArgVec3f ("kc");
5617 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
5620 aBSDF.Kc.r() = aKc.r();
5621 aBSDF.Kc.g() = aKc.g();
5622 aBSDF.Kc.b() = aKc.b();
5625 if (aCmd.HasOption ("kd", 3))
5627 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5629 else if (aCmd.HasOption ("kd", 1, Standard_True))
5631 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5634 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
5638 if (aCmd.HasOption ("ks", 3))
5640 aKs = aCmd.ArgVec3f ("ks");
5644 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5647 aBSDF.Ks.r() = aKs.r();
5648 aBSDF.Ks.g() = aKs.g();
5649 aBSDF.Ks.b() = aKs.b();
5652 if (aCmd.HasOption ("kt", 3))
5654 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5656 else if (aCmd.HasOption ("kt", 1, Standard_True))
5658 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5661 if (aCmd.HasOption ("le", 3))
5663 aBSDF.Le = aCmd.ArgVec3f ("le");
5665 else if (aCmd.HasOption ("le", 1, Standard_True))
5667 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5670 const std::string aFresnelErrorMessage =
5671 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
5673 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5675 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
5678 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
5680 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5681 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5683 if (aFresnelType == "schlick")
5685 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
5686 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
5687 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
5689 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
5690 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
5691 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
5693 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
5697 theDI << aFresnelErrorMessage.c_str() << "\n";
5700 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
5702 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5703 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5705 if (aFresnelType == "conductor")
5707 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5708 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
5710 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
5714 theDI << aFresnelErrorMessage.c_str() << "\n";
5717 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
5719 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5720 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5722 if (aFresnelType == "constant")
5724 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5726 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
5728 else if (aFresnelType == "dielectric")
5730 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5732 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
5736 theDI << aFresnelErrorMessage.c_str() << "\n";
5741 if (aCmd.HasOption ("normalize"))
5746 aMaterial.SetBSDF (aBSDF);
5747 anIObj->SetMaterial (aMaterial);
5752 //==============================================================================
5753 //function : VLoadSelection
5754 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5755 //==============================================================================
5756 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5757 Standard_Integer theArgNb,
5758 const char** theArgVec)
5762 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5766 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5769 ViewerTest::ViewerInit();
5770 aCtx = ViewerTest::GetAISContext();
5773 // Parse input arguments
5774 TColStd_SequenceOfAsciiString aNamesOfIO;
5775 Standard_Boolean isLocal = Standard_False;
5776 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5778 const TCollection_AsciiString aName = theArgVec[anArgIter];
5779 TCollection_AsciiString aNameCase = aName;
5780 aNameCase.LowerCase();
5781 if (aNameCase == "-local")
5783 isLocal = Standard_True;
5787 aNamesOfIO.Append (aName);
5791 if (aNamesOfIO.IsEmpty())
5793 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5798 Standard_DISABLE_DEPRECATION_WARNINGS
5799 if (isLocal && !aCtx->HasOpenedContext())
5801 aCtx->OpenLocalContext (Standard_False);
5803 else if (!isLocal && aCtx->HasOpenedContext())
5805 aCtx->CloseAllContexts (Standard_False);
5807 Standard_ENABLE_DEPRECATION_WARNINGS
5809 // Load selection of interactive objects
5810 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5812 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5814 Handle(AIS_InteractiveObject) aShape;
5815 if (GetMapOfAIS().IsBound2 (aName))
5816 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5818 aShape = GetAISShapeFromName (aName.ToCString());
5820 if (!aShape.IsNull())
5822 if (!GetMapOfAIS().IsBound2 (aName))
5824 GetMapOfAIS().Bind (aShape, aName);
5827 aCtx->Load (aShape, -1, Standard_False);
5828 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5835 //==============================================================================
5836 //function : ViewerTest::Commands
5837 //purpose : Add all the viewer command in the Draw_Interpretor
5838 //==============================================================================
5840 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5842 ViewerTest::ViewerCommands(theCommands);
5843 ViewerTest::RelationCommands(theCommands);
5844 ViewerTest::ObjectCommands(theCommands);
5845 ViewerTest::FilletCommands(theCommands);
5846 ViewerTest::OpenGlCommands(theCommands);
5848 const char *group = "AIS_Display";
5851 theCommands.Add("visos",
5852 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5853 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5854 __FILE__, visos, group);
5856 theCommands.Add("vdisplay",
5857 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5858 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5859 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5860 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5861 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5862 "\n\t\t: [offsetX offsetY]]]"
5863 "\n\t\t: [-dispMode mode] [-highMode mode]"
5864 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5865 "\n\t\t: [-redisplay] [-erased]"
5866 "\n\t\t: name1 [name2] ... [name n]"
5867 "\n\t\t: Displays named objects."
5868 "\n\t\t: Option -local enables displaying of objects in local"
5869 "\n\t\t: selection context. Local selection context will be opened"
5870 "\n\t\t: if there is not any."
5871 "\n\t\t: -noupdate Suppresses viewer redraw call."
5872 "\n\t\t: -mutable Enables optimizations for mutable objects."
5873 "\n\t\t: -neutral Draws objects in main viewer."
5874 "\n\t\t: -erased Loads the object into context, but does not display it."
5875 "\n\t\t: -layer Sets z-layer for objects."
5876 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5877 "\n\t\t: options can be used for the default z-layers."
5878 "\n\t\t: -top Draws object on top of main presentations"
5879 "\n\t\t: but below topmost."
5880 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5881 "\n\t\t: with independent Depth."
5882 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5883 "\n\t\t: (On-Screen-Display)"
5884 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5885 "\n\t\t: (On-Screen-Display)"
5886 "\n\t\t: -selectable|-noselect Controls selection of objects."
5887 "\n\t\t: -trsfPers Sets a transform persistence flags."
5888 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5889 "\n\t\t: -2d Displays object in screen coordinates."
5890 "\n\t\t: (DY looks up)"
5891 "\n\t\t: -dispmode Sets display mode for objects."
5892 "\n\t\t: -highmode Sets hilight mode for objects."
5893 "\n\t\t: -redisplay Recomputes presentation of objects.",
5894 __FILE__, VDisplay2, group);
5896 theCommands.Add ("vnbdisplayed",
5898 "\n\t\t: Returns number of displayed objects",
5899 __FILE__, VNbDisplayed, group);
5901 theCommands.Add ("vupdate",
5902 "vupdate name1 [name2] ... [name n]"
5903 "\n\t\t: Updates named objects in interactive context",
5904 __FILE__, VUpdate, group);
5906 theCommands.Add("verase",
5907 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5908 "\n\t\t: Erases selected or named objects."
5909 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5910 "\n\t\t: Option -local enables erasing of selected or named objects without"
5911 "\n\t\t: closing local selection context.",
5912 __FILE__, VErase, group);
5914 theCommands.Add("vremove",
5915 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5916 "or vremove [-context] -all to remove all objects"
5917 "\n\t\t: Removes selected or named objects."
5918 "\n\t\t If -context is in arguments, the objects are not deleted"
5919 "\n\t\t from the map of objects and names."
5920 "\n\t\t: Option -local enables removing of selected or named objects without"
5921 "\n\t\t: closing local selection context. Empty local selection context will be"
5923 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5924 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5925 __FILE__, VRemove, group);
5927 theCommands.Add("vdonly",
5928 "vdonly [-noupdate|-update] [name1] ... [name n]"
5929 "\n\t\t: Displays only selected or named objects",
5930 __FILE__,VDonly2,group);
5932 theCommands.Add("vdisplayall",
5933 "vidsplayall [-local]"
5934 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5935 "\n\t\t: Option -local enables displaying of the objects in local"
5936 "\n\t\t: selection context.",
5937 __FILE__, VDisplayAll, group);
5939 theCommands.Add("veraseall",
5940 "veraseall [-local]"
5941 "\n\t\t: Erases all objects displayed in the viewer."
5942 "\n\t\t: Option -local enables erasing of the objects in local"
5943 "\n\t\t: selection context.",
5944 __FILE__, VErase, group);
5946 theCommands.Add("verasetype",
5948 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5949 __FILE__, VEraseType, group);
5950 theCommands.Add("vbounding",
5951 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5952 "\n\t\t: [-print] [-hide]"
5953 "\n\t\t: Temporarily display bounding box of specified Interactive"
5954 "\n\t\t: Objects, or print it to console if -print is specified."
5955 "\n\t\t: Already displayed box might be hidden by -hide option.",
5956 __FILE__,VBounding,group);
5958 theCommands.Add("vdisplaytype",
5959 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5960 __FILE__,VDisplayType,group);
5962 theCommands.Add("vsetdispmode",
5963 "vsetdispmode [name] mode(1,2,..)"
5964 "\n\t\t: Sets display mode for all, selected or named objects.",
5965 __FILE__,VDispMode,group);
5967 theCommands.Add("vunsetdispmode",
5968 "vunsetdispmode [name]"
5969 "\n\t\t: Unsets custom display mode for selected or named objects.",
5970 __FILE__,VDispMode,group);
5972 theCommands.Add("vdir",
5973 "Lists all objects displayed in 3D viewer",
5974 __FILE__,VDir,group);
5976 #ifdef HAVE_FREEIMAGE
5977 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5979 #define DUMP_FORMATS "{ppm}"
5981 theCommands.Add("vdump",
5982 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5983 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5984 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5985 "\n\t\t: [-tileSize Size=0]"
5986 "\n\t\t: Dumps content of the active view into image file",
5987 __FILE__,VDump,group);
5989 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5990 __FILE__,VSubInt,group);
5992 theCommands.Add("vaspects",
5993 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5994 "\n\t\t: [-setVisibility 0|1]"
5995 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5996 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5997 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5998 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5999 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
6000 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
6001 "\n\t\t: [-unsetMarkerType]"
6002 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
6003 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
6004 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
6005 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
6006 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
6007 "\n\t\t: [-isoontriangulation 0|1]"
6008 "\n\t\t: [-setMaxParamValue {value}]"
6009 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
6010 "\n\t\t: [-setHatch HatchStyle]"
6011 "\n\t\t: [-setShadingModel {color|flat|gouraud|phong}]"
6012 "\n\t\t: [-unsetShadingModel]"
6013 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
6014 "\n\t\t: Manage presentation properties of all, selected or named objects."
6015 "\n\t\t: When -subshapes is specified than following properties will be"
6016 "\n\t\t: assigned to specified sub-shapes."
6017 "\n\t\t: When -defaults is specified than presentation properties will be"
6018 "\n\t\t: assigned to all objects that have not their own specified properties"
6019 "\n\t\t: and to all objects to be displayed in the future."
6020 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
6021 __FILE__,VAspects,group);
6023 theCommands.Add("vsetcolor",
6024 "vsetcolor [-noupdate|-update] [name] ColorName"
6025 "\n\t\t: Sets color for all, selected or named objects."
6026 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
6027 __FILE__,VAspects,group);
6029 theCommands.Add("vunsetcolor",
6030 "vunsetcolor [-noupdate|-update] [name]"
6031 "\n\t\t: Resets color for all, selected or named objects."
6032 "\n\t\t: Alias for vaspects -unsetcolor [name].",
6033 __FILE__,VAspects,group);
6035 theCommands.Add("vsettransparency",
6036 "vsettransparency [-noupdate|-update] [name] Coefficient"
6037 "\n\t\t: Sets transparency for all, selected or named objects."
6038 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
6039 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
6040 __FILE__,VAspects,group);
6042 theCommands.Add("vunsettransparency",
6043 "vunsettransparency [-noupdate|-update] [name]"
6044 "\n\t\t: Resets transparency for all, selected or named objects."
6045 "\n\t\t: Alias for vaspects -unsettransp [name].",
6046 __FILE__,VAspects,group);
6048 theCommands.Add("vsetmaterial",
6049 "vsetmaterial [-noupdate|-update] [name] MaterialName"
6050 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
6051 __FILE__,VAspects,group);
6053 theCommands.Add("vunsetmaterial",
6054 "vunsetmaterial [-noupdate|-update] [name]"
6055 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
6056 __FILE__,VAspects,group);
6058 theCommands.Add("vsetwidth",
6059 "vsetwidth [-noupdate|-update] [name] width(0->10)"
6060 "\n\t\t: Alias for vaspects -setwidth [name] width.",
6061 __FILE__,VAspects,group);
6063 theCommands.Add("vunsetwidth",
6064 "vunsetwidth [-noupdate|-update] [name]"
6065 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
6066 __FILE__,VAspects,group);
6068 theCommands.Add("vsetinteriorstyle",
6069 "vsetinteriorstyle [-noupdate|-update] [name] style"
6070 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
6071 __FILE__,VSetInteriorStyle,group);
6073 theCommands.Add("vsensdis",
6074 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
6075 "\n\t\t: Standard entity types are those defined in Select3D package:"
6076 "\n\t\t: - sensitive box"
6077 "\n\t\t: - sensitive face"
6078 "\n\t\t: - sensitive curve"
6079 "\n\t\t: - sensitive segment"
6080 "\n\t\t: - sensitive circle"
6081 "\n\t\t: - sensitive point"
6082 "\n\t\t: - sensitive triangulation"
6083 "\n\t\t: - sensitive triangle"
6084 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
6085 __FILE__,VDispSensi,group);
6087 theCommands.Add("vsensera",
6088 "vsensera : erase active entities",
6089 __FILE__,VClearSensi,group);
6091 theCommands.Add("vsetshading",
6092 "vsetshading : vsetshading name Quality(default=0.0008) "
6093 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
6094 __FILE__,VShading,group);
6096 theCommands.Add("vunsetshading",
6097 "vunsetshading :vunsetshading name "
6098 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
6099 __FILE__,VShading,group);
6101 theCommands.Add ("vtexture",
6102 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
6103 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
6104 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
6105 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
6106 "\n\t\t: [-modulate {on|off}]"
6107 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
6108 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
6109 "\n\t\t: [-default]"
6110 "\n\t\t: The texture can be specified by filepath"
6111 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
6112 "\n\t\t: The options are:"
6113 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
6114 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
6115 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
6116 "\n\t\t: -modulate Enable or disable texture color modulation"
6117 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
6118 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
6119 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
6120 "\n\t\t: -setFilter Setup texture filter"
6121 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
6122 "\n\t\t: -default Sets texture mapping default parameters",
6123 __FILE__, VTexture, group);
6125 theCommands.Add("vtexscale",
6126 "vtexscale name ScaleU ScaleV"
6127 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
6128 __FILE__,VTexture,group);
6130 theCommands.Add("vtexorigin",
6131 "vtexorigin name OriginU OriginV"
6132 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
6133 __FILE__,VTexture,group);
6135 theCommands.Add("vtexrepeat",
6136 "vtexrepeat name RepeatU RepeatV"
6137 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
6140 theCommands.Add("vtexdefault",
6142 "\n\t\t: Alias for vtexture name -default.",
6145 theCommands.Add("vstate",
6146 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6147 "\n\t\t: Reports show/hidden state for selected or named objects"
6148 "\n\t\t: -entities - print low-level information about detected entities"
6149 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6150 __FILE__,VState,group);
6152 theCommands.Add("vpickshapes",
6153 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6154 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6155 "\n\t\t: Hold also Shift for multiple selection.",
6156 __FILE__, VPickShape, group);
6158 theCommands.Add("vtypes",
6159 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6162 theCommands.Add("vr",
6164 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6165 __FILE__,vr, group);
6167 theCommands.Add("vselfilter",
6168 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6169 "\nSets selection shape type filter in context or remove all filters."
6170 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6171 "\n : Option -clear remove all filters in context",
6172 __FILE__,VSelFilter,group);
6174 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6175 __FILE__, VPickSelected, group);
6177 theCommands.Add ("vloadselection",
6178 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6179 "\n\t\t: primitives for the shapes with names given without displaying them."
6180 "\n\t\t: -local - open local context before selection computation",
6181 __FILE__, VLoadSelection, group);
6183 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6184 "\nAdjusts parameters of material BSDF:"
6185 "\n -help : Shows this message"
6186 "\n -print : Print BSDF"
6187 "\n -kd : Weight of the Lambertian BRDF"
6188 "\n -kr : Weight of the reflection BRDF"
6189 "\n -kt : Weight of the transmission BTDF"
6190 "\n -ks : Weight of the glossy Blinn BRDF"
6191 "\n -le : Self-emitted radiance"
6192 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6193 "\n Schlick x y z, Dielectric x, Conductor x y"
6194 "\n -roughness : Roughness of material (Blinn's exponent)"
6195 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6196 "\n -absorpcolor : Absorption color (only for transparent material)"
6197 "\n -normalize : Normalize BSDF coefficients",
6198 __FILE__, VBsdf, group);
6202 //=====================================================================
6203 //========================= for testing Draft and Rib =================
6204 //=====================================================================
6205 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6206 #include <DBRep.hxx>
6207 #include <TopoDS_Face.hxx>
6208 #include <gp_Pln.hxx>
6209 #include <AIS_KindOfSurface.hxx>
6210 #include <BRepOffsetAPI_DraftAngle.hxx>
6211 #include <Precision.hxx>
6212 #include <BRepAlgo.hxx>
6213 #include <OSD_Environment.hxx>
6214 #include <DrawTrSurf.hxx>
6215 //#include <DbgTools.hxx>
6216 //#include <FeatAlgo_MakeLinearForm.hxx>
6221 //=======================================================================
6222 //function : IsValid
6224 //=======================================================================
6225 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6226 const TopoDS_Shape& theResult,
6227 const Standard_Boolean closedSolid,
6228 const Standard_Boolean GeomCtrl)
6230 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6231 TCollection_AsciiString checkValid = check.Value();
6232 Standard_Boolean ToCheck = Standard_True;
6233 if (!checkValid.IsEmpty()) {
6235 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6237 if ( checkValid=="true" || checkValid=="TRUE" ) {
6238 ToCheck= Standard_False;
6242 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6245 Standard_Boolean IsValid = Standard_True;
6247 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6252 //===============================================================================
6253 // TDraft : test draft, uses AIS Viewer
6254 // Solid Face Plane Angle Reverse
6255 //===============================================================================
6256 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6258 if (argc < 5) return 1;
6259 // argv[1] - TopoDS_Shape Solid
6260 // argv[2] - TopoDS_Shape Face
6261 // argv[3] - TopoDS_Shape Plane
6262 // argv[4] - Standard_Real Angle
6263 // argv[5] - Standard_Integer Reverse
6265 // Sprintf(prefix, argv[1]);
6266 Standard_Real anAngle = 0;
6267 Standard_Boolean Rev = Standard_False;
6268 Standard_Integer rev = 0;
6269 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
6270 TopoDS_Shape face = GetShapeFromName(argv[2]);
6271 TopoDS_Face Face = TopoDS::Face(face);
6272 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
6273 if (Plane.IsNull ()) {
6274 di << "TEST : Plane is NULL\n";
6277 anAngle = Draw::Atof(argv[4]);
6278 anAngle = 2*M_PI * anAngle / 360.0;
6280 Handle( Geom_Surface )aSurf;
6281 AIS_KindOfSurface aSurfType;
6282 Standard_Real Offset;
6284 if(argc > 4) { // == 5
6285 rev = Draw::Atoi(argv[5]);
6286 Rev = (rev)? Standard_True : Standard_False;
6289 TopoDS_Face face2 = TopoDS::Face(Plane);
6290 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6292 di << "TEST : Can't find plane\n";
6296 aDir = aPln.Axis().Direction();
6299 if (Plane.Orientation() == TopAbs_REVERSED)
6301 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6303 BRepOffsetAPI_DraftAngle Draft (Solid);
6305 if(Abs(anAngle)< Precision::Angular()) {
6306 di << "TEST : NULL angle\n";
6309 if(Rev) anAngle = - anAngle;
6310 Draft.Add (Face, aDir, anAngle, aPln);
6312 if (!Draft.IsDone()) {
6313 di << "TEST : Draft Not DONE \n";
6316 TopTools_ListOfShape Larg;
6318 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6319 di << "TEST : DesignAlgo returns Not valid\n";
6323 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6324 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6326 if ( !ais.IsNull() ) {
6327 ais->SetColor(DEFAULT_COLOR);
6328 ais->SetMaterial(DEFAULT_MATERIAL);
6329 // Display the AIS_Shape without redraw
6330 Ctx->Display(ais, Standard_False);
6332 const char *Name = "draft1";
6333 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6335 Handle(AIS_InteractiveObject) an_object =
6336 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6337 if (!an_object.IsNull()) {
6338 Ctx->Remove(an_object,
6340 GetMapOfAIS().UnBind2(Name) ;
6343 GetMapOfAIS().Bind(ais, Name);
6344 // DBRep::Set("draft", ais->Shape());
6346 Ctx->Display(ais, Standard_True);
6350 //==============================================================================
6351 //function : splitParameter
6352 //purpose : Split parameter string to parameter name and parameter value
6353 //==============================================================================
6354 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6355 TCollection_AsciiString& theName,
6356 TCollection_AsciiString& theValue)
6358 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6360 if (aParamNameEnd == 0)
6362 return Standard_False;
6365 TCollection_AsciiString aString (theString);
6366 if (aParamNameEnd != 0)
6368 theValue = aString.Split (aParamNameEnd);
6369 aString.Split (aString.Length() - 1);
6373 return Standard_True;
6376 //============================================================================
6378 //============================================================================
6379 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6382 DrawTrSurf::BasicCommands(theCommands);
6383 const char* group = "Check Features Operations commands";
6385 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6387 &TDraft,group); //Draft_Modification
6390 //==============================================================================
6391 // ViewerTest::Factory
6392 //==============================================================================
6393 void ViewerTest::Factory(Draw_Interpretor& theDI)
6395 // definition of Viewer Command
6396 ViewerTest::Commands(theDI);
6399 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6403 // Declare entry point PLUGINFACTORY