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();
2636 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2637 Handle(AIS_ColoredShape) aColoredPrs;
2638 Standard_Boolean toDisplay = Standard_False;
2639 Standard_Boolean toRedisplay = Standard_False;
2640 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2642 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2643 if (aShapePrs.IsNull())
2645 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2648 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2649 if (aColoredPrs.IsNull())
2651 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2652 if (aShapePrs->HasDisplayMode())
2654 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2656 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2657 aCtx->Remove (aShapePrs, Standard_False);
2658 GetMapOfAIS().UnBind2 (aName);
2659 GetMapOfAIS().Bind (aColoredPrs, aName);
2660 toDisplay = Standard_True;
2661 aShapePrs = aColoredPrs;
2668 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2669 aChangeSet = &aChangesIter.ChangeValue();
2670 if (aChangeSet->ToSetVisibility == 1)
2672 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2673 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2675 else if (aChangeSet->ToSetMaterial == 1)
2677 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2679 else if (aChangeSet->ToSetMaterial == -1)
2681 aCtx->UnsetMaterial (aPrs, Standard_False);
2683 if (aChangeSet->ToSetColor == 1)
2685 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2687 else if (aChangeSet->ToSetColor == -1)
2689 aCtx->UnsetColor (aPrs, Standard_False);
2691 if (aChangeSet->ToSetTransparency == 1)
2693 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2695 else if (aChangeSet->ToSetTransparency == -1)
2697 aCtx->UnsetTransparency (aPrs, Standard_False);
2699 if (aChangeSet->ToSetLineWidth == 1)
2701 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2703 else if (aChangeSet->ToSetLineWidth == -1)
2705 aCtx->UnsetWidth (aPrs, Standard_False);
2707 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2709 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2710 toRedisplay = Standard_True;
2712 else if (aChangeSet->ToSetSensitivity != 0)
2714 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2716 if (!aDrawer.IsNull())
2718 if (aChangeSet->ToSetShowFreeBoundary == 1)
2720 aDrawer->SetFreeBoundaryDraw (Standard_True);
2721 toRedisplay = Standard_True;
2723 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2725 aDrawer->SetFreeBoundaryDraw (Standard_False);
2726 toRedisplay = Standard_True;
2728 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2730 Handle(Prs3d_LineAspect) aBoundaryAspect =
2731 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2732 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2733 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2734 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2735 toRedisplay = Standard_True;
2737 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2739 Handle(Prs3d_LineAspect) aBoundaryAspect =
2740 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2741 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2742 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2743 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2744 toRedisplay = Standard_True;
2746 if (aChangeSet->ToSetTypeOfLine != 0)
2748 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2749 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2750 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2751 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2752 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2753 toRedisplay = Standard_True;
2755 if (aChangeSet->ToSetTypeOfMarker != 0)
2757 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2758 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2759 aMarkerAspect->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2760 aMarkerAspect->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2761 ? Handle(Graphic3d_MarkerImage)()
2762 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2763 aDrawer->SetPointAspect (aMarkerAspect);
2764 toRedisplay = Standard_True;
2766 if (aChangeSet->ToSetMarkerSize != 0)
2768 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2769 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2770 aMarkerAspect->SetScale (aChangeSet->MarkerSize);
2771 aDrawer->SetPointAspect (aMarkerAspect);
2772 toRedisplay = Standard_True;
2774 if (aChangeSet->ToSetMaxParamValue != 0)
2776 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2778 if (aChangeSet->ToSetHatch != 0)
2780 if (!aDrawer->HasOwnShadingAspect())
2782 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2783 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2786 Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
2787 if (aChangeSet->ToSetHatch == -1)
2789 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2793 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2794 if (!aChangeSet->PathToHatchPattern.IsEmpty())
2796 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2797 if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
2799 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2803 std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
2807 else if (aChangeSet->StdHatchStyle != -1)
2809 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
2812 toRedisplay = Standard_True;
2814 if (aChangeSet->ToSetShadingModel != 0)
2816 aDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2817 toRedisplay = Standard_True;
2819 if (aChangeSet->ToSetAlphaMode != 0)
2821 if (!aDrawer->HasOwnShadingAspect())
2823 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2824 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2826 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2827 toRedisplay = Standard_True;
2831 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2833 aChangeSet = &aChangesIter.ChangeValue();
2834 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2835 aSubShapeIter.More(); aSubShapeIter.Next())
2837 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2838 if (aChangeSet->ToSetVisibility == 1)
2840 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2841 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2843 if (aChangeSet->ToSetColor == 1)
2845 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2847 if (aChangeSet->ToSetLineWidth == 1)
2849 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2851 if (aChangeSet->ToSetColor == -1
2852 || aChangeSet->ToSetLineWidth == -1)
2854 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2856 if (aChangeSet->ToSetMaxParamValue != 0)
2858 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2859 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2861 if (aChangeSet->ToSetSensitivity != 0)
2863 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2865 if (aChangeSet->ToSetShadingModel != 0)
2867 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2868 aCurColDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2874 aCtx->Display (aPrs, Standard_False);
2878 aCtx->Redisplay (aPrs, Standard_False);
2880 else if (!aColoredPrs.IsNull())
2882 aCtx->Redisplay (aColoredPrs, Standard_False);
2889 //==============================================================================
2890 //function : VDonly2
2892 //purpose : Display only a selected or named object
2893 // if there is no selected or named object s, nothing is done
2894 //==============================================================================
2895 static int VDonly2 (Draw_Interpretor& ,
2896 Standard_Integer theArgNb,
2897 const char** theArgVec)
2899 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2900 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2903 std::cerr << "Error: no active view!\n";
2907 Standard_DISABLE_DEPRECATION_WARNINGS
2908 if (aCtx->HasOpenedContext())
2910 aCtx->CloseLocalContext();
2912 Standard_ENABLE_DEPRECATION_WARNINGS
2914 Standard_Integer anArgIter = 1;
2915 for (; anArgIter < theArgNb; ++anArgIter)
2917 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2923 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2924 if (anArgIter >= theArgNb)
2926 // display only selected objects
2927 if (aCtx->NbSelected() < 1)
2932 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2934 aDispSet.Add (aCtx->SelectedInteractive());
2939 // display only specified objects
2940 for (; anArgIter < theArgNb; ++anArgIter)
2942 TCollection_AsciiString aName = theArgVec[anArgIter];
2943 if (GetMapOfAIS().IsBound2 (aName))
2945 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2946 if (!aShape.IsNull())
2948 aCtx->Display (aShape, Standard_False);
2949 aDispSet.Add (aShape);
2955 // weed out other objects
2956 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2958 if (aDispSet.Contains (anIter.Key1()))
2963 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2964 if (!aShape.IsNull())
2966 aCtx->Erase (aShape, Standard_False);
2972 //==============================================================================
2973 //function : VRemove
2974 //purpose : Removes selected or named objects.
2975 // If there is no selected or named objects,
2976 // all objects in the viewer can be removed with argument -all.
2977 // If -context is in arguments, the object is not deleted from the map of
2978 // objects (deleted only from the current context).
2979 //==============================================================================
2980 int VRemove (Draw_Interpretor& theDI,
2981 Standard_Integer theArgNb,
2982 const char** theArgVec)
2984 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2985 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2988 std::cerr << "Error: no active view!\n";
2992 Standard_Boolean isContextOnly = Standard_False;
2993 Standard_Boolean toRemoveAll = Standard_False;
2994 Standard_Boolean toPrintInfo = Standard_True;
2995 Standard_Boolean toRemoveLocal = Standard_False;
2997 Standard_Integer anArgIter = 1;
2998 for (; anArgIter < theArgNb; ++anArgIter)
3000 TCollection_AsciiString anArg = theArgVec[anArgIter];
3002 if (anArg == "-context")
3004 isContextOnly = Standard_True;
3006 else if (anArg == "-all")
3008 toRemoveAll = Standard_True;
3010 else if (anArg == "-noinfo")
3012 toPrintInfo = Standard_False;
3014 else if (anArg == "-local")
3016 toRemoveLocal = Standard_True;
3018 else if (anUpdateTool.parseRedrawMode (anArg))
3028 && anArgIter < theArgNb)
3030 std::cerr << "Error: wrong syntax!\n";
3034 Standard_DISABLE_DEPRECATION_WARNINGS
3035 if (toRemoveLocal && !aCtx->HasOpenedContext())
3037 std::cerr << "Error: local selection context is not open.\n";
3040 else if (!toRemoveLocal && aCtx->HasOpenedContext())
3042 aCtx->CloseAllContexts (Standard_False);
3044 Standard_ENABLE_DEPRECATION_WARNINGS
3046 NCollection_List<TCollection_AsciiString> anIONameList;
3049 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3050 anIter.More(); anIter.Next())
3052 anIONameList.Append (anIter.Key2());
3055 else if (anArgIter < theArgNb) // removed objects names are in argument list
3057 for (; anArgIter < theArgNb; ++anArgIter)
3059 TCollection_AsciiString aName = theArgVec[anArgIter];
3060 if (!GetMapOfAIS().IsBound2 (aName))
3062 theDI << aName.ToCString() << " was not bound to some object.\n";
3066 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3067 if (anIO->GetContext() != aCtx)
3069 theDI << aName.ToCString() << " was not displayed in current context.\n";
3070 theDI << "Please activate view with this object displayed and try again.\n";
3074 anIONameList.Append (aName);
3078 else if (aCtx->NbSelected() > 0)
3080 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3081 anIter.More(); anIter.Next())
3083 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3084 if (!aCtx->IsSelected (anIO))
3089 anIONameList.Append (anIter.Key2());
3094 // Unbind all removed objects from the map of displayed IO.
3095 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3096 anIter.More(); anIter.Next())
3098 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
3099 aCtx->Remove (anIO, Standard_False);
3102 theDI << anIter.Value().ToCString() << " was removed\n";
3106 GetMapOfAIS().UnBind2 (anIter.Value());
3110 // Close local context if it is empty
3111 TColStd_MapOfTransient aLocalIO;
3112 Standard_DISABLE_DEPRECATION_WARNINGS
3113 if (aCtx->HasOpenedContext()
3114 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
3116 aCtx->CloseAllContexts (Standard_False);
3118 Standard_ENABLE_DEPRECATION_WARNINGS
3123 //==============================================================================
3125 //purpose : Erase some selected or named objects
3126 // if there is no selected or named objects, the whole viewer is erased
3127 //==============================================================================
3128 int VErase (Draw_Interpretor& theDI,
3129 Standard_Integer theArgNb,
3130 const char** theArgVec)
3132 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3133 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3134 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3137 std::cerr << "Error: no active view!\n";
3141 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3143 Standard_Integer anArgIter = 1;
3144 Standard_Boolean toEraseLocal = Standard_False;
3145 Standard_Boolean toEraseInView = Standard_False;
3146 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3147 for (; anArgIter < theArgNb; ++anArgIter)
3149 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3150 anArgCase.LowerCase();
3151 if (anUpdateTool.parseRedrawMode (anArgCase))
3155 else if (anArgCase == "-local")
3157 toEraseLocal = Standard_True;
3159 else if (anArgCase == "-view"
3160 || anArgCase == "-inview")
3162 toEraseInView = Standard_True;
3166 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3170 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3172 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3176 Standard_DISABLE_DEPRECATION_WARNINGS
3177 if (toEraseLocal && !aCtx->HasOpenedContext())
3179 std::cerr << "Error: local selection context is not open.\n";
3182 else if (!toEraseLocal && aCtx->HasOpenedContext())
3184 aCtx->CloseAllContexts (Standard_False);
3186 Standard_ENABLE_DEPRECATION_WARNINGS
3188 if (!aNamesOfEraseIO.IsEmpty())
3190 // Erase named objects
3191 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
3193 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
3194 if (!GetMapOfAIS().IsBound2 (aName))
3199 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
3200 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
3201 theDI << aName.ToCString() << " ";
3206 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3210 aCtx->Erase (anIO, Standard_False);
3215 else if (!toEraseAll && aCtx->NbSelected() > 0)
3217 // Erase selected objects
3218 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
3219 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3220 anIter.More(); anIter.Next())
3222 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3224 && aCtx->IsSelected (anIO))
3226 theDI << anIter.Key2().ToCString() << " ";
3229 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3231 else if (aHasOpenedContext)
3233 aCtx->Erase (anIO, Standard_False);
3240 aCtx->EraseSelected (Standard_False);
3245 // Erase all objects
3246 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3247 anIter.More(); anIter.Next())
3249 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3254 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3258 aCtx->Erase (anIO, Standard_False);
3267 //==============================================================================
3268 //function : VDisplayAll
3269 //purpose : Display all the objects of the Map
3270 //==============================================================================
3271 static int VDisplayAll (Draw_Interpretor& ,
3272 Standard_Integer theArgNb,
3273 const char** theArgVec)
3276 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3277 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3280 std::cerr << "Error: no active view!\n";
3284 Standard_Integer anArgIter = 1;
3285 Standard_Boolean toDisplayLocal = Standard_False;
3286 for (; anArgIter < theArgNb; ++anArgIter)
3288 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3289 anArgCase.LowerCase();
3290 if (anArgCase == "-local")
3292 toDisplayLocal = Standard_True;
3294 else if (anUpdateTool.parseRedrawMode (anArgCase))
3303 if (anArgIter < theArgNb)
3305 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3309 Standard_DISABLE_DEPRECATION_WARNINGS
3310 if (toDisplayLocal && !aCtx->HasOpenedContext())
3312 std::cerr << "Error: local selection context is not open.\n";
3315 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3317 aCtx->CloseLocalContext (Standard_False);
3319 Standard_ENABLE_DEPRECATION_WARNINGS
3321 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3322 anIter.More(); anIter.Next())
3324 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3325 aCtx->Erase (aShape, Standard_False);
3328 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3329 anIter.More(); anIter.Next())
3331 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3332 aCtx->Display (aShape, Standard_False);
3337 //! Auxiliary method to check if presentation exists
3338 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3339 const Handle(AIS_InteractiveObject)& theIO,
3340 const Standard_Integer theMode)
3342 if (theIO.IsNull() || theCtx.IsNull())
3349 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3354 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3356 return theIO->DisplayMode();
3358 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3360 return theCtx->DisplayMode();
3366 enum ViewerTest_BndAction
3373 //! Auxiliary method to print bounding box of presentation
3374 inline void bndPresentation (Draw_Interpretor& theDI,
3375 const Handle(PrsMgr_PresentationManager)& theMgr,
3376 const Handle(AIS_InteractiveObject)& theObj,
3377 const Standard_Integer theDispMode,
3378 const TCollection_AsciiString& theName,
3379 const ViewerTest_BndAction theAction,
3380 const Handle(Prs3d_Drawer)& theStyle)
3384 case BndAction_Hide:
3386 theMgr->Unhighlight (theObj);
3389 case BndAction_Show:
3391 theMgr->Color (theObj, theStyle, theDispMode);
3394 case BndAction_Print:
3397 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3399 if (aPrsIter.Value().Mode() != theDispMode)
3402 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3404 gp_Pnt aMin = aBox.CornerMin();
3405 gp_Pnt aMax = aBox.CornerMax();
3406 theDI << theName << "\n"
3407 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3408 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
3414 //==============================================================================
3415 //function : VBounding
3417 //==============================================================================
3418 int VBounding (Draw_Interpretor& theDI,
3419 Standard_Integer theArgNb,
3420 const char** theArgVec)
3422 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3423 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3426 std::cout << "Error: no active view!\n";
3430 ViewerTest_BndAction anAction = BndAction_Show;
3431 Standard_Integer aMode = -1;
3433 Handle(Prs3d_Drawer) aStyle;
3435 Standard_Integer anArgIter = 1;
3436 for (; anArgIter < theArgNb; ++anArgIter)
3438 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3440 if (anArg == "-print")
3442 anAction = BndAction_Print;
3444 else if (anArg == "-show")
3446 anAction = BndAction_Show;
3448 else if (anArg == "-hide")
3450 anAction = BndAction_Hide;
3452 else if (anArg == "-mode")
3454 if (++anArgIter >= theArgNb)
3456 std::cout << "Error: wrong syntax at " << anArg << "\n";
3459 aMode = Draw::Atoi (theArgVec[anArgIter]);
3461 else if (!anUpdateTool.parseRedrawMode (anArg))
3467 if (anAction == BndAction_Show)
3469 aStyle = new Prs3d_Drawer();
3470 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3471 aStyle->SetColor (Quantity_NOC_GRAY99);
3474 Standard_Integer aHighlightedMode = -1;
3475 if (anArgIter < theArgNb)
3477 // has a list of names
3478 for (; anArgIter < theArgNb; ++anArgIter)
3480 TCollection_AsciiString aName = theArgVec[anArgIter];
3481 if (!GetMapOfAIS().IsBound2 (aName))
3483 std::cout << "Error: presentation " << aName << " does not exist\n";
3487 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3488 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3489 if (aHighlightedMode == -1)
3491 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3494 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3497 else if (aCtx->NbSelected() > 0)
3499 // remove all currently selected objects
3500 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3502 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3503 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3504 if (aHighlightedMode != -1)
3506 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3507 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3514 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3515 anIter.More(); anIter.Next())
3517 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3518 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3519 if (aHighlightedMode != -1)
3521 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3528 //==============================================================================
3529 //function : VTexture
3531 //==============================================================================
3532 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
3534 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3537 std::cout << "Error: no active view!\n";
3541 int toModulate = -1;
3542 bool toSetFilter = false;
3543 bool toSetAniso = false;
3544 bool toSetTrsfAngle = false;
3545 bool toSetTrsfTrans = false;
3546 bool toSetTrsfScale = false;
3547 Standard_ShortReal aTrsfRotAngle = 0.0f;
3548 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
3549 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
3550 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
3551 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
3553 Handle(AIS_Shape) aTexturedIO;
3554 Handle(Graphic3d_TextureSet) aTextureSetOld;
3555 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
3556 bool toSetGenRepeat = false;
3557 bool toSetGenScale = false;
3558 bool toSetGenOrigin = false;
3559 bool toSetImage = false;
3560 bool toComputeUV = false;
3562 const TCollection_AsciiString aCommandName (theArgVec[0]);
3563 bool toSetDefaults = aCommandName == "vtexdefault";
3565 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3566 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
3568 const TCollection_AsciiString aName = theArgVec[anArgIter];
3569 TCollection_AsciiString aNameCase = aName;
3570 aNameCase.LowerCase();
3571 if (anUpdateTool.parseRedrawMode (aName))
3575 else if (aTexturedIO.IsNull())
3577 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3578 if (aMapOfIO.IsBound2 (aName))
3580 aTexturedIO = Handle(AIS_Shape)::DownCast (aMapOfIO.Find2 (aName));
3582 if (aTexturedIO.IsNull())
3584 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
3588 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
3590 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
3593 else if (aNameCase == "-scale"
3594 || aNameCase == "-setscale"
3595 || aCommandName == "vtexscale")
3597 if (aCommandName != "vtexscale")
3601 if (anArgIter < theArgsNb)
3603 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3604 TCollection_AsciiString aValUCase = aValU;
3605 aValUCase.LowerCase();
3606 toSetGenScale = true;
3607 if (aValUCase == "off")
3609 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3612 else if (anArgIter + 1 < theArgsNb)
3614 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3615 if (aValU.IsRealValue()
3616 && aValV.IsRealValue())
3618 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3624 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3627 else if (aNameCase == "-origin"
3628 || aNameCase == "-setorigin"
3629 || aCommandName == "vtexorigin")
3631 if (aCommandName != "vtexorigin")
3635 if (anArgIter < theArgsNb)
3637 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3638 TCollection_AsciiString aValUCase = aValU;
3639 aValUCase.LowerCase();
3640 toSetGenOrigin = true;
3641 if (aValUCase == "off")
3643 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3646 else if (anArgIter + 1 < theArgsNb)
3648 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3649 if (aValU.IsRealValue()
3650 && aValV.IsRealValue())
3652 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3658 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3661 else if (aNameCase == "-repeat"
3662 || aNameCase == "-setrepeat"
3663 || aCommandName == "vtexrepeat")
3665 if (aCommandName != "vtexrepeat")
3669 if (anArgIter < theArgsNb)
3671 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3672 TCollection_AsciiString aValUCase = aValU;
3673 aValUCase.LowerCase();
3674 toSetGenRepeat = true;
3675 if (aValUCase == "off")
3677 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3680 else if (anArgIter + 1 < theArgsNb)
3682 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3683 if (aValU.IsRealValue()
3684 && aValV.IsRealValue())
3686 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3692 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3695 else if (aNameCase == "-modulate")
3697 bool toModulateBool = true;
3698 if (anArgIter + 1 < theArgsNb
3699 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
3703 toModulate = toModulateBool ? 1 : 0;
3705 else if ((aNameCase == "-setfilter"
3706 || aNameCase == "-filter")
3707 && anArgIter + 1 < theArgsNb)
3709 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3713 if (aValue == "nearest")
3715 aFilter = Graphic3d_TOTF_NEAREST;
3717 else if (aValue == "bilinear")
3719 aFilter = Graphic3d_TOTF_BILINEAR;
3721 else if (aValue == "trilinear")
3723 aFilter = Graphic3d_TOTF_TRILINEAR;
3727 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3731 else if ((aNameCase == "-setaniso"
3732 || aNameCase == "-setanisofilter"
3733 || aNameCase == "-aniso"
3734 || aNameCase == "-anisofilter")
3735 && anArgIter + 1 < theArgsNb)
3737 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3741 if (aValue == "off")
3743 anAnisoFilter = Graphic3d_LOTA_OFF;
3745 else if (aValue == "fast")
3747 anAnisoFilter = Graphic3d_LOTA_FAST;
3749 else if (aValue == "middle")
3751 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
3753 else if (aValue == "quality"
3754 || aValue == "high")
3756 anAnisoFilter = Graphic3d_LOTA_QUALITY;
3760 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3764 else if ((aNameCase == "-rotateangle"
3765 || aNameCase == "-rotangle"
3766 || aNameCase == "-rotate"
3767 || aNameCase == "-angle"
3768 || aNameCase == "-trsfangle")
3769 && anArgIter + 1 < theArgsNb)
3771 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3772 toSetTrsfAngle = true;
3775 else if ((aNameCase == "-trsftrans"
3776 || aNameCase == "-trsftranslate"
3777 || aNameCase == "-translate"
3778 || aNameCase == "-translation")
3779 && anArgIter + 2 < theArgsNb)
3781 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3782 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3783 toSetTrsfTrans = true;
3786 else if ((aNameCase == "-trsfscale")
3787 && anArgIter + 2 < theArgsNb)
3789 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3790 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3791 toSetTrsfScale = true;
3794 else if (aNameCase == "-default"
3795 || aNameCase == "-defaults")
3797 toSetDefaults = true;
3799 else if (aCommandName == "vtexture"
3800 && (aTextureVecNew.IsEmpty()
3801 || aNameCase.StartsWith ("-tex")))
3803 Standard_Integer aTexIndex = 0;
3804 TCollection_AsciiString aTexName = aName;
3805 if (aNameCase.StartsWith ("-tex"))
3807 if (anArgIter + 1 >= theArgsNb
3808 || aNameCase.Length() < 5)
3810 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3814 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
3815 if (!aTexIndexStr.IsIntegerValue())
3817 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3821 aTexIndex = aTexIndexStr.IntegerValue();
3822 aTexName = theArgVec[anArgIter + 1];
3825 if (aTexIndex >= Graphic3d_TextureUnit_NB
3826 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
3828 std::cout << "Error: too many textures specified\n";
3833 if (aTexName.IsIntegerValue())
3835 const Standard_Integer aValue = aTexName.IntegerValue();
3836 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
3838 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
3841 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
3843 else if (aTexName == "?")
3845 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3847 theDi << "\n Files in current directory : \n\n";
3848 theDi.Eval ("glob -nocomplain *");
3850 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3851 aCmnd += aTextureFolder;
3854 theDi << "Files in " << aTextureFolder << " : \n\n";
3855 theDi.Eval (aCmnd.ToCString());
3858 else if (aTexName != "off")
3860 if (!OSD_File (aTexName).Exists())
3862 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
3865 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
3869 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
3872 if (aTextureVecNew.Value (aTexIndex))
3874 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
3879 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3886 // check if new image set is equal to already set one
3887 Standard_Integer aNbChanged = 0;
3888 Handle(Graphic3d_TextureSet) aTextureSetNew;
3889 if (!aTextureVecNew.IsEmpty())
3891 aNbChanged = aTextureVecNew.Size();
3892 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
3893 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
3895 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
3896 Handle(Graphic3d_TextureRoot) aTextureOld;
3897 if (!aTextureSetOld.IsNull()
3898 && aTexIter < aTextureSetOld->Size())
3900 aTextureOld = aTextureSetOld->Value (aTexIter);
3903 if (!aTextureOld.IsNull()
3904 && !aTextureNew.IsNull())
3906 *aTextureNew->GetParams() = *aTextureOld->GetParams();
3907 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
3909 TCollection_AsciiString aFilePathOld, aFilePathNew;
3910 aTextureOld->Path().SystemName (aFilePathOld);
3911 aTextureNew->Path().SystemName (aFilePathNew);
3912 if (aTextureNew->Name() == anOldManualTex->Name()
3913 && aFilePathOld == aFilePathNew
3914 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
3917 aTextureNew = anOldManualTex;
3921 aTextureSetNew->SetValue (aTexIter, aTextureNew);
3925 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
3926 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
3928 aTextureSetNew = aTextureSetOld;
3931 if (!aTexturedIO->Attributes()->HasOwnShadingAspect())
3933 aTexturedIO->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
3934 *aTexturedIO->Attributes()->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
3937 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
3938 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
3939 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
3940 aTextureSetOld.Nullify();
3945 if (toModulate != -1)
3952 aFilter = Graphic3d_TOTF_BILINEAR;
3957 anAnisoFilter = Graphic3d_LOTA_OFF;
3959 if (!toSetTrsfAngle)
3961 toSetTrsfAngle = true;
3962 aTrsfRotAngle = 0.0f;
3964 if (!toSetTrsfTrans)
3966 toSetTrsfTrans = true;
3967 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
3969 if (!toSetTrsfScale)
3971 toSetTrsfScale = true;
3972 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
3976 if (aCommandName == "vtexture"
3979 if (!aTextureSetOld.IsNull())
3981 //toComputeUV = true; // we can keep UV vertex attributes
3982 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
3983 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
3984 aTextureSetOld.Nullify();
3988 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
3989 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
3991 if (toModulate != -1)
3993 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
3997 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
4001 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
4005 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
4009 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
4013 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
4017 // set default values if requested
4019 && (aCommandName == "vtexrepeat"
4022 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4023 toSetGenRepeat = true;
4026 && (aCommandName == "vtexorigin"
4029 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4030 toSetGenOrigin = true;
4033 && (aCommandName == "vtexscale"
4036 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4037 toSetGenScale = true;
4040 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
4042 aTexturedIO->SetToUpdate (AIS_Shaded);
4045 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
4046 || aCtx->DisplayMode() != AIS_Shaded)
4048 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
4052 aCtx->Display (aTexturedIO, false);
4053 aTexturedIO->SynchronizeAspects();
4057 //! Auxiliary method to parse transformation persistence flags
4058 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
4059 Graphic3d_TransModeFlags& theFlags)
4061 if (theFlagString == "zoom")
4063 theFlags = Graphic3d_TMF_ZoomPers;
4065 else if (theFlagString == "rotate")
4067 theFlags = Graphic3d_TMF_RotatePers;
4069 else if (theFlagString == "zoomrotate")
4071 theFlags = Graphic3d_TMF_ZoomRotatePers;
4073 else if (theFlagString == "trihedron"
4074 || theFlagString == "triedron")
4076 theFlags = Graphic3d_TMF_TriedronPers;
4078 else if (theFlagString == "none")
4080 theFlags = Graphic3d_TMF_None;
4084 return Standard_False;
4087 return Standard_True;
4090 //! Auxiliary method to parse transformation persistence flags
4091 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4092 Aspect_TypeOfTriedronPosition& theCorner)
4094 TCollection_AsciiString aString (theString);
4095 aString.LowerCase();
4096 if (aString == "center")
4098 theCorner = Aspect_TOTP_CENTER;
4100 else if (aString == "top"
4101 || aString == "upper")
4103 theCorner = Aspect_TOTP_TOP;
4105 else if (aString == "bottom"
4106 || aString == "lower")
4108 theCorner = Aspect_TOTP_BOTTOM;
4110 else if (aString == "left")
4112 theCorner = Aspect_TOTP_LEFT;
4114 else if (aString == "right")
4116 theCorner = Aspect_TOTP_RIGHT;
4118 else if (aString == "topleft"
4119 || aString == "leftupper"
4120 || aString == "upperleft")
4122 theCorner = Aspect_TOTP_LEFT_UPPER;
4124 else if (aString == "bottomleft"
4125 || aString == "leftlower"
4126 || aString == "lowerleft")
4128 theCorner = Aspect_TOTP_LEFT_LOWER;
4130 else if (aString == "topright"
4131 || aString == "rightupper"
4132 || aString == "upperright")
4134 theCorner = Aspect_TOTP_RIGHT_UPPER;
4136 else if (aString == "bottomright"
4137 || aString == "lowerright"
4138 || aString == "rightlower")
4140 theCorner = Aspect_TOTP_RIGHT_LOWER;
4144 return Standard_False;
4147 return Standard_True;
4150 //==============================================================================
4151 //function : VDisplay2
4153 //purpose : Display an object from its name
4154 //==============================================================================
4155 static int VDisplay2 (Draw_Interpretor& theDI,
4156 Standard_Integer theArgNb,
4157 const char** theArgVec)
4161 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4165 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4168 ViewerTest::ViewerInit();
4169 aCtx = ViewerTest::GetAISContext();
4172 // Parse input arguments
4173 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4174 Standard_Integer isMutable = -1;
4175 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4176 Standard_Boolean toDisplayLocal = Standard_False;
4177 Standard_Boolean toReDisplay = Standard_False;
4178 Standard_Integer isSelectable = -1;
4179 Standard_Integer anObjDispMode = -2;
4180 Standard_Integer anObjHighMode = -2;
4181 Standard_Boolean toSetTrsfPers = Standard_False;
4182 Handle(Graphic3d_TransformPers) aTrsfPers;
4183 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4184 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4185 Standard_Integer toDisplayInView = Standard_False;
4186 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4188 const TCollection_AsciiString aName = theArgVec[anArgIter];
4189 TCollection_AsciiString aNameCase = aName;
4190 aNameCase.LowerCase();
4191 if (anUpdateTool.parseRedrawMode (aName))
4195 else if (aNameCase == "-mutable")
4199 else if (aNameCase == "-neutral")
4201 aDispStatus = AIS_DS_Displayed;
4203 else if (aNameCase == "-immediate"
4204 || aNameCase == "-top")
4206 aZLayer = Graphic3d_ZLayerId_Top;
4208 else if (aNameCase == "-topmost")
4210 aZLayer = Graphic3d_ZLayerId_Topmost;
4212 else if (aNameCase == "-osd"
4213 || aNameCase == "-toposd"
4214 || aNameCase == "-overlay")
4216 aZLayer = Graphic3d_ZLayerId_TopOSD;
4218 else if (aNameCase == "-botosd"
4219 || aNameCase == "-underlay")
4221 aZLayer = Graphic3d_ZLayerId_BotOSD;
4223 else if (aNameCase == "-select"
4224 || aNameCase == "-selectable")
4228 else if (aNameCase == "-noselect"
4229 || aNameCase == "-noselection")
4233 else if (aNameCase == "-dispmode"
4234 || aNameCase == "-displaymode")
4236 if (++anArgIter >= theArgNb)
4238 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4242 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4244 else if (aNameCase == "-highmode"
4245 || aNameCase == "-highlightmode")
4247 if (++anArgIter >= theArgNb)
4249 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4253 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4255 else if (aNameCase == "-3d")
4257 toSetTrsfPers = Standard_True;
4258 aTrsfPers.Nullify();
4260 else if (aNameCase == "-2d"
4261 || aNameCase == "-trihedron"
4262 || aNameCase == "-triedron")
4264 toSetTrsfPers = Standard_True;
4265 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4267 if (anArgIter + 1 < theArgNb)
4269 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4270 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4273 aTrsfPers->SetCorner2d (aCorner);
4275 if (anArgIter + 2 < theArgNb)
4277 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4278 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4279 if (anX.IsIntegerValue()
4280 && anY.IsIntegerValue())
4283 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4289 else if (aNameCase == "-trsfpers"
4290 || aNameCase == "-pers")
4292 if (++anArgIter >= theArgNb
4293 || !aTrsfPers.IsNull())
4295 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4299 toSetTrsfPers = Standard_True;
4300 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4301 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4302 aPersFlags.LowerCase();
4303 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
4305 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
4309 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4311 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4313 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4315 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
4318 else if (aNameCase == "-trsfperspos"
4319 || aNameCase == "-perspos")
4321 if (anArgIter + 2 >= theArgNb
4322 || aTrsfPers.IsNull())
4324 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4328 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4329 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4330 TCollection_AsciiString aZ = "0";
4331 if (!aX.IsRealValue()
4332 || !aY.IsRealValue())
4334 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4337 if (anArgIter + 1 < theArgNb)
4339 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
4340 if (aTemp.IsRealValue())
4347 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
4348 if (aTrsfPers->IsZoomOrRotate())
4350 aTrsfPers->SetAnchorPoint (aPnt);
4352 else if (aTrsfPers->IsTrihedronOr2d())
4354 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
4357 else if (aNameCase == "-layer")
4359 if (++anArgIter >= theArgNb)
4361 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4365 TCollection_AsciiString aValue (theArgVec[anArgIter]);
4366 if (!aValue.IsIntegerValue())
4368 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4372 aZLayer = aValue.IntegerValue();
4374 else if (aNameCase == "-view"
4375 || aNameCase == "-inview")
4377 toDisplayInView = Standard_True;
4379 else if (aNameCase == "-local")
4381 aDispStatus = AIS_DS_Temporary;
4382 toDisplayLocal = Standard_True;
4384 else if (aNameCase == "-redisplay")
4386 toReDisplay = Standard_True;
4388 else if (aNameCase == "-erased"
4389 || aNameCase == "-load")
4391 aDispStatus = AIS_DS_Erased;
4395 aNamesOfDisplayIO.Append (aName);
4399 if (aNamesOfDisplayIO.IsEmpty())
4401 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4405 // Prepare context for display
4406 Standard_DISABLE_DEPRECATION_WARNINGS
4407 if (toDisplayLocal && !aCtx->HasOpenedContext())
4409 aCtx->OpenLocalContext (Standard_False);
4411 else if (!toDisplayLocal && aCtx->HasOpenedContext())
4413 aCtx->CloseAllContexts (Standard_False);
4415 Standard_ENABLE_DEPRECATION_WARNINGS
4417 // Display interactive objects
4418 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
4420 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
4422 if (!GetMapOfAIS().IsBound2 (aName))
4424 // create the AIS_Shape from a name
4425 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
4426 if (!aShape.IsNull())
4428 if (isMutable != -1)
4430 aShape->SetMutable (isMutable == 1);
4432 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4434 aShape->SetZLayer (aZLayer);
4438 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4440 if (anObjDispMode != -2)
4442 aShape->SetDisplayMode (anObjDispMode);
4444 if (anObjHighMode != -2)
4446 aShape->SetHilightMode (anObjHighMode);
4448 if (!toDisplayLocal)
4449 GetMapOfAIS().Bind (aShape, aName);
4451 Standard_Integer aDispMode = aShape->HasDisplayMode()
4452 ? aShape->DisplayMode()
4453 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4454 ? aCtx->DisplayMode()
4456 Standard_Integer aSelMode = -1;
4457 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4459 aSelMode = aShape->GlobalSelectionMode();
4462 aCtx->Display (aShape, aDispMode, aSelMode,
4463 Standard_False, aShape->AcceptShapeDecomposition(),
4465 if (toDisplayInView)
4467 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
4469 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
4471 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4476 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
4481 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
4482 if (isMutable != -1)
4484 aShape->SetMutable (isMutable == 1);
4486 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4488 aShape->SetZLayer (aZLayer);
4492 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4494 if (anObjDispMode != -2)
4496 aShape->SetDisplayMode (anObjDispMode);
4498 if (anObjHighMode != -2)
4500 aShape->SetHilightMode (anObjHighMode);
4502 Standard_Integer aDispMode = aShape->HasDisplayMode()
4503 ? aShape->DisplayMode()
4504 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4505 ? aCtx->DisplayMode()
4507 Standard_Integer aSelMode = -1;
4508 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4510 aSelMode = aShape->GlobalSelectionMode();
4513 if (aShape->Type() == AIS_KOI_Datum)
4515 aCtx->Display (aShape, Standard_False);
4519 theDI << "Display " << aName.ToCString() << "\n";
4521 // update the Shape in the AIS_Shape
4522 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
4523 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
4524 if (!aShapePrs.IsNull())
4526 if (!aShapePrs->Shape().IsEqual (aNewShape))
4528 toReDisplay = Standard_True;
4530 aShapePrs->Set (aNewShape);
4534 aCtx->Redisplay (aShape, Standard_False);
4539 aCtx->Erase (aShape, Standard_False);
4541 aCtx->Display (aShape, aDispMode, aSelMode,
4542 Standard_False, aShape->AcceptShapeDecomposition(),
4544 if (toDisplayInView)
4546 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4554 //=======================================================================
4555 //function : VNbDisplayed
4556 //purpose : Returns number of displayed objects
4557 //=======================================================================
4558 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
4559 Standard_Integer theArgsNb,
4560 const char** theArgVec)
4564 theDi << "Usage : " << theArgVec[0] << "\n";
4568 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4569 if (aContextAIS.IsNull())
4571 std::cout << theArgVec[0] << "AIS context is not available.\n";
4575 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4576 if(aContext.IsNull())
4578 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
4582 AIS_ListOfInteractive aListOfIO;
4583 aContextAIS->DisplayedObjects(aListOfIO, false);
4585 theDi << aListOfIO.Extent() << "\n";
4589 //===============================================================================================
4590 //function : VUpdate
4592 //===============================================================================================
4593 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
4595 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4596 if (aContextAIS.IsNull())
4598 std::cout << theArgVec[0] << "AIS context is not available.\n";
4604 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
4608 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
4610 AIS_ListOfInteractive aListOfIO;
4612 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4614 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
4616 Handle(AIS_InteractiveObject) anAISObj;
4617 if (anAISMap.IsBound2 (aName))
4619 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
4622 if (anAISObj.IsNull())
4624 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
4628 aListOfIO.Append (anAISObj);
4631 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
4632 for (; anIOIt.More(); anIOIt.Next())
4634 aContextAIS->Update (anIOIt.Value(), Standard_False);
4637 aContextAIS->UpdateCurrentViewer();
4642 //==============================================================================
4643 //function : VShading
4644 //purpose : Sharpen or roughten the quality of the shading
4645 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4646 //==============================================================================
4647 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4649 Standard_Real myDevCoef;
4650 Handle(AIS_InteractiveObject) TheAisIO;
4653 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4657 myDevCoef =Draw::Atof(argv[2]);
4660 TCollection_AsciiString name=argv[1];
4661 if (GetMapOfAIS().IsBound2(name ))
4662 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4663 if (TheAisIO.IsNull())
4664 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4667 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4669 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4671 TheAISContext()->Redisplay (TheAisIO, Standard_True);
4675 //! Auxiliary method to print Interactive Object information
4676 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4677 const Handle(Standard_Transient)& theObject,
4678 Draw_Interpretor& theDI)
4680 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4683 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4687 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4688 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4689 << (theDetected.Contains (anObj) ? " Detected" : " ")
4691 if (anObj->Type() == AIS_KOI_Datum)
4694 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4695 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4696 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4697 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4698 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4699 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4700 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4703 else if (anObj->Type() == AIS_KOI_Shape
4704 && anObj->Signature() == 0)
4706 theDI << " AIS_Shape";
4708 else if (anObj->Type() == AIS_KOI_Relation)
4710 // AIS_Dimention and AIS_Relation
4711 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4712 switch (aRelation->KindOfDimension())
4714 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4715 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4716 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4717 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4718 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4719 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4720 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4721 default: theDI << " UNKNOWN dimension"; break;
4726 theDI << " UserPrs";
4728 theDI << " (" << theObject->DynamicType()->Name() << ")";
4731 //! Print information about locally selected sub-shapes
4732 template <typename T>
4733 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4735 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4736 TCollection_AsciiString aPrevName;
4737 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4739 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4740 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4741 if (aShapeIO.IsNull() || anOwner.IsNull())
4745 if (anOwner == aShapeIO->GlobalSelOwner())
4748 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4749 if (aSubShape.IsNull()
4750 || aShapeIO.IsNull()
4751 || !GetMapOfAIS().IsBound1 (aShapeIO))
4756 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4757 TopTools_MapOfShape aFilter;
4758 Standard_Integer aNumber = 0;
4759 const TopoDS_Shape aShape = aShapeIO->Shape();
4760 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4761 anIter.More(); anIter.Next())
4763 if (!aFilter.Add (anIter.Current()))
4765 continue; // filter duplicates
4769 if (!anIter.Current().IsSame (aSubShape))
4774 Standard_CString aShapeName = NULL;
4775 switch (aSubShape.ShapeType())
4777 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4778 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4779 case TopAbs_SOLID: aShapeName = " Solid"; break;
4780 case TopAbs_SHELL: aShapeName = " Shell"; break;
4781 case TopAbs_FACE: aShapeName = " Face"; break;
4782 case TopAbs_WIRE: aShapeName = " Wire"; break;
4783 case TopAbs_EDGE: aShapeName = " Edge"; break;
4784 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4786 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4789 if (aParentName != aPrevName)
4791 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4792 aPrevName = aParentName;
4794 theDI << " " << aShapeName << " #" << aNumber << "\n";
4800 //==============================================================================
4803 //==============================================================================
4804 static Standard_Integer VState (Draw_Interpretor& theDI,
4805 Standard_Integer theArgNb,
4806 Standard_CString* theArgVec)
4808 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4811 std::cerr << "Error: No opened viewer!\n";
4815 Standard_Boolean toPrintEntities = Standard_False;
4816 Standard_Boolean toCheckSelected = Standard_False;
4818 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4820 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4821 anOption.LowerCase();
4822 if (anOption == "-detectedentities"
4823 || anOption == "-entities")
4825 toPrintEntities = Standard_True;
4827 else if (anOption == "-hasselected")
4829 toCheckSelected = Standard_True;
4833 if (toCheckSelected)
4835 aCtx->InitSelected();
4836 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4837 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4842 if (toPrintEntities)
4844 theDI << "Detected entities:\n";
4845 Standard_DISABLE_DEPRECATION_WARNINGS
4846 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4847 Standard_ENABLE_DEPRECATION_WARNINGS
4848 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4849 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4851 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4852 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4853 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4854 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4855 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4856 aName.LeftJustify (20, ' ');
4857 char anInfoStr[512];
4859 " Depth: %g Distance: %g Point: %g %g %g",
4862 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4863 theDI << " " << aName
4865 << " (" << anEntity->DynamicType()->Name() << ")"
4868 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4869 if (!aBRepOwner.IsNull())
4871 theDI << " Detected Shape: "
4872 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4876 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4877 if (!aWire.IsNull())
4879 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4880 theDI << " Detected Child: "
4881 << aSen->DynamicType()->Name()
4885 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4886 if (!aPrimArr.IsNull())
4888 theDI << " Detected Element: "
4889 << aPrimArr->LastDetectedElement()
4896 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4897 Standard_DISABLE_DEPRECATION_WARNINGS
4898 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4900 aDetected.Add (aCtx->DetectedCurrentObject());
4902 Standard_ENABLE_DEPRECATION_WARNINGS
4904 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4908 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4910 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4911 if (!GetMapOfAIS().IsBound2 (anObjName))
4913 theDI << anObjName << " doesn't exist!\n";
4917 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4918 TCollection_AsciiString aName = anObjName;
4919 aName.LeftJustify (20, ' ');
4920 theDI << " " << aName << " ";
4921 objInfo (aDetected, anObjTrans, theDI);
4927 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4929 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4930 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4932 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4933 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4934 // handle whole object selection
4935 if (anOwner == anObj->GlobalSelOwner())
4937 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4938 aName.LeftJustify (20, ' ');
4939 theDI << aName << " ";
4940 objInfo (aDetected, anObj, theDI);
4945 // process selected sub-shapes
4946 printLocalSelectionInfo (aCtx, theDI);
4951 theDI << "Neutral-point state:\n";
4952 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4953 anObjIter.More(); anObjIter.Next())
4955 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4961 TCollection_AsciiString aName = anObjIter.Key2();
4962 aName.LeftJustify (20, ' ');
4963 theDI << " " << aName << " ";
4964 objInfo (aDetected, anObj, theDI);
4967 printLocalSelectionInfo (aCtx, theDI);
4968 Standard_DISABLE_DEPRECATION_WARNINGS
4969 if (aCtx->HasOpenedContext())
4970 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
4971 Standard_ENABLE_DEPRECATION_WARNINGS
4975 //=======================================================================
4976 //function : PickShape
4977 //purpose : First Activate the rightmode + Put Filters to be able to
4978 // pick objets that are of type <TheType>...
4979 //=======================================================================
4981 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
4982 const Standard_Integer theMaxPick)
4984 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
4985 PickShapes (theShapeType, aResArray, theMaxPick);
4986 return aResArray->First();
4989 //=======================================================================
4990 //function : PickShapes
4992 //=======================================================================
4993 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
4994 Handle(TopTools_HArray1OfShape)& theResArray,
4995 const Standard_Integer theMaxPick)
4997 const Standard_Integer aNbToReach = theResArray->Length();
5000 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
5003 // step 1: prepare the data
5004 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5005 aCtx->RemoveFilters();
5006 AIS_ListOfInteractive aDispObjects;
5007 aCtx->DisplayedObjects (aDispObjects);
5008 if (theShapeType == TopAbs_SHAPE)
5010 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
5014 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
5017 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
5018 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5020 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5022 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5026 // step 2 : wait for the selection...
5027 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
5028 Standard_Integer argccc = 5;
5029 const char *bufff[] = { "A", "B", "C", "D", "E" };
5030 const char **argvvv = (const char** )bufff;
5031 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
5033 while (ViewerMainLoop (argccc, argvvv)) {}
5034 Standard_Integer aNbStored = aCtx->NbSelected();
5035 if (aNbStored != aNbPickGood)
5037 aNbPickGood = aNbStored;
5043 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
5046 // step3 get result.
5047 if (aNbPickFail >= aNbToReach)
5049 return Standard_False;
5052 Standard_Integer anIndex = theResArray->Lower();
5053 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
5055 if (aCtx->HasSelectedShape())
5057 theResArray->SetValue (anIndex, aCtx->SelectedShape());
5061 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
5062 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
5066 aCtx->RemoveFilters();
5067 if (theShapeType != TopAbs_SHAPE)
5069 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5071 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5073 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5077 return Standard_True;
5080 //=======================================================================
5081 //function : VPickShape
5083 //=======================================================================
5084 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5086 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
5089 TCollection_AsciiString aShapeArg (argv[1]);
5090 aShapeArg.LowerCase();
5091 aShapeType = TopAbs_COMPOUND;
5092 if (aShapeArg == "v"
5093 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
5094 else if (aShapeArg == "e"
5095 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
5096 else if (aShapeArg == "w"
5097 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
5098 else if (aShapeArg == "f"
5099 || aShapeArg == "face") aShapeType = TopAbs_FACE;
5100 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
5101 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
5102 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
5105 std::cout << "Syntax error at '" << argv[1] << "'\n";
5110 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5111 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
5113 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
5116 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
5117 if (aPickedShape.IsNull())
5122 TCollection_AsciiString aName;
5129 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5130 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5133 DBRep::Set (aName.ToCString(), aPickedShape);
5134 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5135 ViewerTest::Display (aName, aShapePrs, false, true);
5136 di << "Name of picked shape: " << aName <<"\n";
5140 TCollection_AsciiString aName (argv[2]);
5142 const Standard_Boolean isAutoNaming = aName == ".";
5143 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5144 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5146 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5148 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5150 if (!aPickedShape.IsNull()
5153 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5154 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5158 aName = argv[1 + aPickedIter];
5161 DBRep::Set (aName.ToCString(), aPickedShape);
5162 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5163 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5164 ViewerTest::Display (aName, aShapePrs, false, true);
5168 TheAISContext()->UpdateCurrentViewer();
5172 //=======================================================================
5173 //function : VSelFilter
5175 //=======================================================================
5176 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5177 const char** theArgv)
5179 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5180 if (aContext.IsNull())
5182 std::cout << "Error: AIS context is not available.\n";
5186 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5188 TCollection_AsciiString anArg (theArgv[anArgIter]);
5190 if (anArg == "-clear")
5192 aContext->RemoveFilters();
5194 else if (anArg == "-type"
5195 && anArgIter + 1 < theArgc)
5197 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5198 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5199 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5201 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5205 Handle(SelectMgr_Filter) aFilter;
5206 if (aShapeType == TopAbs_SHAPE)
5208 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5212 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5214 aContext->AddFilter (aFilter);
5218 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5225 //=======================================================================
5226 //function : VPickSelected
5228 //=======================================================================
5229 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5231 static Standard_Integer aCount = 0;
5232 TCollection_AsciiString aName = "PickedShape_";
5240 aName = aName + aCount++ + "_";
5243 Standard_Integer anIdx = 0;
5244 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5246 TopoDS_Shape aShape;
5247 if (TheAISContext()->HasSelectedShape())
5249 aShape = TheAISContext()->SelectedShape();
5253 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5254 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5257 TCollection_AsciiString aCurrentName = aName;
5260 aCurrentName += anIdx;
5263 DBRep::Set ((aCurrentName).ToCString(), aShape);
5265 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5266 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5267 TheAISContext()->Display (aNewShape, Standard_False);
5270 TheAISContext()->UpdateCurrentViewer();
5275 //=======================================================================
5276 //function : list of known objects
5278 //=======================================================================
5279 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5281 // 1234567890 12345678901234567 123456789
5282 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5283 TCollection_AsciiString BlankLine(64,'_');
5284 Standard_Integer i ;
5286 di<<"/n"<<BlankLine.ToCString()<<"\n";
5289 Colum[i].Center(20,' ');
5291 di<<"|"<<Colum[i].ToCString();
5294 di<<BlankLine.ToCString()<<"\n";
5296 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5297 const char ** names = GetTypeNames();
5299 TCollection_AsciiString curstring;
5300 TCollection_AsciiString curcolum[3];
5303 // les objets de type Datum..
5304 curcolum[1]+="Datum";
5306 curcolum[0].Clear();
5307 curcolum[0] += names[i];
5309 curcolum[2].Clear();
5310 curcolum[2]+=TCollection_AsciiString(i+1);
5312 for(Standard_Integer j =0;j<=2;j++){
5313 curcolum[j].Center(20,' ');
5314 di<<"|"<<curcolum[j].ToCString();
5318 di<<BlankLine.ToCString()<<"\n";
5320 // les objets de type shape
5321 curcolum[1].Clear();
5322 curcolum[1]+="Shape";
5323 curcolum[1].Center(20,' ');
5326 curcolum[0].Clear();
5327 curcolum[0] += names[7+i];
5328 curcolum[2].Clear();
5329 curcolum[2]+=TCollection_AsciiString(i);
5331 for(Standard_Integer j =0;j<=2;j++){
5332 curcolum[j].Center(20,' ');
5333 di<<"|"<<curcolum[j].ToCString();
5337 di<<BlankLine.ToCString()<<"\n";
5338 // les IO de type objet...
5339 curcolum[1].Clear();
5340 curcolum[1]+="Object";
5341 curcolum[1].Center(20,' ');
5343 curcolum[0].Clear();
5344 curcolum[0] += names[10+i];
5345 curcolum[2].Clear();
5346 curcolum[2]+=TCollection_AsciiString(i);
5348 for(Standard_Integer j =0;j<=2;j++){
5349 curcolum[j].Center(20,' ');
5350 di<<"|"<<curcolum[j].ToCString();
5354 di<<BlankLine.ToCString()<<"\n";
5355 // les contraintes et dimensions.
5356 // pour l'instant on separe juste contraintes et dimensions...
5357 // plus tard, on detaillera toutes les sortes...
5358 curcolum[1].Clear();
5359 curcolum[1]+="Relation";
5360 curcolum[1].Center(20,' ');
5362 curcolum[0].Clear();
5363 curcolum[0] += names[12+i];
5364 curcolum[2].Clear();
5365 curcolum[2]+=TCollection_AsciiString(i);
5367 for(Standard_Integer j =0;j<=2;j++){
5368 curcolum[j].Center(20,' ');
5369 di<<"|"<<curcolum[j].ToCString();
5373 di<<BlankLine.ToCString()<<"\n";
5380 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5382 if(argc!=2) return 1;
5384 AIS_KindOfInteractive TheType;
5385 Standard_Integer TheSign(-1);
5386 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5389 AIS_ListOfInteractive LIO;
5391 // en attendant l'amelioration ais pour les dimensions...
5393 Standard_Integer dimension_status(-1);
5394 if(TheType==AIS_KOI_Relation){
5395 dimension_status = TheSign ==1 ? 1 : 0;
5399 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5400 Handle(AIS_InteractiveObject) curio;
5401 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5404 if(dimension_status == -1)
5405 TheAISContext()->Erase(curio,Standard_False);
5407 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5408 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5409 (dimension_status==1 && KOD != AIS_KOD_NONE))
5410 TheAISContext()->Erase(curio,Standard_False);
5413 TheAISContext()->UpdateCurrentViewer();
5416 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5418 if(argc!=2) return 1;
5420 AIS_KindOfInteractive TheType;
5421 Standard_Integer TheSign(-1);
5422 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5424 // en attendant l'amelioration ais pour les dimensions...
5426 Standard_Integer dimension_status(-1);
5427 if(TheType==AIS_KOI_Relation){
5428 dimension_status = TheSign ==1 ? 1 : 0;
5432 AIS_ListOfInteractive LIO;
5433 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5434 Handle(AIS_InteractiveObject) curio;
5435 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5437 if(dimension_status == -1)
5438 TheAISContext()->Display(curio,Standard_False);
5440 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5441 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5442 (dimension_status==1 && KOD != AIS_KOD_NONE))
5443 TheAISContext()->Display(curio,Standard_False);
5448 TheAISContext()->UpdateCurrentViewer();
5452 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5455 BRep_Builder builder;
5457 BRepTools::Read(shape, s, builder);
5458 DBRep::Set(a[1], shape);
5459 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5460 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5461 Ctx->Display (ais, Standard_True);
5465 //===============================================================================================
5468 //===============================================================================================
5469 static int VBsdf (Draw_Interpretor& theDI,
5470 Standard_Integer theArgsNb,
5471 const char** theArgVec)
5473 Handle(V3d_View) aView = ViewerTest::CurrentView();
5474 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5476 || aViewer.IsNull())
5478 std::cerr << "No active viewer!\n";
5482 ViewerTest_CmdParser aCmd;
5484 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5486 aCmd.AddOption ("print|echo|p", "Prints BSDF");
5488 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
5490 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
5491 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
5492 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
5493 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
5494 aCmd.AddOption ("le", "Radiance emitted by surface");
5496 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5497 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5499 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
5500 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
5502 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
5503 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
5505 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
5507 aCmd.Parse (theArgsNb, theArgVec);
5509 if (aCmd.HasOption ("help"))
5511 theDI.PrintHelp (theArgVec[0]);
5515 // check viewer update mode
5516 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
5518 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5520 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5526 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5529 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5530 if (!aMap.IsBound2 (aName) )
5532 std::cerr << "Use 'vdisplay' before\n";
5536 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5537 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5538 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5540 if (aCmd.HasOption ("print"))
5543 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
5544 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5545 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5546 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5547 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
5549 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5551 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
5552 : aBSDF.FresnelBase.Serialize();
5554 theDI << (aLayerID < 1 ? "Coat Fresnel: "
5555 : "Base Fresnel: ");
5557 if (aFresnel.x() >= 0.f)
5559 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
5560 << "G = " << aFresnel.g() << ", "
5561 << "B = " << aFresnel.b() << "\n";
5563 else if (aFresnel.x() >= -1.5f)
5565 theDI << "Constant " << aFresnel.z() << "\n";
5567 else if (aFresnel.x() >= -2.5f)
5569 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
5570 << "K = " << aFresnel.z() << "\n";
5574 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
5578 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
5579 << "Base roughness: " << aBSDF.Ks.w() << "\n"
5580 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
5581 << "Absorption color: " << aBSDF.Absorption.r() << ", "
5582 << aBSDF.Absorption.g() << ", "
5583 << aBSDF.Absorption.b() << "\n";
5588 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
5590 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
5593 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
5595 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
5598 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5600 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
5603 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5605 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
5607 aBSDF.Absorption.r() = aRGB.r();
5608 aBSDF.Absorption.g() = aRGB.g();
5609 aBSDF.Absorption.b() = aRGB.b();
5612 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
5616 if (aCmd.HasOption ("kc", 3))
5618 aKc = aCmd.ArgVec3f ("kc");
5622 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
5625 aBSDF.Kc.r() = aKc.r();
5626 aBSDF.Kc.g() = aKc.g();
5627 aBSDF.Kc.b() = aKc.b();
5630 if (aCmd.HasOption ("kd", 3))
5632 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5634 else if (aCmd.HasOption ("kd", 1, Standard_True))
5636 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5639 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
5643 if (aCmd.HasOption ("ks", 3))
5645 aKs = aCmd.ArgVec3f ("ks");
5649 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5652 aBSDF.Ks.r() = aKs.r();
5653 aBSDF.Ks.g() = aKs.g();
5654 aBSDF.Ks.b() = aKs.b();
5657 if (aCmd.HasOption ("kt", 3))
5659 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5661 else if (aCmd.HasOption ("kt", 1, Standard_True))
5663 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5666 if (aCmd.HasOption ("le", 3))
5668 aBSDF.Le = aCmd.ArgVec3f ("le");
5670 else if (aCmd.HasOption ("le", 1, Standard_True))
5672 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5675 const std::string aFresnelErrorMessage =
5676 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
5678 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5680 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
5683 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
5685 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5686 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5688 if (aFresnelType == "schlick")
5690 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
5691 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
5692 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
5694 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
5695 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
5696 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
5698 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
5702 theDI << aFresnelErrorMessage.c_str() << "\n";
5705 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
5707 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5708 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5710 if (aFresnelType == "conductor")
5712 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5713 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
5715 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
5719 theDI << aFresnelErrorMessage.c_str() << "\n";
5722 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
5724 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5725 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5727 if (aFresnelType == "constant")
5729 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5731 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
5733 else if (aFresnelType == "dielectric")
5735 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5737 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
5741 theDI << aFresnelErrorMessage.c_str() << "\n";
5746 if (aCmd.HasOption ("normalize"))
5751 aMaterial.SetBSDF (aBSDF);
5752 anIObj->SetMaterial (aMaterial);
5757 //==============================================================================
5758 //function : VLoadSelection
5759 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5760 //==============================================================================
5761 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5762 Standard_Integer theArgNb,
5763 const char** theArgVec)
5767 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5771 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5774 ViewerTest::ViewerInit();
5775 aCtx = ViewerTest::GetAISContext();
5778 // Parse input arguments
5779 TColStd_SequenceOfAsciiString aNamesOfIO;
5780 Standard_Boolean isLocal = Standard_False;
5781 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5783 const TCollection_AsciiString aName = theArgVec[anArgIter];
5784 TCollection_AsciiString aNameCase = aName;
5785 aNameCase.LowerCase();
5786 if (aNameCase == "-local")
5788 isLocal = Standard_True;
5792 aNamesOfIO.Append (aName);
5796 if (aNamesOfIO.IsEmpty())
5798 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5803 Standard_DISABLE_DEPRECATION_WARNINGS
5804 if (isLocal && !aCtx->HasOpenedContext())
5806 aCtx->OpenLocalContext (Standard_False);
5808 else if (!isLocal && aCtx->HasOpenedContext())
5810 aCtx->CloseAllContexts (Standard_False);
5812 Standard_ENABLE_DEPRECATION_WARNINGS
5814 // Load selection of interactive objects
5815 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5817 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5819 Handle(AIS_InteractiveObject) aShape;
5820 if (GetMapOfAIS().IsBound2 (aName))
5821 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5823 aShape = GetAISShapeFromName (aName.ToCString());
5825 if (!aShape.IsNull())
5827 if (!GetMapOfAIS().IsBound2 (aName))
5829 GetMapOfAIS().Bind (aShape, aName);
5832 aCtx->Load (aShape, -1, Standard_False);
5833 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5840 //==============================================================================
5841 //function : ViewerTest::Commands
5842 //purpose : Add all the viewer command in the Draw_Interpretor
5843 //==============================================================================
5845 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5847 ViewerTest::ViewerCommands(theCommands);
5848 ViewerTest::RelationCommands(theCommands);
5849 ViewerTest::ObjectCommands(theCommands);
5850 ViewerTest::FilletCommands(theCommands);
5851 ViewerTest::OpenGlCommands(theCommands);
5853 const char *group = "AIS_Display";
5856 theCommands.Add("visos",
5857 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5858 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5859 __FILE__, visos, group);
5861 theCommands.Add("vdisplay",
5862 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5863 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5864 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5865 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5866 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5867 "\n\t\t: [offsetX offsetY]]]"
5868 "\n\t\t: [-dispMode mode] [-highMode mode]"
5869 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5870 "\n\t\t: [-redisplay] [-erased]"
5871 "\n\t\t: name1 [name2] ... [name n]"
5872 "\n\t\t: Displays named objects."
5873 "\n\t\t: Option -local enables displaying of objects in local"
5874 "\n\t\t: selection context. Local selection context will be opened"
5875 "\n\t\t: if there is not any."
5876 "\n\t\t: -noupdate Suppresses viewer redraw call."
5877 "\n\t\t: -mutable Enables optimizations for mutable objects."
5878 "\n\t\t: -neutral Draws objects in main viewer."
5879 "\n\t\t: -erased Loads the object into context, but does not display it."
5880 "\n\t\t: -layer Sets z-layer for objects."
5881 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5882 "\n\t\t: options can be used for the default z-layers."
5883 "\n\t\t: -top Draws object on top of main presentations"
5884 "\n\t\t: but below topmost."
5885 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5886 "\n\t\t: with independent Depth."
5887 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5888 "\n\t\t: (On-Screen-Display)"
5889 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5890 "\n\t\t: (On-Screen-Display)"
5891 "\n\t\t: -selectable|-noselect Controls selection of objects."
5892 "\n\t\t: -trsfPers Sets a transform persistence flags."
5893 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5894 "\n\t\t: -2d Displays object in screen coordinates."
5895 "\n\t\t: (DY looks up)"
5896 "\n\t\t: -dispmode Sets display mode for objects."
5897 "\n\t\t: -highmode Sets hilight mode for objects."
5898 "\n\t\t: -redisplay Recomputes presentation of objects.",
5899 __FILE__, VDisplay2, group);
5901 theCommands.Add ("vnbdisplayed",
5903 "\n\t\t: Returns number of displayed objects",
5904 __FILE__, VNbDisplayed, group);
5906 theCommands.Add ("vupdate",
5907 "vupdate name1 [name2] ... [name n]"
5908 "\n\t\t: Updates named objects in interactive context",
5909 __FILE__, VUpdate, group);
5911 theCommands.Add("verase",
5912 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5913 "\n\t\t: Erases selected or named objects."
5914 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5915 "\n\t\t: Option -local enables erasing of selected or named objects without"
5916 "\n\t\t: closing local selection context.",
5917 __FILE__, VErase, group);
5919 theCommands.Add("vremove",
5920 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5921 "or vremove [-context] -all to remove all objects"
5922 "\n\t\t: Removes selected or named objects."
5923 "\n\t\t If -context is in arguments, the objects are not deleted"
5924 "\n\t\t from the map of objects and names."
5925 "\n\t\t: Option -local enables removing of selected or named objects without"
5926 "\n\t\t: closing local selection context. Empty local selection context will be"
5928 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5929 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5930 __FILE__, VRemove, group);
5932 theCommands.Add("vdonly",
5933 "vdonly [-noupdate|-update] [name1] ... [name n]"
5934 "\n\t\t: Displays only selected or named objects",
5935 __FILE__,VDonly2,group);
5937 theCommands.Add("vdisplayall",
5938 "vidsplayall [-local]"
5939 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5940 "\n\t\t: Option -local enables displaying of the objects in local"
5941 "\n\t\t: selection context.",
5942 __FILE__, VDisplayAll, group);
5944 theCommands.Add("veraseall",
5945 "veraseall [-local]"
5946 "\n\t\t: Erases all objects displayed in the viewer."
5947 "\n\t\t: Option -local enables erasing of the objects in local"
5948 "\n\t\t: selection context.",
5949 __FILE__, VErase, group);
5951 theCommands.Add("verasetype",
5953 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5954 __FILE__, VEraseType, group);
5955 theCommands.Add("vbounding",
5956 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5957 "\n\t\t: [-print] [-hide]"
5958 "\n\t\t: Temporarily display bounding box of specified Interactive"
5959 "\n\t\t: Objects, or print it to console if -print is specified."
5960 "\n\t\t: Already displayed box might be hidden by -hide option.",
5961 __FILE__,VBounding,group);
5963 theCommands.Add("vdisplaytype",
5964 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5965 __FILE__,VDisplayType,group);
5967 theCommands.Add("vsetdispmode",
5968 "vsetdispmode [name] mode(1,2,..)"
5969 "\n\t\t: Sets display mode for all, selected or named objects.",
5970 __FILE__,VDispMode,group);
5972 theCommands.Add("vunsetdispmode",
5973 "vunsetdispmode [name]"
5974 "\n\t\t: Unsets custom display mode for selected or named objects.",
5975 __FILE__,VDispMode,group);
5977 theCommands.Add("vdir",
5978 "Lists all objects displayed in 3D viewer",
5979 __FILE__,VDir,group);
5981 #ifdef HAVE_FREEIMAGE
5982 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5984 #define DUMP_FORMATS "{ppm}"
5986 theCommands.Add("vdump",
5987 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5988 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5989 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5990 "\n\t\t: [-tileSize Size=0]"
5991 "\n\t\t: Dumps content of the active view into image file",
5992 __FILE__,VDump,group);
5994 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5995 __FILE__,VSubInt,group);
5997 theCommands.Add("vaspects",
5998 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5999 "\n\t\t: [-setVisibility 0|1]"
6000 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
6001 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
6002 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
6003 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
6004 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
6005 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
6006 "\n\t\t: [-unsetMarkerType]"
6007 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
6008 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
6009 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
6010 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
6011 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
6012 "\n\t\t: [-isoontriangulation 0|1]"
6013 "\n\t\t: [-setMaxParamValue {value}]"
6014 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
6015 "\n\t\t: [-setHatch HatchStyle]"
6016 "\n\t\t: [-setShadingModel {color|flat|gouraud|phong}]"
6017 "\n\t\t: [-unsetShadingModel]"
6018 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
6019 "\n\t\t: Manage presentation properties of all, selected or named objects."
6020 "\n\t\t: When -subshapes is specified than following properties will be"
6021 "\n\t\t: assigned to specified sub-shapes."
6022 "\n\t\t: When -defaults is specified than presentation properties will be"
6023 "\n\t\t: assigned to all objects that have not their own specified properties"
6024 "\n\t\t: and to all objects to be displayed in the future."
6025 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
6026 __FILE__,VAspects,group);
6028 theCommands.Add("vsetcolor",
6029 "vsetcolor [-noupdate|-update] [name] ColorName"
6030 "\n\t\t: Sets color for all, selected or named objects."
6031 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
6032 __FILE__,VAspects,group);
6034 theCommands.Add("vunsetcolor",
6035 "vunsetcolor [-noupdate|-update] [name]"
6036 "\n\t\t: Resets color for all, selected or named objects."
6037 "\n\t\t: Alias for vaspects -unsetcolor [name].",
6038 __FILE__,VAspects,group);
6040 theCommands.Add("vsettransparency",
6041 "vsettransparency [-noupdate|-update] [name] Coefficient"
6042 "\n\t\t: Sets transparency for all, selected or named objects."
6043 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
6044 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
6045 __FILE__,VAspects,group);
6047 theCommands.Add("vunsettransparency",
6048 "vunsettransparency [-noupdate|-update] [name]"
6049 "\n\t\t: Resets transparency for all, selected or named objects."
6050 "\n\t\t: Alias for vaspects -unsettransp [name].",
6051 __FILE__,VAspects,group);
6053 theCommands.Add("vsetmaterial",
6054 "vsetmaterial [-noupdate|-update] [name] MaterialName"
6055 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
6056 __FILE__,VAspects,group);
6058 theCommands.Add("vunsetmaterial",
6059 "vunsetmaterial [-noupdate|-update] [name]"
6060 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
6061 __FILE__,VAspects,group);
6063 theCommands.Add("vsetwidth",
6064 "vsetwidth [-noupdate|-update] [name] width(0->10)"
6065 "\n\t\t: Alias for vaspects -setwidth [name] width.",
6066 __FILE__,VAspects,group);
6068 theCommands.Add("vunsetwidth",
6069 "vunsetwidth [-noupdate|-update] [name]"
6070 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
6071 __FILE__,VAspects,group);
6073 theCommands.Add("vsetinteriorstyle",
6074 "vsetinteriorstyle [-noupdate|-update] [name] style"
6075 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
6076 __FILE__,VSetInteriorStyle,group);
6078 theCommands.Add("vsensdis",
6079 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
6080 "\n\t\t: Standard entity types are those defined in Select3D package:"
6081 "\n\t\t: - sensitive box"
6082 "\n\t\t: - sensitive face"
6083 "\n\t\t: - sensitive curve"
6084 "\n\t\t: - sensitive segment"
6085 "\n\t\t: - sensitive circle"
6086 "\n\t\t: - sensitive point"
6087 "\n\t\t: - sensitive triangulation"
6088 "\n\t\t: - sensitive triangle"
6089 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
6090 __FILE__,VDispSensi,group);
6092 theCommands.Add("vsensera",
6093 "vsensera : erase active entities",
6094 __FILE__,VClearSensi,group);
6096 theCommands.Add("vsetshading",
6097 "vsetshading : vsetshading name Quality(default=0.0008) "
6098 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
6099 __FILE__,VShading,group);
6101 theCommands.Add("vunsetshading",
6102 "vunsetshading :vunsetshading name "
6103 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
6104 __FILE__,VShading,group);
6106 theCommands.Add ("vtexture",
6107 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
6108 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
6109 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
6110 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
6111 "\n\t\t: [-modulate {on|off}]"
6112 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
6113 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
6114 "\n\t\t: [-default]"
6115 "\n\t\t: The texture can be specified by filepath"
6116 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
6117 "\n\t\t: The options are:"
6118 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
6119 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
6120 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
6121 "\n\t\t: -modulate Enable or disable texture color modulation"
6122 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
6123 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
6124 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
6125 "\n\t\t: -setFilter Setup texture filter"
6126 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
6127 "\n\t\t: -default Sets texture mapping default parameters",
6128 __FILE__, VTexture, group);
6130 theCommands.Add("vtexscale",
6131 "vtexscale name ScaleU ScaleV"
6132 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
6133 __FILE__,VTexture,group);
6135 theCommands.Add("vtexorigin",
6136 "vtexorigin name OriginU OriginV"
6137 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
6138 __FILE__,VTexture,group);
6140 theCommands.Add("vtexrepeat",
6141 "vtexrepeat name RepeatU RepeatV"
6142 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
6145 theCommands.Add("vtexdefault",
6147 "\n\t\t: Alias for vtexture name -default.",
6150 theCommands.Add("vstate",
6151 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6152 "\n\t\t: Reports show/hidden state for selected or named objects"
6153 "\n\t\t: -entities - print low-level information about detected entities"
6154 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6155 __FILE__,VState,group);
6157 theCommands.Add("vpickshapes",
6158 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6159 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6160 "\n\t\t: Hold also Shift for multiple selection.",
6161 __FILE__, VPickShape, group);
6163 theCommands.Add("vtypes",
6164 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6167 theCommands.Add("vr",
6169 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6170 __FILE__,vr, group);
6172 theCommands.Add("vselfilter",
6173 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6174 "\nSets selection shape type filter in context or remove all filters."
6175 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6176 "\n : Option -clear remove all filters in context",
6177 __FILE__,VSelFilter,group);
6179 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6180 __FILE__, VPickSelected, group);
6182 theCommands.Add ("vloadselection",
6183 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6184 "\n\t\t: primitives for the shapes with names given without displaying them."
6185 "\n\t\t: -local - open local context before selection computation",
6186 __FILE__, VLoadSelection, group);
6188 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6189 "\nAdjusts parameters of material BSDF:"
6190 "\n -help : Shows this message"
6191 "\n -print : Print BSDF"
6192 "\n -kd : Weight of the Lambertian BRDF"
6193 "\n -kr : Weight of the reflection BRDF"
6194 "\n -kt : Weight of the transmission BTDF"
6195 "\n -ks : Weight of the glossy Blinn BRDF"
6196 "\n -le : Self-emitted radiance"
6197 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6198 "\n Schlick x y z, Dielectric x, Conductor x y"
6199 "\n -roughness : Roughness of material (Blinn's exponent)"
6200 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6201 "\n -absorpcolor : Absorption color (only for transparent material)"
6202 "\n -normalize : Normalize BSDF coefficients",
6203 __FILE__, VBsdf, group);
6207 //=====================================================================
6208 //========================= for testing Draft and Rib =================
6209 //=====================================================================
6210 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6211 #include <DBRep.hxx>
6212 #include <TopoDS_Face.hxx>
6213 #include <gp_Pln.hxx>
6214 #include <AIS_KindOfSurface.hxx>
6215 #include <BRepOffsetAPI_DraftAngle.hxx>
6216 #include <Precision.hxx>
6217 #include <BRepAlgo.hxx>
6218 #include <OSD_Environment.hxx>
6219 #include <DrawTrSurf.hxx>
6220 //#include <DbgTools.hxx>
6221 //#include <FeatAlgo_MakeLinearForm.hxx>
6226 //=======================================================================
6227 //function : IsValid
6229 //=======================================================================
6230 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6231 const TopoDS_Shape& theResult,
6232 const Standard_Boolean closedSolid,
6233 const Standard_Boolean GeomCtrl)
6235 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6236 TCollection_AsciiString checkValid = check.Value();
6237 Standard_Boolean ToCheck = Standard_True;
6238 if (!checkValid.IsEmpty()) {
6240 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6242 if ( checkValid=="true" || checkValid=="TRUE" ) {
6243 ToCheck= Standard_False;
6247 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6250 Standard_Boolean IsValid = Standard_True;
6252 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6257 //===============================================================================
6258 // TDraft : test draft, uses AIS Viewer
6259 // Solid Face Plane Angle Reverse
6260 //===============================================================================
6261 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6263 if (argc < 5) return 1;
6264 // argv[1] - TopoDS_Shape Solid
6265 // argv[2] - TopoDS_Shape Face
6266 // argv[3] - TopoDS_Shape Plane
6267 // argv[4] - Standard_Real Angle
6268 // argv[5] - Standard_Integer Reverse
6270 // Sprintf(prefix, argv[1]);
6271 Standard_Real anAngle = 0;
6272 Standard_Boolean Rev = Standard_False;
6273 Standard_Integer rev = 0;
6274 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
6275 TopoDS_Shape face = GetShapeFromName(argv[2]);
6276 TopoDS_Face Face = TopoDS::Face(face);
6277 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
6278 if (Plane.IsNull ()) {
6279 di << "TEST : Plane is NULL\n";
6282 anAngle = Draw::Atof(argv[4]);
6283 anAngle = 2*M_PI * anAngle / 360.0;
6285 Handle( Geom_Surface )aSurf;
6286 AIS_KindOfSurface aSurfType;
6287 Standard_Real Offset;
6289 if(argc > 4) { // == 5
6290 rev = Draw::Atoi(argv[5]);
6291 Rev = (rev)? Standard_True : Standard_False;
6294 TopoDS_Face face2 = TopoDS::Face(Plane);
6295 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6297 di << "TEST : Can't find plane\n";
6301 aDir = aPln.Axis().Direction();
6304 if (Plane.Orientation() == TopAbs_REVERSED)
6306 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6308 BRepOffsetAPI_DraftAngle Draft (Solid);
6310 if(Abs(anAngle)< Precision::Angular()) {
6311 di << "TEST : NULL angle\n";
6314 if(Rev) anAngle = - anAngle;
6315 Draft.Add (Face, aDir, anAngle, aPln);
6317 if (!Draft.IsDone()) {
6318 di << "TEST : Draft Not DONE \n";
6321 TopTools_ListOfShape Larg;
6323 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6324 di << "TEST : DesignAlgo returns Not valid\n";
6328 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6329 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6331 if ( !ais.IsNull() ) {
6332 ais->SetColor(DEFAULT_COLOR);
6333 ais->SetMaterial(DEFAULT_MATERIAL);
6334 // Display the AIS_Shape without redraw
6335 Ctx->Display(ais, Standard_False);
6337 const char *Name = "draft1";
6338 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6340 Handle(AIS_InteractiveObject) an_object =
6341 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6342 if (!an_object.IsNull()) {
6343 Ctx->Remove(an_object,
6345 GetMapOfAIS().UnBind2(Name) ;
6348 GetMapOfAIS().Bind(ais, Name);
6349 // DBRep::Set("draft", ais->Shape());
6351 Ctx->Display(ais, Standard_True);
6355 //==============================================================================
6356 //function : splitParameter
6357 //purpose : Split parameter string to parameter name and parameter value
6358 //==============================================================================
6359 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6360 TCollection_AsciiString& theName,
6361 TCollection_AsciiString& theValue)
6363 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6365 if (aParamNameEnd == 0)
6367 return Standard_False;
6370 TCollection_AsciiString aString (theString);
6371 if (aParamNameEnd != 0)
6373 theValue = aString.Split (aParamNameEnd);
6374 aString.Split (aString.Length() - 1);
6378 return Standard_True;
6381 //============================================================================
6383 //============================================================================
6384 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6387 DrawTrSurf::BasicCommands(theCommands);
6388 const char* group = "Check Features Operations commands";
6390 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6392 &TDraft,group); //Draft_Modification
6395 //==============================================================================
6396 // ViewerTest::Factory
6397 //==============================================================================
6398 void ViewerTest::Factory(Draw_Interpretor& theDI)
6400 // definition of Viewer Command
6401 ViewerTest::Commands(theDI);
6404 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6408 // Declare entry point PLUGINFACTORY