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))
210 const bool hasColorComponentGreaterThanOne = (anIntegerColor.maxComp() > 1);
211 if (anIntegerColor.a() == THE_COLOR_COMPONENT_NOT_PARSED)
213 anIntegerColor.a() = THE_MAX_INTEGER_COLOR_COMPONENT;
216 Graphic3d_Vec4 aRealColor (anIntegerColor);
217 if (hasColorComponentGreaterThanOne)
219 aRealColor /= static_cast<Standard_ShortReal> (THE_MAX_INTEGER_COLOR_COMPONENT);
221 theColor = Quantity_ColorRGBA (aRealColor);
225 //! Parses an array of strings and get a real color (only values within range 0.0 .. 1.0 are allowed)
226 //! @param theNumberOfColorComponents the number of color components
227 //! @param theColorComponentStrings the array of strings representing color components
228 //! @param theColor a color that is a result of parsing
229 //! @return true if parsing was successful, or false otherwise
230 static bool parseRealColor (Standard_Integer& theNumberOfColorComponents,
231 const char* const* const theColorComponentStrings,
232 Quantity_ColorRGBA& theColor)
234 Graphic3d_Vec4 aRealColor (THE_MAX_REAL_COLOR_COMPONENT);
235 if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, aRealColor))
239 theColor = Quantity_ColorRGBA (aRealColor);
245 //=======================================================================
246 // function : GetColorFromName
247 // purpose : get the Quantity_NameOfColor from a string
248 //=======================================================================
250 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
252 Quantity_NameOfColor aColor = DEFAULT_COLOR;
253 Quantity_Color::ColorFromName (theName, aColor);
257 //=======================================================================
258 // function : parseColor
260 //=======================================================================
261 Standard_Integer ViewerTest::parseColor (const Standard_Integer theArgNb,
262 const char* const* const theArgVec,
263 Quantity_ColorRGBA& theColor,
264 const bool theToParseAlpha)
266 if ((theArgNb >= 1) && Quantity_ColorRGBA::ColorFromHex (theArgVec[0], theColor, !theToParseAlpha))
270 if (theArgNb >= 1 && Quantity_ColorRGBA::ColorFromName (theArgVec[0], theColor))
272 if (theArgNb >= 2 && theToParseAlpha)
274 const Standard_CString anAlphaStr = theArgVec[1];
275 Standard_ShortReal anAlphaComponent;
276 if (parseColorComponent (anAlphaStr, anAlphaComponent))
278 theColor.SetAlpha (anAlphaComponent);
286 const Standard_Integer aNumberOfColorComponentsToParse = Min (theArgNb, theToParseAlpha ? 4 : 3);
287 Standard_Integer aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
288 if (parseIntegerColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
290 return aNumberOfColorComponentsParsed;
292 if (parseRealColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
294 return aNumberOfColorComponentsParsed;
301 //=======================================================================
302 //function : ParseOnOff
304 //=======================================================================
305 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
306 Standard_Boolean& theIsOn)
308 TCollection_AsciiString aFlag(theArg);
313 theIsOn = Standard_True;
314 return Standard_True;
316 else if (aFlag == "off"
319 theIsOn = Standard_False;
320 return Standard_True;
322 return Standard_False;
325 //=======================================================================
326 //function : GetSelectedShapes
328 //=======================================================================
329 void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
331 for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
333 TopoDS_Shape aShape = GetAISContext()->SelectedShape();
334 if (!aShape.IsNull())
336 theSelectedShapes.Append (aShape);
341 //=======================================================================
342 //function : ParseLineType
344 //=======================================================================
345 Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
346 Aspect_TypeOfLine& theType)
348 TCollection_AsciiString aTypeStr (theArg);
349 aTypeStr.LowerCase();
350 if (aTypeStr == "empty")
352 theType = Aspect_TOL_EMPTY;
354 else if (aTypeStr == "solid")
356 theType = Aspect_TOL_SOLID;
358 else if (aTypeStr == "dot")
360 theType = Aspect_TOL_DOT;
362 else if (aTypeStr == "dash")
364 theType = Aspect_TOL_DASH;
366 else if (aTypeStr == "dotdash")
368 theType = Aspect_TOL_DOTDASH;
370 else if (aTypeStr.IsIntegerValue())
372 const int aTypeInt = aTypeStr.IntegerValue();
373 if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
375 return Standard_False;
377 theType = (Aspect_TypeOfLine )aTypeInt;
381 return Standard_False;
383 return Standard_True;
386 //=======================================================================
387 //function : ParseMarkerType
389 //=======================================================================
390 Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
391 Aspect_TypeOfMarker& theType,
392 Handle(Image_PixMap)& theImage)
395 TCollection_AsciiString aTypeStr (theArg);
396 aTypeStr.LowerCase();
397 if (aTypeStr == "empty")
399 theType = Aspect_TOM_EMPTY;
401 else if (aTypeStr == "point"
405 theType = Aspect_TOM_POINT;
407 else if (aTypeStr == "plus"
410 theType = Aspect_TOM_PLUS;
412 else if (aTypeStr == "star"
415 theType = Aspect_TOM_STAR;
417 else if (aTypeStr == "cross"
420 theType = Aspect_TOM_X;
422 else if (aTypeStr == "circle"
425 theType = Aspect_TOM_O;
427 else if (aTypeStr == "pointincircle")
429 theType = Aspect_TOM_O_POINT;
431 else if (aTypeStr == "plusincircle")
433 theType = Aspect_TOM_O_PLUS;
435 else if (aTypeStr == "starincircle")
437 theType = Aspect_TOM_O_STAR;
439 else if (aTypeStr == "crossincircle"
440 || aTypeStr == "xcircle")
442 theType = Aspect_TOM_O_X;
444 else if (aTypeStr == "ring1")
446 theType = Aspect_TOM_RING1;
448 else if (aTypeStr == "ring2")
450 theType = Aspect_TOM_RING2;
452 else if (aTypeStr == "ring"
453 || aTypeStr == "ring3")
455 theType = Aspect_TOM_RING3;
457 else if (aTypeStr == "ball")
459 theType = Aspect_TOM_BALL;
461 else if (aTypeStr.IsIntegerValue())
463 const int aTypeInt = aTypeStr.IntegerValue();
464 if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED)
466 return Standard_False;
468 theType = (Aspect_TypeOfMarker )aTypeInt;
472 theType = Aspect_TOM_USERDEFINED;
473 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
474 if (!anImage->Load (theArg))
476 return Standard_False;
478 if (anImage->Format() == Image_Format_Gray)
480 anImage->SetFormat (Image_Format_Alpha);
482 else if (anImage->Format() == Image_Format_GrayF)
484 anImage->SetFormat (Image_Format_AlphaF);
488 return Standard_True;
491 //=======================================================================
492 //function : ParseShadingModel
494 //=======================================================================
495 Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg,
496 Graphic3d_TypeOfShadingModel& theModel)
498 TCollection_AsciiString aTypeStr (theArg);
499 aTypeStr.LowerCase();
500 if (aTypeStr == "unlit"
501 || aTypeStr == "color"
502 || aTypeStr == "none")
504 theModel = Graphic3d_TOSM_UNLIT;
506 else if (aTypeStr == "flat"
507 || aTypeStr == "facet")
509 theModel = Graphic3d_TOSM_FACET;
511 else if (aTypeStr == "gouraud"
512 || aTypeStr == "vertex"
513 || aTypeStr == "vert")
515 theModel = Graphic3d_TOSM_VERTEX;
517 else if (aTypeStr == "phong"
518 || aTypeStr == "fragment"
519 || aTypeStr == "frag"
520 || aTypeStr == "pixel")
522 theModel = Graphic3d_TOSM_FRAGMENT;
524 else if (aTypeStr == "default"
525 || aTypeStr == "def")
527 theModel = Graphic3d_TOSM_DEFAULT;
529 else if (aTypeStr.IsIntegerValue())
531 const int aTypeInt = aTypeStr.IntegerValue();
532 if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
534 return Standard_False;
536 theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
540 return Standard_False;
542 return Standard_True;
545 //=======================================================================
546 //function : parseZLayer
548 //=======================================================================
549 Standard_Boolean ViewerTest::parseZLayer (Standard_CString theArg,
550 Standard_Boolean theToAllowInteger,
551 Graphic3d_ZLayerId& theLayer)
553 TCollection_AsciiString aName (theArg);
555 if (aName == "default"
558 theLayer = Graphic3d_ZLayerId_Default;
560 else if (aName == "top")
562 theLayer = Graphic3d_ZLayerId_Top;
564 else if (aName == "topmost")
566 theLayer = Graphic3d_ZLayerId_Topmost;
568 else if (aName == "overlay"
569 || aName == "toposd")
571 theLayer = Graphic3d_ZLayerId_TopOSD;
573 else if (aName == "underlay"
574 || aName == "botosd")
576 theLayer = Graphic3d_ZLayerId_BotOSD;
578 else if (aName == "undefined")
580 theLayer = Graphic3d_ZLayerId_UNKNOWN;
582 else if (!GetAISContext().IsNull())
584 const Handle(V3d_Viewer)& aViewer = ViewerTest::GetAISContext()->CurrentViewer();
585 TColStd_SequenceOfInteger aLayers;
586 aViewer->GetAllZLayers (aLayers);
587 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
589 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
590 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aName, Standard_False))
592 theLayer = aLayeriter.Value();
597 if (!theToAllowInteger
598 || !aName.IsIntegerValue())
602 Graphic3d_ZLayerId aLayer = aName.IntegerValue();
603 if (aLayer == Graphic3d_ZLayerId_UNKNOWN
604 || std::find (aLayers.begin(), aLayers.end(), aLayer) != aLayers.end())
614 //=======================================================================
615 //function : GetTypeNames
617 //=======================================================================
618 static const char** GetTypeNames()
620 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
621 "Shape","ConnectedShape","MultiConn.Shape",
622 "ConnectedInter.","MultiConn.",
623 "Constraint","Dimension"};
624 static const char** ThePointer = names;
628 //=======================================================================
629 //function : GetTypeAndSignfromString
631 //=======================================================================
632 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
634 const char ** thefullnames = GetTypeNames();
635 Standard_Integer index(-1);
637 for(Standard_Integer i=0;i<=13 && index==-1;i++)
638 if(!strcasecmp(name,thefullnames[i]))
642 TheType = AIS_KOI_None;
648 TheType = AIS_KOI_Datum;
652 TheType = AIS_KOI_Shape;
656 TheType = AIS_KOI_Object;
660 TheType = AIS_KOI_Relation;
669 #include <Draw_Interpretor.hxx>
671 #include <Draw_Appli.hxx>
675 #include <TCollection_AsciiString.hxx>
676 #include <V3d_Viewer.hxx>
677 #include <V3d_View.hxx>
680 #include <AIS_InteractiveContext.hxx>
681 #include <AIS_Shape.hxx>
682 #include <AIS_DisplayMode.hxx>
683 #include <TColStd_MapOfInteger.hxx>
684 #include <AIS_MapOfInteractive.hxx>
685 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
686 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
687 #include <ViewerTest_EventManager.hxx>
689 #include <TopoDS_Solid.hxx>
690 #include <BRepTools.hxx>
691 #include <BRep_Builder.hxx>
692 #include <TopAbs_ShapeEnum.hxx>
694 #include <TopoDS.hxx>
695 #include <BRep_Tool.hxx>
698 #include <Draw_Window.hxx>
699 #include <AIS_ListIteratorOfListOfInteractive.hxx>
700 #include <AIS_ListOfInteractive.hxx>
701 #include <AIS_DisplayMode.hxx>
702 #include <TopTools_ListOfShape.hxx>
703 #include <BRepOffsetAPI_MakeThickSolid.hxx>
705 //==============================================================================
706 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
707 //==============================================================================
708 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
709 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
713 //=======================================================================
716 //=======================================================================
717 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
718 const Handle(AIS_InteractiveObject)& theObject,
719 const Standard_Boolean theToUpdate,
720 const Standard_Boolean theReplaceIfExists)
722 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
723 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
726 std::cout << "Error: AIS context is not available.\n";
727 return Standard_False;
730 if (aMap.IsBound2 (theName))
732 if (!theReplaceIfExists)
734 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
735 << "Please use another name.\n";
736 return Standard_False;
739 if (Handle(AIS_InteractiveObject) anOldObj = aMap.Find2 (theName))
741 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
743 aMap.UnBind2 (theName);
746 if (theObject.IsNull())
748 // object with specified name has been already unbound
749 return Standard_True;
752 // unbind AIS object if it was bound with another name
753 aMap.UnBind1 (theObject);
755 // can be registered without rebinding
756 aMap.Bind (theObject, theName);
757 aCtx->Display (theObject, theToUpdate);
758 return Standard_True;
761 //! Alias for ViewerTest::Display(), compatibility with old code.
762 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
763 const Handle(AIS_InteractiveObject)& theObject,
764 Standard_Boolean theReplaceIfExists = Standard_True)
766 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
769 static NCollection_List<Handle(ViewerTest_EventManager)> theEventMgrs;
771 static Handle(V3d_View)& a3DView()
773 static Handle(V3d_View) Viou;
778 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
779 static Handle(AIS_InteractiveContext) aContext;
783 const Handle(V3d_View)& ViewerTest::CurrentView()
787 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
792 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
794 return TheAISContext();
797 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
799 TheAISContext() = aCtx;
800 ViewerTest::ResetEventManager();
803 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
805 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
808 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
810 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
814 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
815 theEventMgrs.Prepend(EM);
818 void ViewerTest::UnsetEventManager()
820 theEventMgrs.RemoveFirst();
824 void ViewerTest::ResetEventManager()
826 theEventMgrs.Clear();
827 theEventMgrs.Prepend (new ViewerTest_EventManager (ViewerTest::CurrentView(), ViewerTest::GetAISContext()));
830 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
832 return !theEventMgrs.IsEmpty()
833 ? theEventMgrs.First()
834 : Handle(ViewerTest_EventManager)();
837 //=======================================================================
838 //function : Get Context and active view
840 //=======================================================================
841 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
842 Handle(V3d_View)& theView)
844 theCtx = ViewerTest::GetAISContext();
845 theView = ViewerTest::CurrentView();
849 std::cout << "Error: cannot find an active view!\n";
850 return Standard_False;
852 return Standard_True;
855 //==============================================================================
857 //purpose : Remove all the object from the viewer
858 //==============================================================================
859 void ViewerTest::Clear()
861 if (a3DView().IsNull())
866 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
867 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
869 const Handle(AIS_InteractiveObject) anObj = anObjIter.Key1();
870 if (anObj->GetContext() != TheAISContext())
875 std::cout << "Remove " << anObjIter.Key2() << std::endl;
876 TheAISContext()->Remove (anObj, Standard_False);
877 aListRemoved.Append (anObj);
880 TheAISContext()->RebuildSelectionStructs();
881 TheAISContext()->UpdateCurrentViewer();
882 if (aListRemoved.Size() == GetMapOfAIS().Extent())
884 GetMapOfAIS().Clear();
888 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
890 GetMapOfAIS().UnBind1 (anObjIter.Value());
895 //==============================================================================
896 //function : CopyIsoAspect
897 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
898 //==============================================================================
899 static Handle(Prs3d_IsoAspect) CopyIsoAspect
900 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
901 const Standard_Integer theNbIsos)
903 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
904 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
905 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
907 Handle(Prs3d_IsoAspect) aResult =
908 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
913 //==============================================================================
915 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
916 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
917 //==============================================================================
918 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
920 if (TheAISContext().IsNull()) {
921 di << argv[0] << " Call 'vinit' before!\n";
926 di << "Current number of isos : " <<
927 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
928 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
929 di << "IsoOnPlane mode is " <<
930 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
931 di << "IsoOnTriangulation mode is " <<
932 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
936 Standard_Integer aLastInd = argc - 1;
937 Standard_Boolean isChanged = Standard_False;
938 Standard_Integer aNbUIsos = 0;
939 Standard_Integer aNbVIsos = 0;
942 Standard_Boolean isIsoOnPlane = Standard_False;
944 if (strcmp(argv[aLastInd], "1") == 0) {
945 isIsoOnPlane = Standard_True;
946 isChanged = Standard_True;
947 } else if (strcmp(argv[aLastInd], "0") == 0) {
948 isIsoOnPlane = Standard_False;
949 isChanged = Standard_True;
953 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
954 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
957 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
958 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
960 TheAISContext()->IsoOnPlane(isIsoOnPlane);
963 // If there are no shapes provided set the default numbers.
964 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
965 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
972 for (i = 1; i <= aLastInd; i++)
974 TCollection_AsciiString name(argv[i]);
975 Handle(AIS_InteractiveObject) aShape;
976 GetMapOfAIS().Find2(name, aShape);
979 std::cout << "Syntax error: object '" << name << "' is not found\n";
983 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
984 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
985 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
988 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
989 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
990 TheAISContext()->SetLocalAttributes (aShape, CurDrawer, Standard_False);
991 TheAISContext()->Redisplay (aShape, Standard_False);
995 di << "Number of isos for " << argv[i] << " : "
996 << aUIso->Number() << " " << aVIso->Number() << "\n";
1001 TheAISContext()->UpdateCurrentViewer();
1007 static Standard_Integer VDispSensi (Draw_Interpretor& ,
1008 Standard_Integer theArgNb,
1013 std::cout << "Error: wrong syntax!\n";
1017 Handle(AIS_InteractiveContext) aCtx;
1018 Handle(V3d_View) aView;
1019 if (!getCtxAndView (aCtx, aView))
1024 aCtx->DisplayActiveSensitive (aView);
1029 static Standard_Integer VClearSensi (Draw_Interpretor& ,
1030 Standard_Integer theArgNb,
1035 std::cout << "Error: wrong syntax!\n";
1039 Handle(AIS_InteractiveContext) aCtx;
1040 Handle(V3d_View) aView;
1041 if (!getCtxAndView (aCtx, aView))
1045 aCtx->ClearActiveSensitive (aView);
1049 //==============================================================================
1051 //purpose : To list the displayed object with their attributes
1052 //==============================================================================
1053 static int VDir (Draw_Interpretor& theDI,
1054 Standard_Integer theNbArgs,
1055 const char** theArgVec)
1057 TCollection_AsciiString aMatch;
1058 Standard_Boolean toFormat = Standard_False;
1059 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
1061 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
1062 anArgCase.LowerCase();
1063 if (anArgCase == "-list"
1064 || anArgCase == "-format")
1066 toFormat = Standard_True;
1068 else if (aMatch.IsEmpty())
1070 aMatch = theArgVec[anArgIter];
1074 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
1079 TCollection_AsciiString aRes;
1080 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
1082 if (!aMatch.IsEmpty())
1084 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aMatch + "' '" + anIter.Key2() + "'";
1085 if (theDI.Eval (aCheck.ToCString()) == 0
1086 && *theDI.Result() != '1')
1094 aRes += TCollection_AsciiString("\t") + anIter.Key2() + "\n";
1098 aRes += anIter.Key2() + " ";
1106 //! Auxiliary enumeration
1107 enum ViewerTest_StereoPair
1109 ViewerTest_SP_Single,
1110 ViewerTest_SP_SideBySide,
1111 ViewerTest_SP_OverUnder
1114 //==============================================================================
1116 //purpose : To dump the active view snapshot to image file
1117 //==============================================================================
1118 static Standard_Integer VDump (Draw_Interpretor& theDI,
1119 Standard_Integer theArgNb,
1120 Standard_CString* theArgVec)
1124 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
1128 Standard_Integer anArgIter = 1;
1129 Standard_CString aFilePath = theArgVec[anArgIter++];
1130 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
1131 V3d_ImageDumpOptions aParams;
1132 aParams.BufferType = Graphic3d_BT_RGB;
1133 aParams.StereoOptions = V3d_SDO_MONO;
1134 for (; anArgIter < theArgNb; ++anArgIter)
1136 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1138 if (anArg == "-buffer")
1140 if (++anArgIter >= theArgNb)
1142 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
1146 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
1147 aBufArg.LowerCase();
1148 if (aBufArg == "rgba")
1150 aParams.BufferType = Graphic3d_BT_RGBA;
1152 else if (aBufArg == "rgb")
1154 aParams.BufferType = Graphic3d_BT_RGB;
1156 else if (aBufArg == "depth")
1158 aParams.BufferType = Graphic3d_BT_Depth;
1162 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
1166 else if (anArg == "-stereo")
1168 if (++anArgIter >= theArgNb)
1170 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
1174 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
1175 aStereoArg.LowerCase();
1176 if (aStereoArg == "l"
1177 || aStereoArg == "left")
1179 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1181 else if (aStereoArg == "r"
1182 || aStereoArg == "right")
1184 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1186 else if (aStereoArg == "mono")
1188 aParams.StereoOptions = V3d_SDO_MONO;
1190 else if (aStereoArg == "blended"
1191 || aStereoArg == "blend"
1192 || aStereoArg == "stereo")
1194 aParams.StereoOptions = V3d_SDO_BLENDED;
1196 else if (aStereoArg == "sbs"
1197 || aStereoArg == "sidebyside")
1199 aStereoPair = ViewerTest_SP_SideBySide;
1201 else if (aStereoArg == "ou"
1202 || aStereoArg == "overunder")
1204 aStereoPair = ViewerTest_SP_OverUnder;
1208 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
1212 else if (anArg == "-rgba"
1215 aParams.BufferType = Graphic3d_BT_RGBA;
1217 else if (anArg == "-rgb"
1220 aParams.BufferType = Graphic3d_BT_RGB;
1222 else if (anArg == "-depth"
1223 || anArg == "depth")
1225 aParams.BufferType = Graphic3d_BT_Depth;
1227 else if (anArg == "-width"
1229 || anArg == "sizex")
1231 if (aParams.Width != 0)
1233 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1236 else if (++anArgIter >= theArgNb)
1238 std::cout << "Error: integer value is expected right after 'width'\n";
1241 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1243 else if (anArg == "-height"
1244 || anArg == "height"
1245 || anArg == "-sizey")
1247 if (aParams.Height != 0)
1249 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1252 else if (++anArgIter >= theArgNb)
1254 std::cout << "Error: integer value is expected right after 'height'\n";
1257 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1259 else if (anArg == "-tile"
1260 || anArg == "-tilesize")
1262 if (++anArgIter >= theArgNb)
1264 std::cout << "Error: integer value is expected right after 'tileSize'\n";
1267 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1271 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
1275 if ((aParams.Width <= 0 && aParams.Height > 0)
1276 || (aParams.Width > 0 && aParams.Height <= 0))
1278 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
1282 Handle(V3d_View) aView = ViewerTest::CurrentView();
1285 std::cout << "Error: cannot find an active view!\n";
1289 if (aParams.Width <= 0 || aParams.Height <= 0)
1291 aView->Window()->Size (aParams.Width, aParams.Height);
1294 Image_AlienPixMap aPixMap;
1295 Image_Format aFormat = Image_Format_UNKNOWN;
1296 switch (aParams.BufferType)
1298 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1299 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1300 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1301 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1304 switch (aStereoPair)
1306 case ViewerTest_SP_Single:
1308 if (!aView->ToPixMap (aPixMap, aParams))
1310 theDI << "Fail: view dump failed!\n";
1313 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1314 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1316 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1317 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1321 case ViewerTest_SP_SideBySide:
1323 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1325 theDI << "Fail: not enough memory for image allocation!\n";
1329 Image_PixMap aPixMapL, aPixMapR;
1330 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1331 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1332 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1333 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1335 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1336 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1337 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1338 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1341 theDI << "Fail: view dump failed!\n";
1346 case ViewerTest_SP_OverUnder:
1348 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1350 theDI << "Fail: not enough memory for image allocation!\n";
1354 Image_PixMap aPixMapL, aPixMapR;
1355 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1356 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1357 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1358 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1360 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1361 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1362 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1363 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1366 theDI << "Fail: view dump failed!\n";
1373 if (!aPixMap.Save (aFilePath))
1375 theDI << "Fail: image can not be saved!\n";
1380 enum TypeOfDispOperation
1382 TypeOfDispOperation_SetDispMode,
1383 TypeOfDispOperation_UnsetDispMode
1386 //! Displays,Erase...
1387 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1388 const Standard_Integer theMode,
1389 const TypeOfDispOperation theType,
1390 const Standard_Boolean theToUpdate)
1392 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1395 case TypeOfDispOperation_SetDispMode:
1397 if (!thePrs.IsNull())
1399 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1403 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1407 case TypeOfDispOperation_UnsetDispMode:
1409 if (!thePrs.IsNull())
1411 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1415 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1422 //=======================================================================
1425 //=======================================================================
1426 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1431 std::cout << "Syntax error: wrong number of arguments\n";
1435 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1436 ? TypeOfDispOperation_UnsetDispMode
1437 : TypeOfDispOperation_SetDispMode;
1438 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1439 if (aType == TypeOfDispOperation_UnsetDispMode)
1443 if (aCtx->NbSelected() == 0)
1445 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1449 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1451 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1454 aCtx->UpdateCurrentViewer();
1458 TCollection_AsciiString aName = argv[1];
1459 Handle(AIS_InteractiveObject) aPrs;
1460 if (GetMapOfAIS().Find2 (aName, aPrs)
1463 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1469 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1470 if (aCtx->NbSelected() == 0
1471 && aType == TypeOfDispOperation_SetDispMode)
1473 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1475 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1477 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1479 aCtx->UpdateCurrentViewer();
1483 Handle(AIS_InteractiveObject) aPrs;
1484 TCollection_AsciiString aName (argv[1]);
1485 if (GetMapOfAIS().Find2 (aName, aPrs)
1488 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1495 //=======================================================================
1498 //=======================================================================
1499 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1501 if(argc==1) return 1;
1502 Standard_Integer On = Draw::Atoi(argv[1]);
1503 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1507 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1508 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1509 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1513 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1517 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1521 Ctx->UpdateCurrentViewer();
1524 Handle(AIS_InteractiveObject) IO;
1525 TCollection_AsciiString name = argv[2];
1526 if (GetMapOfAIS().Find2 (name, IO)
1530 Ctx->SubIntensityOn(IO, Standard_True);
1532 Ctx->SubIntensityOff(IO, Standard_True);
1539 //! Auxiliary class to iterate presentations from different collections.
1540 class ViewTest_PrsIter
1544 //! Create and initialize iterator object.
1545 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1546 : mySource (IterSource_All)
1548 NCollection_Sequence<TCollection_AsciiString> aNames;
1549 if (!theName.IsEmpty())
1550 aNames.Append (theName);
1554 //! Create and initialize iterator object.
1555 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1556 : mySource (IterSource_All)
1561 //! Initialize the iterator.
1562 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1564 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1566 mySelIter.Nullify();
1567 myCurrent.Nullify();
1568 myCurrentTrs.Nullify();
1569 if (!mySeq.IsEmpty())
1571 mySource = IterSource_List;
1572 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1574 else if (aCtx->NbSelected() > 0)
1576 mySource = IterSource_Selected;
1578 mySelIter->InitSelected();
1582 mySource = IterSource_All;
1583 myMapIter.Initialize (GetMapOfAIS());
1588 const TCollection_AsciiString& CurrentName() const
1590 return myCurrentName;
1593 const Handle(AIS_InteractiveObject)& Current() const
1598 const Handle(Standard_Transient)& CurrentTrs() const
1600 return myCurrentTrs;
1603 //! @return true if iterator points to valid object within collection
1604 Standard_Boolean More() const
1608 case IterSource_All: return myMapIter.More();
1609 case IterSource_List: return mySeqIter.More();
1610 case IterSource_Selected: return mySelIter->MoreSelected();
1612 return Standard_False;
1615 //! Go to the next item.
1618 myCurrentName.Clear();
1619 myCurrentTrs.Nullify();
1620 myCurrent.Nullify();
1623 case IterSource_All:
1628 case IterSource_List:
1633 case IterSource_Selected:
1635 mySelIter->NextSelected();
1648 case IterSource_All:
1650 if (myMapIter.More())
1652 myCurrentName = myMapIter.Key2();
1653 myCurrentTrs = myMapIter.Key1();
1654 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1658 case IterSource_List:
1660 if (mySeqIter.More())
1662 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1664 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1667 myCurrentName = mySeqIter.Value();
1668 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1669 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1673 case IterSource_Selected:
1675 if (mySelIter->MoreSelected())
1677 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1678 myCurrent = mySelIter->SelectedInteractive();
1696 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1697 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1698 NCollection_Sequence<TCollection_AsciiString> mySeq;
1699 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1701 TCollection_AsciiString myCurrentName;//!< current item name
1702 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1703 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1705 IterSource mySource; //!< iterated collection
1709 //! Parse interior style name.
1710 static bool parseInteriorStyle (const TCollection_AsciiString& theArg,
1711 Aspect_InteriorStyle& theStyle)
1713 TCollection_AsciiString anArg (theArg);
1715 if (anArg == "empty")
1717 theStyle = Aspect_IS_EMPTY;
1719 else if (anArg == "hollow")
1721 theStyle = Aspect_IS_HOLLOW;
1723 else if (anArg == "solid")
1725 theStyle = Aspect_IS_SOLID;
1727 else if (anArg == "hatch")
1729 theStyle = Aspect_IS_HATCH;
1731 else if (anArg == "hiddenline"
1732 || anArg == "hidden-line"
1733 || anArg == "hidden_line")
1735 theStyle = Aspect_IS_HIDDENLINE;
1737 else if (anArg == "point")
1739 theStyle = Aspect_IS_POINT;
1741 else if (theArg.IsIntegerValue())
1743 const Standard_Integer anIntStyle = theArg.IntegerValue();
1744 if (anIntStyle < Aspect_IS_EMPTY || anIntStyle > Aspect_IS_POINT)
1748 theStyle = (Aspect_InteriorStyle)anIntStyle;
1757 //! Auxiliary structure for VAspects
1758 struct ViewerTest_AspectsChangeSet
1760 Standard_Integer ToSetVisibility;
1761 Standard_Integer Visibility;
1763 Standard_Integer ToSetColor;
1764 Quantity_Color Color;
1765 Standard_Integer ToSetBackFaceColor;
1766 Quantity_Color BackFaceColor;
1768 Standard_Integer ToSetLineWidth;
1769 Standard_Real LineWidth;
1771 Standard_Integer ToSetTypeOfLine;
1772 Aspect_TypeOfLine TypeOfLine;
1774 Standard_Integer ToSetTypeOfMarker;
1775 Aspect_TypeOfMarker TypeOfMarker;
1776 Handle(Image_PixMap) MarkerImage;
1778 Standard_Integer ToSetMarkerSize;
1779 Standard_Real MarkerSize;
1781 Standard_Integer ToSetTransparency;
1782 Standard_Real Transparency;
1784 Standard_Integer ToSetAlphaMode;
1785 Graphic3d_AlphaMode AlphaMode;
1786 Standard_ShortReal AlphaCutoff;
1788 Standard_Integer ToSetMaterial;
1789 Graphic3d_NameOfMaterial Material;
1790 TCollection_AsciiString MatName;
1792 NCollection_Sequence<TopoDS_Shape> SubShapes;
1794 Standard_Integer ToSetShowFreeBoundary;
1795 Standard_Integer ToSetFreeBoundaryWidth;
1796 Standard_Real FreeBoundaryWidth;
1797 Standard_Integer ToSetFreeBoundaryColor;
1798 Quantity_Color FreeBoundaryColor;
1800 Standard_Integer ToEnableIsoOnTriangulation;
1802 Standard_Integer ToSetFaceBoundaryDraw;
1803 Standard_Integer ToSetFaceBoundaryUpperContinuity;
1804 GeomAbs_Shape FaceBoundaryUpperContinuity;
1806 Standard_Integer ToSetFaceBoundaryColor;
1807 Quantity_Color FaceBoundaryColor;
1809 Standard_Integer ToSetFaceBoundaryWidth;
1810 Standard_Real FaceBoundaryWidth;
1812 Standard_Integer ToSetTypeOfFaceBoundaryLine;
1813 Aspect_TypeOfLine TypeOfFaceBoundaryLine;
1815 Standard_Integer ToSetMaxParamValue;
1816 Standard_Real MaxParamValue;
1818 Standard_Integer ToSetSensitivity;
1819 Standard_Integer SelectionMode;
1820 Standard_Integer Sensitivity;
1822 Standard_Integer ToSetHatch;
1823 Standard_Integer StdHatchStyle;
1824 TCollection_AsciiString PathToHatchPattern;
1826 Standard_Integer ToSetShadingModel;
1827 Graphic3d_TypeOfShadingModel ShadingModel;
1828 TCollection_AsciiString ShadingModelName;
1830 Standard_Integer ToSetInterior;
1831 Aspect_InteriorStyle InteriorStyle;
1833 Standard_Integer ToSetDrawSilhouette;
1835 Standard_Integer ToSetDrawEdges;
1836 Standard_Integer ToSetQuadEdges;
1838 Standard_Integer ToSetEdgeColor;
1839 Quantity_ColorRGBA EdgeColor;
1841 Standard_Integer ToSetEdgeWidth;
1842 Standard_Real EdgeWidth;
1844 Standard_Integer ToSetTypeOfEdge;
1845 Aspect_TypeOfLine TypeOfEdge;
1847 //! Empty constructor
1848 ViewerTest_AspectsChangeSet()
1849 : ToSetVisibility (0),
1852 Color (DEFAULT_COLOR),
1853 ToSetBackFaceColor(0),
1854 BackFaceColor (DEFAULT_COLOR),
1857 ToSetTypeOfLine (0),
1858 TypeOfLine (Aspect_TOL_SOLID),
1859 ToSetTypeOfMarker (0),
1860 TypeOfMarker (Aspect_TOM_PLUS),
1861 ToSetMarkerSize (0),
1863 ToSetTransparency (0),
1866 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1869 Material (Graphic3d_NOM_DEFAULT),
1870 ToSetShowFreeBoundary (0),
1871 ToSetFreeBoundaryWidth (0),
1872 FreeBoundaryWidth (1.0),
1873 ToSetFreeBoundaryColor (0),
1874 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1875 ToEnableIsoOnTriangulation (0),
1877 ToSetFaceBoundaryDraw (0),
1878 ToSetFaceBoundaryUpperContinuity (0),
1879 FaceBoundaryUpperContinuity(GeomAbs_CN),
1880 ToSetFaceBoundaryColor (0),
1881 FaceBoundaryColor (Quantity_NOC_BLACK),
1882 ToSetFaceBoundaryWidth (0),
1883 FaceBoundaryWidth (1.0f),
1884 ToSetTypeOfFaceBoundaryLine(0),
1885 TypeOfFaceBoundaryLine (Aspect_TOL_SOLID),
1887 ToSetMaxParamValue (0),
1888 MaxParamValue (500000),
1889 ToSetSensitivity (0),
1894 ToSetShadingModel (0),
1895 ShadingModel (Graphic3d_TOSM_DEFAULT),
1897 InteriorStyle (Aspect_IS_SOLID),
1898 ToSetDrawSilhouette (0),
1904 ToSetTypeOfEdge (0),
1905 TypeOfEdge (Aspect_TOL_SOLID)
1908 //! @return true if no changes have been requested
1909 Standard_Boolean IsEmpty() const
1911 return ToSetVisibility == 0
1912 && ToSetLineWidth == 0
1913 && ToSetTransparency == 0
1914 && ToSetAlphaMode == 0
1916 && ToSetBackFaceColor == 0
1917 && ToSetMaterial == 0
1918 && ToSetShowFreeBoundary == 0
1919 && ToSetFreeBoundaryColor == 0
1920 && ToSetFreeBoundaryWidth == 0
1921 && ToEnableIsoOnTriangulation == 0
1922 && ToSetFaceBoundaryDraw == 0
1923 && ToSetFaceBoundaryUpperContinuity == 0
1924 && ToSetFaceBoundaryColor == 0
1925 && ToSetFaceBoundaryWidth == 0
1926 && ToSetTypeOfFaceBoundaryLine == 0
1927 && ToSetMaxParamValue == 0
1928 && ToSetSensitivity == 0
1930 && ToSetShadingModel == 0
1931 && ToSetInterior == 0
1932 && ToSetDrawSilhouette == 0
1933 && ToSetDrawEdges == 0
1934 && ToSetQuadEdges == 0
1935 && ToSetEdgeColor == 0
1936 && ToSetEdgeWidth == 0
1937 && ToSetTypeOfEdge == 0;
1940 //! @return true if properties are valid
1941 Standard_Boolean Validate() const
1943 Standard_Boolean isOk = Standard_True;
1944 if (Visibility != 0 && Visibility != 1)
1946 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1947 isOk = Standard_False;
1949 if (LineWidth <= 0.0
1950 || LineWidth > 10.0)
1952 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1953 isOk = Standard_False;
1955 if (Transparency < 0.0
1956 || Transparency > 1.0)
1958 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1959 isOk = Standard_False;
1961 if (ToSetAlphaMode == 1
1962 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1964 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1965 isOk = Standard_False;
1967 if (FreeBoundaryWidth <= 0.0
1968 || FreeBoundaryWidth > 10.0)
1970 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1971 isOk = Standard_False;
1973 if (MaxParamValue < 0.0)
1975 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1976 isOk = Standard_False;
1978 if (Sensitivity <= 0 && ToSetSensitivity)
1980 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1981 isOk = Standard_False;
1983 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1985 std::cout << "Error: hatch style must be specified\n";
1986 isOk = Standard_False;
1988 if (ToSetShadingModel == 1
1989 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
1991 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1992 isOk = Standard_False;
1997 //! Apply aspects to specified drawer.
1998 bool Apply (const Handle(Prs3d_Drawer)& theDrawer)
2000 bool toRecompute = false;
2001 const Handle(Prs3d_Drawer)& aDefDrawer = ViewerTest::GetAISContext()->DefaultDrawer();
2002 if (ToSetShowFreeBoundary != 0)
2004 theDrawer->SetFreeBoundaryDraw (ToSetShowFreeBoundary == 1);
2007 if (ToSetFreeBoundaryWidth != 0)
2009 if (ToSetFreeBoundaryWidth != -1
2010 || theDrawer->HasOwnFreeBoundaryAspect())
2012 if (!theDrawer->HasOwnFreeBoundaryAspect())
2014 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2015 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
2016 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2019 theDrawer->FreeBoundaryAspect()->SetWidth (FreeBoundaryWidth);
2022 if (ToSetFreeBoundaryColor != 0)
2024 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2025 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
2026 aBoundaryAspect->SetColor (FreeBoundaryColor);
2027 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2030 if (ToSetTypeOfLine != 0)
2032 if (ToSetTypeOfLine != -1
2033 || theDrawer->HasOwnLineAspect()
2034 || theDrawer->HasOwnWireAspect()
2035 || theDrawer->HasOwnFreeBoundaryAspect()
2036 || theDrawer->HasOwnUnFreeBoundaryAspect()
2037 || theDrawer->HasOwnSeenLineAspect())
2039 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
2040 theDrawer->LineAspect()->SetTypeOfLine (TypeOfLine);
2041 theDrawer->WireAspect()->SetTypeOfLine (TypeOfLine);
2042 theDrawer->FreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
2043 theDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
2044 theDrawer->SeenLineAspect()->SetTypeOfLine (TypeOfLine);
2047 if (ToSetTypeOfMarker != 0)
2049 if (ToSetTypeOfMarker != -1
2050 || theDrawer->HasOwnPointAspect())
2052 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
2053 theDrawer->PointAspect()->SetTypeOfMarker (TypeOfMarker);
2054 theDrawer->PointAspect()->Aspect()->SetMarkerImage (MarkerImage.IsNull() ? Handle(Graphic3d_MarkerImage)() : new Graphic3d_MarkerImage (MarkerImage));
2057 if (ToSetMarkerSize != 0)
2059 if (ToSetMarkerSize != -1
2060 || theDrawer->HasOwnPointAspect())
2062 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
2063 theDrawer->PointAspect()->SetScale (MarkerSize);
2067 if (ToSetMaxParamValue != 0)
2069 if (ToSetMaxParamValue != -1
2070 || theDrawer->HasOwnMaximalParameterValue())
2072 theDrawer->SetMaximalParameterValue (MaxParamValue);
2076 if (ToSetFaceBoundaryDraw != 0)
2078 if (ToSetFaceBoundaryDraw != -1
2079 || theDrawer->HasOwnFaceBoundaryDraw())
2082 theDrawer->SetFaceBoundaryDraw (ToSetFaceBoundaryDraw == 1);
2085 if (ToSetFaceBoundaryUpperContinuity != 0)
2087 if (ToSetFaceBoundaryUpperContinuity != -1
2088 || theDrawer->HasOwnFaceBoundaryUpperContinuity())
2091 if (ToSetFaceBoundaryUpperContinuity == -1)
2093 theDrawer->UnsetFaceBoundaryUpperContinuity();
2097 theDrawer->SetFaceBoundaryUpperContinuity (FaceBoundaryUpperContinuity);
2101 if (ToSetFaceBoundaryColor != 0)
2103 if (ToSetFaceBoundaryColor != -1
2104 || theDrawer->HasOwnFaceBoundaryAspect())
2106 if (ToSetFaceBoundaryColor == -1)
2109 theDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
2113 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2114 theDrawer->FaceBoundaryAspect()->SetColor (FaceBoundaryColor);
2118 if (ToSetFaceBoundaryWidth != 0)
2120 if (ToSetFaceBoundaryWidth != -1
2121 || theDrawer->HasOwnFaceBoundaryAspect())
2123 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2124 theDrawer->FaceBoundaryAspect()->SetWidth (FaceBoundaryWidth);
2127 if (ToSetTypeOfFaceBoundaryLine != 0)
2129 if (ToSetTypeOfFaceBoundaryLine != -1
2130 || theDrawer->HasOwnFaceBoundaryAspect())
2132 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2133 theDrawer->FaceBoundaryAspect()->SetTypeOfLine (TypeOfFaceBoundaryLine);
2136 if (ToSetShadingModel != 0)
2138 if (ToSetShadingModel != -1
2139 || theDrawer->HasOwnShadingAspect())
2141 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2142 theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel);
2145 if (ToSetBackFaceColor != 0)
2147 if (ToSetBackFaceColor != -1
2148 || theDrawer->HasOwnShadingAspect())
2150 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2151 theDrawer->ShadingAspect()->SetColor (BackFaceColor, Aspect_TOFM_BACK_SIDE);
2154 if (ToSetAlphaMode != 0)
2156 if (ToSetAlphaMode != -1
2157 || theDrawer->HasOwnShadingAspect())
2159 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2160 theDrawer->ShadingAspect()->Aspect()->SetAlphaMode (AlphaMode, AlphaCutoff);
2163 if (ToSetHatch != 0)
2165 if (ToSetHatch != -1
2166 || theDrawer->HasOwnShadingAspect())
2168 theDrawer->SetupOwnShadingAspect (aDefDrawer);
2169 Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect();
2170 if (ToSetHatch == -1)
2172 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2176 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2177 if (!PathToHatchPattern.IsEmpty())
2179 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2180 if (anImage->Load (TCollection_AsciiString (PathToHatchPattern.ToCString())))
2182 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2186 std::cout << "Error: cannot load the following image: " << PathToHatchPattern << "\n";
2189 else if (StdHatchStyle != -1)
2191 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)StdHatchStyle));
2197 if (ToSetInterior != 0)
2199 if (ToSetInterior != -1
2200 || theDrawer->HasOwnShadingAspect())
2202 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2203 theDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (InteriorStyle);
2204 if (InteriorStyle == Aspect_IS_HATCH
2205 && theDrawer->ShadingAspect()->Aspect()->HatchStyle().IsNull())
2207 theDrawer->ShadingAspect()->Aspect()->SetHatchStyle (Aspect_HS_VERTICAL);
2211 if (ToSetDrawSilhouette != 0)
2213 if (ToSetDrawSilhouette != -1
2214 || theDrawer->HasOwnShadingAspect())
2216 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2217 theDrawer->ShadingAspect()->Aspect()->SetDrawSilhouette (ToSetDrawSilhouette == 1);
2220 if (ToSetDrawEdges != 0)
2222 if (ToSetDrawEdges != -1
2223 || theDrawer->HasOwnShadingAspect())
2225 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2226 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetDrawEdges == 1);
2229 if (ToSetQuadEdges != 0)
2231 if (ToSetQuadEdges != -1
2232 || theDrawer->HasOwnShadingAspect())
2234 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2235 theDrawer->ShadingAspect()->Aspect()->SetSkipFirstEdge (ToSetQuadEdges == 1);
2238 if (ToSetEdgeWidth != 0)
2240 if (ToSetEdgeWidth != -1
2241 || theDrawer->HasOwnShadingAspect())
2243 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2244 theDrawer->ShadingAspect()->Aspect()->SetEdgeWidth (EdgeWidth);
2247 if (ToSetTypeOfEdge != 0)
2249 if (ToSetTypeOfEdge != -1
2250 || theDrawer->HasOwnShadingAspect())
2252 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2253 theDrawer->ShadingAspect()->Aspect()->SetEdgeLineType (TypeOfEdge);
2254 if (ToSetInterior == 0)
2256 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetTypeOfEdge == 1
2257 && TypeOfEdge != Aspect_TOL_EMPTY);
2261 if (ToSetEdgeColor != 0)
2263 if (ToSetEdgeColor != -1
2264 || theDrawer->HasOwnShadingAspect())
2266 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2267 if (ToSetEdgeColor == -1)
2269 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (theDrawer->ShadingAspect()->Aspect()->InteriorColor());
2273 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (EdgeColor);
2281 //==============================================================================
2282 //function : VAspects
2284 //==============================================================================
2285 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
2286 Standard_Integer theArgNb,
2287 const char** theArgVec)
2289 TCollection_AsciiString aCmdName (theArgVec[0]);
2290 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2291 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2294 std::cerr << "Error: no active view!\n";
2298 Standard_Integer anArgIter = 1;
2299 Standard_Boolean isDefaults = Standard_False;
2300 NCollection_Sequence<TCollection_AsciiString> aNames;
2301 for (; anArgIter < theArgNb; ++anArgIter)
2303 TCollection_AsciiString anArg = theArgVec[anArgIter];
2304 if (anUpdateTool.parseRedrawMode (anArg))
2308 else if (!anArg.IsEmpty()
2309 && anArg.Value (1) != '-')
2311 aNames.Append (anArg);
2315 if (anArg == "-defaults")
2317 isDefaults = Standard_True;
2324 if (!aNames.IsEmpty() && isDefaults)
2326 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
2330 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
2331 aChanges.Append (ViewerTest_AspectsChangeSet());
2332 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
2334 // parse syntax of legacy commands
2335 bool toParseAliasArgs = false;
2336 if (aCmdName == "vsetwidth")
2338 if (aNames.IsEmpty()
2339 || !aNames.Last().IsRealValue())
2341 std::cout << "Error: not enough arguments!\n";
2344 aChangeSet->ToSetLineWidth = 1;
2345 aChangeSet->LineWidth = aNames.Last().RealValue();
2346 aNames.Remove (aNames.Length());
2348 else if (aCmdName == "vunsetwidth")
2350 aChangeSet->ToSetLineWidth = -1;
2352 else if (aCmdName == "vsetcolor")
2354 if (aNames.IsEmpty())
2356 std::cout << "Error: not enough arguments!\n";
2359 aChangeSet->ToSetColor = 1;
2361 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2362 Standard_Boolean isOk = Standard_False;
2363 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
2365 aChangeSet->Color = aColor;
2366 aNames.Remove (aNames.Length());
2367 isOk = Standard_True;
2369 else if (aNames.Length() >= 3)
2371 const char* anArgVec[3] =
2373 aNames.Value (aNames.Upper() - 2).ToCString(),
2374 aNames.Value (aNames.Upper() - 1).ToCString(),
2375 aNames.Value (aNames.Upper() - 0).ToCString(),
2378 Standard_Integer aNbParsed = ViewerTest::ParseColor (3, anArgVec, aChangeSet->Color);
2379 isOk = aNbParsed == 3;
2380 aNames.Remove (aNames.Length());
2381 aNames.Remove (aNames.Length());
2382 aNames.Remove (aNames.Length());
2386 std::cout << "Error: not enough arguments!\n";
2390 else if (aCmdName == "vunsetcolor")
2392 aChangeSet->ToSetColor = -1;
2394 else if (aCmdName == "vsettransparency")
2396 if (aNames.IsEmpty()
2397 || !aNames.Last().IsRealValue())
2399 std::cout << "Error: not enough arguments!\n";
2402 aChangeSet->ToSetTransparency = 1;
2403 aChangeSet->Transparency = aNames.Last().RealValue();
2404 aNames.Remove (aNames.Length());
2406 else if (aCmdName == "vunsettransparency")
2408 aChangeSet->ToSetTransparency = -1;
2410 else if (aCmdName == "vsetmaterial")
2412 if (aNames.IsEmpty())
2414 std::cout << "Error: not enough arguments!\n";
2417 aChangeSet->ToSetMaterial = 1;
2418 aChangeSet->MatName = aNames.Last();
2419 aNames.Remove (aNames.Length());
2420 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
2422 std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n";
2426 else if (aCmdName == "vunsetmaterial")
2428 aChangeSet->ToSetMaterial = -1;
2430 else if (aCmdName == "vsetinteriorstyle")
2432 if (aNames.IsEmpty()
2433 || !aNames.Last().IsRealValue())
2435 std::cout << "Error: not enough arguments!\n";
2438 aChangeSet->ToSetInterior = 1;
2439 if (!parseInteriorStyle (aNames.Last(), aChangeSet->InteriorStyle))
2441 std::cout << "Error: wrong syntax at " << aNames.Last() << "\n";
2444 aNames.Remove (aNames.Length());
2446 else if (aCmdName == "vsetedgetype")
2448 aChangeSet->ToSetDrawEdges = 1;
2449 toParseAliasArgs = true;
2451 else if (aCmdName == "vunsetedgetype")
2453 aChangeSet->ToSetDrawEdges = -1;
2454 aChangeSet->ToSetEdgeColor = -1;
2455 aChangeSet->ToSetTypeOfEdge = -1;
2456 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
2458 else if (aCmdName == "vshowfaceboundary")
2460 aChangeSet->ToSetFaceBoundaryDraw = 1;
2461 toParseAliasArgs = true;
2462 if (aNames.Size() >= 2
2463 && aNames.Value (2).IsIntegerValue())
2465 if (aNames.Size() == 7)
2467 if (ViewerTest::ParseLineType (aNames.Value (7).ToCString(), aChangeSet->TypeOfFaceBoundaryLine))
2469 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2473 if (aNames.Size() == 6
2474 && aNames.Value (6).IsRealValue())
2476 aChangeSet->ToSetFaceBoundaryWidth = 1;
2477 aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue();
2480 if (aNames.Size() == 5
2481 && aNames.Value (3).IsIntegerValue()
2482 && aNames.Value (4).IsIntegerValue()
2483 && aNames.Value (5).IsIntegerValue())
2485 aChangeSet->ToSetFaceBoundaryColor = 1;
2486 aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0,
2487 aNames.Value (4).IntegerValue() / 255.0,
2488 aNames.Value (5).IntegerValue() / 255.0,
2494 if (aNames.Size() == 2)
2496 toParseAliasArgs = false;
2497 aChangeSet->ToSetFaceBoundaryDraw = aNames.Value (2).IntegerValue() == 1 ? 1 : -1;
2502 else if (anArgIter >= theArgNb)
2504 std::cout << "Error: not enough arguments!\n";
2508 if (!aChangeSet->IsEmpty()
2509 && !toParseAliasArgs)
2511 anArgIter = theArgNb;
2513 for (; anArgIter < theArgNb; ++anArgIter)
2515 TCollection_AsciiString anArg = theArgVec[anArgIter];
2517 if (anArg == "-setwidth"
2518 || anArg == "-width"
2519 || anArg == "-setlinewidth"
2520 || anArg == "-linewidth"
2521 || anArg == "-setedgewidth"
2522 || anArg == "-setedgeswidth"
2523 || anArg == "-edgewidth"
2524 || anArg == "-edgeswidth"
2525 || anArg == "-setfaceboundarywidth"
2526 || anArg == "-setboundarywidth"
2527 || anArg == "-faceboundarywidth"
2528 || anArg == "-boundarywidth")
2530 if (++anArgIter >= theArgNb)
2532 std::cout << "Error: wrong syntax at " << anArg << "\n";
2536 const Standard_Real aWidth = Draw::Atof (theArgVec[anArgIter]);
2537 if (anArg == "-setedgewidth"
2538 || anArg == "-setedgeswidth"
2539 || anArg == "-edgewidth"
2540 || anArg == "-edgeswidth"
2541 || aCmdName == "vsetedgetype")
2543 aChangeSet->ToSetEdgeWidth = 1;
2544 aChangeSet->EdgeWidth = aWidth;
2546 else if (anArg == "-setfaceboundarywidth"
2547 || anArg == "-setboundarywidth"
2548 || anArg == "-faceboundarywidth"
2549 || anArg == "-boundarywidth"
2550 || aCmdName == "vshowfaceboundary")
2552 aChangeSet->ToSetFaceBoundaryWidth = 1;
2553 aChangeSet->FaceBoundaryWidth = aWidth;
2557 aChangeSet->ToSetLineWidth = 1;
2558 aChangeSet->LineWidth = aWidth;
2561 else if (anArg == "-unsetwidth"
2562 || anArg == "-unsetlinewidth"
2563 || anArg == "-unsetedgewidth")
2565 if (anArg == "-unsetedgewidth")
2567 aChangeSet->ToSetEdgeWidth = -1;
2568 aChangeSet->EdgeWidth = 1.0;
2572 aChangeSet->ToSetLineWidth = -1;
2573 aChangeSet->LineWidth = 1.0;
2576 else if (anArg == "-settransp"
2577 || anArg == "-settransparency"
2578 || anArg == "-transparency"
2579 || anArg == "-transp")
2581 if (++anArgIter >= theArgNb)
2583 std::cout << "Error: wrong syntax at " << anArg << "\n";
2586 aChangeSet->ToSetTransparency = 1;
2587 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2588 if (aChangeSet->Transparency >= 0.0
2589 && aChangeSet->Transparency <= Precision::Confusion())
2591 aChangeSet->ToSetTransparency = -1;
2592 aChangeSet->Transparency = 0.0;
2595 else if (anArg == "-setalphamode"
2596 || anArg == "-alphamode")
2598 if (++anArgIter >= theArgNb)
2600 std::cout << "Error: wrong syntax at " << anArg << "\n";
2603 aChangeSet->ToSetAlphaMode = 1;
2604 aChangeSet->AlphaCutoff = 0.5f;
2606 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2608 if (aParam == "opaque")
2610 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2612 else if (aParam == "mask")
2614 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2616 else if (aParam == "blend")
2618 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2620 else if (aParam == "blendauto"
2621 || aParam == "auto")
2623 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2627 std::cout << "Error: wrong syntax at " << aParam << "\n";
2632 if (anArgIter + 1 < theArgNb
2633 && theArgVec[anArgIter + 1][0] != '-')
2635 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2636 if (aParam2.IsRealValue())
2638 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2643 else if (anArg == "-setvis"
2644 || anArg == "-setvisibility"
2645 || anArg == "-visibility")
2647 if (++anArgIter >= theArgNb)
2649 std::cout << "Error: wrong syntax at " << anArg << "\n";
2653 aChangeSet->ToSetVisibility = 1;
2654 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2656 else if (anArg == "-setalpha"
2657 || anArg == "-alpha")
2659 if (++anArgIter >= theArgNb)
2661 std::cout << "Error: wrong syntax at " << anArg << "\n";
2664 aChangeSet->ToSetTransparency = 1;
2665 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2666 if (aChangeSet->Transparency < 0.0
2667 || aChangeSet->Transparency > 1.0)
2669 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2672 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2673 if (aChangeSet->Transparency >= 0.0
2674 && aChangeSet->Transparency <= Precision::Confusion())
2676 aChangeSet->ToSetTransparency = -1;
2677 aChangeSet->Transparency = 0.0;
2680 else if (anArg == "-unsettransp"
2681 || anArg == "-unsettransparency"
2682 || anArg == "-unsetalpha"
2683 || anArg == "-opaque")
2685 aChangeSet->ToSetTransparency = -1;
2686 aChangeSet->Transparency = 0.0;
2688 else if (anArg == "-setcolor"
2689 || anArg == "-color"
2690 || anArg == "-setbackfacecolor"
2691 || anArg == "-backfacecolor"
2692 || anArg == "-setbackcolor"
2693 || anArg == "-backcolor"
2694 || anArg == "-setfaceboundarycolor"
2695 || anArg == "-setboundarycolor"
2696 || anArg == "-faceboundarycolor"
2697 || anArg == "-boundarycolor")
2699 Quantity_Color aColor;
2700 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2701 theArgVec + anArgIter + 1,
2705 std::cout << "Syntax error at '" << anArg << "'\n";
2708 anArgIter += aNbParsed;
2709 if (aCmdName == "vsetedgetype")
2711 aChangeSet->ToSetEdgeColor = 1;
2712 aChangeSet->EdgeColor = Quantity_ColorRGBA (aColor);
2714 else if (aCmdName == "vshowfaceboundary"
2715 || anArg == "-setfaceboundarycolor"
2716 || anArg == "-setboundarycolor"
2717 || anArg == "-faceboundarycolor"
2718 || anArg == "-boundarycolor")
2720 aChangeSet->ToSetFaceBoundaryColor = 1;
2721 aChangeSet->FaceBoundaryColor = aColor;
2723 else if (anArg == "-setbackfacecolor"
2724 || anArg == "-backfacecolor"
2725 || anArg == "-setbackcolor"
2726 || anArg == "-backcolor")
2728 aChangeSet->ToSetBackFaceColor = 1;
2729 aChangeSet->BackFaceColor = aColor;
2733 aChangeSet->ToSetColor = 1;
2734 aChangeSet->Color = aColor;
2737 else if (anArg == "-setlinetype"
2738 || anArg == "-linetype"
2739 || anArg == "-setedgetype"
2740 || anArg == "-setedgestype"
2741 || anArg == "-edgetype"
2742 || anArg == "-edgestype"
2743 || anArg == "-setfaceboundarystyle"
2744 || anArg == "-faceboundarystyle"
2745 || anArg == "-boundarystyle"
2746 || anArg == "-setfaceboundarytype"
2747 || anArg == "-faceboundarytype"
2748 || anArg == "-setboundarytype"
2749 || anArg == "-boundarytype"
2750 || anArg == "-type")
2752 if (++anArgIter >= theArgNb)
2754 std::cout << "Error: wrong syntax at " << anArg << "\n";
2757 Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY;
2758 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType))
2760 std::cout << "Error: wrong syntax at " << anArg << "\n";
2763 if (anArg == "-setedgetype"
2764 || anArg == "-setedgestype"
2765 || anArg == "-edgetype"
2766 || anArg == "-edgestype"
2767 || aCmdName == "vsetedgetype")
2769 aChangeSet->TypeOfEdge = aLineType;
2770 aChangeSet->ToSetTypeOfEdge = 1;
2772 else if (anArg == "-setfaceboundarystyle"
2773 || anArg == "-faceboundarystyle"
2774 || anArg == "-boundarystyle"
2775 || anArg == "-setfaceboundarytype"
2776 || anArg == "-faceboundarytype"
2777 || anArg == "-setboundarytype"
2778 || anArg == "-boundarytype"
2779 || aCmdName == "vshowfaceboundary")
2781 aChangeSet->TypeOfFaceBoundaryLine = aLineType;
2782 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2786 aChangeSet->TypeOfLine = aLineType;
2787 aChangeSet->ToSetTypeOfLine = 1;
2790 else if (anArg == "-unsetlinetype"
2791 || anArg == "-unsetedgetype"
2792 || anArg == "-unsetedgestype")
2794 if (anArg == "-unsetedgetype"
2795 || anArg == "-unsetedgestype")
2797 aChangeSet->ToSetTypeOfEdge = -1;
2801 aChangeSet->ToSetTypeOfLine = -1;
2804 else if (anArg == "-setmarkertype"
2805 || anArg == "-markertype"
2806 || anArg == "-setpointtype"
2807 || anArg == "-pointtype")
2809 if (++anArgIter >= theArgNb)
2811 std::cout << "Error: wrong syntax at " << anArg << "\n";
2814 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2816 std::cout << "Error: wrong syntax at " << anArg << "\n";
2820 aChangeSet->ToSetTypeOfMarker = 1;
2822 else if (anArg == "-unsetmarkertype"
2823 || anArg == "-unsetpointtype")
2825 aChangeSet->ToSetTypeOfMarker = -1;
2827 else if (anArg == "-setmarkersize"
2828 || anArg == "-markersize"
2829 || anArg == "-setpointsize"
2830 || anArg == "-pointsize")
2832 if (++anArgIter >= theArgNb)
2834 std::cout << "Error: wrong syntax at " << anArg << "\n";
2837 aChangeSet->ToSetMarkerSize = 1;
2838 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2840 else if (anArg == "-unsetmarkersize"
2841 || anArg == "-unsetpointsize")
2843 aChangeSet->ToSetMarkerSize = -1;
2844 aChangeSet->MarkerSize = 1.0;
2846 else if (anArg == "-unsetcolor")
2848 aChangeSet->ToSetColor = -1;
2849 aChangeSet->Color = DEFAULT_COLOR;
2851 else if (anArg == "-setmat"
2853 || anArg == "-setmaterial"
2854 || anArg == "-material")
2856 if (++anArgIter >= theArgNb)
2858 std::cout << "Error: wrong syntax at " << anArg << "\n";
2861 aChangeSet->ToSetMaterial = 1;
2862 aChangeSet->MatName = theArgVec[anArgIter];
2863 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
2865 std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n";
2869 else if (anArg == "-unsetmat"
2870 || anArg == "-unsetmaterial")
2872 aChangeSet->ToSetMaterial = -1;
2873 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2875 else if (anArg == "-subshape"
2876 || anArg == "-subshapes")
2880 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2884 if (aNames.IsEmpty())
2886 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2890 aChanges.Append (ViewerTest_AspectsChangeSet());
2891 aChangeSet = &aChanges.ChangeLast();
2893 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2895 Standard_CString aSubShapeName = theArgVec[anArgIter];
2896 if (*aSubShapeName == '-')
2902 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2903 if (aSubShape.IsNull())
2905 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2908 aChangeSet->SubShapes.Append (aSubShape);
2911 if (aChangeSet->SubShapes.IsEmpty())
2913 std::cerr << "Error: empty list is specified after -subshapes!\n";
2917 else if (anArg == "-setfreeboundary"
2918 || anArg == "-freeboundary"
2919 || anArg == "-setfb"
2922 bool toEnable = true;
2923 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2925 std::cout << "Error: wrong syntax at " << anArg << "\n";
2929 aChangeSet->ToSetShowFreeBoundary = toEnable ? 1 : -1;
2931 else if (anArg == "-setfreeboundarywidth"
2932 || anArg == "-freeboundarywidth"
2933 || anArg == "-setfbwidth"
2934 || anArg == "-fbwidth")
2936 if (++anArgIter >= theArgNb)
2938 std::cout << "Error: wrong syntax at " << anArg << "\n";
2941 aChangeSet->ToSetFreeBoundaryWidth = 1;
2942 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2944 else if (anArg == "-unsetfreeboundarywidth"
2945 || anArg == "-unsetfbwidth")
2947 aChangeSet->ToSetFreeBoundaryWidth = -1;
2948 aChangeSet->FreeBoundaryWidth = 1.0;
2950 else if (anArg == "-setfreeboundarycolor"
2951 || anArg == "-freeboundarycolor"
2952 || anArg == "-setfbcolor"
2953 || anArg == "-fbcolor")
2955 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2956 theArgVec + anArgIter + 1,
2957 aChangeSet->FreeBoundaryColor);
2960 std::cout << "Syntax error at '" << anArg << "'\n";
2963 anArgIter += aNbParsed;
2964 aChangeSet->ToSetFreeBoundaryColor = 1;
2966 else if (anArg == "-unsetfreeboundarycolor"
2967 || anArg == "-unsetfbcolor")
2969 aChangeSet->ToSetFreeBoundaryColor = -1;
2970 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2972 else if (anArg == "-setisoontriangulation"
2973 || anArg == "-isoontriangulation"
2974 || anArg == "-setisoontriang"
2975 || anArg == "-isoontriang")
2977 bool toEnable = true;
2978 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2980 std::cout << "Error: wrong syntax at " << anArg << "\n";
2984 aChangeSet->ToEnableIsoOnTriangulation = toEnable ? 1 : -1;
2986 else if (anArg == "-setfaceboundarydraw"
2987 || anArg == "-setdrawfaceboundary"
2988 || anArg == "-setdrawfaceboundaries"
2989 || anArg == "-setshowfaceboundary"
2990 || anArg == "-setshowfaceboundaries"
2991 || anArg == "-setdrawfaceedges"
2992 || anArg == "-faceboundarydraw"
2993 || anArg == "-drawfaceboundary"
2994 || anArg == "-drawfaceboundaries"
2995 || anArg == "-showfaceboundary"
2996 || anArg == "-showfaceboundaries"
2997 || anArg == "-drawfaceedges"
2998 || anArg == "-faceboundary"
2999 || anArg == "-faceboundaries"
3000 || anArg == "-faceedges")
3002 bool toEnable = true;
3003 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
3005 std::cout << "Error: wrong syntax at " << anArg << "\n";
3009 aChangeSet->ToSetFaceBoundaryDraw = toEnable ? 1 : -1;
3011 else if (anArg == "-unsetfaceboundary"
3012 || anArg == "-unsetboundary")
3014 aChangeSet->ToSetFaceBoundaryDraw = -1;
3015 aChangeSet->ToSetFaceBoundaryColor = -1;
3017 else if (anArg == "-setmostcontinuity"
3018 || anArg == "-mostcontinuity")
3020 TCollection_AsciiString aClassArg (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "");
3021 aClassArg.LowerCase();
3022 GeomAbs_Shape aClass = GeomAbs_CN;
3023 if (aClassArg == "c0"
3024 || aClassArg == "0")
3026 aClass = GeomAbs_C0;
3028 else if (aClassArg == "c1"
3029 || aClassArg == "1")
3031 aClass = GeomAbs_C1;
3033 else if (aClassArg == "c2"
3034 || aClassArg == "2")
3036 aClass = GeomAbs_C2;
3038 else if (aClassArg == "c3"
3039 || aClassArg == "3")
3041 aClass = GeomAbs_C3;
3043 else if (aClassArg == "cn"
3044 || aClassArg == "n")
3046 aClass = GeomAbs_CN;
3050 std::cout << "Syntax error at '" << anArg << "'\n";
3055 aChangeSet->ToSetFaceBoundaryUpperContinuity = 1;
3056 aChangeSet->FaceBoundaryUpperContinuity = aClass;
3058 else if (anArg == "-setmaxparamvalue"
3059 || anArg == "-maxparamvalue")
3061 if (++anArgIter >= theArgNb)
3063 std::cout << "Error: wrong syntax at " << anArg << "\n";
3066 aChangeSet->ToSetMaxParamValue = 1;
3067 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
3069 else if (anArg == "-setsensitivity"
3070 || anArg == "-sensitivity")
3074 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
3078 if (aNames.IsEmpty())
3080 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
3084 if (anArgIter + 2 >= theArgNb)
3086 std::cout << "Error: wrong syntax at " << anArg << "\n";
3089 aChangeSet->ToSetSensitivity = 1;
3090 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
3091 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
3093 else if (anArg == "-sethatch"
3094 || anArg == "-hatch")
3098 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
3102 if (aNames.IsEmpty())
3104 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
3108 aChangeSet->ToSetHatch = 1;
3109 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
3110 if (anArgHatch.Length() <= 2)
3112 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
3114 || anIntStyle >= Aspect_HS_NB)
3116 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
3119 aChangeSet->StdHatchStyle = anIntStyle;
3123 aChangeSet->PathToHatchPattern = anArgHatch;
3126 else if (anArg == "-setshadingmodel"
3127 || anArg == "-setshading"
3128 || anArg == "-shadingmodel"
3129 || anArg == "-shading")
3131 if (++anArgIter >= theArgNb)
3133 std::cout << "Error: wrong syntax at " << anArg << "\n";
3136 aChangeSet->ToSetShadingModel = 1;
3137 aChangeSet->ShadingModelName = theArgVec[anArgIter];
3138 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
3140 std::cout << "Error: wrong syntax at " << anArg << "\n";
3144 else if (anArg == "-unsetshadingmodel")
3146 aChangeSet->ToSetShadingModel = -1;
3147 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
3149 else if (anArg == "-setinterior"
3150 || anArg == "-setinteriorstyle"
3151 || anArg == "-interior"
3152 || anArg == "-interiorstyle")
3154 if (++anArgIter >= theArgNb)
3156 std::cout << "Error: wrong syntax at " << anArg << "\n";
3159 aChangeSet->ToSetInterior = 1;
3160 if (!parseInteriorStyle (theArgVec[anArgIter], aChangeSet->InteriorStyle))
3162 std::cout << "Error: wrong syntax at " << anArg << "\n";
3166 else if (anArg == "-unsetinterior")
3168 aChangeSet->ToSetInterior = -1;
3169 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3171 else if (anArg == "-setdrawoutline"
3172 || anArg == "-setdrawsilhouette"
3173 || anArg == "-setoutline"
3174 || anArg == "-setsilhouette"
3175 || anArg == "-outline"
3176 || anArg == "-outlined"
3177 || anArg == "-silhouette")
3179 bool toDrawOutline = true;
3180 if (anArgIter + 1 < theArgNb
3181 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawOutline))
3185 aChangeSet->ToSetDrawSilhouette = toDrawOutline ? 1 : -1;
3187 else if (anArg == "-setdrawedges"
3188 || anArg == "-setdrawedge"
3189 || anArg == "-drawedges"
3190 || anArg == "-drawedge"
3191 || anArg == "-edges")
3193 bool toDrawEdges = true;
3194 if (anArgIter + 1 < theArgNb
3195 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawEdges))
3199 aChangeSet->ToSetDrawEdges = toDrawEdges ? 1 : -1;
3201 else if (anArg == "-setquadedges"
3202 || anArg == "-setquads"
3203 || anArg == "-quads"
3204 || anArg == "-skipfirstedge")
3206 bool isQuadMode = true;
3207 if (anArgIter + 1 < theArgNb
3208 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isQuadMode))
3212 aChangeSet->ToSetQuadEdges = isQuadMode ? 1 : -1;
3214 else if (anArg == "-setedgecolor"
3215 || anArg == "-setedgescolor"
3216 || anArg == "-edgecolor"
3217 || anArg == "-edgescolor")
3219 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3220 theArgVec + anArgIter + 1,
3221 aChangeSet->EdgeColor);
3224 std::cout << "Syntax error at '" << anArg << "'\n";
3227 anArgIter += aNbParsed;
3228 aChangeSet->ToSetEdgeColor = 1;
3230 else if (anArg == "-unset")
3232 aChangeSet->ToSetVisibility = 1;
3233 aChangeSet->Visibility = 1;
3234 aChangeSet->ToSetLineWidth = -1;
3235 aChangeSet->LineWidth = 1.0;
3236 aChangeSet->ToSetTypeOfLine = -1;
3237 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
3238 aChangeSet->ToSetTypeOfMarker = -1;
3239 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
3240 aChangeSet->ToSetMarkerSize = -1;
3241 aChangeSet->MarkerSize = 1.0;
3242 aChangeSet->ToSetTransparency = -1;
3243 aChangeSet->Transparency = 0.0;
3244 aChangeSet->ToSetAlphaMode = -1;
3245 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
3246 aChangeSet->AlphaCutoff = 0.5f;
3247 aChangeSet->ToSetColor = -1;
3248 aChangeSet->Color = DEFAULT_COLOR;
3249 //aChangeSet->ToSetBackFaceColor = -1; // should be reset by ToSetColor
3250 //aChangeSet->BackFaceColor = DEFAULT_COLOR;
3251 aChangeSet->ToSetMaterial = -1;
3252 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
3253 aChangeSet->ToSetShowFreeBoundary = -1;
3254 aChangeSet->ToSetFreeBoundaryColor = -1;
3255 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
3256 aChangeSet->ToSetFreeBoundaryWidth = -1;
3257 aChangeSet->FreeBoundaryWidth = 1.0;
3258 aChangeSet->ToEnableIsoOnTriangulation = -1;
3260 aChangeSet->ToSetFaceBoundaryDraw = -1;
3261 aChangeSet->ToSetFaceBoundaryUpperContinuity = -1;
3262 aChangeSet->FaceBoundaryUpperContinuity = GeomAbs_CN;
3263 aChangeSet->ToSetFaceBoundaryColor = -1;
3264 aChangeSet->FaceBoundaryColor = Quantity_NOC_BLACK;
3265 aChangeSet->ToSetFaceBoundaryWidth = -1;
3266 aChangeSet->FaceBoundaryWidth = 1.0f;
3267 aChangeSet->ToSetTypeOfFaceBoundaryLine = -1;
3268 aChangeSet->TypeOfFaceBoundaryLine = Aspect_TOL_SOLID;
3270 aChangeSet->ToSetHatch = -1;
3271 aChangeSet->StdHatchStyle = -1;
3272 aChangeSet->PathToHatchPattern.Clear();
3273 aChangeSet->ToSetShadingModel = -1;
3274 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
3275 aChangeSet->ToSetInterior = -1;
3276 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3277 aChangeSet->ToSetDrawSilhouette = -1;
3278 aChangeSet->ToSetDrawEdges = -1;
3279 aChangeSet->ToSetQuadEdges = -1;
3280 aChangeSet->ToSetEdgeColor = -1;
3281 aChangeSet->EdgeColor = Quantity_ColorRGBA (DEFAULT_COLOR);
3282 aChangeSet->ToSetEdgeWidth = -1;
3283 aChangeSet->EdgeWidth = 1.0;
3284 aChangeSet->ToSetTypeOfEdge = -1;
3285 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
3289 std::cout << "Error: wrong syntax at " << anArg << "\n";
3294 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3295 aChangesIter.More(); aChangesIter.Next())
3297 if (!aChangesIter.Value().Validate())
3303 // special case for -defaults parameter.
3304 // all changed values will be set to DefaultDrawer.
3307 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
3308 aChangeSet->Apply (aDrawer);
3309 if (aChangeSet->ToSetLineWidth != 0)
3311 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
3312 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
3313 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
3314 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
3316 if (aChangeSet->ToSetColor != 0)
3318 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
3319 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
3320 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
3321 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
3322 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
3323 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
3325 if (aChangeSet->ToSetTransparency != 0)
3327 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
3329 if (aChangeSet->ToSetMaterial != 0)
3331 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
3333 if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3335 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
3338 // redisplay all objects in context
3339 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3341 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3344 aCtx->Redisplay (aPrs, Standard_False);
3350 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3352 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
3353 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3359 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
3360 Handle(AIS_ColoredShape) aColoredPrs;
3361 Standard_Boolean toDisplay = Standard_False;
3362 Standard_Boolean toRedisplay = Standard_False;
3363 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
3365 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
3366 if (aShapePrs.IsNull())
3368 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
3371 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
3372 if (aColoredPrs.IsNull())
3374 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3375 if (aShapePrs->HasDisplayMode())
3377 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
3379 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
3380 aCtx->Remove (aShapePrs, Standard_False);
3381 GetMapOfAIS().UnBind2 (aName);
3382 GetMapOfAIS().Bind (aColoredPrs, aName);
3383 toDisplay = Standard_True;
3384 aShapePrs = aColoredPrs;
3391 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3392 aChangeSet = &aChangesIter.ChangeValue();
3393 if (aChangeSet->ToSetVisibility == 1)
3395 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
3396 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
3398 else if (aChangeSet->ToSetMaterial == 1)
3400 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
3402 else if (aChangeSet->ToSetMaterial == -1)
3404 aCtx->UnsetMaterial (aPrs, Standard_False);
3406 if (aChangeSet->ToSetColor == 1)
3408 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
3410 else if (aChangeSet->ToSetColor == -1)
3412 aCtx->UnsetColor (aPrs, Standard_False);
3414 if (aChangeSet->ToSetTransparency == 1)
3416 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
3418 else if (aChangeSet->ToSetTransparency == -1)
3420 aCtx->UnsetTransparency (aPrs, Standard_False);
3422 if (aChangeSet->ToSetLineWidth == 1)
3424 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
3426 else if (aChangeSet->ToSetLineWidth == -1)
3428 aCtx->UnsetWidth (aPrs, Standard_False);
3430 else if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3432 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
3433 toRedisplay = Standard_True;
3435 else if (aChangeSet->ToSetSensitivity != 0)
3437 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3439 if (!aDrawer.IsNull())
3441 toRedisplay = aChangeSet->Apply (aDrawer) || toRedisplay;
3444 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
3446 aChangeSet = &aChangesIter.ChangeValue();
3447 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
3448 aSubShapeIter.More(); aSubShapeIter.Next())
3450 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
3451 if (!aChangeSet->IsEmpty())
3453 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3454 aChangeSet->Apply (aCurColDrawer);
3456 if (aChangeSet->ToSetVisibility == 1)
3458 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3459 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
3461 if (aChangeSet->ToSetColor == 1)
3463 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
3465 if (aChangeSet->ToSetTransparency == 1)
3467 aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency);
3469 if (aChangeSet->ToSetLineWidth == 1)
3471 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
3473 if (aChangeSet->ToSetColor == -1
3474 || aChangeSet->ToSetLineWidth == -1)
3476 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
3478 if (aChangeSet->ToSetSensitivity != 0)
3480 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3486 aCtx->Display (aPrs, Standard_False);
3490 aCtx->Redisplay (aPrs, Standard_False);
3492 else if (!aColoredPrs.IsNull())
3494 aCtx->Redisplay (aColoredPrs, Standard_False);
3498 aPrs->SynchronizeAspects();
3505 //==============================================================================
3506 //function : VDonly2
3508 //purpose : Display only a selected or named object
3509 // if there is no selected or named object s, nothing is done
3510 //==============================================================================
3511 static int VDonly2 (Draw_Interpretor& ,
3512 Standard_Integer theArgNb,
3513 const char** theArgVec)
3515 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3516 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3519 std::cerr << "Error: no active view!\n";
3523 Standard_Integer anArgIter = 1;
3524 for (; anArgIter < theArgNb; ++anArgIter)
3526 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3532 NCollection_Map<Handle(Standard_Transient)> aDispSet;
3533 if (anArgIter >= theArgNb)
3535 // display only selected objects
3536 if (aCtx->NbSelected() < 1)
3541 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3543 aDispSet.Add (aCtx->SelectedInteractive());
3548 // display only specified objects
3549 for (; anArgIter < theArgNb; ++anArgIter)
3551 TCollection_AsciiString aName = theArgVec[anArgIter];
3552 Handle(AIS_InteractiveObject) aShape;
3553 if (GetMapOfAIS().Find2 (aName, aShape)
3554 && !aShape.IsNull())
3556 aCtx->Display (aShape, Standard_False);
3557 aDispSet.Add (aShape);
3562 // weed out other objects
3563 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
3565 if (aDispSet.Contains (anIter.Key1()))
3570 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
3572 aCtx->Erase (aShape, Standard_False);
3578 //==============================================================================
3579 //function : VRemove
3580 //purpose : Removes selected or named objects.
3581 // If there is no selected or named objects,
3582 // all objects in the viewer can be removed with argument -all.
3583 // If -context is in arguments, the object is not deleted from the map of
3584 // objects (deleted only from the current context).
3585 //==============================================================================
3586 int VRemove (Draw_Interpretor& theDI,
3587 Standard_Integer theArgNb,
3588 const char** theArgVec)
3590 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3591 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3594 std::cerr << "Error: no active view!\n";
3598 Standard_Boolean isContextOnly = Standard_False;
3599 Standard_Boolean toRemoveAll = Standard_False;
3600 Standard_Boolean toPrintInfo = Standard_True;
3601 Standard_Boolean toFailOnError = Standard_True;
3603 Standard_Integer anArgIter = 1;
3604 for (; anArgIter < theArgNb; ++anArgIter)
3606 TCollection_AsciiString anArg = theArgVec[anArgIter];
3608 if (anArg == "-context")
3610 isContextOnly = Standard_True;
3612 else if (anArg == "-all")
3614 toRemoveAll = Standard_True;
3616 else if (anArg == "-noinfo")
3618 toPrintInfo = Standard_False;
3620 else if (anArg == "-noerror"
3621 || anArg == "-nofail")
3623 toFailOnError = Standard_False;
3625 else if (anUpdateTool.parseRedrawMode (anArg))
3635 && anArgIter < theArgNb)
3637 std::cerr << "Error: wrong syntax!\n";
3641 NCollection_List<TCollection_AsciiString> anIONameList;
3644 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3645 anIter.More(); anIter.Next())
3647 anIONameList.Append (anIter.Key2());
3650 else if (anArgIter < theArgNb) // removed objects names are in argument list
3652 for (; anArgIter < theArgNb; ++anArgIter)
3654 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3655 if (aName.Search ("*") != -1)
3657 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
3659 if (aPrsIter.Key1()->GetContext() != aCtx)
3663 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
3664 if (theDI.Eval (aCheck.ToCString()) == 0
3665 && *theDI.Result() == '1')
3667 anIONameList.Append (aPrsIter.Key2());
3674 Handle(AIS_InteractiveObject) anIO;
3675 if (!GetMapOfAIS().Find2 (aName, anIO))
3679 std::cout << "Syntax error: '" << aName << "' was not bound to some object.\n";
3683 else if (anIO->GetContext() != aCtx)
3687 std::cout << "Syntax error: '" << aName << "' was not displayed in current context.\n"
3688 << "Please activate view with this object displayed and try again.\n";
3694 anIONameList.Append (aName);
3698 else if (aCtx->NbSelected() > 0)
3700 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3701 anIter.More(); anIter.Next())
3703 if (!aCtx->IsSelected (anIter.Key1()))
3708 anIONameList.Append (anIter.Key2());
3713 // Unbind all removed objects from the map of displayed IO.
3714 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3715 anIter.More(); anIter.Next())
3717 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
3718 aCtx->Remove (anIO, Standard_False);
3721 theDI << anIter.Value() << " ";
3725 GetMapOfAIS().UnBind2 (anIter.Value());
3731 //==============================================================================
3733 //purpose : Erase some selected or named objects
3734 // if there is no selected or named objects, the whole viewer is erased
3735 //==============================================================================
3736 int VErase (Draw_Interpretor& theDI,
3737 Standard_Integer theArgNb,
3738 const char** theArgVec)
3740 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3741 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3742 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3745 std::cerr << "Error: no active view!\n";
3749 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3751 Standard_Integer anArgIter = 1;
3752 Standard_Boolean toEraseInView = Standard_False;
3753 Standard_Boolean toFailOnError = Standard_True;
3754 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3755 for (; anArgIter < theArgNb; ++anArgIter)
3757 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3758 anArgCase.LowerCase();
3759 if (anUpdateTool.parseRedrawMode (anArgCase))
3763 else if (anArgCase == "-view"
3764 || anArgCase == "-inview")
3766 toEraseInView = Standard_True;
3768 else if (anArgCase == "-noerror"
3769 || anArgCase == "-nofail")
3771 toFailOnError = Standard_False;
3775 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3779 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3781 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3785 if (!aNamesOfEraseIO.IsEmpty())
3787 // Erase named objects
3788 NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString> aPrsList;
3789 for (TColStd_SequenceOfAsciiString::Iterator anIter (aNamesOfEraseIO); anIter.More(); anIter.Next())
3791 const TCollection_AsciiString& aName = anIter.Value();
3792 if (aName.Search ("*") != -1)
3794 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
3796 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
3797 if (theDI.Eval (aCheck.ToCString()) == 0
3798 && *theDI.Result() == '1')
3800 aPrsList.Add (aPrsIter.Key1(), aPrsIter.Key2());
3807 Handle(AIS_InteractiveObject) anIO;
3808 if (!GetMapOfAIS().Find2 (aName, anIO))
3812 std::cout << "Syntax error: '" << aName << "' is not found\n";
3818 aPrsList.Add (anIO, aName);
3823 for (NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString>::Iterator anIter (aPrsList); anIter.More(); anIter.Next())
3825 theDI << anIter.Value() << " ";
3828 aCtx->SetViewAffinity (anIter.Key(), aView, Standard_False);
3832 aCtx->Erase (anIter.Key(), Standard_False);
3836 else if (!toEraseAll && aCtx->NbSelected() > 0)
3838 // Erase selected objects
3839 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3840 anIter.More(); anIter.Next())
3842 const Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3844 && aCtx->IsSelected (anIO))
3846 theDI << anIter.Key2() << " ";
3849 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3856 aCtx->EraseSelected (Standard_False);
3861 // Erase all objects
3862 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3863 anIter.More(); anIter.Next())
3865 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3870 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3874 aCtx->Erase (anIO, Standard_False);
3883 //==============================================================================
3884 //function : VDisplayAll
3885 //purpose : Display all the objects of the Map
3886 //==============================================================================
3887 static int VDisplayAll (Draw_Interpretor& ,
3888 Standard_Integer theArgNb,
3889 const char** theArgVec)
3892 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3893 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3896 std::cerr << "Error: no active view!\n";
3900 Standard_Integer anArgIter = 1;
3901 for (; anArgIter < theArgNb; ++anArgIter)
3903 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3904 anArgCase.LowerCase();
3905 if (anUpdateTool.parseRedrawMode (anArgCase))
3914 if (anArgIter < theArgNb)
3916 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3920 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3921 anIter.More(); anIter.Next())
3923 aCtx->Erase (anIter.Key1(), Standard_False);
3926 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3927 anIter.More(); anIter.Next())
3929 aCtx->Display (anIter.Key1(), Standard_False);
3934 //! Auxiliary method to check if presentation exists
3935 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3936 const Handle(AIS_InteractiveObject)& theIO,
3937 const Standard_Integer theMode)
3939 if (theIO.IsNull() || theCtx.IsNull())
3946 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3951 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3953 return theIO->DisplayMode();
3955 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3957 return theCtx->DisplayMode();
3963 enum ViewerTest_BndAction
3970 //! Auxiliary method to print bounding box of presentation
3971 inline void bndPresentation (Draw_Interpretor& theDI,
3972 const Handle(PrsMgr_PresentationManager)& theMgr,
3973 const Handle(AIS_InteractiveObject)& theObj,
3974 const Standard_Integer theDispMode,
3975 const TCollection_AsciiString& theName,
3976 const ViewerTest_BndAction theAction,
3977 const Handle(Prs3d_Drawer)& theStyle)
3981 case BndAction_Hide:
3983 theMgr->Unhighlight (theObj);
3986 case BndAction_Show:
3988 theMgr->Color (theObj, theStyle, theDispMode);
3991 case BndAction_Print:
3994 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3996 if (aPrsIter.Value()->Mode() != theDispMode)
3999 aBox = aPrsIter.Value()->MinMaxValues();
4001 gp_Pnt aMin = aBox.CornerMin();
4002 gp_Pnt aMax = aBox.CornerMax();
4003 theDI << theName << "\n"
4004 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
4005 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
4011 //==============================================================================
4012 //function : VBounding
4014 //==============================================================================
4015 int VBounding (Draw_Interpretor& theDI,
4016 Standard_Integer theArgNb,
4017 const char** theArgVec)
4019 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4020 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4023 std::cout << "Error: no active view!\n";
4027 ViewerTest_BndAction anAction = BndAction_Show;
4028 Standard_Integer aMode = -1;
4030 Handle(Prs3d_Drawer) aStyle;
4032 Standard_Integer anArgIter = 1;
4033 for (; anArgIter < theArgNb; ++anArgIter)
4035 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4037 if (anArg == "-print")
4039 anAction = BndAction_Print;
4041 else if (anArg == "-show")
4043 anAction = BndAction_Show;
4045 else if (anArg == "-hide")
4047 anAction = BndAction_Hide;
4049 else if (anArg == "-mode")
4051 if (++anArgIter >= theArgNb)
4053 std::cout << "Error: wrong syntax at " << anArg << "\n";
4056 aMode = Draw::Atoi (theArgVec[anArgIter]);
4058 else if (!anUpdateTool.parseRedrawMode (anArg))
4064 if (anAction == BndAction_Show)
4066 aStyle = new Prs3d_Drawer();
4067 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
4068 aStyle->SetColor (Quantity_NOC_GRAY99);
4071 Standard_Integer aHighlightedMode = -1;
4072 if (anArgIter < theArgNb)
4074 // has a list of names
4075 for (; anArgIter < theArgNb; ++anArgIter)
4077 TCollection_AsciiString aName = theArgVec[anArgIter];
4078 Handle(AIS_InteractiveObject) anIO;
4079 if (!GetMapOfAIS().Find2 (aName, anIO))
4081 std::cout << "Error: presentation " << aName << " does not exist\n";
4085 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4086 if (aHighlightedMode == -1)
4088 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
4091 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
4094 else if (aCtx->NbSelected() > 0)
4096 // remove all currently selected objects
4097 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4099 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
4100 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4101 if (aHighlightedMode != -1)
4103 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
4104 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
4111 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
4112 anIter.More(); anIter.Next())
4114 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
4115 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4116 if (aHighlightedMode != -1)
4118 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
4125 //==============================================================================
4126 //function : VTexture
4128 //==============================================================================
4129 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4131 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4134 std::cout << "Error: no active view!\n";
4138 int toModulate = -1;
4139 bool toSetFilter = false;
4140 bool toSetAniso = false;
4141 bool toSetTrsfAngle = false;
4142 bool toSetTrsfTrans = false;
4143 bool toSetTrsfScale = false;
4144 Standard_ShortReal aTrsfRotAngle = 0.0f;
4145 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
4146 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
4147 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
4148 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
4150 Handle(AIS_InteractiveObject) aTexturedIO;
4151 Handle(AIS_Shape) aTexturedShape;
4152 Handle(Graphic3d_TextureSet) aTextureSetOld;
4153 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
4154 bool toSetGenRepeat = false;
4155 bool toSetGenScale = false;
4156 bool toSetGenOrigin = false;
4157 bool toSetImage = false;
4158 bool toComputeUV = false;
4160 const TCollection_AsciiString aCommandName (theArgVec[0]);
4161 bool toSetDefaults = aCommandName == "vtexdefault";
4163 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4164 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
4166 const TCollection_AsciiString aName = theArgVec[anArgIter];
4167 TCollection_AsciiString aNameCase = aName;
4168 aNameCase.LowerCase();
4169 if (anUpdateTool.parseRedrawMode (aName))
4173 else if (aTexturedIO.IsNull())
4175 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
4176 if (aMapOfIO.IsBound2 (aName))
4178 aTexturedIO = aMapOfIO.Find2 (aName);
4179 aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO);
4181 if (aTexturedIO.IsNull())
4183 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
4187 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
4189 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
4192 else if (!aTexturedShape.IsNull()
4193 && (aNameCase == "-scale"
4194 || aNameCase == "-setscale"
4195 || aCommandName == "vtexscale"))
4197 if (aCommandName != "vtexscale")
4201 if (anArgIter < theArgsNb)
4203 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4204 TCollection_AsciiString aValUCase = aValU;
4205 aValUCase.LowerCase();
4206 toSetGenScale = true;
4207 if (aValUCase == "off")
4209 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4212 else if (anArgIter + 1 < theArgsNb)
4214 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4215 if (aValU.IsRealValue()
4216 && aValV.IsRealValue())
4218 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4224 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4227 else if (!aTexturedShape.IsNull()
4228 && (aNameCase == "-origin"
4229 || aNameCase == "-setorigin"
4230 || aCommandName == "vtexorigin"))
4232 if (aCommandName != "vtexorigin")
4236 if (anArgIter < theArgsNb)
4238 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4239 TCollection_AsciiString aValUCase = aValU;
4240 aValUCase.LowerCase();
4241 toSetGenOrigin = true;
4242 if (aValUCase == "off")
4244 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4247 else if (anArgIter + 1 < theArgsNb)
4249 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4250 if (aValU.IsRealValue()
4251 && aValV.IsRealValue())
4253 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4259 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4262 else if (!aTexturedShape.IsNull()
4263 && (aNameCase == "-repeat"
4264 || aNameCase == "-setrepeat"
4265 || aCommandName == "vtexrepeat"))
4267 if (aCommandName != "vtexrepeat")
4271 if (anArgIter < theArgsNb)
4273 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4274 TCollection_AsciiString aValUCase = aValU;
4275 aValUCase.LowerCase();
4276 toSetGenRepeat = true;
4277 if (aValUCase == "off")
4279 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4282 else if (anArgIter + 1 < theArgsNb)
4284 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4285 if (aValU.IsRealValue()
4286 && aValV.IsRealValue())
4288 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4294 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4297 else if (aNameCase == "-modulate")
4299 bool toModulateBool = true;
4300 if (anArgIter + 1 < theArgsNb
4301 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
4305 toModulate = toModulateBool ? 1 : 0;
4307 else if ((aNameCase == "-setfilter"
4308 || aNameCase == "-filter")
4309 && anArgIter + 1 < theArgsNb)
4311 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4315 if (aValue == "nearest")
4317 aFilter = Graphic3d_TOTF_NEAREST;
4319 else if (aValue == "bilinear")
4321 aFilter = Graphic3d_TOTF_BILINEAR;
4323 else if (aValue == "trilinear")
4325 aFilter = Graphic3d_TOTF_TRILINEAR;
4329 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
4333 else if ((aNameCase == "-setaniso"
4334 || aNameCase == "-setanisofilter"
4335 || aNameCase == "-aniso"
4336 || aNameCase == "-anisofilter")
4337 && anArgIter + 1 < theArgsNb)
4339 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4343 if (aValue == "off")
4345 anAnisoFilter = Graphic3d_LOTA_OFF;
4347 else if (aValue == "fast")
4349 anAnisoFilter = Graphic3d_LOTA_FAST;
4351 else if (aValue == "middle")
4353 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
4355 else if (aValue == "quality"
4356 || aValue == "high")
4358 anAnisoFilter = Graphic3d_LOTA_QUALITY;
4362 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
4366 else if ((aNameCase == "-rotateangle"
4367 || aNameCase == "-rotangle"
4368 || aNameCase == "-rotate"
4369 || aNameCase == "-angle"
4370 || aNameCase == "-trsfangle")
4371 && anArgIter + 1 < theArgsNb)
4373 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4374 toSetTrsfAngle = true;
4377 else if ((aNameCase == "-trsftrans"
4378 || aNameCase == "-trsftranslate"
4379 || aNameCase == "-translate"
4380 || aNameCase == "-translation")
4381 && anArgIter + 2 < theArgsNb)
4383 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4384 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4385 toSetTrsfTrans = true;
4388 else if ((aNameCase == "-trsfscale")
4389 && anArgIter + 2 < theArgsNb)
4391 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4392 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4393 toSetTrsfScale = true;
4396 else if (aNameCase == "-default"
4397 || aNameCase == "-defaults")
4399 toSetDefaults = true;
4401 else if ((aNameCase == "-video")
4402 && anArgIter + 1 < theArgsNb)
4404 const TCollection_AsciiString anInput (theArgVec[++anArgIter]);
4405 Handle(Graphic3d_MediaTextureSet) aMedia = Handle(Graphic3d_MediaTextureSet)::DownCast (aTextureSetOld);
4406 if (aMedia.IsNull())
4408 aMedia = new Graphic3d_MediaTextureSet();
4410 if (aMedia->Input() != anInput)
4412 aMedia->OpenInput (anInput, false);
4416 if (aMedia->SwapFrames()
4417 && !aCtx->CurrentViewer()->ZLayerSettings (aTexturedIO->ZLayer()).IsImmediate())
4419 ViewerTest::CurrentView()->Invalidate();
4422 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4423 && aTexturedShape.IsNull())
4425 aTexturedIO->SetToUpdate();
4428 toComputeUV = aTextureSetOld.IsNull();
4429 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (true);
4430 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia);
4431 aTextureSetOld.Nullify();
4433 else if (aCommandName == "vtexture"
4434 && (aTextureVecNew.IsEmpty()
4435 || aNameCase.StartsWith ("-tex")))
4437 Standard_Integer aTexIndex = 0;
4438 TCollection_AsciiString aTexName = aName;
4439 if (aNameCase.StartsWith ("-tex"))
4441 if (anArgIter + 1 >= theArgsNb
4442 || aNameCase.Length() < 5)
4444 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4448 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
4449 if (!aTexIndexStr.IsIntegerValue())
4451 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4455 aTexIndex = aTexIndexStr.IntegerValue();
4456 aTexName = theArgVec[anArgIter + 1];
4459 if (aTexIndex >= Graphic3d_TextureUnit_NB
4460 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
4462 std::cout << "Error: too many textures specified\n";
4467 if (aTexName.IsIntegerValue())
4469 const Standard_Integer aValue = aTexName.IntegerValue();
4470 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
4472 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
4475 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
4477 else if (aTexName == "?")
4479 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
4481 theDi << "\n Files in current directory : \n\n";
4482 theDi.Eval ("glob -nocomplain *");
4484 TCollection_AsciiString aCmnd ("glob -nocomplain ");
4485 aCmnd += aTextureFolder;
4488 theDi << "Files in " << aTextureFolder << " : \n\n";
4489 theDi.Eval (aCmnd.ToCString());
4492 else if (aTexName != "off")
4494 if (!OSD_File (aTexName).Exists())
4496 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
4499 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
4503 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
4506 if (aTextureVecNew.Value (aTexIndex))
4508 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
4513 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4520 // check if new image set is equal to already set one
4521 Standard_Integer aNbChanged = 0;
4522 Handle(Graphic3d_TextureSet) aTextureSetNew;
4523 if (!aTextureVecNew.IsEmpty())
4525 aNbChanged = aTextureVecNew.Size();
4526 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
4527 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
4529 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
4530 Handle(Graphic3d_TextureRoot) aTextureOld;
4531 if (!aTextureSetOld.IsNull()
4532 && aTexIter < aTextureSetOld->Size())
4534 aTextureOld = aTextureSetOld->Value (aTexIter);
4537 if (!aTextureOld.IsNull()
4538 && !aTextureNew.IsNull())
4540 *aTextureNew->GetParams() = *aTextureOld->GetParams();
4541 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
4543 TCollection_AsciiString aFilePathOld, aFilePathNew;
4544 aTextureOld->Path().SystemName (aFilePathOld);
4545 aTextureNew->Path().SystemName (aFilePathNew);
4546 if (aTextureNew->Name() == anOldManualTex->Name()
4547 && aFilePathOld == aFilePathNew
4548 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
4551 aTextureNew = anOldManualTex;
4555 aTextureSetNew->SetValue (aTexIter, aTextureNew);
4559 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
4560 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
4562 aTextureSetNew = aTextureSetOld;
4565 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4566 && aTexturedShape.IsNull())
4568 aTexturedIO->SetToUpdate();
4571 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
4572 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
4573 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
4574 aTextureSetOld.Nullify();
4579 if (toModulate != -1)
4586 aFilter = Graphic3d_TOTF_BILINEAR;
4591 anAnisoFilter = Graphic3d_LOTA_OFF;
4593 if (!toSetTrsfAngle)
4595 toSetTrsfAngle = true;
4596 aTrsfRotAngle = 0.0f;
4598 if (!toSetTrsfTrans)
4600 toSetTrsfTrans = true;
4601 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
4603 if (!toSetTrsfScale)
4605 toSetTrsfScale = true;
4606 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
4610 if (aCommandName == "vtexture"
4613 if (!aTextureSetOld.IsNull())
4615 //toComputeUV = true; // we can keep UV vertex attributes
4616 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
4617 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
4618 aTextureSetOld.Nullify();
4622 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
4623 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
4625 if (toModulate != -1)
4627 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
4631 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
4635 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
4639 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
4643 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
4647 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
4651 // set default values if requested
4653 && (aCommandName == "vtexrepeat"
4656 if (!aTexturedShape.IsNull())
4658 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4660 toSetGenRepeat = true;
4663 && (aCommandName == "vtexorigin"
4666 if (!aTexturedShape.IsNull())
4668 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4670 toSetGenOrigin = true;
4673 && (aCommandName == "vtexscale"
4676 if (!aTexturedShape.IsNull())
4678 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4680 toSetGenScale = true;
4683 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
4685 if (!aTexturedShape.IsNull())
4687 aTexturedShape->SetToUpdate (AIS_Shaded);
4690 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
4691 || aCtx->DisplayMode() != AIS_Shaded)
4693 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
4698 aCtx->Display (aTexturedIO, false);
4699 aTexturedIO->SynchronizeAspects();
4703 //! Auxiliary method to parse transformation persistence flags
4704 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
4705 Graphic3d_TransModeFlags& theFlags)
4707 if (theFlagString == "zoom")
4709 theFlags = Graphic3d_TMF_ZoomPers;
4711 else if (theFlagString == "rotate")
4713 theFlags = Graphic3d_TMF_RotatePers;
4715 else if (theFlagString == "zoomrotate")
4717 theFlags = Graphic3d_TMF_ZoomRotatePers;
4719 else if (theFlagString == "trihedron"
4720 || theFlagString == "triedron")
4722 theFlags = Graphic3d_TMF_TriedronPers;
4724 else if (theFlagString == "none")
4726 theFlags = Graphic3d_TMF_None;
4730 return Standard_False;
4733 return Standard_True;
4736 //! Auxiliary method to parse transformation persistence flags
4737 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4738 Aspect_TypeOfTriedronPosition& theCorner)
4740 TCollection_AsciiString aString (theString);
4741 aString.LowerCase();
4742 if (aString == "center")
4744 theCorner = Aspect_TOTP_CENTER;
4746 else if (aString == "top"
4747 || aString == "upper")
4749 theCorner = Aspect_TOTP_TOP;
4751 else if (aString == "bottom"
4752 || aString == "lower")
4754 theCorner = Aspect_TOTP_BOTTOM;
4756 else if (aString == "left")
4758 theCorner = Aspect_TOTP_LEFT;
4760 else if (aString == "right")
4762 theCorner = Aspect_TOTP_RIGHT;
4764 else if (aString == "topleft"
4765 || aString == "leftupper"
4766 || aString == "upperleft")
4768 theCorner = Aspect_TOTP_LEFT_UPPER;
4770 else if (aString == "bottomleft"
4771 || aString == "leftlower"
4772 || aString == "lowerleft")
4774 theCorner = Aspect_TOTP_LEFT_LOWER;
4776 else if (aString == "topright"
4777 || aString == "rightupper"
4778 || aString == "upperright")
4780 theCorner = Aspect_TOTP_RIGHT_UPPER;
4782 else if (aString == "bottomright"
4783 || aString == "lowerright"
4784 || aString == "rightlower")
4786 theCorner = Aspect_TOTP_RIGHT_LOWER;
4790 return Standard_False;
4793 return Standard_True;
4796 //==============================================================================
4797 //function : VDisplay2
4799 //purpose : Display an object from its name
4800 //==============================================================================
4801 static int VDisplay2 (Draw_Interpretor& theDI,
4802 Standard_Integer theArgNb,
4803 const char** theArgVec)
4807 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4811 && TCollection_AsciiString (theArgVec[1]) == "*")
4814 return VDisplayAll (theDI, 1, theArgVec);
4817 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4820 ViewerTest::ViewerInit();
4821 aCtx = ViewerTest::GetAISContext();
4824 // Parse input arguments
4825 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4826 Standard_Integer isMutable = -1;
4827 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4828 Standard_Boolean toReDisplay = Standard_False;
4829 Standard_Integer isSelectable = -1;
4830 Standard_Integer anObjDispMode = -2;
4831 Standard_Integer anObjHighMode = -2;
4832 Standard_Boolean toSetTrsfPers = Standard_False;
4833 Handle(Graphic3d_TransformPers) aTrsfPers;
4834 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4835 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4836 Standard_Integer toDisplayInView = Standard_False;
4837 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4839 const TCollection_AsciiString aName = theArgVec[anArgIter];
4840 TCollection_AsciiString aNameCase = aName;
4841 aNameCase.LowerCase();
4842 if (anUpdateTool.parseRedrawMode (aName))
4846 else if (aNameCase == "-mutable")
4850 else if (aNameCase == "-neutral")
4852 aDispStatus = AIS_DS_Displayed;
4854 else if (aNameCase == "-immediate"
4855 || aNameCase == "-top")
4857 aZLayer = Graphic3d_ZLayerId_Top;
4859 else if (aNameCase == "-topmost")
4861 aZLayer = Graphic3d_ZLayerId_Topmost;
4863 else if (aNameCase == "-osd"
4864 || aNameCase == "-toposd"
4865 || aNameCase == "-overlay")
4867 aZLayer = Graphic3d_ZLayerId_TopOSD;
4869 else if (aNameCase == "-botosd"
4870 || aNameCase == "-underlay")
4872 aZLayer = Graphic3d_ZLayerId_BotOSD;
4874 else if (aNameCase == "-select"
4875 || aNameCase == "-selectable")
4879 else if (aNameCase == "-noselect"
4880 || aNameCase == "-noselection")
4884 else if (aNameCase == "-dispmode"
4885 || aNameCase == "-displaymode")
4887 if (++anArgIter >= theArgNb)
4889 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4893 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4895 else if (aNameCase == "-himode"
4896 || aNameCase == "-highmode"
4897 || aNameCase == "-highlightmode")
4899 if (++anArgIter >= theArgNb)
4901 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4905 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4907 else if (aNameCase == "-3d")
4909 toSetTrsfPers = Standard_True;
4910 aTrsfPers.Nullify();
4912 else if (aNameCase == "-2d"
4913 || aNameCase == "-trihedron"
4914 || aNameCase == "-triedron")
4916 toSetTrsfPers = Standard_True;
4917 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4919 if (anArgIter + 1 < theArgNb)
4921 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4922 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4925 aTrsfPers->SetCorner2d (aCorner);
4927 if (anArgIter + 2 < theArgNb)
4929 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4930 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4931 if (anX.IsIntegerValue()
4932 && anY.IsIntegerValue())
4935 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4941 else if (aNameCase == "-trsfpers"
4942 || aNameCase == "-pers")
4944 if (++anArgIter >= theArgNb
4945 || !aTrsfPers.IsNull())
4947 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4951 toSetTrsfPers = Standard_True;
4952 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4953 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4954 aPersFlags.LowerCase();
4955 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
4957 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
4961 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4963 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4965 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4967 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
4970 else if (aNameCase == "-trsfperspos"
4971 || aNameCase == "-perspos")
4973 if (anArgIter + 2 >= theArgNb
4974 || aTrsfPers.IsNull())
4976 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4980 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4981 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4982 TCollection_AsciiString aZ = "0";
4983 if (!aX.IsRealValue()
4984 || !aY.IsRealValue())
4986 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4989 if (anArgIter + 1 < theArgNb)
4991 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
4992 if (aTemp.IsRealValue())
4999 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
5000 if (aTrsfPers->IsZoomOrRotate())
5002 aTrsfPers->SetAnchorPoint (aPnt);
5004 else if (aTrsfPers->IsTrihedronOr2d())
5006 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
5009 else if (aNameCase == "-layer"
5010 || aNameCase == "-zlayer")
5013 if (anArgIter >= theArgNb
5014 || !ViewerTest::ParseZLayer (theArgVec[anArgIter], aZLayer)
5015 || aZLayer == Graphic3d_ZLayerId_UNKNOWN)
5017 std::cerr << "Error: wrong syntax at " << aName << ".\n";
5021 else if (aNameCase == "-view"
5022 || aNameCase == "-inview")
5024 toDisplayInView = Standard_True;
5026 else if (aNameCase == "-redisplay")
5028 toReDisplay = Standard_True;
5030 else if (aNameCase == "-erased"
5031 || aNameCase == "-load")
5033 aDispStatus = AIS_DS_Erased;
5037 aNamesOfDisplayIO.Append (aName);
5041 if (aNamesOfDisplayIO.IsEmpty())
5043 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5047 // Display interactive objects
5048 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
5050 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value (anIter);
5051 Handle(AIS_InteractiveObject) aShape;
5052 if (!GetMapOfAIS().Find2 (aName, aShape))
5054 // create the AIS_Shape from a name
5055 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
5056 if (!aDrawShape.IsNull())
5058 aShape = new AIS_Shape (aDrawShape);
5059 if (isMutable != -1)
5061 aShape->SetMutable (isMutable == 1);
5063 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
5065 aShape->SetZLayer (aZLayer);
5069 aCtx->SetTransformPersistence (aShape, aTrsfPers);
5071 if (anObjDispMode != -2)
5073 if (anObjDispMode == -1)
5075 aShape->UnsetDisplayMode();
5077 if (!aShape->AcceptDisplayMode (anObjDispMode))
5079 std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjDispMode << " display mode\n";
5084 aShape->SetDisplayMode (anObjDispMode);
5087 if (anObjHighMode != -2)
5089 if (anObjHighMode != -1
5090 && !aShape->AcceptDisplayMode (anObjHighMode))
5092 std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjHighMode << " display mode\n";
5095 aShape->SetHilightMode (anObjHighMode);
5098 GetMapOfAIS().Bind (aShape, aName);
5099 Standard_Integer aDispMode = aShape->HasDisplayMode()
5100 ? aShape->DisplayMode()
5101 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5102 ? aCtx->DisplayMode()
5104 Standard_Integer aSelMode = -1;
5105 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5107 aSelMode = aShape->GlobalSelectionMode();
5110 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5111 if (toDisplayInView)
5113 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
5115 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
5117 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5122 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
5127 if (isMutable != -1)
5129 aShape->SetMutable (isMutable == 1);
5131 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
5133 aShape->SetZLayer (aZLayer);
5137 aCtx->SetTransformPersistence (aShape, aTrsfPers);
5139 if (anObjDispMode != -2)
5141 aShape->SetDisplayMode (anObjDispMode);
5143 if (anObjHighMode != -2)
5145 aShape->SetHilightMode (anObjHighMode);
5147 Standard_Integer aDispMode = aShape->HasDisplayMode()
5148 ? aShape->DisplayMode()
5149 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5150 ? aCtx->DisplayMode()
5152 Standard_Integer aSelMode = -1;
5153 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5155 aSelMode = aShape->GlobalSelectionMode();
5158 if (aShape->Type() == AIS_KOI_Datum)
5160 aCtx->Display (aShape, Standard_False);
5164 theDI << "Display " << aName << "\n";
5166 // update the Shape in the AIS_Shape
5167 TopoDS_Shape aNewShape = DBRep::GetExisting (aName);
5168 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
5169 if (!aShapePrs.IsNull())
5171 if (!aShapePrs->Shape().IsEqual (aNewShape))
5173 toReDisplay = Standard_True;
5175 aShapePrs->Set (aNewShape);
5179 aCtx->Redisplay (aShape, Standard_False);
5184 aCtx->Erase (aShape, Standard_False);
5186 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5187 if (toDisplayInView)
5189 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5197 //=======================================================================
5198 //function : VNbDisplayed
5199 //purpose : Returns number of displayed objects
5200 //=======================================================================
5201 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
5202 Standard_Integer theArgsNb,
5203 const char** theArgVec)
5207 theDi << "Usage : " << theArgVec[0] << "\n";
5211 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5212 if (aContextAIS.IsNull())
5214 std::cout << theArgVec[0] << "AIS context is not available.\n";
5218 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5219 if(aContext.IsNull())
5221 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
5225 AIS_ListOfInteractive aListOfIO;
5226 aContextAIS->DisplayedObjects (aListOfIO);
5228 theDi << aListOfIO.Extent() << "\n";
5232 //===============================================================================================
5233 //function : VUpdate
5235 //===============================================================================================
5236 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
5238 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5239 if (aContextAIS.IsNull())
5241 std::cout << theArgVec[0] << "AIS context is not available.\n";
5247 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
5251 AIS_ListOfInteractive aListOfIO;
5252 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5254 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
5256 Handle(AIS_InteractiveObject) anAISObj;
5257 GetMapOfAIS().Find2 (aName, anAISObj);
5258 if (anAISObj.IsNull())
5260 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
5264 aListOfIO.Append (anAISObj);
5267 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
5268 for (; anIOIt.More(); anIOIt.Next())
5270 aContextAIS->Update (anIOIt.Value(), Standard_False);
5273 aContextAIS->UpdateCurrentViewer();
5278 //==============================================================================
5279 //function : VShading
5280 //purpose : Sharpen or roughten the quality of the shading
5281 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
5282 //==============================================================================
5283 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
5285 Standard_Real myDevCoef;
5286 Handle(AIS_InteractiveObject) TheAisIO;
5289 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
5293 myDevCoef =Draw::Atof(argv[2]);
5296 TCollection_AsciiString name=argv[1];
5297 GetMapOfAIS().Find2(name, TheAisIO);
5298 if (TheAisIO.IsNull())
5300 TopoDS_Shape aDrawShape = DBRep::GetExisting (name);
5301 if (!aDrawShape.IsNull())
5303 TheAisIO = new AIS_Shape (aDrawShape);
5308 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5310 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
5312 TheAISContext()->Redisplay (TheAisIO, Standard_True);
5316 //! Auxiliary method to print Interactive Object information
5317 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
5318 const Handle(AIS_InteractiveObject)& theObj,
5319 Draw_Interpretor& theDI)
5321 if (theObj.IsNull())
5323 theDI << "NULL presentation\n";
5327 theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ")
5328 << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ")
5329 << (theDetected.Contains (theObj) ? " Detected" : " ")
5331 if (theObj->Type() == AIS_KOI_Datum)
5334 if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
5335 else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; }
5336 else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; }
5337 else if (theObj->Signature() == 5) { theDI << " AIS_Line"; }
5338 else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; }
5339 else if (theObj->Signature() == 1) { theDI << " AIS_Point"; }
5340 else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
5343 else if (theObj->Type() == AIS_KOI_Shape
5344 && theObj->Signature() == 0)
5346 theDI << " AIS_Shape";
5348 else if (theObj->Type() == AIS_KOI_Relation)
5350 // AIS_Dimention and AIS_Relation
5351 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (theObj);
5352 switch (aRelation->KindOfDimension())
5354 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
5355 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
5356 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
5357 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
5358 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
5359 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
5360 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
5361 default: theDI << " UNKNOWN dimension"; break;
5366 theDI << " UserPrs";
5368 theDI << " (" << theObj->DynamicType()->Name() << ")";
5371 //! Print information about locally selected sub-shapes
5372 template <typename T>
5373 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
5375 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
5376 TCollection_AsciiString aPrevName;
5377 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
5379 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
5380 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
5381 if (aShapeIO.IsNull() || anOwner.IsNull())
5385 if (anOwner == aShapeIO->GlobalSelOwner())
5388 const TopoDS_Shape aSubShape = theContext->SelectedShape();
5389 if (aSubShape.IsNull()
5390 || aShapeIO.IsNull()
5391 || !GetMapOfAIS().IsBound1 (aShapeIO))
5396 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
5397 TopTools_MapOfShape aFilter;
5398 Standard_Integer aNumber = 0;
5399 const TopoDS_Shape aShape = aShapeIO->Shape();
5400 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
5401 anIter.More(); anIter.Next())
5403 if (!aFilter.Add (anIter.Current()))
5405 continue; // filter duplicates
5409 if (!anIter.Current().IsSame (aSubShape))
5414 Standard_CString aShapeName = NULL;
5415 switch (aSubShape.ShapeType())
5417 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
5418 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
5419 case TopAbs_SOLID: aShapeName = " Solid"; break;
5420 case TopAbs_SHELL: aShapeName = " Shell"; break;
5421 case TopAbs_FACE: aShapeName = " Face"; break;
5422 case TopAbs_WIRE: aShapeName = " Wire"; break;
5423 case TopAbs_EDGE: aShapeName = " Edge"; break;
5424 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
5426 case TopAbs_SHAPE: aShapeName = " Shape"; break;
5429 if (aParentName != aPrevName)
5431 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
5432 aPrevName = aParentName;
5434 theDI << " " << aShapeName << " #" << aNumber << "\n";
5440 //==============================================================================
5443 //==============================================================================
5444 static Standard_Integer VState (Draw_Interpretor& theDI,
5445 Standard_Integer theArgNb,
5446 Standard_CString* theArgVec)
5448 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
5451 std::cerr << "Error: No opened viewer!\n";
5455 Standard_Boolean toPrintEntities = Standard_False;
5456 Standard_Boolean toCheckSelected = Standard_False;
5458 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
5460 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
5461 anOption.LowerCase();
5462 if (anOption == "-detectedentities"
5463 || anOption == "-entities")
5465 toPrintEntities = Standard_True;
5467 else if (anOption == "-hasselected")
5469 toCheckSelected = Standard_True;
5473 if (toCheckSelected)
5475 aCtx->InitSelected();
5476 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
5477 theDI << "Check if context has selected shape: " << hasSelected << "\n";
5482 if (toPrintEntities)
5484 theDI << "Detected entities:\n";
5485 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
5487 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
5488 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
5490 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
5491 const Handle(Select3D_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
5492 const Handle(SelectMgr_EntityOwner)& anOwner = anEntity->OwnerId();
5493 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5495 TCollection_AsciiString aName;
5496 GetMapOfAIS().Find1 (anObj, aName);
5497 aName.LeftJustify (20, ' ');
5498 char anInfoStr[512];
5500 " Depth: %g Distance: %g Point: %g %g %g",
5503 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
5504 theDI << " " << aName
5506 << " (" << anEntity->DynamicType()->Name() << ")"
5509 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
5510 if (!aBRepOwner.IsNull())
5512 theDI << " Detected Shape: "
5513 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
5517 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
5518 if (!aWire.IsNull())
5520 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
5521 theDI << " Detected Child: "
5522 << aSen->DynamicType()->Name()
5526 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
5527 if (!aPrimArr.IsNull())
5529 theDI << " Detected Element: "
5530 << aPrimArr->LastDetectedElement()
5537 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
5538 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
5540 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
5543 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
5547 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5549 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
5550 Handle(AIS_InteractiveObject) anObj;
5551 if (!GetMapOfAIS().Find2 (anObjName, anObj))
5553 theDI << anObjName << " doesn't exist!\n";
5557 TCollection_AsciiString aName = anObjName;
5558 aName.LeftJustify (20, ' ');
5559 theDI << " " << aName << " ";
5560 objInfo (aDetected, anObj, theDI);
5566 if (aCtx->NbSelected() > 0 && !toShowAll)
5568 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
5569 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
5571 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
5572 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5573 // handle whole object selection
5574 if (anOwner == anObj->GlobalSelOwner())
5576 TCollection_AsciiString aName;
5577 GetMapOfAIS().Find1 (anObj, aName);
5578 aName.LeftJustify (20, ' ');
5579 theDI << aName << " ";
5580 objInfo (aDetected, anObj, theDI);
5585 // process selected sub-shapes
5586 printLocalSelectionInfo (aCtx, theDI);
5591 theDI << "Neutral-point state:\n";
5592 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5593 anObjIter.More(); anObjIter.Next())
5595 if (anObjIter.Key1().IsNull())
5600 TCollection_AsciiString aName = anObjIter.Key2();
5601 aName.LeftJustify (20, ' ');
5602 theDI << " " << aName << " ";
5603 objInfo (aDetected, anObjIter.Key1(), theDI);
5606 printLocalSelectionInfo (aCtx, theDI);
5610 //=======================================================================
5611 //function : PickShape
5612 //purpose : First Activate the rightmode + Put Filters to be able to
5613 // pick objets that are of type <TheType>...
5614 //=======================================================================
5616 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
5617 const Standard_Integer theMaxPick)
5619 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
5620 PickShapes (theShapeType, aResArray, theMaxPick);
5621 return aResArray->First();
5624 //=======================================================================
5625 //function : PickShapes
5627 //=======================================================================
5628 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
5629 Handle(TopTools_HArray1OfShape)& theResArray,
5630 const Standard_Integer theMaxPick)
5632 const Standard_Integer aNbToReach = theResArray->Length();
5635 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
5638 // step 1: prepare the data
5639 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5640 aCtx->RemoveFilters();
5641 AIS_ListOfInteractive aDispObjects;
5642 aCtx->DisplayedObjects (aDispObjects);
5643 if (theShapeType == TopAbs_SHAPE)
5645 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
5649 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
5652 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
5653 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5655 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5657 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5661 // step 2 : wait for the selection...
5662 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
5663 Standard_Integer argccc = 5;
5664 const char *bufff[] = { "A", "B", "C", "D", "E" };
5665 const char **argvvv = (const char** )bufff;
5666 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
5668 while (ViewerMainLoop (argccc, argvvv)) {}
5669 Standard_Integer aNbStored = aCtx->NbSelected();
5670 if (aNbStored != aNbPickGood)
5672 aNbPickGood = aNbStored;
5678 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
5681 // step3 get result.
5682 if (aNbPickFail >= aNbToReach)
5684 return Standard_False;
5687 Standard_Integer anIndex = theResArray->Lower();
5688 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
5690 if (aCtx->HasSelectedShape())
5692 theResArray->SetValue (anIndex, aCtx->SelectedShape());
5696 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
5697 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
5701 aCtx->RemoveFilters();
5702 if (theShapeType != TopAbs_SHAPE)
5704 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5706 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5708 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5712 return Standard_True;
5715 //=======================================================================
5716 //function : VPickShape
5718 //=======================================================================
5719 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5721 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
5724 TCollection_AsciiString aShapeArg (argv[1]);
5725 aShapeArg.LowerCase();
5726 aShapeType = TopAbs_COMPOUND;
5727 if (aShapeArg == "v"
5728 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
5729 else if (aShapeArg == "e"
5730 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
5731 else if (aShapeArg == "w"
5732 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
5733 else if (aShapeArg == "f"
5734 || aShapeArg == "face") aShapeType = TopAbs_FACE;
5735 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
5736 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
5737 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
5740 std::cout << "Syntax error at '" << argv[1] << "'\n";
5745 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5746 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
5748 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
5751 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
5752 if (aPickedShape.IsNull())
5757 TCollection_AsciiString aName;
5764 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5765 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5768 DBRep::Set (aName.ToCString(), aPickedShape);
5769 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5770 ViewerTest::Display (aName, aShapePrs, false, true);
5771 di << "Name of picked shape: " << aName <<"\n";
5775 TCollection_AsciiString aName (argv[2]);
5777 const Standard_Boolean isAutoNaming = aName == ".";
5778 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5779 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5781 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5783 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5785 if (!aPickedShape.IsNull()
5788 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5789 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5793 aName = argv[1 + aPickedIter];
5796 DBRep::Set (aName.ToCString(), aPickedShape);
5797 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5798 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5799 ViewerTest::Display (aName, aShapePrs, false, true);
5803 TheAISContext()->UpdateCurrentViewer();
5807 //=======================================================================
5808 //function : VSelFilter
5810 //=======================================================================
5811 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5812 const char** theArgv)
5814 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5815 if (aContext.IsNull())
5817 std::cout << "Error: AIS context is not available.\n";
5821 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5823 TCollection_AsciiString anArg (theArgv[anArgIter]);
5825 if (anArg == "-clear")
5827 aContext->RemoveFilters();
5829 else if (anArg == "-type"
5830 && anArgIter + 1 < theArgc)
5832 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5833 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5834 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5836 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5840 Handle(SelectMgr_Filter) aFilter;
5841 if (aShapeType == TopAbs_SHAPE)
5843 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5847 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5849 aContext->AddFilter (aFilter);
5853 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5860 //=======================================================================
5861 //function : VPickSelected
5863 //=======================================================================
5864 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5866 static Standard_Integer aCount = 0;
5867 TCollection_AsciiString aName = "PickedShape_";
5875 aName = aName + aCount++ + "_";
5878 Standard_Integer anIdx = 0;
5879 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5881 TopoDS_Shape aShape;
5882 if (TheAISContext()->HasSelectedShape())
5884 aShape = TheAISContext()->SelectedShape();
5888 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5889 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5892 TCollection_AsciiString aCurrentName = aName;
5895 aCurrentName += anIdx;
5898 DBRep::Set ((aCurrentName).ToCString(), aShape);
5900 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5901 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5902 TheAISContext()->Display (aNewShape, Standard_False);
5905 TheAISContext()->UpdateCurrentViewer();
5910 //=======================================================================
5911 //function : list of known objects
5913 //=======================================================================
5914 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5916 // 1234567890 12345678901234567 123456789
5917 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5918 TCollection_AsciiString BlankLine(64,'_');
5919 Standard_Integer i ;
5921 di<<"/n"<<BlankLine.ToCString()<<"\n";
5924 Colum[i].Center(20,' ');
5926 di<<"|"<<Colum[i].ToCString();
5929 di<<BlankLine.ToCString()<<"\n";
5931 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5932 const char ** names = GetTypeNames();
5934 TCollection_AsciiString curstring;
5935 TCollection_AsciiString curcolum[3];
5938 // les objets de type Datum..
5939 curcolum[1]+="Datum";
5941 curcolum[0].Clear();
5942 curcolum[0] += names[i];
5944 curcolum[2].Clear();
5945 curcolum[2]+=TCollection_AsciiString(i+1);
5947 for(Standard_Integer j =0;j<=2;j++){
5948 curcolum[j].Center(20,' ');
5949 di<<"|"<<curcolum[j].ToCString();
5953 di<<BlankLine.ToCString()<<"\n";
5955 // les objets de type shape
5956 curcolum[1].Clear();
5957 curcolum[1]+="Shape";
5958 curcolum[1].Center(20,' ');
5961 curcolum[0].Clear();
5962 curcolum[0] += names[7+i];
5963 curcolum[2].Clear();
5964 curcolum[2]+=TCollection_AsciiString(i);
5966 for(Standard_Integer j =0;j<=2;j++){
5967 curcolum[j].Center(20,' ');
5968 di<<"|"<<curcolum[j].ToCString();
5972 di<<BlankLine.ToCString()<<"\n";
5973 // les IO de type objet...
5974 curcolum[1].Clear();
5975 curcolum[1]+="Object";
5976 curcolum[1].Center(20,' ');
5978 curcolum[0].Clear();
5979 curcolum[0] += names[10+i];
5980 curcolum[2].Clear();
5981 curcolum[2]+=TCollection_AsciiString(i);
5983 for(Standard_Integer j =0;j<=2;j++){
5984 curcolum[j].Center(20,' ');
5985 di<<"|"<<curcolum[j].ToCString();
5989 di<<BlankLine.ToCString()<<"\n";
5990 // les contraintes et dimensions.
5991 // pour l'instant on separe juste contraintes et dimensions...
5992 // plus tard, on detaillera toutes les sortes...
5993 curcolum[1].Clear();
5994 curcolum[1]+="Relation";
5995 curcolum[1].Center(20,' ');
5997 curcolum[0].Clear();
5998 curcolum[0] += names[12+i];
5999 curcolum[2].Clear();
6000 curcolum[2]+=TCollection_AsciiString(i);
6002 for(Standard_Integer j =0;j<=2;j++){
6003 curcolum[j].Center(20,' ');
6004 di<<"|"<<curcolum[j].ToCString();
6008 di<<BlankLine.ToCString()<<"\n";
6015 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
6017 if(argc!=2) return 1;
6019 AIS_KindOfInteractive TheType;
6020 Standard_Integer TheSign(-1);
6021 GetTypeAndSignfromString(argv[1],TheType,TheSign);
6024 AIS_ListOfInteractive LIO;
6026 // en attendant l'amelioration ais pour les dimensions...
6028 Standard_Integer dimension_status(-1);
6029 if(TheType==AIS_KOI_Relation){
6030 dimension_status = TheSign ==1 ? 1 : 0;
6034 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
6035 Handle(AIS_InteractiveObject) curio;
6036 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
6039 if(dimension_status == -1)
6040 TheAISContext()->Erase(curio,Standard_False);
6042 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
6043 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
6044 (dimension_status==1 && KOD != AIS_KOD_NONE))
6045 TheAISContext()->Erase(curio,Standard_False);
6048 TheAISContext()->UpdateCurrentViewer();
6051 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
6053 if(argc!=2) return 1;
6055 AIS_KindOfInteractive TheType;
6056 Standard_Integer TheSign(-1);
6057 GetTypeAndSignfromString(argv[1],TheType,TheSign);
6059 // en attendant l'amelioration ais pour les dimensions...
6061 Standard_Integer dimension_status(-1);
6062 if(TheType==AIS_KOI_Relation){
6063 dimension_status = TheSign ==1 ? 1 : 0;
6067 AIS_ListOfInteractive LIO;
6068 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
6069 Handle(AIS_InteractiveObject) curio;
6070 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
6072 if(dimension_status == -1)
6073 TheAISContext()->Display(curio,Standard_False);
6075 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
6076 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
6077 (dimension_status==1 && KOD != AIS_KOD_NONE))
6078 TheAISContext()->Display(curio,Standard_False);
6083 TheAISContext()->UpdateCurrentViewer();
6087 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
6089 std::ifstream s(a[1]);
6090 BRep_Builder builder;
6092 BRepTools::Read(shape, s, builder);
6093 DBRep::Set(a[1], shape);
6094 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6095 Handle(AIS_Shape) ais = new AIS_Shape(shape);
6096 Ctx->Display (ais, Standard_True);
6100 //===============================================================================================
6103 //===============================================================================================
6104 static int VBsdf (Draw_Interpretor& theDI,
6105 Standard_Integer theArgsNb,
6106 const char** theArgVec)
6108 Handle(V3d_View) aView = ViewerTest::CurrentView();
6109 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6111 || aViewer.IsNull())
6113 std::cerr << "No active viewer!\n";
6117 ViewerTest_CmdParser aCmd;
6119 aCmd.SetDescription ("Adjusts parameters of material BSDF:");
6121 aCmd.AddOption ("print|echo|p", "Prints BSDF");
6123 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
6125 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
6126 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
6127 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
6128 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
6129 aCmd.AddOption ("le", "Radiance emitted by surface");
6131 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
6132 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
6134 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
6135 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
6137 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
6138 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
6140 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
6142 aCmd.Parse (theArgsNb, theArgVec);
6144 if (aCmd.HasOption ("help"))
6146 theDI.PrintHelp (theArgVec[0]);
6150 // check viewer update mode
6151 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
6152 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6154 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
6161 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
6162 Handle(AIS_InteractiveObject) anIObj;
6163 if (!GetMapOfAIS().Find2 (aName, anIObj))
6165 std::cerr << "Use 'vdisplay' before\n";
6169 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
6170 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
6172 if (aCmd.HasOption ("print"))
6175 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
6176 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
6177 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
6178 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
6179 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
6181 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6183 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
6184 : aBSDF.FresnelBase.Serialize();
6186 theDI << (aLayerID < 1 ? "Coat Fresnel: "
6187 : "Base Fresnel: ");
6189 if (aFresnel.x() >= 0.f)
6191 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
6192 << "G = " << aFresnel.g() << ", "
6193 << "B = " << aFresnel.b() << "\n";
6195 else if (aFresnel.x() >= -1.5f)
6197 theDI << "Constant " << aFresnel.z() << "\n";
6199 else if (aFresnel.x() >= -2.5f)
6201 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
6202 << "K = " << aFresnel.z() << "\n";
6206 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
6210 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
6211 << "Base roughness: " << aBSDF.Ks.w() << "\n"
6212 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
6213 << "Absorption color: " << aBSDF.Absorption.r() << ", "
6214 << aBSDF.Absorption.g() << ", "
6215 << aBSDF.Absorption.b() << "\n";
6220 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
6222 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
6225 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
6227 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
6230 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
6232 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
6235 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
6237 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
6239 aBSDF.Absorption.r() = aRGB.r();
6240 aBSDF.Absorption.g() = aRGB.g();
6241 aBSDF.Absorption.b() = aRGB.b();
6244 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
6248 if (aCmd.HasOption ("kc", 3))
6250 aKc = aCmd.ArgVec3f ("kc");
6254 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
6257 aBSDF.Kc.r() = aKc.r();
6258 aBSDF.Kc.g() = aKc.g();
6259 aBSDF.Kc.b() = aKc.b();
6262 if (aCmd.HasOption ("kd", 3))
6264 aBSDF.Kd = aCmd.ArgVec3f ("kd");
6266 else if (aCmd.HasOption ("kd", 1, Standard_True))
6268 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
6271 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
6275 if (aCmd.HasOption ("ks", 3))
6277 aKs = aCmd.ArgVec3f ("ks");
6281 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
6284 aBSDF.Ks.r() = aKs.r();
6285 aBSDF.Ks.g() = aKs.g();
6286 aBSDF.Ks.b() = aKs.b();
6289 if (aCmd.HasOption ("kt", 3))
6291 aBSDF.Kt = aCmd.ArgVec3f ("kt");
6293 else if (aCmd.HasOption ("kt", 1, Standard_True))
6295 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
6298 if (aCmd.HasOption ("le", 3))
6300 aBSDF.Le = aCmd.ArgVec3f ("le");
6302 else if (aCmd.HasOption ("le", 1, Standard_True))
6304 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
6307 const std::string aFresnelErrorMessage =
6308 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
6310 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6312 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
6315 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
6317 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6318 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6320 if (aFresnelType == "schlick")
6322 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
6323 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
6324 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
6326 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
6327 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
6328 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
6330 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
6334 theDI << aFresnelErrorMessage.c_str() << "\n";
6337 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
6339 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6340 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6342 if (aFresnelType == "conductor")
6344 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6345 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
6347 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
6351 theDI << aFresnelErrorMessage.c_str() << "\n";
6354 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
6356 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6357 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6359 if (aFresnelType == "constant")
6361 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6363 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
6365 else if (aFresnelType == "dielectric")
6367 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6369 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
6373 theDI << aFresnelErrorMessage.c_str() << "\n";
6378 if (aCmd.HasOption ("normalize"))
6383 aMaterial.SetBSDF (aBSDF);
6384 anIObj->SetMaterial (aMaterial);
6389 //==============================================================================
6390 //function : VLoadSelection
6391 //purpose : Adds given objects to map of AIS and loads selection primitives for them
6392 //==============================================================================
6393 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
6394 Standard_Integer theArgNb,
6395 const char** theArgVec)
6399 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
6403 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
6406 ViewerTest::ViewerInit();
6407 aCtx = ViewerTest::GetAISContext();
6410 // Parse input arguments
6411 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6413 const TCollection_AsciiString aName = theArgVec[anArgIter];
6414 Handle(AIS_InteractiveObject) aShape;
6415 if (!GetMapOfAIS().Find2 (aName, aShape))
6417 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
6418 if (!aDrawShape.IsNull())
6420 aShape = new AIS_Shape (aDrawShape);
6421 GetMapOfAIS().Bind (aShape, aName);
6424 if (aShape.IsNull())
6426 std::cout << "Syntax error: presentation '" << aName << "' not found\n";
6430 aCtx->Load (aShape, -1);
6431 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
6436 //==============================================================================
6437 //function : ViewerTest::Commands
6438 //purpose : Add all the viewer command in the Draw_Interpretor
6439 //==============================================================================
6441 void ViewerTest::Commands(Draw_Interpretor& theCommands)
6443 ViewerTest::ViewerCommands(theCommands);
6444 ViewerTest::RelationCommands(theCommands);
6445 ViewerTest::ObjectCommands(theCommands);
6446 ViewerTest::FilletCommands(theCommands);
6447 ViewerTest::OpenGlCommands(theCommands);
6449 const char *group = "AIS_Display";
6452 theCommands.Add("visos",
6453 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
6454 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
6455 __FILE__, visos, group);
6457 theCommands.Add("vdisplay",
6458 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
6459 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
6460 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
6461 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
6462 "\n\t\t: |topRight|bottomLeft|bottomRight}"
6463 "\n\t\t: [offsetX offsetY]]]"
6464 "\n\t\t: [-dispMode mode] [-highMode mode]"
6465 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
6466 "\n\t\t: [-redisplay] [-erased]"
6467 "\n\t\t: name1 [name2] ... [name n]"
6468 "\n\t\t: Displays named objects."
6469 "\n\t\t: Option -local enables displaying of objects in local"
6470 "\n\t\t: selection context. Local selection context will be opened"
6471 "\n\t\t: if there is not any."
6472 "\n\t\t: -noupdate Suppresses viewer redraw call."
6473 "\n\t\t: -mutable Enables optimizations for mutable objects."
6474 "\n\t\t: -neutral Draws objects in main viewer."
6475 "\n\t\t: -erased Loads the object into context, but does not display it."
6476 "\n\t\t: -layer Sets z-layer for objects."
6477 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
6478 "\n\t\t: options can be used for the default z-layers."
6479 "\n\t\t: -top Draws object on top of main presentations"
6480 "\n\t\t: but below topmost."
6481 "\n\t\t: -topmost Draws in overlay for 3D presentations."
6482 "\n\t\t: with independent Depth."
6483 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
6484 "\n\t\t: (On-Screen-Display)"
6485 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
6486 "\n\t\t: (On-Screen-Display)"
6487 "\n\t\t: -selectable|-noselect Controls selection of objects."
6488 "\n\t\t: -trsfPers Sets a transform persistence flags."
6489 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
6490 "\n\t\t: -2d Displays object in screen coordinates."
6491 "\n\t\t: (DY looks up)"
6492 "\n\t\t: -dispmode Sets display mode for objects."
6493 "\n\t\t: -highmode Sets hilight mode for objects."
6494 "\n\t\t: -redisplay Recomputes presentation of objects.",
6495 __FILE__, VDisplay2, group);
6497 theCommands.Add ("vnbdisplayed",
6499 "\n\t\t: Returns number of displayed objects",
6500 __FILE__, VNbDisplayed, group);
6502 theCommands.Add ("vupdate",
6503 "vupdate name1 [name2] ... [name n]"
6504 "\n\t\t: Updates named objects in interactive context",
6505 __FILE__, VUpdate, group);
6507 theCommands.Add("verase",
6508 "verase [-noupdate|-update] [-local] [name1] ... [name n] [-noerror]"
6509 "\n\t\t: Erases selected or named objects."
6510 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
6511 "\n\t\t: Option -local enables erasing of selected or named objects without"
6512 "\n\t\t: closing local selection context."
6513 "\n\t\t: Option -noerror prevents exception on non-existing objects.",
6514 __FILE__, VErase, group);
6516 theCommands.Add("vremove",
6517 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n] [-noerror]"
6518 "or vremove [-context] -all to remove all objects"
6519 "\n\t\t: Removes selected or named objects."
6520 "\n\t\t If -context is in arguments, the objects are not deleted"
6521 "\n\t\t from the map of objects and names."
6522 "\n\t\t: Option -local enables removing of selected or named objects without"
6523 "\n\t\t: closing local selection context. Empty local selection context will be"
6525 "\n\t\t: Option -noupdate suppresses viewer redraw call."
6526 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects."
6527 "\n\t\t: Option -noerror prevents exception on non-existing objects.",
6528 __FILE__, VRemove, group);
6530 theCommands.Add("vdonly",
6531 "vdonly [-noupdate|-update] [name1] ... [name n]"
6532 "\n\t\t: Displays only selected or named objects",
6533 __FILE__,VDonly2,group);
6535 theCommands.Add("vdisplayall",
6537 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
6538 __FILE__, VDisplayAll, group);
6540 theCommands.Add("veraseall",
6542 "\n\t\t: Erases all objects displayed in the viewer.",
6543 __FILE__, VErase, group);
6545 theCommands.Add("verasetype",
6547 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
6548 __FILE__, VEraseType, group);
6549 theCommands.Add("vbounding",
6550 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
6551 "\n\t\t: [-print] [-hide]"
6552 "\n\t\t: Temporarily display bounding box of specified Interactive"
6553 "\n\t\t: Objects, or print it to console if -print is specified."
6554 "\n\t\t: Already displayed box might be hidden by -hide option.",
6555 __FILE__,VBounding,group);
6557 theCommands.Add("vdisplaytype",
6558 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
6559 __FILE__,VDisplayType,group);
6561 theCommands.Add("vsetdispmode",
6562 "vsetdispmode [name] mode(1,2,..)"
6563 "\n\t\t: Sets display mode for all, selected or named objects.",
6564 __FILE__,VDispMode,group);
6566 theCommands.Add("vunsetdispmode",
6567 "vunsetdispmode [name]"
6568 "\n\t\t: Unsets custom display mode for selected or named objects.",
6569 __FILE__,VDispMode,group);
6571 theCommands.Add("vdir",
6572 "vdir [mask] [-list]"
6573 "\n\t\t: Lists all objects displayed in 3D viewer"
6574 "\n\t\t: mask - name filter like prefix*"
6575 "\n\t\t: -list - format list with new-line per name; OFF by default",
6576 __FILE__,VDir,group);
6578 #ifdef HAVE_FREEIMAGE
6579 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
6581 #define DUMP_FORMATS "{ppm}"
6583 theCommands.Add("vdump",
6584 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
6585 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
6586 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
6587 "\n\t\t: [-tileSize Size=0]"
6588 "\n\t\t: Dumps content of the active view into image file",
6589 __FILE__,VDump,group);
6591 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
6592 __FILE__,VSubInt,group);
6594 theCommands.Add("vaspects",
6595 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
6596 "\n\t\t: [-setVisibility 0|1]"
6597 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
6598 "\n\t\t: [-setBackFaceColor Color]"
6599 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
6600 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
6601 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
6602 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
6603 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
6604 "\n\t\t: [-unsetMarkerType]"
6605 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
6606 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
6607 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
6608 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
6609 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
6610 "\n\t\t: [-isoontriangulation 0|1]"
6611 "\n\t\t: [-setMaxParamValue {value}]"
6612 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
6613 "\n\t\t: [-setShadingModel {unlit|flat|gouraud|phong}]"
6614 "\n\t\t: [-unsetShadingModel]"
6615 "\n\t\t: [-setInterior {solid|hatch|hidenline|point}]"
6616 "\n\t\t: [-unsetInterior] [-setHatch HatchStyle]"
6617 "\n\t\t: [-setFaceBoundaryDraw {0|1}] [-setMostContinuity {c0|c1|c2|c3|cn}"
6618 "\n\t\t: [-setFaceBoundaryWidth LineWidth] [-setFaceBoundaryColor R G B] [-setFaceBoundaryType LineType]"
6619 "\n\t\t: [-setDrawEdges {0|1}] [-setEdgeType LineType] [-setEdgeColor R G B] [-setQuadEdges {0|1}]"
6620 "\n\t\t: [-setDrawSilhouette {0|1}]"
6621 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
6622 "\n\t\t: Manage presentation properties of all, selected or named objects."
6623 "\n\t\t: When -subshapes is specified than following properties will be"
6624 "\n\t\t: assigned to specified sub-shapes."
6625 "\n\t\t: When -defaults is specified than presentation properties will be"
6626 "\n\t\t: assigned to all objects that have not their own specified properties"
6627 "\n\t\t: and to all objects to be displayed in the future."
6628 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier."
6629 "\n\t\t: See also vlistcolors and vlistmaterials to list named colors and materials"
6630 "\n\t\t: accepted by arguments -setMaterial and -setColor",
6631 __FILE__,VAspects,group);
6633 theCommands.Add("vsetcolor",
6634 "vsetcolor [-noupdate|-update] [name] ColorName"
6635 "\n\t\t: Sets color for all, selected or named objects."
6636 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
6637 __FILE__,VAspects,group);
6639 theCommands.Add("vunsetcolor",
6640 "vunsetcolor [-noupdate|-update] [name]"
6641 "\n\t\t: Resets color for all, selected or named objects."
6642 "\n\t\t: Alias for vaspects -unsetcolor [name].",
6643 __FILE__,VAspects,group);
6645 theCommands.Add("vsettransparency",
6646 "vsettransparency [-noupdate|-update] [name] Coefficient"
6647 "\n\t\t: Sets transparency for all, selected or named objects."
6648 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
6649 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
6650 __FILE__,VAspects,group);
6652 theCommands.Add("vunsettransparency",
6653 "vunsettransparency [-noupdate|-update] [name]"
6654 "\n\t\t: Resets transparency for all, selected or named objects."
6655 "\n\t\t: Alias for vaspects -unsettransp [name].",
6656 __FILE__,VAspects,group);
6658 theCommands.Add("vsetmaterial",
6659 "vsetmaterial [-noupdate|-update] [name] MaterialName"
6660 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
6661 __FILE__,VAspects,group);
6663 theCommands.Add("vunsetmaterial",
6664 "vunsetmaterial [-noupdate|-update] [name]"
6665 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
6666 __FILE__,VAspects,group);
6668 theCommands.Add("vsetwidth",
6669 "vsetwidth [-noupdate|-update] [name] width(0->10)"
6670 "\n\t\t: Alias for vaspects -setwidth [name] width.",
6671 __FILE__,VAspects,group);
6673 theCommands.Add("vunsetwidth",
6674 "vunsetwidth [-noupdate|-update] [name]"
6675 "\n\t\t: Alias for vaspects -unsetwidth [name].",
6676 __FILE__,VAspects,group);
6678 theCommands.Add("vsetinteriorstyle",
6679 "vsetinteriorstyle [-noupdate|-update] [name] Style"
6680 "\n\t\t: Alias for vaspects -setInterior [name] Style.",
6681 __FILE__,VAspects,group);
6683 theCommands.Add ("vsetedgetype",
6684 "vsetedgetype [name] [-type {solid, dash, dot}] [-color R G B] [-width value]"
6685 "\n\t\t: Alias for vaspects [name] -setEdgeType Type.",
6686 __FILE__, VAspects, group);
6688 theCommands.Add ("vunsetedgetype",
6689 "vunsetedgetype [name]"
6690 "\n\t\t: Alias for vaspects [name] -unsetEdgeType.",
6691 __FILE__, VAspects, group);
6693 theCommands.Add ("vshowfaceboundary",
6694 "vshowfaceboundary [name]"
6695 "\n\t\t: Alias for vaspects [name] -setFaceBoundaryDraw on",
6696 __FILE__, VAspects, group);
6698 theCommands.Add("vsensdis",
6699 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
6700 "\n\t\t: Standard entity types are those defined in Select3D package:"
6701 "\n\t\t: - sensitive box"
6702 "\n\t\t: - sensitive face"
6703 "\n\t\t: - sensitive curve"
6704 "\n\t\t: - sensitive segment"
6705 "\n\t\t: - sensitive circle"
6706 "\n\t\t: - sensitive point"
6707 "\n\t\t: - sensitive triangulation"
6708 "\n\t\t: - sensitive triangle"
6709 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
6710 __FILE__,VDispSensi,group);
6712 theCommands.Add("vsensera",
6713 "vsensera : erase active entities",
6714 __FILE__,VClearSensi,group);
6716 theCommands.Add("vsetshading",
6717 "vsetshading : vsetshading name Quality(default=0.0008) "
6718 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
6719 __FILE__,VShading,group);
6721 theCommands.Add("vunsetshading",
6722 "vunsetshading :vunsetshading name "
6723 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
6724 __FILE__,VShading,group);
6726 theCommands.Add ("vtexture",
6727 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
6728 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
6729 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
6730 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
6731 "\n\t\t: [-modulate {on|off}]"
6732 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
6733 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
6734 "\n\t\t: [-default]"
6735 "\n\t\t: The texture can be specified by filepath"
6736 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
6737 "\n\t\t: The options are:"
6738 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
6739 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
6740 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
6741 "\n\t\t: -modulate Enable or disable texture color modulation"
6742 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
6743 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
6744 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
6745 "\n\t\t: -setFilter Setup texture filter"
6746 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
6747 "\n\t\t: -default Sets texture mapping default parameters",
6748 __FILE__, VTexture, group);
6750 theCommands.Add("vtexscale",
6751 "vtexscale name ScaleU ScaleV"
6752 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
6753 __FILE__,VTexture,group);
6755 theCommands.Add("vtexorigin",
6756 "vtexorigin name OriginU OriginV"
6757 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
6758 __FILE__,VTexture,group);
6760 theCommands.Add("vtexrepeat",
6761 "vtexrepeat name RepeatU RepeatV"
6762 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
6765 theCommands.Add("vtexdefault",
6767 "\n\t\t: Alias for vtexture name -default.",
6770 theCommands.Add("vstate",
6771 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6772 "\n\t\t: Reports show/hidden state for selected or named objects"
6773 "\n\t\t: -entities - print low-level information about detected entities"
6774 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6775 __FILE__,VState,group);
6777 theCommands.Add("vpickshapes",
6778 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6779 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6780 "\n\t\t: Hold also Shift for multiple selection.",
6781 __FILE__, VPickShape, group);
6783 theCommands.Add("vtypes",
6784 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6787 theCommands.Add("vr",
6789 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6790 __FILE__,vr, group);
6792 theCommands.Add("vselfilter",
6793 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6794 "\nSets selection shape type filter in context or remove all filters."
6795 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6796 "\n : Option -clear remove all filters in context",
6797 __FILE__,VSelFilter,group);
6799 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6800 __FILE__, VPickSelected, group);
6802 theCommands.Add ("vloadselection",
6803 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6804 "\n\t\t: primitives for the shapes with names given without displaying them.",
6805 __FILE__, VLoadSelection, group);
6807 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6808 "\nAdjusts parameters of material BSDF:"
6809 "\n -help : Shows this message"
6810 "\n -print : Print BSDF"
6811 "\n -kd : Weight of the Lambertian BRDF"
6812 "\n -kr : Weight of the reflection BRDF"
6813 "\n -kt : Weight of the transmission BTDF"
6814 "\n -ks : Weight of the glossy Blinn BRDF"
6815 "\n -le : Self-emitted radiance"
6816 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6817 "\n Schlick x y z, Dielectric x, Conductor x y"
6818 "\n -roughness : Roughness of material (Blinn's exponent)"
6819 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6820 "\n -absorpcolor : Absorption color (only for transparent material)"
6821 "\n -normalize : Normalize BSDF coefficients",
6822 __FILE__, VBsdf, group);
6826 //=====================================================================
6827 //========================= for testing Draft and Rib =================
6828 //=====================================================================
6829 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6830 #include <DBRep.hxx>
6831 #include <TopoDS_Face.hxx>
6832 #include <gp_Pln.hxx>
6833 #include <AIS_KindOfSurface.hxx>
6834 #include <BRepOffsetAPI_DraftAngle.hxx>
6835 #include <Precision.hxx>
6836 #include <BRepAlgo.hxx>
6837 #include <OSD_Environment.hxx>
6838 #include <DrawTrSurf.hxx>
6839 //#include <DbgTools.hxx>
6840 //#include <FeatAlgo_MakeLinearForm.hxx>
6845 //=======================================================================
6846 //function : IsValid
6848 //=======================================================================
6849 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6850 const TopoDS_Shape& theResult,
6851 const Standard_Boolean closedSolid,
6852 const Standard_Boolean GeomCtrl)
6854 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6855 TCollection_AsciiString checkValid = check.Value();
6856 Standard_Boolean ToCheck = Standard_True;
6857 if (!checkValid.IsEmpty()) {
6859 std::cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6861 if ( checkValid=="true" || checkValid=="TRUE" ) {
6862 ToCheck= Standard_False;
6866 std::cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6869 Standard_Boolean IsValid = Standard_True;
6871 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6876 //===============================================================================
6877 // TDraft : test draft, uses AIS Viewer
6878 // Solid Face Plane Angle Reverse
6879 //===============================================================================
6880 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6882 if (argc < 5) return 1;
6883 // argv[1] - TopoDS_Shape Solid
6884 // argv[2] - TopoDS_Shape Face
6885 // argv[3] - TopoDS_Shape Plane
6886 // argv[4] - Standard_Real Angle
6887 // argv[5] - Standard_Integer Reverse
6889 // Sprintf(prefix, argv[1]);
6890 Standard_Real anAngle = 0;
6891 Standard_Boolean Rev = Standard_False;
6892 Standard_Integer rev = 0;
6893 TopoDS_Shape Solid = DBRep::Get (argv[1]);
6894 TopoDS_Shape face = DBRep::Get (argv[2]);
6895 TopoDS_Face Face = TopoDS::Face(face);
6896 TopoDS_Shape Plane = DBRep::Get (argv[3]);
6897 if (Plane.IsNull ()) {
6898 di << "TEST : Plane is NULL\n";
6901 anAngle = Draw::Atof(argv[4]);
6902 anAngle = 2*M_PI * anAngle / 360.0;
6904 Handle( Geom_Surface )aSurf;
6905 AIS_KindOfSurface aSurfType;
6906 Standard_Real Offset;
6908 if(argc > 4) { // == 5
6909 rev = Draw::Atoi(argv[5]);
6910 Rev = (rev)? Standard_True : Standard_False;
6913 TopoDS_Face face2 = TopoDS::Face(Plane);
6914 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6916 di << "TEST : Can't find plane\n";
6920 aDir = aPln.Axis().Direction();
6923 if (Plane.Orientation() == TopAbs_REVERSED)
6925 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6927 BRepOffsetAPI_DraftAngle Draft (Solid);
6929 if(Abs(anAngle)< Precision::Angular()) {
6930 di << "TEST : NULL angle\n";
6933 if(Rev) anAngle = - anAngle;
6934 Draft.Add (Face, aDir, anAngle, aPln);
6936 if (!Draft.IsDone()) {
6937 di << "TEST : Draft Not DONE \n";
6940 TopTools_ListOfShape Larg;
6942 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6943 di << "TEST : DesignAlgo returns Not valid\n";
6947 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6948 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6950 if ( !ais.IsNull() ) {
6951 ais->SetColor(DEFAULT_COLOR);
6952 ais->SetMaterial(DEFAULT_MATERIAL);
6953 // Display the AIS_Shape without redraw
6954 Ctx->Display(ais, Standard_False);
6956 const char *Name = "draft1";
6957 Handle(AIS_InteractiveObject) an_object;
6958 if (GetMapOfAIS().Find2(Name, an_object))
6960 if (!an_object.IsNull())
6962 Ctx->Remove (an_object, Standard_True);
6964 GetMapOfAIS().UnBind2 (Name);
6966 GetMapOfAIS().Bind(ais, Name);
6967 // DBRep::Set("draft", ais->Shape());
6969 Ctx->Display(ais, Standard_True);
6973 //==============================================================================
6974 //function : splitParameter
6975 //purpose : Split parameter string to parameter name and parameter value
6976 //==============================================================================
6977 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6978 TCollection_AsciiString& theName,
6979 TCollection_AsciiString& theValue)
6981 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6983 if (aParamNameEnd == 0)
6985 return Standard_False;
6988 TCollection_AsciiString aString (theString);
6989 if (aParamNameEnd != 0)
6991 theValue = aString.Split (aParamNameEnd);
6992 aString.Split (aString.Length() - 1);
6996 return Standard_True;
6999 //============================================================================
7001 //============================================================================
7002 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
7005 DrawTrSurf::BasicCommands(theCommands);
7006 const char* group = "Check Features Operations commands";
7008 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
7010 &TDraft,group); //Draft_Modification
7013 //==============================================================================
7014 // ViewerTest::Factory
7015 //==============================================================================
7016 void ViewerTest::Factory(Draw_Interpretor& theDI)
7018 // definition of Viewer Command
7019 ViewerTest::Commands(theDI);
7022 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
7026 // Declare entry point PLUGINFACTORY