1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Standard_Stream.hxx>
19 #include <ViewerTest.hxx>
20 #include <ViewerTest_CmdParser.hxx>
23 #include <TopLoc_Location.hxx>
24 #include <TopTools_HArray1OfShape.hxx>
25 #include <TColStd_HArray1OfTransient.hxx>
26 #include <TColStd_SequenceOfAsciiString.hxx>
27 #include <TColStd_HSequenceOfAsciiString.hxx>
28 #include <TColStd_MapOfTransient.hxx>
29 #include <OSD_Timer.hxx>
30 #include <Geom_Axis2Placement.hxx>
31 #include <Geom_Axis1Placement.hxx>
32 #include <gp_Trsf.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include <StdSelect_ShapeTypeFilter.hxx>
37 #include <AIS_ColoredShape.hxx>
38 #include <AIS_InteractiveObject.hxx>
39 #include <AIS_Trihedron.hxx>
40 #include <AIS_Axis.hxx>
41 #include <AIS_Relation.hxx>
42 #include <AIS_TypeFilter.hxx>
43 #include <AIS_SignatureFilter.hxx>
44 #include <AIS_ListOfInteractive.hxx>
45 #include <AIS_ListIteratorOfListOfInteractive.hxx>
46 #include <Aspect_InteriorStyle.hxx>
47 #include <Aspect_Window.hxx>
48 #include <Graphic3d_AspectFillArea3d.hxx>
49 #include <Graphic3d_AspectLine3d.hxx>
50 #include <Graphic3d_CStructure.hxx>
51 #include <Graphic3d_Texture2Dmanual.hxx>
52 #include <Graphic3d_GraphicDriver.hxx>
53 #include <Graphic3d_MediaTextureSet.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
88 const Standard_Integer THE_MAX_INTEGER_COLOR_COMPONENT = 255;
90 const Standard_ShortReal THE_MAX_REAL_COLOR_COMPONENT = 1.0f;
92 //! Parses string and get an integer color component (only values within range 0 .. 255 are allowed)
93 //! @param theColorComponentString the string representing the color component
94 //! @param theIntegerColorComponent an integer color component that is a result of parsing
95 //! @return true if parsing was successful, or false otherwise
96 static bool parseNumericalColorComponent (const Standard_CString theColorComponentString,
97 Standard_Integer& theIntegerColorComponent)
99 Standard_Integer anIntegerColorComponent;
100 if (!Draw::ParseInteger (theColorComponentString, anIntegerColorComponent))
104 if ((anIntegerColorComponent < 0) || (anIntegerColorComponent > THE_MAX_INTEGER_COLOR_COMPONENT))
108 theIntegerColorComponent = anIntegerColorComponent;
112 //! Parses the string and gets a real color component from it (only values within range 0.0 .. 1.0 are allowed)
113 //! @param theColorComponentString the string representing the color component
114 //! @param theRealColorComponent a real color component that is a result of parsing
115 //! @return true if parsing was successful, or false otherwise
116 static bool parseNumericalColorComponent (const Standard_CString theColorComponentString,
117 Standard_ShortReal& theRealColorComponent)
119 Standard_Real aRealColorComponent;
120 if (!Draw::ParseReal (theColorComponentString, aRealColorComponent))
124 const Standard_ShortReal aShortRealColorComponent = static_cast<Standard_ShortReal> (aRealColorComponent);
125 if ((aShortRealColorComponent < 0.0f) || (aShortRealColorComponent > THE_MAX_REAL_COLOR_COMPONENT))
129 theRealColorComponent = aShortRealColorComponent;
133 //! Parses the string and gets a real color component from it (integer values 2 .. 255 are scaled to the 0.0 .. 1.0
134 //! range, values 0 and 1 are leaved as they are)
135 //! @param theColorComponentString the string representing the color component
136 //! @param theColorComponent a color component that is a result of parsing
137 //! @return true if parsing was successful, or false otherwise
138 static bool parseColorComponent (const Standard_CString theColorComponentString,
139 Standard_ShortReal& theColorComponent)
141 Standard_Integer anIntegerColorComponent;
142 if (parseNumericalColorComponent (theColorComponentString, anIntegerColorComponent))
144 if (anIntegerColorComponent == 1)
146 theColorComponent = THE_MAX_REAL_COLOR_COMPONENT;
150 theColorComponent = anIntegerColorComponent * 1.0f / THE_MAX_INTEGER_COLOR_COMPONENT;
154 return parseNumericalColorComponent (theColorComponentString, theColorComponent);
157 //! Parses the array of strings and gets an integer color (only values within range 0 .. 255 are allowed and at least
158 //! one of components must be greater than 1)
159 //! @tparam TheNumber the type of resulting color vector elements
160 //! @param theNumberOfColorComponents the number of color components
161 //! @param theColorComponentStrings the array of strings representing color components
162 //! @param theNumericalColor a 4-component vector that is a result of parsing
163 //! @return true if parsing was successful, or false otherwise
164 template <typename TheNumber>
165 static bool parseNumericalColor (Standard_Integer& theNumberOfColorComponents,
166 const char* const* const theColorComponentStrings,
167 NCollection_Vec4<TheNumber>& theNumericalColor)
169 for (Standard_Integer aColorComponentIndex = 0; aColorComponentIndex < theNumberOfColorComponents;
170 ++aColorComponentIndex)
172 const char* const aColorComponentString = theColorComponentStrings[aColorComponentIndex];
173 TheNumber aNumericalColorComponent;
174 if (parseNumericalColorComponent (aColorComponentString, aNumericalColorComponent))
176 theNumericalColor[aColorComponentIndex] = aNumericalColorComponent;
180 if (aColorComponentIndex == 3)
182 theNumberOfColorComponents = 3;
193 //! Parses an array of strings and get an integer color (only values within range 0 .. 255 are allowed and at least
194 //! one of components must be greater than 1)
195 //! @param theNumberOfColorComponents the number of color components
196 //! @param theColorComponentStrings the array of strings representing color components
197 //! @param theColor a color that is a result of parsing
198 //! @return true if parsing was successful, or false otherwise
199 static bool parseIntegerColor (Standard_Integer& theNumberOfColorComponents,
200 const char* const* const theColorComponentStrings,
201 Quantity_ColorRGBA& theColor)
203 const Standard_Integer THE_COLOR_COMPONENT_NOT_PARSED = -1;
204 Graphic3d_Vec4i anIntegerColor (THE_COLOR_COMPONENT_NOT_PARSED);
205 if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, anIntegerColor)
206 || anIntegerColor.maxComp() <= 1)
210 if (anIntegerColor.a() == THE_COLOR_COMPONENT_NOT_PARSED)
212 anIntegerColor.a() = THE_MAX_INTEGER_COLOR_COMPONENT;
215 const Graphic3d_Vec4 aRealColor = Graphic3d_Vec4 (anIntegerColor) / static_cast<Standard_ShortReal> (THE_MAX_INTEGER_COLOR_COMPONENT);
216 theColor = Quantity_ColorRGBA (Quantity_ColorRGBA::Convert_sRGB_To_LinearRGB (aRealColor));
220 //! Parses an array of strings and get a real color (only values within range 0.0 .. 1.0 are allowed)
221 //! @param theNumberOfColorComponents the number of color components
222 //! @param theColorComponentStrings the array of strings representing color components
223 //! @param theColor a color that is a result of parsing
224 //! @return true if parsing was successful, or false otherwise
225 static bool parseRealColor (Standard_Integer& theNumberOfColorComponents,
226 const char* const* const theColorComponentStrings,
227 Quantity_ColorRGBA& theColor)
229 Graphic3d_Vec4 aRealColor (THE_MAX_REAL_COLOR_COMPONENT);
230 if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, aRealColor))
234 theColor = Quantity_ColorRGBA (aRealColor);
240 //=======================================================================
241 // function : GetColorFromName
242 // purpose : get the Quantity_NameOfColor from a string
243 //=======================================================================
245 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
247 Quantity_NameOfColor aColor = DEFAULT_COLOR;
248 Quantity_Color::ColorFromName (theName, aColor);
252 //=======================================================================
253 // function : parseColor
255 //=======================================================================
256 Standard_Integer ViewerTest::parseColor (const Standard_Integer theArgNb,
257 const char* const* const theArgVec,
258 Quantity_ColorRGBA& theColor,
259 const bool theToParseAlpha)
261 if ((theArgNb >= 1) && Quantity_ColorRGBA::ColorFromHex (theArgVec[0], theColor, !theToParseAlpha))
265 if (theArgNb >= 1 && Quantity_ColorRGBA::ColorFromName (theArgVec[0], theColor))
267 if (theArgNb >= 2 && theToParseAlpha)
269 const Standard_CString anAlphaStr = theArgVec[1];
270 Standard_ShortReal anAlphaComponent;
271 if (parseColorComponent (anAlphaStr, anAlphaComponent))
273 theColor.SetAlpha (anAlphaComponent);
281 const Standard_Integer aNumberOfColorComponentsToParse = Min (theArgNb, theToParseAlpha ? 4 : 3);
282 Standard_Integer aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
283 if (parseIntegerColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
285 return aNumberOfColorComponentsParsed;
287 aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
288 if (parseRealColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
290 return aNumberOfColorComponentsParsed;
297 //=======================================================================
298 //function : ParseOnOff
300 //=======================================================================
301 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
302 Standard_Boolean& theIsOn)
304 TCollection_AsciiString aFlag(theArg);
309 theIsOn = Standard_True;
310 return Standard_True;
312 else if (aFlag == "off"
315 theIsOn = Standard_False;
316 return Standard_True;
318 return Standard_False;
321 //=======================================================================
322 //function : GetSelectedShapes
324 //=======================================================================
325 void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
327 for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
329 TopoDS_Shape aShape = GetAISContext()->SelectedShape();
330 if (!aShape.IsNull())
332 theSelectedShapes.Append (aShape);
337 //=======================================================================
338 //function : ParseLineType
340 //=======================================================================
341 Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
342 Aspect_TypeOfLine& theType)
344 TCollection_AsciiString aTypeStr (theArg);
345 aTypeStr.LowerCase();
346 if (aTypeStr == "empty")
348 theType = Aspect_TOL_EMPTY;
350 else if (aTypeStr == "solid")
352 theType = Aspect_TOL_SOLID;
354 else if (aTypeStr == "dot")
356 theType = Aspect_TOL_DOT;
358 else if (aTypeStr == "dash")
360 theType = Aspect_TOL_DASH;
362 else if (aTypeStr == "dotdash")
364 theType = Aspect_TOL_DOTDASH;
366 else if (aTypeStr.IsIntegerValue())
368 const int aTypeInt = aTypeStr.IntegerValue();
369 if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
371 return Standard_False;
373 theType = (Aspect_TypeOfLine )aTypeInt;
377 return Standard_False;
379 return Standard_True;
382 //=======================================================================
383 //function : ParseMarkerType
385 //=======================================================================
386 Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
387 Aspect_TypeOfMarker& theType,
388 Handle(Image_PixMap)& theImage)
391 TCollection_AsciiString aTypeStr (theArg);
392 aTypeStr.LowerCase();
393 if (aTypeStr == "empty")
395 theType = Aspect_TOM_EMPTY;
397 else if (aTypeStr == "point"
401 theType = Aspect_TOM_POINT;
403 else if (aTypeStr == "plus"
406 theType = Aspect_TOM_PLUS;
408 else if (aTypeStr == "star"
411 theType = Aspect_TOM_STAR;
413 else if (aTypeStr == "cross"
416 theType = Aspect_TOM_X;
418 else if (aTypeStr == "circle"
421 theType = Aspect_TOM_O;
423 else if (aTypeStr == "pointincircle")
425 theType = Aspect_TOM_O_POINT;
427 else if (aTypeStr == "plusincircle")
429 theType = Aspect_TOM_O_PLUS;
431 else if (aTypeStr == "starincircle")
433 theType = Aspect_TOM_O_STAR;
435 else if (aTypeStr == "crossincircle"
436 || aTypeStr == "xcircle")
438 theType = Aspect_TOM_O_X;
440 else if (aTypeStr == "ring1")
442 theType = Aspect_TOM_RING1;
444 else if (aTypeStr == "ring2")
446 theType = Aspect_TOM_RING2;
448 else if (aTypeStr == "ring"
449 || aTypeStr == "ring3")
451 theType = Aspect_TOM_RING3;
453 else if (aTypeStr == "ball")
455 theType = Aspect_TOM_BALL;
457 else if (aTypeStr.IsIntegerValue())
459 const int aTypeInt = aTypeStr.IntegerValue();
460 if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED)
462 return Standard_False;
464 theType = (Aspect_TypeOfMarker )aTypeInt;
468 theType = Aspect_TOM_USERDEFINED;
469 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
470 if (!anImage->Load (theArg))
472 return Standard_False;
474 if (anImage->Format() == Image_Format_Gray)
476 anImage->SetFormat (Image_Format_Alpha);
478 else if (anImage->Format() == Image_Format_GrayF)
480 anImage->SetFormat (Image_Format_AlphaF);
484 return Standard_True;
487 //=======================================================================
488 //function : ParseShadingModel
490 //=======================================================================
491 Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg,
492 Graphic3d_TypeOfShadingModel& theModel)
494 TCollection_AsciiString aTypeStr (theArg);
495 aTypeStr.LowerCase();
496 if (aTypeStr == "unlit"
497 || aTypeStr == "color"
498 || aTypeStr == "none")
500 theModel = Graphic3d_TOSM_UNLIT;
502 else if (aTypeStr == "flat"
503 || aTypeStr == "facet")
505 theModel = Graphic3d_TOSM_FACET;
507 else if (aTypeStr == "gouraud"
508 || aTypeStr == "vertex"
509 || aTypeStr == "vert")
511 theModel = Graphic3d_TOSM_VERTEX;
513 else if (aTypeStr == "phong"
514 || aTypeStr == "fragment"
515 || aTypeStr == "frag"
516 || aTypeStr == "pixel")
518 theModel = Graphic3d_TOSM_FRAGMENT;
520 else if (aTypeStr == "pbr")
522 theModel = Graphic3d_TOSM_PBR;
524 else if (aTypeStr == "pbr_facet")
526 theModel = Graphic3d_TOSM_PBR_FACET;
528 else if (aTypeStr == "default"
529 || aTypeStr == "def")
531 theModel = Graphic3d_TOSM_DEFAULT;
533 else if (aTypeStr.IsIntegerValue())
535 const int aTypeInt = aTypeStr.IntegerValue();
536 if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
538 return Standard_False;
540 theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
544 return Standard_False;
546 return Standard_True;
549 //=======================================================================
550 //function : parseZLayer
552 //=======================================================================
553 Standard_Boolean ViewerTest::parseZLayer (Standard_CString theArg,
554 Standard_Boolean theToAllowInteger,
555 Graphic3d_ZLayerId& theLayer)
557 TCollection_AsciiString aName (theArg);
559 if (aName == "default"
562 theLayer = Graphic3d_ZLayerId_Default;
564 else if (aName == "top")
566 theLayer = Graphic3d_ZLayerId_Top;
568 else if (aName == "topmost")
570 theLayer = Graphic3d_ZLayerId_Topmost;
572 else if (aName == "overlay"
573 || aName == "toposd")
575 theLayer = Graphic3d_ZLayerId_TopOSD;
577 else if (aName == "underlay"
578 || aName == "botosd")
580 theLayer = Graphic3d_ZLayerId_BotOSD;
582 else if (aName == "undefined")
584 theLayer = Graphic3d_ZLayerId_UNKNOWN;
586 else if (!GetAISContext().IsNull())
588 const Handle(V3d_Viewer)& aViewer = ViewerTest::GetAISContext()->CurrentViewer();
589 TColStd_SequenceOfInteger aLayers;
590 aViewer->GetAllZLayers (aLayers);
591 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
593 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
594 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aName, Standard_False))
596 theLayer = aLayeriter.Value();
601 if (!theToAllowInteger
602 || !aName.IsIntegerValue())
606 Graphic3d_ZLayerId aLayer = aName.IntegerValue();
607 if (aLayer == Graphic3d_ZLayerId_UNKNOWN
608 || std::find (aLayers.begin(), aLayers.end(), aLayer) != aLayers.end())
618 //=======================================================================
619 //function : GetTypeNames
621 //=======================================================================
622 static const char** GetTypeNames()
624 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
625 "Shape","ConnectedShape","MultiConn.Shape",
626 "ConnectedInter.","MultiConn.",
627 "Constraint","Dimension"};
628 static const char** ThePointer = names;
632 //=======================================================================
633 //function : GetTypeAndSignfromString
635 //=======================================================================
636 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
638 const char ** thefullnames = GetTypeNames();
639 Standard_Integer index(-1);
641 for(Standard_Integer i=0;i<=13 && index==-1;i++)
642 if(!strcasecmp(name,thefullnames[i]))
646 TheType = AIS_KOI_None;
652 TheType = AIS_KOI_Datum;
656 TheType = AIS_KOI_Shape;
660 TheType = AIS_KOI_Object;
664 TheType = AIS_KOI_Relation;
673 #include <Draw_Interpretor.hxx>
675 #include <Draw_Appli.hxx>
679 #include <TCollection_AsciiString.hxx>
680 #include <V3d_Viewer.hxx>
681 #include <V3d_View.hxx>
684 #include <AIS_InteractiveContext.hxx>
685 #include <AIS_Shape.hxx>
686 #include <AIS_DisplayMode.hxx>
687 #include <TColStd_MapOfInteger.hxx>
688 #include <AIS_MapOfInteractive.hxx>
689 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
690 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
691 #include <ViewerTest_EventManager.hxx>
693 #include <TopoDS_Solid.hxx>
694 #include <BRepTools.hxx>
695 #include <BRep_Builder.hxx>
696 #include <TopAbs_ShapeEnum.hxx>
698 #include <TopoDS.hxx>
699 #include <BRep_Tool.hxx>
702 #include <Draw_Window.hxx>
703 #include <AIS_ListIteratorOfListOfInteractive.hxx>
704 #include <AIS_ListOfInteractive.hxx>
705 #include <AIS_DisplayMode.hxx>
706 #include <TopTools_ListOfShape.hxx>
707 #include <BRepOffsetAPI_MakeThickSolid.hxx>
709 //==============================================================================
710 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
711 //==============================================================================
712 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
713 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
717 //=======================================================================
720 //=======================================================================
721 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
722 const Handle(AIS_InteractiveObject)& theObject,
723 const Standard_Boolean theToUpdate,
724 const Standard_Boolean theReplaceIfExists)
726 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
727 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
730 std::cout << "Error: AIS context is not available.\n";
731 return Standard_False;
734 if (aMap.IsBound2 (theName))
736 if (!theReplaceIfExists)
738 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
739 << "Please use another name.\n";
740 return Standard_False;
743 if (Handle(AIS_InteractiveObject) anOldObj = aMap.Find2 (theName))
745 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
747 aMap.UnBind2 (theName);
750 if (theObject.IsNull())
752 // object with specified name has been already unbound
753 return Standard_True;
756 // unbind AIS object if it was bound with another name
757 aMap.UnBind1 (theObject);
759 // can be registered without rebinding
760 aMap.Bind (theObject, theName);
761 aCtx->Display (theObject, theToUpdate);
762 return Standard_True;
765 //! Alias for ViewerTest::Display(), compatibility with old code.
766 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
767 const Handle(AIS_InteractiveObject)& theObject,
768 Standard_Boolean theReplaceIfExists = Standard_True)
770 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
773 static NCollection_List<Handle(ViewerTest_EventManager)> theEventMgrs;
775 static Handle(V3d_View)& a3DView()
777 static Handle(V3d_View) Viou;
782 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
783 static Handle(AIS_InteractiveContext) aContext;
787 const Handle(V3d_View)& ViewerTest::CurrentView()
791 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
796 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
798 return TheAISContext();
801 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
803 TheAISContext() = aCtx;
804 ViewerTest::ResetEventManager();
807 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
809 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
812 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
814 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
818 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
819 theEventMgrs.Prepend(EM);
822 void ViewerTest::UnsetEventManager()
824 theEventMgrs.RemoveFirst();
828 void ViewerTest::ResetEventManager()
830 theEventMgrs.Clear();
831 theEventMgrs.Prepend (new ViewerTest_EventManager (ViewerTest::CurrentView(), ViewerTest::GetAISContext()));
834 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
836 return !theEventMgrs.IsEmpty()
837 ? theEventMgrs.First()
838 : Handle(ViewerTest_EventManager)();
841 //=======================================================================
842 //function : Get Context and active view
844 //=======================================================================
845 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
846 Handle(V3d_View)& theView)
848 theCtx = ViewerTest::GetAISContext();
849 theView = ViewerTest::CurrentView();
853 std::cout << "Error: cannot find an active view!\n";
854 return Standard_False;
856 return Standard_True;
859 //==============================================================================
861 //purpose : Remove all the object from the viewer
862 //==============================================================================
863 void ViewerTest::Clear()
865 if (a3DView().IsNull())
870 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
871 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
873 const Handle(AIS_InteractiveObject) anObj = anObjIter.Key1();
874 if (anObj->GetContext() != TheAISContext())
879 std::cout << "Remove " << anObjIter.Key2() << std::endl;
880 TheAISContext()->Remove (anObj, Standard_False);
881 aListRemoved.Append (anObj);
884 TheAISContext()->RebuildSelectionStructs();
885 TheAISContext()->UpdateCurrentViewer();
886 if (aListRemoved.Size() == GetMapOfAIS().Extent())
888 GetMapOfAIS().Clear();
892 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
894 GetMapOfAIS().UnBind1 (anObjIter.Value());
899 //==============================================================================
900 //function : CopyIsoAspect
901 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
902 //==============================================================================
903 static Handle(Prs3d_IsoAspect) CopyIsoAspect
904 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
905 const Standard_Integer theNbIsos)
907 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
908 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
909 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
911 Handle(Prs3d_IsoAspect) aResult =
912 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
917 //==============================================================================
919 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
920 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
921 //==============================================================================
922 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
924 if (TheAISContext().IsNull()) {
925 di << argv[0] << " Call 'vinit' before!\n";
930 di << "Current number of isos : " <<
931 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
932 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
933 di << "IsoOnPlane mode is " <<
934 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
935 di << "IsoOnTriangulation mode is " <<
936 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
940 Standard_Integer aLastInd = argc - 1;
941 Standard_Boolean isChanged = Standard_False;
942 Standard_Integer aNbUIsos = 0;
943 Standard_Integer aNbVIsos = 0;
946 Standard_Boolean isIsoOnPlane = Standard_False;
948 if (strcmp(argv[aLastInd], "1") == 0) {
949 isIsoOnPlane = Standard_True;
950 isChanged = Standard_True;
951 } else if (strcmp(argv[aLastInd], "0") == 0) {
952 isIsoOnPlane = Standard_False;
953 isChanged = Standard_True;
957 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
958 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
961 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
962 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
964 TheAISContext()->IsoOnPlane(isIsoOnPlane);
967 // If there are no shapes provided set the default numbers.
968 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
969 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
976 for (i = 1; i <= aLastInd; i++)
978 TCollection_AsciiString name(argv[i]);
979 Handle(AIS_InteractiveObject) aShape;
980 GetMapOfAIS().Find2(name, aShape);
983 std::cout << "Syntax error: object '" << name << "' is not found\n";
987 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
988 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
989 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
992 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
993 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
994 TheAISContext()->SetLocalAttributes (aShape, CurDrawer, Standard_False);
995 TheAISContext()->Redisplay (aShape, Standard_False);
999 di << "Number of isos for " << argv[i] << " : "
1000 << aUIso->Number() << " " << aVIso->Number() << "\n";
1005 TheAISContext()->UpdateCurrentViewer();
1011 static Standard_Integer VDispSensi (Draw_Interpretor& ,
1012 Standard_Integer theArgNb,
1017 std::cout << "Error: wrong syntax!\n";
1021 Handle(AIS_InteractiveContext) aCtx;
1022 Handle(V3d_View) aView;
1023 if (!getCtxAndView (aCtx, aView))
1028 aCtx->DisplayActiveSensitive (aView);
1033 static Standard_Integer VClearSensi (Draw_Interpretor& ,
1034 Standard_Integer theArgNb,
1039 std::cout << "Error: wrong syntax!\n";
1043 Handle(AIS_InteractiveContext) aCtx;
1044 Handle(V3d_View) aView;
1045 if (!getCtxAndView (aCtx, aView))
1049 aCtx->ClearActiveSensitive (aView);
1053 //==============================================================================
1055 //purpose : To list the displayed object with their attributes
1056 //==============================================================================
1057 static int VDir (Draw_Interpretor& theDI,
1058 Standard_Integer theNbArgs,
1059 const char** theArgVec)
1061 TCollection_AsciiString aMatch;
1062 Standard_Boolean toFormat = Standard_False;
1063 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
1065 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
1066 anArgCase.LowerCase();
1067 if (anArgCase == "-list"
1068 || anArgCase == "-format")
1070 toFormat = Standard_True;
1072 else if (aMatch.IsEmpty())
1074 aMatch = theArgVec[anArgIter];
1078 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
1083 TCollection_AsciiString aRes;
1084 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
1086 if (!aMatch.IsEmpty())
1088 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aMatch + "' '" + anIter.Key2() + "'";
1089 if (theDI.Eval (aCheck.ToCString()) == 0
1090 && *theDI.Result() != '1')
1098 aRes += TCollection_AsciiString("\t") + anIter.Key2() + "\n";
1102 aRes += anIter.Key2() + " ";
1110 //! Auxiliary enumeration
1111 enum ViewerTest_StereoPair
1113 ViewerTest_SP_Single,
1114 ViewerTest_SP_SideBySide,
1115 ViewerTest_SP_OverUnder
1118 //==============================================================================
1120 //purpose : To dump the active view snapshot to image file
1121 //==============================================================================
1122 static Standard_Integer VDump (Draw_Interpretor& theDI,
1123 Standard_Integer theArgNb,
1124 Standard_CString* theArgVec)
1128 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
1132 Standard_Integer anArgIter = 1;
1133 Standard_CString aFilePath = theArgVec[anArgIter++];
1134 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
1135 V3d_ImageDumpOptions aParams;
1136 aParams.BufferType = Graphic3d_BT_RGB;
1137 aParams.StereoOptions = V3d_SDO_MONO;
1138 for (; anArgIter < theArgNb; ++anArgIter)
1140 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1142 if (anArg == "-buffer")
1144 if (++anArgIter >= theArgNb)
1146 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
1150 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
1151 aBufArg.LowerCase();
1152 if (aBufArg == "rgba")
1154 aParams.BufferType = Graphic3d_BT_RGBA;
1156 else if (aBufArg == "rgb")
1158 aParams.BufferType = Graphic3d_BT_RGB;
1160 else if (aBufArg == "depth")
1162 aParams.BufferType = Graphic3d_BT_Depth;
1166 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
1170 else if (anArg == "-stereo")
1172 if (++anArgIter >= theArgNb)
1174 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
1178 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
1179 aStereoArg.LowerCase();
1180 if (aStereoArg == "l"
1181 || aStereoArg == "left")
1183 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1185 else if (aStereoArg == "r"
1186 || aStereoArg == "right")
1188 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1190 else if (aStereoArg == "mono")
1192 aParams.StereoOptions = V3d_SDO_MONO;
1194 else if (aStereoArg == "blended"
1195 || aStereoArg == "blend"
1196 || aStereoArg == "stereo")
1198 aParams.StereoOptions = V3d_SDO_BLENDED;
1200 else if (aStereoArg == "sbs"
1201 || aStereoArg == "sidebyside")
1203 aStereoPair = ViewerTest_SP_SideBySide;
1205 else if (aStereoArg == "ou"
1206 || aStereoArg == "overunder")
1208 aStereoPair = ViewerTest_SP_OverUnder;
1212 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
1216 else if (anArg == "-rgba"
1219 aParams.BufferType = Graphic3d_BT_RGBA;
1221 else if (anArg == "-rgb"
1224 aParams.BufferType = Graphic3d_BT_RGB;
1226 else if (anArg == "-depth"
1227 || anArg == "depth")
1229 aParams.BufferType = Graphic3d_BT_Depth;
1231 else if (anArg == "-width"
1233 || anArg == "sizex")
1235 if (aParams.Width != 0)
1237 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1240 else if (++anArgIter >= theArgNb)
1242 std::cout << "Error: integer value is expected right after 'width'\n";
1245 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1247 else if (anArg == "-height"
1248 || anArg == "height"
1249 || anArg == "-sizey")
1251 if (aParams.Height != 0)
1253 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1256 else if (++anArgIter >= theArgNb)
1258 std::cout << "Error: integer value is expected right after 'height'\n";
1261 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1263 else if (anArg == "-tile"
1264 || anArg == "-tilesize")
1266 if (++anArgIter >= theArgNb)
1268 std::cout << "Error: integer value is expected right after 'tileSize'\n";
1271 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1275 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
1279 if ((aParams.Width <= 0 && aParams.Height > 0)
1280 || (aParams.Width > 0 && aParams.Height <= 0))
1282 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
1286 Handle(V3d_View) aView = ViewerTest::CurrentView();
1289 std::cout << "Error: cannot find an active view!\n";
1293 if (aParams.Width <= 0 || aParams.Height <= 0)
1295 aView->Window()->Size (aParams.Width, aParams.Height);
1298 Image_AlienPixMap aPixMap;
1299 Image_Format aFormat = Image_Format_UNKNOWN;
1300 switch (aParams.BufferType)
1302 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1303 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1304 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1305 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1308 switch (aStereoPair)
1310 case ViewerTest_SP_Single:
1312 if (!aView->ToPixMap (aPixMap, aParams))
1314 theDI << "Fail: view dump failed!\n";
1317 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1318 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1320 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1321 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1325 case ViewerTest_SP_SideBySide:
1327 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1329 theDI << "Fail: not enough memory for image allocation!\n";
1333 Image_PixMap aPixMapL, aPixMapR;
1334 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1335 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1336 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1337 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1339 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1340 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1341 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1342 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1345 theDI << "Fail: view dump failed!\n";
1350 case ViewerTest_SP_OverUnder:
1352 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1354 theDI << "Fail: not enough memory for image allocation!\n";
1358 Image_PixMap aPixMapL, aPixMapR;
1359 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1360 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1361 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1362 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1364 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1365 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1366 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1367 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1370 theDI << "Fail: view dump failed!\n";
1377 if (!aPixMap.Save (aFilePath))
1379 theDI << "Fail: image can not be saved!\n";
1384 enum TypeOfDispOperation
1386 TypeOfDispOperation_SetDispMode,
1387 TypeOfDispOperation_UnsetDispMode
1390 //! Displays,Erase...
1391 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1392 const Standard_Integer theMode,
1393 const TypeOfDispOperation theType,
1394 const Standard_Boolean theToUpdate)
1396 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1399 case TypeOfDispOperation_SetDispMode:
1401 if (!thePrs.IsNull())
1403 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1407 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1411 case TypeOfDispOperation_UnsetDispMode:
1413 if (!thePrs.IsNull())
1415 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1419 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1426 //=======================================================================
1429 //=======================================================================
1430 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1435 std::cout << "Syntax error: wrong number of arguments\n";
1439 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1440 ? TypeOfDispOperation_UnsetDispMode
1441 : TypeOfDispOperation_SetDispMode;
1442 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1443 if (aType == TypeOfDispOperation_UnsetDispMode)
1447 if (aCtx->NbSelected() == 0)
1449 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1453 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1455 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1458 aCtx->UpdateCurrentViewer();
1462 TCollection_AsciiString aName = argv[1];
1463 Handle(AIS_InteractiveObject) aPrs;
1464 if (GetMapOfAIS().Find2 (aName, aPrs)
1467 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1473 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1474 if (aCtx->NbSelected() == 0
1475 && aType == TypeOfDispOperation_SetDispMode)
1477 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1479 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1481 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1483 aCtx->UpdateCurrentViewer();
1487 Handle(AIS_InteractiveObject) aPrs;
1488 TCollection_AsciiString aName (argv[1]);
1489 if (GetMapOfAIS().Find2 (aName, aPrs)
1492 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1499 //=======================================================================
1502 //=======================================================================
1503 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1505 if(argc==1) return 1;
1506 Standard_Integer On = Draw::Atoi(argv[1]);
1507 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1511 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1512 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1513 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1517 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1521 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1525 Ctx->UpdateCurrentViewer();
1528 Handle(AIS_InteractiveObject) IO;
1529 TCollection_AsciiString name = argv[2];
1530 if (GetMapOfAIS().Find2 (name, IO)
1534 Ctx->SubIntensityOn(IO, Standard_True);
1536 Ctx->SubIntensityOff(IO, Standard_True);
1543 //! Auxiliary class to iterate presentations from different collections.
1544 class ViewTest_PrsIter
1548 //! Create and initialize iterator object.
1549 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1550 : mySource (IterSource_All)
1552 NCollection_Sequence<TCollection_AsciiString> aNames;
1553 if (!theName.IsEmpty())
1554 aNames.Append (theName);
1558 //! Create and initialize iterator object.
1559 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1560 : mySource (IterSource_All)
1565 //! Initialize the iterator.
1566 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1568 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1570 mySelIter.Nullify();
1571 myCurrent.Nullify();
1572 myCurrentTrs.Nullify();
1573 if (!mySeq.IsEmpty())
1575 mySource = IterSource_List;
1576 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1578 else if (aCtx->NbSelected() > 0)
1580 mySource = IterSource_Selected;
1582 mySelIter->InitSelected();
1586 mySource = IterSource_All;
1587 myMapIter.Initialize (GetMapOfAIS());
1592 const TCollection_AsciiString& CurrentName() const
1594 return myCurrentName;
1597 const Handle(AIS_InteractiveObject)& Current() const
1602 const Handle(Standard_Transient)& CurrentTrs() const
1604 return myCurrentTrs;
1607 //! @return true if iterator points to valid object within collection
1608 Standard_Boolean More() const
1612 case IterSource_All: return myMapIter.More();
1613 case IterSource_List: return mySeqIter.More();
1614 case IterSource_Selected: return mySelIter->MoreSelected();
1616 return Standard_False;
1619 //! Go to the next item.
1622 myCurrentName.Clear();
1623 myCurrentTrs.Nullify();
1624 myCurrent.Nullify();
1627 case IterSource_All:
1632 case IterSource_List:
1637 case IterSource_Selected:
1639 mySelIter->NextSelected();
1652 case IterSource_All:
1654 if (myMapIter.More())
1656 myCurrentName = myMapIter.Key2();
1657 myCurrentTrs = myMapIter.Key1();
1658 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1662 case IterSource_List:
1664 if (mySeqIter.More())
1666 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1668 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1671 myCurrentName = mySeqIter.Value();
1672 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1673 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1677 case IterSource_Selected:
1679 if (mySelIter->MoreSelected())
1681 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1682 myCurrent = mySelIter->SelectedInteractive();
1700 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1701 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1702 NCollection_Sequence<TCollection_AsciiString> mySeq;
1703 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1705 TCollection_AsciiString myCurrentName;//!< current item name
1706 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1707 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1709 IterSource mySource; //!< iterated collection
1713 //! Parse interior style name.
1714 static bool parseInteriorStyle (const TCollection_AsciiString& theArg,
1715 Aspect_InteriorStyle& theStyle)
1717 TCollection_AsciiString anArg (theArg);
1719 if (anArg == "empty")
1721 theStyle = Aspect_IS_EMPTY;
1723 else if (anArg == "hollow")
1725 theStyle = Aspect_IS_HOLLOW;
1727 else if (anArg == "solid")
1729 theStyle = Aspect_IS_SOLID;
1731 else if (anArg == "hatch")
1733 theStyle = Aspect_IS_HATCH;
1735 else if (anArg == "hiddenline"
1736 || anArg == "hidden-line"
1737 || anArg == "hidden_line")
1739 theStyle = Aspect_IS_HIDDENLINE;
1741 else if (anArg == "point")
1743 theStyle = Aspect_IS_POINT;
1745 else if (theArg.IsIntegerValue())
1747 const Standard_Integer anIntStyle = theArg.IntegerValue();
1748 if (anIntStyle < Aspect_IS_EMPTY || anIntStyle > Aspect_IS_POINT)
1752 theStyle = (Aspect_InteriorStyle)anIntStyle;
1761 //! Auxiliary structure for VAspects
1762 struct ViewerTest_AspectsChangeSet
1764 Standard_Integer ToSetVisibility;
1765 Standard_Integer Visibility;
1767 Standard_Integer ToSetColor;
1768 Quantity_Color Color;
1769 Standard_Integer ToSetBackFaceColor;
1770 Quantity_Color BackFaceColor;
1772 Standard_Integer ToSetLineWidth;
1773 Standard_Real LineWidth;
1775 Standard_Integer ToSetTypeOfLine;
1776 Aspect_TypeOfLine TypeOfLine;
1778 Standard_Integer ToSetTypeOfMarker;
1779 Aspect_TypeOfMarker TypeOfMarker;
1780 Handle(Image_PixMap) MarkerImage;
1782 Standard_Integer ToSetMarkerSize;
1783 Standard_Real MarkerSize;
1785 Standard_Integer ToSetTransparency;
1786 Standard_Real Transparency;
1788 Standard_Integer ToSetAlphaMode;
1789 Graphic3d_AlphaMode AlphaMode;
1790 Standard_ShortReal AlphaCutoff;
1792 Standard_Integer ToSetMaterial;
1793 Graphic3d_NameOfMaterial Material;
1794 TCollection_AsciiString MatName;
1796 NCollection_Sequence<TopoDS_Shape> SubShapes;
1798 Standard_Integer ToSetShowFreeBoundary;
1799 Standard_Integer ToSetFreeBoundaryWidth;
1800 Standard_Real FreeBoundaryWidth;
1801 Standard_Integer ToSetFreeBoundaryColor;
1802 Quantity_Color FreeBoundaryColor;
1804 Standard_Integer ToEnableIsoOnTriangulation;
1806 Standard_Integer ToSetFaceBoundaryDraw;
1807 Standard_Integer ToSetFaceBoundaryUpperContinuity;
1808 GeomAbs_Shape FaceBoundaryUpperContinuity;
1810 Standard_Integer ToSetFaceBoundaryColor;
1811 Quantity_Color FaceBoundaryColor;
1813 Standard_Integer ToSetFaceBoundaryWidth;
1814 Standard_Real FaceBoundaryWidth;
1816 Standard_Integer ToSetTypeOfFaceBoundaryLine;
1817 Aspect_TypeOfLine TypeOfFaceBoundaryLine;
1819 Standard_Integer ToSetMaxParamValue;
1820 Standard_Real MaxParamValue;
1822 Standard_Integer ToSetSensitivity;
1823 Standard_Integer SelectionMode;
1824 Standard_Integer Sensitivity;
1826 Standard_Integer ToSetHatch;
1827 Standard_Integer StdHatchStyle;
1828 TCollection_AsciiString PathToHatchPattern;
1830 Standard_Integer ToSetShadingModel;
1831 Graphic3d_TypeOfShadingModel ShadingModel;
1832 TCollection_AsciiString ShadingModelName;
1834 Standard_Integer ToSetInterior;
1835 Aspect_InteriorStyle InteriorStyle;
1837 Standard_Integer ToSetDrawSilhouette;
1839 Standard_Integer ToSetDrawEdges;
1840 Standard_Integer ToSetQuadEdges;
1842 Standard_Integer ToSetEdgeColor;
1843 Quantity_ColorRGBA EdgeColor;
1845 Standard_Integer ToSetEdgeWidth;
1846 Standard_Real EdgeWidth;
1848 Standard_Integer ToSetTypeOfEdge;
1849 Aspect_TypeOfLine TypeOfEdge;
1851 //! Empty constructor
1852 ViewerTest_AspectsChangeSet()
1853 : ToSetVisibility (0),
1856 Color (DEFAULT_COLOR),
1857 ToSetBackFaceColor(0),
1858 BackFaceColor (DEFAULT_COLOR),
1861 ToSetTypeOfLine (0),
1862 TypeOfLine (Aspect_TOL_SOLID),
1863 ToSetTypeOfMarker (0),
1864 TypeOfMarker (Aspect_TOM_PLUS),
1865 ToSetMarkerSize (0),
1867 ToSetTransparency (0),
1870 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1873 Material (Graphic3d_NOM_DEFAULT),
1874 ToSetShowFreeBoundary (0),
1875 ToSetFreeBoundaryWidth (0),
1876 FreeBoundaryWidth (1.0),
1877 ToSetFreeBoundaryColor (0),
1878 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1879 ToEnableIsoOnTriangulation (0),
1881 ToSetFaceBoundaryDraw (0),
1882 ToSetFaceBoundaryUpperContinuity (0),
1883 FaceBoundaryUpperContinuity(GeomAbs_CN),
1884 ToSetFaceBoundaryColor (0),
1885 FaceBoundaryColor (Quantity_NOC_BLACK),
1886 ToSetFaceBoundaryWidth (0),
1887 FaceBoundaryWidth (1.0f),
1888 ToSetTypeOfFaceBoundaryLine(0),
1889 TypeOfFaceBoundaryLine (Aspect_TOL_SOLID),
1891 ToSetMaxParamValue (0),
1892 MaxParamValue (500000),
1893 ToSetSensitivity (0),
1898 ToSetShadingModel (0),
1899 ShadingModel (Graphic3d_TOSM_DEFAULT),
1901 InteriorStyle (Aspect_IS_SOLID),
1902 ToSetDrawSilhouette (0),
1908 ToSetTypeOfEdge (0),
1909 TypeOfEdge (Aspect_TOL_SOLID)
1912 //! @return true if no changes have been requested
1913 Standard_Boolean IsEmpty() const
1915 return ToSetVisibility == 0
1916 && ToSetLineWidth == 0
1917 && ToSetTransparency == 0
1918 && ToSetAlphaMode == 0
1920 && ToSetBackFaceColor == 0
1921 && ToSetMaterial == 0
1922 && ToSetShowFreeBoundary == 0
1923 && ToSetFreeBoundaryColor == 0
1924 && ToSetFreeBoundaryWidth == 0
1925 && ToEnableIsoOnTriangulation == 0
1926 && ToSetFaceBoundaryDraw == 0
1927 && ToSetFaceBoundaryUpperContinuity == 0
1928 && ToSetFaceBoundaryColor == 0
1929 && ToSetFaceBoundaryWidth == 0
1930 && ToSetTypeOfFaceBoundaryLine == 0
1931 && ToSetMaxParamValue == 0
1932 && ToSetSensitivity == 0
1934 && ToSetShadingModel == 0
1935 && ToSetInterior == 0
1936 && ToSetDrawSilhouette == 0
1937 && ToSetDrawEdges == 0
1938 && ToSetQuadEdges == 0
1939 && ToSetEdgeColor == 0
1940 && ToSetEdgeWidth == 0
1941 && ToSetTypeOfEdge == 0;
1944 //! @return true if properties are valid
1945 Standard_Boolean Validate() const
1947 Standard_Boolean isOk = Standard_True;
1948 if (Visibility != 0 && Visibility != 1)
1950 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1951 isOk = Standard_False;
1953 if (LineWidth <= 0.0
1954 || LineWidth > 10.0)
1956 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1957 isOk = Standard_False;
1959 if (Transparency < 0.0
1960 || Transparency > 1.0)
1962 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1963 isOk = Standard_False;
1965 if (ToSetAlphaMode == 1
1966 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1968 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1969 isOk = Standard_False;
1971 if (FreeBoundaryWidth <= 0.0
1972 || FreeBoundaryWidth > 10.0)
1974 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1975 isOk = Standard_False;
1977 if (MaxParamValue < 0.0)
1979 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1980 isOk = Standard_False;
1982 if (Sensitivity <= 0 && ToSetSensitivity)
1984 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1985 isOk = Standard_False;
1987 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1989 std::cout << "Error: hatch style must be specified\n";
1990 isOk = Standard_False;
1992 if (ToSetShadingModel == 1
1993 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_PBR_FACET))
1995 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1996 isOk = Standard_False;
2001 //! Apply aspects to specified drawer.
2002 bool Apply (const Handle(Prs3d_Drawer)& theDrawer)
2004 bool toRecompute = false;
2005 const Handle(Prs3d_Drawer)& aDefDrawer = ViewerTest::GetAISContext()->DefaultDrawer();
2006 if (ToSetShowFreeBoundary != 0)
2008 theDrawer->SetFreeBoundaryDraw (ToSetShowFreeBoundary == 1);
2011 if (ToSetFreeBoundaryWidth != 0)
2013 if (ToSetFreeBoundaryWidth != -1
2014 || theDrawer->HasOwnFreeBoundaryAspect())
2016 if (!theDrawer->HasOwnFreeBoundaryAspect())
2018 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2019 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
2020 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2023 theDrawer->FreeBoundaryAspect()->SetWidth (FreeBoundaryWidth);
2026 if (ToSetFreeBoundaryColor != 0)
2028 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2029 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
2030 aBoundaryAspect->SetColor (FreeBoundaryColor);
2031 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2034 if (ToSetTypeOfLine != 0)
2036 if (ToSetTypeOfLine != -1
2037 || theDrawer->HasOwnLineAspect()
2038 || theDrawer->HasOwnWireAspect()
2039 || theDrawer->HasOwnFreeBoundaryAspect()
2040 || theDrawer->HasOwnUnFreeBoundaryAspect()
2041 || theDrawer->HasOwnSeenLineAspect())
2043 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
2044 theDrawer->LineAspect()->SetTypeOfLine (TypeOfLine);
2045 theDrawer->WireAspect()->SetTypeOfLine (TypeOfLine);
2046 theDrawer->FreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
2047 theDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
2048 theDrawer->SeenLineAspect()->SetTypeOfLine (TypeOfLine);
2051 if (ToSetTypeOfMarker != 0)
2053 if (ToSetTypeOfMarker != -1
2054 || theDrawer->HasOwnPointAspect())
2056 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
2057 theDrawer->PointAspect()->SetTypeOfMarker (TypeOfMarker);
2058 theDrawer->PointAspect()->Aspect()->SetMarkerImage (MarkerImage.IsNull() ? Handle(Graphic3d_MarkerImage)() : new Graphic3d_MarkerImage (MarkerImage));
2061 if (ToSetMarkerSize != 0)
2063 if (ToSetMarkerSize != -1
2064 || theDrawer->HasOwnPointAspect())
2066 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
2067 theDrawer->PointAspect()->SetScale (MarkerSize);
2071 if (ToSetMaxParamValue != 0)
2073 if (ToSetMaxParamValue != -1
2074 || theDrawer->HasOwnMaximalParameterValue())
2076 theDrawer->SetMaximalParameterValue (MaxParamValue);
2080 if (ToSetFaceBoundaryDraw != 0)
2082 if (ToSetFaceBoundaryDraw != -1
2083 || theDrawer->HasOwnFaceBoundaryDraw())
2086 theDrawer->SetFaceBoundaryDraw (ToSetFaceBoundaryDraw == 1);
2089 if (ToSetFaceBoundaryUpperContinuity != 0)
2091 if (ToSetFaceBoundaryUpperContinuity != -1
2092 || theDrawer->HasOwnFaceBoundaryUpperContinuity())
2095 if (ToSetFaceBoundaryUpperContinuity == -1)
2097 theDrawer->UnsetFaceBoundaryUpperContinuity();
2101 theDrawer->SetFaceBoundaryUpperContinuity (FaceBoundaryUpperContinuity);
2105 if (ToSetFaceBoundaryColor != 0)
2107 if (ToSetFaceBoundaryColor != -1
2108 || theDrawer->HasOwnFaceBoundaryAspect())
2110 if (ToSetFaceBoundaryColor == -1)
2113 theDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
2117 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2118 theDrawer->FaceBoundaryAspect()->SetColor (FaceBoundaryColor);
2122 if (ToSetFaceBoundaryWidth != 0)
2124 if (ToSetFaceBoundaryWidth != -1
2125 || theDrawer->HasOwnFaceBoundaryAspect())
2127 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2128 theDrawer->FaceBoundaryAspect()->SetWidth (FaceBoundaryWidth);
2131 if (ToSetTypeOfFaceBoundaryLine != 0)
2133 if (ToSetTypeOfFaceBoundaryLine != -1
2134 || theDrawer->HasOwnFaceBoundaryAspect())
2136 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2137 theDrawer->FaceBoundaryAspect()->SetTypeOfLine (TypeOfFaceBoundaryLine);
2140 if (ToSetShadingModel != 0)
2142 if (ToSetShadingModel != -1
2143 || theDrawer->HasOwnShadingAspect())
2145 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2146 theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel);
2149 if (ToSetBackFaceColor != 0)
2151 if (ToSetBackFaceColor != -1
2152 || theDrawer->HasOwnShadingAspect())
2154 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2155 theDrawer->ShadingAspect()->SetColor (BackFaceColor, Aspect_TOFM_BACK_SIDE);
2158 if (ToSetAlphaMode != 0)
2160 if (ToSetAlphaMode != -1
2161 || theDrawer->HasOwnShadingAspect())
2163 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2164 theDrawer->ShadingAspect()->Aspect()->SetAlphaMode (AlphaMode, AlphaCutoff);
2167 if (ToSetHatch != 0)
2169 if (ToSetHatch != -1
2170 || theDrawer->HasOwnShadingAspect())
2172 theDrawer->SetupOwnShadingAspect (aDefDrawer);
2173 Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect();
2174 if (ToSetHatch == -1)
2176 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2180 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2181 if (!PathToHatchPattern.IsEmpty())
2183 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2184 if (anImage->Load (TCollection_AsciiString (PathToHatchPattern.ToCString())))
2186 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2190 std::cout << "Error: cannot load the following image: " << PathToHatchPattern << "\n";
2193 else if (StdHatchStyle != -1)
2195 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)StdHatchStyle));
2201 if (ToSetInterior != 0)
2203 if (ToSetInterior != -1
2204 || theDrawer->HasOwnShadingAspect())
2206 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2207 theDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (InteriorStyle);
2208 if (InteriorStyle == Aspect_IS_HATCH
2209 && theDrawer->ShadingAspect()->Aspect()->HatchStyle().IsNull())
2211 theDrawer->ShadingAspect()->Aspect()->SetHatchStyle (Aspect_HS_VERTICAL);
2215 if (ToSetDrawSilhouette != 0)
2217 if (ToSetDrawSilhouette != -1
2218 || theDrawer->HasOwnShadingAspect())
2220 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2221 theDrawer->ShadingAspect()->Aspect()->SetDrawSilhouette (ToSetDrawSilhouette == 1);
2224 if (ToSetDrawEdges != 0)
2226 if (ToSetDrawEdges != -1
2227 || theDrawer->HasOwnShadingAspect())
2229 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2230 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetDrawEdges == 1);
2233 if (ToSetQuadEdges != 0)
2235 if (ToSetQuadEdges != -1
2236 || theDrawer->HasOwnShadingAspect())
2238 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2239 theDrawer->ShadingAspect()->Aspect()->SetSkipFirstEdge (ToSetQuadEdges == 1);
2242 if (ToSetEdgeWidth != 0)
2244 if (ToSetEdgeWidth != -1
2245 || theDrawer->HasOwnShadingAspect())
2247 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2248 theDrawer->ShadingAspect()->Aspect()->SetEdgeWidth (EdgeWidth);
2251 if (ToSetTypeOfEdge != 0)
2253 if (ToSetTypeOfEdge != -1
2254 || theDrawer->HasOwnShadingAspect())
2256 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2257 theDrawer->ShadingAspect()->Aspect()->SetEdgeLineType (TypeOfEdge);
2258 if (ToSetInterior == 0)
2260 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetTypeOfEdge == 1
2261 && TypeOfEdge != Aspect_TOL_EMPTY);
2265 if (ToSetEdgeColor != 0)
2267 if (ToSetEdgeColor != -1
2268 || theDrawer->HasOwnShadingAspect())
2270 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2271 if (ToSetEdgeColor == -1)
2273 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (theDrawer->ShadingAspect()->Aspect()->InteriorColor());
2277 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (EdgeColor);
2285 //==============================================================================
2286 //function : VAspects
2288 //==============================================================================
2289 static Standard_Integer VAspects (Draw_Interpretor& theDI,
2290 Standard_Integer theArgNb,
2291 const char** theArgVec)
2293 TCollection_AsciiString aCmdName (theArgVec[0]);
2294 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2295 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2298 std::cerr << "Error: no active view!\n";
2302 Standard_Integer anArgIter = 1;
2303 Standard_Boolean isDefaults = Standard_False;
2304 NCollection_Sequence<TCollection_AsciiString> aNames;
2305 for (; anArgIter < theArgNb; ++anArgIter)
2307 TCollection_AsciiString anArg = theArgVec[anArgIter];
2308 if (anUpdateTool.parseRedrawMode (anArg))
2312 else if (!anArg.IsEmpty()
2313 && anArg.Value (1) != '-')
2315 aNames.Append (anArg);
2319 if (anArg == "-defaults")
2321 isDefaults = Standard_True;
2328 if (!aNames.IsEmpty() && isDefaults)
2330 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
2334 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
2335 aChanges.Append (ViewerTest_AspectsChangeSet());
2336 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
2338 // parse syntax of legacy commands
2339 bool toParseAliasArgs = false;
2340 Standard_Boolean toDump = 0;
2341 Standard_Boolean toCompactDump = 0;
2342 Standard_Integer aDumpDepth = -1;
2343 if (aCmdName == "vsetwidth")
2345 if (aNames.IsEmpty()
2346 || !aNames.Last().IsRealValue())
2348 std::cout << "Error: not enough arguments!\n";
2351 aChangeSet->ToSetLineWidth = 1;
2352 aChangeSet->LineWidth = aNames.Last().RealValue();
2353 aNames.Remove (aNames.Length());
2355 else if (aCmdName == "vunsetwidth")
2357 aChangeSet->ToSetLineWidth = -1;
2359 else if (aCmdName == "vsetcolor")
2361 if (aNames.IsEmpty())
2363 std::cout << "Error: not enough arguments!\n";
2366 aChangeSet->ToSetColor = 1;
2368 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2369 Standard_Boolean isOk = Standard_False;
2370 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
2372 aChangeSet->Color = aColor;
2373 aNames.Remove (aNames.Length());
2374 isOk = Standard_True;
2376 else if (Quantity_Color::ColorFromHex (aNames.Last().ToCString(), aChangeSet->Color))
2378 aNames.Remove (aNames.Length());
2379 isOk = Standard_True;
2381 else if (aNames.Length() >= 3)
2383 const char* anArgVec[3] =
2385 aNames.Value (aNames.Upper() - 2).ToCString(),
2386 aNames.Value (aNames.Upper() - 1).ToCString(),
2387 aNames.Value (aNames.Upper() - 0).ToCString(),
2390 Standard_Integer aNbParsed = ViewerTest::ParseColor (3, anArgVec, aChangeSet->Color);
2391 isOk = aNbParsed == 3;
2392 aNames.Remove (aNames.Length());
2393 aNames.Remove (aNames.Length());
2394 aNames.Remove (aNames.Length());
2398 std::cout << "Error: not enough arguments!\n";
2402 else if (aCmdName == "vunsetcolor")
2404 aChangeSet->ToSetColor = -1;
2406 else if (aCmdName == "vsettransparency")
2408 if (aNames.IsEmpty()
2409 || !aNames.Last().IsRealValue())
2411 std::cout << "Error: not enough arguments!\n";
2414 aChangeSet->ToSetTransparency = 1;
2415 aChangeSet->Transparency = aNames.Last().RealValue();
2416 aNames.Remove (aNames.Length());
2418 else if (aCmdName == "vunsettransparency")
2420 aChangeSet->ToSetTransparency = -1;
2422 else if (aCmdName == "vsetmaterial")
2424 if (aNames.IsEmpty())
2426 std::cout << "Error: not enough arguments!\n";
2429 aChangeSet->ToSetMaterial = 1;
2430 aChangeSet->MatName = aNames.Last();
2431 aNames.Remove (aNames.Length());
2432 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
2434 std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n";
2438 else if (aCmdName == "vunsetmaterial")
2440 aChangeSet->ToSetMaterial = -1;
2442 else if (aCmdName == "vsetinteriorstyle")
2444 if (aNames.IsEmpty()
2445 || !aNames.Last().IsRealValue())
2447 std::cout << "Error: not enough arguments!\n";
2450 aChangeSet->ToSetInterior = 1;
2451 if (!parseInteriorStyle (aNames.Last(), aChangeSet->InteriorStyle))
2453 std::cout << "Error: wrong syntax at " << aNames.Last() << "\n";
2456 aNames.Remove (aNames.Length());
2458 else if (aCmdName == "vsetedgetype")
2460 aChangeSet->ToSetDrawEdges = 1;
2461 toParseAliasArgs = true;
2463 else if (aCmdName == "vunsetedgetype")
2465 aChangeSet->ToSetDrawEdges = -1;
2466 aChangeSet->ToSetEdgeColor = -1;
2467 aChangeSet->ToSetTypeOfEdge = -1;
2468 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
2470 else if (aCmdName == "vshowfaceboundary")
2472 aChangeSet->ToSetFaceBoundaryDraw = 1;
2473 toParseAliasArgs = true;
2474 if (aNames.Size() >= 2
2475 && aNames.Value (2).IsIntegerValue())
2477 if (aNames.Size() == 7)
2479 if (ViewerTest::ParseLineType (aNames.Value (7).ToCString(), aChangeSet->TypeOfFaceBoundaryLine))
2481 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2485 if (aNames.Size() == 6
2486 && aNames.Value (6).IsRealValue())
2488 aChangeSet->ToSetFaceBoundaryWidth = 1;
2489 aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue();
2492 if (aNames.Size() == 5
2493 && aNames.Value (3).IsIntegerValue()
2494 && aNames.Value (4).IsIntegerValue()
2495 && aNames.Value (5).IsIntegerValue())
2497 aChangeSet->ToSetFaceBoundaryColor = 1;
2498 aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0,
2499 aNames.Value (4).IntegerValue() / 255.0,
2500 aNames.Value (5).IntegerValue() / 255.0,
2506 if (aNames.Size() == 2)
2508 toParseAliasArgs = false;
2509 aChangeSet->ToSetFaceBoundaryDraw = aNames.Value (2).IntegerValue() == 1 ? 1 : -1;
2514 else if (anArgIter >= theArgNb)
2516 std::cout << "Error: not enough arguments!\n";
2520 if (!aChangeSet->IsEmpty()
2521 && !toParseAliasArgs)
2523 anArgIter = theArgNb;
2525 for (; anArgIter < theArgNb; ++anArgIter)
2527 TCollection_AsciiString anArg = theArgVec[anArgIter];
2529 if (anArg == "-setwidth"
2530 || anArg == "-width"
2531 || anArg == "-setlinewidth"
2532 || anArg == "-linewidth"
2533 || anArg == "-setedgewidth"
2534 || anArg == "-setedgeswidth"
2535 || anArg == "-edgewidth"
2536 || anArg == "-edgeswidth"
2537 || anArg == "-setfaceboundarywidth"
2538 || anArg == "-setboundarywidth"
2539 || anArg == "-faceboundarywidth"
2540 || anArg == "-boundarywidth")
2542 if (++anArgIter >= theArgNb)
2544 std::cout << "Error: wrong syntax at " << anArg << "\n";
2548 const Standard_Real aWidth = Draw::Atof (theArgVec[anArgIter]);
2549 if (anArg == "-setedgewidth"
2550 || anArg == "-setedgeswidth"
2551 || anArg == "-edgewidth"
2552 || anArg == "-edgeswidth"
2553 || aCmdName == "vsetedgetype")
2555 aChangeSet->ToSetEdgeWidth = 1;
2556 aChangeSet->EdgeWidth = aWidth;
2558 else if (anArg == "-setfaceboundarywidth"
2559 || anArg == "-setboundarywidth"
2560 || anArg == "-faceboundarywidth"
2561 || anArg == "-boundarywidth"
2562 || aCmdName == "vshowfaceboundary")
2564 aChangeSet->ToSetFaceBoundaryWidth = 1;
2565 aChangeSet->FaceBoundaryWidth = aWidth;
2569 aChangeSet->ToSetLineWidth = 1;
2570 aChangeSet->LineWidth = aWidth;
2573 else if (anArg == "-unsetwidth"
2574 || anArg == "-unsetlinewidth"
2575 || anArg == "-unsetedgewidth")
2577 if (anArg == "-unsetedgewidth")
2579 aChangeSet->ToSetEdgeWidth = -1;
2580 aChangeSet->EdgeWidth = 1.0;
2584 aChangeSet->ToSetLineWidth = -1;
2585 aChangeSet->LineWidth = 1.0;
2588 else if (anArg == "-settransp"
2589 || anArg == "-settransparency"
2590 || anArg == "-transparency"
2591 || anArg == "-transp")
2593 if (++anArgIter >= theArgNb)
2595 std::cout << "Error: wrong syntax at " << anArg << "\n";
2598 aChangeSet->ToSetTransparency = 1;
2599 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2600 if (aChangeSet->Transparency >= 0.0
2601 && aChangeSet->Transparency <= Precision::Confusion())
2603 aChangeSet->ToSetTransparency = -1;
2604 aChangeSet->Transparency = 0.0;
2607 else if (anArg == "-setalphamode"
2608 || anArg == "-alphamode")
2610 if (++anArgIter >= theArgNb)
2612 std::cout << "Error: wrong syntax at " << anArg << "\n";
2615 aChangeSet->ToSetAlphaMode = 1;
2616 aChangeSet->AlphaCutoff = 0.5f;
2618 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2620 if (aParam == "opaque")
2622 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2624 else if (aParam == "mask")
2626 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2628 else if (aParam == "blend")
2630 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2632 else if (aParam == "blendauto"
2633 || aParam == "auto")
2635 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2639 std::cout << "Error: wrong syntax at " << aParam << "\n";
2644 if (anArgIter + 1 < theArgNb
2645 && theArgVec[anArgIter + 1][0] != '-')
2647 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2648 if (aParam2.IsRealValue())
2650 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2655 else if (anArg == "-setvis"
2656 || anArg == "-setvisibility"
2657 || anArg == "-visibility")
2659 if (++anArgIter >= theArgNb)
2661 std::cout << "Error: wrong syntax at " << anArg << "\n";
2665 aChangeSet->ToSetVisibility = 1;
2666 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2668 else if (anArg == "-setalpha"
2669 || anArg == "-alpha")
2671 if (++anArgIter >= theArgNb)
2673 std::cout << "Error: wrong syntax at " << anArg << "\n";
2676 aChangeSet->ToSetTransparency = 1;
2677 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2678 if (aChangeSet->Transparency < 0.0
2679 || aChangeSet->Transparency > 1.0)
2681 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2684 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2685 if (aChangeSet->Transparency >= 0.0
2686 && aChangeSet->Transparency <= Precision::Confusion())
2688 aChangeSet->ToSetTransparency = -1;
2689 aChangeSet->Transparency = 0.0;
2692 else if (anArg == "-unsettransp"
2693 || anArg == "-unsettransparency"
2694 || anArg == "-unsetalpha"
2695 || anArg == "-opaque")
2697 aChangeSet->ToSetTransparency = -1;
2698 aChangeSet->Transparency = 0.0;
2700 else if (anArg == "-setcolor"
2701 || anArg == "-color"
2702 || anArg == "-setbackfacecolor"
2703 || anArg == "-backfacecolor"
2704 || anArg == "-setbackcolor"
2705 || anArg == "-backcolor"
2706 || anArg == "-setfaceboundarycolor"
2707 || anArg == "-setboundarycolor"
2708 || anArg == "-faceboundarycolor"
2709 || anArg == "-boundarycolor")
2711 Quantity_Color aColor;
2712 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2713 theArgVec + anArgIter + 1,
2717 std::cout << "Syntax error at '" << anArg << "'\n";
2720 anArgIter += aNbParsed;
2721 if (aCmdName == "vsetedgetype")
2723 aChangeSet->ToSetEdgeColor = 1;
2724 aChangeSet->EdgeColor = Quantity_ColorRGBA (aColor);
2726 else if (aCmdName == "vshowfaceboundary"
2727 || anArg == "-setfaceboundarycolor"
2728 || anArg == "-setboundarycolor"
2729 || anArg == "-faceboundarycolor"
2730 || anArg == "-boundarycolor")
2732 aChangeSet->ToSetFaceBoundaryColor = 1;
2733 aChangeSet->FaceBoundaryColor = aColor;
2735 else if (anArg == "-setbackfacecolor"
2736 || anArg == "-backfacecolor"
2737 || anArg == "-setbackcolor"
2738 || anArg == "-backcolor")
2740 aChangeSet->ToSetBackFaceColor = 1;
2741 aChangeSet->BackFaceColor = aColor;
2745 aChangeSet->ToSetColor = 1;
2746 aChangeSet->Color = aColor;
2749 else if (anArg == "-setlinetype"
2750 || anArg == "-linetype"
2751 || anArg == "-setedgetype"
2752 || anArg == "-setedgestype"
2753 || anArg == "-edgetype"
2754 || anArg == "-edgestype"
2755 || anArg == "-setfaceboundarystyle"
2756 || anArg == "-faceboundarystyle"
2757 || anArg == "-boundarystyle"
2758 || anArg == "-setfaceboundarytype"
2759 || anArg == "-faceboundarytype"
2760 || anArg == "-setboundarytype"
2761 || anArg == "-boundarytype"
2762 || anArg == "-type")
2764 if (++anArgIter >= theArgNb)
2766 std::cout << "Error: wrong syntax at " << anArg << "\n";
2769 Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY;
2770 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType))
2772 std::cout << "Error: wrong syntax at " << anArg << "\n";
2775 if (anArg == "-setedgetype"
2776 || anArg == "-setedgestype"
2777 || anArg == "-edgetype"
2778 || anArg == "-edgestype"
2779 || aCmdName == "vsetedgetype")
2781 aChangeSet->TypeOfEdge = aLineType;
2782 aChangeSet->ToSetTypeOfEdge = 1;
2784 else if (anArg == "-setfaceboundarystyle"
2785 || anArg == "-faceboundarystyle"
2786 || anArg == "-boundarystyle"
2787 || anArg == "-setfaceboundarytype"
2788 || anArg == "-faceboundarytype"
2789 || anArg == "-setboundarytype"
2790 || anArg == "-boundarytype"
2791 || aCmdName == "vshowfaceboundary")
2793 aChangeSet->TypeOfFaceBoundaryLine = aLineType;
2794 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2798 aChangeSet->TypeOfLine = aLineType;
2799 aChangeSet->ToSetTypeOfLine = 1;
2802 else if (anArg == "-unsetlinetype"
2803 || anArg == "-unsetedgetype"
2804 || anArg == "-unsetedgestype")
2806 if (anArg == "-unsetedgetype"
2807 || anArg == "-unsetedgestype")
2809 aChangeSet->ToSetTypeOfEdge = -1;
2813 aChangeSet->ToSetTypeOfLine = -1;
2816 else if (anArg == "-setmarkertype"
2817 || anArg == "-markertype"
2818 || anArg == "-setpointtype"
2819 || anArg == "-pointtype")
2821 if (++anArgIter >= theArgNb)
2823 std::cout << "Error: wrong syntax at " << anArg << "\n";
2826 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2828 std::cout << "Error: wrong syntax at " << anArg << "\n";
2832 aChangeSet->ToSetTypeOfMarker = 1;
2834 else if (anArg == "-unsetmarkertype"
2835 || anArg == "-unsetpointtype")
2837 aChangeSet->ToSetTypeOfMarker = -1;
2839 else if (anArg == "-setmarkersize"
2840 || anArg == "-markersize"
2841 || anArg == "-setpointsize"
2842 || anArg == "-pointsize")
2844 if (++anArgIter >= theArgNb)
2846 std::cout << "Error: wrong syntax at " << anArg << "\n";
2849 aChangeSet->ToSetMarkerSize = 1;
2850 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2852 else if (anArg == "-unsetmarkersize"
2853 || anArg == "-unsetpointsize")
2855 aChangeSet->ToSetMarkerSize = -1;
2856 aChangeSet->MarkerSize = 1.0;
2858 else if (anArg == "-unsetcolor")
2860 aChangeSet->ToSetColor = -1;
2861 aChangeSet->Color = DEFAULT_COLOR;
2863 else if (anArg == "-setmat"
2865 || anArg == "-setmaterial"
2866 || anArg == "-material")
2868 if (++anArgIter >= theArgNb)
2870 std::cout << "Error: wrong syntax at " << anArg << "\n";
2873 aChangeSet->ToSetMaterial = 1;
2874 aChangeSet->MatName = theArgVec[anArgIter];
2875 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
2877 std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n";
2881 else if (anArg == "-unsetmat"
2882 || anArg == "-unsetmaterial")
2884 aChangeSet->ToSetMaterial = -1;
2885 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2887 else if (anArg == "-subshape"
2888 || anArg == "-subshapes")
2892 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2896 if (aNames.IsEmpty())
2898 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2902 aChanges.Append (ViewerTest_AspectsChangeSet());
2903 aChangeSet = &aChanges.ChangeLast();
2905 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2907 Standard_CString aSubShapeName = theArgVec[anArgIter];
2908 if (*aSubShapeName == '-')
2914 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2915 if (aSubShape.IsNull())
2917 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2920 aChangeSet->SubShapes.Append (aSubShape);
2923 if (aChangeSet->SubShapes.IsEmpty())
2925 std::cerr << "Error: empty list is specified after -subshapes!\n";
2929 else if (anArg == "-setfreeboundary"
2930 || anArg == "-freeboundary"
2931 || anArg == "-setfb"
2934 bool toEnable = true;
2935 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2937 std::cout << "Error: wrong syntax at " << anArg << "\n";
2941 aChangeSet->ToSetShowFreeBoundary = toEnable ? 1 : -1;
2943 else if (anArg == "-setfreeboundarywidth"
2944 || anArg == "-freeboundarywidth"
2945 || anArg == "-setfbwidth"
2946 || anArg == "-fbwidth")
2948 if (++anArgIter >= theArgNb)
2950 std::cout << "Error: wrong syntax at " << anArg << "\n";
2953 aChangeSet->ToSetFreeBoundaryWidth = 1;
2954 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2956 else if (anArg == "-unsetfreeboundarywidth"
2957 || anArg == "-unsetfbwidth")
2959 aChangeSet->ToSetFreeBoundaryWidth = -1;
2960 aChangeSet->FreeBoundaryWidth = 1.0;
2962 else if (anArg == "-setfreeboundarycolor"
2963 || anArg == "-freeboundarycolor"
2964 || anArg == "-setfbcolor"
2965 || anArg == "-fbcolor")
2967 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2968 theArgVec + anArgIter + 1,
2969 aChangeSet->FreeBoundaryColor);
2972 std::cout << "Syntax error at '" << anArg << "'\n";
2975 anArgIter += aNbParsed;
2976 aChangeSet->ToSetFreeBoundaryColor = 1;
2978 else if (anArg == "-unsetfreeboundarycolor"
2979 || anArg == "-unsetfbcolor")
2981 aChangeSet->ToSetFreeBoundaryColor = -1;
2982 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2984 else if (anArg == "-setisoontriangulation"
2985 || anArg == "-isoontriangulation"
2986 || anArg == "-setisoontriang"
2987 || anArg == "-isoontriang")
2989 bool toEnable = true;
2990 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2992 std::cout << "Error: wrong syntax at " << anArg << "\n";
2996 aChangeSet->ToEnableIsoOnTriangulation = toEnable ? 1 : -1;
2998 else if (anArg == "-setfaceboundarydraw"
2999 || anArg == "-setdrawfaceboundary"
3000 || anArg == "-setdrawfaceboundaries"
3001 || anArg == "-setshowfaceboundary"
3002 || anArg == "-setshowfaceboundaries"
3003 || anArg == "-setdrawfaceedges"
3004 || anArg == "-faceboundarydraw"
3005 || anArg == "-drawfaceboundary"
3006 || anArg == "-drawfaceboundaries"
3007 || anArg == "-showfaceboundary"
3008 || anArg == "-showfaceboundaries"
3009 || anArg == "-drawfaceedges"
3010 || anArg == "-faceboundary"
3011 || anArg == "-faceboundaries"
3012 || anArg == "-faceedges")
3014 bool toEnable = true;
3015 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
3017 std::cout << "Error: wrong syntax at " << anArg << "\n";
3021 aChangeSet->ToSetFaceBoundaryDraw = toEnable ? 1 : -1;
3023 else if (anArg == "-unsetfaceboundary"
3024 || anArg == "-unsetboundary")
3026 aChangeSet->ToSetFaceBoundaryDraw = -1;
3027 aChangeSet->ToSetFaceBoundaryColor = -1;
3029 else if (anArg == "-setmostcontinuity"
3030 || anArg == "-mostcontinuity")
3032 TCollection_AsciiString aClassArg (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "");
3033 aClassArg.LowerCase();
3034 GeomAbs_Shape aClass = GeomAbs_CN;
3035 if (aClassArg == "c0"
3036 || aClassArg == "0")
3038 aClass = GeomAbs_C0;
3040 else if (aClassArg == "c1"
3041 || aClassArg == "1")
3043 aClass = GeomAbs_C1;
3045 else if (aClassArg == "c2"
3046 || aClassArg == "2")
3048 aClass = GeomAbs_C2;
3050 else if (aClassArg == "c3"
3051 || aClassArg == "3")
3053 aClass = GeomAbs_C3;
3055 else if (aClassArg == "cn"
3056 || aClassArg == "n")
3058 aClass = GeomAbs_CN;
3062 std::cout << "Syntax error at '" << anArg << "'\n";
3067 aChangeSet->ToSetFaceBoundaryUpperContinuity = 1;
3068 aChangeSet->FaceBoundaryUpperContinuity = aClass;
3070 else if (anArg == "-setmaxparamvalue"
3071 || anArg == "-maxparamvalue")
3073 if (++anArgIter >= theArgNb)
3075 std::cout << "Error: wrong syntax at " << anArg << "\n";
3078 aChangeSet->ToSetMaxParamValue = 1;
3079 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
3081 else if (anArg == "-setsensitivity"
3082 || anArg == "-sensitivity")
3086 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
3090 if (aNames.IsEmpty())
3092 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
3096 if (anArgIter + 2 >= theArgNb)
3098 std::cout << "Error: wrong syntax at " << anArg << "\n";
3101 aChangeSet->ToSetSensitivity = 1;
3102 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
3103 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
3105 else if (anArg == "-sethatch"
3106 || anArg == "-hatch")
3110 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
3114 if (aNames.IsEmpty())
3116 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
3120 aChangeSet->ToSetHatch = 1;
3121 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
3122 if (anArgHatch.Length() <= 2)
3124 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
3126 || anIntStyle >= Aspect_HS_NB)
3128 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
3131 aChangeSet->StdHatchStyle = anIntStyle;
3135 aChangeSet->PathToHatchPattern = anArgHatch;
3138 else if (anArg == "-setshadingmodel"
3139 || anArg == "-setshading"
3140 || anArg == "-shadingmodel"
3141 || anArg == "-shading")
3143 if (++anArgIter >= theArgNb)
3145 std::cout << "Error: wrong syntax at " << anArg << "\n";
3148 aChangeSet->ToSetShadingModel = 1;
3149 aChangeSet->ShadingModelName = theArgVec[anArgIter];
3150 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
3152 std::cout << "Error: wrong syntax at " << anArg << "\n";
3156 else if (anArg == "-unsetshadingmodel")
3158 aChangeSet->ToSetShadingModel = -1;
3159 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
3161 else if (anArg == "-setinterior"
3162 || anArg == "-setinteriorstyle"
3163 || anArg == "-interior"
3164 || anArg == "-interiorstyle")
3166 if (++anArgIter >= theArgNb)
3168 std::cout << "Error: wrong syntax at " << anArg << "\n";
3171 aChangeSet->ToSetInterior = 1;
3172 if (!parseInteriorStyle (theArgVec[anArgIter], aChangeSet->InteriorStyle))
3174 std::cout << "Error: wrong syntax at " << anArg << "\n";
3178 else if (anArg == "-unsetinterior")
3180 aChangeSet->ToSetInterior = -1;
3181 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3183 else if (anArg == "-setdrawoutline"
3184 || anArg == "-setdrawsilhouette"
3185 || anArg == "-setoutline"
3186 || anArg == "-setsilhouette"
3187 || anArg == "-outline"
3188 || anArg == "-outlined"
3189 || anArg == "-silhouette")
3191 bool toDrawOutline = true;
3192 if (anArgIter + 1 < theArgNb
3193 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawOutline))
3197 aChangeSet->ToSetDrawSilhouette = toDrawOutline ? 1 : -1;
3199 else if (anArg == "-setdrawedges"
3200 || anArg == "-setdrawedge"
3201 || anArg == "-drawedges"
3202 || anArg == "-drawedge"
3203 || anArg == "-edges")
3205 bool toDrawEdges = true;
3206 if (anArgIter + 1 < theArgNb
3207 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawEdges))
3211 aChangeSet->ToSetDrawEdges = toDrawEdges ? 1 : -1;
3213 else if (anArg == "-setquadedges"
3214 || anArg == "-setquads"
3215 || anArg == "-quads"
3216 || anArg == "-skipfirstedge")
3218 bool isQuadMode = true;
3219 if (anArgIter + 1 < theArgNb
3220 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isQuadMode))
3224 aChangeSet->ToSetQuadEdges = isQuadMode ? 1 : -1;
3226 else if (anArg == "-setedgecolor"
3227 || anArg == "-setedgescolor"
3228 || anArg == "-edgecolor"
3229 || anArg == "-edgescolor")
3231 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3232 theArgVec + anArgIter + 1,
3233 aChangeSet->EdgeColor);
3236 std::cout << "Syntax error at '" << anArg << "'\n";
3239 anArgIter += aNbParsed;
3240 aChangeSet->ToSetEdgeColor = 1;
3242 else if (anArg == "-unset")
3244 aChangeSet->ToSetVisibility = 1;
3245 aChangeSet->Visibility = 1;
3246 aChangeSet->ToSetLineWidth = -1;
3247 aChangeSet->LineWidth = 1.0;
3248 aChangeSet->ToSetTypeOfLine = -1;
3249 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
3250 aChangeSet->ToSetTypeOfMarker = -1;
3251 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
3252 aChangeSet->ToSetMarkerSize = -1;
3253 aChangeSet->MarkerSize = 1.0;
3254 aChangeSet->ToSetTransparency = -1;
3255 aChangeSet->Transparency = 0.0;
3256 aChangeSet->ToSetAlphaMode = -1;
3257 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
3258 aChangeSet->AlphaCutoff = 0.5f;
3259 aChangeSet->ToSetColor = -1;
3260 aChangeSet->Color = DEFAULT_COLOR;
3261 //aChangeSet->ToSetBackFaceColor = -1; // should be reset by ToSetColor
3262 //aChangeSet->BackFaceColor = DEFAULT_COLOR;
3263 aChangeSet->ToSetMaterial = -1;
3264 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
3265 aChangeSet->ToSetShowFreeBoundary = -1;
3266 aChangeSet->ToSetFreeBoundaryColor = -1;
3267 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
3268 aChangeSet->ToSetFreeBoundaryWidth = -1;
3269 aChangeSet->FreeBoundaryWidth = 1.0;
3270 aChangeSet->ToEnableIsoOnTriangulation = -1;
3272 aChangeSet->ToSetFaceBoundaryDraw = -1;
3273 aChangeSet->ToSetFaceBoundaryUpperContinuity = -1;
3274 aChangeSet->FaceBoundaryUpperContinuity = GeomAbs_CN;
3275 aChangeSet->ToSetFaceBoundaryColor = -1;
3276 aChangeSet->FaceBoundaryColor = Quantity_NOC_BLACK;
3277 aChangeSet->ToSetFaceBoundaryWidth = -1;
3278 aChangeSet->FaceBoundaryWidth = 1.0f;
3279 aChangeSet->ToSetTypeOfFaceBoundaryLine = -1;
3280 aChangeSet->TypeOfFaceBoundaryLine = Aspect_TOL_SOLID;
3282 aChangeSet->ToSetHatch = -1;
3283 aChangeSet->StdHatchStyle = -1;
3284 aChangeSet->PathToHatchPattern.Clear();
3285 aChangeSet->ToSetShadingModel = -1;
3286 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
3287 aChangeSet->ToSetInterior = -1;
3288 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3289 aChangeSet->ToSetDrawSilhouette = -1;
3290 aChangeSet->ToSetDrawEdges = -1;
3291 aChangeSet->ToSetQuadEdges = -1;
3292 aChangeSet->ToSetEdgeColor = -1;
3293 aChangeSet->EdgeColor = Quantity_ColorRGBA (DEFAULT_COLOR);
3294 aChangeSet->ToSetEdgeWidth = -1;
3295 aChangeSet->EdgeWidth = 1.0;
3296 aChangeSet->ToSetTypeOfEdge = -1;
3297 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
3299 else if (anArg == "-dumpjson")
3301 toDump = Standard_True;
3303 else if (anArg == "-dumpcompact")
3305 toCompactDump = Standard_False;
3306 if (++anArgIter >= theArgNb && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toCompactDump))
3309 else if (anArg == "-dumpdepth")
3311 if (++anArgIter >= theArgNb)
3313 std::cout << "Error: wrong syntax at " << anArg << "\n";
3316 aDumpDepth = Draw::Atoi (theArgVec[anArgIter]);
3320 std::cout << "Error: wrong syntax at " << anArg << "\n";
3325 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3326 aChangesIter.More(); aChangesIter.Next())
3328 if (!aChangesIter.Value().Validate())
3334 // special case for -defaults parameter.
3335 // all changed values will be set to DefaultDrawer.
3338 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
3339 aChangeSet->Apply (aDrawer);
3340 if (aChangeSet->ToSetLineWidth != 0)
3342 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
3343 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
3344 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
3345 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
3347 if (aChangeSet->ToSetColor != 0)
3349 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
3350 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
3351 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
3352 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
3353 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
3354 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
3356 if (aChangeSet->ToSetTransparency != 0)
3358 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
3360 if (aChangeSet->ToSetMaterial != 0)
3362 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
3364 if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3366 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
3369 // redisplay all objects in context
3370 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3372 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3375 aCtx->Redisplay (aPrs, Standard_False);
3380 Standard_SStream aStream;
3381 aDrawer->DumpJson (aStream, aDumpDepth);
3384 theDI << Standard_Dump::Text (aStream);
3386 theDI << Standard_Dump::FormatJson (aStream);
3391 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3393 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
3394 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3400 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
3401 Handle(AIS_ColoredShape) aColoredPrs;
3402 Standard_Boolean toDisplay = Standard_False;
3403 Standard_Boolean toRedisplay = Standard_False;
3404 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
3406 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
3407 if (aShapePrs.IsNull())
3409 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
3412 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
3413 if (aColoredPrs.IsNull())
3415 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3416 if (aShapePrs->HasDisplayMode())
3418 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
3420 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
3421 aCtx->Remove (aShapePrs, Standard_False);
3422 GetMapOfAIS().UnBind2 (aName);
3423 GetMapOfAIS().Bind (aColoredPrs, aName);
3424 toDisplay = Standard_True;
3425 aShapePrs = aColoredPrs;
3432 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3433 aChangeSet = &aChangesIter.ChangeValue();
3434 if (aChangeSet->ToSetVisibility == 1)
3436 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
3437 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
3439 else if (aChangeSet->ToSetMaterial == 1)
3441 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
3443 else if (aChangeSet->ToSetMaterial == -1)
3445 aCtx->UnsetMaterial (aPrs, Standard_False);
3447 if (aChangeSet->ToSetColor == 1)
3449 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
3451 else if (aChangeSet->ToSetColor == -1)
3453 aCtx->UnsetColor (aPrs, Standard_False);
3455 if (aChangeSet->ToSetTransparency == 1)
3457 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
3459 else if (aChangeSet->ToSetTransparency == -1)
3461 aCtx->UnsetTransparency (aPrs, Standard_False);
3463 if (aChangeSet->ToSetLineWidth == 1)
3465 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
3467 else if (aChangeSet->ToSetLineWidth == -1)
3469 aCtx->UnsetWidth (aPrs, Standard_False);
3471 else if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3473 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
3474 toRedisplay = Standard_True;
3476 else if (aChangeSet->ToSetSensitivity != 0)
3478 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3480 if (!aDrawer.IsNull())
3482 toRedisplay = aChangeSet->Apply (aDrawer) || toRedisplay;
3485 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
3487 aChangeSet = &aChangesIter.ChangeValue();
3488 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
3489 aSubShapeIter.More(); aSubShapeIter.Next())
3491 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
3492 if (!aChangeSet->IsEmpty())
3494 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3495 aChangeSet->Apply (aCurColDrawer);
3497 if (aChangeSet->ToSetVisibility == 1)
3499 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3500 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
3502 if (aChangeSet->ToSetColor == 1)
3504 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
3506 if (aChangeSet->ToSetTransparency == 1)
3508 aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency);
3510 if (aChangeSet->ToSetLineWidth == 1)
3512 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
3514 if (aChangeSet->ToSetColor == -1
3515 || aChangeSet->ToSetLineWidth == -1)
3517 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
3519 if (aChangeSet->ToSetSensitivity != 0)
3521 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3527 aCtx->Display (aPrs, Standard_False);
3531 aCtx->Redisplay (aPrs, Standard_False);
3533 else if (!aColoredPrs.IsNull())
3535 aCtx->Redisplay (aColoredPrs, Standard_False);
3539 aPrs->SynchronizeAspects();
3544 Standard_SStream aStream;
3545 aDrawer->DumpJson (aStream);
3547 theDI << aName << ": \n";
3548 theDI << Standard_Dump::FormatJson (aStream);
3556 //==============================================================================
3557 //function : VDonly2
3559 //purpose : Display only a selected or named object
3560 // if there is no selected or named object s, nothing is done
3561 //==============================================================================
3562 static int VDonly2 (Draw_Interpretor& ,
3563 Standard_Integer theArgNb,
3564 const char** theArgVec)
3566 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3567 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3570 std::cerr << "Error: no active view!\n";
3574 Standard_Integer anArgIter = 1;
3575 for (; anArgIter < theArgNb; ++anArgIter)
3577 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3583 NCollection_Map<Handle(Standard_Transient)> aDispSet;
3584 if (anArgIter >= theArgNb)
3586 // display only selected objects
3587 if (aCtx->NbSelected() < 1)
3592 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3594 aDispSet.Add (aCtx->SelectedInteractive());
3599 // display only specified objects
3600 for (; anArgIter < theArgNb; ++anArgIter)
3602 TCollection_AsciiString aName = theArgVec[anArgIter];
3603 Handle(AIS_InteractiveObject) aShape;
3604 if (GetMapOfAIS().Find2 (aName, aShape)
3605 && !aShape.IsNull())
3607 aCtx->Display (aShape, Standard_False);
3608 aDispSet.Add (aShape);
3613 // weed out other objects
3614 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
3616 if (aDispSet.Contains (anIter.Key1()))
3621 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
3623 aCtx->Erase (aShape, Standard_False);
3629 //==============================================================================
3630 //function : VRemove
3631 //purpose : Removes selected or named objects.
3632 // If there is no selected or named objects,
3633 // all objects in the viewer can be removed with argument -all.
3634 // If -context is in arguments, the object is not deleted from the map of
3635 // objects (deleted only from the current context).
3636 //==============================================================================
3637 int VRemove (Draw_Interpretor& theDI,
3638 Standard_Integer theArgNb,
3639 const char** theArgVec)
3641 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3642 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3645 std::cerr << "Error: no active view!\n";
3649 Standard_Boolean isContextOnly = Standard_False;
3650 Standard_Boolean toRemoveAll = Standard_False;
3651 Standard_Boolean toPrintInfo = Standard_True;
3652 Standard_Boolean toFailOnError = Standard_True;
3654 Standard_Integer anArgIter = 1;
3655 for (; anArgIter < theArgNb; ++anArgIter)
3657 TCollection_AsciiString anArg = theArgVec[anArgIter];
3659 if (anArg == "-context")
3661 isContextOnly = Standard_True;
3663 else if (anArg == "-all")
3665 toRemoveAll = Standard_True;
3667 else if (anArg == "-noinfo")
3669 toPrintInfo = Standard_False;
3671 else if (anArg == "-noerror"
3672 || anArg == "-nofail")
3674 toFailOnError = Standard_False;
3676 else if (anUpdateTool.parseRedrawMode (anArg))
3686 && anArgIter < theArgNb)
3688 std::cerr << "Error: wrong syntax!\n";
3692 NCollection_List<TCollection_AsciiString> anIONameList;
3695 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3696 anIter.More(); anIter.Next())
3698 anIONameList.Append (anIter.Key2());
3701 else if (anArgIter < theArgNb) // removed objects names are in argument list
3703 for (; anArgIter < theArgNb; ++anArgIter)
3705 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3706 if (aName.Search ("*") != -1)
3708 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
3710 if (aPrsIter.Key1()->GetContext() != aCtx)
3714 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
3715 if (theDI.Eval (aCheck.ToCString()) == 0
3716 && *theDI.Result() == '1')
3718 anIONameList.Append (aPrsIter.Key2());
3725 Handle(AIS_InteractiveObject) anIO;
3726 if (!GetMapOfAIS().Find2 (aName, anIO))
3730 std::cout << "Syntax error: '" << aName << "' was not bound to some object.\n";
3734 else if (anIO->GetContext() != aCtx)
3738 std::cout << "Syntax error: '" << aName << "' was not displayed in current context.\n"
3739 << "Please activate view with this object displayed and try again.\n";
3745 anIONameList.Append (aName);
3749 else if (aCtx->NbSelected() > 0)
3751 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3752 anIter.More(); anIter.Next())
3754 if (!aCtx->IsSelected (anIter.Key1()))
3759 anIONameList.Append (anIter.Key2());
3764 // Unbind all removed objects from the map of displayed IO.
3765 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3766 anIter.More(); anIter.Next())
3768 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
3769 aCtx->Remove (anIO, Standard_False);
3772 theDI << anIter.Value() << " ";
3776 GetMapOfAIS().UnBind2 (anIter.Value());
3782 //==============================================================================
3784 //purpose : Erase some selected or named objects
3785 // if there is no selected or named objects, the whole viewer is erased
3786 //==============================================================================
3787 int VErase (Draw_Interpretor& theDI,
3788 Standard_Integer theArgNb,
3789 const char** theArgVec)
3791 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3792 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3793 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3796 std::cerr << "Error: no active view!\n";
3800 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3802 Standard_Integer anArgIter = 1;
3803 Standard_Boolean toEraseInView = Standard_False;
3804 Standard_Boolean toFailOnError = Standard_True;
3805 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3806 for (; anArgIter < theArgNb; ++anArgIter)
3808 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3809 anArgCase.LowerCase();
3810 if (anUpdateTool.parseRedrawMode (anArgCase))
3814 else if (anArgCase == "-view"
3815 || anArgCase == "-inview")
3817 toEraseInView = Standard_True;
3819 else if (anArgCase == "-noerror"
3820 || anArgCase == "-nofail")
3822 toFailOnError = Standard_False;
3826 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3830 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3832 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3836 if (!aNamesOfEraseIO.IsEmpty())
3838 // Erase named objects
3839 NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString> aPrsList;
3840 for (TColStd_SequenceOfAsciiString::Iterator anIter (aNamesOfEraseIO); anIter.More(); anIter.Next())
3842 const TCollection_AsciiString& aName = anIter.Value();
3843 if (aName.Search ("*") != -1)
3845 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
3847 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
3848 if (theDI.Eval (aCheck.ToCString()) == 0
3849 && *theDI.Result() == '1')
3851 aPrsList.Add (aPrsIter.Key1(), aPrsIter.Key2());
3858 Handle(AIS_InteractiveObject) anIO;
3859 if (!GetMapOfAIS().Find2 (aName, anIO))
3863 std::cout << "Syntax error: '" << aName << "' is not found\n";
3869 aPrsList.Add (anIO, aName);
3874 for (NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString>::Iterator anIter (aPrsList); anIter.More(); anIter.Next())
3876 theDI << anIter.Value() << " ";
3879 aCtx->SetViewAffinity (anIter.Key(), aView, Standard_False);
3883 aCtx->Erase (anIter.Key(), Standard_False);
3887 else if (!toEraseAll && aCtx->NbSelected() > 0)
3889 // Erase selected objects
3890 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3891 anIter.More(); anIter.Next())
3893 const Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3895 && aCtx->IsSelected (anIO))
3897 theDI << anIter.Key2() << " ";
3900 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3907 aCtx->EraseSelected (Standard_False);
3912 // Erase all objects
3913 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3914 anIter.More(); anIter.Next())
3916 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3921 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3925 aCtx->Erase (anIO, Standard_False);
3934 //==============================================================================
3935 //function : VDisplayAll
3936 //purpose : Display all the objects of the Map
3937 //==============================================================================
3938 static int VDisplayAll (Draw_Interpretor& ,
3939 Standard_Integer theArgNb,
3940 const char** theArgVec)
3943 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3944 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3947 std::cerr << "Error: no active view!\n";
3951 Standard_Integer anArgIter = 1;
3952 for (; anArgIter < theArgNb; ++anArgIter)
3954 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3955 anArgCase.LowerCase();
3956 if (anUpdateTool.parseRedrawMode (anArgCase))
3965 if (anArgIter < theArgNb)
3967 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3971 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3972 anIter.More(); anIter.Next())
3974 aCtx->Erase (anIter.Key1(), Standard_False);
3977 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3978 anIter.More(); anIter.Next())
3980 aCtx->Display (anIter.Key1(), Standard_False);
3985 //! Auxiliary method to check if presentation exists
3986 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3987 const Handle(AIS_InteractiveObject)& theIO,
3988 const Standard_Integer theMode)
3990 if (theIO.IsNull() || theCtx.IsNull())
3997 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
4002 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
4004 return theIO->DisplayMode();
4006 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
4008 return theCtx->DisplayMode();
4014 enum ViewerTest_BndAction
4021 //! Auxiliary method to print bounding box of presentation
4022 inline void bndPresentation (Draw_Interpretor& theDI,
4023 const Handle(PrsMgr_PresentationManager)& theMgr,
4024 const Handle(AIS_InteractiveObject)& theObj,
4025 const Standard_Integer theDispMode,
4026 const TCollection_AsciiString& theName,
4027 const ViewerTest_BndAction theAction,
4028 const Handle(Prs3d_Drawer)& theStyle)
4032 case BndAction_Hide:
4034 theMgr->Unhighlight (theObj);
4037 case BndAction_Show:
4039 theMgr->Color (theObj, theStyle, theDispMode);
4042 case BndAction_Print:
4045 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
4047 if (aPrsIter.Value()->Mode() != theDispMode)
4050 aBox = aPrsIter.Value()->MinMaxValues();
4052 gp_Pnt aMin = aBox.CornerMin();
4053 gp_Pnt aMax = aBox.CornerMax();
4054 theDI << theName << "\n"
4055 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
4056 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
4062 //==============================================================================
4063 //function : VBounding
4065 //==============================================================================
4066 int VBounding (Draw_Interpretor& theDI,
4067 Standard_Integer theArgNb,
4068 const char** theArgVec)
4070 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4071 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4074 std::cout << "Error: no active view!\n";
4078 ViewerTest_BndAction anAction = BndAction_Show;
4079 Standard_Integer aMode = -1;
4081 Handle(Prs3d_Drawer) aStyle;
4083 Standard_Integer anArgIter = 1;
4084 for (; anArgIter < theArgNb; ++anArgIter)
4086 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4088 if (anArg == "-print")
4090 anAction = BndAction_Print;
4092 else if (anArg == "-show")
4094 anAction = BndAction_Show;
4096 else if (anArg == "-hide")
4098 anAction = BndAction_Hide;
4100 else if (anArg == "-mode")
4102 if (++anArgIter >= theArgNb)
4104 std::cout << "Error: wrong syntax at " << anArg << "\n";
4107 aMode = Draw::Atoi (theArgVec[anArgIter]);
4109 else if (!anUpdateTool.parseRedrawMode (anArg))
4115 if (anAction == BndAction_Show)
4117 aStyle = new Prs3d_Drawer();
4118 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
4119 aStyle->SetColor (Quantity_NOC_GRAY99);
4122 Standard_Integer aHighlightedMode = -1;
4123 if (anArgIter < theArgNb)
4125 // has a list of names
4126 for (; anArgIter < theArgNb; ++anArgIter)
4128 TCollection_AsciiString aName = theArgVec[anArgIter];
4129 Handle(AIS_InteractiveObject) anIO;
4130 if (!GetMapOfAIS().Find2 (aName, anIO))
4132 std::cout << "Error: presentation " << aName << " does not exist\n";
4136 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4137 if (aHighlightedMode == -1)
4139 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
4142 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
4145 else if (aCtx->NbSelected() > 0)
4147 // remove all currently selected objects
4148 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4150 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
4151 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4152 if (aHighlightedMode != -1)
4154 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
4155 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
4162 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
4163 anIter.More(); anIter.Next())
4165 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
4166 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4167 if (aHighlightedMode != -1)
4169 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
4176 //==============================================================================
4177 //function : VTexture
4179 //==============================================================================
4180 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4182 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4185 std::cout << "Error: no active view!\n";
4189 int toModulate = -1;
4190 bool toSetFilter = false;
4191 bool toSetAniso = false;
4192 bool toSetTrsfAngle = false;
4193 bool toSetTrsfTrans = false;
4194 bool toSetTrsfScale = false;
4195 Standard_ShortReal aTrsfRotAngle = 0.0f;
4196 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
4197 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
4198 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
4199 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
4201 Handle(AIS_InteractiveObject) aTexturedIO;
4202 Handle(AIS_Shape) aTexturedShape;
4203 Handle(Graphic3d_TextureSet) aTextureSetOld;
4204 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
4205 bool toSetGenRepeat = false;
4206 bool toSetGenScale = false;
4207 bool toSetGenOrigin = false;
4208 bool toSetImage = false;
4209 bool toComputeUV = false;
4211 const TCollection_AsciiString aCommandName (theArgVec[0]);
4212 bool toSetDefaults = aCommandName == "vtexdefault";
4214 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4215 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
4217 const TCollection_AsciiString aName = theArgVec[anArgIter];
4218 TCollection_AsciiString aNameCase = aName;
4219 aNameCase.LowerCase();
4220 if (anUpdateTool.parseRedrawMode (aName))
4224 else if (aTexturedIO.IsNull())
4226 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
4227 if (aMapOfIO.IsBound2 (aName))
4229 aTexturedIO = aMapOfIO.Find2 (aName);
4230 aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO);
4232 if (aTexturedIO.IsNull())
4234 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
4238 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
4240 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
4243 else if (!aTexturedShape.IsNull()
4244 && (aNameCase == "-scale"
4245 || aNameCase == "-setscale"
4246 || aCommandName == "vtexscale"))
4248 if (aCommandName != "vtexscale")
4252 if (anArgIter < theArgsNb)
4254 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4255 TCollection_AsciiString aValUCase = aValU;
4256 aValUCase.LowerCase();
4257 toSetGenScale = true;
4258 if (aValUCase == "off")
4260 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4263 else if (anArgIter + 1 < theArgsNb)
4265 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4266 if (aValU.IsRealValue()
4267 && aValV.IsRealValue())
4269 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4275 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4278 else if (!aTexturedShape.IsNull()
4279 && (aNameCase == "-origin"
4280 || aNameCase == "-setorigin"
4281 || aCommandName == "vtexorigin"))
4283 if (aCommandName != "vtexorigin")
4287 if (anArgIter < theArgsNb)
4289 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4290 TCollection_AsciiString aValUCase = aValU;
4291 aValUCase.LowerCase();
4292 toSetGenOrigin = true;
4293 if (aValUCase == "off")
4295 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4298 else if (anArgIter + 1 < theArgsNb)
4300 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4301 if (aValU.IsRealValue()
4302 && aValV.IsRealValue())
4304 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4310 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4313 else if (!aTexturedShape.IsNull()
4314 && (aNameCase == "-repeat"
4315 || aNameCase == "-setrepeat"
4316 || aCommandName == "vtexrepeat"))
4318 if (aCommandName != "vtexrepeat")
4322 if (anArgIter < theArgsNb)
4324 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4325 TCollection_AsciiString aValUCase = aValU;
4326 aValUCase.LowerCase();
4327 toSetGenRepeat = true;
4328 if (aValUCase == "off")
4330 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4333 else if (anArgIter + 1 < theArgsNb)
4335 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4336 if (aValU.IsRealValue()
4337 && aValV.IsRealValue())
4339 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4345 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4348 else if (aNameCase == "-modulate")
4350 bool toModulateBool = true;
4351 if (anArgIter + 1 < theArgsNb
4352 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
4356 toModulate = toModulateBool ? 1 : 0;
4358 else if ((aNameCase == "-setfilter"
4359 || aNameCase == "-filter")
4360 && anArgIter + 1 < theArgsNb)
4362 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4366 if (aValue == "nearest")
4368 aFilter = Graphic3d_TOTF_NEAREST;
4370 else if (aValue == "bilinear")
4372 aFilter = Graphic3d_TOTF_BILINEAR;
4374 else if (aValue == "trilinear")
4376 aFilter = Graphic3d_TOTF_TRILINEAR;
4380 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
4384 else if ((aNameCase == "-setaniso"
4385 || aNameCase == "-setanisofilter"
4386 || aNameCase == "-aniso"
4387 || aNameCase == "-anisofilter")
4388 && anArgIter + 1 < theArgsNb)
4390 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4394 if (aValue == "off")
4396 anAnisoFilter = Graphic3d_LOTA_OFF;
4398 else if (aValue == "fast")
4400 anAnisoFilter = Graphic3d_LOTA_FAST;
4402 else if (aValue == "middle")
4404 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
4406 else if (aValue == "quality"
4407 || aValue == "high")
4409 anAnisoFilter = Graphic3d_LOTA_QUALITY;
4413 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
4417 else if ((aNameCase == "-rotateangle"
4418 || aNameCase == "-rotangle"
4419 || aNameCase == "-rotate"
4420 || aNameCase == "-angle"
4421 || aNameCase == "-trsfangle")
4422 && anArgIter + 1 < theArgsNb)
4424 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4425 toSetTrsfAngle = true;
4428 else if ((aNameCase == "-trsftrans"
4429 || aNameCase == "-trsftranslate"
4430 || aNameCase == "-translate"
4431 || aNameCase == "-translation")
4432 && anArgIter + 2 < theArgsNb)
4434 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4435 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4436 toSetTrsfTrans = true;
4439 else if ((aNameCase == "-trsfscale")
4440 && anArgIter + 2 < theArgsNb)
4442 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4443 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4444 toSetTrsfScale = true;
4447 else if (aNameCase == "-default"
4448 || aNameCase == "-defaults")
4450 toSetDefaults = true;
4452 else if ((aNameCase == "-video")
4453 && anArgIter + 1 < theArgsNb)
4455 const TCollection_AsciiString anInput (theArgVec[++anArgIter]);
4456 Handle(Graphic3d_MediaTextureSet) aMedia = Handle(Graphic3d_MediaTextureSet)::DownCast (aTextureSetOld);
4457 if (aMedia.IsNull())
4459 aMedia = new Graphic3d_MediaTextureSet();
4461 if (aMedia->Input() != anInput)
4463 aMedia->OpenInput (anInput, false);
4467 if (aMedia->SwapFrames()
4468 && !aCtx->CurrentViewer()->ZLayerSettings (aTexturedIO->ZLayer()).IsImmediate())
4470 ViewerTest::CurrentView()->Invalidate();
4473 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4474 && aTexturedShape.IsNull())
4476 aTexturedIO->SetToUpdate();
4479 toComputeUV = aTextureSetOld.IsNull();
4480 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (true);
4481 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia);
4482 aTextureSetOld.Nullify();
4484 else if (aCommandName == "vtexture"
4485 && (aTextureVecNew.IsEmpty()
4486 || aNameCase.StartsWith ("-tex")))
4488 Standard_Integer aTexIndex = 0;
4489 TCollection_AsciiString aTexName = aName;
4490 if (aNameCase.StartsWith ("-tex"))
4492 if (anArgIter + 1 >= theArgsNb
4493 || aNameCase.Length() < 5)
4495 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4499 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
4500 if (!aTexIndexStr.IsIntegerValue())
4502 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4506 aTexIndex = aTexIndexStr.IntegerValue();
4507 aTexName = theArgVec[anArgIter + 1];
4510 if (aTexIndex >= Graphic3d_TextureUnit_NB
4511 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
4513 std::cout << "Error: too many textures specified\n";
4518 if (aTexName.IsIntegerValue())
4520 const Standard_Integer aValue = aTexName.IntegerValue();
4521 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
4523 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
4526 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
4528 else if (aTexName == "?")
4530 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
4532 theDi << "\n Files in current directory : \n\n";
4533 theDi.Eval ("glob -nocomplain *");
4535 TCollection_AsciiString aCmnd ("glob -nocomplain ");
4536 aCmnd += aTextureFolder;
4539 theDi << "Files in " << aTextureFolder << " : \n\n";
4540 theDi.Eval (aCmnd.ToCString());
4543 else if (aTexName != "off")
4545 if (!OSD_File (aTexName).Exists())
4547 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
4550 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
4554 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
4557 if (aTextureVecNew.Value (aTexIndex))
4559 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
4564 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4571 // check if new image set is equal to already set one
4572 Standard_Integer aNbChanged = 0;
4573 Handle(Graphic3d_TextureSet) aTextureSetNew;
4574 if (!aTextureVecNew.IsEmpty())
4576 aNbChanged = aTextureVecNew.Size();
4577 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
4578 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
4580 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
4581 Handle(Graphic3d_TextureRoot) aTextureOld;
4582 if (!aTextureSetOld.IsNull()
4583 && aTexIter < aTextureSetOld->Size())
4585 aTextureOld = aTextureSetOld->Value (aTexIter);
4588 if (!aTextureOld.IsNull()
4589 && !aTextureNew.IsNull())
4591 *aTextureNew->GetParams() = *aTextureOld->GetParams();
4592 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
4594 TCollection_AsciiString aFilePathOld, aFilePathNew;
4595 aTextureOld->Path().SystemName (aFilePathOld);
4596 aTextureNew->Path().SystemName (aFilePathNew);
4597 if (aTextureNew->Name() == anOldManualTex->Name()
4598 && aFilePathOld == aFilePathNew
4599 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
4602 aTextureNew = anOldManualTex;
4606 aTextureSetNew->SetValue (aTexIter, aTextureNew);
4610 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
4611 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
4613 aTextureSetNew = aTextureSetOld;
4616 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4617 && aTexturedShape.IsNull())
4619 aTexturedIO->SetToUpdate();
4622 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
4623 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
4624 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
4625 aTextureSetOld.Nullify();
4630 if (toModulate != -1)
4637 aFilter = Graphic3d_TOTF_BILINEAR;
4642 anAnisoFilter = Graphic3d_LOTA_OFF;
4644 if (!toSetTrsfAngle)
4646 toSetTrsfAngle = true;
4647 aTrsfRotAngle = 0.0f;
4649 if (!toSetTrsfTrans)
4651 toSetTrsfTrans = true;
4652 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
4654 if (!toSetTrsfScale)
4656 toSetTrsfScale = true;
4657 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
4661 if (aCommandName == "vtexture"
4664 if (!aTextureSetOld.IsNull())
4666 //toComputeUV = true; // we can keep UV vertex attributes
4667 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
4668 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
4669 aTextureSetOld.Nullify();
4673 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
4674 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
4676 if (toModulate != -1)
4678 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
4682 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
4686 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
4690 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
4694 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
4698 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
4702 // set default values if requested
4704 && (aCommandName == "vtexrepeat"
4707 if (!aTexturedShape.IsNull())
4709 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4711 toSetGenRepeat = true;
4714 && (aCommandName == "vtexorigin"
4717 if (!aTexturedShape.IsNull())
4719 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4721 toSetGenOrigin = true;
4724 && (aCommandName == "vtexscale"
4727 if (!aTexturedShape.IsNull())
4729 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4731 toSetGenScale = true;
4734 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
4736 if (!aTexturedShape.IsNull())
4738 aTexturedShape->SetToUpdate (AIS_Shaded);
4741 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
4742 || aCtx->DisplayMode() != AIS_Shaded)
4744 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
4749 aCtx->Display (aTexturedIO, false);
4750 aTexturedIO->SynchronizeAspects();
4754 //! Auxiliary method to parse transformation persistence flags
4755 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
4756 Graphic3d_TransModeFlags& theFlags)
4758 if (theFlagString == "zoom")
4760 theFlags = Graphic3d_TMF_ZoomPers;
4762 else if (theFlagString == "rotate")
4764 theFlags = Graphic3d_TMF_RotatePers;
4766 else if (theFlagString == "zoomrotate")
4768 theFlags = Graphic3d_TMF_ZoomRotatePers;
4770 else if (theFlagString == "trihedron"
4771 || theFlagString == "triedron")
4773 theFlags = Graphic3d_TMF_TriedronPers;
4775 else if (theFlagString == "none")
4777 theFlags = Graphic3d_TMF_None;
4781 return Standard_False;
4784 return Standard_True;
4787 //! Auxiliary method to parse transformation persistence flags
4788 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4789 Aspect_TypeOfTriedronPosition& theCorner)
4791 TCollection_AsciiString aString (theString);
4792 aString.LowerCase();
4793 if (aString == "center")
4795 theCorner = Aspect_TOTP_CENTER;
4797 else if (aString == "top"
4798 || aString == "upper")
4800 theCorner = Aspect_TOTP_TOP;
4802 else if (aString == "bottom"
4803 || aString == "lower")
4805 theCorner = Aspect_TOTP_BOTTOM;
4807 else if (aString == "left")
4809 theCorner = Aspect_TOTP_LEFT;
4811 else if (aString == "right")
4813 theCorner = Aspect_TOTP_RIGHT;
4815 else if (aString == "topleft"
4816 || aString == "leftupper"
4817 || aString == "upperleft")
4819 theCorner = Aspect_TOTP_LEFT_UPPER;
4821 else if (aString == "bottomleft"
4822 || aString == "leftlower"
4823 || aString == "lowerleft")
4825 theCorner = Aspect_TOTP_LEFT_LOWER;
4827 else if (aString == "topright"
4828 || aString == "rightupper"
4829 || aString == "upperright")
4831 theCorner = Aspect_TOTP_RIGHT_UPPER;
4833 else if (aString == "bottomright"
4834 || aString == "lowerright"
4835 || aString == "rightlower")
4837 theCorner = Aspect_TOTP_RIGHT_LOWER;
4841 return Standard_False;
4844 return Standard_True;
4847 //==============================================================================
4848 //function : VDisplay2
4850 //purpose : Display an object from its name
4851 //==============================================================================
4852 static int VDisplay2 (Draw_Interpretor& theDI,
4853 Standard_Integer theArgNb,
4854 const char** theArgVec)
4858 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4862 && TCollection_AsciiString (theArgVec[1]) == "*")
4865 return VDisplayAll (theDI, 1, theArgVec);
4868 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4871 ViewerTest::ViewerInit();
4872 aCtx = ViewerTest::GetAISContext();
4875 // Parse input arguments
4876 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4877 Standard_Integer isMutable = -1;
4878 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4879 Standard_Boolean toReDisplay = Standard_False;
4880 Standard_Integer isSelectable = -1;
4881 Standard_Integer anObjDispMode = -2;
4882 Standard_Integer anObjHighMode = -2;
4883 Standard_Boolean toSetTrsfPers = Standard_False;
4884 Handle(Graphic3d_TransformPers) aTrsfPers;
4885 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4886 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4887 Standard_Integer toDisplayInView = Standard_False;
4888 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4890 const TCollection_AsciiString aName = theArgVec[anArgIter];
4891 TCollection_AsciiString aNameCase = aName;
4892 aNameCase.LowerCase();
4893 if (anUpdateTool.parseRedrawMode (aName))
4897 else if (aNameCase == "-mutable")
4901 else if (aNameCase == "-neutral")
4903 aDispStatus = AIS_DS_Displayed;
4905 else if (aNameCase == "-immediate"
4906 || aNameCase == "-top")
4908 aZLayer = Graphic3d_ZLayerId_Top;
4910 else if (aNameCase == "-topmost")
4912 aZLayer = Graphic3d_ZLayerId_Topmost;
4914 else if (aNameCase == "-osd"
4915 || aNameCase == "-toposd"
4916 || aNameCase == "-overlay")
4918 aZLayer = Graphic3d_ZLayerId_TopOSD;
4920 else if (aNameCase == "-botosd"
4921 || aNameCase == "-underlay")
4923 aZLayer = Graphic3d_ZLayerId_BotOSD;
4925 else if (aNameCase == "-select"
4926 || aNameCase == "-selectable")
4930 else if (aNameCase == "-noselect"
4931 || aNameCase == "-noselection")
4935 else if (aNameCase == "-dispmode"
4936 || aNameCase == "-displaymode")
4938 if (++anArgIter >= theArgNb)
4940 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4944 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4946 else if (aNameCase == "-himode"
4947 || aNameCase == "-highmode"
4948 || aNameCase == "-highlightmode")
4950 if (++anArgIter >= theArgNb)
4952 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4956 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4958 else if (aNameCase == "-3d")
4960 toSetTrsfPers = Standard_True;
4961 aTrsfPers.Nullify();
4963 else if (aNameCase == "-2d"
4964 || aNameCase == "-trihedron"
4965 || aNameCase == "-triedron")
4967 toSetTrsfPers = Standard_True;
4968 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4970 if (anArgIter + 1 < theArgNb)
4972 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4973 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4976 aTrsfPers->SetCorner2d (aCorner);
4978 if (anArgIter + 2 < theArgNb)
4980 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4981 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4982 if (anX.IsIntegerValue()
4983 && anY.IsIntegerValue())
4986 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4992 else if (aNameCase == "-trsfpers"
4993 || aNameCase == "-pers")
4995 if (++anArgIter >= theArgNb
4996 || !aTrsfPers.IsNull())
4998 std::cerr << "Error: wrong syntax at " << aName << ".\n";
5002 toSetTrsfPers = Standard_True;
5003 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
5004 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
5005 aPersFlags.LowerCase();
5006 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
5008 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
5012 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
5014 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
5016 else if (aTrsfPersFlags != Graphic3d_TMF_None)
5018 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
5021 else if (aNameCase == "-trsfperspos"
5022 || aNameCase == "-perspos")
5024 if (anArgIter + 2 >= theArgNb
5025 || aTrsfPers.IsNull())
5027 std::cerr << "Error: wrong syntax at " << aName << ".\n";
5031 TCollection_AsciiString aX (theArgVec[++anArgIter]);
5032 TCollection_AsciiString aY (theArgVec[++anArgIter]);
5033 TCollection_AsciiString aZ = "0";
5034 if (!aX.IsRealValue()
5035 || !aY.IsRealValue())
5037 std::cerr << "Error: wrong syntax at " << aName << ".\n";
5040 if (anArgIter + 1 < theArgNb)
5042 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
5043 if (aTemp.IsRealValue())
5050 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
5051 if (aTrsfPers->IsZoomOrRotate())
5053 aTrsfPers->SetAnchorPoint (aPnt);
5055 else if (aTrsfPers->IsTrihedronOr2d())
5057 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
5060 else if (aNameCase == "-layer"
5061 || aNameCase == "-zlayer")
5064 if (anArgIter >= theArgNb
5065 || !ViewerTest::ParseZLayer (theArgVec[anArgIter], aZLayer)
5066 || aZLayer == Graphic3d_ZLayerId_UNKNOWN)
5068 std::cerr << "Error: wrong syntax at " << aName << ".\n";
5072 else if (aNameCase == "-view"
5073 || aNameCase == "-inview")
5075 toDisplayInView = Standard_True;
5077 else if (aNameCase == "-redisplay")
5079 toReDisplay = Standard_True;
5081 else if (aNameCase == "-erased"
5082 || aNameCase == "-load")
5084 aDispStatus = AIS_DS_Erased;
5088 aNamesOfDisplayIO.Append (aName);
5092 if (aNamesOfDisplayIO.IsEmpty())
5094 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5098 // Display interactive objects
5099 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
5101 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value (anIter);
5102 Handle(AIS_InteractiveObject) aShape;
5103 if (!GetMapOfAIS().Find2 (aName, aShape))
5105 // create the AIS_Shape from a name
5106 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
5107 if (!aDrawShape.IsNull())
5109 aShape = new AIS_Shape (aDrawShape);
5110 if (isMutable != -1)
5112 aShape->SetMutable (isMutable == 1);
5114 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
5116 aShape->SetZLayer (aZLayer);
5120 aCtx->SetTransformPersistence (aShape, aTrsfPers);
5122 if (anObjDispMode != -2)
5124 if (anObjDispMode == -1)
5126 aShape->UnsetDisplayMode();
5128 if (!aShape->AcceptDisplayMode (anObjDispMode))
5130 std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjDispMode << " display mode\n";
5135 aShape->SetDisplayMode (anObjDispMode);
5138 if (anObjHighMode != -2)
5140 if (anObjHighMode != -1
5141 && !aShape->AcceptDisplayMode (anObjHighMode))
5143 std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjHighMode << " display mode\n";
5146 aShape->SetHilightMode (anObjHighMode);
5149 GetMapOfAIS().Bind (aShape, aName);
5150 Standard_Integer aDispMode = aShape->HasDisplayMode()
5151 ? aShape->DisplayMode()
5152 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5153 ? aCtx->DisplayMode()
5155 Standard_Integer aSelMode = -1;
5156 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5158 aSelMode = aShape->GlobalSelectionMode();
5161 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5162 if (toDisplayInView)
5164 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
5166 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
5168 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5173 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
5178 if (isMutable != -1)
5180 aShape->SetMutable (isMutable == 1);
5182 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
5184 aShape->SetZLayer (aZLayer);
5188 aCtx->SetTransformPersistence (aShape, aTrsfPers);
5190 if (anObjDispMode != -2)
5192 aShape->SetDisplayMode (anObjDispMode);
5194 if (anObjHighMode != -2)
5196 aShape->SetHilightMode (anObjHighMode);
5198 Standard_Integer aDispMode = aShape->HasDisplayMode()
5199 ? aShape->DisplayMode()
5200 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5201 ? aCtx->DisplayMode()
5203 Standard_Integer aSelMode = -1;
5204 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5206 aSelMode = aShape->GlobalSelectionMode();
5209 if (aShape->Type() == AIS_KOI_Datum)
5211 aCtx->Display (aShape, Standard_False);
5215 theDI << "Display " << aName << "\n";
5217 // update the Shape in the AIS_Shape
5218 TopoDS_Shape aNewShape = DBRep::GetExisting (aName);
5219 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
5220 if (!aShapePrs.IsNull())
5222 if (!aShapePrs->Shape().IsEqual (aNewShape))
5224 toReDisplay = Standard_True;
5226 aShapePrs->Set (aNewShape);
5230 aCtx->Redisplay (aShape, Standard_False);
5235 aCtx->Erase (aShape, Standard_False);
5237 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5238 if (toDisplayInView)
5240 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5248 //=======================================================================
5249 //function : VNbDisplayed
5250 //purpose : Returns number of displayed objects
5251 //=======================================================================
5252 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
5253 Standard_Integer theArgsNb,
5254 const char** theArgVec)
5258 theDi << "Usage : " << theArgVec[0] << "\n";
5262 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5263 if (aContextAIS.IsNull())
5265 std::cout << theArgVec[0] << "AIS context is not available.\n";
5269 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5270 if(aContext.IsNull())
5272 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
5276 AIS_ListOfInteractive aListOfIO;
5277 aContextAIS->DisplayedObjects (aListOfIO);
5279 theDi << aListOfIO.Extent() << "\n";
5283 //===============================================================================================
5284 //function : VUpdate
5286 //===============================================================================================
5287 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
5289 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5290 if (aContextAIS.IsNull())
5292 std::cout << theArgVec[0] << "AIS context is not available.\n";
5298 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
5302 AIS_ListOfInteractive aListOfIO;
5303 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5305 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
5307 Handle(AIS_InteractiveObject) anAISObj;
5308 GetMapOfAIS().Find2 (aName, anAISObj);
5309 if (anAISObj.IsNull())
5311 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
5315 aListOfIO.Append (anAISObj);
5318 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
5319 for (; anIOIt.More(); anIOIt.Next())
5321 aContextAIS->Update (anIOIt.Value(), Standard_False);
5324 aContextAIS->UpdateCurrentViewer();
5329 //==============================================================================
5330 //function : VShading
5331 //purpose : Sharpen or roughten the quality of the shading
5332 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
5333 //==============================================================================
5334 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
5336 Standard_Real myDevCoef;
5337 Handle(AIS_InteractiveObject) TheAisIO;
5340 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
5344 myDevCoef =Draw::Atof(argv[2]);
5347 TCollection_AsciiString name=argv[1];
5348 GetMapOfAIS().Find2(name, TheAisIO);
5349 if (TheAisIO.IsNull())
5351 TopoDS_Shape aDrawShape = DBRep::GetExisting (name);
5352 if (!aDrawShape.IsNull())
5354 TheAisIO = new AIS_Shape (aDrawShape);
5359 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5361 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
5363 TheAISContext()->Redisplay (TheAisIO, Standard_True);
5367 //! Auxiliary method to print Interactive Object information
5368 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
5369 const Handle(AIS_InteractiveObject)& theObj,
5370 Draw_Interpretor& theDI)
5372 if (theObj.IsNull())
5374 theDI << "NULL presentation\n";
5378 theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ")
5379 << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ")
5380 << (theDetected.Contains (theObj) ? " Detected" : " ")
5382 if (theObj->Type() == AIS_KOI_Datum)
5385 if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
5386 else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; }
5387 else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; }
5388 else if (theObj->Signature() == 5) { theDI << " AIS_Line"; }
5389 else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; }
5390 else if (theObj->Signature() == 1) { theDI << " AIS_Point"; }
5391 else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
5394 else if (theObj->Type() == AIS_KOI_Shape
5395 && theObj->Signature() == 0)
5397 theDI << " AIS_Shape";
5399 else if (theObj->Type() == AIS_KOI_Relation)
5401 // AIS_Dimention and AIS_Relation
5402 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (theObj);
5403 switch (aRelation->KindOfDimension())
5405 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
5406 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
5407 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
5408 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
5409 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
5410 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
5411 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
5412 default: theDI << " UNKNOWN dimension"; break;
5417 theDI << " UserPrs";
5419 theDI << " (" << theObj->DynamicType()->Name() << ")";
5422 //! Print information about locally selected sub-shapes
5423 template <typename T>
5424 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
5426 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
5427 TCollection_AsciiString aPrevName;
5428 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
5430 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
5431 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
5432 if (aShapeIO.IsNull() || anOwner.IsNull())
5436 if (anOwner == aShapeIO->GlobalSelOwner())
5439 const TopoDS_Shape aSubShape = theContext->SelectedShape();
5440 if (aSubShape.IsNull()
5441 || aShapeIO.IsNull()
5442 || !GetMapOfAIS().IsBound1 (aShapeIO))
5447 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
5448 TopTools_MapOfShape aFilter;
5449 Standard_Integer aNumber = 0;
5450 const TopoDS_Shape aShape = aShapeIO->Shape();
5451 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
5452 anIter.More(); anIter.Next())
5454 if (!aFilter.Add (anIter.Current()))
5456 continue; // filter duplicates
5460 if (!anIter.Current().IsSame (aSubShape))
5465 Standard_CString aShapeName = NULL;
5466 switch (aSubShape.ShapeType())
5468 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
5469 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
5470 case TopAbs_SOLID: aShapeName = " Solid"; break;
5471 case TopAbs_SHELL: aShapeName = " Shell"; break;
5472 case TopAbs_FACE: aShapeName = " Face"; break;
5473 case TopAbs_WIRE: aShapeName = " Wire"; break;
5474 case TopAbs_EDGE: aShapeName = " Edge"; break;
5475 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
5477 case TopAbs_SHAPE: aShapeName = " Shape"; break;
5480 if (aParentName != aPrevName)
5482 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
5483 aPrevName = aParentName;
5485 theDI << " " << aShapeName << " #" << aNumber << "\n";
5491 //==============================================================================
5494 //==============================================================================
5495 static Standard_Integer VState (Draw_Interpretor& theDI,
5496 Standard_Integer theArgNb,
5497 Standard_CString* theArgVec)
5499 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
5502 std::cerr << "Error: No opened viewer!\n";
5506 Standard_Boolean toPrintEntities = Standard_False;
5507 Standard_Boolean toCheckSelected = Standard_False;
5509 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
5511 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
5512 anOption.LowerCase();
5513 if (anOption == "-detectedentities"
5514 || anOption == "-entities")
5516 toPrintEntities = Standard_True;
5518 else if (anOption == "-hasselected")
5520 toCheckSelected = Standard_True;
5524 if (toCheckSelected)
5526 aCtx->InitSelected();
5527 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
5528 theDI << "Check if context has selected shape: " << hasSelected << "\n";
5533 if (toPrintEntities)
5535 theDI << "Detected entities:\n";
5536 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
5538 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
5539 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
5541 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
5542 const Handle(Select3D_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
5543 const Handle(SelectMgr_EntityOwner)& anOwner = anEntity->OwnerId();
5544 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5546 TCollection_AsciiString aName;
5547 GetMapOfAIS().Find1 (anObj, aName);
5548 aName.LeftJustify (20, ' ');
5549 char anInfoStr[512];
5551 " Depth: %g Distance: %g Point: %g %g %g",
5554 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
5555 theDI << " " << aName
5557 << " (" << anEntity->DynamicType()->Name() << ")"
5560 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
5561 if (!aBRepOwner.IsNull())
5563 theDI << " Detected Shape: "
5564 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
5568 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
5569 if (!aWire.IsNull())
5571 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
5572 theDI << " Detected Child: "
5573 << aSen->DynamicType()->Name()
5577 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
5578 if (!aPrimArr.IsNull())
5580 theDI << " Detected Element: "
5581 << aPrimArr->LastDetectedElement()
5588 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
5589 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
5591 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
5594 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
5598 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5600 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
5601 Handle(AIS_InteractiveObject) anObj;
5602 if (!GetMapOfAIS().Find2 (anObjName, anObj))
5604 theDI << anObjName << " doesn't exist!\n";
5608 TCollection_AsciiString aName = anObjName;
5609 aName.LeftJustify (20, ' ');
5610 theDI << " " << aName << " ";
5611 objInfo (aDetected, anObj, theDI);
5617 if (aCtx->NbSelected() > 0 && !toShowAll)
5619 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
5620 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
5622 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
5623 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5624 // handle whole object selection
5625 if (anOwner == anObj->GlobalSelOwner())
5627 TCollection_AsciiString aName;
5628 GetMapOfAIS().Find1 (anObj, aName);
5629 aName.LeftJustify (20, ' ');
5630 theDI << aName << " ";
5631 objInfo (aDetected, anObj, theDI);
5636 // process selected sub-shapes
5637 printLocalSelectionInfo (aCtx, theDI);
5642 theDI << "Neutral-point state:\n";
5643 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5644 anObjIter.More(); anObjIter.Next())
5646 if (anObjIter.Key1().IsNull())
5651 TCollection_AsciiString aName = anObjIter.Key2();
5652 aName.LeftJustify (20, ' ');
5653 theDI << " " << aName << " ";
5654 objInfo (aDetected, anObjIter.Key1(), theDI);
5657 printLocalSelectionInfo (aCtx, theDI);
5661 //=======================================================================
5662 //function : PickShape
5663 //purpose : First Activate the rightmode + Put Filters to be able to
5664 // pick objets that are of type <TheType>...
5665 //=======================================================================
5667 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
5668 const Standard_Integer theMaxPick)
5670 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
5671 PickShapes (theShapeType, aResArray, theMaxPick);
5672 return aResArray->First();
5675 //=======================================================================
5676 //function : PickShapes
5678 //=======================================================================
5679 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
5680 Handle(TopTools_HArray1OfShape)& theResArray,
5681 const Standard_Integer theMaxPick)
5683 const Standard_Integer aNbToReach = theResArray->Length();
5686 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
5689 // step 1: prepare the data
5690 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5691 aCtx->RemoveFilters();
5692 AIS_ListOfInteractive aDispObjects;
5693 aCtx->DisplayedObjects (aDispObjects);
5694 if (theShapeType == TopAbs_SHAPE)
5696 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
5700 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
5703 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
5704 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5706 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5708 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5712 // step 2 : wait for the selection...
5713 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
5714 Standard_Integer argccc = 5;
5715 const char *bufff[] = { "A", "B", "C", "D", "E" };
5716 const char **argvvv = (const char** )bufff;
5717 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
5719 while (ViewerMainLoop (argccc, argvvv)) {}
5720 Standard_Integer aNbStored = aCtx->NbSelected();
5721 if (aNbStored != aNbPickGood)
5723 aNbPickGood = aNbStored;
5729 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
5732 // step3 get result.
5733 if (aNbPickFail >= aNbToReach)
5735 return Standard_False;
5738 Standard_Integer anIndex = theResArray->Lower();
5739 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
5741 if (aCtx->HasSelectedShape())
5743 theResArray->SetValue (anIndex, aCtx->SelectedShape());
5747 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
5748 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
5752 aCtx->RemoveFilters();
5753 if (theShapeType != TopAbs_SHAPE)
5755 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5757 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5759 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5763 return Standard_True;
5766 //=======================================================================
5767 //function : VPickShape
5769 //=======================================================================
5770 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5772 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
5775 TCollection_AsciiString aShapeArg (argv[1]);
5776 aShapeArg.LowerCase();
5777 aShapeType = TopAbs_COMPOUND;
5778 if (aShapeArg == "v"
5779 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
5780 else if (aShapeArg == "e"
5781 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
5782 else if (aShapeArg == "w"
5783 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
5784 else if (aShapeArg == "f"
5785 || aShapeArg == "face") aShapeType = TopAbs_FACE;
5786 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
5787 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
5788 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
5791 std::cout << "Syntax error at '" << argv[1] << "'\n";
5796 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5797 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
5799 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
5802 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
5803 if (aPickedShape.IsNull())
5808 TCollection_AsciiString aName;
5815 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5816 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5819 DBRep::Set (aName.ToCString(), aPickedShape);
5820 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5821 ViewerTest::Display (aName, aShapePrs, false, true);
5822 di << "Name of picked shape: " << aName <<"\n";
5826 TCollection_AsciiString aName (argv[2]);
5828 const Standard_Boolean isAutoNaming = aName == ".";
5829 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5830 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5832 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5834 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5836 if (!aPickedShape.IsNull()
5839 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5840 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5844 aName = argv[1 + aPickedIter];
5847 DBRep::Set (aName.ToCString(), aPickedShape);
5848 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5849 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5850 ViewerTest::Display (aName, aShapePrs, false, true);
5854 TheAISContext()->UpdateCurrentViewer();
5858 //=======================================================================
5859 //function : VSelFilter
5861 //=======================================================================
5862 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5863 const char** theArgv)
5865 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5866 if (aContext.IsNull())
5868 std::cout << "Error: AIS context is not available.\n";
5872 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5874 TCollection_AsciiString anArg (theArgv[anArgIter]);
5876 if (anArg == "-clear")
5878 aContext->RemoveFilters();
5880 else if (anArg == "-type"
5881 && anArgIter + 1 < theArgc)
5883 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5884 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5885 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5887 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5891 Handle(SelectMgr_Filter) aFilter;
5892 if (aShapeType == TopAbs_SHAPE)
5894 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5898 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5900 aContext->AddFilter (aFilter);
5904 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5911 //=======================================================================
5912 //function : VPickSelected
5914 //=======================================================================
5915 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5917 static Standard_Integer aCount = 0;
5918 TCollection_AsciiString aName = "PickedShape_";
5926 aName = aName + aCount++ + "_";
5929 Standard_Integer anIdx = 0;
5930 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5932 TopoDS_Shape aShape;
5933 if (TheAISContext()->HasSelectedShape())
5935 aShape = TheAISContext()->SelectedShape();
5939 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5940 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5943 TCollection_AsciiString aCurrentName = aName;
5946 aCurrentName += anIdx;
5949 DBRep::Set ((aCurrentName).ToCString(), aShape);
5951 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5952 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5953 TheAISContext()->Display (aNewShape, Standard_False);
5956 TheAISContext()->UpdateCurrentViewer();
5961 //=======================================================================
5962 //function : list of known objects
5964 //=======================================================================
5965 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5967 // 1234567890 12345678901234567 123456789
5968 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5969 TCollection_AsciiString BlankLine(64,'_');
5970 Standard_Integer i ;
5972 di<<"/n"<<BlankLine.ToCString()<<"\n";
5975 Colum[i].Center(20,' ');
5977 di<<"|"<<Colum[i].ToCString();
5980 di<<BlankLine.ToCString()<<"\n";
5982 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5983 const char ** names = GetTypeNames();
5985 TCollection_AsciiString curstring;
5986 TCollection_AsciiString curcolum[3];
5989 // les objets de type Datum..
5990 curcolum[1]+="Datum";
5992 curcolum[0].Clear();
5993 curcolum[0] += names[i];
5995 curcolum[2].Clear();
5996 curcolum[2]+=TCollection_AsciiString(i+1);
5998 for(Standard_Integer j =0;j<=2;j++){
5999 curcolum[j].Center(20,' ');
6000 di<<"|"<<curcolum[j].ToCString();
6004 di<<BlankLine.ToCString()<<"\n";
6006 // les objets de type shape
6007 curcolum[1].Clear();
6008 curcolum[1]+="Shape";
6009 curcolum[1].Center(20,' ');
6012 curcolum[0].Clear();
6013 curcolum[0] += names[7+i];
6014 curcolum[2].Clear();
6015 curcolum[2]+=TCollection_AsciiString(i);
6017 for(Standard_Integer j =0;j<=2;j++){
6018 curcolum[j].Center(20,' ');
6019 di<<"|"<<curcolum[j].ToCString();
6023 di<<BlankLine.ToCString()<<"\n";
6024 // les IO de type objet...
6025 curcolum[1].Clear();
6026 curcolum[1]+="Object";
6027 curcolum[1].Center(20,' ');
6029 curcolum[0].Clear();
6030 curcolum[0] += names[10+i];
6031 curcolum[2].Clear();
6032 curcolum[2]+=TCollection_AsciiString(i);
6034 for(Standard_Integer j =0;j<=2;j++){
6035 curcolum[j].Center(20,' ');
6036 di<<"|"<<curcolum[j].ToCString();
6040 di<<BlankLine.ToCString()<<"\n";
6041 // les contraintes et dimensions.
6042 // pour l'instant on separe juste contraintes et dimensions...
6043 // plus tard, on detaillera toutes les sortes...
6044 curcolum[1].Clear();
6045 curcolum[1]+="Relation";
6046 curcolum[1].Center(20,' ');
6048 curcolum[0].Clear();
6049 curcolum[0] += names[12+i];
6050 curcolum[2].Clear();
6051 curcolum[2]+=TCollection_AsciiString(i);
6053 for(Standard_Integer j =0;j<=2;j++){
6054 curcolum[j].Center(20,' ');
6055 di<<"|"<<curcolum[j].ToCString();
6059 di<<BlankLine.ToCString()<<"\n";
6066 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
6068 if(argc!=2) return 1;
6070 AIS_KindOfInteractive TheType;
6071 Standard_Integer TheSign(-1);
6072 GetTypeAndSignfromString(argv[1],TheType,TheSign);
6075 AIS_ListOfInteractive LIO;
6077 // en attendant l'amelioration ais pour les dimensions...
6079 Standard_Integer dimension_status(-1);
6080 if(TheType==AIS_KOI_Relation){
6081 dimension_status = TheSign ==1 ? 1 : 0;
6085 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
6086 Handle(AIS_InteractiveObject) curio;
6087 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
6090 if(dimension_status == -1)
6091 TheAISContext()->Erase(curio,Standard_False);
6093 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
6094 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
6095 (dimension_status==1 && KOD != AIS_KOD_NONE))
6096 TheAISContext()->Erase(curio,Standard_False);
6099 TheAISContext()->UpdateCurrentViewer();
6102 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
6104 if(argc!=2) return 1;
6106 AIS_KindOfInteractive TheType;
6107 Standard_Integer TheSign(-1);
6108 GetTypeAndSignfromString(argv[1],TheType,TheSign);
6110 // en attendant l'amelioration ais pour les dimensions...
6112 Standard_Integer dimension_status(-1);
6113 if(TheType==AIS_KOI_Relation){
6114 dimension_status = TheSign ==1 ? 1 : 0;
6118 AIS_ListOfInteractive LIO;
6119 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
6120 Handle(AIS_InteractiveObject) curio;
6121 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
6123 if(dimension_status == -1)
6124 TheAISContext()->Display(curio,Standard_False);
6126 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
6127 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
6128 (dimension_status==1 && KOD != AIS_KOD_NONE))
6129 TheAISContext()->Display(curio,Standard_False);
6134 TheAISContext()->UpdateCurrentViewer();
6138 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
6140 std::ifstream s(a[1]);
6141 BRep_Builder builder;
6143 BRepTools::Read(shape, s, builder);
6144 DBRep::Set(a[1], shape);
6145 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6146 Handle(AIS_Shape) ais = new AIS_Shape(shape);
6147 Ctx->Display (ais, Standard_True);
6151 //===============================================================================================
6154 //===============================================================================================
6155 static int VBsdf (Draw_Interpretor& theDI,
6156 Standard_Integer theArgsNb,
6157 const char** theArgVec)
6159 Handle(V3d_View) aView = ViewerTest::CurrentView();
6160 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6162 || aViewer.IsNull())
6164 std::cerr << "No active viewer!\n";
6168 ViewerTest_CmdParser aCmd;
6170 aCmd.SetDescription ("Adjusts parameters of material BSDF:");
6172 aCmd.AddOption ("print|echo|p", "Prints BSDF");
6174 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
6176 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
6177 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
6178 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
6179 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
6180 aCmd.AddOption ("le", "Radiance emitted by surface");
6182 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
6183 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
6185 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
6186 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
6188 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
6189 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
6191 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
6193 aCmd.Parse (theArgsNb, theArgVec);
6195 if (aCmd.HasOption ("help"))
6197 theDI.PrintHelp (theArgVec[0]);
6201 // check viewer update mode
6202 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
6203 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6205 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
6212 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
6213 Handle(AIS_InteractiveObject) anIObj;
6214 if (!GetMapOfAIS().Find2 (aName, anIObj))
6216 std::cerr << "Use 'vdisplay' before\n";
6220 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
6221 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
6223 if (aCmd.HasOption ("print"))
6226 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
6227 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
6228 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
6229 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
6230 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
6232 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6234 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
6235 : aBSDF.FresnelBase.Serialize();
6237 theDI << (aLayerID < 1 ? "Coat Fresnel: "
6238 : "Base Fresnel: ");
6240 if (aFresnel.x() >= 0.f)
6242 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
6243 << "G = " << aFresnel.g() << ", "
6244 << "B = " << aFresnel.b() << "\n";
6246 else if (aFresnel.x() >= -1.5f)
6248 theDI << "Constant " << aFresnel.z() << "\n";
6250 else if (aFresnel.x() >= -2.5f)
6252 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
6253 << "K = " << aFresnel.z() << "\n";
6257 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
6261 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
6262 << "Base roughness: " << aBSDF.Ks.w() << "\n"
6263 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
6264 << "Absorption color: " << aBSDF.Absorption.r() << ", "
6265 << aBSDF.Absorption.g() << ", "
6266 << aBSDF.Absorption.b() << "\n";
6271 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
6273 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
6276 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
6278 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
6281 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
6283 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
6286 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
6288 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
6290 aBSDF.Absorption.r() = aRGB.r();
6291 aBSDF.Absorption.g() = aRGB.g();
6292 aBSDF.Absorption.b() = aRGB.b();
6295 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
6299 if (aCmd.HasOption ("kc", 3))
6301 aKc = aCmd.ArgVec3f ("kc");
6305 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
6308 aBSDF.Kc.r() = aKc.r();
6309 aBSDF.Kc.g() = aKc.g();
6310 aBSDF.Kc.b() = aKc.b();
6313 if (aCmd.HasOption ("kd", 3))
6315 aBSDF.Kd = aCmd.ArgVec3f ("kd");
6317 else if (aCmd.HasOption ("kd", 1, Standard_True))
6319 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
6322 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
6326 if (aCmd.HasOption ("ks", 3))
6328 aKs = aCmd.ArgVec3f ("ks");
6332 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
6335 aBSDF.Ks.r() = aKs.r();
6336 aBSDF.Ks.g() = aKs.g();
6337 aBSDF.Ks.b() = aKs.b();
6340 if (aCmd.HasOption ("kt", 3))
6342 aBSDF.Kt = aCmd.ArgVec3f ("kt");
6344 else if (aCmd.HasOption ("kt", 1, Standard_True))
6346 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
6349 if (aCmd.HasOption ("le", 3))
6351 aBSDF.Le = aCmd.ArgVec3f ("le");
6353 else if (aCmd.HasOption ("le", 1, Standard_True))
6355 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
6358 const std::string aFresnelErrorMessage =
6359 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
6361 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6363 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
6366 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
6368 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6369 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6371 if (aFresnelType == "schlick")
6373 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
6374 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
6375 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
6377 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
6378 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
6379 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
6381 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
6385 theDI << aFresnelErrorMessage.c_str() << "\n";
6388 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
6390 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6391 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6393 if (aFresnelType == "conductor")
6395 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6396 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
6398 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
6402 theDI << aFresnelErrorMessage.c_str() << "\n";
6405 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
6407 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6408 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6410 if (aFresnelType == "constant")
6412 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6414 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
6416 else if (aFresnelType == "dielectric")
6418 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6420 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
6424 theDI << aFresnelErrorMessage.c_str() << "\n";
6429 if (aCmd.HasOption ("normalize"))
6434 aMaterial.SetBSDF (aBSDF);
6435 anIObj->SetMaterial (aMaterial);
6440 //==============================================================================
6441 //function : VLoadSelection
6442 //purpose : Adds given objects to map of AIS and loads selection primitives for them
6443 //==============================================================================
6444 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
6445 Standard_Integer theArgNb,
6446 const char** theArgVec)
6450 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
6454 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
6457 ViewerTest::ViewerInit();
6458 aCtx = ViewerTest::GetAISContext();
6461 // Parse input arguments
6462 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6464 const TCollection_AsciiString aName = theArgVec[anArgIter];
6465 Handle(AIS_InteractiveObject) aShape;
6466 if (!GetMapOfAIS().Find2 (aName, aShape))
6468 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
6469 if (!aDrawShape.IsNull())
6471 aShape = new AIS_Shape (aDrawShape);
6472 GetMapOfAIS().Bind (aShape, aName);
6475 if (aShape.IsNull())
6477 std::cout << "Syntax error: presentation '" << aName << "' not found\n";
6481 aCtx->Load (aShape, -1);
6482 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
6487 //==============================================================================
6488 //function : ViewerTest::Commands
6489 //purpose : Add all the viewer command in the Draw_Interpretor
6490 //==============================================================================
6492 void ViewerTest::Commands(Draw_Interpretor& theCommands)
6494 ViewerTest::ViewerCommands(theCommands);
6495 ViewerTest::RelationCommands(theCommands);
6496 ViewerTest::ObjectCommands(theCommands);
6497 ViewerTest::FilletCommands(theCommands);
6498 ViewerTest::OpenGlCommands(theCommands);
6500 const char *group = "AIS_Display";
6503 theCommands.Add("visos",
6504 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
6505 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
6506 __FILE__, visos, group);
6508 theCommands.Add("vdisplay",
6509 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
6510 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
6511 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
6512 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
6513 "\n\t\t: |topRight|bottomLeft|bottomRight}"
6514 "\n\t\t: [offsetX offsetY]]]"
6515 "\n\t\t: [-dispMode mode] [-highMode mode]"
6516 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
6517 "\n\t\t: [-redisplay] [-erased]"
6518 "\n\t\t: name1 [name2] ... [name n]"
6519 "\n\t\t: Displays named objects."
6520 "\n\t\t: Option -local enables displaying of objects in local"
6521 "\n\t\t: selection context. Local selection context will be opened"
6522 "\n\t\t: if there is not any."
6523 "\n\t\t: -noupdate Suppresses viewer redraw call."
6524 "\n\t\t: -mutable Enables optimizations for mutable objects."
6525 "\n\t\t: -neutral Draws objects in main viewer."
6526 "\n\t\t: -erased Loads the object into context, but does not display it."
6527 "\n\t\t: -layer Sets z-layer for objects."
6528 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
6529 "\n\t\t: options can be used for the default z-layers."
6530 "\n\t\t: -top Draws object on top of main presentations"
6531 "\n\t\t: but below topmost."
6532 "\n\t\t: -topmost Draws in overlay for 3D presentations."
6533 "\n\t\t: with independent Depth."
6534 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
6535 "\n\t\t: (On-Screen-Display)"
6536 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
6537 "\n\t\t: (On-Screen-Display)"
6538 "\n\t\t: -selectable|-noselect Controls selection of objects."
6539 "\n\t\t: -trsfPers Sets a transform persistence flags."
6540 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
6541 "\n\t\t: -2d Displays object in screen coordinates."
6542 "\n\t\t: (DY looks up)"
6543 "\n\t\t: -dispmode Sets display mode for objects."
6544 "\n\t\t: -highmode Sets hilight mode for objects."
6545 "\n\t\t: -redisplay Recomputes presentation of objects.",
6546 __FILE__, VDisplay2, group);
6548 theCommands.Add ("vnbdisplayed",
6550 "\n\t\t: Returns number of displayed objects",
6551 __FILE__, VNbDisplayed, group);
6553 theCommands.Add ("vupdate",
6554 "vupdate name1 [name2] ... [name n]"
6555 "\n\t\t: Updates named objects in interactive context",
6556 __FILE__, VUpdate, group);
6558 theCommands.Add("verase",
6559 "verase [-noupdate|-update] [-local] [name1] ... [name n] [-noerror]"
6560 "\n\t\t: Erases selected or named objects."
6561 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
6562 "\n\t\t: Option -local enables erasing of selected or named objects without"
6563 "\n\t\t: closing local selection context."
6564 "\n\t\t: Option -noerror prevents exception on non-existing objects.",
6565 __FILE__, VErase, group);
6567 theCommands.Add("vremove",
6568 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n] [-noerror]"
6569 "or vremove [-context] -all to remove all objects"
6570 "\n\t\t: Removes selected or named objects."
6571 "\n\t\t If -context is in arguments, the objects are not deleted"
6572 "\n\t\t from the map of objects and names."
6573 "\n\t\t: Option -local enables removing of selected or named objects without"
6574 "\n\t\t: closing local selection context. Empty local selection context will be"
6576 "\n\t\t: Option -noupdate suppresses viewer redraw call."
6577 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects."
6578 "\n\t\t: Option -noerror prevents exception on non-existing objects.",
6579 __FILE__, VRemove, group);
6581 theCommands.Add("vdonly",
6582 "vdonly [-noupdate|-update] [name1] ... [name n]"
6583 "\n\t\t: Displays only selected or named objects",
6584 __FILE__,VDonly2,group);
6586 theCommands.Add("vdisplayall",
6588 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
6589 __FILE__, VDisplayAll, group);
6591 theCommands.Add("veraseall",
6593 "\n\t\t: Erases all objects displayed in the viewer.",
6594 __FILE__, VErase, group);
6596 theCommands.Add("verasetype",
6598 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
6599 __FILE__, VEraseType, group);
6600 theCommands.Add("vbounding",
6601 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
6602 "\n\t\t: [-print] [-hide]"
6603 "\n\t\t: Temporarily display bounding box of specified Interactive"
6604 "\n\t\t: Objects, or print it to console if -print is specified."
6605 "\n\t\t: Already displayed box might be hidden by -hide option.",
6606 __FILE__,VBounding,group);
6608 theCommands.Add("vdisplaytype",
6609 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
6610 __FILE__,VDisplayType,group);
6612 theCommands.Add("vsetdispmode",
6613 "vsetdispmode [name] mode(1,2,..)"
6614 "\n\t\t: Sets display mode for all, selected or named objects.",
6615 __FILE__,VDispMode,group);
6617 theCommands.Add("vunsetdispmode",
6618 "vunsetdispmode [name]"
6619 "\n\t\t: Unsets custom display mode for selected or named objects.",
6620 __FILE__,VDispMode,group);
6622 theCommands.Add("vdir",
6623 "vdir [mask] [-list]"
6624 "\n\t\t: Lists all objects displayed in 3D viewer"
6625 "\n\t\t: mask - name filter like prefix*"
6626 "\n\t\t: -list - format list with new-line per name; OFF by default",
6627 __FILE__,VDir,group);
6629 #ifdef HAVE_FREEIMAGE
6630 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
6632 #define DUMP_FORMATS "{ppm}"
6634 theCommands.Add("vdump",
6635 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
6636 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
6637 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
6638 "\n\t\t: [-tileSize Size=0]"
6639 "\n\t\t: Dumps content of the active view into image file",
6640 __FILE__,VDump,group);
6642 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
6643 __FILE__,VSubInt,group);
6645 theCommands.Add("vaspects",
6646 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
6647 "\n\t\t: [-setVisibility 0|1]"
6648 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
6649 "\n\t\t: [-setBackFaceColor Color]"
6650 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
6651 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
6652 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
6653 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
6654 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
6655 "\n\t\t: [-unsetMarkerType]"
6656 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
6657 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
6658 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
6659 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
6660 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
6661 "\n\t\t: [-isoontriangulation 0|1]"
6662 "\n\t\t: [-setMaxParamValue {value}]"
6663 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
6664 "\n\t\t: [-setShadingModel {unlit|flat|gouraud|phong}]"
6665 "\n\t\t: [-unsetShadingModel]"
6666 "\n\t\t: [-setInterior {solid|hatch|hidenline|point}]"
6667 "\n\t\t: [-unsetInterior] [-setHatch HatchStyle]"
6668 "\n\t\t: [-setFaceBoundaryDraw {0|1}] [-setMostContinuity {c0|c1|c2|c3|cn}"
6669 "\n\t\t: [-setFaceBoundaryWidth LineWidth] [-setFaceBoundaryColor R G B] [-setFaceBoundaryType LineType]"
6670 "\n\t\t: [-setDrawEdges {0|1}] [-setEdgeType LineType] [-setEdgeColor R G B] [-setQuadEdges {0|1}]"
6671 "\n\t\t: [-setDrawSilhouette {0|1}]"
6672 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
6673 "\n\t\t: [-dumpJson]"
6674 "\n\t\t: [-dumpCompact {0|1}]"
6675 "\n\t\t: [-dumpDepth depth]"
6676 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
6677 "\n\t\t: Manage presentation properties of all, selected or named objects."
6678 "\n\t\t: When -subshapes is specified than following properties will be"
6679 "\n\t\t: assigned to specified sub-shapes."
6680 "\n\t\t: When -defaults is specified than presentation properties will be"
6681 "\n\t\t: assigned to all objects that have not their own specified properties"
6682 "\n\t\t: and to all objects to be displayed in the future."
6683 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier."
6684 "\n\t\t: See also vlistcolors and vlistmaterials to list named colors and materials"
6685 "\n\t\t: accepted by arguments -setMaterial and -setColor",
6686 __FILE__,VAspects,group);
6688 theCommands.Add("vsetcolor",
6689 "vsetcolor [-noupdate|-update] [name] ColorName"
6690 "\n\t\t: Sets color for all, selected or named objects."
6691 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
6692 __FILE__,VAspects,group);
6694 theCommands.Add("vunsetcolor",
6695 "vunsetcolor [-noupdate|-update] [name]"
6696 "\n\t\t: Resets color for all, selected or named objects."
6697 "\n\t\t: Alias for vaspects -unsetcolor [name].",
6698 __FILE__,VAspects,group);
6700 theCommands.Add("vsettransparency",
6701 "vsettransparency [-noupdate|-update] [name] Coefficient"
6702 "\n\t\t: Sets transparency for all, selected or named objects."
6703 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
6704 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
6705 __FILE__,VAspects,group);
6707 theCommands.Add("vunsettransparency",
6708 "vunsettransparency [-noupdate|-update] [name]"
6709 "\n\t\t: Resets transparency for all, selected or named objects."
6710 "\n\t\t: Alias for vaspects -unsettransp [name].",
6711 __FILE__,VAspects,group);
6713 theCommands.Add("vsetmaterial",
6714 "vsetmaterial [-noupdate|-update] [name] MaterialName"
6715 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
6716 __FILE__,VAspects,group);
6718 theCommands.Add("vunsetmaterial",
6719 "vunsetmaterial [-noupdate|-update] [name]"
6720 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
6721 __FILE__,VAspects,group);
6723 theCommands.Add("vsetwidth",
6724 "vsetwidth [-noupdate|-update] [name] width(0->10)"
6725 "\n\t\t: Alias for vaspects -setwidth [name] width.",
6726 __FILE__,VAspects,group);
6728 theCommands.Add("vunsetwidth",
6729 "vunsetwidth [-noupdate|-update] [name]"
6730 "\n\t\t: Alias for vaspects -unsetwidth [name].",
6731 __FILE__,VAspects,group);
6733 theCommands.Add("vsetinteriorstyle",
6734 "vsetinteriorstyle [-noupdate|-update] [name] Style"
6735 "\n\t\t: Alias for vaspects -setInterior [name] Style.",
6736 __FILE__,VAspects,group);
6738 theCommands.Add ("vsetedgetype",
6739 "vsetedgetype [name] [-type {solid, dash, dot}] [-color R G B] [-width value]"
6740 "\n\t\t: Alias for vaspects [name] -setEdgeType Type.",
6741 __FILE__, VAspects, group);
6743 theCommands.Add ("vunsetedgetype",
6744 "vunsetedgetype [name]"
6745 "\n\t\t: Alias for vaspects [name] -unsetEdgeType.",
6746 __FILE__, VAspects, group);
6748 theCommands.Add ("vshowfaceboundary",
6749 "vshowfaceboundary [name]"
6750 "\n\t\t: Alias for vaspects [name] -setFaceBoundaryDraw on",
6751 __FILE__, VAspects, group);
6753 theCommands.Add("vsensdis",
6754 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
6755 "\n\t\t: Standard entity types are those defined in Select3D package:"
6756 "\n\t\t: - sensitive box"
6757 "\n\t\t: - sensitive face"
6758 "\n\t\t: - sensitive curve"
6759 "\n\t\t: - sensitive segment"
6760 "\n\t\t: - sensitive circle"
6761 "\n\t\t: - sensitive point"
6762 "\n\t\t: - sensitive triangulation"
6763 "\n\t\t: - sensitive triangle"
6764 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
6765 __FILE__,VDispSensi,group);
6767 theCommands.Add("vsensera",
6768 "vsensera : erase active entities",
6769 __FILE__,VClearSensi,group);
6771 theCommands.Add("vsetshading",
6772 "vsetshading : vsetshading name Quality(default=0.0008) "
6773 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
6774 __FILE__,VShading,group);
6776 theCommands.Add("vunsetshading",
6777 "vunsetshading :vunsetshading name "
6778 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
6779 __FILE__,VShading,group);
6781 theCommands.Add ("vtexture",
6782 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
6783 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
6784 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
6785 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
6786 "\n\t\t: [-modulate {on|off}]"
6787 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
6788 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
6789 "\n\t\t: [-default]"
6790 "\n\t\t: The texture can be specified by filepath"
6791 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
6792 "\n\t\t: The options are:"
6793 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
6794 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
6795 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
6796 "\n\t\t: -modulate Enable or disable texture color modulation"
6797 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
6798 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
6799 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
6800 "\n\t\t: -setFilter Setup texture filter"
6801 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
6802 "\n\t\t: -default Sets texture mapping default parameters",
6803 __FILE__, VTexture, group);
6805 theCommands.Add("vtexscale",
6806 "vtexscale name ScaleU ScaleV"
6807 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
6808 __FILE__,VTexture,group);
6810 theCommands.Add("vtexorigin",
6811 "vtexorigin name OriginU OriginV"
6812 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
6813 __FILE__,VTexture,group);
6815 theCommands.Add("vtexrepeat",
6816 "vtexrepeat name RepeatU RepeatV"
6817 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
6820 theCommands.Add("vtexdefault",
6822 "\n\t\t: Alias for vtexture name -default.",
6825 theCommands.Add("vstate",
6826 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6827 "\n\t\t: Reports show/hidden state for selected or named objects"
6828 "\n\t\t: -entities - print low-level information about detected entities"
6829 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6830 __FILE__,VState,group);
6832 theCommands.Add("vpickshapes",
6833 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6834 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6835 "\n\t\t: Hold also Shift for multiple selection.",
6836 __FILE__, VPickShape, group);
6838 theCommands.Add("vtypes",
6839 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6842 theCommands.Add("vr",
6844 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6845 __FILE__,vr, group);
6847 theCommands.Add("vselfilter",
6848 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6849 "\nSets selection shape type filter in context or remove all filters."
6850 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6851 "\n : Option -clear remove all filters in context",
6852 __FILE__,VSelFilter,group);
6854 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6855 __FILE__, VPickSelected, group);
6857 theCommands.Add ("vloadselection",
6858 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6859 "\n\t\t: primitives for the shapes with names given without displaying them.",
6860 __FILE__, VLoadSelection, group);
6862 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6863 "\nAdjusts parameters of material BSDF:"
6864 "\n -help : Shows this message"
6865 "\n -print : Print BSDF"
6866 "\n -kd : Weight of the Lambertian BRDF"
6867 "\n -kr : Weight of the reflection BRDF"
6868 "\n -kt : Weight of the transmission BTDF"
6869 "\n -ks : Weight of the glossy Blinn BRDF"
6870 "\n -le : Self-emitted radiance"
6871 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6872 "\n Schlick x y z, Dielectric x, Conductor x y"
6873 "\n -roughness : Roughness of material (Blinn's exponent)"
6874 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6875 "\n -absorpcolor : Absorption color (only for transparent material)"
6876 "\n -normalize : Normalize BSDF coefficients",
6877 __FILE__, VBsdf, group);
6881 //=====================================================================
6882 //========================= for testing Draft and Rib =================
6883 //=====================================================================
6884 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6885 #include <DBRep.hxx>
6886 #include <TopoDS_Face.hxx>
6887 #include <gp_Pln.hxx>
6888 #include <AIS_KindOfSurface.hxx>
6889 #include <BRepOffsetAPI_DraftAngle.hxx>
6890 #include <Precision.hxx>
6891 #include <BRepAlgo.hxx>
6892 #include <OSD_Environment.hxx>
6893 #include <DrawTrSurf.hxx>
6894 //#include <DbgTools.hxx>
6895 //#include <FeatAlgo_MakeLinearForm.hxx>
6900 //=======================================================================
6901 //function : IsValid
6903 //=======================================================================
6904 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6905 const TopoDS_Shape& theResult,
6906 const Standard_Boolean closedSolid,
6907 const Standard_Boolean GeomCtrl)
6909 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6910 TCollection_AsciiString checkValid = check.Value();
6911 Standard_Boolean ToCheck = Standard_True;
6912 if (!checkValid.IsEmpty()) {
6914 std::cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6916 if ( checkValid=="true" || checkValid=="TRUE" ) {
6917 ToCheck= Standard_False;
6921 std::cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6924 Standard_Boolean IsValid = Standard_True;
6926 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6931 //===============================================================================
6932 // TDraft : test draft, uses AIS Viewer
6933 // Solid Face Plane Angle Reverse
6934 //===============================================================================
6935 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6937 if (argc < 5) return 1;
6938 // argv[1] - TopoDS_Shape Solid
6939 // argv[2] - TopoDS_Shape Face
6940 // argv[3] - TopoDS_Shape Plane
6941 // argv[4] - Standard_Real Angle
6942 // argv[5] - Standard_Integer Reverse
6944 // Sprintf(prefix, argv[1]);
6945 Standard_Real anAngle = 0;
6946 Standard_Boolean Rev = Standard_False;
6947 Standard_Integer rev = 0;
6948 TopoDS_Shape Solid = DBRep::Get (argv[1]);
6949 TopoDS_Shape face = DBRep::Get (argv[2]);
6950 TopoDS_Face Face = TopoDS::Face(face);
6951 TopoDS_Shape Plane = DBRep::Get (argv[3]);
6952 if (Plane.IsNull ()) {
6953 di << "TEST : Plane is NULL\n";
6956 anAngle = Draw::Atof(argv[4]);
6957 anAngle = 2*M_PI * anAngle / 360.0;
6959 Handle( Geom_Surface )aSurf;
6960 AIS_KindOfSurface aSurfType;
6961 Standard_Real Offset;
6963 if(argc > 4) { // == 5
6964 rev = Draw::Atoi(argv[5]);
6965 Rev = (rev)? Standard_True : Standard_False;
6968 TopoDS_Face face2 = TopoDS::Face(Plane);
6969 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6971 di << "TEST : Can't find plane\n";
6975 aDir = aPln.Axis().Direction();
6978 if (Plane.Orientation() == TopAbs_REVERSED)
6980 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6982 BRepOffsetAPI_DraftAngle Draft (Solid);
6984 if(Abs(anAngle)< Precision::Angular()) {
6985 di << "TEST : NULL angle\n";
6988 if(Rev) anAngle = - anAngle;
6989 Draft.Add (Face, aDir, anAngle, aPln);
6991 if (!Draft.IsDone()) {
6992 di << "TEST : Draft Not DONE \n";
6995 TopTools_ListOfShape Larg;
6997 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6998 di << "TEST : DesignAlgo returns Not valid\n";
7002 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
7003 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
7005 if ( !ais.IsNull() ) {
7006 ais->SetColor(DEFAULT_COLOR);
7007 ais->SetMaterial(DEFAULT_MATERIAL);
7008 // Display the AIS_Shape without redraw
7009 Ctx->Display(ais, Standard_False);
7011 const char *Name = "draft1";
7012 Handle(AIS_InteractiveObject) an_object;
7013 if (GetMapOfAIS().Find2(Name, an_object))
7015 if (!an_object.IsNull())
7017 Ctx->Remove (an_object, Standard_True);
7019 GetMapOfAIS().UnBind2 (Name);
7021 GetMapOfAIS().Bind(ais, Name);
7022 // DBRep::Set("draft", ais->Shape());
7024 Ctx->Display(ais, Standard_True);
7028 //==============================================================================
7029 //function : splitParameter
7030 //purpose : Split parameter string to parameter name and parameter value
7031 //==============================================================================
7032 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
7033 TCollection_AsciiString& theName,
7034 TCollection_AsciiString& theValue)
7036 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
7038 if (aParamNameEnd == 0)
7040 return Standard_False;
7043 TCollection_AsciiString aString (theString);
7044 if (aParamNameEnd != 0)
7046 theValue = aString.Split (aParamNameEnd);
7047 aString.Split (aString.Length() - 1);
7051 return Standard_True;
7054 //============================================================================
7056 //============================================================================
7057 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
7060 DrawTrSurf::BasicCommands(theCommands);
7061 const char* group = "Check Features Operations commands";
7063 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
7065 &TDraft,group); //Draft_Modification
7068 //==============================================================================
7069 // ViewerTest::Factory
7070 //==============================================================================
7071 void ViewerTest::Factory(Draw_Interpretor& theDI)
7073 // definition of Viewer Command
7074 ViewerTest::Commands(theDI);
7077 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
7081 // Declare entry point PLUGINFACTORY