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 TColStd_MapOfInteger theactivatedmodes(8);
770 static TColStd_ListOfTransient theEventMgrs;
772 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
773 const Handle(AIS_InteractiveContext)& Ctx)
775 theEventMgrs.Clear();
776 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
779 static Handle(V3d_View)& a3DView()
781 static Handle(V3d_View) Viou;
786 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
787 static Handle(AIS_InteractiveContext) aContext;
791 const Handle(V3d_View)& ViewerTest::CurrentView()
795 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
800 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
802 return TheAISContext();
805 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
807 TheAISContext() = aCtx;
808 ViewerTest::ResetEventManager();
811 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
813 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
816 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
818 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
822 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
823 theEventMgrs.Prepend(EM);
826 void ViewerTest::UnsetEventManager()
828 theEventMgrs.RemoveFirst();
832 void ViewerTest::ResetEventManager()
834 const Handle(V3d_View) aView = ViewerTest::CurrentView();
835 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
838 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
840 Handle(ViewerTest_EventManager) EM;
841 if(theEventMgrs.IsEmpty()) return EM;
842 Handle(Standard_Transient) Tr = theEventMgrs.First();
843 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
847 //=======================================================================
848 //function : Get Context and active view
850 //=======================================================================
851 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
852 Handle(V3d_View)& theView)
854 theCtx = ViewerTest::GetAISContext();
855 theView = ViewerTest::CurrentView();
859 std::cout << "Error: cannot find an active view!\n";
860 return Standard_False;
862 return Standard_True;
865 //==============================================================================
867 //purpose : Remove all the object from the viewer
868 //==============================================================================
869 void ViewerTest::Clear()
871 if (a3DView().IsNull())
876 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
877 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
879 const Handle(AIS_InteractiveObject) anObj = anObjIter.Key1();
880 if (anObj->GetContext() != TheAISContext())
885 std::cout << "Remove " << anObjIter.Key2() << std::endl;
886 TheAISContext()->Remove (anObj, Standard_False);
887 aListRemoved.Append (anObj);
890 TheAISContext()->RebuildSelectionStructs();
891 TheAISContext()->UpdateCurrentViewer();
892 if (aListRemoved.Size() == GetMapOfAIS().Extent())
894 GetMapOfAIS().Clear();
898 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
900 GetMapOfAIS().UnBind1 (anObjIter.Value());
905 //==============================================================================
906 //function : CopyIsoAspect
907 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
908 //==============================================================================
909 static Handle(Prs3d_IsoAspect) CopyIsoAspect
910 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
911 const Standard_Integer theNbIsos)
913 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
914 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
915 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
917 Handle(Prs3d_IsoAspect) aResult =
918 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
923 //==============================================================================
925 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
926 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
927 //==============================================================================
928 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
930 if (TheAISContext().IsNull()) {
931 di << argv[0] << " Call 'vinit' before!\n";
936 di << "Current number of isos : " <<
937 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
938 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
939 di << "IsoOnPlane mode is " <<
940 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
941 di << "IsoOnTriangulation mode is " <<
942 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
946 Standard_Integer aLastInd = argc - 1;
947 Standard_Boolean isChanged = Standard_False;
948 Standard_Integer aNbUIsos = 0;
949 Standard_Integer aNbVIsos = 0;
952 Standard_Boolean isIsoOnPlane = Standard_False;
954 if (strcmp(argv[aLastInd], "1") == 0) {
955 isIsoOnPlane = Standard_True;
956 isChanged = Standard_True;
957 } else if (strcmp(argv[aLastInd], "0") == 0) {
958 isIsoOnPlane = Standard_False;
959 isChanged = Standard_True;
963 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
964 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
967 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
968 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
970 TheAISContext()->IsoOnPlane(isIsoOnPlane);
973 // If there are no shapes provided set the default numbers.
974 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
975 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
982 for (i = 1; i <= aLastInd; i++)
984 TCollection_AsciiString name(argv[i]);
985 Handle(AIS_InteractiveObject) aShape;
986 GetMapOfAIS().Find2(name, aShape);
989 std::cout << "Syntax error: object '" << name << "' is not found\n";
993 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
994 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
995 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
998 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
999 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
1000 TheAISContext()->SetLocalAttributes (aShape, CurDrawer, Standard_False);
1001 TheAISContext()->Redisplay (aShape, Standard_False);
1005 di << "Number of isos for " << argv[i] << " : "
1006 << aUIso->Number() << " " << aVIso->Number() << "\n";
1011 TheAISContext()->UpdateCurrentViewer();
1017 static Standard_Integer VDispSensi (Draw_Interpretor& ,
1018 Standard_Integer theArgNb,
1023 std::cout << "Error: wrong syntax!\n";
1027 Handle(AIS_InteractiveContext) aCtx;
1028 Handle(V3d_View) aView;
1029 if (!getCtxAndView (aCtx, aView))
1034 aCtx->DisplayActiveSensitive (aView);
1039 static Standard_Integer VClearSensi (Draw_Interpretor& ,
1040 Standard_Integer theArgNb,
1045 std::cout << "Error: wrong syntax!\n";
1049 Handle(AIS_InteractiveContext) aCtx;
1050 Handle(V3d_View) aView;
1051 if (!getCtxAndView (aCtx, aView))
1055 aCtx->ClearActiveSensitive (aView);
1059 //==============================================================================
1061 //purpose : To list the displayed object with their attributes
1062 //==============================================================================
1063 static int VDir (Draw_Interpretor& theDI,
1067 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1068 anIter.More(); anIter.Next())
1070 theDI << "\t" << anIter.Key2() << "\n";
1075 //! Auxiliary enumeration
1076 enum ViewerTest_StereoPair
1078 ViewerTest_SP_Single,
1079 ViewerTest_SP_SideBySide,
1080 ViewerTest_SP_OverUnder
1083 //==============================================================================
1085 //purpose : To dump the active view snapshot to image file
1086 //==============================================================================
1087 static Standard_Integer VDump (Draw_Interpretor& theDI,
1088 Standard_Integer theArgNb,
1089 Standard_CString* theArgVec)
1093 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
1097 Standard_Integer anArgIter = 1;
1098 Standard_CString aFilePath = theArgVec[anArgIter++];
1099 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
1100 V3d_ImageDumpOptions aParams;
1101 aParams.BufferType = Graphic3d_BT_RGB;
1102 aParams.StereoOptions = V3d_SDO_MONO;
1103 for (; anArgIter < theArgNb; ++anArgIter)
1105 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1107 if (anArg == "-buffer")
1109 if (++anArgIter >= theArgNb)
1111 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
1115 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
1116 aBufArg.LowerCase();
1117 if (aBufArg == "rgba")
1119 aParams.BufferType = Graphic3d_BT_RGBA;
1121 else if (aBufArg == "rgb")
1123 aParams.BufferType = Graphic3d_BT_RGB;
1125 else if (aBufArg == "depth")
1127 aParams.BufferType = Graphic3d_BT_Depth;
1131 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
1135 else if (anArg == "-stereo")
1137 if (++anArgIter >= theArgNb)
1139 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
1143 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
1144 aStereoArg.LowerCase();
1145 if (aStereoArg == "l"
1146 || aStereoArg == "left")
1148 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1150 else if (aStereoArg == "r"
1151 || aStereoArg == "right")
1153 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1155 else if (aStereoArg == "mono")
1157 aParams.StereoOptions = V3d_SDO_MONO;
1159 else if (aStereoArg == "blended"
1160 || aStereoArg == "blend"
1161 || aStereoArg == "stereo")
1163 aParams.StereoOptions = V3d_SDO_BLENDED;
1165 else if (aStereoArg == "sbs"
1166 || aStereoArg == "sidebyside")
1168 aStereoPair = ViewerTest_SP_SideBySide;
1170 else if (aStereoArg == "ou"
1171 || aStereoArg == "overunder")
1173 aStereoPair = ViewerTest_SP_OverUnder;
1177 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
1181 else if (anArg == "-rgba"
1184 aParams.BufferType = Graphic3d_BT_RGBA;
1186 else if (anArg == "-rgb"
1189 aParams.BufferType = Graphic3d_BT_RGB;
1191 else if (anArg == "-depth"
1192 || anArg == "depth")
1194 aParams.BufferType = Graphic3d_BT_Depth;
1196 else if (anArg == "-width"
1198 || anArg == "sizex")
1200 if (aParams.Width != 0)
1202 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1205 else if (++anArgIter >= theArgNb)
1207 std::cout << "Error: integer value is expected right after 'width'\n";
1210 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1212 else if (anArg == "-height"
1213 || anArg == "height"
1214 || anArg == "-sizey")
1216 if (aParams.Height != 0)
1218 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1221 else if (++anArgIter >= theArgNb)
1223 std::cout << "Error: integer value is expected right after 'height'\n";
1226 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1228 else if (anArg == "-tile"
1229 || anArg == "-tilesize")
1231 if (++anArgIter >= theArgNb)
1233 std::cout << "Error: integer value is expected right after 'tileSize'\n";
1236 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1240 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
1244 if ((aParams.Width <= 0 && aParams.Height > 0)
1245 || (aParams.Width > 0 && aParams.Height <= 0))
1247 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
1251 Handle(V3d_View) aView = ViewerTest::CurrentView();
1254 std::cout << "Error: cannot find an active view!\n";
1258 if (aParams.Width <= 0 || aParams.Height <= 0)
1260 aView->Window()->Size (aParams.Width, aParams.Height);
1263 Image_AlienPixMap aPixMap;
1264 Image_Format aFormat = Image_Format_UNKNOWN;
1265 switch (aParams.BufferType)
1267 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1268 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1269 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1270 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1273 switch (aStereoPair)
1275 case ViewerTest_SP_Single:
1277 if (!aView->ToPixMap (aPixMap, aParams))
1279 theDI << "Fail: view dump failed!\n";
1282 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1283 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1285 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1286 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1290 case ViewerTest_SP_SideBySide:
1292 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1294 theDI << "Fail: not enough memory for image allocation!\n";
1298 Image_PixMap aPixMapL, aPixMapR;
1299 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1300 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1301 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1302 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1304 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1305 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1306 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1307 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1310 theDI << "Fail: view dump failed!\n";
1315 case ViewerTest_SP_OverUnder:
1317 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1319 theDI << "Fail: not enough memory for image allocation!\n";
1323 Image_PixMap aPixMapL, aPixMapR;
1324 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1325 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1326 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1327 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1329 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1330 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1331 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1332 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1335 theDI << "Fail: view dump failed!\n";
1342 if (!aPixMap.Save (aFilePath))
1344 theDI << "Fail: image can not be saved!\n";
1349 enum TypeOfDispOperation
1351 TypeOfDispOperation_SetDispMode,
1352 TypeOfDispOperation_UnsetDispMode
1355 //! Displays,Erase...
1356 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1357 const Standard_Integer theMode,
1358 const TypeOfDispOperation theType,
1359 const Standard_Boolean theToUpdate)
1361 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1364 case TypeOfDispOperation_SetDispMode:
1366 if (!thePrs.IsNull())
1368 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1372 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1376 case TypeOfDispOperation_UnsetDispMode:
1378 if (!thePrs.IsNull())
1380 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1384 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1391 //=======================================================================
1394 //=======================================================================
1395 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1400 std::cout << "Syntax error: wrong number of arguments\n";
1404 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1405 ? TypeOfDispOperation_UnsetDispMode
1406 : TypeOfDispOperation_SetDispMode;
1407 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1408 if (aType == TypeOfDispOperation_UnsetDispMode)
1412 if (aCtx->NbSelected() == 0)
1414 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1418 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1420 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1423 aCtx->UpdateCurrentViewer();
1427 TCollection_AsciiString aName = argv[1];
1428 Handle(AIS_InteractiveObject) aPrs;
1429 if (GetMapOfAIS().Find2 (aName, aPrs)
1432 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1438 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1439 if (aCtx->NbSelected() == 0
1440 && aType == TypeOfDispOperation_SetDispMode)
1442 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1444 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1446 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1448 aCtx->UpdateCurrentViewer();
1452 Handle(AIS_InteractiveObject) aPrs;
1453 TCollection_AsciiString aName (argv[1]);
1454 if (GetMapOfAIS().Find2 (aName, aPrs)
1457 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1464 //=======================================================================
1467 //=======================================================================
1468 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1470 if(argc==1) return 1;
1471 Standard_Integer On = Draw::Atoi(argv[1]);
1472 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1476 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1477 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1478 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1482 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1486 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1490 Ctx->UpdateCurrentViewer();
1493 Handle(AIS_InteractiveObject) IO;
1494 TCollection_AsciiString name = argv[2];
1495 if (GetMapOfAIS().Find2 (name, IO)
1499 Ctx->SubIntensityOn(IO, Standard_True);
1501 Ctx->SubIntensityOff(IO, Standard_True);
1508 //! Auxiliary class to iterate presentations from different collections.
1509 class ViewTest_PrsIter
1513 //! Create and initialize iterator object.
1514 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1515 : mySource (IterSource_All)
1517 NCollection_Sequence<TCollection_AsciiString> aNames;
1518 if (!theName.IsEmpty())
1519 aNames.Append (theName);
1523 //! Create and initialize iterator object.
1524 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1525 : mySource (IterSource_All)
1530 //! Initialize the iterator.
1531 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1533 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1535 mySelIter.Nullify();
1536 myCurrent.Nullify();
1537 myCurrentTrs.Nullify();
1538 if (!mySeq.IsEmpty())
1540 mySource = IterSource_List;
1541 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1543 else if (aCtx->NbSelected() > 0)
1545 mySource = IterSource_Selected;
1547 mySelIter->InitSelected();
1551 mySource = IterSource_All;
1552 myMapIter.Initialize (GetMapOfAIS());
1557 const TCollection_AsciiString& CurrentName() const
1559 return myCurrentName;
1562 const Handle(AIS_InteractiveObject)& Current() const
1567 const Handle(Standard_Transient)& CurrentTrs() const
1569 return myCurrentTrs;
1572 //! @return true if iterator points to valid object within collection
1573 Standard_Boolean More() const
1577 case IterSource_All: return myMapIter.More();
1578 case IterSource_List: return mySeqIter.More();
1579 case IterSource_Selected: return mySelIter->MoreSelected();
1581 return Standard_False;
1584 //! Go to the next item.
1587 myCurrentName.Clear();
1588 myCurrentTrs.Nullify();
1589 myCurrent.Nullify();
1592 case IterSource_All:
1597 case IterSource_List:
1602 case IterSource_Selected:
1604 mySelIter->NextSelected();
1617 case IterSource_All:
1619 if (myMapIter.More())
1621 myCurrentName = myMapIter.Key2();
1622 myCurrentTrs = myMapIter.Key1();
1623 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1627 case IterSource_List:
1629 if (mySeqIter.More())
1631 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1633 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1636 myCurrentName = mySeqIter.Value();
1637 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1638 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1642 case IterSource_Selected:
1644 if (mySelIter->MoreSelected())
1646 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1647 myCurrent = mySelIter->SelectedInteractive();
1665 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1666 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1667 NCollection_Sequence<TCollection_AsciiString> mySeq;
1668 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1670 TCollection_AsciiString myCurrentName;//!< current item name
1671 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1672 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1674 IterSource mySource; //!< iterated collection
1678 //! Parse interior style name.
1679 static bool parseInteriorStyle (const TCollection_AsciiString& theArg,
1680 Aspect_InteriorStyle& theStyle)
1682 TCollection_AsciiString anArg (theArg);
1684 if (anArg == "empty")
1686 theStyle = Aspect_IS_EMPTY;
1688 else if (anArg == "hollow")
1690 theStyle = Aspect_IS_HOLLOW;
1692 else if (anArg == "solid")
1694 theStyle = Aspect_IS_SOLID;
1696 else if (anArg == "hatch")
1698 theStyle = Aspect_IS_HATCH;
1700 else if (anArg == "hiddenline"
1701 || anArg == "hidden-line"
1702 || anArg == "hidden_line")
1704 theStyle = Aspect_IS_HIDDENLINE;
1706 else if (anArg == "point")
1708 theStyle = Aspect_IS_POINT;
1710 else if (theArg.IsIntegerValue())
1712 const Standard_Integer anIntStyle = theArg.IntegerValue();
1713 if (anIntStyle < Aspect_IS_EMPTY || anIntStyle > Aspect_IS_POINT)
1717 theStyle = (Aspect_InteriorStyle)anIntStyle;
1726 //! Auxiliary structure for VAspects
1727 struct ViewerTest_AspectsChangeSet
1729 Standard_Integer ToSetVisibility;
1730 Standard_Integer Visibility;
1732 Standard_Integer ToSetColor;
1733 Quantity_Color Color;
1735 Standard_Integer ToSetLineWidth;
1736 Standard_Real LineWidth;
1738 Standard_Integer ToSetTypeOfLine;
1739 Aspect_TypeOfLine TypeOfLine;
1741 Standard_Integer ToSetTypeOfMarker;
1742 Aspect_TypeOfMarker TypeOfMarker;
1743 Handle(Image_PixMap) MarkerImage;
1745 Standard_Integer ToSetMarkerSize;
1746 Standard_Real MarkerSize;
1748 Standard_Integer ToSetTransparency;
1749 Standard_Real Transparency;
1751 Standard_Integer ToSetAlphaMode;
1752 Graphic3d_AlphaMode AlphaMode;
1753 Standard_ShortReal AlphaCutoff;
1755 Standard_Integer ToSetMaterial;
1756 Graphic3d_NameOfMaterial Material;
1757 TCollection_AsciiString MatName;
1759 NCollection_Sequence<TopoDS_Shape> SubShapes;
1761 Standard_Integer ToSetShowFreeBoundary;
1762 Standard_Integer ToSetFreeBoundaryWidth;
1763 Standard_Real FreeBoundaryWidth;
1764 Standard_Integer ToSetFreeBoundaryColor;
1765 Quantity_Color FreeBoundaryColor;
1767 Standard_Integer ToEnableIsoOnTriangulation;
1769 Standard_Integer ToSetFaceBoundaryDraw;
1770 Standard_Integer ToSetFaceBoundaryUpperContinuity;
1771 GeomAbs_Shape FaceBoundaryUpperContinuity;
1773 Standard_Integer ToSetFaceBoundaryColor;
1774 Quantity_Color FaceBoundaryColor;
1776 Standard_Integer ToSetFaceBoundaryWidth;
1777 Standard_Real FaceBoundaryWidth;
1779 Standard_Integer ToSetTypeOfFaceBoundaryLine;
1780 Aspect_TypeOfLine TypeOfFaceBoundaryLine;
1782 Standard_Integer ToSetMaxParamValue;
1783 Standard_Real MaxParamValue;
1785 Standard_Integer ToSetSensitivity;
1786 Standard_Integer SelectionMode;
1787 Standard_Integer Sensitivity;
1789 Standard_Integer ToSetHatch;
1790 Standard_Integer StdHatchStyle;
1791 TCollection_AsciiString PathToHatchPattern;
1793 Standard_Integer ToSetShadingModel;
1794 Graphic3d_TypeOfShadingModel ShadingModel;
1795 TCollection_AsciiString ShadingModelName;
1797 Standard_Integer ToSetInterior;
1798 Aspect_InteriorStyle InteriorStyle;
1800 Standard_Integer ToSetDrawSilhouette;
1802 Standard_Integer ToSetDrawEdges;
1803 Standard_Integer ToSetQuadEdges;
1805 Standard_Integer ToSetEdgeColor;
1806 Quantity_ColorRGBA EdgeColor;
1808 Standard_Integer ToSetEdgeWidth;
1809 Standard_Real EdgeWidth;
1811 Standard_Integer ToSetTypeOfEdge;
1812 Aspect_TypeOfLine TypeOfEdge;
1814 //! Empty constructor
1815 ViewerTest_AspectsChangeSet()
1816 : ToSetVisibility (0),
1819 Color (DEFAULT_COLOR),
1822 ToSetTypeOfLine (0),
1823 TypeOfLine (Aspect_TOL_SOLID),
1824 ToSetTypeOfMarker (0),
1825 TypeOfMarker (Aspect_TOM_PLUS),
1826 ToSetMarkerSize (0),
1828 ToSetTransparency (0),
1831 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1834 Material (Graphic3d_NOM_DEFAULT),
1835 ToSetShowFreeBoundary (0),
1836 ToSetFreeBoundaryWidth (0),
1837 FreeBoundaryWidth (1.0),
1838 ToSetFreeBoundaryColor (0),
1839 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1840 ToEnableIsoOnTriangulation (0),
1842 ToSetFaceBoundaryDraw (0),
1843 ToSetFaceBoundaryUpperContinuity (0),
1844 FaceBoundaryUpperContinuity(GeomAbs_CN),
1845 ToSetFaceBoundaryColor (0),
1846 FaceBoundaryColor (Quantity_NOC_BLACK),
1847 ToSetFaceBoundaryWidth (0),
1848 FaceBoundaryWidth (1.0f),
1849 ToSetTypeOfFaceBoundaryLine(0),
1850 TypeOfFaceBoundaryLine (Aspect_TOL_SOLID),
1852 ToSetMaxParamValue (0),
1853 MaxParamValue (500000),
1854 ToSetSensitivity (0),
1859 ToSetShadingModel (0),
1860 ShadingModel (Graphic3d_TOSM_DEFAULT),
1862 InteriorStyle (Aspect_IS_SOLID),
1863 ToSetDrawSilhouette (0),
1869 ToSetTypeOfEdge (0),
1870 TypeOfEdge (Aspect_TOL_SOLID)
1873 //! @return true if no changes have been requested
1874 Standard_Boolean IsEmpty() const
1876 return ToSetVisibility == 0
1877 && ToSetLineWidth == 0
1878 && ToSetTransparency == 0
1879 && ToSetAlphaMode == 0
1881 && ToSetMaterial == 0
1882 && ToSetShowFreeBoundary == 0
1883 && ToSetFreeBoundaryColor == 0
1884 && ToSetFreeBoundaryWidth == 0
1885 && ToEnableIsoOnTriangulation == 0
1886 && ToSetFaceBoundaryDraw == 0
1887 && ToSetFaceBoundaryUpperContinuity == 0
1888 && ToSetFaceBoundaryColor == 0
1889 && ToSetFaceBoundaryWidth == 0
1890 && ToSetTypeOfFaceBoundaryLine == 0
1891 && ToSetMaxParamValue == 0
1892 && ToSetSensitivity == 0
1894 && ToSetShadingModel == 0
1895 && ToSetInterior == 0
1896 && ToSetDrawSilhouette == 0
1897 && ToSetDrawEdges == 0
1898 && ToSetQuadEdges == 0
1899 && ToSetEdgeColor == 0
1900 && ToSetEdgeWidth == 0
1901 && ToSetTypeOfEdge == 0;
1904 //! @return true if properties are valid
1905 Standard_Boolean Validate() const
1907 Standard_Boolean isOk = Standard_True;
1908 if (Visibility != 0 && Visibility != 1)
1910 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1911 isOk = Standard_False;
1913 if (LineWidth <= 0.0
1914 || LineWidth > 10.0)
1916 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1917 isOk = Standard_False;
1919 if (Transparency < 0.0
1920 || Transparency > 1.0)
1922 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1923 isOk = Standard_False;
1925 if (ToSetAlphaMode == 1
1926 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1928 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1929 isOk = Standard_False;
1931 if (ToSetMaterial == 1
1932 && Material == Graphic3d_NOM_DEFAULT)
1934 std::cout << "Error: unknown material " << MatName << ".\n";
1935 isOk = Standard_False;
1937 if (FreeBoundaryWidth <= 0.0
1938 || FreeBoundaryWidth > 10.0)
1940 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1941 isOk = Standard_False;
1943 if (MaxParamValue < 0.0)
1945 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1946 isOk = Standard_False;
1948 if (Sensitivity <= 0 && ToSetSensitivity)
1950 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1951 isOk = Standard_False;
1953 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1955 std::cout << "Error: hatch style must be specified\n";
1956 isOk = Standard_False;
1958 if (ToSetShadingModel == 1
1959 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
1961 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1962 isOk = Standard_False;
1967 //! Apply aspects to specified drawer.
1968 bool Apply (const Handle(Prs3d_Drawer)& theDrawer)
1970 bool toRecompute = false;
1971 const Handle(Prs3d_Drawer)& aDefDrawer = ViewerTest::GetAISContext()->DefaultDrawer();
1972 if (ToSetShowFreeBoundary != 0)
1974 theDrawer->SetFreeBoundaryDraw (ToSetShowFreeBoundary == 1);
1977 if (ToSetFreeBoundaryWidth != 0)
1979 if (ToSetFreeBoundaryWidth != -1
1980 || theDrawer->HasOwnFreeBoundaryAspect())
1982 if (!theDrawer->HasOwnFreeBoundaryAspect())
1984 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
1985 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
1986 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
1989 theDrawer->FreeBoundaryAspect()->SetWidth (FreeBoundaryWidth);
1992 if (ToSetFreeBoundaryColor != 0)
1994 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
1995 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
1996 aBoundaryAspect->SetColor (FreeBoundaryColor);
1997 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2000 if (ToSetTypeOfLine != 0)
2002 if (ToSetTypeOfLine != -1
2003 || theDrawer->HasOwnLineAspect()
2004 || theDrawer->HasOwnWireAspect()
2005 || theDrawer->HasOwnFreeBoundaryAspect()
2006 || theDrawer->HasOwnUnFreeBoundaryAspect()
2007 || theDrawer->HasOwnSeenLineAspect())
2009 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
2010 theDrawer->LineAspect()->SetTypeOfLine (TypeOfLine);
2011 theDrawer->WireAspect()->SetTypeOfLine (TypeOfLine);
2012 theDrawer->FreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
2013 theDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
2014 theDrawer->SeenLineAspect()->SetTypeOfLine (TypeOfLine);
2017 if (ToSetTypeOfMarker != 0)
2019 if (ToSetTypeOfMarker != -1
2020 || theDrawer->HasOwnPointAspect())
2022 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
2023 theDrawer->PointAspect()->SetTypeOfMarker (TypeOfMarker);
2024 theDrawer->PointAspect()->Aspect()->SetMarkerImage (MarkerImage.IsNull() ? Handle(Graphic3d_MarkerImage)() : new Graphic3d_MarkerImage (MarkerImage));
2027 if (ToSetMarkerSize != 0)
2029 if (ToSetMarkerSize != -1
2030 || theDrawer->HasOwnPointAspect())
2032 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
2033 theDrawer->PointAspect()->SetScale (MarkerSize);
2037 if (ToSetMaxParamValue != 0)
2039 if (ToSetMaxParamValue != -1
2040 || theDrawer->HasOwnMaximalParameterValue())
2042 theDrawer->SetMaximalParameterValue (MaxParamValue);
2046 if (ToSetFaceBoundaryDraw != 0)
2048 if (ToSetFaceBoundaryDraw != -1
2049 || theDrawer->HasOwnFaceBoundaryDraw())
2052 theDrawer->SetFaceBoundaryDraw (ToSetFaceBoundaryDraw == 1);
2055 if (ToSetFaceBoundaryUpperContinuity != 0)
2057 if (ToSetFaceBoundaryUpperContinuity != -1
2058 || theDrawer->HasOwnFaceBoundaryUpperContinuity())
2061 if (ToSetFaceBoundaryUpperContinuity == -1)
2063 theDrawer->UnsetFaceBoundaryUpperContinuity();
2067 theDrawer->SetFaceBoundaryUpperContinuity (FaceBoundaryUpperContinuity);
2071 if (ToSetFaceBoundaryColor != 0)
2073 if (ToSetFaceBoundaryColor != -1
2074 || theDrawer->HasOwnFaceBoundaryAspect())
2076 if (ToSetFaceBoundaryColor == -1)
2079 theDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
2083 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2084 theDrawer->FaceBoundaryAspect()->SetColor (FaceBoundaryColor);
2088 if (ToSetFaceBoundaryWidth != 0)
2090 if (ToSetFaceBoundaryWidth != -1
2091 || theDrawer->HasOwnFaceBoundaryAspect())
2093 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2094 theDrawer->FaceBoundaryAspect()->SetWidth (FaceBoundaryWidth);
2097 if (ToSetTypeOfFaceBoundaryLine != 0)
2099 if (ToSetTypeOfFaceBoundaryLine != -1
2100 || theDrawer->HasOwnFaceBoundaryAspect())
2102 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2103 theDrawer->FaceBoundaryAspect()->SetTypeOfLine (TypeOfFaceBoundaryLine);
2106 if (ToSetShadingModel != 0)
2108 if (ToSetShadingModel != -1
2109 || theDrawer->HasOwnShadingAspect())
2111 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2112 theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel);
2115 if (ToSetAlphaMode != 0)
2117 if (ToSetAlphaMode != -1
2118 || theDrawer->HasOwnShadingAspect())
2120 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2121 theDrawer->ShadingAspect()->Aspect()->SetAlphaMode (AlphaMode, AlphaCutoff);
2124 if (ToSetHatch != 0)
2126 if (ToSetHatch != -1
2127 || theDrawer->HasOwnShadingAspect())
2129 theDrawer->SetupOwnShadingAspect (aDefDrawer);
2130 Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect();
2131 if (ToSetHatch == -1)
2133 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2137 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2138 if (!PathToHatchPattern.IsEmpty())
2140 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2141 if (anImage->Load (TCollection_AsciiString (PathToHatchPattern.ToCString())))
2143 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2147 std::cout << "Error: cannot load the following image: " << PathToHatchPattern << "\n";
2150 else if (StdHatchStyle != -1)
2152 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)StdHatchStyle));
2158 if (ToSetInterior != 0)
2160 if (ToSetInterior != -1
2161 || theDrawer->HasOwnShadingAspect())
2163 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2164 theDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (InteriorStyle);
2165 if (InteriorStyle == Aspect_IS_HATCH
2166 && theDrawer->ShadingAspect()->Aspect()->HatchStyle().IsNull())
2168 theDrawer->ShadingAspect()->Aspect()->SetHatchStyle (Aspect_HS_VERTICAL);
2172 if (ToSetDrawSilhouette != 0)
2174 if (ToSetDrawSilhouette != -1
2175 || theDrawer->HasOwnShadingAspect())
2177 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2178 theDrawer->ShadingAspect()->Aspect()->SetDrawSilhouette (ToSetDrawSilhouette == 1);
2181 if (ToSetDrawEdges != 0)
2183 if (ToSetDrawEdges != -1
2184 || theDrawer->HasOwnShadingAspect())
2186 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2187 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetDrawEdges == 1);
2190 if (ToSetQuadEdges != 0)
2192 if (ToSetQuadEdges != -1
2193 || theDrawer->HasOwnShadingAspect())
2195 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2196 theDrawer->ShadingAspect()->Aspect()->SetSkipFirstEdge (ToSetQuadEdges == 1);
2199 if (ToSetEdgeWidth != 0)
2201 if (ToSetEdgeWidth != -1
2202 || theDrawer->HasOwnShadingAspect())
2204 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2205 theDrawer->ShadingAspect()->Aspect()->SetEdgeWidth (EdgeWidth);
2208 if (ToSetTypeOfEdge != 0)
2210 if (ToSetTypeOfEdge != -1
2211 || theDrawer->HasOwnShadingAspect())
2213 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2214 theDrawer->ShadingAspect()->Aspect()->SetEdgeLineType (TypeOfEdge);
2215 if (ToSetInterior == 0)
2217 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetTypeOfEdge == 1
2218 && TypeOfEdge != Aspect_TOL_EMPTY);
2222 if (ToSetEdgeColor != 0)
2224 if (ToSetEdgeColor != -1
2225 || theDrawer->HasOwnShadingAspect())
2227 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2228 if (ToSetEdgeColor == -1)
2230 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (theDrawer->ShadingAspect()->Aspect()->InteriorColor());
2234 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (EdgeColor);
2242 //==============================================================================
2243 //function : VAspects
2245 //==============================================================================
2246 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
2247 Standard_Integer theArgNb,
2248 const char** theArgVec)
2250 TCollection_AsciiString aCmdName (theArgVec[0]);
2251 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2252 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2255 std::cerr << "Error: no active view!\n";
2259 Standard_Integer anArgIter = 1;
2260 Standard_Boolean isDefaults = Standard_False;
2261 NCollection_Sequence<TCollection_AsciiString> aNames;
2262 for (; anArgIter < theArgNb; ++anArgIter)
2264 TCollection_AsciiString anArg = theArgVec[anArgIter];
2265 if (anUpdateTool.parseRedrawMode (anArg))
2269 else if (!anArg.IsEmpty()
2270 && anArg.Value (1) != '-')
2272 aNames.Append (anArg);
2276 if (anArg == "-defaults")
2278 isDefaults = Standard_True;
2285 if (!aNames.IsEmpty() && isDefaults)
2287 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
2291 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
2292 aChanges.Append (ViewerTest_AspectsChangeSet());
2293 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
2295 // parse syntax of legacy commands
2296 bool toParseAliasArgs = false;
2297 if (aCmdName == "vsetwidth")
2299 if (aNames.IsEmpty()
2300 || !aNames.Last().IsRealValue())
2302 std::cout << "Error: not enough arguments!\n";
2305 aChangeSet->ToSetLineWidth = 1;
2306 aChangeSet->LineWidth = aNames.Last().RealValue();
2307 aNames.Remove (aNames.Length());
2309 else if (aCmdName == "vunsetwidth")
2311 aChangeSet->ToSetLineWidth = -1;
2313 else if (aCmdName == "vsetcolor")
2315 if (aNames.IsEmpty())
2317 std::cout << "Error: not enough arguments!\n";
2320 aChangeSet->ToSetColor = 1;
2322 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2323 Standard_Boolean isOk = Standard_False;
2324 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
2326 aChangeSet->Color = aColor;
2327 aNames.Remove (aNames.Length());
2328 isOk = Standard_True;
2330 else if (aNames.Length() >= 3)
2332 const char* anArgVec[3] =
2334 aNames.Value (aNames.Upper() - 2).ToCString(),
2335 aNames.Value (aNames.Upper() - 1).ToCString(),
2336 aNames.Value (aNames.Upper() - 0).ToCString(),
2339 Standard_Integer aNbParsed = ViewerTest::ParseColor (3, anArgVec, aChangeSet->Color);
2340 isOk = aNbParsed == 3;
2341 aNames.Remove (aNames.Length());
2342 aNames.Remove (aNames.Length());
2343 aNames.Remove (aNames.Length());
2347 std::cout << "Error: not enough arguments!\n";
2351 else if (aCmdName == "vunsetcolor")
2353 aChangeSet->ToSetColor = -1;
2355 else if (aCmdName == "vsettransparency")
2357 if (aNames.IsEmpty()
2358 || !aNames.Last().IsRealValue())
2360 std::cout << "Error: not enough arguments!\n";
2363 aChangeSet->ToSetTransparency = 1;
2364 aChangeSet->Transparency = aNames.Last().RealValue();
2365 aNames.Remove (aNames.Length());
2367 else if (aCmdName == "vunsettransparency")
2369 aChangeSet->ToSetTransparency = -1;
2371 else if (aCmdName == "vsetmaterial")
2373 if (aNames.IsEmpty())
2375 std::cout << "Error: not enough arguments!\n";
2378 aChangeSet->ToSetMaterial = 1;
2379 aChangeSet->MatName = aNames.Last();
2380 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2381 aNames.Remove (aNames.Length());
2383 else if (aCmdName == "vunsetmaterial")
2385 aChangeSet->ToSetMaterial = -1;
2387 else if (aCmdName == "vsetinteriorstyle")
2389 if (aNames.IsEmpty()
2390 || !aNames.Last().IsRealValue())
2392 std::cout << "Error: not enough arguments!\n";
2395 aChangeSet->ToSetInterior = 1;
2396 if (!parseInteriorStyle (aNames.Last(), aChangeSet->InteriorStyle))
2398 std::cout << "Error: wrong syntax at " << aNames.Last() << "\n";
2401 aNames.Remove (aNames.Length());
2403 else if (aCmdName == "vsetedgetype")
2405 aChangeSet->ToSetDrawEdges = 1;
2406 toParseAliasArgs = true;
2408 else if (aCmdName == "vunsetedgetype")
2410 aChangeSet->ToSetDrawEdges = -1;
2411 aChangeSet->ToSetEdgeColor = -1;
2412 aChangeSet->ToSetTypeOfEdge = -1;
2413 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
2415 else if (aCmdName == "vshowfaceboundary")
2417 aChangeSet->ToSetFaceBoundaryDraw = 1;
2418 toParseAliasArgs = true;
2419 if (aNames.Size() >= 2
2420 && aNames.Value (2).IsIntegerValue())
2422 if (aNames.Size() == 7)
2424 if (ViewerTest::ParseLineType (aNames.Value (7).ToCString(), aChangeSet->TypeOfFaceBoundaryLine))
2426 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2430 if (aNames.Size() == 6
2431 && aNames.Value (6).IsRealValue())
2433 aChangeSet->ToSetFaceBoundaryWidth = 1;
2434 aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue();
2437 if (aNames.Size() == 5
2438 && aNames.Value (3).IsIntegerValue()
2439 && aNames.Value (4).IsIntegerValue()
2440 && aNames.Value (5).IsIntegerValue())
2442 aChangeSet->ToSetFaceBoundaryColor = 1;
2443 aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0,
2444 aNames.Value (4).IntegerValue() / 255.0,
2445 aNames.Value (5).IntegerValue() / 255.0,
2451 if (aNames.Size() == 2)
2453 toParseAliasArgs = false;
2454 aChangeSet->ToSetFaceBoundaryDraw = aNames.Value (2).IntegerValue() == 1 ? 1 : -1;
2459 else if (anArgIter >= theArgNb)
2461 std::cout << "Error: not enough arguments!\n";
2465 if (!aChangeSet->IsEmpty()
2466 && !toParseAliasArgs)
2468 anArgIter = theArgNb;
2470 for (; anArgIter < theArgNb; ++anArgIter)
2472 TCollection_AsciiString anArg = theArgVec[anArgIter];
2474 if (anArg == "-setwidth"
2475 || anArg == "-width"
2476 || anArg == "-setlinewidth"
2477 || anArg == "-linewidth"
2478 || anArg == "-setedgewidth"
2479 || anArg == "-setedgeswidth"
2480 || anArg == "-edgewidth"
2481 || anArg == "-edgeswidth"
2482 || anArg == "-setfaceboundarywidth"
2483 || anArg == "-setboundarywidth"
2484 || anArg == "-faceboundarywidth"
2485 || anArg == "-boundarywidth")
2487 if (++anArgIter >= theArgNb)
2489 std::cout << "Error: wrong syntax at " << anArg << "\n";
2493 const Standard_Real aWidth = Draw::Atof (theArgVec[anArgIter]);
2494 if (anArg == "-setedgewidth"
2495 || anArg == "-setedgeswidth"
2496 || anArg == "-edgewidth"
2497 || anArg == "-edgeswidth"
2498 || aCmdName == "vsetedgetype")
2500 aChangeSet->ToSetEdgeWidth = 1;
2501 aChangeSet->EdgeWidth = aWidth;
2503 else if (anArg == "-setfaceboundarywidth"
2504 || anArg == "-setboundarywidth"
2505 || anArg == "-faceboundarywidth"
2506 || anArg == "-boundarywidth"
2507 || aCmdName == "vshowfaceboundary")
2509 aChangeSet->ToSetFaceBoundaryWidth = 1;
2510 aChangeSet->FaceBoundaryWidth = aWidth;
2514 aChangeSet->ToSetLineWidth = 1;
2515 aChangeSet->LineWidth = aWidth;
2518 else if (anArg == "-unsetwidth"
2519 || anArg == "-unsetlinewidth"
2520 || anArg == "-unsetedgewidth")
2522 if (anArg == "-unsetedgewidth")
2524 aChangeSet->ToSetEdgeWidth = -1;
2525 aChangeSet->EdgeWidth = 1.0;
2529 aChangeSet->ToSetLineWidth = -1;
2530 aChangeSet->LineWidth = 1.0;
2533 else if (anArg == "-settransp"
2534 || anArg == "-settransparency"
2535 || anArg == "-transparency"
2536 || anArg == "-transp")
2538 if (++anArgIter >= theArgNb)
2540 std::cout << "Error: wrong syntax at " << anArg << "\n";
2543 aChangeSet->ToSetTransparency = 1;
2544 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2545 if (aChangeSet->Transparency >= 0.0
2546 && aChangeSet->Transparency <= Precision::Confusion())
2548 aChangeSet->ToSetTransparency = -1;
2549 aChangeSet->Transparency = 0.0;
2552 else if (anArg == "-setalphamode"
2553 || anArg == "-alphamode")
2555 if (++anArgIter >= theArgNb)
2557 std::cout << "Error: wrong syntax at " << anArg << "\n";
2560 aChangeSet->ToSetAlphaMode = 1;
2561 aChangeSet->AlphaCutoff = 0.5f;
2563 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2565 if (aParam == "opaque")
2567 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2569 else if (aParam == "mask")
2571 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2573 else if (aParam == "blend")
2575 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2577 else if (aParam == "blendauto"
2578 || aParam == "auto")
2580 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2584 std::cout << "Error: wrong syntax at " << aParam << "\n";
2589 if (anArgIter + 1 < theArgNb
2590 && theArgVec[anArgIter + 1][0] != '-')
2592 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2593 if (aParam2.IsRealValue())
2595 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2600 else if (anArg == "-setvis"
2601 || anArg == "-setvisibility"
2602 || anArg == "-visibility")
2604 if (++anArgIter >= theArgNb)
2606 std::cout << "Error: wrong syntax at " << anArg << "\n";
2610 aChangeSet->ToSetVisibility = 1;
2611 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2613 else if (anArg == "-setalpha"
2614 || anArg == "-alpha")
2616 if (++anArgIter >= theArgNb)
2618 std::cout << "Error: wrong syntax at " << anArg << "\n";
2621 aChangeSet->ToSetTransparency = 1;
2622 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2623 if (aChangeSet->Transparency < 0.0
2624 || aChangeSet->Transparency > 1.0)
2626 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2629 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2630 if (aChangeSet->Transparency >= 0.0
2631 && aChangeSet->Transparency <= Precision::Confusion())
2633 aChangeSet->ToSetTransparency = -1;
2634 aChangeSet->Transparency = 0.0;
2637 else if (anArg == "-unsettransp"
2638 || anArg == "-unsettransparency"
2639 || anArg == "-unsetalpha"
2640 || anArg == "-opaque")
2642 aChangeSet->ToSetTransparency = -1;
2643 aChangeSet->Transparency = 0.0;
2645 else if (anArg == "-setcolor"
2646 || anArg == "-color"
2647 || anArg == "-setfaceboundarycolor"
2648 || anArg == "-setboundarycolor"
2649 || anArg == "-faceboundarycolor"
2650 || anArg == "-boundarycolor")
2652 Quantity_Color aColor;
2653 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2654 theArgVec + anArgIter + 1,
2658 std::cout << "Syntax error at '" << anArg << "'\n";
2661 anArgIter += aNbParsed;
2662 if (aCmdName == "vsetedgetype")
2664 aChangeSet->ToSetEdgeColor = 1;
2665 aChangeSet->EdgeColor = Quantity_ColorRGBA (aColor);
2667 else if (aCmdName == "vshowfaceboundary"
2668 || anArg == "-setfaceboundarycolor"
2669 || anArg == "-setboundarycolor"
2670 || anArg == "-faceboundarycolor"
2671 || anArg == "-boundarycolor")
2673 aChangeSet->ToSetFaceBoundaryColor = 1;
2674 aChangeSet->FaceBoundaryColor = aColor;
2678 aChangeSet->ToSetColor = 1;
2679 aChangeSet->Color = aColor;
2682 else if (anArg == "-setlinetype"
2683 || anArg == "-linetype"
2684 || anArg == "-setedgetype"
2685 || anArg == "-setedgestype"
2686 || anArg == "-edgetype"
2687 || anArg == "-edgestype"
2688 || anArg == "-setfaceboundarystyle"
2689 || anArg == "-faceboundarystyle"
2690 || anArg == "-boundarystyle"
2691 || anArg == "-setfaceboundarytype"
2692 || anArg == "-faceboundarytype"
2693 || anArg == "-setboundarytype"
2694 || anArg == "-boundarytype"
2695 || anArg == "-type")
2697 if (++anArgIter >= theArgNb)
2699 std::cout << "Error: wrong syntax at " << anArg << "\n";
2702 Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY;
2703 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType))
2705 std::cout << "Error: wrong syntax at " << anArg << "\n";
2708 if (anArg == "-setedgetype"
2709 || anArg == "-setedgestype"
2710 || anArg == "-edgetype"
2711 || anArg == "-edgestype"
2712 || aCmdName == "vsetedgetype")
2714 aChangeSet->TypeOfEdge = aLineType;
2715 aChangeSet->ToSetTypeOfEdge = 1;
2717 else if (anArg == "-setfaceboundarystyle"
2718 || anArg == "-faceboundarystyle"
2719 || anArg == "-boundarystyle"
2720 || anArg == "-setfaceboundarytype"
2721 || anArg == "-faceboundarytype"
2722 || anArg == "-setboundarytype"
2723 || anArg == "-boundarytype"
2724 || aCmdName == "vshowfaceboundary")
2726 aChangeSet->TypeOfFaceBoundaryLine = aLineType;
2727 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2731 aChangeSet->TypeOfLine = aLineType;
2732 aChangeSet->ToSetTypeOfLine = 1;
2735 else if (anArg == "-unsetlinetype"
2736 || anArg == "-unsetedgetype"
2737 || anArg == "-unsetedgestype")
2739 if (anArg == "-unsetedgetype"
2740 || anArg == "-unsetedgestype")
2742 aChangeSet->ToSetTypeOfEdge = -1;
2746 aChangeSet->ToSetTypeOfLine = -1;
2749 else if (anArg == "-setmarkertype"
2750 || anArg == "-markertype"
2751 || anArg == "-setpointtype"
2752 || anArg == "-pointtype")
2754 if (++anArgIter >= theArgNb)
2756 std::cout << "Error: wrong syntax at " << anArg << "\n";
2759 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2761 std::cout << "Error: wrong syntax at " << anArg << "\n";
2765 aChangeSet->ToSetTypeOfMarker = 1;
2767 else if (anArg == "-unsetmarkertype"
2768 || anArg == "-unsetpointtype")
2770 aChangeSet->ToSetTypeOfMarker = -1;
2772 else if (anArg == "-setmarkersize"
2773 || anArg == "-markersize"
2774 || anArg == "-setpointsize"
2775 || anArg == "-pointsize")
2777 if (++anArgIter >= theArgNb)
2779 std::cout << "Error: wrong syntax at " << anArg << "\n";
2782 aChangeSet->ToSetMarkerSize = 1;
2783 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2785 else if (anArg == "-unsetmarkersize"
2786 || anArg == "-unsetpointsize")
2788 aChangeSet->ToSetMarkerSize = -1;
2789 aChangeSet->MarkerSize = 1.0;
2791 else if (anArg == "-unsetcolor")
2793 aChangeSet->ToSetColor = -1;
2794 aChangeSet->Color = DEFAULT_COLOR;
2796 else if (anArg == "-setmat"
2798 || anArg == "-setmaterial"
2799 || anArg == "-material")
2801 if (++anArgIter >= theArgNb)
2803 std::cout << "Error: wrong syntax at " << anArg << "\n";
2806 aChangeSet->ToSetMaterial = 1;
2807 aChangeSet->MatName = theArgVec[anArgIter];
2808 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2810 else if (anArg == "-unsetmat"
2811 || anArg == "-unsetmaterial")
2813 aChangeSet->ToSetMaterial = -1;
2814 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2816 else if (anArg == "-subshape"
2817 || anArg == "-subshapes")
2821 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2825 if (aNames.IsEmpty())
2827 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2831 aChanges.Append (ViewerTest_AspectsChangeSet());
2832 aChangeSet = &aChanges.ChangeLast();
2834 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2836 Standard_CString aSubShapeName = theArgVec[anArgIter];
2837 if (*aSubShapeName == '-')
2843 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2844 if (aSubShape.IsNull())
2846 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2849 aChangeSet->SubShapes.Append (aSubShape);
2852 if (aChangeSet->SubShapes.IsEmpty())
2854 std::cerr << "Error: empty list is specified after -subshapes!\n";
2858 else if (anArg == "-setfreeboundary"
2859 || anArg == "-freeboundary"
2860 || anArg == "-setfb"
2863 bool toEnable = true;
2864 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2866 std::cout << "Error: wrong syntax at " << anArg << "\n";
2870 aChangeSet->ToSetShowFreeBoundary = toEnable ? 1 : -1;
2872 else if (anArg == "-setfreeboundarywidth"
2873 || anArg == "-freeboundarywidth"
2874 || anArg == "-setfbwidth"
2875 || anArg == "-fbwidth")
2877 if (++anArgIter >= theArgNb)
2879 std::cout << "Error: wrong syntax at " << anArg << "\n";
2882 aChangeSet->ToSetFreeBoundaryWidth = 1;
2883 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2885 else if (anArg == "-unsetfreeboundarywidth"
2886 || anArg == "-unsetfbwidth")
2888 aChangeSet->ToSetFreeBoundaryWidth = -1;
2889 aChangeSet->FreeBoundaryWidth = 1.0;
2891 else if (anArg == "-setfreeboundarycolor"
2892 || anArg == "-freeboundarycolor"
2893 || anArg == "-setfbcolor"
2894 || anArg == "-fbcolor")
2896 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2897 theArgVec + anArgIter + 1,
2898 aChangeSet->FreeBoundaryColor);
2901 std::cout << "Syntax error at '" << anArg << "'\n";
2904 anArgIter += aNbParsed;
2905 aChangeSet->ToSetFreeBoundaryColor = 1;
2907 else if (anArg == "-unsetfreeboundarycolor"
2908 || anArg == "-unsetfbcolor")
2910 aChangeSet->ToSetFreeBoundaryColor = -1;
2911 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2913 else if (anArg == "-setisoontriangulation"
2914 || anArg == "-isoontriangulation"
2915 || anArg == "-setisoontriang"
2916 || anArg == "-isoontriang")
2918 bool toEnable = true;
2919 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2921 std::cout << "Error: wrong syntax at " << anArg << "\n";
2925 aChangeSet->ToEnableIsoOnTriangulation = toEnable ? 1 : -1;
2927 else if (anArg == "-setfaceboundarydraw"
2928 || anArg == "-setdrawfaceboundary"
2929 || anArg == "-setdrawfaceboundaries"
2930 || anArg == "-setshowfaceboundary"
2931 || anArg == "-setshowfaceboundaries"
2932 || anArg == "-setdrawfaceedges"
2933 || anArg == "-faceboundarydraw"
2934 || anArg == "-drawfaceboundary"
2935 || anArg == "-drawfaceboundaries"
2936 || anArg == "-showfaceboundary"
2937 || anArg == "-showfaceboundaries"
2938 || anArg == "-drawfaceedges"
2939 || anArg == "-faceboundary"
2940 || anArg == "-faceboundaries"
2941 || anArg == "-faceedges")
2943 bool toEnable = true;
2944 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2946 std::cout << "Error: wrong syntax at " << anArg << "\n";
2950 aChangeSet->ToSetFaceBoundaryDraw = toEnable ? 1 : -1;
2952 else if (anArg == "-unsetfaceboundary"
2953 || anArg == "-unsetboundary")
2955 aChangeSet->ToSetFaceBoundaryDraw = -1;
2956 aChangeSet->ToSetFaceBoundaryColor = -1;
2958 else if (anArg == "-setmostcontinuity"
2959 || anArg == "-mostcontinuity")
2961 TCollection_AsciiString aClassArg (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "");
2962 aClassArg.LowerCase();
2963 GeomAbs_Shape aClass = GeomAbs_CN;
2964 if (aClassArg == "c0"
2965 || aClassArg == "0")
2967 aClass = GeomAbs_C0;
2969 else if (aClassArg == "c1"
2970 || aClassArg == "1")
2972 aClass = GeomAbs_C1;
2974 else if (aClassArg == "c2"
2975 || aClassArg == "2")
2977 aClass = GeomAbs_C2;
2979 else if (aClassArg == "c3"
2980 || aClassArg == "3")
2982 aClass = GeomAbs_C3;
2984 else if (aClassArg == "cn"
2985 || aClassArg == "n")
2987 aClass = GeomAbs_CN;
2991 std::cout << "Syntax error at '" << anArg << "'\n";
2996 aChangeSet->ToSetFaceBoundaryUpperContinuity = 1;
2997 aChangeSet->FaceBoundaryUpperContinuity = aClass;
2999 else if (anArg == "-setmaxparamvalue"
3000 || anArg == "-maxparamvalue")
3002 if (++anArgIter >= theArgNb)
3004 std::cout << "Error: wrong syntax at " << anArg << "\n";
3007 aChangeSet->ToSetMaxParamValue = 1;
3008 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
3010 else if (anArg == "-setsensitivity"
3011 || anArg == "-sensitivity")
3015 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
3019 if (aNames.IsEmpty())
3021 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
3025 if (anArgIter + 2 >= theArgNb)
3027 std::cout << "Error: wrong syntax at " << anArg << "\n";
3030 aChangeSet->ToSetSensitivity = 1;
3031 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
3032 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
3034 else if (anArg == "-sethatch"
3035 || anArg == "-hatch")
3039 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
3043 if (aNames.IsEmpty())
3045 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
3049 aChangeSet->ToSetHatch = 1;
3050 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
3051 if (anArgHatch.Length() <= 2)
3053 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
3055 || anIntStyle >= Aspect_HS_NB)
3057 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
3060 aChangeSet->StdHatchStyle = anIntStyle;
3064 aChangeSet->PathToHatchPattern = anArgHatch;
3067 else if (anArg == "-setshadingmodel"
3068 || anArg == "-setshading"
3069 || anArg == "-shadingmodel"
3070 || anArg == "-shading")
3072 if (++anArgIter >= theArgNb)
3074 std::cout << "Error: wrong syntax at " << anArg << "\n";
3077 aChangeSet->ToSetShadingModel = 1;
3078 aChangeSet->ShadingModelName = theArgVec[anArgIter];
3079 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
3081 std::cout << "Error: wrong syntax at " << anArg << "\n";
3085 else if (anArg == "-unsetshadingmodel")
3087 aChangeSet->ToSetShadingModel = -1;
3088 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
3090 else if (anArg == "-setinterior"
3091 || anArg == "-setinteriorstyle"
3092 || anArg == "-interior"
3093 || anArg == "-interiorstyle")
3095 if (++anArgIter >= theArgNb)
3097 std::cout << "Error: wrong syntax at " << anArg << "\n";
3100 aChangeSet->ToSetInterior = 1;
3101 if (!parseInteriorStyle (theArgVec[anArgIter], aChangeSet->InteriorStyle))
3103 std::cout << "Error: wrong syntax at " << anArg << "\n";
3107 else if (anArg == "-unsetinterior")
3109 aChangeSet->ToSetInterior = -1;
3110 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3112 else if (anArg == "-setdrawoutline"
3113 || anArg == "-setdrawsilhouette"
3114 || anArg == "-setoutline"
3115 || anArg == "-setsilhouette"
3116 || anArg == "-outline"
3117 || anArg == "-outlined"
3118 || anArg == "-silhouette")
3120 bool toDrawOutline = true;
3121 if (anArgIter + 1 < theArgNb
3122 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawOutline))
3126 aChangeSet->ToSetDrawSilhouette = toDrawOutline ? 1 : -1;
3128 else if (anArg == "-setdrawedges"
3129 || anArg == "-setdrawedge"
3130 || anArg == "-drawedges"
3131 || anArg == "-drawedge"
3132 || anArg == "-edges")
3134 bool toDrawEdges = true;
3135 if (anArgIter + 1 < theArgNb
3136 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawEdges))
3140 aChangeSet->ToSetDrawEdges = toDrawEdges ? 1 : -1;
3142 else if (anArg == "-setquadedges"
3143 || anArg == "-setquads"
3144 || anArg == "-quads"
3145 || anArg == "-skipfirstedge")
3147 bool isQuadMode = true;
3148 if (anArgIter + 1 < theArgNb
3149 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isQuadMode))
3153 aChangeSet->ToSetQuadEdges = isQuadMode ? 1 : -1;
3155 else if (anArg == "-setedgecolor"
3156 || anArg == "-setedgescolor"
3157 || anArg == "-edgecolor"
3158 || anArg == "-edgescolor")
3160 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3161 theArgVec + anArgIter + 1,
3162 aChangeSet->EdgeColor);
3165 std::cout << "Syntax error at '" << anArg << "'\n";
3168 anArgIter += aNbParsed;
3169 aChangeSet->ToSetEdgeColor = 1;
3171 else if (anArg == "-unset")
3173 aChangeSet->ToSetVisibility = 1;
3174 aChangeSet->Visibility = 1;
3175 aChangeSet->ToSetLineWidth = -1;
3176 aChangeSet->LineWidth = 1.0;
3177 aChangeSet->ToSetTypeOfLine = -1;
3178 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
3179 aChangeSet->ToSetTypeOfMarker = -1;
3180 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
3181 aChangeSet->ToSetMarkerSize = -1;
3182 aChangeSet->MarkerSize = 1.0;
3183 aChangeSet->ToSetTransparency = -1;
3184 aChangeSet->Transparency = 0.0;
3185 aChangeSet->ToSetAlphaMode = -1;
3186 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
3187 aChangeSet->AlphaCutoff = 0.5f;
3188 aChangeSet->ToSetColor = -1;
3189 aChangeSet->Color = DEFAULT_COLOR;
3190 aChangeSet->ToSetMaterial = -1;
3191 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
3192 aChangeSet->ToSetShowFreeBoundary = -1;
3193 aChangeSet->ToSetFreeBoundaryColor = -1;
3194 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
3195 aChangeSet->ToSetFreeBoundaryWidth = -1;
3196 aChangeSet->FreeBoundaryWidth = 1.0;
3197 aChangeSet->ToEnableIsoOnTriangulation = -1;
3199 aChangeSet->ToSetFaceBoundaryDraw = -1;
3200 aChangeSet->ToSetFaceBoundaryUpperContinuity = -1;
3201 aChangeSet->FaceBoundaryUpperContinuity = GeomAbs_CN;
3202 aChangeSet->ToSetFaceBoundaryColor = -1;
3203 aChangeSet->FaceBoundaryColor = Quantity_NOC_BLACK;
3204 aChangeSet->ToSetFaceBoundaryWidth = -1;
3205 aChangeSet->FaceBoundaryWidth = 1.0f;
3206 aChangeSet->ToSetTypeOfFaceBoundaryLine = -1;
3207 aChangeSet->TypeOfFaceBoundaryLine = Aspect_TOL_SOLID;
3209 aChangeSet->ToSetHatch = -1;
3210 aChangeSet->StdHatchStyle = -1;
3211 aChangeSet->PathToHatchPattern.Clear();
3212 aChangeSet->ToSetShadingModel = -1;
3213 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
3214 aChangeSet->ToSetInterior = -1;
3215 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3216 aChangeSet->ToSetDrawSilhouette = -1;
3217 aChangeSet->ToSetDrawEdges = -1;
3218 aChangeSet->ToSetQuadEdges = -1;
3219 aChangeSet->ToSetEdgeColor = -1;
3220 aChangeSet->EdgeColor = Quantity_ColorRGBA (DEFAULT_COLOR);
3221 aChangeSet->ToSetEdgeWidth = -1;
3222 aChangeSet->EdgeWidth = 1.0;
3223 aChangeSet->ToSetTypeOfEdge = -1;
3224 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
3228 std::cout << "Error: wrong syntax at " << anArg << "\n";
3233 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3234 aChangesIter.More(); aChangesIter.Next())
3236 if (!aChangesIter.Value().Validate())
3242 // special case for -defaults parameter.
3243 // all changed values will be set to DefaultDrawer.
3246 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
3247 aChangeSet->Apply (aDrawer);
3248 if (aChangeSet->ToSetLineWidth != 0)
3250 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
3251 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
3252 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
3253 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
3255 if (aChangeSet->ToSetColor != 0)
3257 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
3258 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
3259 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
3260 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
3261 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
3262 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
3264 if (aChangeSet->ToSetTransparency != 0)
3266 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
3268 if (aChangeSet->ToSetMaterial != 0)
3270 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
3272 if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3274 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
3277 // redisplay all objects in context
3278 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3280 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3283 aCtx->Redisplay (aPrs, Standard_False);
3289 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3291 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
3292 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3298 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
3299 Handle(AIS_ColoredShape) aColoredPrs;
3300 Standard_Boolean toDisplay = Standard_False;
3301 Standard_Boolean toRedisplay = Standard_False;
3302 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
3304 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
3305 if (aShapePrs.IsNull())
3307 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
3310 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
3311 if (aColoredPrs.IsNull())
3313 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3314 if (aShapePrs->HasDisplayMode())
3316 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
3318 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
3319 aCtx->Remove (aShapePrs, Standard_False);
3320 GetMapOfAIS().UnBind2 (aName);
3321 GetMapOfAIS().Bind (aColoredPrs, aName);
3322 toDisplay = Standard_True;
3323 aShapePrs = aColoredPrs;
3330 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3331 aChangeSet = &aChangesIter.ChangeValue();
3332 if (aChangeSet->ToSetVisibility == 1)
3334 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
3335 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
3337 else if (aChangeSet->ToSetMaterial == 1)
3339 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
3341 else if (aChangeSet->ToSetMaterial == -1)
3343 aCtx->UnsetMaterial (aPrs, Standard_False);
3345 if (aChangeSet->ToSetColor == 1)
3347 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
3349 else if (aChangeSet->ToSetColor == -1)
3351 aCtx->UnsetColor (aPrs, Standard_False);
3353 if (aChangeSet->ToSetTransparency == 1)
3355 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
3357 else if (aChangeSet->ToSetTransparency == -1)
3359 aCtx->UnsetTransparency (aPrs, Standard_False);
3361 if (aChangeSet->ToSetLineWidth == 1)
3363 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
3365 else if (aChangeSet->ToSetLineWidth == -1)
3367 aCtx->UnsetWidth (aPrs, Standard_False);
3369 else if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3371 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
3372 toRedisplay = Standard_True;
3374 else if (aChangeSet->ToSetSensitivity != 0)
3376 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3378 if (!aDrawer.IsNull())
3380 toRedisplay = aChangeSet->Apply (aDrawer) || toRedisplay;
3383 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
3385 aChangeSet = &aChangesIter.ChangeValue();
3386 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
3387 aSubShapeIter.More(); aSubShapeIter.Next())
3389 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
3390 if (!aChangeSet->IsEmpty())
3392 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3393 aChangeSet->Apply (aCurColDrawer);
3395 if (aChangeSet->ToSetVisibility == 1)
3397 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3398 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
3400 if (aChangeSet->ToSetColor == 1)
3402 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
3404 if (aChangeSet->ToSetTransparency == 1)
3406 aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency);
3408 if (aChangeSet->ToSetLineWidth == 1)
3410 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
3412 if (aChangeSet->ToSetColor == -1
3413 || aChangeSet->ToSetLineWidth == -1)
3415 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
3417 if (aChangeSet->ToSetSensitivity != 0)
3419 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3425 aCtx->Display (aPrs, Standard_False);
3429 aCtx->Redisplay (aPrs, Standard_False);
3431 else if (!aColoredPrs.IsNull())
3433 aCtx->Redisplay (aColoredPrs, Standard_False);
3437 aPrs->SynchronizeAspects();
3444 //==============================================================================
3445 //function : VDonly2
3447 //purpose : Display only a selected or named object
3448 // if there is no selected or named object s, nothing is done
3449 //==============================================================================
3450 static int VDonly2 (Draw_Interpretor& ,
3451 Standard_Integer theArgNb,
3452 const char** theArgVec)
3454 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3455 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3458 std::cerr << "Error: no active view!\n";
3462 Standard_Integer anArgIter = 1;
3463 for (; anArgIter < theArgNb; ++anArgIter)
3465 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3471 NCollection_Map<Handle(Standard_Transient)> aDispSet;
3472 if (anArgIter >= theArgNb)
3474 // display only selected objects
3475 if (aCtx->NbSelected() < 1)
3480 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3482 aDispSet.Add (aCtx->SelectedInteractive());
3487 // display only specified objects
3488 for (; anArgIter < theArgNb; ++anArgIter)
3490 TCollection_AsciiString aName = theArgVec[anArgIter];
3491 Handle(AIS_InteractiveObject) aShape;
3492 if (GetMapOfAIS().Find2 (aName, aShape)
3493 && !aShape.IsNull())
3495 aCtx->Display (aShape, Standard_False);
3496 aDispSet.Add (aShape);
3501 // weed out other objects
3502 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
3504 if (aDispSet.Contains (anIter.Key1()))
3509 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
3511 aCtx->Erase (aShape, Standard_False);
3517 //==============================================================================
3518 //function : VRemove
3519 //purpose : Removes selected or named objects.
3520 // If there is no selected or named objects,
3521 // all objects in the viewer can be removed with argument -all.
3522 // If -context is in arguments, the object is not deleted from the map of
3523 // objects (deleted only from the current context).
3524 //==============================================================================
3525 int VRemove (Draw_Interpretor& theDI,
3526 Standard_Integer theArgNb,
3527 const char** theArgVec)
3529 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3530 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3533 std::cerr << "Error: no active view!\n";
3537 Standard_Boolean isContextOnly = Standard_False;
3538 Standard_Boolean toRemoveAll = Standard_False;
3539 Standard_Boolean toPrintInfo = Standard_True;
3541 Standard_Integer anArgIter = 1;
3542 for (; anArgIter < theArgNb; ++anArgIter)
3544 TCollection_AsciiString anArg = theArgVec[anArgIter];
3546 if (anArg == "-context")
3548 isContextOnly = Standard_True;
3550 else if (anArg == "-all")
3552 toRemoveAll = Standard_True;
3554 else if (anArg == "-noinfo")
3556 toPrintInfo = Standard_False;
3558 else if (anUpdateTool.parseRedrawMode (anArg))
3568 && anArgIter < theArgNb)
3570 std::cerr << "Error: wrong syntax!\n";
3574 NCollection_List<TCollection_AsciiString> anIONameList;
3577 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3578 anIter.More(); anIter.Next())
3580 anIONameList.Append (anIter.Key2());
3583 else if (anArgIter < theArgNb) // removed objects names are in argument list
3585 for (; anArgIter < theArgNb; ++anArgIter)
3587 TCollection_AsciiString aName = theArgVec[anArgIter];
3588 Handle(AIS_InteractiveObject) anIO;
3589 if (!GetMapOfAIS().Find2 (aName, anIO))
3591 theDI << aName << " was not bound to some object.\n";
3595 if (anIO->GetContext() != aCtx)
3597 theDI << aName << " was not displayed in current context.\n";
3598 theDI << "Please activate view with this object displayed and try again.\n";
3602 anIONameList.Append (aName);
3606 else if (aCtx->NbSelected() > 0)
3608 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3609 anIter.More(); anIter.Next())
3611 if (!aCtx->IsSelected (anIter.Key1()))
3616 anIONameList.Append (anIter.Key2());
3621 // Unbind all removed objects from the map of displayed IO.
3622 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3623 anIter.More(); anIter.Next())
3625 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
3626 aCtx->Remove (anIO, Standard_False);
3629 theDI << anIter.Value() << " was removed\n";
3633 GetMapOfAIS().UnBind2 (anIter.Value());
3639 //==============================================================================
3641 //purpose : Erase some selected or named objects
3642 // if there is no selected or named objects, the whole viewer is erased
3643 //==============================================================================
3644 int VErase (Draw_Interpretor& theDI,
3645 Standard_Integer theArgNb,
3646 const char** theArgVec)
3648 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3649 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3650 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3653 std::cerr << "Error: no active view!\n";
3657 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3659 Standard_Integer anArgIter = 1;
3660 Standard_Boolean toEraseInView = Standard_False;
3661 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3662 for (; anArgIter < theArgNb; ++anArgIter)
3664 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3665 anArgCase.LowerCase();
3666 if (anUpdateTool.parseRedrawMode (anArgCase))
3670 else if (anArgCase == "-view"
3671 || anArgCase == "-inview")
3673 toEraseInView = Standard_True;
3677 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3681 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3683 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3687 if (!aNamesOfEraseIO.IsEmpty())
3689 // Erase named objects
3690 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
3692 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
3693 Handle(AIS_InteractiveObject) anIO;
3694 if (!GetMapOfAIS().Find2 (aName, anIO))
3699 theDI << aName << " ";
3704 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3708 aCtx->Erase (anIO, Standard_False);
3713 else if (!toEraseAll && aCtx->NbSelected() > 0)
3715 // Erase selected objects
3716 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3717 anIter.More(); anIter.Next())
3719 const Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3721 && aCtx->IsSelected (anIO))
3723 theDI << anIter.Key2() << " ";
3726 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3733 aCtx->EraseSelected (Standard_False);
3738 // Erase all objects
3739 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3740 anIter.More(); anIter.Next())
3742 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3747 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3751 aCtx->Erase (anIO, Standard_False);
3760 //==============================================================================
3761 //function : VDisplayAll
3762 //purpose : Display all the objects of the Map
3763 //==============================================================================
3764 static int VDisplayAll (Draw_Interpretor& ,
3765 Standard_Integer theArgNb,
3766 const char** theArgVec)
3769 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3770 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3773 std::cerr << "Error: no active view!\n";
3777 Standard_Integer anArgIter = 1;
3778 for (; anArgIter < theArgNb; ++anArgIter)
3780 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3781 anArgCase.LowerCase();
3782 if (anUpdateTool.parseRedrawMode (anArgCase))
3791 if (anArgIter < theArgNb)
3793 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3797 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3798 anIter.More(); anIter.Next())
3800 aCtx->Erase (anIter.Key1(), Standard_False);
3803 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3804 anIter.More(); anIter.Next())
3806 aCtx->Display (anIter.Key1(), Standard_False);
3811 //! Auxiliary method to check if presentation exists
3812 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3813 const Handle(AIS_InteractiveObject)& theIO,
3814 const Standard_Integer theMode)
3816 if (theIO.IsNull() || theCtx.IsNull())
3823 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3828 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3830 return theIO->DisplayMode();
3832 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3834 return theCtx->DisplayMode();
3840 enum ViewerTest_BndAction
3847 //! Auxiliary method to print bounding box of presentation
3848 inline void bndPresentation (Draw_Interpretor& theDI,
3849 const Handle(PrsMgr_PresentationManager)& theMgr,
3850 const Handle(AIS_InteractiveObject)& theObj,
3851 const Standard_Integer theDispMode,
3852 const TCollection_AsciiString& theName,
3853 const ViewerTest_BndAction theAction,
3854 const Handle(Prs3d_Drawer)& theStyle)
3858 case BndAction_Hide:
3860 theMgr->Unhighlight (theObj);
3863 case BndAction_Show:
3865 theMgr->Color (theObj, theStyle, theDispMode);
3868 case BndAction_Print:
3871 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3873 if (aPrsIter.Value().Mode() != theDispMode)
3876 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3878 gp_Pnt aMin = aBox.CornerMin();
3879 gp_Pnt aMax = aBox.CornerMax();
3880 theDI << theName << "\n"
3881 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3882 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
3888 //==============================================================================
3889 //function : VBounding
3891 //==============================================================================
3892 int VBounding (Draw_Interpretor& theDI,
3893 Standard_Integer theArgNb,
3894 const char** theArgVec)
3896 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3897 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3900 std::cout << "Error: no active view!\n";
3904 ViewerTest_BndAction anAction = BndAction_Show;
3905 Standard_Integer aMode = -1;
3907 Handle(Prs3d_Drawer) aStyle;
3909 Standard_Integer anArgIter = 1;
3910 for (; anArgIter < theArgNb; ++anArgIter)
3912 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3914 if (anArg == "-print")
3916 anAction = BndAction_Print;
3918 else if (anArg == "-show")
3920 anAction = BndAction_Show;
3922 else if (anArg == "-hide")
3924 anAction = BndAction_Hide;
3926 else if (anArg == "-mode")
3928 if (++anArgIter >= theArgNb)
3930 std::cout << "Error: wrong syntax at " << anArg << "\n";
3933 aMode = Draw::Atoi (theArgVec[anArgIter]);
3935 else if (!anUpdateTool.parseRedrawMode (anArg))
3941 if (anAction == BndAction_Show)
3943 aStyle = new Prs3d_Drawer();
3944 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3945 aStyle->SetColor (Quantity_NOC_GRAY99);
3948 Standard_Integer aHighlightedMode = -1;
3949 if (anArgIter < theArgNb)
3951 // has a list of names
3952 for (; anArgIter < theArgNb; ++anArgIter)
3954 TCollection_AsciiString aName = theArgVec[anArgIter];
3955 Handle(AIS_InteractiveObject) anIO;
3956 if (!GetMapOfAIS().Find2 (aName, anIO))
3958 std::cout << "Error: presentation " << aName << " does not exist\n";
3962 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3963 if (aHighlightedMode == -1)
3965 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3968 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3971 else if (aCtx->NbSelected() > 0)
3973 // remove all currently selected objects
3974 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3976 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3977 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3978 if (aHighlightedMode != -1)
3980 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3981 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3988 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3989 anIter.More(); anIter.Next())
3991 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3992 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3993 if (aHighlightedMode != -1)
3995 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
4002 //==============================================================================
4003 //function : VTexture
4005 //==============================================================================
4006 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4008 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4011 std::cout << "Error: no active view!\n";
4015 int toModulate = -1;
4016 bool toSetFilter = false;
4017 bool toSetAniso = false;
4018 bool toSetTrsfAngle = false;
4019 bool toSetTrsfTrans = false;
4020 bool toSetTrsfScale = false;
4021 Standard_ShortReal aTrsfRotAngle = 0.0f;
4022 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
4023 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
4024 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
4025 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
4027 Handle(AIS_InteractiveObject) aTexturedIO;
4028 Handle(AIS_Shape) aTexturedShape;
4029 Handle(Graphic3d_TextureSet) aTextureSetOld;
4030 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
4031 bool toSetGenRepeat = false;
4032 bool toSetGenScale = false;
4033 bool toSetGenOrigin = false;
4034 bool toSetImage = false;
4035 bool toComputeUV = false;
4037 const TCollection_AsciiString aCommandName (theArgVec[0]);
4038 bool toSetDefaults = aCommandName == "vtexdefault";
4040 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4041 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
4043 const TCollection_AsciiString aName = theArgVec[anArgIter];
4044 TCollection_AsciiString aNameCase = aName;
4045 aNameCase.LowerCase();
4046 if (anUpdateTool.parseRedrawMode (aName))
4050 else if (aTexturedIO.IsNull())
4052 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
4053 if (aMapOfIO.IsBound2 (aName))
4055 aTexturedIO = aMapOfIO.Find2 (aName);
4056 aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO);
4058 if (aTexturedIO.IsNull())
4060 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
4064 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
4066 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
4069 else if (!aTexturedShape.IsNull()
4070 && (aNameCase == "-scale"
4071 || aNameCase == "-setscale"
4072 || aCommandName == "vtexscale"))
4074 if (aCommandName != "vtexscale")
4078 if (anArgIter < theArgsNb)
4080 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4081 TCollection_AsciiString aValUCase = aValU;
4082 aValUCase.LowerCase();
4083 toSetGenScale = true;
4084 if (aValUCase == "off")
4086 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4089 else if (anArgIter + 1 < theArgsNb)
4091 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4092 if (aValU.IsRealValue()
4093 && aValV.IsRealValue())
4095 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4101 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4104 else if (!aTexturedShape.IsNull()
4105 && (aNameCase == "-origin"
4106 || aNameCase == "-setorigin"
4107 || aCommandName == "vtexorigin"))
4109 if (aCommandName != "vtexorigin")
4113 if (anArgIter < theArgsNb)
4115 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4116 TCollection_AsciiString aValUCase = aValU;
4117 aValUCase.LowerCase();
4118 toSetGenOrigin = true;
4119 if (aValUCase == "off")
4121 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4124 else if (anArgIter + 1 < theArgsNb)
4126 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4127 if (aValU.IsRealValue()
4128 && aValV.IsRealValue())
4130 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4136 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4139 else if (!aTexturedShape.IsNull()
4140 && (aNameCase == "-repeat"
4141 || aNameCase == "-setrepeat"
4142 || aCommandName == "vtexrepeat"))
4144 if (aCommandName != "vtexrepeat")
4148 if (anArgIter < theArgsNb)
4150 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4151 TCollection_AsciiString aValUCase = aValU;
4152 aValUCase.LowerCase();
4153 toSetGenRepeat = true;
4154 if (aValUCase == "off")
4156 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4159 else if (anArgIter + 1 < theArgsNb)
4161 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4162 if (aValU.IsRealValue()
4163 && aValV.IsRealValue())
4165 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4171 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4174 else if (aNameCase == "-modulate")
4176 bool toModulateBool = true;
4177 if (anArgIter + 1 < theArgsNb
4178 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
4182 toModulate = toModulateBool ? 1 : 0;
4184 else if ((aNameCase == "-setfilter"
4185 || aNameCase == "-filter")
4186 && anArgIter + 1 < theArgsNb)
4188 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4192 if (aValue == "nearest")
4194 aFilter = Graphic3d_TOTF_NEAREST;
4196 else if (aValue == "bilinear")
4198 aFilter = Graphic3d_TOTF_BILINEAR;
4200 else if (aValue == "trilinear")
4202 aFilter = Graphic3d_TOTF_TRILINEAR;
4206 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
4210 else if ((aNameCase == "-setaniso"
4211 || aNameCase == "-setanisofilter"
4212 || aNameCase == "-aniso"
4213 || aNameCase == "-anisofilter")
4214 && anArgIter + 1 < theArgsNb)
4216 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4220 if (aValue == "off")
4222 anAnisoFilter = Graphic3d_LOTA_OFF;
4224 else if (aValue == "fast")
4226 anAnisoFilter = Graphic3d_LOTA_FAST;
4228 else if (aValue == "middle")
4230 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
4232 else if (aValue == "quality"
4233 || aValue == "high")
4235 anAnisoFilter = Graphic3d_LOTA_QUALITY;
4239 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
4243 else if ((aNameCase == "-rotateangle"
4244 || aNameCase == "-rotangle"
4245 || aNameCase == "-rotate"
4246 || aNameCase == "-angle"
4247 || aNameCase == "-trsfangle")
4248 && anArgIter + 1 < theArgsNb)
4250 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4251 toSetTrsfAngle = true;
4254 else if ((aNameCase == "-trsftrans"
4255 || aNameCase == "-trsftranslate"
4256 || aNameCase == "-translate"
4257 || aNameCase == "-translation")
4258 && anArgIter + 2 < theArgsNb)
4260 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4261 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4262 toSetTrsfTrans = true;
4265 else if ((aNameCase == "-trsfscale")
4266 && anArgIter + 2 < theArgsNb)
4268 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4269 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4270 toSetTrsfScale = true;
4273 else if (aNameCase == "-default"
4274 || aNameCase == "-defaults")
4276 toSetDefaults = true;
4278 else if ((aNameCase == "-video")
4279 && anArgIter + 1 < theArgsNb)
4281 const TCollection_AsciiString anInput (theArgVec[++anArgIter]);
4282 Handle(Graphic3d_MediaTextureSet) aMedia = Handle(Graphic3d_MediaTextureSet)::DownCast (aTextureSetOld);
4283 if (aMedia.IsNull())
4285 aMedia = new Graphic3d_MediaTextureSet();
4287 if (aMedia->Input() != anInput)
4289 aMedia->OpenInput (anInput, false);
4293 if (aMedia->SwapFrames()
4294 && !aCtx->CurrentViewer()->ZLayerSettings (aTexturedIO->ZLayer()).IsImmediate())
4296 ViewerTest::CurrentView()->Invalidate();
4299 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4300 && aTexturedShape.IsNull())
4302 aTexturedIO->SetToUpdate();
4305 toComputeUV = aTextureSetOld.IsNull();
4306 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (true);
4307 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia);
4308 aTextureSetOld.Nullify();
4310 else if (aCommandName == "vtexture"
4311 && (aTextureVecNew.IsEmpty()
4312 || aNameCase.StartsWith ("-tex")))
4314 Standard_Integer aTexIndex = 0;
4315 TCollection_AsciiString aTexName = aName;
4316 if (aNameCase.StartsWith ("-tex"))
4318 if (anArgIter + 1 >= theArgsNb
4319 || aNameCase.Length() < 5)
4321 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4325 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
4326 if (!aTexIndexStr.IsIntegerValue())
4328 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4332 aTexIndex = aTexIndexStr.IntegerValue();
4333 aTexName = theArgVec[anArgIter + 1];
4336 if (aTexIndex >= Graphic3d_TextureUnit_NB
4337 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
4339 std::cout << "Error: too many textures specified\n";
4344 if (aTexName.IsIntegerValue())
4346 const Standard_Integer aValue = aTexName.IntegerValue();
4347 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
4349 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
4352 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
4354 else if (aTexName == "?")
4356 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
4358 theDi << "\n Files in current directory : \n\n";
4359 theDi.Eval ("glob -nocomplain *");
4361 TCollection_AsciiString aCmnd ("glob -nocomplain ");
4362 aCmnd += aTextureFolder;
4365 theDi << "Files in " << aTextureFolder << " : \n\n";
4366 theDi.Eval (aCmnd.ToCString());
4369 else if (aTexName != "off")
4371 if (!OSD_File (aTexName).Exists())
4373 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
4376 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
4380 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
4383 if (aTextureVecNew.Value (aTexIndex))
4385 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
4390 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4397 // check if new image set is equal to already set one
4398 Standard_Integer aNbChanged = 0;
4399 Handle(Graphic3d_TextureSet) aTextureSetNew;
4400 if (!aTextureVecNew.IsEmpty())
4402 aNbChanged = aTextureVecNew.Size();
4403 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
4404 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
4406 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
4407 Handle(Graphic3d_TextureRoot) aTextureOld;
4408 if (!aTextureSetOld.IsNull()
4409 && aTexIter < aTextureSetOld->Size())
4411 aTextureOld = aTextureSetOld->Value (aTexIter);
4414 if (!aTextureOld.IsNull()
4415 && !aTextureNew.IsNull())
4417 *aTextureNew->GetParams() = *aTextureOld->GetParams();
4418 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
4420 TCollection_AsciiString aFilePathOld, aFilePathNew;
4421 aTextureOld->Path().SystemName (aFilePathOld);
4422 aTextureNew->Path().SystemName (aFilePathNew);
4423 if (aTextureNew->Name() == anOldManualTex->Name()
4424 && aFilePathOld == aFilePathNew
4425 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
4428 aTextureNew = anOldManualTex;
4432 aTextureSetNew->SetValue (aTexIter, aTextureNew);
4436 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
4437 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
4439 aTextureSetNew = aTextureSetOld;
4442 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4443 && aTexturedShape.IsNull())
4445 aTexturedIO->SetToUpdate();
4448 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
4449 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
4450 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
4451 aTextureSetOld.Nullify();
4456 if (toModulate != -1)
4463 aFilter = Graphic3d_TOTF_BILINEAR;
4468 anAnisoFilter = Graphic3d_LOTA_OFF;
4470 if (!toSetTrsfAngle)
4472 toSetTrsfAngle = true;
4473 aTrsfRotAngle = 0.0f;
4475 if (!toSetTrsfTrans)
4477 toSetTrsfTrans = true;
4478 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
4480 if (!toSetTrsfScale)
4482 toSetTrsfScale = true;
4483 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
4487 if (aCommandName == "vtexture"
4490 if (!aTextureSetOld.IsNull())
4492 //toComputeUV = true; // we can keep UV vertex attributes
4493 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
4494 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
4495 aTextureSetOld.Nullify();
4499 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
4500 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
4502 if (toModulate != -1)
4504 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
4508 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
4512 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
4516 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
4520 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
4524 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
4528 // set default values if requested
4530 && (aCommandName == "vtexrepeat"
4533 if (!aTexturedShape.IsNull())
4535 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4537 toSetGenRepeat = true;
4540 && (aCommandName == "vtexorigin"
4543 if (!aTexturedShape.IsNull())
4545 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4547 toSetGenOrigin = true;
4550 && (aCommandName == "vtexscale"
4553 if (!aTexturedShape.IsNull())
4555 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4557 toSetGenScale = true;
4560 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
4562 if (!aTexturedShape.IsNull())
4564 aTexturedShape->SetToUpdate (AIS_Shaded);
4567 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
4568 || aCtx->DisplayMode() != AIS_Shaded)
4570 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
4575 aCtx->Display (aTexturedIO, false);
4576 aTexturedIO->SynchronizeAspects();
4580 //! Auxiliary method to parse transformation persistence flags
4581 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
4582 Graphic3d_TransModeFlags& theFlags)
4584 if (theFlagString == "zoom")
4586 theFlags = Graphic3d_TMF_ZoomPers;
4588 else if (theFlagString == "rotate")
4590 theFlags = Graphic3d_TMF_RotatePers;
4592 else if (theFlagString == "zoomrotate")
4594 theFlags = Graphic3d_TMF_ZoomRotatePers;
4596 else if (theFlagString == "trihedron"
4597 || theFlagString == "triedron")
4599 theFlags = Graphic3d_TMF_TriedronPers;
4601 else if (theFlagString == "none")
4603 theFlags = Graphic3d_TMF_None;
4607 return Standard_False;
4610 return Standard_True;
4613 //! Auxiliary method to parse transformation persistence flags
4614 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4615 Aspect_TypeOfTriedronPosition& theCorner)
4617 TCollection_AsciiString aString (theString);
4618 aString.LowerCase();
4619 if (aString == "center")
4621 theCorner = Aspect_TOTP_CENTER;
4623 else if (aString == "top"
4624 || aString == "upper")
4626 theCorner = Aspect_TOTP_TOP;
4628 else if (aString == "bottom"
4629 || aString == "lower")
4631 theCorner = Aspect_TOTP_BOTTOM;
4633 else if (aString == "left")
4635 theCorner = Aspect_TOTP_LEFT;
4637 else if (aString == "right")
4639 theCorner = Aspect_TOTP_RIGHT;
4641 else if (aString == "topleft"
4642 || aString == "leftupper"
4643 || aString == "upperleft")
4645 theCorner = Aspect_TOTP_LEFT_UPPER;
4647 else if (aString == "bottomleft"
4648 || aString == "leftlower"
4649 || aString == "lowerleft")
4651 theCorner = Aspect_TOTP_LEFT_LOWER;
4653 else if (aString == "topright"
4654 || aString == "rightupper"
4655 || aString == "upperright")
4657 theCorner = Aspect_TOTP_RIGHT_UPPER;
4659 else if (aString == "bottomright"
4660 || aString == "lowerright"
4661 || aString == "rightlower")
4663 theCorner = Aspect_TOTP_RIGHT_LOWER;
4667 return Standard_False;
4670 return Standard_True;
4673 //==============================================================================
4674 //function : VDisplay2
4676 //purpose : Display an object from its name
4677 //==============================================================================
4678 static int VDisplay2 (Draw_Interpretor& theDI,
4679 Standard_Integer theArgNb,
4680 const char** theArgVec)
4684 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4688 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4691 ViewerTest::ViewerInit();
4692 aCtx = ViewerTest::GetAISContext();
4695 // Parse input arguments
4696 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4697 Standard_Integer isMutable = -1;
4698 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4699 Standard_Boolean toReDisplay = Standard_False;
4700 Standard_Integer isSelectable = -1;
4701 Standard_Integer anObjDispMode = -2;
4702 Standard_Integer anObjHighMode = -2;
4703 Standard_Boolean toSetTrsfPers = Standard_False;
4704 Handle(Graphic3d_TransformPers) aTrsfPers;
4705 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4706 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4707 Standard_Integer toDisplayInView = Standard_False;
4708 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4710 const TCollection_AsciiString aName = theArgVec[anArgIter];
4711 TCollection_AsciiString aNameCase = aName;
4712 aNameCase.LowerCase();
4713 if (anUpdateTool.parseRedrawMode (aName))
4717 else if (aNameCase == "-mutable")
4721 else if (aNameCase == "-neutral")
4723 aDispStatus = AIS_DS_Displayed;
4725 else if (aNameCase == "-immediate"
4726 || aNameCase == "-top")
4728 aZLayer = Graphic3d_ZLayerId_Top;
4730 else if (aNameCase == "-topmost")
4732 aZLayer = Graphic3d_ZLayerId_Topmost;
4734 else if (aNameCase == "-osd"
4735 || aNameCase == "-toposd"
4736 || aNameCase == "-overlay")
4738 aZLayer = Graphic3d_ZLayerId_TopOSD;
4740 else if (aNameCase == "-botosd"
4741 || aNameCase == "-underlay")
4743 aZLayer = Graphic3d_ZLayerId_BotOSD;
4745 else if (aNameCase == "-select"
4746 || aNameCase == "-selectable")
4750 else if (aNameCase == "-noselect"
4751 || aNameCase == "-noselection")
4755 else if (aNameCase == "-dispmode"
4756 || aNameCase == "-displaymode")
4758 if (++anArgIter >= theArgNb)
4760 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4764 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4766 else if (aNameCase == "-highmode"
4767 || aNameCase == "-highlightmode")
4769 if (++anArgIter >= theArgNb)
4771 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4775 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4777 else if (aNameCase == "-3d")
4779 toSetTrsfPers = Standard_True;
4780 aTrsfPers.Nullify();
4782 else if (aNameCase == "-2d"
4783 || aNameCase == "-trihedron"
4784 || aNameCase == "-triedron")
4786 toSetTrsfPers = Standard_True;
4787 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4789 if (anArgIter + 1 < theArgNb)
4791 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4792 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4795 aTrsfPers->SetCorner2d (aCorner);
4797 if (anArgIter + 2 < theArgNb)
4799 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4800 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4801 if (anX.IsIntegerValue()
4802 && anY.IsIntegerValue())
4805 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4811 else if (aNameCase == "-trsfpers"
4812 || aNameCase == "-pers")
4814 if (++anArgIter >= theArgNb
4815 || !aTrsfPers.IsNull())
4817 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4821 toSetTrsfPers = Standard_True;
4822 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4823 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4824 aPersFlags.LowerCase();
4825 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
4827 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
4831 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4833 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4835 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4837 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
4840 else if (aNameCase == "-trsfperspos"
4841 || aNameCase == "-perspos")
4843 if (anArgIter + 2 >= theArgNb
4844 || aTrsfPers.IsNull())
4846 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4850 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4851 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4852 TCollection_AsciiString aZ = "0";
4853 if (!aX.IsRealValue()
4854 || !aY.IsRealValue())
4856 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4859 if (anArgIter + 1 < theArgNb)
4861 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
4862 if (aTemp.IsRealValue())
4869 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
4870 if (aTrsfPers->IsZoomOrRotate())
4872 aTrsfPers->SetAnchorPoint (aPnt);
4874 else if (aTrsfPers->IsTrihedronOr2d())
4876 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
4879 else if (aNameCase == "-layer"
4880 || aNameCase == "-zlayer")
4883 if (anArgIter >= theArgNb
4884 || !ViewerTest::ParseZLayer (theArgVec[anArgIter], aZLayer)
4885 || aZLayer == Graphic3d_ZLayerId_UNKNOWN)
4887 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4891 else if (aNameCase == "-view"
4892 || aNameCase == "-inview")
4894 toDisplayInView = Standard_True;
4896 else if (aNameCase == "-redisplay")
4898 toReDisplay = Standard_True;
4900 else if (aNameCase == "-erased"
4901 || aNameCase == "-load")
4903 aDispStatus = AIS_DS_Erased;
4907 aNamesOfDisplayIO.Append (aName);
4911 if (aNamesOfDisplayIO.IsEmpty())
4913 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4917 // Display interactive objects
4918 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
4920 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value (anIter);
4921 Handle(AIS_InteractiveObject) aShape;
4922 if (!GetMapOfAIS().Find2 (aName, aShape))
4924 // create the AIS_Shape from a name
4925 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
4926 if (!aDrawShape.IsNull())
4928 aShape = new AIS_Shape (aDrawShape);
4929 if (isMutable != -1)
4931 aShape->SetMutable (isMutable == 1);
4933 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4935 aShape->SetZLayer (aZLayer);
4939 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4941 if (anObjDispMode != -2)
4943 aShape->SetDisplayMode (anObjDispMode);
4945 if (anObjHighMode != -2)
4947 aShape->SetHilightMode (anObjHighMode);
4950 GetMapOfAIS().Bind (aShape, aName);
4951 Standard_Integer aDispMode = aShape->HasDisplayMode()
4952 ? aShape->DisplayMode()
4953 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4954 ? aCtx->DisplayMode()
4956 Standard_Integer aSelMode = -1;
4957 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4959 aSelMode = aShape->GlobalSelectionMode();
4962 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
4963 if (toDisplayInView)
4965 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
4967 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
4969 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4974 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
4979 if (isMutable != -1)
4981 aShape->SetMutable (isMutable == 1);
4983 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4985 aShape->SetZLayer (aZLayer);
4989 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4991 if (anObjDispMode != -2)
4993 aShape->SetDisplayMode (anObjDispMode);
4995 if (anObjHighMode != -2)
4997 aShape->SetHilightMode (anObjHighMode);
4999 Standard_Integer aDispMode = aShape->HasDisplayMode()
5000 ? aShape->DisplayMode()
5001 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5002 ? aCtx->DisplayMode()
5004 Standard_Integer aSelMode = -1;
5005 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5007 aSelMode = aShape->GlobalSelectionMode();
5010 if (aShape->Type() == AIS_KOI_Datum)
5012 aCtx->Display (aShape, Standard_False);
5016 theDI << "Display " << aName << "\n";
5018 // update the Shape in the AIS_Shape
5019 TopoDS_Shape aNewShape = DBRep::GetExisting (aName);
5020 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
5021 if (!aShapePrs.IsNull())
5023 if (!aShapePrs->Shape().IsEqual (aNewShape))
5025 toReDisplay = Standard_True;
5027 aShapePrs->Set (aNewShape);
5031 aCtx->Redisplay (aShape, Standard_False);
5036 aCtx->Erase (aShape, Standard_False);
5038 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5039 if (toDisplayInView)
5041 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5049 //=======================================================================
5050 //function : VNbDisplayed
5051 //purpose : Returns number of displayed objects
5052 //=======================================================================
5053 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
5054 Standard_Integer theArgsNb,
5055 const char** theArgVec)
5059 theDi << "Usage : " << theArgVec[0] << "\n";
5063 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5064 if (aContextAIS.IsNull())
5066 std::cout << theArgVec[0] << "AIS context is not available.\n";
5070 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5071 if(aContext.IsNull())
5073 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
5077 AIS_ListOfInteractive aListOfIO;
5078 aContextAIS->DisplayedObjects (aListOfIO);
5080 theDi << aListOfIO.Extent() << "\n";
5084 //===============================================================================================
5085 //function : VUpdate
5087 //===============================================================================================
5088 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
5090 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5091 if (aContextAIS.IsNull())
5093 std::cout << theArgVec[0] << "AIS context is not available.\n";
5099 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
5103 AIS_ListOfInteractive aListOfIO;
5104 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5106 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
5108 Handle(AIS_InteractiveObject) anAISObj;
5109 GetMapOfAIS().Find2 (aName, anAISObj);
5110 if (anAISObj.IsNull())
5112 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
5116 aListOfIO.Append (anAISObj);
5119 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
5120 for (; anIOIt.More(); anIOIt.Next())
5122 aContextAIS->Update (anIOIt.Value(), Standard_False);
5125 aContextAIS->UpdateCurrentViewer();
5130 //==============================================================================
5131 //function : VShading
5132 //purpose : Sharpen or roughten the quality of the shading
5133 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
5134 //==============================================================================
5135 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
5137 Standard_Real myDevCoef;
5138 Handle(AIS_InteractiveObject) TheAisIO;
5141 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
5145 myDevCoef =Draw::Atof(argv[2]);
5148 TCollection_AsciiString name=argv[1];
5149 GetMapOfAIS().Find2(name, TheAisIO);
5150 if (TheAisIO.IsNull())
5152 TopoDS_Shape aDrawShape = DBRep::GetExisting (name);
5153 if (!aDrawShape.IsNull())
5155 TheAisIO = new AIS_Shape (aDrawShape);
5160 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5162 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
5164 TheAISContext()->Redisplay (TheAisIO, Standard_True);
5168 //! Auxiliary method to print Interactive Object information
5169 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
5170 const Handle(AIS_InteractiveObject)& theObj,
5171 Draw_Interpretor& theDI)
5173 if (theObj.IsNull())
5175 theDI << "NULL presentation\n";
5179 theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ")
5180 << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ")
5181 << (theDetected.Contains (theObj) ? " Detected" : " ")
5183 if (theObj->Type() == AIS_KOI_Datum)
5186 if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
5187 else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; }
5188 else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; }
5189 else if (theObj->Signature() == 5) { theDI << " AIS_Line"; }
5190 else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; }
5191 else if (theObj->Signature() == 1) { theDI << " AIS_Point"; }
5192 else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
5195 else if (theObj->Type() == AIS_KOI_Shape
5196 && theObj->Signature() == 0)
5198 theDI << " AIS_Shape";
5200 else if (theObj->Type() == AIS_KOI_Relation)
5202 // AIS_Dimention and AIS_Relation
5203 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (theObj);
5204 switch (aRelation->KindOfDimension())
5206 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
5207 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
5208 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
5209 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
5210 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
5211 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
5212 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
5213 default: theDI << " UNKNOWN dimension"; break;
5218 theDI << " UserPrs";
5220 theDI << " (" << theObj->DynamicType()->Name() << ")";
5223 //! Print information about locally selected sub-shapes
5224 template <typename T>
5225 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
5227 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
5228 TCollection_AsciiString aPrevName;
5229 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
5231 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
5232 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
5233 if (aShapeIO.IsNull() || anOwner.IsNull())
5237 if (anOwner == aShapeIO->GlobalSelOwner())
5240 const TopoDS_Shape aSubShape = theContext->SelectedShape();
5241 if (aSubShape.IsNull()
5242 || aShapeIO.IsNull()
5243 || !GetMapOfAIS().IsBound1 (aShapeIO))
5248 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
5249 TopTools_MapOfShape aFilter;
5250 Standard_Integer aNumber = 0;
5251 const TopoDS_Shape aShape = aShapeIO->Shape();
5252 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
5253 anIter.More(); anIter.Next())
5255 if (!aFilter.Add (anIter.Current()))
5257 continue; // filter duplicates
5261 if (!anIter.Current().IsSame (aSubShape))
5266 Standard_CString aShapeName = NULL;
5267 switch (aSubShape.ShapeType())
5269 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
5270 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
5271 case TopAbs_SOLID: aShapeName = " Solid"; break;
5272 case TopAbs_SHELL: aShapeName = " Shell"; break;
5273 case TopAbs_FACE: aShapeName = " Face"; break;
5274 case TopAbs_WIRE: aShapeName = " Wire"; break;
5275 case TopAbs_EDGE: aShapeName = " Edge"; break;
5276 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
5278 case TopAbs_SHAPE: aShapeName = " Shape"; break;
5281 if (aParentName != aPrevName)
5283 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
5284 aPrevName = aParentName;
5286 theDI << " " << aShapeName << " #" << aNumber << "\n";
5292 //==============================================================================
5295 //==============================================================================
5296 static Standard_Integer VState (Draw_Interpretor& theDI,
5297 Standard_Integer theArgNb,
5298 Standard_CString* theArgVec)
5300 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
5303 std::cerr << "Error: No opened viewer!\n";
5307 Standard_Boolean toPrintEntities = Standard_False;
5308 Standard_Boolean toCheckSelected = Standard_False;
5310 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
5312 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
5313 anOption.LowerCase();
5314 if (anOption == "-detectedentities"
5315 || anOption == "-entities")
5317 toPrintEntities = Standard_True;
5319 else if (anOption == "-hasselected")
5321 toCheckSelected = Standard_True;
5325 if (toCheckSelected)
5327 aCtx->InitSelected();
5328 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
5329 theDI << "Check if context has selected shape: " << hasSelected << "\n";
5334 if (toPrintEntities)
5336 theDI << "Detected entities:\n";
5337 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
5339 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
5340 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
5342 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
5343 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
5344 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
5345 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5346 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
5347 aName.LeftJustify (20, ' ');
5348 char anInfoStr[512];
5350 " Depth: %g Distance: %g Point: %g %g %g",
5353 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
5354 theDI << " " << aName
5356 << " (" << anEntity->DynamicType()->Name() << ")"
5359 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
5360 if (!aBRepOwner.IsNull())
5362 theDI << " Detected Shape: "
5363 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
5367 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
5368 if (!aWire.IsNull())
5370 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
5371 theDI << " Detected Child: "
5372 << aSen->DynamicType()->Name()
5376 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
5377 if (!aPrimArr.IsNull())
5379 theDI << " Detected Element: "
5380 << aPrimArr->LastDetectedElement()
5387 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
5388 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
5390 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
5393 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
5397 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5399 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
5400 Handle(AIS_InteractiveObject) anObj;
5401 if (!GetMapOfAIS().Find2 (anObjName, anObj))
5403 theDI << anObjName << " doesn't exist!\n";
5407 TCollection_AsciiString aName = anObjName;
5408 aName.LeftJustify (20, ' ');
5409 theDI << " " << aName << " ";
5410 objInfo (aDetected, anObj, theDI);
5416 if (aCtx->NbSelected() > 0 && !toShowAll)
5418 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
5419 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
5421 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
5422 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5423 // handle whole object selection
5424 if (anOwner == anObj->GlobalSelOwner())
5426 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
5427 aName.LeftJustify (20, ' ');
5428 theDI << aName << " ";
5429 objInfo (aDetected, anObj, theDI);
5434 // process selected sub-shapes
5435 printLocalSelectionInfo (aCtx, theDI);
5440 theDI << "Neutral-point state:\n";
5441 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5442 anObjIter.More(); anObjIter.Next())
5444 if (anObjIter.Key1().IsNull())
5449 TCollection_AsciiString aName = anObjIter.Key2();
5450 aName.LeftJustify (20, ' ');
5451 theDI << " " << aName << " ";
5452 objInfo (aDetected, anObjIter.Key1(), theDI);
5455 printLocalSelectionInfo (aCtx, theDI);
5459 //=======================================================================
5460 //function : PickShape
5461 //purpose : First Activate the rightmode + Put Filters to be able to
5462 // pick objets that are of type <TheType>...
5463 //=======================================================================
5465 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
5466 const Standard_Integer theMaxPick)
5468 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
5469 PickShapes (theShapeType, aResArray, theMaxPick);
5470 return aResArray->First();
5473 //=======================================================================
5474 //function : PickShapes
5476 //=======================================================================
5477 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
5478 Handle(TopTools_HArray1OfShape)& theResArray,
5479 const Standard_Integer theMaxPick)
5481 const Standard_Integer aNbToReach = theResArray->Length();
5484 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
5487 // step 1: prepare the data
5488 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5489 aCtx->RemoveFilters();
5490 AIS_ListOfInteractive aDispObjects;
5491 aCtx->DisplayedObjects (aDispObjects);
5492 if (theShapeType == TopAbs_SHAPE)
5494 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
5498 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
5501 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
5502 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5504 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5506 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5510 // step 2 : wait for the selection...
5511 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
5512 Standard_Integer argccc = 5;
5513 const char *bufff[] = { "A", "B", "C", "D", "E" };
5514 const char **argvvv = (const char** )bufff;
5515 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
5517 while (ViewerMainLoop (argccc, argvvv)) {}
5518 Standard_Integer aNbStored = aCtx->NbSelected();
5519 if (aNbStored != aNbPickGood)
5521 aNbPickGood = aNbStored;
5527 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
5530 // step3 get result.
5531 if (aNbPickFail >= aNbToReach)
5533 return Standard_False;
5536 Standard_Integer anIndex = theResArray->Lower();
5537 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
5539 if (aCtx->HasSelectedShape())
5541 theResArray->SetValue (anIndex, aCtx->SelectedShape());
5545 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
5546 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
5550 aCtx->RemoveFilters();
5551 if (theShapeType != TopAbs_SHAPE)
5553 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5555 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5557 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5561 return Standard_True;
5564 //=======================================================================
5565 //function : VPickShape
5567 //=======================================================================
5568 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5570 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
5573 TCollection_AsciiString aShapeArg (argv[1]);
5574 aShapeArg.LowerCase();
5575 aShapeType = TopAbs_COMPOUND;
5576 if (aShapeArg == "v"
5577 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
5578 else if (aShapeArg == "e"
5579 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
5580 else if (aShapeArg == "w"
5581 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
5582 else if (aShapeArg == "f"
5583 || aShapeArg == "face") aShapeType = TopAbs_FACE;
5584 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
5585 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
5586 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
5589 std::cout << "Syntax error at '" << argv[1] << "'\n";
5594 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5595 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
5597 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
5600 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
5601 if (aPickedShape.IsNull())
5606 TCollection_AsciiString aName;
5613 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5614 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5617 DBRep::Set (aName.ToCString(), aPickedShape);
5618 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5619 ViewerTest::Display (aName, aShapePrs, false, true);
5620 di << "Name of picked shape: " << aName <<"\n";
5624 TCollection_AsciiString aName (argv[2]);
5626 const Standard_Boolean isAutoNaming = aName == ".";
5627 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5628 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5630 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5632 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5634 if (!aPickedShape.IsNull()
5637 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5638 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5642 aName = argv[1 + aPickedIter];
5645 DBRep::Set (aName.ToCString(), aPickedShape);
5646 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5647 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5648 ViewerTest::Display (aName, aShapePrs, false, true);
5652 TheAISContext()->UpdateCurrentViewer();
5656 //=======================================================================
5657 //function : VSelFilter
5659 //=======================================================================
5660 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5661 const char** theArgv)
5663 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5664 if (aContext.IsNull())
5666 std::cout << "Error: AIS context is not available.\n";
5670 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5672 TCollection_AsciiString anArg (theArgv[anArgIter]);
5674 if (anArg == "-clear")
5676 aContext->RemoveFilters();
5678 else if (anArg == "-type"
5679 && anArgIter + 1 < theArgc)
5681 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5682 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5683 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5685 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5689 Handle(SelectMgr_Filter) aFilter;
5690 if (aShapeType == TopAbs_SHAPE)
5692 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5696 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5698 aContext->AddFilter (aFilter);
5702 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5709 //=======================================================================
5710 //function : VPickSelected
5712 //=======================================================================
5713 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5715 static Standard_Integer aCount = 0;
5716 TCollection_AsciiString aName = "PickedShape_";
5724 aName = aName + aCount++ + "_";
5727 Standard_Integer anIdx = 0;
5728 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5730 TopoDS_Shape aShape;
5731 if (TheAISContext()->HasSelectedShape())
5733 aShape = TheAISContext()->SelectedShape();
5737 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5738 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5741 TCollection_AsciiString aCurrentName = aName;
5744 aCurrentName += anIdx;
5747 DBRep::Set ((aCurrentName).ToCString(), aShape);
5749 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5750 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5751 TheAISContext()->Display (aNewShape, Standard_False);
5754 TheAISContext()->UpdateCurrentViewer();
5759 //=======================================================================
5760 //function : list of known objects
5762 //=======================================================================
5763 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5765 // 1234567890 12345678901234567 123456789
5766 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5767 TCollection_AsciiString BlankLine(64,'_');
5768 Standard_Integer i ;
5770 di<<"/n"<<BlankLine.ToCString()<<"\n";
5773 Colum[i].Center(20,' ');
5775 di<<"|"<<Colum[i].ToCString();
5778 di<<BlankLine.ToCString()<<"\n";
5780 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5781 const char ** names = GetTypeNames();
5783 TCollection_AsciiString curstring;
5784 TCollection_AsciiString curcolum[3];
5787 // les objets de type Datum..
5788 curcolum[1]+="Datum";
5790 curcolum[0].Clear();
5791 curcolum[0] += names[i];
5793 curcolum[2].Clear();
5794 curcolum[2]+=TCollection_AsciiString(i+1);
5796 for(Standard_Integer j =0;j<=2;j++){
5797 curcolum[j].Center(20,' ');
5798 di<<"|"<<curcolum[j].ToCString();
5802 di<<BlankLine.ToCString()<<"\n";
5804 // les objets de type shape
5805 curcolum[1].Clear();
5806 curcolum[1]+="Shape";
5807 curcolum[1].Center(20,' ');
5810 curcolum[0].Clear();
5811 curcolum[0] += names[7+i];
5812 curcolum[2].Clear();
5813 curcolum[2]+=TCollection_AsciiString(i);
5815 for(Standard_Integer j =0;j<=2;j++){
5816 curcolum[j].Center(20,' ');
5817 di<<"|"<<curcolum[j].ToCString();
5821 di<<BlankLine.ToCString()<<"\n";
5822 // les IO de type objet...
5823 curcolum[1].Clear();
5824 curcolum[1]+="Object";
5825 curcolum[1].Center(20,' ');
5827 curcolum[0].Clear();
5828 curcolum[0] += names[10+i];
5829 curcolum[2].Clear();
5830 curcolum[2]+=TCollection_AsciiString(i);
5832 for(Standard_Integer j =0;j<=2;j++){
5833 curcolum[j].Center(20,' ');
5834 di<<"|"<<curcolum[j].ToCString();
5838 di<<BlankLine.ToCString()<<"\n";
5839 // les contraintes et dimensions.
5840 // pour l'instant on separe juste contraintes et dimensions...
5841 // plus tard, on detaillera toutes les sortes...
5842 curcolum[1].Clear();
5843 curcolum[1]+="Relation";
5844 curcolum[1].Center(20,' ');
5846 curcolum[0].Clear();
5847 curcolum[0] += names[12+i];
5848 curcolum[2].Clear();
5849 curcolum[2]+=TCollection_AsciiString(i);
5851 for(Standard_Integer j =0;j<=2;j++){
5852 curcolum[j].Center(20,' ');
5853 di<<"|"<<curcolum[j].ToCString();
5857 di<<BlankLine.ToCString()<<"\n";
5864 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5866 if(argc!=2) return 1;
5868 AIS_KindOfInteractive TheType;
5869 Standard_Integer TheSign(-1);
5870 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5873 AIS_ListOfInteractive LIO;
5875 // en attendant l'amelioration ais pour les dimensions...
5877 Standard_Integer dimension_status(-1);
5878 if(TheType==AIS_KOI_Relation){
5879 dimension_status = TheSign ==1 ? 1 : 0;
5883 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5884 Handle(AIS_InteractiveObject) curio;
5885 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5888 if(dimension_status == -1)
5889 TheAISContext()->Erase(curio,Standard_False);
5891 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5892 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5893 (dimension_status==1 && KOD != AIS_KOD_NONE))
5894 TheAISContext()->Erase(curio,Standard_False);
5897 TheAISContext()->UpdateCurrentViewer();
5900 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5902 if(argc!=2) return 1;
5904 AIS_KindOfInteractive TheType;
5905 Standard_Integer TheSign(-1);
5906 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5908 // en attendant l'amelioration ais pour les dimensions...
5910 Standard_Integer dimension_status(-1);
5911 if(TheType==AIS_KOI_Relation){
5912 dimension_status = TheSign ==1 ? 1 : 0;
5916 AIS_ListOfInteractive LIO;
5917 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5918 Handle(AIS_InteractiveObject) curio;
5919 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5921 if(dimension_status == -1)
5922 TheAISContext()->Display(curio,Standard_False);
5924 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5925 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5926 (dimension_status==1 && KOD != AIS_KOD_NONE))
5927 TheAISContext()->Display(curio,Standard_False);
5932 TheAISContext()->UpdateCurrentViewer();
5936 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5939 BRep_Builder builder;
5941 BRepTools::Read(shape, s, builder);
5942 DBRep::Set(a[1], shape);
5943 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5944 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5945 Ctx->Display (ais, Standard_True);
5949 //===============================================================================================
5952 //===============================================================================================
5953 static int VBsdf (Draw_Interpretor& theDI,
5954 Standard_Integer theArgsNb,
5955 const char** theArgVec)
5957 Handle(V3d_View) aView = ViewerTest::CurrentView();
5958 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5960 || aViewer.IsNull())
5962 std::cerr << "No active viewer!\n";
5966 ViewerTest_CmdParser aCmd;
5968 aCmd.SetDescription ("Adjusts parameters of material BSDF:");
5970 aCmd.AddOption ("print|echo|p", "Prints BSDF");
5972 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
5974 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
5975 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
5976 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
5977 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
5978 aCmd.AddOption ("le", "Radiance emitted by surface");
5980 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5981 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5983 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
5984 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
5986 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
5987 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
5989 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
5991 aCmd.Parse (theArgsNb, theArgVec);
5993 if (aCmd.HasOption ("help"))
5995 theDI.PrintHelp (theArgVec[0]);
5999 // check viewer update mode
6000 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
6001 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6003 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
6010 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
6011 Handle(AIS_InteractiveObject) anIObj;
6012 if (!GetMapOfAIS().Find2 (aName, anIObj))
6014 std::cerr << "Use 'vdisplay' before\n";
6018 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
6019 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
6021 if (aCmd.HasOption ("print"))
6024 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
6025 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
6026 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
6027 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
6028 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
6030 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6032 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
6033 : aBSDF.FresnelBase.Serialize();
6035 theDI << (aLayerID < 1 ? "Coat Fresnel: "
6036 : "Base Fresnel: ");
6038 if (aFresnel.x() >= 0.f)
6040 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
6041 << "G = " << aFresnel.g() << ", "
6042 << "B = " << aFresnel.b() << "\n";
6044 else if (aFresnel.x() >= -1.5f)
6046 theDI << "Constant " << aFresnel.z() << "\n";
6048 else if (aFresnel.x() >= -2.5f)
6050 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
6051 << "K = " << aFresnel.z() << "\n";
6055 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
6059 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
6060 << "Base roughness: " << aBSDF.Ks.w() << "\n"
6061 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
6062 << "Absorption color: " << aBSDF.Absorption.r() << ", "
6063 << aBSDF.Absorption.g() << ", "
6064 << aBSDF.Absorption.b() << "\n";
6069 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
6071 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
6074 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
6076 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
6079 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
6081 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
6084 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
6086 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
6088 aBSDF.Absorption.r() = aRGB.r();
6089 aBSDF.Absorption.g() = aRGB.g();
6090 aBSDF.Absorption.b() = aRGB.b();
6093 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
6097 if (aCmd.HasOption ("kc", 3))
6099 aKc = aCmd.ArgVec3f ("kc");
6103 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
6106 aBSDF.Kc.r() = aKc.r();
6107 aBSDF.Kc.g() = aKc.g();
6108 aBSDF.Kc.b() = aKc.b();
6111 if (aCmd.HasOption ("kd", 3))
6113 aBSDF.Kd = aCmd.ArgVec3f ("kd");
6115 else if (aCmd.HasOption ("kd", 1, Standard_True))
6117 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
6120 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
6124 if (aCmd.HasOption ("ks", 3))
6126 aKs = aCmd.ArgVec3f ("ks");
6130 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
6133 aBSDF.Ks.r() = aKs.r();
6134 aBSDF.Ks.g() = aKs.g();
6135 aBSDF.Ks.b() = aKs.b();
6138 if (aCmd.HasOption ("kt", 3))
6140 aBSDF.Kt = aCmd.ArgVec3f ("kt");
6142 else if (aCmd.HasOption ("kt", 1, Standard_True))
6144 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
6147 if (aCmd.HasOption ("le", 3))
6149 aBSDF.Le = aCmd.ArgVec3f ("le");
6151 else if (aCmd.HasOption ("le", 1, Standard_True))
6153 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
6156 const std::string aFresnelErrorMessage =
6157 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
6159 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6161 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
6164 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
6166 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6167 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6169 if (aFresnelType == "schlick")
6171 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
6172 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
6173 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
6175 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
6176 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
6177 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
6179 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
6183 theDI << aFresnelErrorMessage.c_str() << "\n";
6186 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
6188 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6189 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6191 if (aFresnelType == "conductor")
6193 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6194 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
6196 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
6200 theDI << aFresnelErrorMessage.c_str() << "\n";
6203 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
6205 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6206 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6208 if (aFresnelType == "constant")
6210 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6212 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
6214 else if (aFresnelType == "dielectric")
6216 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6218 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
6222 theDI << aFresnelErrorMessage.c_str() << "\n";
6227 if (aCmd.HasOption ("normalize"))
6232 aMaterial.SetBSDF (aBSDF);
6233 anIObj->SetMaterial (aMaterial);
6238 //==============================================================================
6239 //function : VLoadSelection
6240 //purpose : Adds given objects to map of AIS and loads selection primitives for them
6241 //==============================================================================
6242 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
6243 Standard_Integer theArgNb,
6244 const char** theArgVec)
6248 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
6252 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
6255 ViewerTest::ViewerInit();
6256 aCtx = ViewerTest::GetAISContext();
6259 // Parse input arguments
6260 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6262 const TCollection_AsciiString aName = theArgVec[anArgIter];
6263 Handle(AIS_InteractiveObject) aShape;
6264 if (!GetMapOfAIS().Find2 (aName, aShape))
6266 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
6267 if (!aDrawShape.IsNull())
6269 aShape = new AIS_Shape (aDrawShape);
6270 GetMapOfAIS().Bind (aShape, aName);
6273 if (aShape.IsNull())
6275 std::cout << "Syntax error: presentation '" << aName << "' not found\n";
6279 aCtx->Load (aShape, -1);
6280 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
6285 //==============================================================================
6286 //function : ViewerTest::Commands
6287 //purpose : Add all the viewer command in the Draw_Interpretor
6288 //==============================================================================
6290 void ViewerTest::Commands(Draw_Interpretor& theCommands)
6292 ViewerTest::ViewerCommands(theCommands);
6293 ViewerTest::RelationCommands(theCommands);
6294 ViewerTest::ObjectCommands(theCommands);
6295 ViewerTest::FilletCommands(theCommands);
6296 ViewerTest::OpenGlCommands(theCommands);
6298 const char *group = "AIS_Display";
6301 theCommands.Add("visos",
6302 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
6303 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
6304 __FILE__, visos, group);
6306 theCommands.Add("vdisplay",
6307 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
6308 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
6309 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
6310 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
6311 "\n\t\t: |topRight|bottomLeft|bottomRight}"
6312 "\n\t\t: [offsetX offsetY]]]"
6313 "\n\t\t: [-dispMode mode] [-highMode mode]"
6314 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
6315 "\n\t\t: [-redisplay] [-erased]"
6316 "\n\t\t: name1 [name2] ... [name n]"
6317 "\n\t\t: Displays named objects."
6318 "\n\t\t: Option -local enables displaying of objects in local"
6319 "\n\t\t: selection context. Local selection context will be opened"
6320 "\n\t\t: if there is not any."
6321 "\n\t\t: -noupdate Suppresses viewer redraw call."
6322 "\n\t\t: -mutable Enables optimizations for mutable objects."
6323 "\n\t\t: -neutral Draws objects in main viewer."
6324 "\n\t\t: -erased Loads the object into context, but does not display it."
6325 "\n\t\t: -layer Sets z-layer for objects."
6326 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
6327 "\n\t\t: options can be used for the default z-layers."
6328 "\n\t\t: -top Draws object on top of main presentations"
6329 "\n\t\t: but below topmost."
6330 "\n\t\t: -topmost Draws in overlay for 3D presentations."
6331 "\n\t\t: with independent Depth."
6332 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
6333 "\n\t\t: (On-Screen-Display)"
6334 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
6335 "\n\t\t: (On-Screen-Display)"
6336 "\n\t\t: -selectable|-noselect Controls selection of objects."
6337 "\n\t\t: -trsfPers Sets a transform persistence flags."
6338 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
6339 "\n\t\t: -2d Displays object in screen coordinates."
6340 "\n\t\t: (DY looks up)"
6341 "\n\t\t: -dispmode Sets display mode for objects."
6342 "\n\t\t: -highmode Sets hilight mode for objects."
6343 "\n\t\t: -redisplay Recomputes presentation of objects.",
6344 __FILE__, VDisplay2, group);
6346 theCommands.Add ("vnbdisplayed",
6348 "\n\t\t: Returns number of displayed objects",
6349 __FILE__, VNbDisplayed, group);
6351 theCommands.Add ("vupdate",
6352 "vupdate name1 [name2] ... [name n]"
6353 "\n\t\t: Updates named objects in interactive context",
6354 __FILE__, VUpdate, group);
6356 theCommands.Add("verase",
6357 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
6358 "\n\t\t: Erases selected or named objects."
6359 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
6360 "\n\t\t: Option -local enables erasing of selected or named objects without"
6361 "\n\t\t: closing local selection context.",
6362 __FILE__, VErase, group);
6364 theCommands.Add("vremove",
6365 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
6366 "or vremove [-context] -all to remove all objects"
6367 "\n\t\t: Removes selected or named objects."
6368 "\n\t\t If -context is in arguments, the objects are not deleted"
6369 "\n\t\t from the map of objects and names."
6370 "\n\t\t: Option -local enables removing of selected or named objects without"
6371 "\n\t\t: closing local selection context. Empty local selection context will be"
6373 "\n\t\t: Option -noupdate suppresses viewer redraw call."
6374 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
6375 __FILE__, VRemove, group);
6377 theCommands.Add("vdonly",
6378 "vdonly [-noupdate|-update] [name1] ... [name n]"
6379 "\n\t\t: Displays only selected or named objects",
6380 __FILE__,VDonly2,group);
6382 theCommands.Add("vdisplayall",
6384 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
6385 __FILE__, VDisplayAll, group);
6387 theCommands.Add("veraseall",
6389 "\n\t\t: Erases all objects displayed in the viewer.",
6390 __FILE__, VErase, group);
6392 theCommands.Add("verasetype",
6394 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
6395 __FILE__, VEraseType, group);
6396 theCommands.Add("vbounding",
6397 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
6398 "\n\t\t: [-print] [-hide]"
6399 "\n\t\t: Temporarily display bounding box of specified Interactive"
6400 "\n\t\t: Objects, or print it to console if -print is specified."
6401 "\n\t\t: Already displayed box might be hidden by -hide option.",
6402 __FILE__,VBounding,group);
6404 theCommands.Add("vdisplaytype",
6405 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
6406 __FILE__,VDisplayType,group);
6408 theCommands.Add("vsetdispmode",
6409 "vsetdispmode [name] mode(1,2,..)"
6410 "\n\t\t: Sets display mode for all, selected or named objects.",
6411 __FILE__,VDispMode,group);
6413 theCommands.Add("vunsetdispmode",
6414 "vunsetdispmode [name]"
6415 "\n\t\t: Unsets custom display mode for selected or named objects.",
6416 __FILE__,VDispMode,group);
6418 theCommands.Add("vdir",
6419 "Lists all objects displayed in 3D viewer",
6420 __FILE__,VDir,group);
6422 #ifdef HAVE_FREEIMAGE
6423 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
6425 #define DUMP_FORMATS "{ppm}"
6427 theCommands.Add("vdump",
6428 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
6429 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
6430 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
6431 "\n\t\t: [-tileSize Size=0]"
6432 "\n\t\t: Dumps content of the active view into image file",
6433 __FILE__,VDump,group);
6435 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
6436 __FILE__,VSubInt,group);
6438 theCommands.Add("vaspects",
6439 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
6440 "\n\t\t: [-setVisibility 0|1]"
6441 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
6442 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
6443 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
6444 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
6445 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
6446 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
6447 "\n\t\t: [-unsetMarkerType]"
6448 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
6449 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
6450 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
6451 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
6452 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
6453 "\n\t\t: [-isoontriangulation 0|1]"
6454 "\n\t\t: [-setMaxParamValue {value}]"
6455 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
6456 "\n\t\t: [-setShadingModel {color|flat|gouraud|phong}]"
6457 "\n\t\t: [-unsetShadingModel]"
6458 "\n\t\t: [-setInterior {solid|hatch|hidenline|point}]"
6459 "\n\t\t: [-unsetInterior] [-setHatch HatchStyle]"
6460 "\n\t\t: [-setFaceBoundaryDraw {0|1}] [-setMostContinuity {c0|c1|c2|c3|cn}"
6461 "\n\t\t: [-setFaceBoundaryWidth LineWidth] [-setFaceBoundaryColor R G B] [-setFaceBoundaryType LineType]"
6462 "\n\t\t: [-setDrawEdges {0|1}] [-setEdgeType LineType] [-setEdgeColor R G B] [-setQuadEdges {0|1}]"
6463 "\n\t\t: [-setDrawSilhouette {0|1}]"
6464 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
6465 "\n\t\t: Manage presentation properties of all, selected or named objects."
6466 "\n\t\t: When -subshapes is specified than following properties will be"
6467 "\n\t\t: assigned to specified sub-shapes."
6468 "\n\t\t: When -defaults is specified than presentation properties will be"
6469 "\n\t\t: assigned to all objects that have not their own specified properties"
6470 "\n\t\t: and to all objects to be displayed in the future."
6471 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
6472 __FILE__,VAspects,group);
6474 theCommands.Add("vsetcolor",
6475 "vsetcolor [-noupdate|-update] [name] ColorName"
6476 "\n\t\t: Sets color for all, selected or named objects."
6477 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
6478 __FILE__,VAspects,group);
6480 theCommands.Add("vunsetcolor",
6481 "vunsetcolor [-noupdate|-update] [name]"
6482 "\n\t\t: Resets color for all, selected or named objects."
6483 "\n\t\t: Alias for vaspects -unsetcolor [name].",
6484 __FILE__,VAspects,group);
6486 theCommands.Add("vsettransparency",
6487 "vsettransparency [-noupdate|-update] [name] Coefficient"
6488 "\n\t\t: Sets transparency for all, selected or named objects."
6489 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
6490 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
6491 __FILE__,VAspects,group);
6493 theCommands.Add("vunsettransparency",
6494 "vunsettransparency [-noupdate|-update] [name]"
6495 "\n\t\t: Resets transparency for all, selected or named objects."
6496 "\n\t\t: Alias for vaspects -unsettransp [name].",
6497 __FILE__,VAspects,group);
6499 theCommands.Add("vsetmaterial",
6500 "vsetmaterial [-noupdate|-update] [name] MaterialName"
6501 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
6502 __FILE__,VAspects,group);
6504 theCommands.Add("vunsetmaterial",
6505 "vunsetmaterial [-noupdate|-update] [name]"
6506 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
6507 __FILE__,VAspects,group);
6509 theCommands.Add("vsetwidth",
6510 "vsetwidth [-noupdate|-update] [name] width(0->10)"
6511 "\n\t\t: Alias for vaspects -setwidth [name] width.",
6512 __FILE__,VAspects,group);
6514 theCommands.Add("vunsetwidth",
6515 "vunsetwidth [-noupdate|-update] [name]"
6516 "\n\t\t: Alias for vaspects -unsetwidth [name].",
6517 __FILE__,VAspects,group);
6519 theCommands.Add("vsetinteriorstyle",
6520 "vsetinteriorstyle [-noupdate|-update] [name] Style"
6521 "\n\t\t: Alias for vaspects -setInterior [name] Style.",
6522 __FILE__,VAspects,group);
6524 theCommands.Add ("vsetedgetype",
6525 "vsetedgetype [name] [-type {solid, dash, dot}] [-color R G B] [-width value]"
6526 "\n\t\t: Alias for vaspects [name] -setEdgeType Type.",
6527 __FILE__, VAspects, group);
6529 theCommands.Add ("vunsetedgetype",
6530 "vunsetedgetype [name]"
6531 "\n\t\t: Alias for vaspects [name] -unsetEdgeType.",
6532 __FILE__, VAspects, group);
6534 theCommands.Add ("vshowfaceboundary",
6535 "vshowfaceboundary [name]"
6536 "\n\t\t: Alias for vaspects [name] -setFaceBoundaryDraw on",
6537 __FILE__, VAspects, group);
6539 theCommands.Add("vsensdis",
6540 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
6541 "\n\t\t: Standard entity types are those defined in Select3D package:"
6542 "\n\t\t: - sensitive box"
6543 "\n\t\t: - sensitive face"
6544 "\n\t\t: - sensitive curve"
6545 "\n\t\t: - sensitive segment"
6546 "\n\t\t: - sensitive circle"
6547 "\n\t\t: - sensitive point"
6548 "\n\t\t: - sensitive triangulation"
6549 "\n\t\t: - sensitive triangle"
6550 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
6551 __FILE__,VDispSensi,group);
6553 theCommands.Add("vsensera",
6554 "vsensera : erase active entities",
6555 __FILE__,VClearSensi,group);
6557 theCommands.Add("vsetshading",
6558 "vsetshading : vsetshading name Quality(default=0.0008) "
6559 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
6560 __FILE__,VShading,group);
6562 theCommands.Add("vunsetshading",
6563 "vunsetshading :vunsetshading name "
6564 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
6565 __FILE__,VShading,group);
6567 theCommands.Add ("vtexture",
6568 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
6569 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
6570 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
6571 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
6572 "\n\t\t: [-modulate {on|off}]"
6573 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
6574 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
6575 "\n\t\t: [-default]"
6576 "\n\t\t: The texture can be specified by filepath"
6577 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
6578 "\n\t\t: The options are:"
6579 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
6580 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
6581 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
6582 "\n\t\t: -modulate Enable or disable texture color modulation"
6583 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
6584 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
6585 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
6586 "\n\t\t: -setFilter Setup texture filter"
6587 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
6588 "\n\t\t: -default Sets texture mapping default parameters",
6589 __FILE__, VTexture, group);
6591 theCommands.Add("vtexscale",
6592 "vtexscale name ScaleU ScaleV"
6593 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
6594 __FILE__,VTexture,group);
6596 theCommands.Add("vtexorigin",
6597 "vtexorigin name OriginU OriginV"
6598 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
6599 __FILE__,VTexture,group);
6601 theCommands.Add("vtexrepeat",
6602 "vtexrepeat name RepeatU RepeatV"
6603 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
6606 theCommands.Add("vtexdefault",
6608 "\n\t\t: Alias for vtexture name -default.",
6611 theCommands.Add("vstate",
6612 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6613 "\n\t\t: Reports show/hidden state for selected or named objects"
6614 "\n\t\t: -entities - print low-level information about detected entities"
6615 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6616 __FILE__,VState,group);
6618 theCommands.Add("vpickshapes",
6619 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6620 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6621 "\n\t\t: Hold also Shift for multiple selection.",
6622 __FILE__, VPickShape, group);
6624 theCommands.Add("vtypes",
6625 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6628 theCommands.Add("vr",
6630 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6631 __FILE__,vr, group);
6633 theCommands.Add("vselfilter",
6634 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6635 "\nSets selection shape type filter in context or remove all filters."
6636 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6637 "\n : Option -clear remove all filters in context",
6638 __FILE__,VSelFilter,group);
6640 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6641 __FILE__, VPickSelected, group);
6643 theCommands.Add ("vloadselection",
6644 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6645 "\n\t\t: primitives for the shapes with names given without displaying them.",
6646 __FILE__, VLoadSelection, group);
6648 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6649 "\nAdjusts parameters of material BSDF:"
6650 "\n -help : Shows this message"
6651 "\n -print : Print BSDF"
6652 "\n -kd : Weight of the Lambertian BRDF"
6653 "\n -kr : Weight of the reflection BRDF"
6654 "\n -kt : Weight of the transmission BTDF"
6655 "\n -ks : Weight of the glossy Blinn BRDF"
6656 "\n -le : Self-emitted radiance"
6657 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6658 "\n Schlick x y z, Dielectric x, Conductor x y"
6659 "\n -roughness : Roughness of material (Blinn's exponent)"
6660 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6661 "\n -absorpcolor : Absorption color (only for transparent material)"
6662 "\n -normalize : Normalize BSDF coefficients",
6663 __FILE__, VBsdf, group);
6667 //=====================================================================
6668 //========================= for testing Draft and Rib =================
6669 //=====================================================================
6670 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6671 #include <DBRep.hxx>
6672 #include <TopoDS_Face.hxx>
6673 #include <gp_Pln.hxx>
6674 #include <AIS_KindOfSurface.hxx>
6675 #include <BRepOffsetAPI_DraftAngle.hxx>
6676 #include <Precision.hxx>
6677 #include <BRepAlgo.hxx>
6678 #include <OSD_Environment.hxx>
6679 #include <DrawTrSurf.hxx>
6680 //#include <DbgTools.hxx>
6681 //#include <FeatAlgo_MakeLinearForm.hxx>
6686 //=======================================================================
6687 //function : IsValid
6689 //=======================================================================
6690 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6691 const TopoDS_Shape& theResult,
6692 const Standard_Boolean closedSolid,
6693 const Standard_Boolean GeomCtrl)
6695 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6696 TCollection_AsciiString checkValid = check.Value();
6697 Standard_Boolean ToCheck = Standard_True;
6698 if (!checkValid.IsEmpty()) {
6700 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6702 if ( checkValid=="true" || checkValid=="TRUE" ) {
6703 ToCheck= Standard_False;
6707 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6710 Standard_Boolean IsValid = Standard_True;
6712 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6717 //===============================================================================
6718 // TDraft : test draft, uses AIS Viewer
6719 // Solid Face Plane Angle Reverse
6720 //===============================================================================
6721 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6723 if (argc < 5) return 1;
6724 // argv[1] - TopoDS_Shape Solid
6725 // argv[2] - TopoDS_Shape Face
6726 // argv[3] - TopoDS_Shape Plane
6727 // argv[4] - Standard_Real Angle
6728 // argv[5] - Standard_Integer Reverse
6730 // Sprintf(prefix, argv[1]);
6731 Standard_Real anAngle = 0;
6732 Standard_Boolean Rev = Standard_False;
6733 Standard_Integer rev = 0;
6734 TopoDS_Shape Solid = DBRep::Get (argv[1]);
6735 TopoDS_Shape face = DBRep::Get (argv[2]);
6736 TopoDS_Face Face = TopoDS::Face(face);
6737 TopoDS_Shape Plane = DBRep::Get (argv[3]);
6738 if (Plane.IsNull ()) {
6739 di << "TEST : Plane is NULL\n";
6742 anAngle = Draw::Atof(argv[4]);
6743 anAngle = 2*M_PI * anAngle / 360.0;
6745 Handle( Geom_Surface )aSurf;
6746 AIS_KindOfSurface aSurfType;
6747 Standard_Real Offset;
6749 if(argc > 4) { // == 5
6750 rev = Draw::Atoi(argv[5]);
6751 Rev = (rev)? Standard_True : Standard_False;
6754 TopoDS_Face face2 = TopoDS::Face(Plane);
6755 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6757 di << "TEST : Can't find plane\n";
6761 aDir = aPln.Axis().Direction();
6764 if (Plane.Orientation() == TopAbs_REVERSED)
6766 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6768 BRepOffsetAPI_DraftAngle Draft (Solid);
6770 if(Abs(anAngle)< Precision::Angular()) {
6771 di << "TEST : NULL angle\n";
6774 if(Rev) anAngle = - anAngle;
6775 Draft.Add (Face, aDir, anAngle, aPln);
6777 if (!Draft.IsDone()) {
6778 di << "TEST : Draft Not DONE \n";
6781 TopTools_ListOfShape Larg;
6783 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6784 di << "TEST : DesignAlgo returns Not valid\n";
6788 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6789 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6791 if ( !ais.IsNull() ) {
6792 ais->SetColor(DEFAULT_COLOR);
6793 ais->SetMaterial(DEFAULT_MATERIAL);
6794 // Display the AIS_Shape without redraw
6795 Ctx->Display(ais, Standard_False);
6797 const char *Name = "draft1";
6798 Handle(AIS_InteractiveObject) an_object;
6799 if (GetMapOfAIS().Find2(Name, an_object))
6801 if (!an_object.IsNull())
6803 Ctx->Remove (an_object, Standard_True);
6805 GetMapOfAIS().UnBind2 (Name);
6807 GetMapOfAIS().Bind(ais, Name);
6808 // DBRep::Set("draft", ais->Shape());
6810 Ctx->Display(ais, Standard_True);
6814 //==============================================================================
6815 //function : splitParameter
6816 //purpose : Split parameter string to parameter name and parameter value
6817 //==============================================================================
6818 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6819 TCollection_AsciiString& theName,
6820 TCollection_AsciiString& theValue)
6822 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6824 if (aParamNameEnd == 0)
6826 return Standard_False;
6829 TCollection_AsciiString aString (theString);
6830 if (aParamNameEnd != 0)
6832 theValue = aString.Split (aParamNameEnd);
6833 aString.Split (aString.Length() - 1);
6837 return Standard_True;
6840 //============================================================================
6842 //============================================================================
6843 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6846 DrawTrSurf::BasicCommands(theCommands);
6847 const char* group = "Check Features Operations commands";
6849 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6851 &TDraft,group); //Draft_Modification
6854 //==============================================================================
6855 // ViewerTest::Factory
6856 //==============================================================================
6857 void ViewerTest::Factory(Draw_Interpretor& theDI)
6859 // definition of Viewer Command
6860 ViewerTest::Commands(theDI);
6863 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6867 // Declare entry point PLUGINFACTORY