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 (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 == "default"
521 || aTypeStr == "def")
523 theModel = Graphic3d_TOSM_DEFAULT;
525 else if (aTypeStr.IsIntegerValue())
527 const int aTypeInt = aTypeStr.IntegerValue();
528 if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
530 return Standard_False;
532 theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
536 return Standard_False;
538 return Standard_True;
541 //=======================================================================
542 //function : parseZLayer
544 //=======================================================================
545 Standard_Boolean ViewerTest::parseZLayer (Standard_CString theArg,
546 Standard_Boolean theToAllowInteger,
547 Graphic3d_ZLayerId& theLayer)
549 TCollection_AsciiString aName (theArg);
551 if (aName == "default"
554 theLayer = Graphic3d_ZLayerId_Default;
556 else if (aName == "top")
558 theLayer = Graphic3d_ZLayerId_Top;
560 else if (aName == "topmost")
562 theLayer = Graphic3d_ZLayerId_Topmost;
564 else if (aName == "overlay"
565 || aName == "toposd")
567 theLayer = Graphic3d_ZLayerId_TopOSD;
569 else if (aName == "underlay"
570 || aName == "botosd")
572 theLayer = Graphic3d_ZLayerId_BotOSD;
574 else if (aName == "undefined")
576 theLayer = Graphic3d_ZLayerId_UNKNOWN;
578 else if (!GetAISContext().IsNull())
580 const Handle(V3d_Viewer)& aViewer = ViewerTest::GetAISContext()->CurrentViewer();
581 TColStd_SequenceOfInteger aLayers;
582 aViewer->GetAllZLayers (aLayers);
583 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
585 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
586 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aName, Standard_False))
588 theLayer = aLayeriter.Value();
593 if (!theToAllowInteger
594 || !aName.IsIntegerValue())
598 Graphic3d_ZLayerId aLayer = aName.IntegerValue();
599 if (aLayer == Graphic3d_ZLayerId_UNKNOWN
600 || std::find (aLayers.begin(), aLayers.end(), aLayer) != aLayers.end())
610 //=======================================================================
611 //function : GetTypeNames
613 //=======================================================================
614 static const char** GetTypeNames()
616 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
617 "Shape","ConnectedShape","MultiConn.Shape",
618 "ConnectedInter.","MultiConn.",
619 "Constraint","Dimension"};
620 static const char** ThePointer = names;
624 //=======================================================================
625 //function : GetTypeAndSignfromString
627 //=======================================================================
628 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
630 const char ** thefullnames = GetTypeNames();
631 Standard_Integer index(-1);
633 for(Standard_Integer i=0;i<=13 && index==-1;i++)
634 if(!strcasecmp(name,thefullnames[i]))
638 TheType = AIS_KOI_None;
644 TheType = AIS_KOI_Datum;
648 TheType = AIS_KOI_Shape;
652 TheType = AIS_KOI_Object;
656 TheType = AIS_KOI_Relation;
665 #include <Draw_Interpretor.hxx>
667 #include <Draw_Appli.hxx>
671 #include <TCollection_AsciiString.hxx>
672 #include <V3d_Viewer.hxx>
673 #include <V3d_View.hxx>
676 #include <AIS_InteractiveContext.hxx>
677 #include <AIS_Shape.hxx>
678 #include <AIS_DisplayMode.hxx>
679 #include <TColStd_MapOfInteger.hxx>
680 #include <AIS_MapOfInteractive.hxx>
681 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
682 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
683 #include <ViewerTest_EventManager.hxx>
685 #include <TopoDS_Solid.hxx>
686 #include <BRepTools.hxx>
687 #include <BRep_Builder.hxx>
688 #include <TopAbs_ShapeEnum.hxx>
690 #include <TopoDS.hxx>
691 #include <BRep_Tool.hxx>
694 #include <Draw_Window.hxx>
695 #include <AIS_ListIteratorOfListOfInteractive.hxx>
696 #include <AIS_ListOfInteractive.hxx>
697 #include <AIS_DisplayMode.hxx>
698 #include <TopTools_ListOfShape.hxx>
699 #include <BRepOffsetAPI_MakeThickSolid.hxx>
701 //==============================================================================
702 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
703 //==============================================================================
704 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
705 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
709 //=======================================================================
712 //=======================================================================
713 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
714 const Handle(AIS_InteractiveObject)& theObject,
715 const Standard_Boolean theToUpdate,
716 const Standard_Boolean theReplaceIfExists)
718 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
719 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
722 std::cout << "Error: AIS context is not available.\n";
723 return Standard_False;
726 if (aMap.IsBound2 (theName))
728 if (!theReplaceIfExists)
730 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
731 << "Please use another name.\n";
732 return Standard_False;
735 if (Handle(AIS_InteractiveObject) anOldObj = aMap.Find2 (theName))
737 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
739 aMap.UnBind2 (theName);
742 if (theObject.IsNull())
744 // object with specified name has been already unbound
745 return Standard_True;
748 // unbind AIS object if it was bound with another name
749 aMap.UnBind1 (theObject);
751 // can be registered without rebinding
752 aMap.Bind (theObject, theName);
753 aCtx->Display (theObject, theToUpdate);
754 return Standard_True;
757 //! Alias for ViewerTest::Display(), compatibility with old code.
758 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
759 const Handle(AIS_InteractiveObject)& theObject,
760 Standard_Boolean theReplaceIfExists = Standard_True)
762 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
765 static NCollection_List<Handle(ViewerTest_EventManager)> theEventMgrs;
767 static Handle(V3d_View)& a3DView()
769 static Handle(V3d_View) Viou;
774 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
775 static Handle(AIS_InteractiveContext) aContext;
779 const Handle(V3d_View)& ViewerTest::CurrentView()
783 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
788 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
790 return TheAISContext();
793 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
795 TheAISContext() = aCtx;
796 ViewerTest::ResetEventManager();
799 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
801 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
804 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
806 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
810 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
811 theEventMgrs.Prepend(EM);
814 void ViewerTest::UnsetEventManager()
816 theEventMgrs.RemoveFirst();
820 void ViewerTest::ResetEventManager()
822 theEventMgrs.Clear();
823 theEventMgrs.Prepend (new ViewerTest_EventManager (ViewerTest::CurrentView(), ViewerTest::GetAISContext()));
826 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
828 return !theEventMgrs.IsEmpty()
829 ? theEventMgrs.First()
830 : Handle(ViewerTest_EventManager)();
833 //=======================================================================
834 //function : Get Context and active view
836 //=======================================================================
837 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
838 Handle(V3d_View)& theView)
840 theCtx = ViewerTest::GetAISContext();
841 theView = ViewerTest::CurrentView();
845 std::cout << "Error: cannot find an active view!\n";
846 return Standard_False;
848 return Standard_True;
851 //==============================================================================
853 //purpose : Remove all the object from the viewer
854 //==============================================================================
855 void ViewerTest::Clear()
857 if (a3DView().IsNull())
862 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
863 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
865 const Handle(AIS_InteractiveObject) anObj = anObjIter.Key1();
866 if (anObj->GetContext() != TheAISContext())
871 std::cout << "Remove " << anObjIter.Key2() << std::endl;
872 TheAISContext()->Remove (anObj, Standard_False);
873 aListRemoved.Append (anObj);
876 TheAISContext()->RebuildSelectionStructs();
877 TheAISContext()->UpdateCurrentViewer();
878 if (aListRemoved.Size() == GetMapOfAIS().Extent())
880 GetMapOfAIS().Clear();
884 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
886 GetMapOfAIS().UnBind1 (anObjIter.Value());
891 //==============================================================================
892 //function : CopyIsoAspect
893 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
894 //==============================================================================
895 static Handle(Prs3d_IsoAspect) CopyIsoAspect
896 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
897 const Standard_Integer theNbIsos)
899 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
900 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
901 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
903 Handle(Prs3d_IsoAspect) aResult =
904 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
909 //==============================================================================
911 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
912 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
913 //==============================================================================
914 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
916 if (TheAISContext().IsNull()) {
917 di << argv[0] << " Call 'vinit' before!\n";
922 di << "Current number of isos : " <<
923 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
924 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
925 di << "IsoOnPlane mode is " <<
926 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
927 di << "IsoOnTriangulation mode is " <<
928 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
932 Standard_Integer aLastInd = argc - 1;
933 Standard_Boolean isChanged = Standard_False;
934 Standard_Integer aNbUIsos = 0;
935 Standard_Integer aNbVIsos = 0;
938 Standard_Boolean isIsoOnPlane = Standard_False;
940 if (strcmp(argv[aLastInd], "1") == 0) {
941 isIsoOnPlane = Standard_True;
942 isChanged = Standard_True;
943 } else if (strcmp(argv[aLastInd], "0") == 0) {
944 isIsoOnPlane = Standard_False;
945 isChanged = Standard_True;
949 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
950 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
953 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
954 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
956 TheAISContext()->IsoOnPlane(isIsoOnPlane);
959 // If there are no shapes provided set the default numbers.
960 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
961 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
968 for (i = 1; i <= aLastInd; i++)
970 TCollection_AsciiString name(argv[i]);
971 Handle(AIS_InteractiveObject) aShape;
972 GetMapOfAIS().Find2(name, aShape);
975 std::cout << "Syntax error: object '" << name << "' is not found\n";
979 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
980 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
981 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
984 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
985 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
986 TheAISContext()->SetLocalAttributes (aShape, CurDrawer, Standard_False);
987 TheAISContext()->Redisplay (aShape, Standard_False);
991 di << "Number of isos for " << argv[i] << " : "
992 << aUIso->Number() << " " << aVIso->Number() << "\n";
997 TheAISContext()->UpdateCurrentViewer();
1003 static Standard_Integer VDispSensi (Draw_Interpretor& ,
1004 Standard_Integer theArgNb,
1009 std::cout << "Error: wrong syntax!\n";
1013 Handle(AIS_InteractiveContext) aCtx;
1014 Handle(V3d_View) aView;
1015 if (!getCtxAndView (aCtx, aView))
1020 aCtx->DisplayActiveSensitive (aView);
1025 static Standard_Integer VClearSensi (Draw_Interpretor& ,
1026 Standard_Integer theArgNb,
1031 std::cout << "Error: wrong syntax!\n";
1035 Handle(AIS_InteractiveContext) aCtx;
1036 Handle(V3d_View) aView;
1037 if (!getCtxAndView (aCtx, aView))
1041 aCtx->ClearActiveSensitive (aView);
1045 //==============================================================================
1047 //purpose : To list the displayed object with their attributes
1048 //==============================================================================
1049 static int VDir (Draw_Interpretor& theDI,
1050 Standard_Integer theNbArgs,
1051 const char** theArgVec)
1053 TCollection_AsciiString aMatch;
1054 Standard_Boolean toFormat = Standard_False;
1055 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
1057 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
1058 anArgCase.LowerCase();
1059 if (anArgCase == "-list"
1060 || anArgCase == "-format")
1062 toFormat = Standard_True;
1064 else if (aMatch.IsEmpty())
1066 aMatch = theArgVec[anArgIter];
1070 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
1075 TCollection_AsciiString aRes;
1076 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
1078 if (!aMatch.IsEmpty())
1080 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aMatch + "' '" + anIter.Key2() + "'";
1081 if (theDI.Eval (aCheck.ToCString()) == 0
1082 && *theDI.Result() != '1')
1090 aRes += TCollection_AsciiString("\t") + anIter.Key2() + "\n";
1094 aRes += anIter.Key2() + " ";
1102 //! Auxiliary enumeration
1103 enum ViewerTest_StereoPair
1105 ViewerTest_SP_Single,
1106 ViewerTest_SP_SideBySide,
1107 ViewerTest_SP_OverUnder
1110 //==============================================================================
1112 //purpose : To dump the active view snapshot to image file
1113 //==============================================================================
1114 static Standard_Integer VDump (Draw_Interpretor& theDI,
1115 Standard_Integer theArgNb,
1116 Standard_CString* theArgVec)
1120 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
1124 Standard_Integer anArgIter = 1;
1125 Standard_CString aFilePath = theArgVec[anArgIter++];
1126 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
1127 V3d_ImageDumpOptions aParams;
1128 aParams.BufferType = Graphic3d_BT_RGB;
1129 aParams.StereoOptions = V3d_SDO_MONO;
1130 for (; anArgIter < theArgNb; ++anArgIter)
1132 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1134 if (anArg == "-buffer")
1136 if (++anArgIter >= theArgNb)
1138 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
1142 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
1143 aBufArg.LowerCase();
1144 if (aBufArg == "rgba")
1146 aParams.BufferType = Graphic3d_BT_RGBA;
1148 else if (aBufArg == "rgb")
1150 aParams.BufferType = Graphic3d_BT_RGB;
1152 else if (aBufArg == "depth")
1154 aParams.BufferType = Graphic3d_BT_Depth;
1158 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
1162 else if (anArg == "-stereo")
1164 if (++anArgIter >= theArgNb)
1166 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
1170 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
1171 aStereoArg.LowerCase();
1172 if (aStereoArg == "l"
1173 || aStereoArg == "left")
1175 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1177 else if (aStereoArg == "r"
1178 || aStereoArg == "right")
1180 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1182 else if (aStereoArg == "mono")
1184 aParams.StereoOptions = V3d_SDO_MONO;
1186 else if (aStereoArg == "blended"
1187 || aStereoArg == "blend"
1188 || aStereoArg == "stereo")
1190 aParams.StereoOptions = V3d_SDO_BLENDED;
1192 else if (aStereoArg == "sbs"
1193 || aStereoArg == "sidebyside")
1195 aStereoPair = ViewerTest_SP_SideBySide;
1197 else if (aStereoArg == "ou"
1198 || aStereoArg == "overunder")
1200 aStereoPair = ViewerTest_SP_OverUnder;
1204 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
1208 else if (anArg == "-rgba"
1211 aParams.BufferType = Graphic3d_BT_RGBA;
1213 else if (anArg == "-rgb"
1216 aParams.BufferType = Graphic3d_BT_RGB;
1218 else if (anArg == "-depth"
1219 || anArg == "depth")
1221 aParams.BufferType = Graphic3d_BT_Depth;
1223 else if (anArg == "-width"
1225 || anArg == "sizex")
1227 if (aParams.Width != 0)
1229 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1232 else if (++anArgIter >= theArgNb)
1234 std::cout << "Error: integer value is expected right after 'width'\n";
1237 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1239 else if (anArg == "-height"
1240 || anArg == "height"
1241 || anArg == "-sizey")
1243 if (aParams.Height != 0)
1245 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1248 else if (++anArgIter >= theArgNb)
1250 std::cout << "Error: integer value is expected right after 'height'\n";
1253 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1255 else if (anArg == "-tile"
1256 || anArg == "-tilesize")
1258 if (++anArgIter >= theArgNb)
1260 std::cout << "Error: integer value is expected right after 'tileSize'\n";
1263 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1267 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
1271 if ((aParams.Width <= 0 && aParams.Height > 0)
1272 || (aParams.Width > 0 && aParams.Height <= 0))
1274 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
1278 Handle(V3d_View) aView = ViewerTest::CurrentView();
1281 std::cout << "Error: cannot find an active view!\n";
1285 if (aParams.Width <= 0 || aParams.Height <= 0)
1287 aView->Window()->Size (aParams.Width, aParams.Height);
1290 Image_AlienPixMap aPixMap;
1291 Image_Format aFormat = Image_Format_UNKNOWN;
1292 switch (aParams.BufferType)
1294 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1295 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1296 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1297 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1300 switch (aStereoPair)
1302 case ViewerTest_SP_Single:
1304 if (!aView->ToPixMap (aPixMap, aParams))
1306 theDI << "Fail: view dump failed!\n";
1309 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1310 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1312 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1313 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1317 case ViewerTest_SP_SideBySide:
1319 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1321 theDI << "Fail: not enough memory for image allocation!\n";
1325 Image_PixMap aPixMapL, aPixMapR;
1326 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1327 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1328 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1329 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1331 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1332 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1333 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1334 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1337 theDI << "Fail: view dump failed!\n";
1342 case ViewerTest_SP_OverUnder:
1344 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1346 theDI << "Fail: not enough memory for image allocation!\n";
1350 Image_PixMap aPixMapL, aPixMapR;
1351 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1352 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1353 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1354 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1356 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1357 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1358 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1359 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1362 theDI << "Fail: view dump failed!\n";
1369 if (!aPixMap.Save (aFilePath))
1371 theDI << "Fail: image can not be saved!\n";
1376 enum TypeOfDispOperation
1378 TypeOfDispOperation_SetDispMode,
1379 TypeOfDispOperation_UnsetDispMode
1382 //! Displays,Erase...
1383 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1384 const Standard_Integer theMode,
1385 const TypeOfDispOperation theType,
1386 const Standard_Boolean theToUpdate)
1388 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1391 case TypeOfDispOperation_SetDispMode:
1393 if (!thePrs.IsNull())
1395 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1399 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1403 case TypeOfDispOperation_UnsetDispMode:
1405 if (!thePrs.IsNull())
1407 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1411 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1418 //=======================================================================
1421 //=======================================================================
1422 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1427 std::cout << "Syntax error: wrong number of arguments\n";
1431 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1432 ? TypeOfDispOperation_UnsetDispMode
1433 : TypeOfDispOperation_SetDispMode;
1434 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1435 if (aType == TypeOfDispOperation_UnsetDispMode)
1439 if (aCtx->NbSelected() == 0)
1441 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1445 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1447 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1450 aCtx->UpdateCurrentViewer();
1454 TCollection_AsciiString aName = argv[1];
1455 Handle(AIS_InteractiveObject) aPrs;
1456 if (GetMapOfAIS().Find2 (aName, aPrs)
1459 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1465 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1466 if (aCtx->NbSelected() == 0
1467 && aType == TypeOfDispOperation_SetDispMode)
1469 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1471 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1473 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1475 aCtx->UpdateCurrentViewer();
1479 Handle(AIS_InteractiveObject) aPrs;
1480 TCollection_AsciiString aName (argv[1]);
1481 if (GetMapOfAIS().Find2 (aName, aPrs)
1484 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1491 //=======================================================================
1494 //=======================================================================
1495 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1497 if(argc==1) return 1;
1498 Standard_Integer On = Draw::Atoi(argv[1]);
1499 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1503 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1504 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1505 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1509 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1513 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1517 Ctx->UpdateCurrentViewer();
1520 Handle(AIS_InteractiveObject) IO;
1521 TCollection_AsciiString name = argv[2];
1522 if (GetMapOfAIS().Find2 (name, IO)
1526 Ctx->SubIntensityOn(IO, Standard_True);
1528 Ctx->SubIntensityOff(IO, Standard_True);
1535 //! Auxiliary class to iterate presentations from different collections.
1536 class ViewTest_PrsIter
1540 //! Create and initialize iterator object.
1541 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1542 : mySource (IterSource_All)
1544 NCollection_Sequence<TCollection_AsciiString> aNames;
1545 if (!theName.IsEmpty())
1546 aNames.Append (theName);
1550 //! Create and initialize iterator object.
1551 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1552 : mySource (IterSource_All)
1557 //! Initialize the iterator.
1558 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1560 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1562 mySelIter.Nullify();
1563 myCurrent.Nullify();
1564 myCurrentTrs.Nullify();
1565 if (!mySeq.IsEmpty())
1567 mySource = IterSource_List;
1568 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1570 else if (aCtx->NbSelected() > 0)
1572 mySource = IterSource_Selected;
1574 mySelIter->InitSelected();
1578 mySource = IterSource_All;
1579 myMapIter.Initialize (GetMapOfAIS());
1584 const TCollection_AsciiString& CurrentName() const
1586 return myCurrentName;
1589 const Handle(AIS_InteractiveObject)& Current() const
1594 const Handle(Standard_Transient)& CurrentTrs() const
1596 return myCurrentTrs;
1599 //! @return true if iterator points to valid object within collection
1600 Standard_Boolean More() const
1604 case IterSource_All: return myMapIter.More();
1605 case IterSource_List: return mySeqIter.More();
1606 case IterSource_Selected: return mySelIter->MoreSelected();
1608 return Standard_False;
1611 //! Go to the next item.
1614 myCurrentName.Clear();
1615 myCurrentTrs.Nullify();
1616 myCurrent.Nullify();
1619 case IterSource_All:
1624 case IterSource_List:
1629 case IterSource_Selected:
1631 mySelIter->NextSelected();
1644 case IterSource_All:
1646 if (myMapIter.More())
1648 myCurrentName = myMapIter.Key2();
1649 myCurrentTrs = myMapIter.Key1();
1650 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1654 case IterSource_List:
1656 if (mySeqIter.More())
1658 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1660 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1663 myCurrentName = mySeqIter.Value();
1664 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1665 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1669 case IterSource_Selected:
1671 if (mySelIter->MoreSelected())
1673 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1674 myCurrent = mySelIter->SelectedInteractive();
1692 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1693 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1694 NCollection_Sequence<TCollection_AsciiString> mySeq;
1695 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1697 TCollection_AsciiString myCurrentName;//!< current item name
1698 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1699 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1701 IterSource mySource; //!< iterated collection
1705 //! Parse interior style name.
1706 static bool parseInteriorStyle (const TCollection_AsciiString& theArg,
1707 Aspect_InteriorStyle& theStyle)
1709 TCollection_AsciiString anArg (theArg);
1711 if (anArg == "empty")
1713 theStyle = Aspect_IS_EMPTY;
1715 else if (anArg == "hollow")
1717 theStyle = Aspect_IS_HOLLOW;
1719 else if (anArg == "solid")
1721 theStyle = Aspect_IS_SOLID;
1723 else if (anArg == "hatch")
1725 theStyle = Aspect_IS_HATCH;
1727 else if (anArg == "hiddenline"
1728 || anArg == "hidden-line"
1729 || anArg == "hidden_line")
1731 theStyle = Aspect_IS_HIDDENLINE;
1733 else if (anArg == "point")
1735 theStyle = Aspect_IS_POINT;
1737 else if (theArg.IsIntegerValue())
1739 const Standard_Integer anIntStyle = theArg.IntegerValue();
1740 if (anIntStyle < Aspect_IS_EMPTY || anIntStyle > Aspect_IS_POINT)
1744 theStyle = (Aspect_InteriorStyle)anIntStyle;
1753 //! Auxiliary structure for VAspects
1754 struct ViewerTest_AspectsChangeSet
1756 Standard_Integer ToSetVisibility;
1757 Standard_Integer Visibility;
1759 Standard_Integer ToSetColor;
1760 Quantity_Color Color;
1761 Standard_Integer ToSetBackFaceColor;
1762 Quantity_Color BackFaceColor;
1764 Standard_Integer ToSetLineWidth;
1765 Standard_Real LineWidth;
1767 Standard_Integer ToSetTypeOfLine;
1768 Aspect_TypeOfLine TypeOfLine;
1770 Standard_Integer ToSetTypeOfMarker;
1771 Aspect_TypeOfMarker TypeOfMarker;
1772 Handle(Image_PixMap) MarkerImage;
1774 Standard_Integer ToSetMarkerSize;
1775 Standard_Real MarkerSize;
1777 Standard_Integer ToSetTransparency;
1778 Standard_Real Transparency;
1780 Standard_Integer ToSetAlphaMode;
1781 Graphic3d_AlphaMode AlphaMode;
1782 Standard_ShortReal AlphaCutoff;
1784 Standard_Integer ToSetMaterial;
1785 Graphic3d_NameOfMaterial Material;
1786 TCollection_AsciiString MatName;
1788 NCollection_Sequence<TopoDS_Shape> SubShapes;
1790 Standard_Integer ToSetShowFreeBoundary;
1791 Standard_Integer ToSetFreeBoundaryWidth;
1792 Standard_Real FreeBoundaryWidth;
1793 Standard_Integer ToSetFreeBoundaryColor;
1794 Quantity_Color FreeBoundaryColor;
1796 Standard_Integer ToEnableIsoOnTriangulation;
1798 Standard_Integer ToSetFaceBoundaryDraw;
1799 Standard_Integer ToSetFaceBoundaryUpperContinuity;
1800 GeomAbs_Shape FaceBoundaryUpperContinuity;
1802 Standard_Integer ToSetFaceBoundaryColor;
1803 Quantity_Color FaceBoundaryColor;
1805 Standard_Integer ToSetFaceBoundaryWidth;
1806 Standard_Real FaceBoundaryWidth;
1808 Standard_Integer ToSetTypeOfFaceBoundaryLine;
1809 Aspect_TypeOfLine TypeOfFaceBoundaryLine;
1811 Standard_Integer ToSetMaxParamValue;
1812 Standard_Real MaxParamValue;
1814 Standard_Integer ToSetSensitivity;
1815 Standard_Integer SelectionMode;
1816 Standard_Integer Sensitivity;
1818 Standard_Integer ToSetHatch;
1819 Standard_Integer StdHatchStyle;
1820 TCollection_AsciiString PathToHatchPattern;
1822 Standard_Integer ToSetShadingModel;
1823 Graphic3d_TypeOfShadingModel ShadingModel;
1824 TCollection_AsciiString ShadingModelName;
1826 Standard_Integer ToSetInterior;
1827 Aspect_InteriorStyle InteriorStyle;
1829 Standard_Integer ToSetDrawSilhouette;
1831 Standard_Integer ToSetDrawEdges;
1832 Standard_Integer ToSetQuadEdges;
1834 Standard_Integer ToSetEdgeColor;
1835 Quantity_ColorRGBA EdgeColor;
1837 Standard_Integer ToSetEdgeWidth;
1838 Standard_Real EdgeWidth;
1840 Standard_Integer ToSetTypeOfEdge;
1841 Aspect_TypeOfLine TypeOfEdge;
1843 //! Empty constructor
1844 ViewerTest_AspectsChangeSet()
1845 : ToSetVisibility (0),
1848 Color (DEFAULT_COLOR),
1849 ToSetBackFaceColor(0),
1850 BackFaceColor (DEFAULT_COLOR),
1853 ToSetTypeOfLine (0),
1854 TypeOfLine (Aspect_TOL_SOLID),
1855 ToSetTypeOfMarker (0),
1856 TypeOfMarker (Aspect_TOM_PLUS),
1857 ToSetMarkerSize (0),
1859 ToSetTransparency (0),
1862 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1865 Material (Graphic3d_NOM_DEFAULT),
1866 ToSetShowFreeBoundary (0),
1867 ToSetFreeBoundaryWidth (0),
1868 FreeBoundaryWidth (1.0),
1869 ToSetFreeBoundaryColor (0),
1870 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1871 ToEnableIsoOnTriangulation (0),
1873 ToSetFaceBoundaryDraw (0),
1874 ToSetFaceBoundaryUpperContinuity (0),
1875 FaceBoundaryUpperContinuity(GeomAbs_CN),
1876 ToSetFaceBoundaryColor (0),
1877 FaceBoundaryColor (Quantity_NOC_BLACK),
1878 ToSetFaceBoundaryWidth (0),
1879 FaceBoundaryWidth (1.0f),
1880 ToSetTypeOfFaceBoundaryLine(0),
1881 TypeOfFaceBoundaryLine (Aspect_TOL_SOLID),
1883 ToSetMaxParamValue (0),
1884 MaxParamValue (500000),
1885 ToSetSensitivity (0),
1890 ToSetShadingModel (0),
1891 ShadingModel (Graphic3d_TOSM_DEFAULT),
1893 InteriorStyle (Aspect_IS_SOLID),
1894 ToSetDrawSilhouette (0),
1900 ToSetTypeOfEdge (0),
1901 TypeOfEdge (Aspect_TOL_SOLID)
1904 //! @return true if no changes have been requested
1905 Standard_Boolean IsEmpty() const
1907 return ToSetVisibility == 0
1908 && ToSetLineWidth == 0
1909 && ToSetTransparency == 0
1910 && ToSetAlphaMode == 0
1912 && ToSetBackFaceColor == 0
1913 && ToSetMaterial == 0
1914 && ToSetShowFreeBoundary == 0
1915 && ToSetFreeBoundaryColor == 0
1916 && ToSetFreeBoundaryWidth == 0
1917 && ToEnableIsoOnTriangulation == 0
1918 && ToSetFaceBoundaryDraw == 0
1919 && ToSetFaceBoundaryUpperContinuity == 0
1920 && ToSetFaceBoundaryColor == 0
1921 && ToSetFaceBoundaryWidth == 0
1922 && ToSetTypeOfFaceBoundaryLine == 0
1923 && ToSetMaxParamValue == 0
1924 && ToSetSensitivity == 0
1926 && ToSetShadingModel == 0
1927 && ToSetInterior == 0
1928 && ToSetDrawSilhouette == 0
1929 && ToSetDrawEdges == 0
1930 && ToSetQuadEdges == 0
1931 && ToSetEdgeColor == 0
1932 && ToSetEdgeWidth == 0
1933 && ToSetTypeOfEdge == 0;
1936 //! @return true if properties are valid
1937 Standard_Boolean Validate() const
1939 Standard_Boolean isOk = Standard_True;
1940 if (Visibility != 0 && Visibility != 1)
1942 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1943 isOk = Standard_False;
1945 if (LineWidth <= 0.0
1946 || LineWidth > 10.0)
1948 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1949 isOk = Standard_False;
1951 if (Transparency < 0.0
1952 || Transparency > 1.0)
1954 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1955 isOk = Standard_False;
1957 if (ToSetAlphaMode == 1
1958 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1960 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1961 isOk = Standard_False;
1963 if (FreeBoundaryWidth <= 0.0
1964 || FreeBoundaryWidth > 10.0)
1966 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1967 isOk = Standard_False;
1969 if (MaxParamValue < 0.0)
1971 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1972 isOk = Standard_False;
1974 if (Sensitivity <= 0 && ToSetSensitivity)
1976 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1977 isOk = Standard_False;
1979 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1981 std::cout << "Error: hatch style must be specified\n";
1982 isOk = Standard_False;
1984 if (ToSetShadingModel == 1
1985 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
1987 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1988 isOk = Standard_False;
1993 //! Apply aspects to specified drawer.
1994 bool Apply (const Handle(Prs3d_Drawer)& theDrawer)
1996 bool toRecompute = false;
1997 const Handle(Prs3d_Drawer)& aDefDrawer = ViewerTest::GetAISContext()->DefaultDrawer();
1998 if (ToSetShowFreeBoundary != 0)
2000 theDrawer->SetFreeBoundaryDraw (ToSetShowFreeBoundary == 1);
2003 if (ToSetFreeBoundaryWidth != 0)
2005 if (ToSetFreeBoundaryWidth != -1
2006 || theDrawer->HasOwnFreeBoundaryAspect())
2008 if (!theDrawer->HasOwnFreeBoundaryAspect())
2010 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2011 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
2012 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2015 theDrawer->FreeBoundaryAspect()->SetWidth (FreeBoundaryWidth);
2018 if (ToSetFreeBoundaryColor != 0)
2020 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2021 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
2022 aBoundaryAspect->SetColor (FreeBoundaryColor);
2023 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2026 if (ToSetTypeOfLine != 0)
2028 if (ToSetTypeOfLine != -1
2029 || theDrawer->HasOwnLineAspect()
2030 || theDrawer->HasOwnWireAspect()
2031 || theDrawer->HasOwnFreeBoundaryAspect()
2032 || theDrawer->HasOwnUnFreeBoundaryAspect()
2033 || theDrawer->HasOwnSeenLineAspect())
2035 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
2036 theDrawer->LineAspect()->SetTypeOfLine (TypeOfLine);
2037 theDrawer->WireAspect()->SetTypeOfLine (TypeOfLine);
2038 theDrawer->FreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
2039 theDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
2040 theDrawer->SeenLineAspect()->SetTypeOfLine (TypeOfLine);
2043 if (ToSetTypeOfMarker != 0)
2045 if (ToSetTypeOfMarker != -1
2046 || theDrawer->HasOwnPointAspect())
2048 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
2049 theDrawer->PointAspect()->SetTypeOfMarker (TypeOfMarker);
2050 theDrawer->PointAspect()->Aspect()->SetMarkerImage (MarkerImage.IsNull() ? Handle(Graphic3d_MarkerImage)() : new Graphic3d_MarkerImage (MarkerImage));
2053 if (ToSetMarkerSize != 0)
2055 if (ToSetMarkerSize != -1
2056 || theDrawer->HasOwnPointAspect())
2058 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
2059 theDrawer->PointAspect()->SetScale (MarkerSize);
2063 if (ToSetMaxParamValue != 0)
2065 if (ToSetMaxParamValue != -1
2066 || theDrawer->HasOwnMaximalParameterValue())
2068 theDrawer->SetMaximalParameterValue (MaxParamValue);
2072 if (ToSetFaceBoundaryDraw != 0)
2074 if (ToSetFaceBoundaryDraw != -1
2075 || theDrawer->HasOwnFaceBoundaryDraw())
2078 theDrawer->SetFaceBoundaryDraw (ToSetFaceBoundaryDraw == 1);
2081 if (ToSetFaceBoundaryUpperContinuity != 0)
2083 if (ToSetFaceBoundaryUpperContinuity != -1
2084 || theDrawer->HasOwnFaceBoundaryUpperContinuity())
2087 if (ToSetFaceBoundaryUpperContinuity == -1)
2089 theDrawer->UnsetFaceBoundaryUpperContinuity();
2093 theDrawer->SetFaceBoundaryUpperContinuity (FaceBoundaryUpperContinuity);
2097 if (ToSetFaceBoundaryColor != 0)
2099 if (ToSetFaceBoundaryColor != -1
2100 || theDrawer->HasOwnFaceBoundaryAspect())
2102 if (ToSetFaceBoundaryColor == -1)
2105 theDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
2109 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2110 theDrawer->FaceBoundaryAspect()->SetColor (FaceBoundaryColor);
2114 if (ToSetFaceBoundaryWidth != 0)
2116 if (ToSetFaceBoundaryWidth != -1
2117 || theDrawer->HasOwnFaceBoundaryAspect())
2119 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2120 theDrawer->FaceBoundaryAspect()->SetWidth (FaceBoundaryWidth);
2123 if (ToSetTypeOfFaceBoundaryLine != 0)
2125 if (ToSetTypeOfFaceBoundaryLine != -1
2126 || theDrawer->HasOwnFaceBoundaryAspect())
2128 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2129 theDrawer->FaceBoundaryAspect()->SetTypeOfLine (TypeOfFaceBoundaryLine);
2132 if (ToSetShadingModel != 0)
2134 if (ToSetShadingModel != -1
2135 || theDrawer->HasOwnShadingAspect())
2137 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2138 theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel);
2141 if (ToSetBackFaceColor != 0)
2143 if (ToSetBackFaceColor != -1
2144 || theDrawer->HasOwnShadingAspect())
2146 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2147 theDrawer->ShadingAspect()->SetColor (BackFaceColor, Aspect_TOFM_BACK_SIDE);
2150 if (ToSetAlphaMode != 0)
2152 if (ToSetAlphaMode != -1
2153 || theDrawer->HasOwnShadingAspect())
2155 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2156 theDrawer->ShadingAspect()->Aspect()->SetAlphaMode (AlphaMode, AlphaCutoff);
2159 if (ToSetHatch != 0)
2161 if (ToSetHatch != -1
2162 || theDrawer->HasOwnShadingAspect())
2164 theDrawer->SetupOwnShadingAspect (aDefDrawer);
2165 Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect();
2166 if (ToSetHatch == -1)
2168 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2172 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2173 if (!PathToHatchPattern.IsEmpty())
2175 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2176 if (anImage->Load (TCollection_AsciiString (PathToHatchPattern.ToCString())))
2178 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2182 std::cout << "Error: cannot load the following image: " << PathToHatchPattern << "\n";
2185 else if (StdHatchStyle != -1)
2187 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)StdHatchStyle));
2193 if (ToSetInterior != 0)
2195 if (ToSetInterior != -1
2196 || theDrawer->HasOwnShadingAspect())
2198 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2199 theDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (InteriorStyle);
2200 if (InteriorStyle == Aspect_IS_HATCH
2201 && theDrawer->ShadingAspect()->Aspect()->HatchStyle().IsNull())
2203 theDrawer->ShadingAspect()->Aspect()->SetHatchStyle (Aspect_HS_VERTICAL);
2207 if (ToSetDrawSilhouette != 0)
2209 if (ToSetDrawSilhouette != -1
2210 || theDrawer->HasOwnShadingAspect())
2212 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2213 theDrawer->ShadingAspect()->Aspect()->SetDrawSilhouette (ToSetDrawSilhouette == 1);
2216 if (ToSetDrawEdges != 0)
2218 if (ToSetDrawEdges != -1
2219 || theDrawer->HasOwnShadingAspect())
2221 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2222 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetDrawEdges == 1);
2225 if (ToSetQuadEdges != 0)
2227 if (ToSetQuadEdges != -1
2228 || theDrawer->HasOwnShadingAspect())
2230 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2231 theDrawer->ShadingAspect()->Aspect()->SetSkipFirstEdge (ToSetQuadEdges == 1);
2234 if (ToSetEdgeWidth != 0)
2236 if (ToSetEdgeWidth != -1
2237 || theDrawer->HasOwnShadingAspect())
2239 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2240 theDrawer->ShadingAspect()->Aspect()->SetEdgeWidth (EdgeWidth);
2243 if (ToSetTypeOfEdge != 0)
2245 if (ToSetTypeOfEdge != -1
2246 || theDrawer->HasOwnShadingAspect())
2248 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2249 theDrawer->ShadingAspect()->Aspect()->SetEdgeLineType (TypeOfEdge);
2250 if (ToSetInterior == 0)
2252 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetTypeOfEdge == 1
2253 && TypeOfEdge != Aspect_TOL_EMPTY);
2257 if (ToSetEdgeColor != 0)
2259 if (ToSetEdgeColor != -1
2260 || theDrawer->HasOwnShadingAspect())
2262 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2263 if (ToSetEdgeColor == -1)
2265 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (theDrawer->ShadingAspect()->Aspect()->InteriorColor());
2269 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (EdgeColor);
2277 //==============================================================================
2278 //function : VAspects
2280 //==============================================================================
2281 static Standard_Integer VAspects (Draw_Interpretor& theDI,
2282 Standard_Integer theArgNb,
2283 const char** theArgVec)
2285 TCollection_AsciiString aCmdName (theArgVec[0]);
2286 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2287 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2290 std::cerr << "Error: no active view!\n";
2294 Standard_Integer anArgIter = 1;
2295 Standard_Boolean isDefaults = Standard_False;
2296 NCollection_Sequence<TCollection_AsciiString> aNames;
2297 for (; anArgIter < theArgNb; ++anArgIter)
2299 TCollection_AsciiString anArg = theArgVec[anArgIter];
2300 if (anUpdateTool.parseRedrawMode (anArg))
2304 else if (!anArg.IsEmpty()
2305 && anArg.Value (1) != '-')
2307 aNames.Append (anArg);
2311 if (anArg == "-defaults")
2313 isDefaults = Standard_True;
2320 if (!aNames.IsEmpty() && isDefaults)
2322 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
2326 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
2327 aChanges.Append (ViewerTest_AspectsChangeSet());
2328 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
2330 // parse syntax of legacy commands
2331 bool toParseAliasArgs = false;
2332 Standard_Boolean toDump = 0;
2333 Standard_Boolean toCompactDump = 0;
2334 Standard_Integer aDumpDepth = -1;
2335 if (aCmdName == "vsetwidth")
2337 if (aNames.IsEmpty()
2338 || !aNames.Last().IsRealValue())
2340 std::cout << "Error: not enough arguments!\n";
2343 aChangeSet->ToSetLineWidth = 1;
2344 aChangeSet->LineWidth = aNames.Last().RealValue();
2345 aNames.Remove (aNames.Length());
2347 else if (aCmdName == "vunsetwidth")
2349 aChangeSet->ToSetLineWidth = -1;
2351 else if (aCmdName == "vsetcolor")
2353 if (aNames.IsEmpty())
2355 std::cout << "Error: not enough arguments!\n";
2358 aChangeSet->ToSetColor = 1;
2360 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2361 Standard_Boolean isOk = Standard_False;
2362 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
2364 aChangeSet->Color = aColor;
2365 aNames.Remove (aNames.Length());
2366 isOk = Standard_True;
2368 else if (Quantity_Color::ColorFromHex (aNames.Last().ToCString(), aChangeSet->Color))
2370 aNames.Remove (aNames.Length());
2371 isOk = Standard_True;
2373 else if (aNames.Length() >= 3)
2375 const char* anArgVec[3] =
2377 aNames.Value (aNames.Upper() - 2).ToCString(),
2378 aNames.Value (aNames.Upper() - 1).ToCString(),
2379 aNames.Value (aNames.Upper() - 0).ToCString(),
2382 Standard_Integer aNbParsed = ViewerTest::ParseColor (3, anArgVec, aChangeSet->Color);
2383 isOk = aNbParsed == 3;
2384 aNames.Remove (aNames.Length());
2385 aNames.Remove (aNames.Length());
2386 aNames.Remove (aNames.Length());
2390 std::cout << "Error: not enough arguments!\n";
2394 else if (aCmdName == "vunsetcolor")
2396 aChangeSet->ToSetColor = -1;
2398 else if (aCmdName == "vsettransparency")
2400 if (aNames.IsEmpty()
2401 || !aNames.Last().IsRealValue())
2403 std::cout << "Error: not enough arguments!\n";
2406 aChangeSet->ToSetTransparency = 1;
2407 aChangeSet->Transparency = aNames.Last().RealValue();
2408 aNames.Remove (aNames.Length());
2410 else if (aCmdName == "vunsettransparency")
2412 aChangeSet->ToSetTransparency = -1;
2414 else if (aCmdName == "vsetmaterial")
2416 if (aNames.IsEmpty())
2418 std::cout << "Error: not enough arguments!\n";
2421 aChangeSet->ToSetMaterial = 1;
2422 aChangeSet->MatName = aNames.Last();
2423 aNames.Remove (aNames.Length());
2424 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
2426 std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n";
2430 else if (aCmdName == "vunsetmaterial")
2432 aChangeSet->ToSetMaterial = -1;
2434 else if (aCmdName == "vsetinteriorstyle")
2436 if (aNames.IsEmpty()
2437 || !aNames.Last().IsRealValue())
2439 std::cout << "Error: not enough arguments!\n";
2442 aChangeSet->ToSetInterior = 1;
2443 if (!parseInteriorStyle (aNames.Last(), aChangeSet->InteriorStyle))
2445 std::cout << "Error: wrong syntax at " << aNames.Last() << "\n";
2448 aNames.Remove (aNames.Length());
2450 else if (aCmdName == "vsetedgetype")
2452 aChangeSet->ToSetDrawEdges = 1;
2453 toParseAliasArgs = true;
2455 else if (aCmdName == "vunsetedgetype")
2457 aChangeSet->ToSetDrawEdges = -1;
2458 aChangeSet->ToSetEdgeColor = -1;
2459 aChangeSet->ToSetTypeOfEdge = -1;
2460 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
2462 else if (aCmdName == "vshowfaceboundary")
2464 aChangeSet->ToSetFaceBoundaryDraw = 1;
2465 toParseAliasArgs = true;
2466 if (aNames.Size() >= 2
2467 && aNames.Value (2).IsIntegerValue())
2469 if (aNames.Size() == 7)
2471 if (ViewerTest::ParseLineType (aNames.Value (7).ToCString(), aChangeSet->TypeOfFaceBoundaryLine))
2473 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2477 if (aNames.Size() == 6
2478 && aNames.Value (6).IsRealValue())
2480 aChangeSet->ToSetFaceBoundaryWidth = 1;
2481 aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue();
2484 if (aNames.Size() == 5
2485 && aNames.Value (3).IsIntegerValue()
2486 && aNames.Value (4).IsIntegerValue()
2487 && aNames.Value (5).IsIntegerValue())
2489 aChangeSet->ToSetFaceBoundaryColor = 1;
2490 aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0,
2491 aNames.Value (4).IntegerValue() / 255.0,
2492 aNames.Value (5).IntegerValue() / 255.0,
2498 if (aNames.Size() == 2)
2500 toParseAliasArgs = false;
2501 aChangeSet->ToSetFaceBoundaryDraw = aNames.Value (2).IntegerValue() == 1 ? 1 : -1;
2506 else if (anArgIter >= theArgNb)
2508 std::cout << "Error: not enough arguments!\n";
2512 if (!aChangeSet->IsEmpty()
2513 && !toParseAliasArgs)
2515 anArgIter = theArgNb;
2517 for (; anArgIter < theArgNb; ++anArgIter)
2519 TCollection_AsciiString anArg = theArgVec[anArgIter];
2521 if (anArg == "-setwidth"
2522 || anArg == "-width"
2523 || anArg == "-setlinewidth"
2524 || anArg == "-linewidth"
2525 || anArg == "-setedgewidth"
2526 || anArg == "-setedgeswidth"
2527 || anArg == "-edgewidth"
2528 || anArg == "-edgeswidth"
2529 || anArg == "-setfaceboundarywidth"
2530 || anArg == "-setboundarywidth"
2531 || anArg == "-faceboundarywidth"
2532 || anArg == "-boundarywidth")
2534 if (++anArgIter >= theArgNb)
2536 std::cout << "Error: wrong syntax at " << anArg << "\n";
2540 const Standard_Real aWidth = Draw::Atof (theArgVec[anArgIter]);
2541 if (anArg == "-setedgewidth"
2542 || anArg == "-setedgeswidth"
2543 || anArg == "-edgewidth"
2544 || anArg == "-edgeswidth"
2545 || aCmdName == "vsetedgetype")
2547 aChangeSet->ToSetEdgeWidth = 1;
2548 aChangeSet->EdgeWidth = aWidth;
2550 else if (anArg == "-setfaceboundarywidth"
2551 || anArg == "-setboundarywidth"
2552 || anArg == "-faceboundarywidth"
2553 || anArg == "-boundarywidth"
2554 || aCmdName == "vshowfaceboundary")
2556 aChangeSet->ToSetFaceBoundaryWidth = 1;
2557 aChangeSet->FaceBoundaryWidth = aWidth;
2561 aChangeSet->ToSetLineWidth = 1;
2562 aChangeSet->LineWidth = aWidth;
2565 else if (anArg == "-unsetwidth"
2566 || anArg == "-unsetlinewidth"
2567 || anArg == "-unsetedgewidth")
2569 if (anArg == "-unsetedgewidth")
2571 aChangeSet->ToSetEdgeWidth = -1;
2572 aChangeSet->EdgeWidth = 1.0;
2576 aChangeSet->ToSetLineWidth = -1;
2577 aChangeSet->LineWidth = 1.0;
2580 else if (anArg == "-settransp"
2581 || anArg == "-settransparency"
2582 || anArg == "-transparency"
2583 || anArg == "-transp")
2585 if (++anArgIter >= theArgNb)
2587 std::cout << "Error: wrong syntax at " << anArg << "\n";
2590 aChangeSet->ToSetTransparency = 1;
2591 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2592 if (aChangeSet->Transparency >= 0.0
2593 && aChangeSet->Transparency <= Precision::Confusion())
2595 aChangeSet->ToSetTransparency = -1;
2596 aChangeSet->Transparency = 0.0;
2599 else if (anArg == "-setalphamode"
2600 || anArg == "-alphamode")
2602 if (++anArgIter >= theArgNb)
2604 std::cout << "Error: wrong syntax at " << anArg << "\n";
2607 aChangeSet->ToSetAlphaMode = 1;
2608 aChangeSet->AlphaCutoff = 0.5f;
2610 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2612 if (aParam == "opaque")
2614 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2616 else if (aParam == "mask")
2618 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2620 else if (aParam == "blend")
2622 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2624 else if (aParam == "blendauto"
2625 || aParam == "auto")
2627 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2631 std::cout << "Error: wrong syntax at " << aParam << "\n";
2636 if (anArgIter + 1 < theArgNb
2637 && theArgVec[anArgIter + 1][0] != '-')
2639 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2640 if (aParam2.IsRealValue())
2642 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2647 else if (anArg == "-setvis"
2648 || anArg == "-setvisibility"
2649 || anArg == "-visibility")
2651 if (++anArgIter >= theArgNb)
2653 std::cout << "Error: wrong syntax at " << anArg << "\n";
2657 aChangeSet->ToSetVisibility = 1;
2658 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2660 else if (anArg == "-setalpha"
2661 || anArg == "-alpha")
2663 if (++anArgIter >= theArgNb)
2665 std::cout << "Error: wrong syntax at " << anArg << "\n";
2668 aChangeSet->ToSetTransparency = 1;
2669 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2670 if (aChangeSet->Transparency < 0.0
2671 || aChangeSet->Transparency > 1.0)
2673 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2676 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2677 if (aChangeSet->Transparency >= 0.0
2678 && aChangeSet->Transparency <= Precision::Confusion())
2680 aChangeSet->ToSetTransparency = -1;
2681 aChangeSet->Transparency = 0.0;
2684 else if (anArg == "-unsettransp"
2685 || anArg == "-unsettransparency"
2686 || anArg == "-unsetalpha"
2687 || anArg == "-opaque")
2689 aChangeSet->ToSetTransparency = -1;
2690 aChangeSet->Transparency = 0.0;
2692 else if (anArg == "-setcolor"
2693 || anArg == "-color"
2694 || anArg == "-setbackfacecolor"
2695 || anArg == "-backfacecolor"
2696 || anArg == "-setbackcolor"
2697 || anArg == "-backcolor"
2698 || anArg == "-setfaceboundarycolor"
2699 || anArg == "-setboundarycolor"
2700 || anArg == "-faceboundarycolor"
2701 || anArg == "-boundarycolor")
2703 Quantity_Color aColor;
2704 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2705 theArgVec + anArgIter + 1,
2709 std::cout << "Syntax error at '" << anArg << "'\n";
2712 anArgIter += aNbParsed;
2713 if (aCmdName == "vsetedgetype")
2715 aChangeSet->ToSetEdgeColor = 1;
2716 aChangeSet->EdgeColor = Quantity_ColorRGBA (aColor);
2718 else if (aCmdName == "vshowfaceboundary"
2719 || anArg == "-setfaceboundarycolor"
2720 || anArg == "-setboundarycolor"
2721 || anArg == "-faceboundarycolor"
2722 || anArg == "-boundarycolor")
2724 aChangeSet->ToSetFaceBoundaryColor = 1;
2725 aChangeSet->FaceBoundaryColor = aColor;
2727 else if (anArg == "-setbackfacecolor"
2728 || anArg == "-backfacecolor"
2729 || anArg == "-setbackcolor"
2730 || anArg == "-backcolor")
2732 aChangeSet->ToSetBackFaceColor = 1;
2733 aChangeSet->BackFaceColor = aColor;
2737 aChangeSet->ToSetColor = 1;
2738 aChangeSet->Color = aColor;
2741 else if (anArg == "-setlinetype"
2742 || anArg == "-linetype"
2743 || anArg == "-setedgetype"
2744 || anArg == "-setedgestype"
2745 || anArg == "-edgetype"
2746 || anArg == "-edgestype"
2747 || anArg == "-setfaceboundarystyle"
2748 || anArg == "-faceboundarystyle"
2749 || anArg == "-boundarystyle"
2750 || anArg == "-setfaceboundarytype"
2751 || anArg == "-faceboundarytype"
2752 || anArg == "-setboundarytype"
2753 || anArg == "-boundarytype"
2754 || anArg == "-type")
2756 if (++anArgIter >= theArgNb)
2758 std::cout << "Error: wrong syntax at " << anArg << "\n";
2761 Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY;
2762 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType))
2764 std::cout << "Error: wrong syntax at " << anArg << "\n";
2767 if (anArg == "-setedgetype"
2768 || anArg == "-setedgestype"
2769 || anArg == "-edgetype"
2770 || anArg == "-edgestype"
2771 || aCmdName == "vsetedgetype")
2773 aChangeSet->TypeOfEdge = aLineType;
2774 aChangeSet->ToSetTypeOfEdge = 1;
2776 else if (anArg == "-setfaceboundarystyle"
2777 || anArg == "-faceboundarystyle"
2778 || anArg == "-boundarystyle"
2779 || anArg == "-setfaceboundarytype"
2780 || anArg == "-faceboundarytype"
2781 || anArg == "-setboundarytype"
2782 || anArg == "-boundarytype"
2783 || aCmdName == "vshowfaceboundary")
2785 aChangeSet->TypeOfFaceBoundaryLine = aLineType;
2786 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2790 aChangeSet->TypeOfLine = aLineType;
2791 aChangeSet->ToSetTypeOfLine = 1;
2794 else if (anArg == "-unsetlinetype"
2795 || anArg == "-unsetedgetype"
2796 || anArg == "-unsetedgestype")
2798 if (anArg == "-unsetedgetype"
2799 || anArg == "-unsetedgestype")
2801 aChangeSet->ToSetTypeOfEdge = -1;
2805 aChangeSet->ToSetTypeOfLine = -1;
2808 else if (anArg == "-setmarkertype"
2809 || anArg == "-markertype"
2810 || anArg == "-setpointtype"
2811 || anArg == "-pointtype")
2813 if (++anArgIter >= theArgNb)
2815 std::cout << "Error: wrong syntax at " << anArg << "\n";
2818 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2820 std::cout << "Error: wrong syntax at " << anArg << "\n";
2824 aChangeSet->ToSetTypeOfMarker = 1;
2826 else if (anArg == "-unsetmarkertype"
2827 || anArg == "-unsetpointtype")
2829 aChangeSet->ToSetTypeOfMarker = -1;
2831 else if (anArg == "-setmarkersize"
2832 || anArg == "-markersize"
2833 || anArg == "-setpointsize"
2834 || anArg == "-pointsize")
2836 if (++anArgIter >= theArgNb)
2838 std::cout << "Error: wrong syntax at " << anArg << "\n";
2841 aChangeSet->ToSetMarkerSize = 1;
2842 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2844 else if (anArg == "-unsetmarkersize"
2845 || anArg == "-unsetpointsize")
2847 aChangeSet->ToSetMarkerSize = -1;
2848 aChangeSet->MarkerSize = 1.0;
2850 else if (anArg == "-unsetcolor")
2852 aChangeSet->ToSetColor = -1;
2853 aChangeSet->Color = DEFAULT_COLOR;
2855 else if (anArg == "-setmat"
2857 || anArg == "-setmaterial"
2858 || anArg == "-material")
2860 if (++anArgIter >= theArgNb)
2862 std::cout << "Error: wrong syntax at " << anArg << "\n";
2865 aChangeSet->ToSetMaterial = 1;
2866 aChangeSet->MatName = theArgVec[anArgIter];
2867 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
2869 std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n";
2873 else if (anArg == "-unsetmat"
2874 || anArg == "-unsetmaterial")
2876 aChangeSet->ToSetMaterial = -1;
2877 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2879 else if (anArg == "-subshape"
2880 || anArg == "-subshapes")
2884 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2888 if (aNames.IsEmpty())
2890 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2894 aChanges.Append (ViewerTest_AspectsChangeSet());
2895 aChangeSet = &aChanges.ChangeLast();
2897 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2899 Standard_CString aSubShapeName = theArgVec[anArgIter];
2900 if (*aSubShapeName == '-')
2906 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2907 if (aSubShape.IsNull())
2909 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2912 aChangeSet->SubShapes.Append (aSubShape);
2915 if (aChangeSet->SubShapes.IsEmpty())
2917 std::cerr << "Error: empty list is specified after -subshapes!\n";
2921 else if (anArg == "-setfreeboundary"
2922 || anArg == "-freeboundary"
2923 || anArg == "-setfb"
2926 bool toEnable = true;
2927 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2929 std::cout << "Error: wrong syntax at " << anArg << "\n";
2933 aChangeSet->ToSetShowFreeBoundary = toEnable ? 1 : -1;
2935 else if (anArg == "-setfreeboundarywidth"
2936 || anArg == "-freeboundarywidth"
2937 || anArg == "-setfbwidth"
2938 || anArg == "-fbwidth")
2940 if (++anArgIter >= theArgNb)
2942 std::cout << "Error: wrong syntax at " << anArg << "\n";
2945 aChangeSet->ToSetFreeBoundaryWidth = 1;
2946 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2948 else if (anArg == "-unsetfreeboundarywidth"
2949 || anArg == "-unsetfbwidth")
2951 aChangeSet->ToSetFreeBoundaryWidth = -1;
2952 aChangeSet->FreeBoundaryWidth = 1.0;
2954 else if (anArg == "-setfreeboundarycolor"
2955 || anArg == "-freeboundarycolor"
2956 || anArg == "-setfbcolor"
2957 || anArg == "-fbcolor")
2959 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2960 theArgVec + anArgIter + 1,
2961 aChangeSet->FreeBoundaryColor);
2964 std::cout << "Syntax error at '" << anArg << "'\n";
2967 anArgIter += aNbParsed;
2968 aChangeSet->ToSetFreeBoundaryColor = 1;
2970 else if (anArg == "-unsetfreeboundarycolor"
2971 || anArg == "-unsetfbcolor")
2973 aChangeSet->ToSetFreeBoundaryColor = -1;
2974 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2976 else if (anArg == "-setisoontriangulation"
2977 || anArg == "-isoontriangulation"
2978 || anArg == "-setisoontriang"
2979 || anArg == "-isoontriang")
2981 bool toEnable = true;
2982 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2984 std::cout << "Error: wrong syntax at " << anArg << "\n";
2988 aChangeSet->ToEnableIsoOnTriangulation = toEnable ? 1 : -1;
2990 else if (anArg == "-setfaceboundarydraw"
2991 || anArg == "-setdrawfaceboundary"
2992 || anArg == "-setdrawfaceboundaries"
2993 || anArg == "-setshowfaceboundary"
2994 || anArg == "-setshowfaceboundaries"
2995 || anArg == "-setdrawfaceedges"
2996 || anArg == "-faceboundarydraw"
2997 || anArg == "-drawfaceboundary"
2998 || anArg == "-drawfaceboundaries"
2999 || anArg == "-showfaceboundary"
3000 || anArg == "-showfaceboundaries"
3001 || anArg == "-drawfaceedges"
3002 || anArg == "-faceboundary"
3003 || anArg == "-faceboundaries"
3004 || anArg == "-faceedges")
3006 bool toEnable = true;
3007 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
3009 std::cout << "Error: wrong syntax at " << anArg << "\n";
3013 aChangeSet->ToSetFaceBoundaryDraw = toEnable ? 1 : -1;
3015 else if (anArg == "-unsetfaceboundary"
3016 || anArg == "-unsetboundary")
3018 aChangeSet->ToSetFaceBoundaryDraw = -1;
3019 aChangeSet->ToSetFaceBoundaryColor = -1;
3021 else if (anArg == "-setmostcontinuity"
3022 || anArg == "-mostcontinuity")
3024 TCollection_AsciiString aClassArg (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "");
3025 aClassArg.LowerCase();
3026 GeomAbs_Shape aClass = GeomAbs_CN;
3027 if (aClassArg == "c0"
3028 || aClassArg == "0")
3030 aClass = GeomAbs_C0;
3032 else if (aClassArg == "c1"
3033 || aClassArg == "1")
3035 aClass = GeomAbs_C1;
3037 else if (aClassArg == "c2"
3038 || aClassArg == "2")
3040 aClass = GeomAbs_C2;
3042 else if (aClassArg == "c3"
3043 || aClassArg == "3")
3045 aClass = GeomAbs_C3;
3047 else if (aClassArg == "cn"
3048 || aClassArg == "n")
3050 aClass = GeomAbs_CN;
3054 std::cout << "Syntax error at '" << anArg << "'\n";
3059 aChangeSet->ToSetFaceBoundaryUpperContinuity = 1;
3060 aChangeSet->FaceBoundaryUpperContinuity = aClass;
3062 else if (anArg == "-setmaxparamvalue"
3063 || anArg == "-maxparamvalue")
3065 if (++anArgIter >= theArgNb)
3067 std::cout << "Error: wrong syntax at " << anArg << "\n";
3070 aChangeSet->ToSetMaxParamValue = 1;
3071 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
3073 else if (anArg == "-setsensitivity"
3074 || anArg == "-sensitivity")
3078 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
3082 if (aNames.IsEmpty())
3084 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
3088 if (anArgIter + 2 >= theArgNb)
3090 std::cout << "Error: wrong syntax at " << anArg << "\n";
3093 aChangeSet->ToSetSensitivity = 1;
3094 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
3095 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
3097 else if (anArg == "-sethatch"
3098 || anArg == "-hatch")
3102 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
3106 if (aNames.IsEmpty())
3108 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
3112 aChangeSet->ToSetHatch = 1;
3113 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
3114 if (anArgHatch.Length() <= 2)
3116 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
3118 || anIntStyle >= Aspect_HS_NB)
3120 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
3123 aChangeSet->StdHatchStyle = anIntStyle;
3127 aChangeSet->PathToHatchPattern = anArgHatch;
3130 else if (anArg == "-setshadingmodel"
3131 || anArg == "-setshading"
3132 || anArg == "-shadingmodel"
3133 || anArg == "-shading")
3135 if (++anArgIter >= theArgNb)
3137 std::cout << "Error: wrong syntax at " << anArg << "\n";
3140 aChangeSet->ToSetShadingModel = 1;
3141 aChangeSet->ShadingModelName = theArgVec[anArgIter];
3142 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
3144 std::cout << "Error: wrong syntax at " << anArg << "\n";
3148 else if (anArg == "-unsetshadingmodel")
3150 aChangeSet->ToSetShadingModel = -1;
3151 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
3153 else if (anArg == "-setinterior"
3154 || anArg == "-setinteriorstyle"
3155 || anArg == "-interior"
3156 || anArg == "-interiorstyle")
3158 if (++anArgIter >= theArgNb)
3160 std::cout << "Error: wrong syntax at " << anArg << "\n";
3163 aChangeSet->ToSetInterior = 1;
3164 if (!parseInteriorStyle (theArgVec[anArgIter], aChangeSet->InteriorStyle))
3166 std::cout << "Error: wrong syntax at " << anArg << "\n";
3170 else if (anArg == "-unsetinterior")
3172 aChangeSet->ToSetInterior = -1;
3173 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3175 else if (anArg == "-setdrawoutline"
3176 || anArg == "-setdrawsilhouette"
3177 || anArg == "-setoutline"
3178 || anArg == "-setsilhouette"
3179 || anArg == "-outline"
3180 || anArg == "-outlined"
3181 || anArg == "-silhouette")
3183 bool toDrawOutline = true;
3184 if (anArgIter + 1 < theArgNb
3185 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawOutline))
3189 aChangeSet->ToSetDrawSilhouette = toDrawOutline ? 1 : -1;
3191 else if (anArg == "-setdrawedges"
3192 || anArg == "-setdrawedge"
3193 || anArg == "-drawedges"
3194 || anArg == "-drawedge"
3195 || anArg == "-edges")
3197 bool toDrawEdges = true;
3198 if (anArgIter + 1 < theArgNb
3199 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawEdges))
3203 aChangeSet->ToSetDrawEdges = toDrawEdges ? 1 : -1;
3205 else if (anArg == "-setquadedges"
3206 || anArg == "-setquads"
3207 || anArg == "-quads"
3208 || anArg == "-skipfirstedge")
3210 bool isQuadMode = true;
3211 if (anArgIter + 1 < theArgNb
3212 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isQuadMode))
3216 aChangeSet->ToSetQuadEdges = isQuadMode ? 1 : -1;
3218 else if (anArg == "-setedgecolor"
3219 || anArg == "-setedgescolor"
3220 || anArg == "-edgecolor"
3221 || anArg == "-edgescolor")
3223 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3224 theArgVec + anArgIter + 1,
3225 aChangeSet->EdgeColor);
3228 std::cout << "Syntax error at '" << anArg << "'\n";
3231 anArgIter += aNbParsed;
3232 aChangeSet->ToSetEdgeColor = 1;
3234 else if (anArg == "-unset")
3236 aChangeSet->ToSetVisibility = 1;
3237 aChangeSet->Visibility = 1;
3238 aChangeSet->ToSetLineWidth = -1;
3239 aChangeSet->LineWidth = 1.0;
3240 aChangeSet->ToSetTypeOfLine = -1;
3241 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
3242 aChangeSet->ToSetTypeOfMarker = -1;
3243 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
3244 aChangeSet->ToSetMarkerSize = -1;
3245 aChangeSet->MarkerSize = 1.0;
3246 aChangeSet->ToSetTransparency = -1;
3247 aChangeSet->Transparency = 0.0;
3248 aChangeSet->ToSetAlphaMode = -1;
3249 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
3250 aChangeSet->AlphaCutoff = 0.5f;
3251 aChangeSet->ToSetColor = -1;
3252 aChangeSet->Color = DEFAULT_COLOR;
3253 //aChangeSet->ToSetBackFaceColor = -1; // should be reset by ToSetColor
3254 //aChangeSet->BackFaceColor = DEFAULT_COLOR;
3255 aChangeSet->ToSetMaterial = -1;
3256 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
3257 aChangeSet->ToSetShowFreeBoundary = -1;
3258 aChangeSet->ToSetFreeBoundaryColor = -1;
3259 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
3260 aChangeSet->ToSetFreeBoundaryWidth = -1;
3261 aChangeSet->FreeBoundaryWidth = 1.0;
3262 aChangeSet->ToEnableIsoOnTriangulation = -1;
3264 aChangeSet->ToSetFaceBoundaryDraw = -1;
3265 aChangeSet->ToSetFaceBoundaryUpperContinuity = -1;
3266 aChangeSet->FaceBoundaryUpperContinuity = GeomAbs_CN;
3267 aChangeSet->ToSetFaceBoundaryColor = -1;
3268 aChangeSet->FaceBoundaryColor = Quantity_NOC_BLACK;
3269 aChangeSet->ToSetFaceBoundaryWidth = -1;
3270 aChangeSet->FaceBoundaryWidth = 1.0f;
3271 aChangeSet->ToSetTypeOfFaceBoundaryLine = -1;
3272 aChangeSet->TypeOfFaceBoundaryLine = Aspect_TOL_SOLID;
3274 aChangeSet->ToSetHatch = -1;
3275 aChangeSet->StdHatchStyle = -1;
3276 aChangeSet->PathToHatchPattern.Clear();
3277 aChangeSet->ToSetShadingModel = -1;
3278 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
3279 aChangeSet->ToSetInterior = -1;
3280 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3281 aChangeSet->ToSetDrawSilhouette = -1;
3282 aChangeSet->ToSetDrawEdges = -1;
3283 aChangeSet->ToSetQuadEdges = -1;
3284 aChangeSet->ToSetEdgeColor = -1;
3285 aChangeSet->EdgeColor = Quantity_ColorRGBA (DEFAULT_COLOR);
3286 aChangeSet->ToSetEdgeWidth = -1;
3287 aChangeSet->EdgeWidth = 1.0;
3288 aChangeSet->ToSetTypeOfEdge = -1;
3289 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
3291 else if (anArg == "-dumpjson")
3293 toDump = Standard_True;
3295 else if (anArg == "-dumpcompact")
3297 toCompactDump = Standard_False;
3298 if (++anArgIter >= theArgNb && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toCompactDump))
3301 else if (anArg == "-dumpdepth")
3303 if (++anArgIter >= theArgNb)
3305 std::cout << "Error: wrong syntax at " << anArg << "\n";
3308 aDumpDepth = Draw::Atoi (theArgVec[anArgIter]);
3312 std::cout << "Error: wrong syntax at " << anArg << "\n";
3317 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3318 aChangesIter.More(); aChangesIter.Next())
3320 if (!aChangesIter.Value().Validate())
3326 // special case for -defaults parameter.
3327 // all changed values will be set to DefaultDrawer.
3330 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
3331 aChangeSet->Apply (aDrawer);
3332 if (aChangeSet->ToSetLineWidth != 0)
3334 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
3335 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
3336 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
3337 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
3339 if (aChangeSet->ToSetColor != 0)
3341 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
3342 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
3343 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
3344 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
3345 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
3346 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
3348 if (aChangeSet->ToSetTransparency != 0)
3350 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
3352 if (aChangeSet->ToSetMaterial != 0)
3354 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
3356 if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3358 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
3361 // redisplay all objects in context
3362 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3364 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3367 aCtx->Redisplay (aPrs, Standard_False);
3372 Standard_SStream aStream;
3373 aDrawer->DumpJson (aStream, aDumpDepth);
3376 theDI << Standard_Dump::Text (aStream);
3378 theDI << Standard_Dump::FormatJson (aStream);
3383 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3385 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
3386 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3392 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
3393 Handle(AIS_ColoredShape) aColoredPrs;
3394 Standard_Boolean toDisplay = Standard_False;
3395 Standard_Boolean toRedisplay = Standard_False;
3396 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
3398 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
3399 if (aShapePrs.IsNull())
3401 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
3404 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
3405 if (aColoredPrs.IsNull())
3407 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3408 if (aShapePrs->HasDisplayMode())
3410 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
3412 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
3413 aCtx->Remove (aShapePrs, Standard_False);
3414 GetMapOfAIS().UnBind2 (aName);
3415 GetMapOfAIS().Bind (aColoredPrs, aName);
3416 toDisplay = Standard_True;
3417 aShapePrs = aColoredPrs;
3424 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3425 aChangeSet = &aChangesIter.ChangeValue();
3426 if (aChangeSet->ToSetVisibility == 1)
3428 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
3429 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
3431 else if (aChangeSet->ToSetMaterial == 1)
3433 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
3435 else if (aChangeSet->ToSetMaterial == -1)
3437 aCtx->UnsetMaterial (aPrs, Standard_False);
3439 if (aChangeSet->ToSetColor == 1)
3441 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
3443 else if (aChangeSet->ToSetColor == -1)
3445 aCtx->UnsetColor (aPrs, Standard_False);
3447 if (aChangeSet->ToSetTransparency == 1)
3449 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
3451 else if (aChangeSet->ToSetTransparency == -1)
3453 aCtx->UnsetTransparency (aPrs, Standard_False);
3455 if (aChangeSet->ToSetLineWidth == 1)
3457 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
3459 else if (aChangeSet->ToSetLineWidth == -1)
3461 aCtx->UnsetWidth (aPrs, Standard_False);
3463 else if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3465 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
3466 toRedisplay = Standard_True;
3468 else if (aChangeSet->ToSetSensitivity != 0)
3470 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3472 if (!aDrawer.IsNull())
3474 toRedisplay = aChangeSet->Apply (aDrawer) || toRedisplay;
3477 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
3479 aChangeSet = &aChangesIter.ChangeValue();
3480 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
3481 aSubShapeIter.More(); aSubShapeIter.Next())
3483 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
3484 if (!aChangeSet->IsEmpty())
3486 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3487 aChangeSet->Apply (aCurColDrawer);
3489 if (aChangeSet->ToSetVisibility == 1)
3491 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3492 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
3494 if (aChangeSet->ToSetColor == 1)
3496 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
3498 if (aChangeSet->ToSetTransparency == 1)
3500 aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency);
3502 if (aChangeSet->ToSetLineWidth == 1)
3504 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
3506 if (aChangeSet->ToSetColor == -1
3507 || aChangeSet->ToSetLineWidth == -1)
3509 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
3511 if (aChangeSet->ToSetSensitivity != 0)
3513 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3519 aCtx->Display (aPrs, Standard_False);
3523 aCtx->Redisplay (aPrs, Standard_False);
3525 else if (!aColoredPrs.IsNull())
3527 aCtx->Redisplay (aColoredPrs, Standard_False);
3531 aPrs->SynchronizeAspects();
3536 Standard_SStream aStream;
3537 aDrawer->DumpJson (aStream);
3539 theDI << aName << ": \n";
3540 theDI << Standard_Dump::FormatJson (aStream);
3548 //==============================================================================
3549 //function : VDonly2
3551 //purpose : Display only a selected or named object
3552 // if there is no selected or named object s, nothing is done
3553 //==============================================================================
3554 static int VDonly2 (Draw_Interpretor& ,
3555 Standard_Integer theArgNb,
3556 const char** theArgVec)
3558 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3559 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3562 std::cerr << "Error: no active view!\n";
3566 Standard_Integer anArgIter = 1;
3567 for (; anArgIter < theArgNb; ++anArgIter)
3569 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3575 NCollection_Map<Handle(Standard_Transient)> aDispSet;
3576 if (anArgIter >= theArgNb)
3578 // display only selected objects
3579 if (aCtx->NbSelected() < 1)
3584 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3586 aDispSet.Add (aCtx->SelectedInteractive());
3591 // display only specified objects
3592 for (; anArgIter < theArgNb; ++anArgIter)
3594 TCollection_AsciiString aName = theArgVec[anArgIter];
3595 Handle(AIS_InteractiveObject) aShape;
3596 if (GetMapOfAIS().Find2 (aName, aShape)
3597 && !aShape.IsNull())
3599 aCtx->Display (aShape, Standard_False);
3600 aDispSet.Add (aShape);
3605 // weed out other objects
3606 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
3608 if (aDispSet.Contains (anIter.Key1()))
3613 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
3615 aCtx->Erase (aShape, Standard_False);
3621 //==============================================================================
3622 //function : VRemove
3623 //purpose : Removes selected or named objects.
3624 // If there is no selected or named objects,
3625 // all objects in the viewer can be removed with argument -all.
3626 // If -context is in arguments, the object is not deleted from the map of
3627 // objects (deleted only from the current context).
3628 //==============================================================================
3629 int VRemove (Draw_Interpretor& theDI,
3630 Standard_Integer theArgNb,
3631 const char** theArgVec)
3633 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3634 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3637 std::cerr << "Error: no active view!\n";
3641 Standard_Boolean isContextOnly = Standard_False;
3642 Standard_Boolean toRemoveAll = Standard_False;
3643 Standard_Boolean toPrintInfo = Standard_True;
3644 Standard_Boolean toFailOnError = Standard_True;
3646 Standard_Integer anArgIter = 1;
3647 for (; anArgIter < theArgNb; ++anArgIter)
3649 TCollection_AsciiString anArg = theArgVec[anArgIter];
3651 if (anArg == "-context")
3653 isContextOnly = Standard_True;
3655 else if (anArg == "-all")
3657 toRemoveAll = Standard_True;
3659 else if (anArg == "-noinfo")
3661 toPrintInfo = Standard_False;
3663 else if (anArg == "-noerror"
3664 || anArg == "-nofail")
3666 toFailOnError = Standard_False;
3668 else if (anUpdateTool.parseRedrawMode (anArg))
3678 && anArgIter < theArgNb)
3680 std::cerr << "Error: wrong syntax!\n";
3684 NCollection_List<TCollection_AsciiString> anIONameList;
3687 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3688 anIter.More(); anIter.Next())
3690 anIONameList.Append (anIter.Key2());
3693 else if (anArgIter < theArgNb) // removed objects names are in argument list
3695 for (; anArgIter < theArgNb; ++anArgIter)
3697 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3698 if (aName.Search ("*") != -1)
3700 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
3702 if (aPrsIter.Key1()->GetContext() != aCtx)
3706 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
3707 if (theDI.Eval (aCheck.ToCString()) == 0
3708 && *theDI.Result() == '1')
3710 anIONameList.Append (aPrsIter.Key2());
3717 Handle(AIS_InteractiveObject) anIO;
3718 if (!GetMapOfAIS().Find2 (aName, anIO))
3722 std::cout << "Syntax error: '" << aName << "' was not bound to some object.\n";
3726 else if (anIO->GetContext() != aCtx)
3730 std::cout << "Syntax error: '" << aName << "' was not displayed in current context.\n"
3731 << "Please activate view with this object displayed and try again.\n";
3737 anIONameList.Append (aName);
3741 else if (aCtx->NbSelected() > 0)
3743 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3744 anIter.More(); anIter.Next())
3746 if (!aCtx->IsSelected (anIter.Key1()))
3751 anIONameList.Append (anIter.Key2());
3756 // Unbind all removed objects from the map of displayed IO.
3757 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3758 anIter.More(); anIter.Next())
3760 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
3761 aCtx->Remove (anIO, Standard_False);
3764 theDI << anIter.Value() << " ";
3768 GetMapOfAIS().UnBind2 (anIter.Value());
3774 //==============================================================================
3776 //purpose : Erase some selected or named objects
3777 // if there is no selected or named objects, the whole viewer is erased
3778 //==============================================================================
3779 int VErase (Draw_Interpretor& theDI,
3780 Standard_Integer theArgNb,
3781 const char** theArgVec)
3783 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3784 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3785 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3788 std::cerr << "Error: no active view!\n";
3792 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3794 Standard_Integer anArgIter = 1;
3795 Standard_Boolean toEraseInView = Standard_False;
3796 Standard_Boolean toFailOnError = Standard_True;
3797 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3798 for (; anArgIter < theArgNb; ++anArgIter)
3800 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3801 anArgCase.LowerCase();
3802 if (anUpdateTool.parseRedrawMode (anArgCase))
3806 else if (anArgCase == "-view"
3807 || anArgCase == "-inview")
3809 toEraseInView = Standard_True;
3811 else if (anArgCase == "-noerror"
3812 || anArgCase == "-nofail")
3814 toFailOnError = Standard_False;
3818 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3822 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3824 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3828 if (!aNamesOfEraseIO.IsEmpty())
3830 // Erase named objects
3831 NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString> aPrsList;
3832 for (TColStd_SequenceOfAsciiString::Iterator anIter (aNamesOfEraseIO); anIter.More(); anIter.Next())
3834 const TCollection_AsciiString& aName = anIter.Value();
3835 if (aName.Search ("*") != -1)
3837 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
3839 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
3840 if (theDI.Eval (aCheck.ToCString()) == 0
3841 && *theDI.Result() == '1')
3843 aPrsList.Add (aPrsIter.Key1(), aPrsIter.Key2());
3850 Handle(AIS_InteractiveObject) anIO;
3851 if (!GetMapOfAIS().Find2 (aName, anIO))
3855 std::cout << "Syntax error: '" << aName << "' is not found\n";
3861 aPrsList.Add (anIO, aName);
3866 for (NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString>::Iterator anIter (aPrsList); anIter.More(); anIter.Next())
3868 theDI << anIter.Value() << " ";
3871 aCtx->SetViewAffinity (anIter.Key(), aView, Standard_False);
3875 aCtx->Erase (anIter.Key(), Standard_False);
3879 else if (!toEraseAll && aCtx->NbSelected() > 0)
3881 // Erase selected objects
3882 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3883 anIter.More(); anIter.Next())
3885 const Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3887 && aCtx->IsSelected (anIO))
3889 theDI << anIter.Key2() << " ";
3892 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3899 aCtx->EraseSelected (Standard_False);
3904 // Erase all objects
3905 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3906 anIter.More(); anIter.Next())
3908 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3913 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3917 aCtx->Erase (anIO, Standard_False);
3926 //==============================================================================
3927 //function : VDisplayAll
3928 //purpose : Display all the objects of the Map
3929 //==============================================================================
3930 static int VDisplayAll (Draw_Interpretor& ,
3931 Standard_Integer theArgNb,
3932 const char** theArgVec)
3935 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3936 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3939 std::cerr << "Error: no active view!\n";
3943 Standard_Integer anArgIter = 1;
3944 for (; anArgIter < theArgNb; ++anArgIter)
3946 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3947 anArgCase.LowerCase();
3948 if (anUpdateTool.parseRedrawMode (anArgCase))
3957 if (anArgIter < theArgNb)
3959 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3963 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3964 anIter.More(); anIter.Next())
3966 aCtx->Erase (anIter.Key1(), Standard_False);
3969 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3970 anIter.More(); anIter.Next())
3972 aCtx->Display (anIter.Key1(), Standard_False);
3977 //! Auxiliary method to check if presentation exists
3978 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3979 const Handle(AIS_InteractiveObject)& theIO,
3980 const Standard_Integer theMode)
3982 if (theIO.IsNull() || theCtx.IsNull())
3989 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3994 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3996 return theIO->DisplayMode();
3998 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
4000 return theCtx->DisplayMode();
4006 enum ViewerTest_BndAction
4013 //! Auxiliary method to print bounding box of presentation
4014 inline void bndPresentation (Draw_Interpretor& theDI,
4015 const Handle(PrsMgr_PresentationManager)& theMgr,
4016 const Handle(AIS_InteractiveObject)& theObj,
4017 const Standard_Integer theDispMode,
4018 const TCollection_AsciiString& theName,
4019 const ViewerTest_BndAction theAction,
4020 const Handle(Prs3d_Drawer)& theStyle)
4024 case BndAction_Hide:
4026 theMgr->Unhighlight (theObj);
4029 case BndAction_Show:
4031 theMgr->Color (theObj, theStyle, theDispMode);
4034 case BndAction_Print:
4037 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
4039 if (aPrsIter.Value()->Mode() != theDispMode)
4042 aBox = aPrsIter.Value()->MinMaxValues();
4044 gp_Pnt aMin = aBox.CornerMin();
4045 gp_Pnt aMax = aBox.CornerMax();
4046 theDI << theName << "\n"
4047 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
4048 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
4054 //==============================================================================
4055 //function : VBounding
4057 //==============================================================================
4058 int VBounding (Draw_Interpretor& theDI,
4059 Standard_Integer theArgNb,
4060 const char** theArgVec)
4062 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4063 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4066 std::cout << "Error: no active view!\n";
4070 ViewerTest_BndAction anAction = BndAction_Show;
4071 Standard_Integer aMode = -1;
4073 Handle(Prs3d_Drawer) aStyle;
4075 Standard_Integer anArgIter = 1;
4076 for (; anArgIter < theArgNb; ++anArgIter)
4078 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4080 if (anArg == "-print")
4082 anAction = BndAction_Print;
4084 else if (anArg == "-show")
4086 anAction = BndAction_Show;
4088 else if (anArg == "-hide")
4090 anAction = BndAction_Hide;
4092 else if (anArg == "-mode")
4094 if (++anArgIter >= theArgNb)
4096 std::cout << "Error: wrong syntax at " << anArg << "\n";
4099 aMode = Draw::Atoi (theArgVec[anArgIter]);
4101 else if (!anUpdateTool.parseRedrawMode (anArg))
4107 if (anAction == BndAction_Show)
4109 aStyle = new Prs3d_Drawer();
4110 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
4111 aStyle->SetColor (Quantity_NOC_GRAY99);
4114 Standard_Integer aHighlightedMode = -1;
4115 if (anArgIter < theArgNb)
4117 // has a list of names
4118 for (; anArgIter < theArgNb; ++anArgIter)
4120 TCollection_AsciiString aName = theArgVec[anArgIter];
4121 Handle(AIS_InteractiveObject) anIO;
4122 if (!GetMapOfAIS().Find2 (aName, anIO))
4124 std::cout << "Error: presentation " << aName << " does not exist\n";
4128 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4129 if (aHighlightedMode == -1)
4131 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
4134 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
4137 else if (aCtx->NbSelected() > 0)
4139 // remove all currently selected objects
4140 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4142 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
4143 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4144 if (aHighlightedMode != -1)
4146 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
4147 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
4154 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
4155 anIter.More(); anIter.Next())
4157 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
4158 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4159 if (aHighlightedMode != -1)
4161 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
4168 //==============================================================================
4169 //function : VTexture
4171 //==============================================================================
4172 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4174 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4177 std::cout << "Error: no active view!\n";
4181 int toModulate = -1;
4182 bool toSetFilter = false;
4183 bool toSetAniso = false;
4184 bool toSetTrsfAngle = false;
4185 bool toSetTrsfTrans = false;
4186 bool toSetTrsfScale = false;
4187 Standard_ShortReal aTrsfRotAngle = 0.0f;
4188 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
4189 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
4190 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
4191 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
4193 Handle(AIS_InteractiveObject) aTexturedIO;
4194 Handle(AIS_Shape) aTexturedShape;
4195 Handle(Graphic3d_TextureSet) aTextureSetOld;
4196 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
4197 bool toSetGenRepeat = false;
4198 bool toSetGenScale = false;
4199 bool toSetGenOrigin = false;
4200 bool toSetImage = false;
4201 bool toComputeUV = false;
4203 const TCollection_AsciiString aCommandName (theArgVec[0]);
4204 bool toSetDefaults = aCommandName == "vtexdefault";
4206 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4207 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
4209 const TCollection_AsciiString aName = theArgVec[anArgIter];
4210 TCollection_AsciiString aNameCase = aName;
4211 aNameCase.LowerCase();
4212 if (anUpdateTool.parseRedrawMode (aName))
4216 else if (aTexturedIO.IsNull())
4218 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
4219 if (aMapOfIO.IsBound2 (aName))
4221 aTexturedIO = aMapOfIO.Find2 (aName);
4222 aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO);
4224 if (aTexturedIO.IsNull())
4226 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
4230 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
4232 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
4235 else if (!aTexturedShape.IsNull()
4236 && (aNameCase == "-scale"
4237 || aNameCase == "-setscale"
4238 || aCommandName == "vtexscale"))
4240 if (aCommandName != "vtexscale")
4244 if (anArgIter < theArgsNb)
4246 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4247 TCollection_AsciiString aValUCase = aValU;
4248 aValUCase.LowerCase();
4249 toSetGenScale = true;
4250 if (aValUCase == "off")
4252 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4255 else if (anArgIter + 1 < theArgsNb)
4257 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4258 if (aValU.IsRealValue()
4259 && aValV.IsRealValue())
4261 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4267 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4270 else if (!aTexturedShape.IsNull()
4271 && (aNameCase == "-origin"
4272 || aNameCase == "-setorigin"
4273 || aCommandName == "vtexorigin"))
4275 if (aCommandName != "vtexorigin")
4279 if (anArgIter < theArgsNb)
4281 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4282 TCollection_AsciiString aValUCase = aValU;
4283 aValUCase.LowerCase();
4284 toSetGenOrigin = true;
4285 if (aValUCase == "off")
4287 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4290 else if (anArgIter + 1 < theArgsNb)
4292 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4293 if (aValU.IsRealValue()
4294 && aValV.IsRealValue())
4296 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4302 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4305 else if (!aTexturedShape.IsNull()
4306 && (aNameCase == "-repeat"
4307 || aNameCase == "-setrepeat"
4308 || aCommandName == "vtexrepeat"))
4310 if (aCommandName != "vtexrepeat")
4314 if (anArgIter < theArgsNb)
4316 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4317 TCollection_AsciiString aValUCase = aValU;
4318 aValUCase.LowerCase();
4319 toSetGenRepeat = true;
4320 if (aValUCase == "off")
4322 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4325 else if (anArgIter + 1 < theArgsNb)
4327 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4328 if (aValU.IsRealValue()
4329 && aValV.IsRealValue())
4331 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4337 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4340 else if (aNameCase == "-modulate")
4342 bool toModulateBool = true;
4343 if (anArgIter + 1 < theArgsNb
4344 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
4348 toModulate = toModulateBool ? 1 : 0;
4350 else if ((aNameCase == "-setfilter"
4351 || aNameCase == "-filter")
4352 && anArgIter + 1 < theArgsNb)
4354 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4358 if (aValue == "nearest")
4360 aFilter = Graphic3d_TOTF_NEAREST;
4362 else if (aValue == "bilinear")
4364 aFilter = Graphic3d_TOTF_BILINEAR;
4366 else if (aValue == "trilinear")
4368 aFilter = Graphic3d_TOTF_TRILINEAR;
4372 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
4376 else if ((aNameCase == "-setaniso"
4377 || aNameCase == "-setanisofilter"
4378 || aNameCase == "-aniso"
4379 || aNameCase == "-anisofilter")
4380 && anArgIter + 1 < theArgsNb)
4382 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4386 if (aValue == "off")
4388 anAnisoFilter = Graphic3d_LOTA_OFF;
4390 else if (aValue == "fast")
4392 anAnisoFilter = Graphic3d_LOTA_FAST;
4394 else if (aValue == "middle")
4396 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
4398 else if (aValue == "quality"
4399 || aValue == "high")
4401 anAnisoFilter = Graphic3d_LOTA_QUALITY;
4405 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
4409 else if ((aNameCase == "-rotateangle"
4410 || aNameCase == "-rotangle"
4411 || aNameCase == "-rotate"
4412 || aNameCase == "-angle"
4413 || aNameCase == "-trsfangle")
4414 && anArgIter + 1 < theArgsNb)
4416 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4417 toSetTrsfAngle = true;
4420 else if ((aNameCase == "-trsftrans"
4421 || aNameCase == "-trsftranslate"
4422 || aNameCase == "-translate"
4423 || aNameCase == "-translation")
4424 && anArgIter + 2 < theArgsNb)
4426 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4427 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4428 toSetTrsfTrans = true;
4431 else if ((aNameCase == "-trsfscale")
4432 && anArgIter + 2 < theArgsNb)
4434 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4435 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4436 toSetTrsfScale = true;
4439 else if (aNameCase == "-default"
4440 || aNameCase == "-defaults")
4442 toSetDefaults = true;
4444 else if ((aNameCase == "-video")
4445 && anArgIter + 1 < theArgsNb)
4447 const TCollection_AsciiString anInput (theArgVec[++anArgIter]);
4448 Handle(Graphic3d_MediaTextureSet) aMedia = Handle(Graphic3d_MediaTextureSet)::DownCast (aTextureSetOld);
4449 if (aMedia.IsNull())
4451 aMedia = new Graphic3d_MediaTextureSet();
4453 if (aMedia->Input() != anInput)
4455 aMedia->OpenInput (anInput, false);
4459 if (aMedia->SwapFrames()
4460 && !aCtx->CurrentViewer()->ZLayerSettings (aTexturedIO->ZLayer()).IsImmediate())
4462 ViewerTest::CurrentView()->Invalidate();
4465 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4466 && aTexturedShape.IsNull())
4468 aTexturedIO->SetToUpdate();
4471 toComputeUV = aTextureSetOld.IsNull();
4472 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (true);
4473 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia);
4474 aTextureSetOld.Nullify();
4476 else if (aCommandName == "vtexture"
4477 && (aTextureVecNew.IsEmpty()
4478 || aNameCase.StartsWith ("-tex")))
4480 Standard_Integer aTexIndex = 0;
4481 TCollection_AsciiString aTexName = aName;
4482 if (aNameCase.StartsWith ("-tex"))
4484 if (anArgIter + 1 >= theArgsNb
4485 || aNameCase.Length() < 5)
4487 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4491 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
4492 if (!aTexIndexStr.IsIntegerValue())
4494 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4498 aTexIndex = aTexIndexStr.IntegerValue();
4499 aTexName = theArgVec[anArgIter + 1];
4502 if (aTexIndex >= Graphic3d_TextureUnit_NB
4503 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
4505 std::cout << "Error: too many textures specified\n";
4510 if (aTexName.IsIntegerValue())
4512 const Standard_Integer aValue = aTexName.IntegerValue();
4513 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
4515 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
4518 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
4520 else if (aTexName == "?")
4522 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
4524 theDi << "\n Files in current directory : \n\n";
4525 theDi.Eval ("glob -nocomplain *");
4527 TCollection_AsciiString aCmnd ("glob -nocomplain ");
4528 aCmnd += aTextureFolder;
4531 theDi << "Files in " << aTextureFolder << " : \n\n";
4532 theDi.Eval (aCmnd.ToCString());
4535 else if (aTexName != "off")
4537 if (!OSD_File (aTexName).Exists())
4539 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
4542 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
4546 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
4549 if (aTextureVecNew.Value (aTexIndex))
4551 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
4556 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4563 // check if new image set is equal to already set one
4564 Standard_Integer aNbChanged = 0;
4565 Handle(Graphic3d_TextureSet) aTextureSetNew;
4566 if (!aTextureVecNew.IsEmpty())
4568 aNbChanged = aTextureVecNew.Size();
4569 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
4570 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
4572 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
4573 Handle(Graphic3d_TextureRoot) aTextureOld;
4574 if (!aTextureSetOld.IsNull()
4575 && aTexIter < aTextureSetOld->Size())
4577 aTextureOld = aTextureSetOld->Value (aTexIter);
4580 if (!aTextureOld.IsNull()
4581 && !aTextureNew.IsNull())
4583 *aTextureNew->GetParams() = *aTextureOld->GetParams();
4584 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
4586 TCollection_AsciiString aFilePathOld, aFilePathNew;
4587 aTextureOld->Path().SystemName (aFilePathOld);
4588 aTextureNew->Path().SystemName (aFilePathNew);
4589 if (aTextureNew->Name() == anOldManualTex->Name()
4590 && aFilePathOld == aFilePathNew
4591 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
4594 aTextureNew = anOldManualTex;
4598 aTextureSetNew->SetValue (aTexIter, aTextureNew);
4602 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
4603 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
4605 aTextureSetNew = aTextureSetOld;
4608 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4609 && aTexturedShape.IsNull())
4611 aTexturedIO->SetToUpdate();
4614 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
4615 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
4616 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
4617 aTextureSetOld.Nullify();
4622 if (toModulate != -1)
4629 aFilter = Graphic3d_TOTF_BILINEAR;
4634 anAnisoFilter = Graphic3d_LOTA_OFF;
4636 if (!toSetTrsfAngle)
4638 toSetTrsfAngle = true;
4639 aTrsfRotAngle = 0.0f;
4641 if (!toSetTrsfTrans)
4643 toSetTrsfTrans = true;
4644 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
4646 if (!toSetTrsfScale)
4648 toSetTrsfScale = true;
4649 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
4653 if (aCommandName == "vtexture"
4656 if (!aTextureSetOld.IsNull())
4658 //toComputeUV = true; // we can keep UV vertex attributes
4659 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
4660 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
4661 aTextureSetOld.Nullify();
4665 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
4666 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
4668 if (toModulate != -1)
4670 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
4674 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
4678 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
4682 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
4686 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
4690 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
4694 // set default values if requested
4696 && (aCommandName == "vtexrepeat"
4699 if (!aTexturedShape.IsNull())
4701 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4703 toSetGenRepeat = true;
4706 && (aCommandName == "vtexorigin"
4709 if (!aTexturedShape.IsNull())
4711 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4713 toSetGenOrigin = true;
4716 && (aCommandName == "vtexscale"
4719 if (!aTexturedShape.IsNull())
4721 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4723 toSetGenScale = true;
4726 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
4728 if (!aTexturedShape.IsNull())
4730 aTexturedShape->SetToUpdate (AIS_Shaded);
4733 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
4734 || aCtx->DisplayMode() != AIS_Shaded)
4736 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
4741 aCtx->Display (aTexturedIO, false);
4742 aTexturedIO->SynchronizeAspects();
4746 //! Auxiliary method to parse transformation persistence flags
4747 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
4748 Graphic3d_TransModeFlags& theFlags)
4750 if (theFlagString == "zoom")
4752 theFlags = Graphic3d_TMF_ZoomPers;
4754 else if (theFlagString == "rotate")
4756 theFlags = Graphic3d_TMF_RotatePers;
4758 else if (theFlagString == "zoomrotate")
4760 theFlags = Graphic3d_TMF_ZoomRotatePers;
4762 else if (theFlagString == "trihedron"
4763 || theFlagString == "triedron")
4765 theFlags = Graphic3d_TMF_TriedronPers;
4767 else if (theFlagString == "none")
4769 theFlags = Graphic3d_TMF_None;
4773 return Standard_False;
4776 return Standard_True;
4779 //! Auxiliary method to parse transformation persistence flags
4780 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4781 Aspect_TypeOfTriedronPosition& theCorner)
4783 TCollection_AsciiString aString (theString);
4784 aString.LowerCase();
4785 if (aString == "center")
4787 theCorner = Aspect_TOTP_CENTER;
4789 else if (aString == "top"
4790 || aString == "upper")
4792 theCorner = Aspect_TOTP_TOP;
4794 else if (aString == "bottom"
4795 || aString == "lower")
4797 theCorner = Aspect_TOTP_BOTTOM;
4799 else if (aString == "left")
4801 theCorner = Aspect_TOTP_LEFT;
4803 else if (aString == "right")
4805 theCorner = Aspect_TOTP_RIGHT;
4807 else if (aString == "topleft"
4808 || aString == "leftupper"
4809 || aString == "upperleft")
4811 theCorner = Aspect_TOTP_LEFT_UPPER;
4813 else if (aString == "bottomleft"
4814 || aString == "leftlower"
4815 || aString == "lowerleft")
4817 theCorner = Aspect_TOTP_LEFT_LOWER;
4819 else if (aString == "topright"
4820 || aString == "rightupper"
4821 || aString == "upperright")
4823 theCorner = Aspect_TOTP_RIGHT_UPPER;
4825 else if (aString == "bottomright"
4826 || aString == "lowerright"
4827 || aString == "rightlower")
4829 theCorner = Aspect_TOTP_RIGHT_LOWER;
4833 return Standard_False;
4836 return Standard_True;
4839 //==============================================================================
4840 //function : VDisplay2
4842 //purpose : Display an object from its name
4843 //==============================================================================
4844 static int VDisplay2 (Draw_Interpretor& theDI,
4845 Standard_Integer theArgNb,
4846 const char** theArgVec)
4850 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4854 && TCollection_AsciiString (theArgVec[1]) == "*")
4857 return VDisplayAll (theDI, 1, theArgVec);
4860 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4863 ViewerTest::ViewerInit();
4864 aCtx = ViewerTest::GetAISContext();
4867 // Parse input arguments
4868 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4869 Standard_Integer isMutable = -1;
4870 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4871 Standard_Boolean toReDisplay = Standard_False;
4872 Standard_Integer isSelectable = -1;
4873 Standard_Integer anObjDispMode = -2;
4874 Standard_Integer anObjHighMode = -2;
4875 Standard_Boolean toSetTrsfPers = Standard_False;
4876 Handle(Graphic3d_TransformPers) aTrsfPers;
4877 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4878 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4879 Standard_Integer toDisplayInView = Standard_False;
4880 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4882 const TCollection_AsciiString aName = theArgVec[anArgIter];
4883 TCollection_AsciiString aNameCase = aName;
4884 aNameCase.LowerCase();
4885 if (anUpdateTool.parseRedrawMode (aName))
4889 else if (aNameCase == "-mutable")
4893 else if (aNameCase == "-neutral")
4895 aDispStatus = AIS_DS_Displayed;
4897 else if (aNameCase == "-immediate"
4898 || aNameCase == "-top")
4900 aZLayer = Graphic3d_ZLayerId_Top;
4902 else if (aNameCase == "-topmost")
4904 aZLayer = Graphic3d_ZLayerId_Topmost;
4906 else if (aNameCase == "-osd"
4907 || aNameCase == "-toposd"
4908 || aNameCase == "-overlay")
4910 aZLayer = Graphic3d_ZLayerId_TopOSD;
4912 else if (aNameCase == "-botosd"
4913 || aNameCase == "-underlay")
4915 aZLayer = Graphic3d_ZLayerId_BotOSD;
4917 else if (aNameCase == "-select"
4918 || aNameCase == "-selectable")
4922 else if (aNameCase == "-noselect"
4923 || aNameCase == "-noselection")
4927 else if (aNameCase == "-dispmode"
4928 || aNameCase == "-displaymode")
4930 if (++anArgIter >= theArgNb)
4932 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4936 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4938 else if (aNameCase == "-himode"
4939 || aNameCase == "-highmode"
4940 || aNameCase == "-highlightmode")
4942 if (++anArgIter >= theArgNb)
4944 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4948 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4950 else if (aNameCase == "-3d")
4952 toSetTrsfPers = Standard_True;
4953 aTrsfPers.Nullify();
4955 else if (aNameCase == "-2d"
4956 || aNameCase == "-trihedron"
4957 || aNameCase == "-triedron")
4959 toSetTrsfPers = Standard_True;
4960 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4962 if (anArgIter + 1 < theArgNb)
4964 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4965 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4968 aTrsfPers->SetCorner2d (aCorner);
4970 if (anArgIter + 2 < theArgNb)
4972 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4973 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4974 if (anX.IsIntegerValue()
4975 && anY.IsIntegerValue())
4978 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4984 else if (aNameCase == "-trsfpers"
4985 || aNameCase == "-pers")
4987 if (++anArgIter >= theArgNb
4988 || !aTrsfPers.IsNull())
4990 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4994 toSetTrsfPers = Standard_True;
4995 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4996 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4997 aPersFlags.LowerCase();
4998 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
5000 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
5004 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
5006 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
5008 else if (aTrsfPersFlags != Graphic3d_TMF_None)
5010 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
5013 else if (aNameCase == "-trsfperspos"
5014 || aNameCase == "-perspos")
5016 if (anArgIter + 2 >= theArgNb
5017 || aTrsfPers.IsNull())
5019 std::cerr << "Error: wrong syntax at " << aName << ".\n";
5023 TCollection_AsciiString aX (theArgVec[++anArgIter]);
5024 TCollection_AsciiString aY (theArgVec[++anArgIter]);
5025 TCollection_AsciiString aZ = "0";
5026 if (!aX.IsRealValue()
5027 || !aY.IsRealValue())
5029 std::cerr << "Error: wrong syntax at " << aName << ".\n";
5032 if (anArgIter + 1 < theArgNb)
5034 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
5035 if (aTemp.IsRealValue())
5042 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
5043 if (aTrsfPers->IsZoomOrRotate())
5045 aTrsfPers->SetAnchorPoint (aPnt);
5047 else if (aTrsfPers->IsTrihedronOr2d())
5049 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
5052 else if (aNameCase == "-layer"
5053 || aNameCase == "-zlayer")
5056 if (anArgIter >= theArgNb
5057 || !ViewerTest::ParseZLayer (theArgVec[anArgIter], aZLayer)
5058 || aZLayer == Graphic3d_ZLayerId_UNKNOWN)
5060 std::cerr << "Error: wrong syntax at " << aName << ".\n";
5064 else if (aNameCase == "-view"
5065 || aNameCase == "-inview")
5067 toDisplayInView = Standard_True;
5069 else if (aNameCase == "-redisplay")
5071 toReDisplay = Standard_True;
5073 else if (aNameCase == "-erased"
5074 || aNameCase == "-load")
5076 aDispStatus = AIS_DS_Erased;
5080 aNamesOfDisplayIO.Append (aName);
5084 if (aNamesOfDisplayIO.IsEmpty())
5086 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5090 // Display interactive objects
5091 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
5093 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value (anIter);
5094 Handle(AIS_InteractiveObject) aShape;
5095 if (!GetMapOfAIS().Find2 (aName, aShape))
5097 // create the AIS_Shape from a name
5098 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
5099 if (!aDrawShape.IsNull())
5101 aShape = new AIS_Shape (aDrawShape);
5102 if (isMutable != -1)
5104 aShape->SetMutable (isMutable == 1);
5106 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
5108 aShape->SetZLayer (aZLayer);
5112 aCtx->SetTransformPersistence (aShape, aTrsfPers);
5114 if (anObjDispMode != -2)
5116 if (anObjDispMode == -1)
5118 aShape->UnsetDisplayMode();
5120 if (!aShape->AcceptDisplayMode (anObjDispMode))
5122 std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjDispMode << " display mode\n";
5127 aShape->SetDisplayMode (anObjDispMode);
5130 if (anObjHighMode != -2)
5132 if (anObjHighMode != -1
5133 && !aShape->AcceptDisplayMode (anObjHighMode))
5135 std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjHighMode << " display mode\n";
5138 aShape->SetHilightMode (anObjHighMode);
5141 GetMapOfAIS().Bind (aShape, aName);
5142 Standard_Integer aDispMode = aShape->HasDisplayMode()
5143 ? aShape->DisplayMode()
5144 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5145 ? aCtx->DisplayMode()
5147 Standard_Integer aSelMode = -1;
5148 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5150 aSelMode = aShape->GlobalSelectionMode();
5153 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5154 if (toDisplayInView)
5156 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
5158 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
5160 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5165 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
5170 if (isMutable != -1)
5172 aShape->SetMutable (isMutable == 1);
5174 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
5176 aShape->SetZLayer (aZLayer);
5180 aCtx->SetTransformPersistence (aShape, aTrsfPers);
5182 if (anObjDispMode != -2)
5184 aShape->SetDisplayMode (anObjDispMode);
5186 if (anObjHighMode != -2)
5188 aShape->SetHilightMode (anObjHighMode);
5190 Standard_Integer aDispMode = aShape->HasDisplayMode()
5191 ? aShape->DisplayMode()
5192 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5193 ? aCtx->DisplayMode()
5195 Standard_Integer aSelMode = -1;
5196 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5198 aSelMode = aShape->GlobalSelectionMode();
5201 if (aShape->Type() == AIS_KOI_Datum)
5203 aCtx->Display (aShape, Standard_False);
5207 theDI << "Display " << aName << "\n";
5209 // update the Shape in the AIS_Shape
5210 TopoDS_Shape aNewShape = DBRep::GetExisting (aName);
5211 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
5212 if (!aShapePrs.IsNull())
5214 if (!aShapePrs->Shape().IsEqual (aNewShape))
5216 toReDisplay = Standard_True;
5218 aShapePrs->Set (aNewShape);
5222 aCtx->Redisplay (aShape, Standard_False);
5227 aCtx->Erase (aShape, Standard_False);
5229 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5230 if (toDisplayInView)
5232 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5240 //=======================================================================
5241 //function : VNbDisplayed
5242 //purpose : Returns number of displayed objects
5243 //=======================================================================
5244 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
5245 Standard_Integer theArgsNb,
5246 const char** theArgVec)
5250 theDi << "Usage : " << theArgVec[0] << "\n";
5254 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5255 if (aContextAIS.IsNull())
5257 std::cout << theArgVec[0] << "AIS context is not available.\n";
5261 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5262 if(aContext.IsNull())
5264 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
5268 AIS_ListOfInteractive aListOfIO;
5269 aContextAIS->DisplayedObjects (aListOfIO);
5271 theDi << aListOfIO.Extent() << "\n";
5275 //===============================================================================================
5276 //function : VUpdate
5278 //===============================================================================================
5279 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
5281 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5282 if (aContextAIS.IsNull())
5284 std::cout << theArgVec[0] << "AIS context is not available.\n";
5290 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
5294 AIS_ListOfInteractive aListOfIO;
5295 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5297 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
5299 Handle(AIS_InteractiveObject) anAISObj;
5300 GetMapOfAIS().Find2 (aName, anAISObj);
5301 if (anAISObj.IsNull())
5303 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
5307 aListOfIO.Append (anAISObj);
5310 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
5311 for (; anIOIt.More(); anIOIt.Next())
5313 aContextAIS->Update (anIOIt.Value(), Standard_False);
5316 aContextAIS->UpdateCurrentViewer();
5321 //==============================================================================
5322 //function : VShading
5323 //purpose : Sharpen or roughten the quality of the shading
5324 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
5325 //==============================================================================
5326 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
5328 Standard_Real myDevCoef;
5329 Handle(AIS_InteractiveObject) TheAisIO;
5332 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
5336 myDevCoef =Draw::Atof(argv[2]);
5339 TCollection_AsciiString name=argv[1];
5340 GetMapOfAIS().Find2(name, TheAisIO);
5341 if (TheAisIO.IsNull())
5343 TopoDS_Shape aDrawShape = DBRep::GetExisting (name);
5344 if (!aDrawShape.IsNull())
5346 TheAisIO = new AIS_Shape (aDrawShape);
5351 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5353 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
5355 TheAISContext()->Redisplay (TheAisIO, Standard_True);
5359 //! Auxiliary method to print Interactive Object information
5360 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
5361 const Handle(AIS_InteractiveObject)& theObj,
5362 Draw_Interpretor& theDI)
5364 if (theObj.IsNull())
5366 theDI << "NULL presentation\n";
5370 theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ")
5371 << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ")
5372 << (theDetected.Contains (theObj) ? " Detected" : " ")
5374 if (theObj->Type() == AIS_KOI_Datum)
5377 if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
5378 else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; }
5379 else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; }
5380 else if (theObj->Signature() == 5) { theDI << " AIS_Line"; }
5381 else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; }
5382 else if (theObj->Signature() == 1) { theDI << " AIS_Point"; }
5383 else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
5386 else if (theObj->Type() == AIS_KOI_Shape
5387 && theObj->Signature() == 0)
5389 theDI << " AIS_Shape";
5391 else if (theObj->Type() == AIS_KOI_Relation)
5393 // AIS_Dimention and AIS_Relation
5394 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (theObj);
5395 switch (aRelation->KindOfDimension())
5397 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
5398 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
5399 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
5400 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
5401 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
5402 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
5403 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
5404 default: theDI << " UNKNOWN dimension"; break;
5409 theDI << " UserPrs";
5411 theDI << " (" << theObj->DynamicType()->Name() << ")";
5414 //! Print information about locally selected sub-shapes
5415 template <typename T>
5416 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
5418 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
5419 TCollection_AsciiString aPrevName;
5420 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
5422 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
5423 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
5424 if (aShapeIO.IsNull() || anOwner.IsNull())
5428 if (anOwner == aShapeIO->GlobalSelOwner())
5431 const TopoDS_Shape aSubShape = theContext->SelectedShape();
5432 if (aSubShape.IsNull()
5433 || aShapeIO.IsNull()
5434 || !GetMapOfAIS().IsBound1 (aShapeIO))
5439 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
5440 TopTools_MapOfShape aFilter;
5441 Standard_Integer aNumber = 0;
5442 const TopoDS_Shape aShape = aShapeIO->Shape();
5443 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
5444 anIter.More(); anIter.Next())
5446 if (!aFilter.Add (anIter.Current()))
5448 continue; // filter duplicates
5452 if (!anIter.Current().IsSame (aSubShape))
5457 Standard_CString aShapeName = NULL;
5458 switch (aSubShape.ShapeType())
5460 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
5461 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
5462 case TopAbs_SOLID: aShapeName = " Solid"; break;
5463 case TopAbs_SHELL: aShapeName = " Shell"; break;
5464 case TopAbs_FACE: aShapeName = " Face"; break;
5465 case TopAbs_WIRE: aShapeName = " Wire"; break;
5466 case TopAbs_EDGE: aShapeName = " Edge"; break;
5467 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
5469 case TopAbs_SHAPE: aShapeName = " Shape"; break;
5472 if (aParentName != aPrevName)
5474 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
5475 aPrevName = aParentName;
5477 theDI << " " << aShapeName << " #" << aNumber << "\n";
5483 //==============================================================================
5486 //==============================================================================
5487 static Standard_Integer VState (Draw_Interpretor& theDI,
5488 Standard_Integer theArgNb,
5489 Standard_CString* theArgVec)
5491 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
5494 std::cerr << "Error: No opened viewer!\n";
5498 Standard_Boolean toPrintEntities = Standard_False;
5499 Standard_Boolean toCheckSelected = Standard_False;
5501 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
5503 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
5504 anOption.LowerCase();
5505 if (anOption == "-detectedentities"
5506 || anOption == "-entities")
5508 toPrintEntities = Standard_True;
5510 else if (anOption == "-hasselected")
5512 toCheckSelected = Standard_True;
5516 if (toCheckSelected)
5518 aCtx->InitSelected();
5519 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
5520 theDI << "Check if context has selected shape: " << hasSelected << "\n";
5525 if (toPrintEntities)
5527 theDI << "Detected entities:\n";
5528 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
5530 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
5531 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
5533 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
5534 const Handle(Select3D_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
5535 const Handle(SelectMgr_EntityOwner)& anOwner = anEntity->OwnerId();
5536 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5538 TCollection_AsciiString aName;
5539 GetMapOfAIS().Find1 (anObj, aName);
5540 aName.LeftJustify (20, ' ');
5541 char anInfoStr[512];
5543 " Depth: %g Distance: %g Point: %g %g %g",
5546 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
5547 theDI << " " << aName
5549 << " (" << anEntity->DynamicType()->Name() << ")"
5552 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
5553 if (!aBRepOwner.IsNull())
5555 theDI << " Detected Shape: "
5556 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
5560 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
5561 if (!aWire.IsNull())
5563 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
5564 theDI << " Detected Child: "
5565 << aSen->DynamicType()->Name()
5569 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
5570 if (!aPrimArr.IsNull())
5572 theDI << " Detected Element: "
5573 << aPrimArr->LastDetectedElement()
5580 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
5581 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
5583 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
5586 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
5590 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5592 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
5593 Handle(AIS_InteractiveObject) anObj;
5594 if (!GetMapOfAIS().Find2 (anObjName, anObj))
5596 theDI << anObjName << " doesn't exist!\n";
5600 TCollection_AsciiString aName = anObjName;
5601 aName.LeftJustify (20, ' ');
5602 theDI << " " << aName << " ";
5603 objInfo (aDetected, anObj, theDI);
5609 if (aCtx->NbSelected() > 0 && !toShowAll)
5611 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
5612 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
5614 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
5615 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5616 // handle whole object selection
5617 if (anOwner == anObj->GlobalSelOwner())
5619 TCollection_AsciiString aName;
5620 GetMapOfAIS().Find1 (anObj, aName);
5621 aName.LeftJustify (20, ' ');
5622 theDI << aName << " ";
5623 objInfo (aDetected, anObj, theDI);
5628 // process selected sub-shapes
5629 printLocalSelectionInfo (aCtx, theDI);
5634 theDI << "Neutral-point state:\n";
5635 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5636 anObjIter.More(); anObjIter.Next())
5638 if (anObjIter.Key1().IsNull())
5643 TCollection_AsciiString aName = anObjIter.Key2();
5644 aName.LeftJustify (20, ' ');
5645 theDI << " " << aName << " ";
5646 objInfo (aDetected, anObjIter.Key1(), theDI);
5649 printLocalSelectionInfo (aCtx, theDI);
5653 //=======================================================================
5654 //function : PickShape
5655 //purpose : First Activate the rightmode + Put Filters to be able to
5656 // pick objets that are of type <TheType>...
5657 //=======================================================================
5659 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
5660 const Standard_Integer theMaxPick)
5662 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
5663 PickShapes (theShapeType, aResArray, theMaxPick);
5664 return aResArray->First();
5667 //=======================================================================
5668 //function : PickShapes
5670 //=======================================================================
5671 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
5672 Handle(TopTools_HArray1OfShape)& theResArray,
5673 const Standard_Integer theMaxPick)
5675 const Standard_Integer aNbToReach = theResArray->Length();
5678 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
5681 // step 1: prepare the data
5682 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5683 aCtx->RemoveFilters();
5684 AIS_ListOfInteractive aDispObjects;
5685 aCtx->DisplayedObjects (aDispObjects);
5686 if (theShapeType == TopAbs_SHAPE)
5688 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
5692 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
5695 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
5696 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5698 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5700 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5704 // step 2 : wait for the selection...
5705 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
5706 Standard_Integer argccc = 5;
5707 const char *bufff[] = { "A", "B", "C", "D", "E" };
5708 const char **argvvv = (const char** )bufff;
5709 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
5711 while (ViewerMainLoop (argccc, argvvv)) {}
5712 Standard_Integer aNbStored = aCtx->NbSelected();
5713 if (aNbStored != aNbPickGood)
5715 aNbPickGood = aNbStored;
5721 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
5724 // step3 get result.
5725 if (aNbPickFail >= aNbToReach)
5727 return Standard_False;
5730 Standard_Integer anIndex = theResArray->Lower();
5731 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
5733 if (aCtx->HasSelectedShape())
5735 theResArray->SetValue (anIndex, aCtx->SelectedShape());
5739 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
5740 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
5744 aCtx->RemoveFilters();
5745 if (theShapeType != TopAbs_SHAPE)
5747 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5749 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5751 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5755 return Standard_True;
5758 //=======================================================================
5759 //function : VPickShape
5761 //=======================================================================
5762 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5764 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
5767 TCollection_AsciiString aShapeArg (argv[1]);
5768 aShapeArg.LowerCase();
5769 aShapeType = TopAbs_COMPOUND;
5770 if (aShapeArg == "v"
5771 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
5772 else if (aShapeArg == "e"
5773 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
5774 else if (aShapeArg == "w"
5775 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
5776 else if (aShapeArg == "f"
5777 || aShapeArg == "face") aShapeType = TopAbs_FACE;
5778 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
5779 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
5780 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
5783 std::cout << "Syntax error at '" << argv[1] << "'\n";
5788 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5789 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
5791 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
5794 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
5795 if (aPickedShape.IsNull())
5800 TCollection_AsciiString aName;
5807 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5808 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5811 DBRep::Set (aName.ToCString(), aPickedShape);
5812 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5813 ViewerTest::Display (aName, aShapePrs, false, true);
5814 di << "Name of picked shape: " << aName <<"\n";
5818 TCollection_AsciiString aName (argv[2]);
5820 const Standard_Boolean isAutoNaming = aName == ".";
5821 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5822 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5824 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5826 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5828 if (!aPickedShape.IsNull()
5831 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5832 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5836 aName = argv[1 + aPickedIter];
5839 DBRep::Set (aName.ToCString(), aPickedShape);
5840 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5841 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5842 ViewerTest::Display (aName, aShapePrs, false, true);
5846 TheAISContext()->UpdateCurrentViewer();
5850 //=======================================================================
5851 //function : VSelFilter
5853 //=======================================================================
5854 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5855 const char** theArgv)
5857 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5858 if (aContext.IsNull())
5860 std::cout << "Error: AIS context is not available.\n";
5864 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5866 TCollection_AsciiString anArg (theArgv[anArgIter]);
5868 if (anArg == "-clear")
5870 aContext->RemoveFilters();
5872 else if (anArg == "-type"
5873 && anArgIter + 1 < theArgc)
5875 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5876 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5877 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5879 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5883 Handle(SelectMgr_Filter) aFilter;
5884 if (aShapeType == TopAbs_SHAPE)
5886 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5890 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5892 aContext->AddFilter (aFilter);
5896 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5903 //=======================================================================
5904 //function : VPickSelected
5906 //=======================================================================
5907 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5909 static Standard_Integer aCount = 0;
5910 TCollection_AsciiString aName = "PickedShape_";
5918 aName = aName + aCount++ + "_";
5921 Standard_Integer anIdx = 0;
5922 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5924 TopoDS_Shape aShape;
5925 if (TheAISContext()->HasSelectedShape())
5927 aShape = TheAISContext()->SelectedShape();
5931 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5932 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5935 TCollection_AsciiString aCurrentName = aName;
5938 aCurrentName += anIdx;
5941 DBRep::Set ((aCurrentName).ToCString(), aShape);
5943 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5944 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5945 TheAISContext()->Display (aNewShape, Standard_False);
5948 TheAISContext()->UpdateCurrentViewer();
5953 //=======================================================================
5954 //function : list of known objects
5956 //=======================================================================
5957 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5959 // 1234567890 12345678901234567 123456789
5960 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5961 TCollection_AsciiString BlankLine(64,'_');
5962 Standard_Integer i ;
5964 di<<"/n"<<BlankLine.ToCString()<<"\n";
5967 Colum[i].Center(20,' ');
5969 di<<"|"<<Colum[i].ToCString();
5972 di<<BlankLine.ToCString()<<"\n";
5974 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5975 const char ** names = GetTypeNames();
5977 TCollection_AsciiString curstring;
5978 TCollection_AsciiString curcolum[3];
5981 // les objets de type Datum..
5982 curcolum[1]+="Datum";
5984 curcolum[0].Clear();
5985 curcolum[0] += names[i];
5987 curcolum[2].Clear();
5988 curcolum[2]+=TCollection_AsciiString(i+1);
5990 for(Standard_Integer j =0;j<=2;j++){
5991 curcolum[j].Center(20,' ');
5992 di<<"|"<<curcolum[j].ToCString();
5996 di<<BlankLine.ToCString()<<"\n";
5998 // les objets de type shape
5999 curcolum[1].Clear();
6000 curcolum[1]+="Shape";
6001 curcolum[1].Center(20,' ');
6004 curcolum[0].Clear();
6005 curcolum[0] += names[7+i];
6006 curcolum[2].Clear();
6007 curcolum[2]+=TCollection_AsciiString(i);
6009 for(Standard_Integer j =0;j<=2;j++){
6010 curcolum[j].Center(20,' ');
6011 di<<"|"<<curcolum[j].ToCString();
6015 di<<BlankLine.ToCString()<<"\n";
6016 // les IO de type objet...
6017 curcolum[1].Clear();
6018 curcolum[1]+="Object";
6019 curcolum[1].Center(20,' ');
6021 curcolum[0].Clear();
6022 curcolum[0] += names[10+i];
6023 curcolum[2].Clear();
6024 curcolum[2]+=TCollection_AsciiString(i);
6026 for(Standard_Integer j =0;j<=2;j++){
6027 curcolum[j].Center(20,' ');
6028 di<<"|"<<curcolum[j].ToCString();
6032 di<<BlankLine.ToCString()<<"\n";
6033 // les contraintes et dimensions.
6034 // pour l'instant on separe juste contraintes et dimensions...
6035 // plus tard, on detaillera toutes les sortes...
6036 curcolum[1].Clear();
6037 curcolum[1]+="Relation";
6038 curcolum[1].Center(20,' ');
6040 curcolum[0].Clear();
6041 curcolum[0] += names[12+i];
6042 curcolum[2].Clear();
6043 curcolum[2]+=TCollection_AsciiString(i);
6045 for(Standard_Integer j =0;j<=2;j++){
6046 curcolum[j].Center(20,' ');
6047 di<<"|"<<curcolum[j].ToCString();
6051 di<<BlankLine.ToCString()<<"\n";
6058 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
6060 if(argc!=2) return 1;
6062 AIS_KindOfInteractive TheType;
6063 Standard_Integer TheSign(-1);
6064 GetTypeAndSignfromString(argv[1],TheType,TheSign);
6067 AIS_ListOfInteractive LIO;
6069 // en attendant l'amelioration ais pour les dimensions...
6071 Standard_Integer dimension_status(-1);
6072 if(TheType==AIS_KOI_Relation){
6073 dimension_status = TheSign ==1 ? 1 : 0;
6077 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
6078 Handle(AIS_InteractiveObject) curio;
6079 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
6082 if(dimension_status == -1)
6083 TheAISContext()->Erase(curio,Standard_False);
6085 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
6086 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
6087 (dimension_status==1 && KOD != AIS_KOD_NONE))
6088 TheAISContext()->Erase(curio,Standard_False);
6091 TheAISContext()->UpdateCurrentViewer();
6094 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
6096 if(argc!=2) return 1;
6098 AIS_KindOfInteractive TheType;
6099 Standard_Integer TheSign(-1);
6100 GetTypeAndSignfromString(argv[1],TheType,TheSign);
6102 // en attendant l'amelioration ais pour les dimensions...
6104 Standard_Integer dimension_status(-1);
6105 if(TheType==AIS_KOI_Relation){
6106 dimension_status = TheSign ==1 ? 1 : 0;
6110 AIS_ListOfInteractive LIO;
6111 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
6112 Handle(AIS_InteractiveObject) curio;
6113 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
6115 if(dimension_status == -1)
6116 TheAISContext()->Display(curio,Standard_False);
6118 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
6119 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
6120 (dimension_status==1 && KOD != AIS_KOD_NONE))
6121 TheAISContext()->Display(curio,Standard_False);
6126 TheAISContext()->UpdateCurrentViewer();
6130 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
6132 std::ifstream s(a[1]);
6133 BRep_Builder builder;
6135 BRepTools::Read(shape, s, builder);
6136 DBRep::Set(a[1], shape);
6137 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6138 Handle(AIS_Shape) ais = new AIS_Shape(shape);
6139 Ctx->Display (ais, Standard_True);
6143 //===============================================================================================
6146 //===============================================================================================
6147 static int VBsdf (Draw_Interpretor& theDI,
6148 Standard_Integer theArgsNb,
6149 const char** theArgVec)
6151 Handle(V3d_View) aView = ViewerTest::CurrentView();
6152 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6154 || aViewer.IsNull())
6156 std::cerr << "No active viewer!\n";
6160 ViewerTest_CmdParser aCmd;
6162 aCmd.SetDescription ("Adjusts parameters of material BSDF:");
6164 aCmd.AddOption ("print|echo|p", "Prints BSDF");
6166 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
6168 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
6169 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
6170 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
6171 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
6172 aCmd.AddOption ("le", "Radiance emitted by surface");
6174 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
6175 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
6177 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
6178 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
6180 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
6181 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
6183 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
6185 aCmd.Parse (theArgsNb, theArgVec);
6187 if (aCmd.HasOption ("help"))
6189 theDI.PrintHelp (theArgVec[0]);
6193 // check viewer update mode
6194 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
6195 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6197 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
6204 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
6205 Handle(AIS_InteractiveObject) anIObj;
6206 if (!GetMapOfAIS().Find2 (aName, anIObj))
6208 std::cerr << "Use 'vdisplay' before\n";
6212 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
6213 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
6215 if (aCmd.HasOption ("print"))
6218 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
6219 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
6220 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
6221 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
6222 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
6224 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6226 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
6227 : aBSDF.FresnelBase.Serialize();
6229 theDI << (aLayerID < 1 ? "Coat Fresnel: "
6230 : "Base Fresnel: ");
6232 if (aFresnel.x() >= 0.f)
6234 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
6235 << "G = " << aFresnel.g() << ", "
6236 << "B = " << aFresnel.b() << "\n";
6238 else if (aFresnel.x() >= -1.5f)
6240 theDI << "Constant " << aFresnel.z() << "\n";
6242 else if (aFresnel.x() >= -2.5f)
6244 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
6245 << "K = " << aFresnel.z() << "\n";
6249 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
6253 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
6254 << "Base roughness: " << aBSDF.Ks.w() << "\n"
6255 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
6256 << "Absorption color: " << aBSDF.Absorption.r() << ", "
6257 << aBSDF.Absorption.g() << ", "
6258 << aBSDF.Absorption.b() << "\n";
6263 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
6265 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
6268 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
6270 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
6273 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
6275 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
6278 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
6280 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
6282 aBSDF.Absorption.r() = aRGB.r();
6283 aBSDF.Absorption.g() = aRGB.g();
6284 aBSDF.Absorption.b() = aRGB.b();
6287 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
6291 if (aCmd.HasOption ("kc", 3))
6293 aKc = aCmd.ArgVec3f ("kc");
6297 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
6300 aBSDF.Kc.r() = aKc.r();
6301 aBSDF.Kc.g() = aKc.g();
6302 aBSDF.Kc.b() = aKc.b();
6305 if (aCmd.HasOption ("kd", 3))
6307 aBSDF.Kd = aCmd.ArgVec3f ("kd");
6309 else if (aCmd.HasOption ("kd", 1, Standard_True))
6311 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
6314 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
6318 if (aCmd.HasOption ("ks", 3))
6320 aKs = aCmd.ArgVec3f ("ks");
6324 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
6327 aBSDF.Ks.r() = aKs.r();
6328 aBSDF.Ks.g() = aKs.g();
6329 aBSDF.Ks.b() = aKs.b();
6332 if (aCmd.HasOption ("kt", 3))
6334 aBSDF.Kt = aCmd.ArgVec3f ("kt");
6336 else if (aCmd.HasOption ("kt", 1, Standard_True))
6338 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
6341 if (aCmd.HasOption ("le", 3))
6343 aBSDF.Le = aCmd.ArgVec3f ("le");
6345 else if (aCmd.HasOption ("le", 1, Standard_True))
6347 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
6350 const std::string aFresnelErrorMessage =
6351 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
6353 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6355 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
6358 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
6360 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6361 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6363 if (aFresnelType == "schlick")
6365 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
6366 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
6367 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
6369 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
6370 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
6371 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
6373 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
6377 theDI << aFresnelErrorMessage.c_str() << "\n";
6380 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
6382 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6383 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6385 if (aFresnelType == "conductor")
6387 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6388 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
6390 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
6394 theDI << aFresnelErrorMessage.c_str() << "\n";
6397 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
6399 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6400 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6402 if (aFresnelType == "constant")
6404 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6406 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
6408 else if (aFresnelType == "dielectric")
6410 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6412 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
6416 theDI << aFresnelErrorMessage.c_str() << "\n";
6421 if (aCmd.HasOption ("normalize"))
6426 aMaterial.SetBSDF (aBSDF);
6427 anIObj->SetMaterial (aMaterial);
6432 //==============================================================================
6433 //function : VLoadSelection
6434 //purpose : Adds given objects to map of AIS and loads selection primitives for them
6435 //==============================================================================
6436 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
6437 Standard_Integer theArgNb,
6438 const char** theArgVec)
6442 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
6446 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
6449 ViewerTest::ViewerInit();
6450 aCtx = ViewerTest::GetAISContext();
6453 // Parse input arguments
6454 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6456 const TCollection_AsciiString aName = theArgVec[anArgIter];
6457 Handle(AIS_InteractiveObject) aShape;
6458 if (!GetMapOfAIS().Find2 (aName, aShape))
6460 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
6461 if (!aDrawShape.IsNull())
6463 aShape = new AIS_Shape (aDrawShape);
6464 GetMapOfAIS().Bind (aShape, aName);
6467 if (aShape.IsNull())
6469 std::cout << "Syntax error: presentation '" << aName << "' not found\n";
6473 aCtx->Load (aShape, -1);
6474 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
6479 //==============================================================================
6480 //function : ViewerTest::Commands
6481 //purpose : Add all the viewer command in the Draw_Interpretor
6482 //==============================================================================
6484 void ViewerTest::Commands(Draw_Interpretor& theCommands)
6486 ViewerTest::ViewerCommands(theCommands);
6487 ViewerTest::RelationCommands(theCommands);
6488 ViewerTest::ObjectCommands(theCommands);
6489 ViewerTest::FilletCommands(theCommands);
6490 ViewerTest::OpenGlCommands(theCommands);
6492 const char *group = "AIS_Display";
6495 theCommands.Add("visos",
6496 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
6497 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
6498 __FILE__, visos, group);
6500 theCommands.Add("vdisplay",
6501 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
6502 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
6503 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
6504 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
6505 "\n\t\t: |topRight|bottomLeft|bottomRight}"
6506 "\n\t\t: [offsetX offsetY]]]"
6507 "\n\t\t: [-dispMode mode] [-highMode mode]"
6508 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
6509 "\n\t\t: [-redisplay] [-erased]"
6510 "\n\t\t: name1 [name2] ... [name n]"
6511 "\n\t\t: Displays named objects."
6512 "\n\t\t: Option -local enables displaying of objects in local"
6513 "\n\t\t: selection context. Local selection context will be opened"
6514 "\n\t\t: if there is not any."
6515 "\n\t\t: -noupdate Suppresses viewer redraw call."
6516 "\n\t\t: -mutable Enables optimizations for mutable objects."
6517 "\n\t\t: -neutral Draws objects in main viewer."
6518 "\n\t\t: -erased Loads the object into context, but does not display it."
6519 "\n\t\t: -layer Sets z-layer for objects."
6520 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
6521 "\n\t\t: options can be used for the default z-layers."
6522 "\n\t\t: -top Draws object on top of main presentations"
6523 "\n\t\t: but below topmost."
6524 "\n\t\t: -topmost Draws in overlay for 3D presentations."
6525 "\n\t\t: with independent Depth."
6526 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
6527 "\n\t\t: (On-Screen-Display)"
6528 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
6529 "\n\t\t: (On-Screen-Display)"
6530 "\n\t\t: -selectable|-noselect Controls selection of objects."
6531 "\n\t\t: -trsfPers Sets a transform persistence flags."
6532 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
6533 "\n\t\t: -2d Displays object in screen coordinates."
6534 "\n\t\t: (DY looks up)"
6535 "\n\t\t: -dispmode Sets display mode for objects."
6536 "\n\t\t: -highmode Sets hilight mode for objects."
6537 "\n\t\t: -redisplay Recomputes presentation of objects.",
6538 __FILE__, VDisplay2, group);
6540 theCommands.Add ("vnbdisplayed",
6542 "\n\t\t: Returns number of displayed objects",
6543 __FILE__, VNbDisplayed, group);
6545 theCommands.Add ("vupdate",
6546 "vupdate name1 [name2] ... [name n]"
6547 "\n\t\t: Updates named objects in interactive context",
6548 __FILE__, VUpdate, group);
6550 theCommands.Add("verase",
6551 "verase [-noupdate|-update] [-local] [name1] ... [name n] [-noerror]"
6552 "\n\t\t: Erases selected or named objects."
6553 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
6554 "\n\t\t: Option -local enables erasing of selected or named objects without"
6555 "\n\t\t: closing local selection context."
6556 "\n\t\t: Option -noerror prevents exception on non-existing objects.",
6557 __FILE__, VErase, group);
6559 theCommands.Add("vremove",
6560 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n] [-noerror]"
6561 "or vremove [-context] -all to remove all objects"
6562 "\n\t\t: Removes selected or named objects."
6563 "\n\t\t If -context is in arguments, the objects are not deleted"
6564 "\n\t\t from the map of objects and names."
6565 "\n\t\t: Option -local enables removing of selected or named objects without"
6566 "\n\t\t: closing local selection context. Empty local selection context will be"
6568 "\n\t\t: Option -noupdate suppresses viewer redraw call."
6569 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects."
6570 "\n\t\t: Option -noerror prevents exception on non-existing objects.",
6571 __FILE__, VRemove, group);
6573 theCommands.Add("vdonly",
6574 "vdonly [-noupdate|-update] [name1] ... [name n]"
6575 "\n\t\t: Displays only selected or named objects",
6576 __FILE__,VDonly2,group);
6578 theCommands.Add("vdisplayall",
6580 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
6581 __FILE__, VDisplayAll, group);
6583 theCommands.Add("veraseall",
6585 "\n\t\t: Erases all objects displayed in the viewer.",
6586 __FILE__, VErase, group);
6588 theCommands.Add("verasetype",
6590 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
6591 __FILE__, VEraseType, group);
6592 theCommands.Add("vbounding",
6593 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
6594 "\n\t\t: [-print] [-hide]"
6595 "\n\t\t: Temporarily display bounding box of specified Interactive"
6596 "\n\t\t: Objects, or print it to console if -print is specified."
6597 "\n\t\t: Already displayed box might be hidden by -hide option.",
6598 __FILE__,VBounding,group);
6600 theCommands.Add("vdisplaytype",
6601 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
6602 __FILE__,VDisplayType,group);
6604 theCommands.Add("vsetdispmode",
6605 "vsetdispmode [name] mode(1,2,..)"
6606 "\n\t\t: Sets display mode for all, selected or named objects.",
6607 __FILE__,VDispMode,group);
6609 theCommands.Add("vunsetdispmode",
6610 "vunsetdispmode [name]"
6611 "\n\t\t: Unsets custom display mode for selected or named objects.",
6612 __FILE__,VDispMode,group);
6614 theCommands.Add("vdir",
6615 "vdir [mask] [-list]"
6616 "\n\t\t: Lists all objects displayed in 3D viewer"
6617 "\n\t\t: mask - name filter like prefix*"
6618 "\n\t\t: -list - format list with new-line per name; OFF by default",
6619 __FILE__,VDir,group);
6621 #ifdef HAVE_FREEIMAGE
6622 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
6624 #define DUMP_FORMATS "{ppm}"
6626 theCommands.Add("vdump",
6627 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
6628 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
6629 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
6630 "\n\t\t: [-tileSize Size=0]"
6631 "\n\t\t: Dumps content of the active view into image file",
6632 __FILE__,VDump,group);
6634 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
6635 __FILE__,VSubInt,group);
6637 theCommands.Add("vaspects",
6638 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
6639 "\n\t\t: [-setVisibility 0|1]"
6640 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
6641 "\n\t\t: [-setBackFaceColor Color]"
6642 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
6643 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
6644 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
6645 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
6646 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
6647 "\n\t\t: [-unsetMarkerType]"
6648 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
6649 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
6650 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
6651 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
6652 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
6653 "\n\t\t: [-isoontriangulation 0|1]"
6654 "\n\t\t: [-setMaxParamValue {value}]"
6655 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
6656 "\n\t\t: [-setShadingModel {unlit|flat|gouraud|phong}]"
6657 "\n\t\t: [-unsetShadingModel]"
6658 "\n\t\t: [-setInterior {solid|hatch|hidenline|point}]"
6659 "\n\t\t: [-unsetInterior] [-setHatch HatchStyle]"
6660 "\n\t\t: [-setFaceBoundaryDraw {0|1}] [-setMostContinuity {c0|c1|c2|c3|cn}"
6661 "\n\t\t: [-setFaceBoundaryWidth LineWidth] [-setFaceBoundaryColor R G B] [-setFaceBoundaryType LineType]"
6662 "\n\t\t: [-setDrawEdges {0|1}] [-setEdgeType LineType] [-setEdgeColor R G B] [-setQuadEdges {0|1}]"
6663 "\n\t\t: [-setDrawSilhouette {0|1}]"
6664 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
6665 "\n\t\t: [-dumpJson]"
6666 "\n\t\t: [-dumpCompact {0|1}]"
6667 "\n\t\t: [-dumpDepth depth]"
6668 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
6669 "\n\t\t: Manage presentation properties of all, selected or named objects."
6670 "\n\t\t: When -subshapes is specified than following properties will be"
6671 "\n\t\t: assigned to specified sub-shapes."
6672 "\n\t\t: When -defaults is specified than presentation properties will be"
6673 "\n\t\t: assigned to all objects that have not their own specified properties"
6674 "\n\t\t: and to all objects to be displayed in the future."
6675 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier."
6676 "\n\t\t: See also vlistcolors and vlistmaterials to list named colors and materials"
6677 "\n\t\t: accepted by arguments -setMaterial and -setColor",
6678 __FILE__,VAspects,group);
6680 theCommands.Add("vsetcolor",
6681 "vsetcolor [-noupdate|-update] [name] ColorName"
6682 "\n\t\t: Sets color for all, selected or named objects."
6683 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
6684 __FILE__,VAspects,group);
6686 theCommands.Add("vunsetcolor",
6687 "vunsetcolor [-noupdate|-update] [name]"
6688 "\n\t\t: Resets color for all, selected or named objects."
6689 "\n\t\t: Alias for vaspects -unsetcolor [name].",
6690 __FILE__,VAspects,group);
6692 theCommands.Add("vsettransparency",
6693 "vsettransparency [-noupdate|-update] [name] Coefficient"
6694 "\n\t\t: Sets transparency for all, selected or named objects."
6695 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
6696 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
6697 __FILE__,VAspects,group);
6699 theCommands.Add("vunsettransparency",
6700 "vunsettransparency [-noupdate|-update] [name]"
6701 "\n\t\t: Resets transparency for all, selected or named objects."
6702 "\n\t\t: Alias for vaspects -unsettransp [name].",
6703 __FILE__,VAspects,group);
6705 theCommands.Add("vsetmaterial",
6706 "vsetmaterial [-noupdate|-update] [name] MaterialName"
6707 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
6708 __FILE__,VAspects,group);
6710 theCommands.Add("vunsetmaterial",
6711 "vunsetmaterial [-noupdate|-update] [name]"
6712 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
6713 __FILE__,VAspects,group);
6715 theCommands.Add("vsetwidth",
6716 "vsetwidth [-noupdate|-update] [name] width(0->10)"
6717 "\n\t\t: Alias for vaspects -setwidth [name] width.",
6718 __FILE__,VAspects,group);
6720 theCommands.Add("vunsetwidth",
6721 "vunsetwidth [-noupdate|-update] [name]"
6722 "\n\t\t: Alias for vaspects -unsetwidth [name].",
6723 __FILE__,VAspects,group);
6725 theCommands.Add("vsetinteriorstyle",
6726 "vsetinteriorstyle [-noupdate|-update] [name] Style"
6727 "\n\t\t: Alias for vaspects -setInterior [name] Style.",
6728 __FILE__,VAspects,group);
6730 theCommands.Add ("vsetedgetype",
6731 "vsetedgetype [name] [-type {solid, dash, dot}] [-color R G B] [-width value]"
6732 "\n\t\t: Alias for vaspects [name] -setEdgeType Type.",
6733 __FILE__, VAspects, group);
6735 theCommands.Add ("vunsetedgetype",
6736 "vunsetedgetype [name]"
6737 "\n\t\t: Alias for vaspects [name] -unsetEdgeType.",
6738 __FILE__, VAspects, group);
6740 theCommands.Add ("vshowfaceboundary",
6741 "vshowfaceboundary [name]"
6742 "\n\t\t: Alias for vaspects [name] -setFaceBoundaryDraw on",
6743 __FILE__, VAspects, group);
6745 theCommands.Add("vsensdis",
6746 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
6747 "\n\t\t: Standard entity types are those defined in Select3D package:"
6748 "\n\t\t: - sensitive box"
6749 "\n\t\t: - sensitive face"
6750 "\n\t\t: - sensitive curve"
6751 "\n\t\t: - sensitive segment"
6752 "\n\t\t: - sensitive circle"
6753 "\n\t\t: - sensitive point"
6754 "\n\t\t: - sensitive triangulation"
6755 "\n\t\t: - sensitive triangle"
6756 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
6757 __FILE__,VDispSensi,group);
6759 theCommands.Add("vsensera",
6760 "vsensera : erase active entities",
6761 __FILE__,VClearSensi,group);
6763 theCommands.Add("vsetshading",
6764 "vsetshading : vsetshading name Quality(default=0.0008) "
6765 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
6766 __FILE__,VShading,group);
6768 theCommands.Add("vunsetshading",
6769 "vunsetshading :vunsetshading name "
6770 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
6771 __FILE__,VShading,group);
6773 theCommands.Add ("vtexture",
6774 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
6775 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
6776 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
6777 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
6778 "\n\t\t: [-modulate {on|off}]"
6779 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
6780 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
6781 "\n\t\t: [-default]"
6782 "\n\t\t: The texture can be specified by filepath"
6783 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
6784 "\n\t\t: The options are:"
6785 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
6786 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
6787 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
6788 "\n\t\t: -modulate Enable or disable texture color modulation"
6789 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
6790 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
6791 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
6792 "\n\t\t: -setFilter Setup texture filter"
6793 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
6794 "\n\t\t: -default Sets texture mapping default parameters",
6795 __FILE__, VTexture, group);
6797 theCommands.Add("vtexscale",
6798 "vtexscale name ScaleU ScaleV"
6799 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
6800 __FILE__,VTexture,group);
6802 theCommands.Add("vtexorigin",
6803 "vtexorigin name OriginU OriginV"
6804 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
6805 __FILE__,VTexture,group);
6807 theCommands.Add("vtexrepeat",
6808 "vtexrepeat name RepeatU RepeatV"
6809 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
6812 theCommands.Add("vtexdefault",
6814 "\n\t\t: Alias for vtexture name -default.",
6817 theCommands.Add("vstate",
6818 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6819 "\n\t\t: Reports show/hidden state for selected or named objects"
6820 "\n\t\t: -entities - print low-level information about detected entities"
6821 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6822 __FILE__,VState,group);
6824 theCommands.Add("vpickshapes",
6825 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6826 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6827 "\n\t\t: Hold also Shift for multiple selection.",
6828 __FILE__, VPickShape, group);
6830 theCommands.Add("vtypes",
6831 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6834 theCommands.Add("vr",
6836 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6837 __FILE__,vr, group);
6839 theCommands.Add("vselfilter",
6840 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6841 "\nSets selection shape type filter in context or remove all filters."
6842 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6843 "\n : Option -clear remove all filters in context",
6844 __FILE__,VSelFilter,group);
6846 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6847 __FILE__, VPickSelected, group);
6849 theCommands.Add ("vloadselection",
6850 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6851 "\n\t\t: primitives for the shapes with names given without displaying them.",
6852 __FILE__, VLoadSelection, group);
6854 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6855 "\nAdjusts parameters of material BSDF:"
6856 "\n -help : Shows this message"
6857 "\n -print : Print BSDF"
6858 "\n -kd : Weight of the Lambertian BRDF"
6859 "\n -kr : Weight of the reflection BRDF"
6860 "\n -kt : Weight of the transmission BTDF"
6861 "\n -ks : Weight of the glossy Blinn BRDF"
6862 "\n -le : Self-emitted radiance"
6863 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6864 "\n Schlick x y z, Dielectric x, Conductor x y"
6865 "\n -roughness : Roughness of material (Blinn's exponent)"
6866 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6867 "\n -absorpcolor : Absorption color (only for transparent material)"
6868 "\n -normalize : Normalize BSDF coefficients",
6869 __FILE__, VBsdf, group);
6873 //=====================================================================
6874 //========================= for testing Draft and Rib =================
6875 //=====================================================================
6876 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6877 #include <DBRep.hxx>
6878 #include <TopoDS_Face.hxx>
6879 #include <gp_Pln.hxx>
6880 #include <AIS_KindOfSurface.hxx>
6881 #include <BRepOffsetAPI_DraftAngle.hxx>
6882 #include <Precision.hxx>
6883 #include <BRepAlgo.hxx>
6884 #include <OSD_Environment.hxx>
6885 #include <DrawTrSurf.hxx>
6886 //#include <DbgTools.hxx>
6887 //#include <FeatAlgo_MakeLinearForm.hxx>
6892 //=======================================================================
6893 //function : IsValid
6895 //=======================================================================
6896 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6897 const TopoDS_Shape& theResult,
6898 const Standard_Boolean closedSolid,
6899 const Standard_Boolean GeomCtrl)
6901 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6902 TCollection_AsciiString checkValid = check.Value();
6903 Standard_Boolean ToCheck = Standard_True;
6904 if (!checkValid.IsEmpty()) {
6906 std::cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6908 if ( checkValid=="true" || checkValid=="TRUE" ) {
6909 ToCheck= Standard_False;
6913 std::cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6916 Standard_Boolean IsValid = Standard_True;
6918 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6923 //===============================================================================
6924 // TDraft : test draft, uses AIS Viewer
6925 // Solid Face Plane Angle Reverse
6926 //===============================================================================
6927 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6929 if (argc < 5) return 1;
6930 // argv[1] - TopoDS_Shape Solid
6931 // argv[2] - TopoDS_Shape Face
6932 // argv[3] - TopoDS_Shape Plane
6933 // argv[4] - Standard_Real Angle
6934 // argv[5] - Standard_Integer Reverse
6936 // Sprintf(prefix, argv[1]);
6937 Standard_Real anAngle = 0;
6938 Standard_Boolean Rev = Standard_False;
6939 Standard_Integer rev = 0;
6940 TopoDS_Shape Solid = DBRep::Get (argv[1]);
6941 TopoDS_Shape face = DBRep::Get (argv[2]);
6942 TopoDS_Face Face = TopoDS::Face(face);
6943 TopoDS_Shape Plane = DBRep::Get (argv[3]);
6944 if (Plane.IsNull ()) {
6945 di << "TEST : Plane is NULL\n";
6948 anAngle = Draw::Atof(argv[4]);
6949 anAngle = 2*M_PI * anAngle / 360.0;
6951 Handle( Geom_Surface )aSurf;
6952 AIS_KindOfSurface aSurfType;
6953 Standard_Real Offset;
6955 if(argc > 4) { // == 5
6956 rev = Draw::Atoi(argv[5]);
6957 Rev = (rev)? Standard_True : Standard_False;
6960 TopoDS_Face face2 = TopoDS::Face(Plane);
6961 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6963 di << "TEST : Can't find plane\n";
6967 aDir = aPln.Axis().Direction();
6970 if (Plane.Orientation() == TopAbs_REVERSED)
6972 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6974 BRepOffsetAPI_DraftAngle Draft (Solid);
6976 if(Abs(anAngle)< Precision::Angular()) {
6977 di << "TEST : NULL angle\n";
6980 if(Rev) anAngle = - anAngle;
6981 Draft.Add (Face, aDir, anAngle, aPln);
6983 if (!Draft.IsDone()) {
6984 di << "TEST : Draft Not DONE \n";
6987 TopTools_ListOfShape Larg;
6989 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6990 di << "TEST : DesignAlgo returns Not valid\n";
6994 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6995 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6997 if ( !ais.IsNull() ) {
6998 ais->SetColor(DEFAULT_COLOR);
6999 ais->SetMaterial(DEFAULT_MATERIAL);
7000 // Display the AIS_Shape without redraw
7001 Ctx->Display(ais, Standard_False);
7003 const char *Name = "draft1";
7004 Handle(AIS_InteractiveObject) an_object;
7005 if (GetMapOfAIS().Find2(Name, an_object))
7007 if (!an_object.IsNull())
7009 Ctx->Remove (an_object, Standard_True);
7011 GetMapOfAIS().UnBind2 (Name);
7013 GetMapOfAIS().Bind(ais, Name);
7014 // DBRep::Set("draft", ais->Shape());
7016 Ctx->Display(ais, Standard_True);
7020 //==============================================================================
7021 //function : splitParameter
7022 //purpose : Split parameter string to parameter name and parameter value
7023 //==============================================================================
7024 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
7025 TCollection_AsciiString& theName,
7026 TCollection_AsciiString& theValue)
7028 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
7030 if (aParamNameEnd == 0)
7032 return Standard_False;
7035 TCollection_AsciiString aString (theString);
7036 if (aParamNameEnd != 0)
7038 theValue = aString.Split (aParamNameEnd);
7039 aString.Split (aString.Length() - 1);
7043 return Standard_True;
7046 //============================================================================
7048 //============================================================================
7049 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
7052 DrawTrSurf::BasicCommands(theCommands);
7053 const char* group = "Check Features Operations commands";
7055 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
7057 &TDraft,group); //Draft_Modification
7060 //==============================================================================
7061 // ViewerTest::Factory
7062 //==============================================================================
7063 void ViewerTest::Factory(Draw_Interpretor& theDI)
7065 // definition of Viewer Command
7066 ViewerTest::Commands(theDI);
7069 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
7073 // Declare entry point PLUGINFACTORY