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>
21 #include <ViewerTest_AutoUpdater.hxx>
24 #include <TopLoc_Location.hxx>
25 #include <TopTools_HArray1OfShape.hxx>
26 #include <TColStd_HArray1OfTransient.hxx>
27 #include <TColStd_SequenceOfAsciiString.hxx>
28 #include <TColStd_HSequenceOfAsciiString.hxx>
29 #include <TColStd_MapOfTransient.hxx>
30 #include <OSD_Timer.hxx>
31 #include <Geom_Axis2Placement.hxx>
32 #include <Geom_Axis1Placement.hxx>
33 #include <gp_Trsf.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <BRepAdaptor_Curve.hxx>
36 #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_TypeFilter.hxx>
42 #include <AIS_SignatureFilter.hxx>
43 #include <AIS_ListOfInteractive.hxx>
44 #include <AIS_ListIteratorOfListOfInteractive.hxx>
45 #include <Aspect_InteriorStyle.hxx>
46 #include <Aspect_Window.hxx>
47 #include <Aspect_XRSession.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 <Message.hxx>
56 #include <OSD_File.hxx>
57 #include <Prs3d_Drawer.hxx>
58 #include <Prs3d_ShadingAspect.hxx>
59 #include <Prs3d_IsoAspect.hxx>
60 #include <Prs3d_PointAspect.hxx>
62 #include <PrsDim_Relation.hxx>
63 #include <Select3D_SensitiveWire.hxx>
64 #include <Select3D_SensitivePrimitiveArray.hxx>
65 #include <Select3D_SensitiveTriangulation.hxx>
66 #include <SelectMgr_EntityOwner.hxx>
67 #include <StdSelect_BRepOwner.hxx>
68 #include <StdSelect_ViewerSelector3d.hxx>
69 #include <TopTools_MapOfShape.hxx>
70 #include <V3d_Viewer.hxx>
74 #include <Draw_Interpretor.hxx>
75 #include <TCollection_AsciiString.hxx>
76 #include <Draw_PluginMacro.hxx>
78 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
80 #include <Quantity_Color.hxx>
81 #include <Quantity_NameOfColor.hxx>
83 #include <Graphic3d_NameOfMaterial.hxx>
85 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
86 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
87 #define DEFAULT_MATERIAL Graphic3d_NameOfMaterial_Brass
89 //=======================================================================
90 // function : GetColorFromName
91 // purpose : get the Quantity_NameOfColor from a string
92 //=======================================================================
94 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
96 Quantity_NameOfColor aColor = DEFAULT_COLOR;
97 Quantity_Color::ColorFromName (theName, aColor);
101 //=======================================================================
102 // function : ParseColor
104 //=======================================================================
105 Standard_Integer ViewerTest::ParseColor (const Standard_Integer theArgNb,
106 const char* const* const theArgVec,
107 Quantity_ColorRGBA& theColor)
109 return Draw::ParseColor (theArgNb, theArgVec, theColor);
112 //=======================================================================
113 // function : ParseColor
115 //=======================================================================
116 Standard_Integer ViewerTest::ParseColor (const Standard_Integer theArgNb,
117 const char* const* const theArgVec,
118 Quantity_Color& theColor)
120 return Draw::ParseColor (theArgNb, theArgVec, theColor);
123 //=======================================================================
124 //function : ParseOnOff
126 //=======================================================================
127 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
128 Standard_Boolean& theIsOn)
130 return Draw::ParseOnOff (theArg, theIsOn);
133 //=======================================================================
134 //function : GetSelectedShapes
136 //=======================================================================
137 void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
139 for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
141 TopoDS_Shape aShape = GetAISContext()->SelectedShape();
142 if (!aShape.IsNull())
144 theSelectedShapes.Append (aShape);
149 //=======================================================================
150 //function : ParseLineType
152 //=======================================================================
153 Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
154 Aspect_TypeOfLine& theType,
155 uint16_t& thePattern)
157 TCollection_AsciiString aTypeStr (theArg);
158 aTypeStr.LowerCase();
159 if (aTypeStr == "empty"
162 theType = Aspect_TOL_EMPTY;
163 thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType);
165 else if (aTypeStr == "solid"
168 theType = Aspect_TOL_SOLID;
169 thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType);
171 else if (aTypeStr == "dot"
174 theType = Aspect_TOL_DOT;
175 thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType);
177 else if (aTypeStr == "dash"
180 theType = Aspect_TOL_DASH;
181 thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType);
183 else if (aTypeStr == "dotdash"
186 theType = Aspect_TOL_DOTDASH;
187 thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType);
191 if (aTypeStr.StartsWith ("0x"))
193 aTypeStr = aTypeStr.SubString (3, aTypeStr.Length());
196 if (aTypeStr.Length() != 4
197 || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (1)))
198 || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (2)))
199 || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (3)))
200 || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (4))))
202 return Standard_False;
205 std::stringstream aStream;
206 aStream << std::setbase (16) << aTypeStr.ToCString();
209 return Standard_False;
212 Standard_Integer aNumber = -1;
216 return Standard_False;
219 thePattern = (uint16_t )aNumber;
220 theType = Graphic3d_Aspects::DefaultLineTypeForPattern (thePattern);
222 return Standard_True;
225 //=======================================================================
226 //function : ParseMarkerType
228 //=======================================================================
229 Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
230 Aspect_TypeOfMarker& theType,
231 Handle(Image_PixMap)& theImage)
234 TCollection_AsciiString aTypeStr (theArg);
235 aTypeStr.LowerCase();
236 if (aTypeStr == "empty")
238 theType = Aspect_TOM_EMPTY;
240 else if (aTypeStr == "point"
244 theType = Aspect_TOM_POINT;
246 else if (aTypeStr == "plus"
249 theType = Aspect_TOM_PLUS;
251 else if (aTypeStr == "star"
254 theType = Aspect_TOM_STAR;
256 else if (aTypeStr == "cross"
259 theType = Aspect_TOM_X;
261 else if (aTypeStr == "circle"
264 theType = Aspect_TOM_O;
266 else if (aTypeStr == "pointincircle")
268 theType = Aspect_TOM_O_POINT;
270 else if (aTypeStr == "plusincircle")
272 theType = Aspect_TOM_O_PLUS;
274 else if (aTypeStr == "starincircle")
276 theType = Aspect_TOM_O_STAR;
278 else if (aTypeStr == "crossincircle"
279 || aTypeStr == "xcircle")
281 theType = Aspect_TOM_O_X;
283 else if (aTypeStr == "ring1")
285 theType = Aspect_TOM_RING1;
287 else if (aTypeStr == "ring2")
289 theType = Aspect_TOM_RING2;
291 else if (aTypeStr == "ring"
292 || aTypeStr == "ring3")
294 theType = Aspect_TOM_RING3;
296 else if (aTypeStr == "ball")
298 theType = Aspect_TOM_BALL;
300 else if (aTypeStr.IsIntegerValue())
302 const int aTypeInt = aTypeStr.IntegerValue();
303 if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED)
305 return Standard_False;
307 theType = (Aspect_TypeOfMarker )aTypeInt;
311 theType = Aspect_TOM_USERDEFINED;
312 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
313 if (!anImage->Load (theArg))
315 return Standard_False;
317 if (anImage->Format() == Image_Format_Gray)
319 anImage->SetFormat (Image_Format_Alpha);
321 else if (anImage->Format() == Image_Format_GrayF)
323 anImage->SetFormat (Image_Format_AlphaF);
327 return Standard_True;
330 //=======================================================================
331 //function : ParseShadingModel
333 //=======================================================================
334 Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg,
335 Graphic3d_TypeOfShadingModel& theModel)
337 TCollection_AsciiString aTypeStr (theArg);
338 aTypeStr.LowerCase();
339 if (aTypeStr == "unlit"
340 || aTypeStr == "color"
341 || aTypeStr == "none")
343 theModel = Graphic3d_TypeOfShadingModel_Unlit;
345 else if (aTypeStr == "flat"
346 || aTypeStr == "facet")
348 theModel = Graphic3d_TypeOfShadingModel_PhongFacet;
350 else if (aTypeStr == "gouraud"
351 || aTypeStr == "vertex"
352 || aTypeStr == "vert")
354 theModel = Graphic3d_TypeOfShadingModel_Gouraud;
356 else if (aTypeStr == "phong"
357 || aTypeStr == "fragment"
358 || aTypeStr == "frag"
359 || aTypeStr == "pixel")
361 theModel = Graphic3d_TypeOfShadingModel_Phong;
363 else if (aTypeStr == "pbr")
365 theModel = Graphic3d_TypeOfShadingModel_Pbr;
367 else if (aTypeStr == "pbr_facet")
369 theModel = Graphic3d_TypeOfShadingModel_PbrFacet;
371 else if (aTypeStr == "default"
372 || aTypeStr == "def")
374 theModel = Graphic3d_TypeOfShadingModel_DEFAULT;
376 else if (aTypeStr.IsIntegerValue())
378 const int aTypeInt = aTypeStr.IntegerValue();
379 if (aTypeInt <= Graphic3d_TypeOfShadingModel_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
381 return Standard_False;
383 theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
387 return Standard_False;
389 return Standard_True;
392 //=======================================================================
393 //function : parseZLayer
395 //=======================================================================
396 Standard_Boolean ViewerTest::parseZLayer (Standard_CString theArg,
397 Standard_Boolean theToAllowInteger,
398 Graphic3d_ZLayerId& theLayer)
400 TCollection_AsciiString aName (theArg);
402 if (aName == "default"
405 theLayer = Graphic3d_ZLayerId_Default;
407 else if (aName == "top")
409 theLayer = Graphic3d_ZLayerId_Top;
411 else if (aName == "topmost")
413 theLayer = Graphic3d_ZLayerId_Topmost;
415 else if (aName == "overlay"
416 || aName == "toposd")
418 theLayer = Graphic3d_ZLayerId_TopOSD;
420 else if (aName == "underlay"
421 || aName == "botosd")
423 theLayer = Graphic3d_ZLayerId_BotOSD;
425 else if (aName == "undefined")
427 theLayer = Graphic3d_ZLayerId_UNKNOWN;
429 else if (!GetAISContext().IsNull())
431 const Handle(V3d_Viewer)& aViewer = ViewerTest::GetAISContext()->CurrentViewer();
432 TColStd_SequenceOfInteger aLayers;
433 aViewer->GetAllZLayers (aLayers);
434 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
436 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
437 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aName, Standard_False))
439 theLayer = aLayeriter.Value();
444 if (!theToAllowInteger
445 || !aName.IsIntegerValue())
449 Graphic3d_ZLayerId aLayer = aName.IntegerValue();
450 if (aLayer == Graphic3d_ZLayerId_UNKNOWN
451 || std::find (aLayers.begin(), aLayers.end(), aLayer) != aLayers.end())
461 //=======================================================================
462 //function : GetTypeNames
464 //=======================================================================
465 static const char** GetTypeNames()
467 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
468 "Shape","ConnectedShape","MultiConn.Shape",
469 "ConnectedInter.","MultiConn.",
470 "Constraint","Dimension"};
471 static const char** ThePointer = names;
475 //=======================================================================
476 //function : GetTypeAndSignfromString
478 //=======================================================================
479 static void GetTypeAndSignfromString (const char* theName,
480 AIS_KindOfInteractive& theType,
481 Standard_Integer& theSign)
483 const char** aFullNames = GetTypeNames();
484 Standard_Integer anIndex = -1;
485 for (Standard_Integer i = 0; i <= 13 && anIndex == -1; ++i)
487 if (strcasecmp (theName, aFullNames[i]) == 0)
495 theType = AIS_KindOfInteractive_None;
502 theType = AIS_KindOfInteractive_Datum;
505 else if (anIndex <= 9)
507 theType = AIS_KindOfInteractive_Shape;
508 theSign = anIndex - 7;
510 else if (anIndex <= 11)
512 theType = AIS_KindOfInteractive_Object;
513 theSign = anIndex - 10;
517 theType = AIS_KindOfInteractive_Relation;
518 theSign = anIndex - 12;
523 #include <Draw_Interpretor.hxx>
525 #include <Draw_Appli.hxx>
529 #include <TCollection_AsciiString.hxx>
530 #include <V3d_Viewer.hxx>
531 #include <V3d_View.hxx>
534 #include <AIS_InteractiveContext.hxx>
535 #include <AIS_Shape.hxx>
536 #include <AIS_DisplayMode.hxx>
537 #include <TColStd_MapOfInteger.hxx>
538 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
539 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
540 #include <ViewerTest_EventManager.hxx>
542 #include <TopoDS_Solid.hxx>
543 #include <BRepTools.hxx>
544 #include <BRep_Builder.hxx>
545 #include <TopAbs_ShapeEnum.hxx>
547 #include <TopoDS.hxx>
548 #include <BRep_Tool.hxx>
551 #include <Draw_Window.hxx>
552 #include <AIS_ListIteratorOfListOfInteractive.hxx>
553 #include <AIS_ListOfInteractive.hxx>
554 #include <AIS_DisplayMode.hxx>
555 #include <TopTools_ListOfShape.hxx>
556 #include <BRepOffsetAPI_MakeThickSolid.hxx>
558 //==============================================================================
559 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
560 //==============================================================================
561 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
562 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
566 //=======================================================================
569 //=======================================================================
570 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
571 const Handle(AIS_InteractiveObject)& theObject,
572 const Standard_Boolean theToUpdate,
573 const Standard_Boolean theReplaceIfExists)
575 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
576 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
579 Message::SendFail ("Error: AIS context is not available.");
580 return Standard_False;
583 if (aMap.IsBound2 (theName))
585 if (!theReplaceIfExists)
587 Message::SendFail() << "Error: other interactive object has been already registered with name: " << theName << ".\n"
588 << "Please use another name.";
589 return Standard_False;
592 if (Handle(AIS_InteractiveObject) anOldObj = aMap.Find2 (theName))
594 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
596 aMap.UnBind2 (theName);
599 if (theObject.IsNull())
601 // object with specified name has been already unbound
602 return Standard_True;
605 // unbind AIS object if it was bound with another name
606 aMap.UnBind1 (theObject);
608 // can be registered without rebinding
609 aMap.Bind (theObject, theName);
610 aCtx->Display (theObject, theToUpdate);
611 return Standard_True;
614 //! Alias for ViewerTest::Display(), compatibility with old code.
615 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
616 const Handle(AIS_InteractiveObject)& theObject,
617 Standard_Boolean theReplaceIfExists = Standard_True)
619 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
622 static NCollection_List<Handle(ViewerTest_EventManager)> theEventMgrs;
624 static Handle(V3d_View)& a3DView()
626 static Handle(V3d_View) Viou;
631 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
632 static Handle(AIS_InteractiveContext) aContext;
636 const Handle(V3d_View)& ViewerTest::CurrentView()
640 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
645 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
647 return TheAISContext();
650 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
652 TheAISContext() = aCtx;
653 ViewerTest::ResetEventManager();
656 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
658 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
661 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
663 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
667 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
668 theEventMgrs.Prepend(EM);
671 void ViewerTest::UnsetEventManager()
673 theEventMgrs.RemoveFirst();
677 void ViewerTest::ResetEventManager()
679 theEventMgrs.Clear();
680 theEventMgrs.Prepend (new ViewerTest_EventManager (ViewerTest::CurrentView(), ViewerTest::GetAISContext()));
683 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
685 return !theEventMgrs.IsEmpty()
686 ? theEventMgrs.First()
687 : Handle(ViewerTest_EventManager)();
690 //=======================================================================
691 //function : Get Context and active view
693 //=======================================================================
694 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
695 Handle(V3d_View)& theView)
697 theCtx = ViewerTest::GetAISContext();
698 theView = ViewerTest::CurrentView();
702 Message::SendFail ("Error: cannot find an active view!");
703 return Standard_False;
705 return Standard_True;
708 //==============================================================================
710 //purpose : Remove all the object from the viewer
711 //==============================================================================
712 void ViewerTest::Clear()
714 if (a3DView().IsNull())
719 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
720 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
722 const Handle(AIS_InteractiveObject) anObj = anObjIter.Key1();
723 if (anObj->GetContext() != TheAISContext())
728 Message::SendInfo() << "Remove " << anObjIter.Key2();
729 TheAISContext()->Remove (anObj, Standard_False);
730 aListRemoved.Append (anObj);
733 TheAISContext()->RebuildSelectionStructs();
734 TheAISContext()->UpdateCurrentViewer();
735 if (aListRemoved.Size() == GetMapOfAIS().Extent())
737 GetMapOfAIS().Clear();
741 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
743 GetMapOfAIS().UnBind1 (anObjIter.Value());
748 //==============================================================================
749 //function : CopyIsoAspect
750 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
751 //==============================================================================
752 static Handle(Prs3d_IsoAspect) CopyIsoAspect
753 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
754 const Standard_Integer theNbIsos)
756 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
757 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
758 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
760 Handle(Prs3d_IsoAspect) aResult =
761 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
766 //==============================================================================
768 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
769 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
770 //==============================================================================
771 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
773 if (TheAISContext().IsNull()) {
774 di << argv[0] << " Call 'vinit' before!\n";
779 di << "Current number of isos : " <<
780 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
781 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
782 di << "IsoOnPlane mode is " <<
783 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
784 di << "IsoOnTriangulation mode is " <<
785 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
789 Standard_Integer aLastInd = argc - 1;
790 Standard_Boolean isChanged = Standard_False;
791 Standard_Integer aNbUIsos = 0;
792 Standard_Integer aNbVIsos = 0;
795 Standard_Boolean isIsoOnPlane = Standard_False;
797 if (strcmp(argv[aLastInd], "1") == 0) {
798 isIsoOnPlane = Standard_True;
799 isChanged = Standard_True;
800 } else if (strcmp(argv[aLastInd], "0") == 0) {
801 isIsoOnPlane = Standard_False;
802 isChanged = Standard_True;
806 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
807 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
810 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
811 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
813 TheAISContext()->IsoOnPlane(isIsoOnPlane);
816 // If there are no shapes provided set the default numbers.
817 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
818 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
825 for (i = 1; i <= aLastInd; i++)
827 TCollection_AsciiString name(argv[i]);
828 Handle(AIS_InteractiveObject) aShape;
829 GetMapOfAIS().Find2(name, aShape);
832 Message::SendFail() << "Syntax error: object '" << name << "' is not found";
836 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
837 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
838 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
841 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
842 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
843 TheAISContext()->SetLocalAttributes (aShape, CurDrawer, Standard_False);
844 TheAISContext()->Redisplay (aShape, Standard_False);
848 di << "Number of isos for " << argv[i] << " : "
849 << aUIso->Number() << " " << aVIso->Number() << "\n";
854 TheAISContext()->UpdateCurrentViewer();
860 static Standard_Integer VDispSensi (Draw_Interpretor& ,
861 Standard_Integer theArgNb,
866 Message::SendFail ("Error: wrong syntax!");
870 Handle(AIS_InteractiveContext) aCtx;
871 Handle(V3d_View) aView;
872 if (!getCtxAndView (aCtx, aView))
877 aCtx->DisplayActiveSensitive (aView);
882 static Standard_Integer VClearSensi (Draw_Interpretor& ,
883 Standard_Integer theArgNb,
888 Message::SendFail ("Error: wrong syntax!");
892 Handle(AIS_InteractiveContext) aCtx;
893 Handle(V3d_View) aView;
894 if (!getCtxAndView (aCtx, aView))
898 aCtx->ClearActiveSensitive (aView);
902 //==============================================================================
904 //purpose : To list the displayed object with their attributes
905 //==============================================================================
906 static int VDir (Draw_Interpretor& theDI,
907 Standard_Integer theNbArgs,
908 const char** theArgVec)
910 TCollection_AsciiString aMatch;
911 Standard_Boolean toFormat = Standard_False;
912 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
914 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
915 anArgCase.LowerCase();
916 if (anArgCase == "-list"
917 || anArgCase == "-format")
919 toFormat = Standard_True;
921 else if (aMatch.IsEmpty())
923 aMatch = theArgVec[anArgIter];
927 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
932 TCollection_AsciiString aRes;
933 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
935 if (!aMatch.IsEmpty())
937 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aMatch + "' '" + anIter.Key2() + "'";
938 if (theDI.Eval (aCheck.ToCString()) == 0
939 && *theDI.Result() != '1')
947 aRes += TCollection_AsciiString("\t") + anIter.Key2() + "\n";
951 aRes += anIter.Key2() + " ";
959 //! Auxiliary enumeration
960 enum ViewerTest_StereoPair
962 ViewerTest_SP_Single,
963 ViewerTest_SP_SideBySide,
964 ViewerTest_SP_OverUnder
967 //==============================================================================
969 //purpose : To dump the active view snapshot to image file
970 //==============================================================================
971 static Standard_Integer VDump (Draw_Interpretor& theDI,
972 Standard_Integer theArgNb,
973 Standard_CString* theArgVec)
975 Handle(V3d_View) aView = ViewerTest::CurrentView();
978 Message::SendFail ("Error: wrong number of arguments! Image file name should be specified at least.");
983 Message::SendFail() << "Error: cannot find an active view!";
987 Standard_Integer anArgIter = 1;
988 Standard_CString aFilePath = theArgVec[anArgIter++];
989 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
990 V3d_ImageDumpOptions aParams;
991 Handle(Graphic3d_Camera) aCustomCam;
992 aParams.BufferType = Graphic3d_BT_RGB;
993 aParams.StereoOptions = V3d_SDO_MONO;
994 for (; anArgIter < theArgNb; ++anArgIter)
996 TCollection_AsciiString anArg (theArgVec[anArgIter]);
998 if (anArg == "-buffer")
1000 if (++anArgIter >= theArgNb)
1002 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
1006 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
1007 aBufArg.LowerCase();
1008 if (aBufArg == "rgba")
1010 aParams.BufferType = Graphic3d_BT_RGBA;
1012 else if (aBufArg == "rgb")
1014 aParams.BufferType = Graphic3d_BT_RGB;
1016 else if (aBufArg == "red")
1018 aParams.BufferType = Graphic3d_BT_Red;
1020 else if (aBufArg == "depth")
1022 aParams.BufferType = Graphic3d_BT_Depth;
1026 Message::SendFail() << "Error: unknown buffer '" << aBufArg << "'";
1030 else if (anArgIter + 1 < theArgNb
1031 && anArg == "-xrpose")
1033 TCollection_AsciiString anXRArg (theArgVec[++anArgIter]);
1034 anXRArg.LowerCase();
1035 if (anXRArg == "base")
1037 aCustomCam = aView->View()->BaseXRCamera();
1039 else if (anXRArg == "head")
1041 aCustomCam = aView->View()->PosedXRCamera();
1043 else if (anXRArg == "handleft"
1044 || anXRArg == "handright")
1046 if (aView->View()->IsActiveXR())
1048 aCustomCam = new Graphic3d_Camera();
1049 aView->View()->ComputeXRPosedCameraFromBase (*aCustomCam, anXRArg == "handleft"
1050 ? aView->View()->XRSession()->LeftHandPose()
1051 : aView->View()->XRSession()->RightHandPose());
1056 Message::SendFail() << "Syntax error: unknown XR pose '" << anXRArg << "'";
1059 if (aCustomCam.IsNull())
1061 Message::SendFail() << "Error: undefined XR pose";
1065 else if (anArg == "-stereo")
1067 if (++anArgIter >= theArgNb)
1069 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
1073 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
1074 aStereoArg.LowerCase();
1075 if (aStereoArg == "l"
1076 || aStereoArg == "left")
1078 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1080 else if (aStereoArg == "r"
1081 || aStereoArg == "right")
1083 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1085 else if (aStereoArg == "mono")
1087 aParams.StereoOptions = V3d_SDO_MONO;
1089 else if (aStereoArg == "blended"
1090 || aStereoArg == "blend"
1091 || aStereoArg == "stereo")
1093 aParams.StereoOptions = V3d_SDO_BLENDED;
1095 else if (aStereoArg == "sbs"
1096 || aStereoArg == "sidebyside")
1098 aStereoPair = ViewerTest_SP_SideBySide;
1100 else if (aStereoArg == "ou"
1101 || aStereoArg == "overunder")
1103 aStereoPair = ViewerTest_SP_OverUnder;
1107 Message::SendFail() << "Error: unknown stereo format '" << aStereoArg << "'";
1111 else if (anArg == "-rgba"
1114 aParams.BufferType = Graphic3d_BT_RGBA;
1116 else if (anArg == "-rgb"
1119 aParams.BufferType = Graphic3d_BT_RGB;
1121 else if (anArg == "-red"
1124 aParams.BufferType = Graphic3d_BT_Red;
1126 else if (anArg == "-depth"
1127 || anArg == "depth")
1129 aParams.BufferType = Graphic3d_BT_Depth;
1131 else if (anArg == "-width"
1133 || anArg == "sizex")
1135 if (aParams.Width != 0)
1137 Message::SendFail() << "Error: wrong syntax at " << theArgVec[anArgIter];
1140 else if (++anArgIter >= theArgNb)
1142 Message::SendFail() << "Error: integer value is expected right after 'width'";
1145 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1147 else if (anArg == "-height"
1148 || anArg == "height"
1149 || anArg == "-sizey")
1151 if (aParams.Height != 0)
1153 Message::SendFail() << "Error: wrong syntax at " << theArgVec[anArgIter];
1156 else if (++anArgIter >= theArgNb)
1158 Message::SendFail() << "Error: integer value is expected right after 'height'";
1161 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1163 else if (anArg == "-tile"
1164 || anArg == "-tilesize")
1166 if (++anArgIter >= theArgNb)
1168 Message::SendFail() << "Error: integer value is expected right after 'tileSize'";
1171 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1175 Message::SendFail() << "Error: unknown argument '" << theArgVec[anArgIter] << "'";
1179 if ((aParams.Width <= 0 && aParams.Height > 0)
1180 || (aParams.Width > 0 && aParams.Height <= 0))
1182 Message::SendFail() << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect";
1186 if (aParams.Width <= 0 || aParams.Height <= 0)
1188 aView->Window()->Size (aParams.Width, aParams.Height);
1191 Image_AlienPixMap aPixMap;
1192 Image_Format aFormat = Image_Format_UNKNOWN;
1193 switch (aParams.BufferType)
1195 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1196 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1197 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1198 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1199 case Graphic3d_BT_Red: aFormat = Image_Format_Gray; break;
1202 const bool wasImmUpdate = aView->SetImmediateUpdate (false);
1203 Handle(Graphic3d_Camera) aCamBack = aView->Camera();
1204 if (!aCustomCam.IsNull())
1206 aView->SetCamera (aCustomCam);
1208 switch (aStereoPair)
1210 case ViewerTest_SP_Single:
1212 if (!aView->ToPixMap (aPixMap, aParams))
1214 theDI << "Fail: view dump failed!\n";
1217 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1218 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1220 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1221 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1225 case ViewerTest_SP_SideBySide:
1227 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1229 theDI << "Fail: not enough memory for image allocation!\n";
1233 Image_PixMap aPixMapL, aPixMapR;
1234 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1235 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1236 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1237 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1239 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1240 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1241 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1242 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1245 theDI << "Fail: view dump failed!\n";
1250 case ViewerTest_SP_OverUnder:
1252 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1254 theDI << "Fail: not enough memory for image allocation!\n";
1258 Image_PixMap aPixMapL, aPixMapR;
1259 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1260 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1261 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1262 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1264 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1265 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1266 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1267 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1270 theDI << "Fail: view dump failed!\n";
1276 if (!aCustomCam.IsNull())
1278 aView->SetCamera (aCamBack);
1280 aView->SetImmediateUpdate (wasImmUpdate);
1282 if (!aPixMap.Save (aFilePath))
1284 theDI << "Fail: image can not be saved!\n";
1289 enum TypeOfDispOperation
1291 TypeOfDispOperation_SetDispMode,
1292 TypeOfDispOperation_UnsetDispMode
1295 //! Displays,Erase...
1296 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1297 const Standard_Integer theMode,
1298 const TypeOfDispOperation theType,
1299 const Standard_Boolean theToUpdate)
1301 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1304 case TypeOfDispOperation_SetDispMode:
1306 if (!thePrs.IsNull())
1308 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1312 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1316 case TypeOfDispOperation_UnsetDispMode:
1318 if (!thePrs.IsNull())
1320 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1324 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1331 //=======================================================================
1334 //=======================================================================
1335 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1340 Message::SendFail() << "Syntax error: wrong number of arguments";
1344 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1345 ? TypeOfDispOperation_UnsetDispMode
1346 : TypeOfDispOperation_SetDispMode;
1347 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1350 Message::SendFail ("Error: no active viewer");
1354 if (aType == TypeOfDispOperation_UnsetDispMode)
1358 if (aCtx->NbSelected() == 0)
1360 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1364 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1366 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1369 aCtx->UpdateCurrentViewer();
1373 TCollection_AsciiString aName = argv[1];
1374 Handle(AIS_InteractiveObject) aPrs;
1375 if (GetMapOfAIS().Find2 (aName, aPrs)
1378 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1384 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1385 if (aCtx->NbSelected() == 0
1386 && aType == TypeOfDispOperation_SetDispMode)
1388 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1390 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1392 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1394 aCtx->UpdateCurrentViewer();
1398 Handle(AIS_InteractiveObject) aPrs;
1399 TCollection_AsciiString aName (argv[1]);
1400 if (GetMapOfAIS().Find2 (aName, aPrs)
1403 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1410 //=======================================================================
1413 //=======================================================================
1414 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1416 if(argc==1) return 1;
1417 Standard_Integer On = Draw::Atoi(argv[1]);
1418 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1421 Message::SendFail ("Error: no active viewer");
1427 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1428 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1429 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1433 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1437 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1441 Ctx->UpdateCurrentViewer();
1444 Handle(AIS_InteractiveObject) IO;
1445 TCollection_AsciiString name = argv[2];
1446 if (GetMapOfAIS().Find2 (name, IO)
1450 Ctx->SubIntensityOn(IO, Standard_True);
1452 Ctx->SubIntensityOff(IO, Standard_True);
1459 //! Auxiliary class to iterate presentations from different collections.
1460 class ViewTest_PrsIter
1464 //! Create and initialize iterator object.
1465 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1466 : mySource (IterSource_All)
1468 NCollection_Sequence<TCollection_AsciiString> aNames;
1469 if (!theName.IsEmpty())
1470 aNames.Append (theName);
1474 //! Create and initialize iterator object.
1475 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1476 : mySource (IterSource_All)
1481 //! Initialize the iterator.
1482 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1484 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1486 mySelIter.Nullify();
1487 myCurrent.Nullify();
1488 myCurrentTrs.Nullify();
1489 if (!mySeq.IsEmpty())
1491 mySource = IterSource_List;
1492 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1494 else if (aCtx->NbSelected() > 0)
1496 mySource = IterSource_Selected;
1498 mySelIter->InitSelected();
1502 mySource = IterSource_All;
1503 myMapIter.Initialize (GetMapOfAIS());
1508 const TCollection_AsciiString& CurrentName() const
1510 return myCurrentName;
1513 const Handle(AIS_InteractiveObject)& Current() const
1518 const Handle(Standard_Transient)& CurrentTrs() const
1520 return myCurrentTrs;
1523 //! @return true if iterator points to valid object within collection
1524 Standard_Boolean More() const
1528 case IterSource_All: return myMapIter.More();
1529 case IterSource_List: return mySeqIter.More();
1530 case IterSource_Selected: return mySelIter->MoreSelected();
1532 return Standard_False;
1535 //! Go to the next item.
1538 myCurrentName.Clear();
1539 myCurrentTrs.Nullify();
1540 myCurrent.Nullify();
1543 case IterSource_All:
1548 case IterSource_List:
1553 case IterSource_Selected:
1555 mySelIter->NextSelected();
1568 case IterSource_All:
1570 if (myMapIter.More())
1572 myCurrentName = myMapIter.Key2();
1573 myCurrentTrs = myMapIter.Key1();
1574 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1578 case IterSource_List:
1580 if (mySeqIter.More())
1582 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1584 Message::SendFail() << "Error: object " << mySeqIter.Value() << " is not displayed!";
1587 myCurrentName = mySeqIter.Value();
1588 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1589 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1593 case IterSource_Selected:
1595 if (mySelIter->MoreSelected())
1597 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1598 myCurrent = mySelIter->SelectedInteractive();
1616 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1617 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1618 NCollection_Sequence<TCollection_AsciiString> mySeq;
1619 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1621 TCollection_AsciiString myCurrentName;//!< current item name
1622 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1623 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1625 IterSource mySource; //!< iterated collection
1629 //! Parse interior style name.
1630 static bool parseInteriorStyle (const TCollection_AsciiString& theArg,
1631 Aspect_InteriorStyle& theStyle)
1633 TCollection_AsciiString anArg (theArg);
1635 if (anArg == "empty")
1637 theStyle = Aspect_IS_EMPTY;
1639 else if (anArg == "hollow")
1641 theStyle = Aspect_IS_HOLLOW;
1643 else if (anArg == "solid")
1645 theStyle = Aspect_IS_SOLID;
1647 else if (anArg == "hatch")
1649 theStyle = Aspect_IS_HATCH;
1651 else if (anArg == "hiddenline"
1652 || anArg == "hidden-line"
1653 || anArg == "hidden_line")
1655 theStyle = Aspect_IS_HIDDENLINE;
1657 else if (anArg == "point")
1659 theStyle = Aspect_IS_POINT;
1661 else if (theArg.IsIntegerValue())
1663 const Standard_Integer anIntStyle = theArg.IntegerValue();
1664 if (anIntStyle < Aspect_IS_EMPTY || anIntStyle > Aspect_IS_POINT)
1668 theStyle = (Aspect_InteriorStyle)anIntStyle;
1677 //! Auxiliary structure for VAspects
1678 struct ViewerTest_AspectsChangeSet
1680 Standard_Integer ToSetVisibility;
1681 Standard_Integer Visibility;
1683 Standard_Integer ToSetColor;
1684 Quantity_Color Color;
1685 Standard_Integer ToSetBackFaceColor;
1686 Quantity_Color BackFaceColor;
1688 Standard_Integer ToSetLineWidth;
1689 Standard_Real LineWidth;
1691 Standard_Integer ToSetTypeOfLine;
1692 uint16_t StippleLinePattern;
1693 uint16_t StippleLineFactor;
1695 Standard_Integer ToSetTypeOfMarker;
1696 Aspect_TypeOfMarker TypeOfMarker;
1697 Handle(Image_PixMap) MarkerImage;
1699 Standard_Integer ToSetMarkerSize;
1700 Standard_Real MarkerSize;
1702 Standard_Integer ToSetTransparency;
1703 Standard_Real Transparency;
1705 Standard_Integer ToSetAlphaMode;
1706 Graphic3d_AlphaMode AlphaMode;
1707 Standard_ShortReal AlphaCutoff;
1709 Standard_Integer ToSetMaterial;
1710 Graphic3d_NameOfMaterial Material;
1711 TCollection_AsciiString MatName;
1713 NCollection_Sequence<TopoDS_Shape> SubShapes;
1715 Standard_Integer ToSetShowFreeBoundary;
1716 Standard_Integer ToSetFreeBoundaryWidth;
1717 Standard_Real FreeBoundaryWidth;
1718 Standard_Integer ToSetFreeBoundaryColor;
1719 Quantity_Color FreeBoundaryColor;
1721 Standard_Integer ToEnableIsoOnTriangulation;
1723 Standard_Integer ToSetFaceBoundaryDraw;
1724 Standard_Integer ToSetFaceBoundaryUpperContinuity;
1725 GeomAbs_Shape FaceBoundaryUpperContinuity;
1727 Standard_Integer ToSetFaceBoundaryColor;
1728 Quantity_Color FaceBoundaryColor;
1730 Standard_Integer ToSetFaceBoundaryWidth;
1731 Standard_Real FaceBoundaryWidth;
1733 Standard_Integer ToSetTypeOfFaceBoundaryLine;
1734 Aspect_TypeOfLine TypeOfFaceBoundaryLine;
1736 Standard_Integer ToSetMaxParamValue;
1737 Standard_Real MaxParamValue;
1739 Standard_Integer ToSetSensitivity;
1740 Standard_Integer SelectionMode;
1741 Standard_Integer Sensitivity;
1743 Standard_Integer ToSetHatch;
1744 Standard_Integer StdHatchStyle;
1745 TCollection_AsciiString PathToHatchPattern;
1747 Standard_Integer ToSetShadingModel;
1748 Graphic3d_TypeOfShadingModel ShadingModel;
1749 TCollection_AsciiString ShadingModelName;
1751 Standard_Integer ToSetInterior;
1752 Aspect_InteriorStyle InteriorStyle;
1754 Standard_Integer ToSetDrawSilhouette;
1756 Standard_Integer ToSetDrawEdges;
1757 Standard_Integer ToSetQuadEdges;
1759 Standard_Integer ToSetEdgeColor;
1760 Quantity_ColorRGBA EdgeColor;
1762 Standard_Integer ToSetEdgeWidth;
1763 Standard_Real EdgeWidth;
1765 Standard_Integer ToSetTypeOfEdge;
1766 Aspect_TypeOfLine TypeOfEdge;
1768 //! Empty constructor
1769 ViewerTest_AspectsChangeSet()
1770 : ToSetVisibility (0),
1773 Color (DEFAULT_COLOR),
1774 ToSetBackFaceColor(0),
1775 BackFaceColor (DEFAULT_COLOR),
1778 ToSetTypeOfLine (0),
1779 StippleLinePattern(0xFFFF),
1780 StippleLineFactor (1),
1781 ToSetTypeOfMarker (0),
1782 TypeOfMarker (Aspect_TOM_PLUS),
1783 ToSetMarkerSize (0),
1785 ToSetTransparency (0),
1788 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1791 Material (Graphic3d_NameOfMaterial_DEFAULT),
1792 ToSetShowFreeBoundary (0),
1793 ToSetFreeBoundaryWidth (0),
1794 FreeBoundaryWidth (1.0),
1795 ToSetFreeBoundaryColor (0),
1796 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1797 ToEnableIsoOnTriangulation (0),
1799 ToSetFaceBoundaryDraw (0),
1800 ToSetFaceBoundaryUpperContinuity (0),
1801 FaceBoundaryUpperContinuity(GeomAbs_CN),
1802 ToSetFaceBoundaryColor (0),
1803 FaceBoundaryColor (Quantity_NOC_BLACK),
1804 ToSetFaceBoundaryWidth (0),
1805 FaceBoundaryWidth (1.0f),
1806 ToSetTypeOfFaceBoundaryLine(0),
1807 TypeOfFaceBoundaryLine (Aspect_TOL_SOLID),
1809 ToSetMaxParamValue (0),
1810 MaxParamValue (500000),
1811 ToSetSensitivity (0),
1816 ToSetShadingModel (0),
1817 ShadingModel (Graphic3d_TypeOfShadingModel_DEFAULT),
1819 InteriorStyle (Aspect_IS_SOLID),
1820 ToSetDrawSilhouette (0),
1826 ToSetTypeOfEdge (0),
1827 TypeOfEdge (Aspect_TOL_SOLID)
1830 //! @return true if no changes have been requested
1831 Standard_Boolean IsEmpty() const
1833 return ToSetVisibility == 0
1834 && ToSetLineWidth == 0
1835 && ToSetTransparency == 0
1836 && ToSetAlphaMode == 0
1838 && ToSetBackFaceColor == 0
1839 && ToSetMaterial == 0
1840 && ToSetShowFreeBoundary == 0
1841 && ToSetFreeBoundaryColor == 0
1842 && ToSetFreeBoundaryWidth == 0
1843 && ToEnableIsoOnTriangulation == 0
1844 && ToSetFaceBoundaryDraw == 0
1845 && ToSetFaceBoundaryUpperContinuity == 0
1846 && ToSetFaceBoundaryColor == 0
1847 && ToSetFaceBoundaryWidth == 0
1848 && ToSetTypeOfFaceBoundaryLine == 0
1849 && ToSetMaxParamValue == 0
1850 && ToSetSensitivity == 0
1852 && ToSetShadingModel == 0
1853 && ToSetInterior == 0
1854 && ToSetDrawSilhouette == 0
1855 && ToSetDrawEdges == 0
1856 && ToSetQuadEdges == 0
1857 && ToSetEdgeColor == 0
1858 && ToSetEdgeWidth == 0
1859 && ToSetTypeOfEdge == 0;
1862 //! @return true if properties are valid
1863 Standard_Boolean Validate() const
1865 Standard_Boolean isOk = Standard_True;
1866 if (Visibility != 0 && Visibility != 1)
1868 Message::SendFail() << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")";
1869 isOk = Standard_False;
1871 if (LineWidth <= 0.0
1872 || LineWidth > 10.0)
1874 Message::SendFail() << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")";
1875 isOk = Standard_False;
1877 if (Transparency < 0.0
1878 || Transparency > 1.0)
1880 Message::SendFail() << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")";
1881 isOk = Standard_False;
1883 if (ToSetAlphaMode == 1
1884 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1886 Message::SendFail() << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")";
1887 isOk = Standard_False;
1889 if (FreeBoundaryWidth <= 0.0
1890 || FreeBoundaryWidth > 10.0)
1892 Message::SendFail() << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")";
1893 isOk = Standard_False;
1895 if (MaxParamValue < 0.0)
1897 Message::SendFail() << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")";
1898 isOk = Standard_False;
1900 if (Sensitivity < 0 && ToSetSensitivity)
1902 Message::SendFail() << "Error: sensitivity parameter value should not be negative (specified " << Sensitivity << ")";
1903 isOk = Standard_False;
1905 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1907 Message::SendFail ("Error: hatch style must be specified");
1908 isOk = Standard_False;
1910 if (ToSetShadingModel == 1
1911 && (ShadingModel < Graphic3d_TypeOfShadingModel_DEFAULT || ShadingModel > Graphic3d_TypeOfShadingModel_PbrFacet))
1913 Message::SendFail() << "Error: unknown shading model " << ShadingModelName << ".";
1914 isOk = Standard_False;
1919 //! Apply aspects to specified drawer.
1920 bool Apply (const Handle(Prs3d_Drawer)& theDrawer)
1922 bool toRecompute = false;
1923 const Handle(Prs3d_Drawer)& aDefDrawer = ViewerTest::GetAISContext()->DefaultDrawer();
1924 if (ToSetShowFreeBoundary != 0)
1926 theDrawer->SetFreeBoundaryDraw (ToSetShowFreeBoundary == 1);
1929 if (ToSetFreeBoundaryWidth != 0)
1931 if (ToSetFreeBoundaryWidth != -1
1932 || theDrawer->HasOwnFreeBoundaryAspect())
1934 if (!theDrawer->HasOwnFreeBoundaryAspect())
1936 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
1937 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
1938 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
1941 theDrawer->FreeBoundaryAspect()->SetWidth (FreeBoundaryWidth);
1944 if (ToSetFreeBoundaryColor != 0)
1946 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
1947 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
1948 aBoundaryAspect->SetColor (FreeBoundaryColor);
1949 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
1952 if (ToSetTypeOfLine != 0)
1954 if (ToSetTypeOfLine != -1
1955 || theDrawer->HasOwnLineAspect()
1956 || theDrawer->HasOwnWireAspect()
1957 || theDrawer->HasOwnFreeBoundaryAspect()
1958 || theDrawer->HasOwnUnFreeBoundaryAspect()
1959 || theDrawer->HasOwnSeenLineAspect())
1961 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
1962 theDrawer->LineAspect()->Aspect()->SetLinePattern (StippleLinePattern);
1963 theDrawer->LineAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor);
1964 theDrawer->WireAspect()->Aspect()->SetLinePattern (StippleLinePattern);
1965 theDrawer->WireAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor);
1966 theDrawer->FreeBoundaryAspect()->Aspect()->SetLinePattern (StippleLinePattern);
1967 theDrawer->FreeBoundaryAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor);
1968 theDrawer->UnFreeBoundaryAspect()->Aspect()->SetLinePattern (StippleLinePattern);
1969 theDrawer->UnFreeBoundaryAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor);
1970 theDrawer->SeenLineAspect()->Aspect()->SetLinePattern (StippleLinePattern);
1971 theDrawer->SeenLineAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor);
1974 if (ToSetTypeOfMarker != 0)
1976 if (ToSetTypeOfMarker != -1
1977 || theDrawer->HasOwnPointAspect())
1979 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
1980 theDrawer->PointAspect()->SetTypeOfMarker (TypeOfMarker);
1981 theDrawer->PointAspect()->Aspect()->SetMarkerImage (MarkerImage.IsNull() ? Handle(Graphic3d_MarkerImage)() : new Graphic3d_MarkerImage (MarkerImage));
1984 if (ToSetMarkerSize != 0)
1986 if (ToSetMarkerSize != -1
1987 || theDrawer->HasOwnPointAspect())
1989 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
1990 theDrawer->PointAspect()->SetScale (MarkerSize);
1994 if (ToSetMaxParamValue != 0)
1996 if (ToSetMaxParamValue != -1
1997 || theDrawer->HasOwnMaximalParameterValue())
1999 theDrawer->SetMaximalParameterValue (MaxParamValue);
2003 if (ToSetFaceBoundaryDraw != 0)
2005 if (ToSetFaceBoundaryDraw != -1
2006 || theDrawer->HasOwnFaceBoundaryDraw())
2009 theDrawer->SetFaceBoundaryDraw (ToSetFaceBoundaryDraw == 1);
2012 if (ToSetFaceBoundaryUpperContinuity != 0)
2014 if (ToSetFaceBoundaryUpperContinuity != -1
2015 || theDrawer->HasOwnFaceBoundaryUpperContinuity())
2018 if (ToSetFaceBoundaryUpperContinuity == -1)
2020 theDrawer->UnsetFaceBoundaryUpperContinuity();
2024 theDrawer->SetFaceBoundaryUpperContinuity (FaceBoundaryUpperContinuity);
2028 if (ToSetFaceBoundaryColor != 0)
2030 if (ToSetFaceBoundaryColor != -1
2031 || theDrawer->HasOwnFaceBoundaryAspect())
2033 if (ToSetFaceBoundaryColor == -1)
2036 theDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
2040 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2041 theDrawer->FaceBoundaryAspect()->SetColor (FaceBoundaryColor);
2045 if (ToSetFaceBoundaryWidth != 0)
2047 if (ToSetFaceBoundaryWidth != -1
2048 || theDrawer->HasOwnFaceBoundaryAspect())
2050 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2051 theDrawer->FaceBoundaryAspect()->SetWidth (FaceBoundaryWidth);
2054 if (ToSetTypeOfFaceBoundaryLine != 0)
2056 if (ToSetTypeOfFaceBoundaryLine != -1
2057 || theDrawer->HasOwnFaceBoundaryAspect())
2059 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2060 theDrawer->FaceBoundaryAspect()->SetTypeOfLine (TypeOfFaceBoundaryLine);
2063 if (ToSetShadingModel != 0)
2065 if (ToSetShadingModel != -1
2066 || theDrawer->HasOwnShadingAspect())
2068 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2069 theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel);
2072 if (ToSetBackFaceColor != 0)
2074 if (ToSetBackFaceColor != -1
2075 || theDrawer->HasOwnShadingAspect())
2077 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2078 theDrawer->ShadingAspect()->SetColor (BackFaceColor, Aspect_TOFM_BACK_SIDE);
2081 if (ToSetAlphaMode != 0)
2083 if (ToSetAlphaMode != -1
2084 || theDrawer->HasOwnShadingAspect())
2086 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2087 theDrawer->ShadingAspect()->Aspect()->SetAlphaMode (AlphaMode, AlphaCutoff);
2090 if (ToSetHatch != 0)
2092 if (ToSetHatch != -1
2093 || theDrawer->HasOwnShadingAspect())
2095 theDrawer->SetupOwnShadingAspect (aDefDrawer);
2096 Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect();
2097 if (ToSetHatch == -1)
2099 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2103 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2104 if (!PathToHatchPattern.IsEmpty())
2106 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2107 if (anImage->Load (TCollection_AsciiString (PathToHatchPattern.ToCString())))
2109 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2113 Message::SendFail() << "Error: cannot load the following image: " << PathToHatchPattern;
2116 else if (StdHatchStyle != -1)
2118 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)StdHatchStyle));
2124 if (ToSetInterior != 0)
2126 if (ToSetInterior != -1
2127 || theDrawer->HasOwnShadingAspect())
2129 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2130 theDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (InteriorStyle);
2131 if (InteriorStyle == Aspect_IS_HATCH
2132 && theDrawer->ShadingAspect()->Aspect()->HatchStyle().IsNull())
2134 theDrawer->ShadingAspect()->Aspect()->SetHatchStyle (Aspect_HS_VERTICAL);
2138 if (ToSetDrawSilhouette != 0)
2140 if (ToSetDrawSilhouette != -1
2141 || theDrawer->HasOwnShadingAspect())
2143 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2144 theDrawer->ShadingAspect()->Aspect()->SetDrawSilhouette (ToSetDrawSilhouette == 1);
2147 if (ToSetDrawEdges != 0)
2149 if (ToSetDrawEdges != -1
2150 || theDrawer->HasOwnShadingAspect())
2152 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2153 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetDrawEdges == 1);
2156 if (ToSetQuadEdges != 0)
2158 if (ToSetQuadEdges != -1
2159 || theDrawer->HasOwnShadingAspect())
2161 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2162 theDrawer->ShadingAspect()->Aspect()->SetSkipFirstEdge (ToSetQuadEdges == 1);
2165 if (ToSetEdgeWidth != 0)
2167 if (ToSetEdgeWidth != -1
2168 || theDrawer->HasOwnShadingAspect())
2170 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2171 theDrawer->ShadingAspect()->Aspect()->SetEdgeWidth (EdgeWidth);
2174 if (ToSetTypeOfEdge != 0)
2176 if (ToSetTypeOfEdge != -1
2177 || theDrawer->HasOwnShadingAspect())
2179 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2180 theDrawer->ShadingAspect()->Aspect()->SetEdgeLineType (TypeOfEdge);
2181 if (ToSetInterior == 0)
2183 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetTypeOfEdge == 1
2184 && TypeOfEdge != Aspect_TOL_EMPTY);
2188 if (ToSetEdgeColor != 0)
2190 if (ToSetEdgeColor != -1
2191 || theDrawer->HasOwnShadingAspect())
2193 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2194 if (ToSetEdgeColor == -1)
2196 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (theDrawer->ShadingAspect()->Aspect()->InteriorColor());
2200 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (EdgeColor);
2208 //==============================================================================
2209 //function : VAspects
2211 //==============================================================================
2212 static Standard_Integer VAspects (Draw_Interpretor& theDI,
2213 Standard_Integer theArgNb,
2214 const char** theArgVec)
2216 TCollection_AsciiString aCmdName (theArgVec[0]);
2217 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2218 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2221 Message::SendFail ("Error: no active view!");
2225 Standard_Integer anArgIter = 1;
2226 Standard_Boolean isDefaults = Standard_False;
2227 NCollection_Sequence<TCollection_AsciiString> aNames;
2228 for (; anArgIter < theArgNb; ++anArgIter)
2230 TCollection_AsciiString anArg = theArgVec[anArgIter];
2231 if (anUpdateTool.parseRedrawMode (anArg))
2235 else if (!anArg.IsEmpty()
2236 && anArg.Value (1) != '-')
2238 aNames.Append (anArg);
2242 if (anArg == "-defaults")
2244 isDefaults = Standard_True;
2251 if (!aNames.IsEmpty() && isDefaults)
2253 Message::SendFail ("Error: wrong syntax. If -defaults is used there should not be any objects' names!");
2257 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
2258 aChanges.Append (ViewerTest_AspectsChangeSet());
2259 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
2261 // parse syntax of legacy commands
2262 bool toParseAliasArgs = false;
2263 Standard_Boolean toDump = 0;
2264 Standard_Boolean toCompactDump = 0;
2265 Standard_Integer aDumpDepth = -1;
2266 if (aCmdName == "vsetwidth")
2268 if (aNames.IsEmpty()
2269 || !aNames.Last().IsRealValue (Standard_True))
2271 Message::SendFail ("Error: not enough arguments!");
2274 aChangeSet->ToSetLineWidth = 1;
2275 aChangeSet->LineWidth = aNames.Last().RealValue();
2276 aNames.Remove (aNames.Length());
2278 else if (aCmdName == "vunsetwidth")
2280 aChangeSet->ToSetLineWidth = -1;
2282 else if (aCmdName == "vsetcolor")
2284 if (aNames.IsEmpty())
2286 Message::SendFail ("Error: not enough arguments!");
2289 aChangeSet->ToSetColor = 1;
2291 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2292 Standard_Boolean isOk = Standard_False;
2293 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
2295 aChangeSet->Color = aColor;
2296 aNames.Remove (aNames.Length());
2297 isOk = Standard_True;
2299 else if (Quantity_Color::ColorFromHex (aNames.Last().ToCString(), aChangeSet->Color))
2301 aNames.Remove (aNames.Length());
2302 isOk = Standard_True;
2304 else if (aNames.Length() >= 3)
2306 const char* anArgVec[3] =
2308 aNames.Value (aNames.Upper() - 2).ToCString(),
2309 aNames.Value (aNames.Upper() - 1).ToCString(),
2310 aNames.Value (aNames.Upper() - 0).ToCString(),
2313 Standard_Integer aNbParsed = Draw::ParseColor (3, anArgVec, aChangeSet->Color);
2314 isOk = aNbParsed == 3;
2315 aNames.Remove (aNames.Length());
2316 aNames.Remove (aNames.Length());
2317 aNames.Remove (aNames.Length());
2321 Message::SendFail ("Error: not enough arguments!");
2325 else if (aCmdName == "vunsetcolor")
2327 aChangeSet->ToSetColor = -1;
2329 else if (aCmdName == "vsettransparency")
2331 if (aNames.IsEmpty()
2332 || !aNames.Last().IsRealValue (Standard_True))
2334 Message::SendFail ("Error: not enough arguments!");
2337 aChangeSet->ToSetTransparency = 1;
2338 aChangeSet->Transparency = aNames.Last().RealValue();
2339 aNames.Remove (aNames.Length());
2341 else if (aCmdName == "vunsettransparency")
2343 aChangeSet->ToSetTransparency = -1;
2345 else if (aCmdName == "vsetmaterial")
2347 if (aNames.IsEmpty())
2349 Message::SendFail ("Error: not enough arguments!");
2352 aChangeSet->ToSetMaterial = 1;
2353 aChangeSet->MatName = aNames.Last();
2354 aNames.Remove (aNames.Length());
2355 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
2357 Message::SendFail() << "Syntax error: unknown material '" << aChangeSet->MatName << "'.";
2361 else if (aCmdName == "vunsetmaterial")
2363 aChangeSet->ToSetMaterial = -1;
2365 else if (aCmdName == "vsetinteriorstyle")
2367 if (aNames.IsEmpty()
2368 || !aNames.Last().IsRealValue (Standard_True))
2370 Message::SendFail ("Error: not enough arguments!");
2373 aChangeSet->ToSetInterior = 1;
2374 if (!parseInteriorStyle (aNames.Last(), aChangeSet->InteriorStyle))
2376 Message::SendFail() << "Error: wrong syntax at " << aNames.Last();
2379 aNames.Remove (aNames.Length());
2381 else if (aCmdName == "vsetedgetype")
2383 aChangeSet->ToSetDrawEdges = 1;
2384 toParseAliasArgs = true;
2386 else if (aCmdName == "vunsetedgetype")
2388 aChangeSet->ToSetDrawEdges = -1;
2389 aChangeSet->ToSetEdgeColor = -1;
2390 aChangeSet->ToSetTypeOfEdge = -1;
2391 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
2393 else if (aCmdName == "vshowfaceboundary")
2395 aChangeSet->ToSetFaceBoundaryDraw = 1;
2396 toParseAliasArgs = true;
2397 if (aNames.Size() >= 2
2398 && aNames.Value (2).IsIntegerValue())
2400 if (aNames.Size() == 7)
2402 if (ViewerTest::ParseLineType (aNames.Value (7).ToCString(), aChangeSet->TypeOfFaceBoundaryLine))
2404 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2408 if (aNames.Size() == 6
2409 && aNames.Value (6).IsRealValue (Standard_True))
2411 aChangeSet->ToSetFaceBoundaryWidth = 1;
2412 aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue();
2415 if (aNames.Size() == 5
2416 && aNames.Value (3).IsIntegerValue()
2417 && aNames.Value (4).IsIntegerValue()
2418 && aNames.Value (5).IsIntegerValue())
2420 aChangeSet->ToSetFaceBoundaryColor = 1;
2421 aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0,
2422 aNames.Value (4).IntegerValue() / 255.0,
2423 aNames.Value (5).IntegerValue() / 255.0,
2429 if (aNames.Size() == 2)
2431 toParseAliasArgs = false;
2432 aChangeSet->ToSetFaceBoundaryDraw = aNames.Value (2).IntegerValue() == 1 ? 1 : -1;
2437 else if (anArgIter >= theArgNb)
2439 Message::SendFail ("Error: not enough arguments!");
2443 if (!aChangeSet->IsEmpty()
2444 && !toParseAliasArgs)
2446 anArgIter = theArgNb;
2448 for (; anArgIter < theArgNb; ++anArgIter)
2450 TCollection_AsciiString anArg = theArgVec[anArgIter];
2452 if (anArg == "-setwidth"
2453 || anArg == "-width"
2454 || anArg == "-setlinewidth"
2455 || anArg == "-linewidth"
2456 || anArg == "-setedgewidth"
2457 || anArg == "-setedgeswidth"
2458 || anArg == "-edgewidth"
2459 || anArg == "-edgeswidth"
2460 || anArg == "-setfaceboundarywidth"
2461 || anArg == "-setboundarywidth"
2462 || anArg == "-faceboundarywidth"
2463 || anArg == "-boundarywidth")
2465 if (++anArgIter >= theArgNb)
2467 Message::SendFail() << "Error: wrong syntax at " << anArg;
2471 const Standard_Real aWidth = Draw::Atof (theArgVec[anArgIter]);
2472 if (anArg == "-setedgewidth"
2473 || anArg == "-setedgeswidth"
2474 || anArg == "-edgewidth"
2475 || anArg == "-edgeswidth"
2476 || aCmdName == "vsetedgetype")
2478 aChangeSet->ToSetEdgeWidth = 1;
2479 aChangeSet->EdgeWidth = aWidth;
2481 else if (anArg == "-setfaceboundarywidth"
2482 || anArg == "-setboundarywidth"
2483 || anArg == "-faceboundarywidth"
2484 || anArg == "-boundarywidth"
2485 || aCmdName == "vshowfaceboundary")
2487 aChangeSet->ToSetFaceBoundaryWidth = 1;
2488 aChangeSet->FaceBoundaryWidth = aWidth;
2492 aChangeSet->ToSetLineWidth = 1;
2493 aChangeSet->LineWidth = aWidth;
2496 else if (anArg == "-unsetwidth"
2497 || anArg == "-unsetlinewidth"
2498 || anArg == "-unsetedgewidth")
2500 if (anArg == "-unsetedgewidth")
2502 aChangeSet->ToSetEdgeWidth = -1;
2503 aChangeSet->EdgeWidth = 1.0;
2507 aChangeSet->ToSetLineWidth = -1;
2508 aChangeSet->LineWidth = 1.0;
2511 else if (anArg == "-settransp"
2512 || anArg == "-settransparency"
2513 || anArg == "-transparency"
2514 || anArg == "-transp")
2516 if (++anArgIter >= theArgNb)
2518 Message::SendFail() << "Error: wrong syntax at " << anArg;
2521 aChangeSet->ToSetTransparency = 1;
2522 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2523 if (aChangeSet->Transparency >= 0.0
2524 && aChangeSet->Transparency <= Precision::Confusion())
2526 aChangeSet->ToSetTransparency = -1;
2527 aChangeSet->Transparency = 0.0;
2530 else if (anArg == "-setalphamode"
2531 || anArg == "-alphamode")
2533 if (++anArgIter >= theArgNb)
2535 Message::SendFail() << "Error: wrong syntax at " << anArg;
2538 aChangeSet->ToSetAlphaMode = 1;
2539 aChangeSet->AlphaCutoff = 0.5f;
2541 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2543 if (aParam == "opaque")
2545 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2547 else if (aParam == "mask")
2549 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2551 else if (aParam == "blend")
2553 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2555 else if (aParam == "maskblend"
2556 || aParam == "blendmask")
2558 aChangeSet->AlphaMode = Graphic3d_AlphaMode_MaskBlend;
2560 else if (aParam == "blendauto"
2561 || aParam == "auto")
2563 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2567 Message::SendFail() << "Error: wrong syntax at " << aParam;
2572 if (anArgIter + 1 < theArgNb
2573 && theArgVec[anArgIter + 1][0] != '-')
2575 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2576 if (aParam2.IsRealValue (Standard_True))
2578 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2583 else if (anArg == "-setvis"
2584 || anArg == "-setvisibility"
2585 || anArg == "-visibility")
2587 if (++anArgIter >= theArgNb)
2589 Message::SendFail() << "Error: wrong syntax at " << anArg;
2593 aChangeSet->ToSetVisibility = 1;
2594 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2596 else if (anArg == "-setalpha"
2597 || anArg == "-alpha")
2599 if (++anArgIter >= theArgNb)
2601 Message::SendFail() << "Error: wrong syntax at " << anArg;
2604 aChangeSet->ToSetTransparency = 1;
2605 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2606 if (aChangeSet->Transparency < 0.0
2607 || aChangeSet->Transparency > 1.0)
2609 Message::SendFail() << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")";
2612 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2613 if (aChangeSet->Transparency >= 0.0
2614 && aChangeSet->Transparency <= Precision::Confusion())
2616 aChangeSet->ToSetTransparency = -1;
2617 aChangeSet->Transparency = 0.0;
2620 else if (anArg == "-unsettransp"
2621 || anArg == "-unsettransparency"
2622 || anArg == "-unsetalpha"
2623 || anArg == "-opaque")
2625 aChangeSet->ToSetTransparency = -1;
2626 aChangeSet->Transparency = 0.0;
2628 else if (anArg == "-setcolor"
2629 || anArg == "-color"
2630 || anArg == "-setbackfacecolor"
2631 || anArg == "-backfacecolor"
2632 || anArg == "-setbackcolor"
2633 || anArg == "-backcolor"
2634 || anArg == "-setfaceboundarycolor"
2635 || anArg == "-setboundarycolor"
2636 || anArg == "-faceboundarycolor"
2637 || anArg == "-boundarycolor")
2639 Quantity_Color aColor;
2640 Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1,
2641 theArgVec + anArgIter + 1,
2645 Message::SendFail() << "Syntax error at '" << anArg << "'";
2648 anArgIter += aNbParsed;
2649 if (aCmdName == "vsetedgetype")
2651 aChangeSet->ToSetEdgeColor = 1;
2652 aChangeSet->EdgeColor = Quantity_ColorRGBA (aColor);
2654 else if (aCmdName == "vshowfaceboundary"
2655 || anArg == "-setfaceboundarycolor"
2656 || anArg == "-setboundarycolor"
2657 || anArg == "-faceboundarycolor"
2658 || anArg == "-boundarycolor")
2660 aChangeSet->ToSetFaceBoundaryColor = 1;
2661 aChangeSet->FaceBoundaryColor = aColor;
2663 else if (anArg == "-setbackfacecolor"
2664 || anArg == "-backfacecolor"
2665 || anArg == "-setbackcolor"
2666 || anArg == "-backcolor")
2668 aChangeSet->ToSetBackFaceColor = 1;
2669 aChangeSet->BackFaceColor = aColor;
2673 aChangeSet->ToSetColor = 1;
2674 aChangeSet->Color = aColor;
2677 else if (anArg == "-setlinetype"
2678 || anArg == "-linetype"
2679 || anArg == "-setedgetype"
2680 || anArg == "-setedgestype"
2681 || anArg == "-edgetype"
2682 || anArg == "-edgestype"
2683 || anArg == "-setfaceboundarystyle"
2684 || anArg == "-faceboundarystyle"
2685 || anArg == "-boundarystyle"
2686 || anArg == "-setfaceboundarytype"
2687 || anArg == "-faceboundarytype"
2688 || anArg == "-setboundarytype"
2689 || anArg == "-boundarytype"
2690 || anArg == "-type")
2692 if (++anArgIter >= theArgNb)
2694 Message::SendFail() << "Error: wrong syntax at " << anArg;
2697 Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY;
2698 uint16_t aLinePattern = 0xFFFF;
2699 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType, aLinePattern))
2701 Message::SendFail() << "Error: wrong syntax at " << anArg;
2705 if (anArg == "-setedgetype"
2706 || anArg == "-setedgestype"
2707 || anArg == "-edgetype"
2708 || anArg == "-edgestype"
2709 || aCmdName == "vsetedgetype")
2711 aChangeSet->TypeOfEdge = Graphic3d_Aspects::DefaultLineTypeForPattern (aLinePattern);
2712 aChangeSet->ToSetTypeOfEdge = 1;
2714 else if (anArg == "-setfaceboundarystyle"
2715 || anArg == "-faceboundarystyle"
2716 || anArg == "-boundarystyle"
2717 || anArg == "-setfaceboundarytype"
2718 || anArg == "-faceboundarytype"
2719 || anArg == "-setboundarytype"
2720 || anArg == "-boundarytype"
2721 || aCmdName == "vshowfaceboundary")
2723 aChangeSet->TypeOfFaceBoundaryLine = Graphic3d_Aspects::DefaultLineTypeForPattern (aLinePattern);
2724 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2728 aChangeSet->StippleLinePattern = aLinePattern;
2729 aChangeSet->ToSetTypeOfLine = 1;
2732 else if (anArg == "-unsetlinetype"
2733 || anArg == "-unsetedgetype"
2734 || anArg == "-unsetedgestype")
2736 if (anArg == "-unsetedgetype"
2737 || anArg == "-unsetedgestype")
2739 aChangeSet->ToSetTypeOfEdge = -1;
2743 aChangeSet->ToSetTypeOfLine = -1;
2746 else if (anArg == "-setstipplelinefactor"
2747 || anArg == "-setstipplefactor"
2748 || anArg == "-setlinefactor"
2749 || anArg == "-stipplelinefactor"
2750 || anArg == "-stipplefactor"
2751 || anArg == "-linefactor")
2753 if (aChangeSet->ToSetTypeOfLine == -1)
2755 Message::SendFail() << "Error: -setStippleLineFactor requires -setLineType";
2758 if (++anArgIter >= theArgNb)
2760 Message::SendFail() << "Error: wrong syntax at " << anArg;
2763 aChangeSet->StippleLineFactor = (uint16_t )Draw::Atoi (theArgVec[anArgIter]);
2765 else if (anArg == "-setmarkertype"
2766 || anArg == "-markertype"
2767 || anArg == "-setpointtype"
2768 || anArg == "-pointtype")
2770 if (++anArgIter >= theArgNb)
2772 Message::SendFail() << "Error: wrong syntax at " << anArg;
2775 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2777 Message::SendFail() << "Error: wrong syntax at " << anArg;
2781 aChangeSet->ToSetTypeOfMarker = 1;
2783 else if (anArg == "-unsetmarkertype"
2784 || anArg == "-unsetpointtype")
2786 aChangeSet->ToSetTypeOfMarker = -1;
2788 else if (anArg == "-setmarkersize"
2789 || anArg == "-markersize"
2790 || anArg == "-setpointsize"
2791 || anArg == "-pointsize")
2793 if (++anArgIter >= theArgNb)
2795 Message::SendFail() << "Error: wrong syntax at " << anArg;
2798 aChangeSet->ToSetMarkerSize = 1;
2799 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2801 else if (anArg == "-unsetmarkersize"
2802 || anArg == "-unsetpointsize")
2804 aChangeSet->ToSetMarkerSize = -1;
2805 aChangeSet->MarkerSize = 1.0;
2807 else if (anArg == "-unsetcolor")
2809 aChangeSet->ToSetColor = -1;
2810 aChangeSet->Color = DEFAULT_COLOR;
2812 else if (anArg == "-setmat"
2814 || anArg == "-setmaterial"
2815 || anArg == "-material")
2817 if (++anArgIter >= theArgNb)
2819 Message::SendFail() << "Error: wrong syntax at " << anArg;
2822 aChangeSet->ToSetMaterial = 1;
2823 aChangeSet->MatName = theArgVec[anArgIter];
2824 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
2826 Message::SendFail() << "Syntax error: unknown material '" << aChangeSet->MatName << "'.";
2830 else if (anArg == "-unsetmat"
2831 || anArg == "-unsetmaterial")
2833 aChangeSet->ToSetMaterial = -1;
2834 aChangeSet->Material = Graphic3d_NameOfMaterial_DEFAULT;
2836 else if (anArg == "-subshape"
2837 || anArg == "-subshapes")
2841 Message::SendFail() << "Error: wrong syntax. -subshapes can not be used together with -defaults call!";
2845 if (aNames.IsEmpty())
2847 Message::SendFail() << "Error: main objects should specified explicitly when -subshapes is used!";
2851 aChanges.Append (ViewerTest_AspectsChangeSet());
2852 aChangeSet = &aChanges.ChangeLast();
2854 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2856 Standard_CString aSubShapeName = theArgVec[anArgIter];
2857 if (*aSubShapeName == '-')
2863 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2864 if (aSubShape.IsNull())
2866 Message::SendFail() << "Error: shape " << aSubShapeName << " doesn't found!";
2869 aChangeSet->SubShapes.Append (aSubShape);
2872 if (aChangeSet->SubShapes.IsEmpty())
2874 Message::SendFail() << "Error: empty list is specified after -subshapes!";
2878 else if (anArg == "-setfreeboundary"
2879 || anArg == "-freeboundary"
2880 || anArg == "-setfb"
2883 bool toEnable = true;
2884 if (!Draw::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2886 Message::SendFail() << "Error: wrong syntax at " << anArg;
2890 aChangeSet->ToSetShowFreeBoundary = toEnable ? 1 : -1;
2892 else if (anArg == "-setfreeboundarywidth"
2893 || anArg == "-freeboundarywidth"
2894 || anArg == "-setfbwidth"
2895 || anArg == "-fbwidth")
2897 if (++anArgIter >= theArgNb)
2899 Message::SendFail() << "Error: wrong syntax at " << anArg;
2902 aChangeSet->ToSetFreeBoundaryWidth = 1;
2903 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2905 else if (anArg == "-unsetfreeboundarywidth"
2906 || anArg == "-unsetfbwidth")
2908 aChangeSet->ToSetFreeBoundaryWidth = -1;
2909 aChangeSet->FreeBoundaryWidth = 1.0;
2911 else if (anArg == "-setfreeboundarycolor"
2912 || anArg == "-freeboundarycolor"
2913 || anArg == "-setfbcolor"
2914 || anArg == "-fbcolor")
2916 Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1,
2917 theArgVec + anArgIter + 1,
2918 aChangeSet->FreeBoundaryColor);
2921 Message::SendFail() << "Syntax error at '" << anArg << "'";
2924 anArgIter += aNbParsed;
2925 aChangeSet->ToSetFreeBoundaryColor = 1;
2927 else if (anArg == "-unsetfreeboundarycolor"
2928 || anArg == "-unsetfbcolor")
2930 aChangeSet->ToSetFreeBoundaryColor = -1;
2931 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2933 else if (anArg == "-setisoontriangulation"
2934 || anArg == "-isoontriangulation"
2935 || anArg == "-setisoontriang"
2936 || anArg == "-isoontriang")
2938 bool toEnable = true;
2939 if (!Draw::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2941 Message::SendFail() << "Error: wrong syntax at " << anArg;
2945 aChangeSet->ToEnableIsoOnTriangulation = toEnable ? 1 : -1;
2947 else if (anArg == "-setfaceboundarydraw"
2948 || anArg == "-setdrawfaceboundary"
2949 || anArg == "-setdrawfaceboundaries"
2950 || anArg == "-setshowfaceboundary"
2951 || anArg == "-setshowfaceboundaries"
2952 || anArg == "-setdrawfaceedges"
2953 || anArg == "-faceboundarydraw"
2954 || anArg == "-drawfaceboundary"
2955 || anArg == "-drawfaceboundaries"
2956 || anArg == "-showfaceboundary"
2957 || anArg == "-showfaceboundaries"
2958 || anArg == "-drawfaceedges"
2959 || anArg == "-faceboundary"
2960 || anArg == "-faceboundaries"
2961 || anArg == "-faceedges")
2963 bool toEnable = true;
2964 if (!Draw::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2966 Message::SendFail() << "Error: wrong syntax at " << anArg;
2970 aChangeSet->ToSetFaceBoundaryDraw = toEnable ? 1 : -1;
2972 else if (anArg == "-unsetfaceboundary"
2973 || anArg == "-unsetboundary")
2975 aChangeSet->ToSetFaceBoundaryDraw = -1;
2976 aChangeSet->ToSetFaceBoundaryColor = -1;
2978 else if (anArg == "-setmostcontinuity"
2979 || anArg == "-mostcontinuity")
2981 TCollection_AsciiString aClassArg (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "");
2982 aClassArg.LowerCase();
2983 GeomAbs_Shape aClass = GeomAbs_CN;
2984 if (aClassArg == "c0"
2985 || aClassArg == "0")
2987 aClass = GeomAbs_C0;
2989 else if (aClassArg == "g1")
2991 aClass = GeomAbs_G1;
2993 else if (aClassArg == "c1"
2994 || aClassArg == "1")
2996 aClass = GeomAbs_C1;
2998 else if (aClassArg == "g2")
3000 aClass = GeomAbs_G2;
3002 else if (aClassArg == "c2"
3003 || aClassArg == "2")
3005 aClass = GeomAbs_C2;
3007 else if (aClassArg == "c3"
3008 || aClassArg == "3")
3010 aClass = GeomAbs_C3;
3012 else if (aClassArg == "cn"
3013 || aClassArg == "n")
3015 aClass = GeomAbs_CN;
3019 Message::SendFail() << "Syntax error at '" << anArg << "'";
3024 aChangeSet->ToSetFaceBoundaryUpperContinuity = 1;
3025 aChangeSet->FaceBoundaryUpperContinuity = aClass;
3027 else if (anArg == "-setmaxparamvalue"
3028 || anArg == "-maxparamvalue")
3030 if (++anArgIter >= theArgNb)
3032 Message::SendFail() << "Error: wrong syntax at " << anArg;
3035 aChangeSet->ToSetMaxParamValue = 1;
3036 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
3038 else if (anArg == "-setsensitivity"
3039 || anArg == "-sensitivity")
3043 Message::SendFail() << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!";
3047 if (aNames.IsEmpty())
3049 Message::SendFail() << "Error: object and selection mode should specified explicitly when -setSensitivity is used!";
3053 if (anArgIter + 2 >= theArgNb)
3055 Message::SendFail() << "Error: wrong syntax at " << anArg;
3058 aChangeSet->ToSetSensitivity = 1;
3059 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
3060 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
3062 else if (anArg == "-sethatch"
3063 || anArg == "-hatch")
3067 Message::SendFail() << "Error: wrong syntax. -setHatch can not be used together with -defaults call!";
3071 if (aNames.IsEmpty())
3073 Message::SendFail() << "Error: object should be specified explicitly when -setHatch is used!";
3077 aChangeSet->ToSetHatch = 1;
3078 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
3079 if (anArgHatch.Length() <= 2)
3081 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
3083 || anIntStyle >= Aspect_HS_NB)
3085 Message::SendFail() << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!";
3088 aChangeSet->StdHatchStyle = anIntStyle;
3092 aChangeSet->PathToHatchPattern = anArgHatch;
3095 else if (anArg == "-setshadingmodel"
3096 || anArg == "-setshading"
3097 || anArg == "-shadingmodel"
3098 || anArg == "-shading")
3100 if (++anArgIter >= theArgNb)
3102 Message::SendFail() << "Error: wrong syntax at " << anArg;
3105 aChangeSet->ToSetShadingModel = 1;
3106 aChangeSet->ShadingModelName = theArgVec[anArgIter];
3107 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
3109 Message::SendFail() << "Error: wrong syntax at " << anArg;
3113 else if (anArg == "-unsetshadingmodel")
3115 aChangeSet->ToSetShadingModel = -1;
3116 aChangeSet->ShadingModel = Graphic3d_TypeOfShadingModel_DEFAULT;
3118 else if (anArg == "-setinterior"
3119 || anArg == "-setinteriorstyle"
3120 || anArg == "-interior"
3121 || anArg == "-interiorstyle")
3123 if (++anArgIter >= theArgNb)
3125 Message::SendFail() << "Error: wrong syntax at " << anArg;
3128 aChangeSet->ToSetInterior = 1;
3129 if (!parseInteriorStyle (theArgVec[anArgIter], aChangeSet->InteriorStyle))
3131 Message::SendFail() << "Error: wrong syntax at " << anArg;
3135 else if (anArg == "-unsetinterior")
3137 aChangeSet->ToSetInterior = -1;
3138 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3140 else if (anArg == "-setdrawoutline"
3141 || anArg == "-setdrawsilhouette"
3142 || anArg == "-setoutline"
3143 || anArg == "-setsilhouette"
3144 || anArg == "-outline"
3145 || anArg == "-outlined"
3146 || anArg == "-drawsilhouette"
3147 || anArg == "-silhouette")
3149 bool toDrawOutline = true;
3150 if (anArgIter + 1 < theArgNb
3151 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toDrawOutline))
3155 aChangeSet->ToSetDrawSilhouette = toDrawOutline ? 1 : -1;
3157 else if (anArg == "-setdrawedges"
3158 || anArg == "-setdrawedge"
3159 || anArg == "-drawedges"
3160 || anArg == "-drawedge"
3161 || anArg == "-edges")
3163 bool toDrawEdges = true;
3164 if (anArgIter + 1 < theArgNb
3165 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toDrawEdges))
3169 aChangeSet->ToSetDrawEdges = toDrawEdges ? 1 : -1;
3171 else if (anArg == "-setquadedges"
3172 || anArg == "-setquads"
3173 || anArg == "-quads"
3174 || anArg == "-skipfirstedge")
3176 bool isQuadMode = true;
3177 if (anArgIter + 1 < theArgNb
3178 && Draw::ParseOnOff (theArgVec[anArgIter + 1], isQuadMode))
3182 aChangeSet->ToSetQuadEdges = isQuadMode ? 1 : -1;
3184 else if (anArg == "-setedgecolor"
3185 || anArg == "-setedgescolor"
3186 || anArg == "-edgecolor"
3187 || anArg == "-edgescolor")
3189 Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1,
3190 theArgVec + anArgIter + 1,
3191 aChangeSet->EdgeColor);
3194 Message::SendFail() << "Syntax error at '" << anArg << "'";
3197 anArgIter += aNbParsed;
3198 aChangeSet->ToSetEdgeColor = 1;
3200 else if (anArg == "-unset")
3202 aChangeSet->ToSetVisibility = 1;
3203 aChangeSet->Visibility = 1;
3204 aChangeSet->ToSetLineWidth = -1;
3205 aChangeSet->LineWidth = 1.0;
3206 aChangeSet->ToSetTypeOfLine = -1;
3207 aChangeSet->StippleLinePattern = 0xFFFF;
3208 aChangeSet->StippleLineFactor = 1;
3209 aChangeSet->ToSetTypeOfMarker = -1;
3210 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
3211 aChangeSet->ToSetMarkerSize = -1;
3212 aChangeSet->MarkerSize = 1.0;
3213 aChangeSet->ToSetTransparency = -1;
3214 aChangeSet->Transparency = 0.0;
3215 aChangeSet->ToSetAlphaMode = -1;
3216 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
3217 aChangeSet->AlphaCutoff = 0.5f;
3218 aChangeSet->ToSetColor = -1;
3219 aChangeSet->Color = DEFAULT_COLOR;
3220 //aChangeSet->ToSetBackFaceColor = -1; // should be reset by ToSetColor
3221 //aChangeSet->BackFaceColor = DEFAULT_COLOR;
3222 aChangeSet->ToSetMaterial = -1;
3223 aChangeSet->Material = Graphic3d_NameOfMaterial_DEFAULT;
3224 aChangeSet->ToSetShowFreeBoundary = -1;
3225 aChangeSet->ToSetFreeBoundaryColor = -1;
3226 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
3227 aChangeSet->ToSetFreeBoundaryWidth = -1;
3228 aChangeSet->FreeBoundaryWidth = 1.0;
3229 aChangeSet->ToEnableIsoOnTriangulation = -1;
3231 aChangeSet->ToSetFaceBoundaryDraw = -1;
3232 aChangeSet->ToSetFaceBoundaryUpperContinuity = -1;
3233 aChangeSet->FaceBoundaryUpperContinuity = GeomAbs_CN;
3234 aChangeSet->ToSetFaceBoundaryColor = -1;
3235 aChangeSet->FaceBoundaryColor = Quantity_NOC_BLACK;
3236 aChangeSet->ToSetFaceBoundaryWidth = -1;
3237 aChangeSet->FaceBoundaryWidth = 1.0f;
3238 aChangeSet->ToSetTypeOfFaceBoundaryLine = -1;
3239 aChangeSet->TypeOfFaceBoundaryLine = Aspect_TOL_SOLID;
3241 aChangeSet->ToSetHatch = -1;
3242 aChangeSet->StdHatchStyle = -1;
3243 aChangeSet->PathToHatchPattern.Clear();
3244 aChangeSet->ToSetShadingModel = -1;
3245 aChangeSet->ShadingModel = Graphic3d_TypeOfShadingModel_DEFAULT;
3246 aChangeSet->ToSetInterior = -1;
3247 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3248 aChangeSet->ToSetDrawSilhouette = -1;
3249 aChangeSet->ToSetDrawEdges = -1;
3250 aChangeSet->ToSetQuadEdges = -1;
3251 aChangeSet->ToSetEdgeColor = -1;
3252 aChangeSet->EdgeColor = Quantity_ColorRGBA (DEFAULT_COLOR);
3253 aChangeSet->ToSetEdgeWidth = -1;
3254 aChangeSet->EdgeWidth = 1.0;
3255 aChangeSet->ToSetTypeOfEdge = -1;
3256 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
3258 else if (anArg == "-dumpjson")
3260 toDump = Standard_True;
3262 else if (anArg == "-dumpcompact")
3264 toCompactDump = Standard_False;
3265 if (++anArgIter >= theArgNb && Draw::ParseOnOff (theArgVec[anArgIter + 1], toCompactDump))
3268 else if (anArg == "-dumpdepth")
3270 if (++anArgIter >= theArgNb)
3272 Message::SendFail() << "Error: wrong syntax at " << anArg;
3275 aDumpDepth = Draw::Atoi (theArgVec[anArgIter]);
3279 Message::SendFail() << "Error: wrong syntax at " << anArg;
3284 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3285 aChangesIter.More(); aChangesIter.Next())
3287 if (!aChangesIter.Value().Validate())
3293 // special case for -defaults parameter.
3294 // all changed values will be set to DefaultDrawer.
3297 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
3298 aChangeSet->Apply (aDrawer);
3299 if (aChangeSet->ToSetLineWidth != 0)
3301 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
3302 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
3303 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
3304 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
3306 if (aChangeSet->ToSetColor != 0)
3308 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
3309 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
3310 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
3311 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
3312 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
3313 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
3315 if (aChangeSet->ToSetTransparency != 0)
3317 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
3319 if (aChangeSet->ToSetMaterial != 0)
3321 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
3323 if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3325 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
3328 // redisplay all objects in context
3329 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3331 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3334 aCtx->Redisplay (aPrs, Standard_False);
3339 Standard_SStream aStream;
3340 aDrawer->DumpJson (aStream, aDumpDepth);
3343 theDI << Standard_Dump::Text (aStream);
3345 theDI << Standard_Dump::FormatJson (aStream);
3350 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3352 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
3353 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3359 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
3360 Handle(AIS_ColoredShape) aColoredPrs;
3361 Standard_Boolean toDisplay = Standard_False;
3362 Standard_Boolean toRedisplay = Standard_False;
3363 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
3365 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
3366 if (aShapePrs.IsNull())
3368 Message::SendFail() << "Error: an object " << aName << " is not an AIS_Shape presentation!";
3371 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
3372 if (aColoredPrs.IsNull())
3374 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3375 if (aShapePrs->HasDisplayMode())
3377 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
3379 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
3380 aCtx->Remove (aShapePrs, Standard_False);
3381 GetMapOfAIS().UnBind2 (aName);
3382 GetMapOfAIS().Bind (aColoredPrs, aName);
3383 toDisplay = Standard_True;
3384 aShapePrs = aColoredPrs;
3391 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3392 aChangeSet = &aChangesIter.ChangeValue();
3393 if (aChangeSet->ToSetVisibility == 1)
3395 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
3396 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
3398 else if (aChangeSet->ToSetMaterial == 1)
3400 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
3402 else if (aChangeSet->ToSetMaterial == -1)
3404 aCtx->UnsetMaterial (aPrs, Standard_False);
3406 if (aChangeSet->ToSetColor == 1)
3408 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
3410 else if (aChangeSet->ToSetColor == -1)
3412 aCtx->UnsetColor (aPrs, Standard_False);
3414 if (aChangeSet->ToSetTransparency == 1)
3416 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
3418 else if (aChangeSet->ToSetTransparency == -1)
3420 aCtx->UnsetTransparency (aPrs, Standard_False);
3422 if (aChangeSet->ToSetLineWidth == 1)
3424 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
3426 else if (aChangeSet->ToSetLineWidth == -1)
3428 aCtx->UnsetWidth (aPrs, Standard_False);
3430 else if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3432 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
3433 toRedisplay = Standard_True;
3435 else if (aChangeSet->ToSetSensitivity != 0)
3437 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3439 if (!aDrawer.IsNull())
3441 toRedisplay = aChangeSet->Apply (aDrawer) || toRedisplay;
3444 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
3446 aChangeSet = &aChangesIter.ChangeValue();
3447 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
3448 aSubShapeIter.More(); aSubShapeIter.Next())
3450 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
3451 if (!aChangeSet->IsEmpty())
3453 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3454 aChangeSet->Apply (aCurColDrawer);
3456 if (aChangeSet->ToSetVisibility == 1)
3458 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3459 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
3461 if (aChangeSet->ToSetColor == 1)
3463 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
3465 if (aChangeSet->ToSetTransparency == 1)
3467 aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency);
3469 if (aChangeSet->ToSetLineWidth == 1)
3471 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
3473 if (aChangeSet->ToSetColor == -1
3474 || aChangeSet->ToSetLineWidth == -1)
3476 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
3478 if (aChangeSet->ToSetSensitivity != 0)
3480 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3486 aCtx->Display (aPrs, Standard_False);
3490 aCtx->Redisplay (aPrs, Standard_False);
3492 else if (!aColoredPrs.IsNull())
3494 aCtx->Redisplay (aColoredPrs, Standard_False);
3498 aPrs->SynchronizeAspects();
3503 Standard_SStream aStream;
3504 aDrawer->DumpJson (aStream);
3506 theDI << aName << ": \n";
3507 theDI << Standard_Dump::FormatJson (aStream);
3515 //==============================================================================
3516 //function : VDonly2
3518 //purpose : Display only a selected or named object
3519 // if there is no selected or named object s, nothing is done
3520 //==============================================================================
3521 static int VDonly2 (Draw_Interpretor& ,
3522 Standard_Integer theArgNb,
3523 const char** theArgVec)
3525 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3526 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3529 Message::SendFail ("Error: no active view!");
3533 Standard_Integer anArgIter = 1;
3534 for (; anArgIter < theArgNb; ++anArgIter)
3536 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3542 NCollection_Map<Handle(Standard_Transient)> aDispSet;
3543 if (anArgIter >= theArgNb)
3545 // display only selected objects
3546 if (aCtx->NbSelected() < 1)
3551 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3553 aDispSet.Add (aCtx->SelectedInteractive());
3558 // display only specified objects
3559 for (; anArgIter < theArgNb; ++anArgIter)
3561 TCollection_AsciiString aName = theArgVec[anArgIter];
3562 Handle(AIS_InteractiveObject) aShape;
3563 if (GetMapOfAIS().Find2 (aName, aShape)
3564 && !aShape.IsNull())
3566 aCtx->Display (aShape, Standard_False);
3567 aDispSet.Add (aShape);
3572 // weed out other objects
3573 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
3575 if (aDispSet.Contains (anIter.Key1()))
3580 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
3582 aCtx->Erase (aShape, Standard_False);
3588 //==============================================================================
3589 //function : VRemove
3590 //purpose : Removes selected or named objects.
3591 // If there is no selected or named objects,
3592 // all objects in the viewer can be removed with argument -all.
3593 // If -context is in arguments, the object is not deleted from the map of
3594 // objects (deleted only from the current context).
3595 //==============================================================================
3596 int VRemove (Draw_Interpretor& theDI,
3597 Standard_Integer theArgNb,
3598 const char** theArgVec)
3600 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3601 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3604 Message::SendFail ("Error: no active view!");
3608 Standard_Boolean isContextOnly = Standard_False;
3609 Standard_Boolean toRemoveAll = Standard_False;
3610 Standard_Boolean toPrintInfo = Standard_True;
3611 Standard_Boolean toFailOnError = Standard_True;
3613 Standard_Integer anArgIter = 1;
3614 for (; anArgIter < theArgNb; ++anArgIter)
3616 TCollection_AsciiString anArg = theArgVec[anArgIter];
3618 if (anArg == "-context")
3620 isContextOnly = Standard_True;
3622 else if (anArg == "-all")
3624 toRemoveAll = Standard_True;
3626 else if (anArg == "-noinfo")
3628 toPrintInfo = Standard_False;
3630 else if (anArg == "-noerror"
3631 || anArg == "-nofail")
3633 toFailOnError = Standard_False;
3635 else if (anUpdateTool.parseRedrawMode (anArg))
3645 && anArgIter < theArgNb)
3647 Message::SendFail ("Error: wrong syntax!");
3651 NCollection_List<TCollection_AsciiString> anIONameList;
3654 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3655 anIter.More(); anIter.Next())
3657 anIONameList.Append (anIter.Key2());
3660 else if (anArgIter < theArgNb) // removed objects names are in argument list
3662 for (; anArgIter < theArgNb; ++anArgIter)
3664 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3665 if (aName.Search ("*") != -1)
3667 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
3669 if (aPrsIter.Key1()->GetContext() != aCtx)
3673 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
3674 if (theDI.Eval (aCheck.ToCString()) == 0
3675 && *theDI.Result() == '1')
3677 anIONameList.Append (aPrsIter.Key2());
3684 Handle(AIS_InteractiveObject) anIO;
3685 if (!GetMapOfAIS().Find2 (aName, anIO))
3689 Message::SendFail() << "Syntax error: '" << aName << "' was not bound to some object.";
3693 else if (anIO->GetContext() != aCtx)
3697 Message::SendFail() << "Syntax error: '" << aName << "' was not displayed in current context.\n"
3698 << "Please activate view with this object displayed and try again.";
3704 anIONameList.Append (aName);
3708 else if (aCtx->NbSelected() > 0)
3710 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3711 anIter.More(); anIter.Next())
3713 if (!aCtx->IsSelected (anIter.Key1()))
3718 anIONameList.Append (anIter.Key2());
3723 // Unbind all removed objects from the map of displayed IO.
3724 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3725 anIter.More(); anIter.Next())
3727 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
3728 aCtx->Remove (anIO, Standard_False);
3731 theDI << anIter.Value() << " ";
3735 GetMapOfAIS().UnBind2 (anIter.Value());
3741 //==============================================================================
3743 //purpose : Erase some selected or named objects
3744 // if there is no selected or named objects, the whole viewer is erased
3745 //==============================================================================
3746 int VErase (Draw_Interpretor& theDI,
3747 Standard_Integer theArgNb,
3748 const char** theArgVec)
3750 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3751 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3752 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3755 Message::SendFail ("Error: no active view!");
3759 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3761 Standard_Integer anArgIter = 1;
3762 Standard_Boolean toEraseInView = Standard_False;
3763 Standard_Boolean toFailOnError = Standard_True;
3764 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3765 for (; anArgIter < theArgNb; ++anArgIter)
3767 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3768 anArgCase.LowerCase();
3769 if (anUpdateTool.parseRedrawMode (anArgCase))
3773 else if (anArgCase == "-view"
3774 || anArgCase == "-inview")
3776 toEraseInView = Standard_True;
3778 else if (anArgCase == "-noerror"
3779 || anArgCase == "-nofail")
3781 toFailOnError = Standard_False;
3785 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3789 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3791 Message::SendFail() << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.";
3795 if (!aNamesOfEraseIO.IsEmpty())
3797 // Erase named objects
3798 NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString> aPrsList;
3799 for (TColStd_SequenceOfAsciiString::Iterator anIter (aNamesOfEraseIO); anIter.More(); anIter.Next())
3801 const TCollection_AsciiString& aName = anIter.Value();
3802 if (aName.Search ("*") != -1)
3804 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
3806 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
3807 if (theDI.Eval (aCheck.ToCString()) == 0
3808 && *theDI.Result() == '1')
3810 aPrsList.Add (aPrsIter.Key1(), aPrsIter.Key2());
3817 Handle(AIS_InteractiveObject) anIO;
3818 if (!GetMapOfAIS().Find2 (aName, anIO))
3822 Message::SendFail() << "Syntax error: '" << aName << "' is not found";
3828 aPrsList.Add (anIO, aName);
3833 for (NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString>::Iterator anIter (aPrsList); anIter.More(); anIter.Next())
3835 theDI << anIter.Value() << " ";
3838 aCtx->SetViewAffinity (anIter.Key(), aView, Standard_False);
3842 aCtx->Erase (anIter.Key(), Standard_False);
3846 else if (!toEraseAll && aCtx->NbSelected() > 0)
3848 // Erase selected objects
3849 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3850 anIter.More(); anIter.Next())
3852 const Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3854 && aCtx->IsSelected (anIO))
3856 theDI << anIter.Key2() << " ";
3859 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3866 aCtx->EraseSelected (Standard_False);
3871 // Erase all objects
3872 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3873 anIter.More(); anIter.Next())
3875 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3880 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3884 aCtx->Erase (anIO, Standard_False);
3893 //==============================================================================
3894 //function : VDisplayAll
3895 //purpose : Display all the objects of the Map
3896 //==============================================================================
3897 static int VDisplayAll (Draw_Interpretor& ,
3898 Standard_Integer theArgNb,
3899 const char** theArgVec)
3902 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3903 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3906 Message::SendFail ("Error: no active view!");
3910 Standard_Integer anArgIter = 1;
3911 for (; anArgIter < theArgNb; ++anArgIter)
3913 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3914 anArgCase.LowerCase();
3915 if (anUpdateTool.parseRedrawMode (anArgCase))
3924 if (anArgIter < theArgNb)
3926 Message::SendFail() << theArgVec[0] << "Error: wrong syntax";
3930 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3931 anIter.More(); anIter.Next())
3933 aCtx->Erase (anIter.Key1(), Standard_False);
3936 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3937 anIter.More(); anIter.Next())
3939 aCtx->Display (anIter.Key1(), Standard_False);
3944 //! Auxiliary method to check if presentation exists
3945 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3946 const Handle(AIS_InteractiveObject)& theIO,
3947 const Standard_Integer theMode)
3949 if (theIO.IsNull() || theCtx.IsNull())
3956 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3961 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3963 return theIO->DisplayMode();
3965 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3967 return theCtx->DisplayMode();
3973 enum ViewerTest_BndAction
3980 //! Auxiliary method to print bounding box of presentation
3981 inline void bndPresentation (Draw_Interpretor& theDI,
3982 const Handle(PrsMgr_PresentationManager)& theMgr,
3983 const Handle(AIS_InteractiveObject)& theObj,
3984 const Standard_Integer theDispMode,
3985 const TCollection_AsciiString& theName,
3986 const ViewerTest_BndAction theAction,
3987 const Handle(Prs3d_Drawer)& theStyle)
3991 case BndAction_Hide:
3993 theMgr->Unhighlight (theObj);
3996 case BndAction_Show:
3998 theMgr->Color (theObj, theStyle, theDispMode);
4001 case BndAction_Print:
4004 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
4006 if (aPrsIter.Value()->Mode() != theDispMode)
4009 aBox = aPrsIter.Value()->MinMaxValues();
4011 gp_Pnt aMin = aBox.CornerMin();
4012 gp_Pnt aMax = aBox.CornerMax();
4013 theDI << theName << "\n"
4014 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
4015 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
4021 //==============================================================================
4022 //function : VBounding
4024 //==============================================================================
4025 int VBounding (Draw_Interpretor& theDI,
4026 Standard_Integer theArgNb,
4027 const char** theArgVec)
4029 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4030 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4033 Message::SendFail ("Error: no active view!");
4037 ViewerTest_BndAction anAction = BndAction_Show;
4038 Standard_Integer aMode = -1;
4040 Handle(Prs3d_Drawer) aStyle;
4042 Standard_Integer anArgIter = 1;
4043 for (; anArgIter < theArgNb; ++anArgIter)
4045 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4047 if (anArg == "-print")
4049 anAction = BndAction_Print;
4051 else if (anArg == "-show")
4053 anAction = BndAction_Show;
4055 else if (anArg == "-hide")
4057 anAction = BndAction_Hide;
4059 else if (anArg == "-mode")
4061 if (++anArgIter >= theArgNb)
4063 Message::SendFail() << "Error: wrong syntax at " << anArg;
4066 aMode = Draw::Atoi (theArgVec[anArgIter]);
4068 else if (!anUpdateTool.parseRedrawMode (anArg))
4074 if (anAction == BndAction_Show)
4076 aStyle = new Prs3d_Drawer();
4077 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
4078 aStyle->SetColor (Quantity_NOC_GRAY99);
4081 Standard_Integer aHighlightedMode = -1;
4082 if (anArgIter < theArgNb)
4084 // has a list of names
4085 for (; anArgIter < theArgNb; ++anArgIter)
4087 TCollection_AsciiString aName = theArgVec[anArgIter];
4088 Handle(AIS_InteractiveObject) anIO;
4089 if (!GetMapOfAIS().Find2 (aName, anIO))
4091 Message::SendFail() << "Error: presentation " << aName << " does not exist";
4095 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4096 if (aHighlightedMode == -1)
4098 Message::SendFail() << "Error: object " << aName << " has no presentation with mode " << aMode;
4101 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
4104 else if (aCtx->NbSelected() > 0)
4106 // remove all currently selected objects
4107 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4109 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
4110 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4111 if (aHighlightedMode != -1)
4113 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
4114 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
4121 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
4122 anIter.More(); anIter.Next())
4124 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
4125 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4126 if (aHighlightedMode != -1)
4128 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
4135 //==============================================================================
4136 //function : VTexture
4138 //==============================================================================
4139 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4141 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4144 Message::SendFail() << "Error: no active view!";
4148 int toModulate = -1;
4150 bool toSetFilter = false;
4151 bool toSetAniso = false;
4152 bool toSetTrsfAngle = false;
4153 bool toSetTrsfTrans = false;
4154 bool toSetTrsfScale = false;
4155 Standard_ShortReal aTrsfRotAngle = 0.0f;
4156 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
4157 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
4158 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
4159 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
4161 Handle(AIS_InteractiveObject) aTexturedIO;
4162 Handle(AIS_Shape) aTexturedShape;
4163 Handle(Graphic3d_TextureSet) aTextureSetOld;
4164 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
4165 bool toSetGenRepeat = false;
4166 bool toSetGenScale = false;
4167 bool toSetGenOrigin = false;
4168 bool toSetImage = false;
4169 bool toComputeUV = false;
4171 const TCollection_AsciiString aCommandName (theArgVec[0]);
4172 bool toSetDefaults = aCommandName == "vtexdefault";
4174 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4175 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
4177 const TCollection_AsciiString aName = theArgVec[anArgIter];
4178 TCollection_AsciiString aNameCase = aName;
4179 aNameCase.LowerCase();
4180 if (anUpdateTool.parseRedrawMode (aName))
4184 else if (aTexturedIO.IsNull())
4186 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
4187 if (aMapOfIO.IsBound2 (aName))
4189 aTexturedIO = aMapOfIO.Find2 (aName);
4190 aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO);
4192 if (aTexturedIO.IsNull())
4194 Message::SendFail() << "Syntax error: shape " << aName << " does not exists in the viewer.";
4198 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
4200 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
4203 else if (!aTexturedShape.IsNull()
4204 && (aNameCase == "-scale"
4205 || aNameCase == "-setscale"
4206 || aCommandName == "vtexscale"))
4208 if (aCommandName != "vtexscale")
4212 if (anArgIter < theArgsNb)
4214 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4215 TCollection_AsciiString aValUCase = aValU;
4216 aValUCase.LowerCase();
4217 toSetGenScale = true;
4218 if (aValUCase == "off")
4220 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4223 else if (anArgIter + 1 < theArgsNb)
4225 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4226 if (aValU.IsRealValue (Standard_True)
4227 && aValV.IsRealValue (Standard_True))
4229 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4235 Message::SendFail() << "Syntax error: unexpected argument '" << aName << "'";
4238 else if (!aTexturedShape.IsNull()
4239 && (aNameCase == "-origin"
4240 || aNameCase == "-setorigin"
4241 || aCommandName == "vtexorigin"))
4243 if (aCommandName != "vtexorigin")
4247 if (anArgIter < theArgsNb)
4249 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4250 TCollection_AsciiString aValUCase = aValU;
4251 aValUCase.LowerCase();
4252 toSetGenOrigin = true;
4253 if (aValUCase == "off")
4255 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4258 else if (anArgIter + 1 < theArgsNb)
4260 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4261 if (aValU.IsRealValue (Standard_True)
4262 && aValV.IsRealValue (Standard_True))
4264 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4270 Message::SendFail() << "Syntax error: unexpected argument '" << aName << "'";
4273 else if (!aTexturedShape.IsNull()
4274 && (aNameCase == "-repeat"
4275 || aNameCase == "-setrepeat"
4276 || aCommandName == "vtexrepeat"))
4278 if (aCommandName != "vtexrepeat")
4282 if (anArgIter < theArgsNb)
4284 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4285 TCollection_AsciiString aValUCase = aValU;
4286 aValUCase.LowerCase();
4287 toSetGenRepeat = true;
4288 if (aValUCase == "off")
4290 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4293 else if (anArgIter + 1 < theArgsNb)
4295 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4296 if (aValU.IsRealValue (Standard_True)
4297 && aValV.IsRealValue (Standard_True))
4299 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4305 Message::SendFail() << "Syntax error: unexpected argument '" << aName << "'";
4308 else if (aNameCase == "-modulate"
4309 || aNameCase == "-nomodulate")
4311 toModulate = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0;
4313 else if (aNameCase == "-srgb"
4314 || aNameCase == "-nosrgb")
4316 toSetSRgb = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0;
4318 else if ((aNameCase == "-setfilter"
4319 || aNameCase == "-filter")
4320 && anArgIter + 1 < theArgsNb)
4322 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4326 if (aValue == "nearest")
4328 aFilter = Graphic3d_TOTF_NEAREST;
4330 else if (aValue == "bilinear")
4332 aFilter = Graphic3d_TOTF_BILINEAR;
4334 else if (aValue == "trilinear")
4336 aFilter = Graphic3d_TOTF_TRILINEAR;
4340 Message::SendFail() << "Syntax error: unexpected argument '" << aValue << "'";
4344 else if ((aNameCase == "-setaniso"
4345 || aNameCase == "-setanisofilter"
4346 || aNameCase == "-aniso"
4347 || aNameCase == "-anisofilter")
4348 && anArgIter + 1 < theArgsNb)
4350 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4354 if (aValue == "off")
4356 anAnisoFilter = Graphic3d_LOTA_OFF;
4358 else if (aValue == "fast")
4360 anAnisoFilter = Graphic3d_LOTA_FAST;
4362 else if (aValue == "middle")
4364 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
4366 else if (aValue == "quality"
4367 || aValue == "high")
4369 anAnisoFilter = Graphic3d_LOTA_QUALITY;
4373 Message::SendFail() << "Syntax error: unexpected argument '" << aValue << "'";
4377 else if ((aNameCase == "-rotateangle"
4378 || aNameCase == "-rotangle"
4379 || aNameCase == "-rotate"
4380 || aNameCase == "-angle"
4381 || aNameCase == "-trsfangle")
4382 && anArgIter + 1 < theArgsNb)
4384 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4385 toSetTrsfAngle = true;
4388 else if ((aNameCase == "-trsftrans"
4389 || aNameCase == "-trsftranslate"
4390 || aNameCase == "-translate"
4391 || aNameCase == "-translation")
4392 && anArgIter + 2 < theArgsNb)
4394 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4395 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4396 toSetTrsfTrans = true;
4399 else if ((aNameCase == "-trsfscale")
4400 && anArgIter + 2 < theArgsNb)
4402 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4403 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4404 toSetTrsfScale = true;
4407 else if (aNameCase == "-default"
4408 || aNameCase == "-defaults")
4410 toSetDefaults = true;
4412 else if ((aNameCase == "-video")
4413 && anArgIter + 1 < theArgsNb)
4415 const TCollection_AsciiString anInput (theArgVec[++anArgIter]);
4416 Handle(Graphic3d_MediaTextureSet) aMedia = Handle(Graphic3d_MediaTextureSet)::DownCast (aTextureSetOld);
4417 if (aMedia.IsNull())
4419 aMedia = new Graphic3d_MediaTextureSet();
4421 if (aMedia->Input() != anInput)
4423 aMedia->OpenInput (anInput, false);
4427 if (aMedia->SwapFrames()
4428 && !aCtx->CurrentViewer()->ZLayerSettings (aTexturedIO->ZLayer()).IsImmediate())
4430 ViewerTest::CurrentView()->Invalidate();
4433 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4434 && aTexturedShape.IsNull())
4436 aTexturedIO->SetToUpdate();
4439 toComputeUV = aTextureSetOld.IsNull();
4440 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (true);
4441 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia);
4442 aTextureSetOld.Nullify();
4444 else if (aCommandName == "vtexture"
4445 && (aTextureVecNew.IsEmpty()
4446 || aNameCase.StartsWith ("-tex")))
4448 Standard_Integer aTexIndex = 0;
4449 TCollection_AsciiString aTexName = aName;
4450 if (aNameCase.StartsWith ("-tex"))
4452 if (anArgIter + 1 >= theArgsNb
4453 || aNameCase.Length() < 5)
4455 Message::SendFail() << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'";
4459 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
4460 if (!aTexIndexStr.IsIntegerValue())
4462 Message::SendFail() << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'";
4466 aTexIndex = aTexIndexStr.IntegerValue();
4467 aTexName = theArgVec[anArgIter + 1];
4470 if (aTexIndex >= Graphic3d_TextureUnit_NB
4471 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
4473 Message::SendFail ("Error: too many textures specified");
4478 if (aTexName.IsIntegerValue())
4480 const Standard_Integer aValue = aTexName.IntegerValue();
4481 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
4483 Message::SendFail() << "Syntax error: texture with ID " << aValue << " is undefined!";
4486 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
4488 else if (aTexName == "?")
4490 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
4492 theDi << "\n Files in current directory : \n\n";
4493 theDi.Eval ("glob -nocomplain *");
4495 TCollection_AsciiString aCmnd ("glob -nocomplain ");
4496 aCmnd += aTextureFolder;
4499 theDi << "Files in " << aTextureFolder << " : \n\n";
4500 theDi.Eval (aCmnd.ToCString());
4503 else if (aTexName != "off")
4505 if (!OSD_File (aTexName).Exists())
4507 Message::SendFail() << "Syntax error: non-existing image file has been specified '" << aTexName << "'.";
4510 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
4514 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
4517 if (aTextureVecNew.Value (aTexIndex))
4519 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
4524 Message::SendFail() << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'";
4531 // check if new image set is equal to already set one
4532 Standard_Integer aNbChanged = 0;
4533 Handle(Graphic3d_TextureSet) aTextureSetNew;
4534 if (!aTextureVecNew.IsEmpty())
4536 aNbChanged = aTextureVecNew.Size();
4537 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
4538 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
4540 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
4541 Handle(Graphic3d_TextureRoot) aTextureOld;
4542 if (!aTextureSetOld.IsNull()
4543 && aTexIter < aTextureSetOld->Size())
4545 aTextureOld = aTextureSetOld->Value (aTexIter);
4548 if (!aTextureOld.IsNull()
4549 && !aTextureNew.IsNull())
4551 *aTextureNew->GetParams() = *aTextureOld->GetParams();
4552 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
4554 TCollection_AsciiString aFilePathOld, aFilePathNew;
4555 aTextureOld->Path().SystemName (aFilePathOld);
4556 aTextureNew->Path().SystemName (aFilePathNew);
4557 if (aTextureNew->Name() == anOldManualTex->Name()
4558 && aFilePathOld == aFilePathNew
4559 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
4562 aTextureNew = anOldManualTex;
4566 aTextureSetNew->SetValue (aTexIter, aTextureNew);
4570 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
4571 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
4573 aTextureSetNew = aTextureSetOld;
4576 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4577 && aTexturedShape.IsNull())
4579 aTexturedIO->SetToUpdate();
4582 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
4583 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
4584 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
4585 aTextureSetOld.Nullify();
4590 if (toModulate != -1)
4597 aFilter = Graphic3d_TOTF_BILINEAR;
4602 anAnisoFilter = Graphic3d_LOTA_OFF;
4604 if (!toSetTrsfAngle)
4606 toSetTrsfAngle = true;
4607 aTrsfRotAngle = 0.0f;
4609 if (!toSetTrsfTrans)
4611 toSetTrsfTrans = true;
4612 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
4614 if (!toSetTrsfScale)
4616 toSetTrsfScale = true;
4617 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
4621 if (aCommandName == "vtexture"
4624 if (!aTextureSetOld.IsNull())
4626 //toComputeUV = true; // we can keep UV vertex attributes
4627 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
4628 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
4629 aTextureSetOld.Nullify();
4633 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
4634 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
4636 if (toModulate != -1)
4638 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
4640 if (toSetSRgb != -1)
4642 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->SetColorMap (toSetSRgb == 1);
4646 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
4650 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
4654 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
4658 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
4662 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
4666 // set default values if requested
4668 && (aCommandName == "vtexrepeat"
4671 if (!aTexturedShape.IsNull())
4673 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4675 toSetGenRepeat = true;
4678 && (aCommandName == "vtexorigin"
4681 if (!aTexturedShape.IsNull())
4683 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4685 toSetGenOrigin = true;
4688 && (aCommandName == "vtexscale"
4691 if (!aTexturedShape.IsNull())
4693 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4695 toSetGenScale = true;
4698 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
4700 if (!aTexturedShape.IsNull())
4702 aTexturedShape->SetToUpdate (AIS_Shaded);
4705 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
4706 || aCtx->DisplayMode() != AIS_Shaded)
4708 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
4713 aCtx->Display (aTexturedIO, false);
4714 aTexturedIO->SynchronizeAspects();
4718 //! Auxiliary method to parse transformation persistence flags
4719 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
4720 Graphic3d_TransModeFlags& theFlags)
4722 if (theFlagString == "zoom")
4724 theFlags = Graphic3d_TMF_ZoomPers;
4726 else if (theFlagString == "rotate")
4728 theFlags = Graphic3d_TMF_RotatePers;
4730 else if (theFlagString == "zoomrotate")
4732 theFlags = Graphic3d_TMF_ZoomRotatePers;
4734 else if (theFlagString == "trihedron"
4735 || theFlagString == "triedron")
4737 theFlags = Graphic3d_TMF_TriedronPers;
4739 else if (theFlagString == "none")
4741 theFlags = Graphic3d_TMF_None;
4745 return Standard_False;
4748 return Standard_True;
4751 //! Auxiliary method to parse transformation persistence flags
4752 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4753 Aspect_TypeOfTriedronPosition& theCorner)
4755 TCollection_AsciiString aString (theString);
4756 aString.LowerCase();
4757 if (aString == "center")
4759 theCorner = Aspect_TOTP_CENTER;
4761 else if (aString == "top"
4762 || aString == "upper")
4764 theCorner = Aspect_TOTP_TOP;
4766 else if (aString == "bottom"
4767 || aString == "lower")
4769 theCorner = Aspect_TOTP_BOTTOM;
4771 else if (aString == "left")
4773 theCorner = Aspect_TOTP_LEFT;
4775 else if (aString == "right")
4777 theCorner = Aspect_TOTP_RIGHT;
4779 else if (aString == "topleft"
4780 || aString == "leftupper"
4781 || aString == "upperleft")
4783 theCorner = Aspect_TOTP_LEFT_UPPER;
4785 else if (aString == "bottomleft"
4786 || aString == "leftlower"
4787 || aString == "lowerleft")
4789 theCorner = Aspect_TOTP_LEFT_LOWER;
4791 else if (aString == "topright"
4792 || aString == "rightupper"
4793 || aString == "upperright")
4795 theCorner = Aspect_TOTP_RIGHT_UPPER;
4797 else if (aString == "bottomright"
4798 || aString == "lowerright"
4799 || aString == "rightlower")
4801 theCorner = Aspect_TOTP_RIGHT_LOWER;
4805 return Standard_False;
4808 return Standard_True;
4811 //==============================================================================
4812 //function : VDisplay2
4814 //purpose : Display an object from its name
4815 //==============================================================================
4816 static int VDisplay2 (Draw_Interpretor& theDI,
4817 Standard_Integer theArgNb,
4818 const char** theArgVec)
4822 Message::SendFail ("Syntax error: wrong number of arguments.");
4826 && TCollection_AsciiString (theArgVec[1]) == "*")
4829 return VDisplayAll (theDI, 1, theArgVec);
4832 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4835 ViewerTest::ViewerInit();
4836 aCtx = ViewerTest::GetAISContext();
4839 // Parse input arguments
4840 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4841 Standard_Integer isMutable = -1;
4842 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4843 Standard_Boolean toReDisplay = Standard_False;
4844 Standard_Integer isSelectable = -1;
4845 Standard_Integer anObjDispMode = -2;
4846 Standard_Integer anObjHighMode = -2;
4847 Standard_Boolean toSetTrsfPers = Standard_False;
4848 Standard_Boolean toEcho = Standard_True;
4849 Standard_Integer isAutoTriang = -1;
4850 Handle(Graphic3d_TransformPers) aTrsfPers;
4851 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4852 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4853 Standard_Integer toDisplayInView = Standard_False;
4854 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4856 const TCollection_AsciiString aName = theArgVec[anArgIter];
4857 TCollection_AsciiString aNameCase = aName;
4858 aNameCase.LowerCase();
4859 if (anUpdateTool.parseRedrawMode (aName))
4863 else if (aNameCase == "-mutable")
4867 else if (aNameCase == "-neutral")
4869 aDispStatus = AIS_DS_Displayed;
4871 else if (aNameCase == "-immediate"
4872 || aNameCase == "-top")
4874 aZLayer = Graphic3d_ZLayerId_Top;
4876 else if (aNameCase == "-topmost")
4878 aZLayer = Graphic3d_ZLayerId_Topmost;
4880 else if (aNameCase == "-osd"
4881 || aNameCase == "-toposd"
4882 || aNameCase == "-overlay")
4884 aZLayer = Graphic3d_ZLayerId_TopOSD;
4886 else if (aNameCase == "-botosd"
4887 || aNameCase == "-underlay")
4889 aZLayer = Graphic3d_ZLayerId_BotOSD;
4891 else if (aNameCase == "-select"
4892 || aNameCase == "-selectable")
4896 else if (aNameCase == "-noselect"
4897 || aNameCase == "-noselection")
4901 else if (aNameCase == "-dispmode"
4902 || aNameCase == "-displaymode")
4904 if (++anArgIter >= theArgNb)
4906 Message::SendFail() << "Error: wrong syntax at " << aName << ".";
4910 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4912 else if (aNameCase == "-himode"
4913 || aNameCase == "-highmode"
4914 || aNameCase == "-highlightmode")
4916 if (++anArgIter >= theArgNb)
4918 Message::SendFail() << "Error: wrong syntax at " << aName << ".";
4922 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4924 else if (aNameCase == "-3d")
4926 toSetTrsfPers = Standard_True;
4927 aTrsfPers.Nullify();
4929 else if (aNameCase == "-2d"
4930 || aNameCase == "-trihedron"
4931 || aNameCase == "-triedron")
4933 toSetTrsfPers = Standard_True;
4934 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4936 if (anArgIter + 1 < theArgNb)
4938 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4939 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4942 aTrsfPers->SetCorner2d (aCorner);
4944 if (anArgIter + 2 < theArgNb)
4946 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4947 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4948 if (anX.IsIntegerValue()
4949 && anY.IsIntegerValue())
4952 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4958 else if (aNameCase == "-trsfpers"
4959 || aNameCase == "-pers")
4961 if (++anArgIter >= theArgNb
4962 || !aTrsfPers.IsNull())
4964 Message::SendFail() << "Error: wrong syntax at " << aName << ".";
4968 toSetTrsfPers = Standard_True;
4969 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4970 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4971 aPersFlags.LowerCase();
4972 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
4974 Message::SendFail() << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".";
4978 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4980 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4982 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4984 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
4987 else if (aNameCase == "-trsfperspos"
4988 || aNameCase == "-perspos")
4990 if (anArgIter + 2 >= theArgNb
4991 || aTrsfPers.IsNull())
4993 Message::SendFail() << "Error: wrong syntax at " << aName << ".";
4997 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4998 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4999 TCollection_AsciiString aZ = "0";
5000 if (!aX.IsRealValue (Standard_True)
5001 || !aY.IsRealValue (Standard_True))
5003 Message::SendFail() << "Error: wrong syntax at " << aName << ".";
5006 if (anArgIter + 1 < theArgNb)
5008 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
5009 if (aTemp.IsRealValue (Standard_True))
5016 if (aTrsfPers->IsZoomOrRotate())
5018 aTrsfPers->SetAnchorPoint (gp_Pnt (aX.RealValue(), aY.RealValue(), aZ.RealValue()));
5020 else if (aTrsfPers->IsTrihedronOr2d())
5022 Standard_Integer aCorner = Aspect_TOTP_CENTER;
5023 if (aX.RealValue() > 0.0) { aCorner |= Aspect_TOTP_RIGHT; }
5024 else if (aX.RealValue() < 0.0) { aCorner |= Aspect_TOTP_LEFT; }
5025 if (aY.RealValue() > 0.0) { aCorner |= Aspect_TOTP_TOP; }
5026 else if (aY.RealValue() < 0.0) { aCorner |= Aspect_TOTP_BOTTOM; }
5027 aTrsfPers = new Graphic3d_TransformPers (aTrsfPers->Mode(), Aspect_TypeOfTriedronPosition (aCorner), Graphic3d_Vec2i (aZ.IntegerValue()));
5030 else if (aNameCase == "-layer"
5031 || aNameCase == "-zlayer")
5034 if (anArgIter >= theArgNb
5035 || !ViewerTest::ParseZLayer (theArgVec[anArgIter], aZLayer)
5036 || aZLayer == Graphic3d_ZLayerId_UNKNOWN)
5038 Message::SendFail() << "Error: wrong syntax at " << aName << ".";
5042 else if (aNameCase == "-view"
5043 || aNameCase == "-inview")
5045 toDisplayInView = Standard_True;
5047 else if (aNameCase == "-redisplay")
5049 toReDisplay = Standard_True;
5051 else if (aNameCase == "-autotr"
5052 || aNameCase == "-autotrian"
5053 || aNameCase == "-autotriang"
5054 || aNameCase == "-autotriangulation"
5055 || aNameCase == "-noautotr"
5056 || aNameCase == "-noautotrian"
5057 || aNameCase == "-noautotriang"
5058 || aNameCase == "-noautotriangulation")
5060 isAutoTriang = Draw::ParseOnOffNoIterator (theArgNb, theArgVec, anArgIter) ? 1 : 0;
5062 else if (aNameCase == "-erased"
5063 || aNameCase == "-load")
5065 aDispStatus = AIS_DS_Erased;
5067 else if (aNameCase == "-noecho")
5073 aNamesOfDisplayIO.Append (aName);
5077 if (aNamesOfDisplayIO.IsEmpty())
5079 Message::SendFail ("Syntax error: wrong number of arguments.");
5083 // Display interactive objects
5084 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
5086 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value (anIter);
5087 Handle(AIS_InteractiveObject) aShape;
5088 if (!GetMapOfAIS().Find2 (aName, aShape))
5090 // create the AIS_Shape from a name
5091 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
5092 if (!aDrawShape.IsNull())
5094 aShape = new AIS_Shape (aDrawShape);
5095 if (isMutable != -1)
5097 aShape->SetMutable (isMutable == 1);
5099 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
5101 aShape->SetZLayer (aZLayer);
5103 if (isAutoTriang != -1)
5105 aShape->Attributes()->SetAutoTriangulation (isAutoTriang == 1);
5109 aCtx->SetTransformPersistence (aShape, aTrsfPers);
5111 if (anObjDispMode != -2)
5113 if (anObjDispMode == -1)
5115 aShape->UnsetDisplayMode();
5117 if (!aShape->AcceptDisplayMode (anObjDispMode))
5119 Message::SendFail() << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjDispMode << " display mode";
5124 aShape->SetDisplayMode (anObjDispMode);
5127 if (anObjHighMode != -2)
5129 if (anObjHighMode != -1
5130 && !aShape->AcceptDisplayMode (anObjHighMode))
5132 Message::SendFail() << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjHighMode << " display mode";
5135 aShape->SetHilightMode (anObjHighMode);
5138 GetMapOfAIS().Bind (aShape, aName);
5139 Standard_Integer aDispMode = aShape->HasDisplayMode()
5140 ? aShape->DisplayMode()
5141 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5142 ? aCtx->DisplayMode()
5144 Standard_Integer aSelMode = -1;
5145 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5147 aSelMode = aShape->GlobalSelectionMode();
5150 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5151 if (toDisplayInView)
5153 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
5155 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
5157 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5162 Message::SendFail() << "Error: object with name '" << aName << "' does not exist!";
5167 if (isMutable != -1)
5169 aShape->SetMutable (isMutable == 1);
5171 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
5173 aShape->SetZLayer (aZLayer);
5175 if (isAutoTriang != -1)
5177 aShape->Attributes()->SetAutoTriangulation (isAutoTriang == 1);
5181 aCtx->SetTransformPersistence (aShape, aTrsfPers);
5183 if (anObjDispMode != -2)
5185 aShape->SetDisplayMode (anObjDispMode);
5187 if (anObjHighMode != -2)
5189 aShape->SetHilightMode (anObjHighMode);
5191 Standard_Integer aDispMode = aShape->HasDisplayMode()
5192 ? aShape->DisplayMode()
5193 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5194 ? aCtx->DisplayMode()
5196 Standard_Integer aSelMode = -1;
5197 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5199 aSelMode = aShape->GlobalSelectionMode();
5202 if (aShape->Type() == AIS_KindOfInteractive_Datum)
5204 aCtx->Display (aShape, Standard_False);
5210 theDI << "Display " << aName << "\n";
5213 // update the Shape in the AIS_Shape
5214 TopoDS_Shape aNewShape = DBRep::GetExisting (aName);
5215 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
5216 if (!aShapePrs.IsNull())
5218 if (!aShapePrs->Shape().IsEqual (aNewShape))
5220 toReDisplay = Standard_True;
5222 aShapePrs->Set (aNewShape);
5226 aCtx->Redisplay (aShape, Standard_False);
5231 aCtx->Erase (aShape, Standard_False);
5233 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5234 if (toDisplayInView)
5236 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5244 //=======================================================================
5245 //function : VNbDisplayed
5246 //purpose : Returns number of displayed objects
5247 //=======================================================================
5248 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
5249 Standard_Integer theArgsNb,
5250 const char** theArgVec)
5254 theDi << "Usage : " << theArgVec[0] << "\n";
5258 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5259 if (aContextAIS.IsNull())
5261 Message::SendFail ("Syntax error: AIS context is not available.");
5265 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5266 if(aContext.IsNull())
5268 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
5272 AIS_ListOfInteractive aListOfIO;
5273 aContextAIS->DisplayedObjects (aListOfIO);
5275 theDi << aListOfIO.Extent() << "\n";
5279 //===============================================================================================
5280 //function : VUpdate
5282 //===============================================================================================
5283 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
5285 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5286 if (aContextAIS.IsNull())
5288 Message::SendFail ("Syntax error: AIS context is not available.");
5294 Message::SendFail ("Syntax error: insufficient arguments. Type help for more information.");
5298 AIS_ListOfInteractive aListOfIO;
5299 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5301 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
5303 Handle(AIS_InteractiveObject) anAISObj;
5304 GetMapOfAIS().Find2 (aName, anAISObj);
5305 if (anAISObj.IsNull())
5307 Message::SendFail() << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".";
5311 aListOfIO.Append (anAISObj);
5314 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
5315 for (; anIOIt.More(); anIOIt.Next())
5317 aContextAIS->Update (anIOIt.Value(), Standard_False);
5320 aContextAIS->UpdateCurrentViewer();
5325 //==============================================================================
5326 //function : VShading
5327 //purpose : Sharpen or roughten the quality of the shading
5328 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
5329 //==============================================================================
5330 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
5332 Standard_Real myDevCoef;
5333 Handle(AIS_InteractiveObject) TheAisIO;
5336 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
5340 myDevCoef =Draw::Atof(argv[2]);
5343 TCollection_AsciiString name=argv[1];
5344 GetMapOfAIS().Find2(name, TheAisIO);
5345 if (TheAisIO.IsNull())
5347 TopoDS_Shape aDrawShape = DBRep::GetExisting (name);
5348 if (!aDrawShape.IsNull())
5350 TheAisIO = new AIS_Shape (aDrawShape);
5355 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5357 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
5359 TheAISContext()->Redisplay (TheAisIO, Standard_True);
5363 //! Auxiliary method to print Interactive Object information
5364 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
5365 const Handle(AIS_InteractiveObject)& theObj,
5366 Draw_Interpretor& theDI)
5368 if (theObj.IsNull())
5370 theDI << "NULL presentation\n";
5374 theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ")
5375 << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ")
5376 << (theDetected.Contains (theObj) ? " Detected" : " ")
5378 if (theObj->Type() == AIS_KindOfInteractive_Datum)
5381 if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
5382 else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; }
5383 else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; }
5384 else if (theObj->Signature() == 5) { theDI << " AIS_Line"; }
5385 else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; }
5386 else if (theObj->Signature() == 1) { theDI << " AIS_Point"; }
5387 else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
5390 else if (theObj->Type() == AIS_KindOfInteractive_Shape
5391 && theObj->Signature() == 0)
5393 theDI << " AIS_Shape";
5395 else if (theObj->Type() == AIS_KindOfInteractive_Relation)
5397 // PrsDim_Dimension and AIS_Relation
5398 Handle(PrsDim_Relation) aRelation = Handle(PrsDim_Relation)::DownCast (theObj);
5399 switch (aRelation->KindOfDimension())
5401 case PrsDim_KOD_PLANEANGLE: theDI << " PrsDim_AngleDimension"; break;
5402 case PrsDim_KOD_LENGTH: theDI << " PrsDim_Chamf2/3dDimension/PrsDim_LengthDimension"; break;
5403 case PrsDim_KOD_DIAMETER: theDI << " PrsDim_DiameterDimension"; break;
5404 case PrsDim_KOD_ELLIPSERADIUS: theDI << " PrsDim_EllipseRadiusDimension"; break;
5405 //case PrsDim_KOD_FILLETRADIUS: theDI << " PrsDim_FilletRadiusDimension "; break;
5406 case PrsDim_KOD_OFFSET: theDI << " PrsDim_OffsetDimension"; break;
5407 case PrsDim_KOD_RADIUS: theDI << " PrsDim_RadiusDimension"; break;
5408 default: theDI << " UNKNOWN dimension"; break;
5413 theDI << " UserPrs";
5415 theDI << " (" << theObj->DynamicType()->Name() << ")";
5418 //! Print information about locally selected sub-shapes
5419 template <typename T>
5420 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
5422 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
5423 TCollection_AsciiString aPrevName;
5424 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
5426 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
5427 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
5428 if (aShapeIO.IsNull() || anOwner.IsNull())
5432 if (anOwner == aShapeIO->GlobalSelOwner())
5435 const TopoDS_Shape aSubShape = theContext->SelectedShape();
5436 if (aSubShape.IsNull()
5437 || aShapeIO.IsNull()
5438 || !GetMapOfAIS().IsBound1 (aShapeIO))
5443 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
5444 TopTools_MapOfShape aFilter;
5445 Standard_Integer aNumber = 0;
5446 const TopoDS_Shape aShape = aShapeIO->Shape();
5447 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
5448 anIter.More(); anIter.Next())
5450 if (!aFilter.Add (anIter.Current()))
5452 continue; // filter duplicates
5456 if (!anIter.Current().IsSame (aSubShape))
5461 Standard_CString aShapeName = NULL;
5462 switch (aSubShape.ShapeType())
5464 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
5465 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
5466 case TopAbs_SOLID: aShapeName = " Solid"; break;
5467 case TopAbs_SHELL: aShapeName = " Shell"; break;
5468 case TopAbs_FACE: aShapeName = " Face"; break;
5469 case TopAbs_WIRE: aShapeName = " Wire"; break;
5470 case TopAbs_EDGE: aShapeName = " Edge"; break;
5471 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
5473 case TopAbs_SHAPE: aShapeName = " Shape"; break;
5476 if (aParentName != aPrevName)
5478 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
5479 aPrevName = aParentName;
5481 theDI << " " << aShapeName << " #" << aNumber << "\n";
5487 //==============================================================================
5490 //==============================================================================
5491 static Standard_Integer VState (Draw_Interpretor& theDI,
5492 Standard_Integer theArgNb,
5493 Standard_CString* theArgVec)
5495 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
5498 Message::SendFail ("Error: No opened viewer!");
5502 Standard_Boolean toPrintEntities = Standard_False;
5503 Standard_Boolean toCheckSelected = Standard_False;
5505 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
5507 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
5508 anOption.LowerCase();
5509 if (anOption == "-detectedentities"
5510 || anOption == "-entities")
5512 toPrintEntities = Standard_True;
5514 else if (anOption == "-hasselected")
5516 toCheckSelected = Standard_True;
5520 if (toCheckSelected)
5522 aCtx->InitSelected();
5523 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
5524 theDI << "Check if context has selected shape: " << hasSelected << "\n";
5529 if (toPrintEntities)
5531 theDI << "Detected entities:\n";
5532 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
5534 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
5535 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
5537 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
5538 const Handle(Select3D_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
5539 const Handle(SelectMgr_EntityOwner)& anOwner = anEntity->OwnerId();
5540 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5542 TCollection_AsciiString aName;
5543 GetMapOfAIS().Find1 (anObj, aName);
5544 aName.LeftJustify (20, ' ');
5545 char anInfoStr[512];
5546 if (aPickData.Normal.SquareModulus() > ShortRealEpsilon())
5549 " Depth: %g Distance: %g Point: %g %g %g Normal: %g %g %g",
5552 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z(),
5553 aPickData.Normal.x(), aPickData.Normal.y(), aPickData.Normal.z());
5558 " Depth: %g Distance: %g Point: %g %g %g",
5561 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
5563 theDI << " " << aName
5565 << " (" << anEntity->DynamicType()->Name() << ")"
5568 if (Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner))
5570 theDI << " Detected Shape: "
5571 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
5575 if (Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity))
5577 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
5578 theDI << " Detected Child: "
5579 << aSen->DynamicType()->Name()
5582 else if (Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity))
5584 theDI << " Detected Element: "
5585 << aPrimArr->LastDetectedElement()
5588 else if (Handle(Select3D_SensitiveTriangulation) aTriSens = Handle(Select3D_SensitiveTriangulation)::DownCast (anEntity))
5590 theDI << " Detected Triangle: "
5591 << aTriSens->LastDetectedTriangleIndex()
5598 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
5599 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
5601 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
5604 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
5608 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5610 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
5611 Handle(AIS_InteractiveObject) anObj;
5612 if (!GetMapOfAIS().Find2 (anObjName, anObj))
5614 theDI << anObjName << " doesn't exist!\n";
5618 TCollection_AsciiString aName = anObjName;
5619 aName.LeftJustify (20, ' ');
5620 theDI << " " << aName << " ";
5621 objInfo (aDetected, anObj, theDI);
5627 if (aCtx->NbSelected() > 0 && !toShowAll)
5629 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
5630 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
5632 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
5633 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5634 // handle whole object selection
5635 if (anOwner == anObj->GlobalSelOwner())
5637 TCollection_AsciiString aName;
5638 GetMapOfAIS().Find1 (anObj, aName);
5639 aName.LeftJustify (20, ' ');
5640 theDI << aName << " ";
5641 objInfo (aDetected, anObj, theDI);
5646 // process selected sub-shapes
5647 printLocalSelectionInfo (aCtx, theDI);
5652 theDI << "Neutral-point state:\n";
5653 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5654 anObjIter.More(); anObjIter.Next())
5656 if (anObjIter.Key1().IsNull())
5661 TCollection_AsciiString aName = anObjIter.Key2();
5662 aName.LeftJustify (20, ' ');
5663 theDI << " " << aName << " ";
5664 objInfo (aDetected, anObjIter.Key1(), theDI);
5667 printLocalSelectionInfo (aCtx, theDI);
5671 //=======================================================================
5672 //function : PickShape
5673 //purpose : First Activate the rightmode + Put Filters to be able to
5674 // pick objets that are of type <TheType>...
5675 //=======================================================================
5677 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
5678 const Standard_Integer theMaxPick)
5680 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
5681 PickShapes (theShapeType, aResArray, theMaxPick);
5682 return aResArray->First();
5685 //=======================================================================
5686 //function : PickShapes
5688 //=======================================================================
5689 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
5690 Handle(TopTools_HArray1OfShape)& theResArray,
5691 const Standard_Integer theMaxPick)
5693 const Standard_Integer aNbToReach = theResArray->Length();
5696 Message::SendWarning ("WARNING : Pick with Shift+ MB1 for Selection of more than 1 object");
5699 // step 1: prepare the data
5700 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5703 Message::SendFail ("Error: no active viewer");
5704 return Standard_False;
5707 aCtx->RemoveFilters();
5708 AIS_ListOfInteractive aDispObjects;
5709 aCtx->DisplayedObjects (aDispObjects);
5710 if (theShapeType == TopAbs_SHAPE)
5712 aCtx->AddFilter (new AIS_TypeFilter (AIS_KindOfInteractive_Shape));
5716 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
5719 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
5720 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5722 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5724 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5728 // step 2 : wait for the selection...
5729 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
5730 Standard_Integer argccc = 5;
5731 const char *bufff[] = { "A", "B", "C", "D", "E" };
5732 const char **argvvv = (const char** )bufff;
5733 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
5735 while (ViewerMainLoop (argccc, argvvv)) {}
5736 Standard_Integer aNbStored = aCtx->NbSelected();
5737 if (aNbStored != aNbPickGood)
5739 aNbPickGood = aNbStored;
5745 Message::SendInfo() << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail;
5748 // step3 get result.
5749 if (aNbPickFail >= aNbToReach)
5751 return Standard_False;
5754 Standard_Integer anIndex = theResArray->Lower();
5755 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
5757 if (aCtx->HasSelectedShape())
5759 theResArray->SetValue (anIndex, aCtx->SelectedShape());
5763 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
5764 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
5768 aCtx->RemoveFilters();
5769 if (theShapeType != TopAbs_SHAPE)
5771 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5773 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5775 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5779 return Standard_True;
5782 //=======================================================================
5783 //function : VPickShape
5785 //=======================================================================
5786 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5788 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
5791 TCollection_AsciiString aShapeArg (argv[1]);
5792 aShapeArg.LowerCase();
5793 aShapeType = TopAbs_COMPOUND;
5794 if (aShapeArg == "v"
5795 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
5796 else if (aShapeArg == "e"
5797 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
5798 else if (aShapeArg == "w"
5799 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
5800 else if (aShapeArg == "f"
5801 || aShapeArg == "face") aShapeType = TopAbs_FACE;
5802 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
5803 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
5804 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
5807 Message::SendFail() << "Syntax error at '" << argv[1] << "'";
5812 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5813 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
5815 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
5818 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
5819 if (aPickedShape.IsNull())
5824 TCollection_AsciiString aName;
5831 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5832 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5835 DBRep::Set (aName.ToCString(), aPickedShape);
5836 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5837 ViewerTest::Display (aName, aShapePrs, false, true);
5838 di << "Name of picked shape: " << aName <<"\n";
5842 TCollection_AsciiString aName (argv[2]);
5844 const Standard_Boolean isAutoNaming = aName == ".";
5845 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5846 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5848 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5850 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5852 if (!aPickedShape.IsNull()
5855 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5856 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5860 aName = argv[1 + aPickedIter];
5863 DBRep::Set (aName.ToCString(), aPickedShape);
5864 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5865 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5866 ViewerTest::Display (aName, aShapePrs, false, true);
5870 TheAISContext()->UpdateCurrentViewer();
5874 //=======================================================================
5875 //function : VSelFilter
5877 //=======================================================================
5878 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5879 const char** theArgv)
5881 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5882 if (aContext.IsNull())
5884 Message::SendFail ("Error: AIS context is not available.");
5888 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5890 TCollection_AsciiString anArg (theArgv[anArgIter]);
5892 if (anArg == "-clear")
5894 aContext->RemoveFilters();
5896 else if (anArg == "-contextfilter" && anArgIter + 1 < theArgc)
5898 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5902 aContext->SetFilterType (SelectMgr_FilterType_AND);
5904 else if (aVal == "or")
5906 aContext->SetFilterType (SelectMgr_FilterType_OR);
5910 Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'";
5914 else if (anArg == "-type"
5915 && anArgIter + 1 < theArgc)
5917 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5918 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5919 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5921 Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'";
5925 Handle(SelectMgr_Filter) aFilter;
5926 if (aShapeType == TopAbs_SHAPE)
5928 aFilter = new AIS_TypeFilter (AIS_KindOfInteractive_Shape);
5932 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5934 aContext->AddFilter (aFilter);
5936 else if (anArg == "-secondtype"
5937 && anArgIter + 1 < theArgc)
5939 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5940 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5941 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5943 Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'";
5947 Handle(SelectMgr_Filter) aFilter;
5948 if (aShapeType == TopAbs_SHAPE)
5950 aFilter = new AIS_TypeFilter (AIS_KindOfInteractive_Shape);
5954 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5956 aContext->AddFilter (aFilter);
5960 Message::SendFail() << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'";
5967 //=======================================================================
5968 //function : VPickSelected
5970 //=======================================================================
5971 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5973 static Standard_Integer aCount = 0;
5974 TCollection_AsciiString aName = "PickedShape_";
5982 aName = aName + aCount++ + "_";
5985 Standard_Integer anIdx = 0;
5986 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5988 TopoDS_Shape aShape;
5989 if (TheAISContext()->HasSelectedShape())
5991 aShape = TheAISContext()->SelectedShape();
5995 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5996 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5999 TCollection_AsciiString aCurrentName = aName;
6002 aCurrentName += anIdx;
6005 DBRep::Set ((aCurrentName).ToCString(), aShape);
6007 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
6008 GetMapOfAIS().Bind (aNewShape, aCurrentName);
6009 TheAISContext()->Display (aNewShape, Standard_False);
6012 TheAISContext()->UpdateCurrentViewer();
6017 //=======================================================================
6018 //function : list of known objects
6020 //=======================================================================
6021 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
6023 // 1234567890 12345678901234567 123456789
6024 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
6025 TCollection_AsciiString BlankLine(64,'_');
6026 Standard_Integer i ;
6028 di<<"/n"<<BlankLine.ToCString()<<"\n";
6031 Colum[i].Center(20,' ');
6033 di<<"|"<<Colum[i].ToCString();
6036 di<<BlankLine.ToCString()<<"\n";
6038 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
6039 const char ** names = GetTypeNames();
6041 TCollection_AsciiString curstring;
6042 TCollection_AsciiString curcolum[3];
6045 // les objets de type Datum..
6046 curcolum[1]+="Datum";
6048 curcolum[0].Clear();
6049 curcolum[0] += names[i];
6051 curcolum[2].Clear();
6052 curcolum[2]+=TCollection_AsciiString(i+1);
6054 for(Standard_Integer j =0;j<=2;j++){
6055 curcolum[j].Center(20,' ');
6056 di<<"|"<<curcolum[j].ToCString();
6060 di<<BlankLine.ToCString()<<"\n";
6062 // les objets de type shape
6063 curcolum[1].Clear();
6064 curcolum[1]+="Shape";
6065 curcolum[1].Center(20,' ');
6068 curcolum[0].Clear();
6069 curcolum[0] += names[7+i];
6070 curcolum[2].Clear();
6071 curcolum[2]+=TCollection_AsciiString(i);
6073 for(Standard_Integer j =0;j<=2;j++){
6074 curcolum[j].Center(20,' ');
6075 di<<"|"<<curcolum[j].ToCString();
6079 di<<BlankLine.ToCString()<<"\n";
6080 // les IO de type objet...
6081 curcolum[1].Clear();
6082 curcolum[1]+="Object";
6083 curcolum[1].Center(20,' ');
6085 curcolum[0].Clear();
6086 curcolum[0] += names[10+i];
6087 curcolum[2].Clear();
6088 curcolum[2]+=TCollection_AsciiString(i);
6090 for(Standard_Integer j =0;j<=2;j++){
6091 curcolum[j].Center(20,' ');
6092 di<<"|"<<curcolum[j].ToCString();
6096 di<<BlankLine.ToCString()<<"\n";
6097 // les contraintes et dimensions.
6098 // pour l'instant on separe juste contraintes et dimensions...
6099 // plus tard, on detaillera toutes les sortes...
6100 curcolum[1].Clear();
6101 curcolum[1]+="Relation";
6102 curcolum[1].Center(20,' ');
6104 curcolum[0].Clear();
6105 curcolum[0] += names[12+i];
6106 curcolum[2].Clear();
6107 curcolum[2]+=TCollection_AsciiString(i);
6109 for(Standard_Integer j =0;j<=2;j++){
6110 curcolum[j].Center(20,' ');
6111 di<<"|"<<curcolum[j].ToCString();
6115 di<<BlankLine.ToCString()<<"\n";
6122 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
6124 if(argc!=2) return 1;
6126 AIS_KindOfInteractive TheType;
6127 Standard_Integer TheSign(-1);
6128 GetTypeAndSignfromString(argv[1],TheType,TheSign);
6131 AIS_ListOfInteractive LIO;
6133 // en attendant l'amelioration ais pour les dimensions...
6135 Standard_Integer dimension_status(-1);
6136 if (TheType==AIS_KindOfInteractive_Relation)
6138 dimension_status = TheSign == 1 ? 1 : 0;
6142 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
6143 Handle(AIS_InteractiveObject) curio;
6144 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
6147 if(dimension_status == -1)
6148 TheAISContext()->Erase(curio,Standard_False);
6150 PrsDim_KindOfDimension KOD = Handle(PrsDim_Relation)::DownCast (curio)->KindOfDimension();
6151 if ((dimension_status==0 && KOD == PrsDim_KOD_NONE)||
6152 (dimension_status==1 && KOD != PrsDim_KOD_NONE))
6153 TheAISContext()->Erase(curio,Standard_False);
6156 TheAISContext()->UpdateCurrentViewer();
6159 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
6161 if(argc!=2) return 1;
6163 AIS_KindOfInteractive TheType;
6164 Standard_Integer TheSign(-1);
6165 GetTypeAndSignfromString(argv[1],TheType,TheSign);
6167 // en attendant l'amelioration ais pour les dimensions...
6169 Standard_Integer dimension_status(-1);
6170 if (TheType==AIS_KindOfInteractive_Relation)
6172 dimension_status = TheSign == 1 ? 1 : 0;
6176 AIS_ListOfInteractive LIO;
6177 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
6178 Handle(AIS_InteractiveObject) curio;
6179 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
6181 if(dimension_status == -1)
6182 TheAISContext()->Display(curio,Standard_False);
6184 PrsDim_KindOfDimension KOD = Handle(PrsDim_Relation)::DownCast (curio)->KindOfDimension();
6185 if ((dimension_status==0 && KOD == PrsDim_KOD_NONE)||
6186 (dimension_status==1 && KOD != PrsDim_KOD_NONE))
6187 TheAISContext()->Display(curio,Standard_False);
6192 TheAISContext()->UpdateCurrentViewer();
6196 //===============================================================================================
6199 //===============================================================================================
6200 static int VBsdf (Draw_Interpretor& theDI,
6201 Standard_Integer theArgsNb,
6202 const char** theArgVec)
6204 Handle(V3d_View) aView = ViewerTest::CurrentView();
6205 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6207 || aViewer.IsNull())
6209 Message::SendFail ("Error: No active viewer!");
6213 ViewerTest_CmdParser aCmd;
6215 aCmd.SetDescription ("Adjusts parameters of material BSDF:");
6217 aCmd.AddOption ("print|echo|p", "Prints BSDF");
6219 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
6221 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
6222 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
6223 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
6224 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
6225 aCmd.AddOption ("le", "Radiance emitted by surface");
6227 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
6228 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
6230 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
6231 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
6233 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
6234 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
6236 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
6238 aCmd.Parse (theArgsNb, theArgVec);
6240 if (aCmd.HasOption ("help"))
6242 theDI.PrintHelp (theArgVec[0]);
6246 // check viewer update mode
6247 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
6248 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6250 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
6257 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
6258 Handle(AIS_InteractiveObject) anIObj;
6259 if (!GetMapOfAIS().Find2 (aName, anIObj))
6261 Message::SendFail ("Error: no active viewer");
6265 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
6266 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
6268 if (aCmd.HasOption ("print"))
6271 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
6272 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
6273 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
6274 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
6275 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
6277 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6279 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
6280 : aBSDF.FresnelBase.Serialize();
6282 theDI << (aLayerID < 1 ? "Coat Fresnel: "
6283 : "Base Fresnel: ");
6285 if (aFresnel.x() >= 0.f)
6287 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
6288 << "G = " << aFresnel.g() << ", "
6289 << "B = " << aFresnel.b() << "\n";
6291 else if (aFresnel.x() >= -1.5f)
6293 theDI << "Constant " << aFresnel.z() << "\n";
6295 else if (aFresnel.x() >= -2.5f)
6297 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
6298 << "K = " << aFresnel.z() << "\n";
6302 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
6306 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
6307 << "Base roughness: " << aBSDF.Ks.w() << "\n"
6308 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
6309 << "Absorption color: " << aBSDF.Absorption.r() << ", "
6310 << aBSDF.Absorption.g() << ", "
6311 << aBSDF.Absorption.b() << "\n";
6316 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
6318 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
6321 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
6323 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
6326 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
6328 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
6331 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
6333 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
6335 aBSDF.Absorption.r() = aRGB.r();
6336 aBSDF.Absorption.g() = aRGB.g();
6337 aBSDF.Absorption.b() = aRGB.b();
6340 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
6344 if (aCmd.HasOption ("kc", 3))
6346 aKc = aCmd.ArgVec3f ("kc");
6350 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
6353 aBSDF.Kc.r() = aKc.r();
6354 aBSDF.Kc.g() = aKc.g();
6355 aBSDF.Kc.b() = aKc.b();
6358 if (aCmd.HasOption ("kd", 3))
6360 aBSDF.Kd = aCmd.ArgVec3f ("kd");
6362 else if (aCmd.HasOption ("kd", 1, Standard_True))
6364 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
6367 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
6371 if (aCmd.HasOption ("ks", 3))
6373 aKs = aCmd.ArgVec3f ("ks");
6377 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
6380 aBSDF.Ks.r() = aKs.r();
6381 aBSDF.Ks.g() = aKs.g();
6382 aBSDF.Ks.b() = aKs.b();
6385 if (aCmd.HasOption ("kt", 3))
6387 aBSDF.Kt = aCmd.ArgVec3f ("kt");
6389 else if (aCmd.HasOption ("kt", 1, Standard_True))
6391 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
6394 if (aCmd.HasOption ("le", 3))
6396 aBSDF.Le = aCmd.ArgVec3f ("le");
6398 else if (aCmd.HasOption ("le", 1, Standard_True))
6400 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
6403 const std::string aFresnelErrorMessage =
6404 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
6406 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6408 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
6411 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
6413 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6414 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6416 if (aFresnelType == "schlick")
6418 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
6419 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
6420 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
6422 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
6423 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
6424 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
6426 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
6430 theDI << aFresnelErrorMessage.c_str() << "\n";
6433 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
6435 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6436 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6438 if (aFresnelType == "conductor")
6440 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6441 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
6443 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
6447 theDI << aFresnelErrorMessage.c_str() << "\n";
6450 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
6452 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6453 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6455 if (aFresnelType == "constant")
6457 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6459 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
6461 else if (aFresnelType == "dielectric")
6463 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6465 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
6469 theDI << aFresnelErrorMessage.c_str() << "\n";
6474 if (aCmd.HasOption ("normalize"))
6479 aMaterial.SetBSDF (aBSDF);
6480 anIObj->SetMaterial (aMaterial);
6485 //==============================================================================
6486 //function : VLoadSelection
6487 //purpose : Adds given objects to map of AIS and loads selection primitives for them
6488 //==============================================================================
6489 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
6490 Standard_Integer theArgNb,
6491 const char** theArgVec)
6495 Message::SendFail ("Syntax error: wrong number of arguments.");
6499 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
6502 ViewerTest::ViewerInit();
6503 aCtx = ViewerTest::GetAISContext();
6506 // Parse input arguments
6507 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6509 const TCollection_AsciiString aName = theArgVec[anArgIter];
6510 Handle(AIS_InteractiveObject) aShape;
6511 if (!GetMapOfAIS().Find2 (aName, aShape))
6513 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
6514 if (!aDrawShape.IsNull())
6516 aShape = new AIS_Shape (aDrawShape);
6517 GetMapOfAIS().Bind (aShape, aName);
6520 if (aShape.IsNull())
6522 Message::SendFail() << "Syntax error: presentation '" << aName << "' not found";
6526 aCtx->Load (aShape, -1);
6527 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
6532 //==============================================================================
6533 //function : ViewerTest::Commands
6534 //purpose : Add all the viewer command in the Draw_Interpretor
6535 //==============================================================================
6537 void ViewerTest::Commands(Draw_Interpretor& theCommands)
6539 ViewerTest::ViewerCommands(theCommands);
6540 ViewerTest::RelationCommands(theCommands);
6541 ViewerTest::ObjectCommands(theCommands);
6542 ViewerTest::FilletCommands(theCommands);
6543 ViewerTest::OpenGlCommands(theCommands);
6545 const char *group = "AIS_Display";
6548 theCommands.Add("visos",
6549 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
6550 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
6551 __FILE__, visos, group);
6553 theCommands.Add("vdisplay",
6554 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
6555 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
6556 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
6557 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
6558 "\n\t\t: |topRight|bottomLeft|bottomRight}"
6559 "\n\t\t: [offsetX offsetY]]]"
6560 "\n\t\t: [-dispMode mode] [-highMode mode]"
6561 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
6562 "\n\t\t: [-redisplay] [-erased]"
6563 "\n\t\t: [-noecho] [-autoTriangulation {0|1}]"
6564 "\n\t\t: name1 [name2] ... [name n]"
6565 "\n\t\t: Displays named objects."
6566 "\n\t\t: Option -local enables displaying of objects in local"
6567 "\n\t\t: selection context. Local selection context will be opened"
6568 "\n\t\t: if there is not any."
6569 "\n\t\t: -noupdate Suppresses viewer redraw call."
6570 "\n\t\t: -mutable Enables optimizations for mutable objects."
6571 "\n\t\t: -neutral Draws objects in main viewer."
6572 "\n\t\t: -erased Loads the object into context, but does not display it."
6573 "\n\t\t: -layer Sets z-layer for objects."
6574 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
6575 "\n\t\t: options can be used for the default z-layers."
6576 "\n\t\t: -top Draws object on top of main presentations"
6577 "\n\t\t: but below topmost."
6578 "\n\t\t: -topmost Draws in overlay for 3D presentations."
6579 "\n\t\t: with independent Depth."
6580 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
6581 "\n\t\t: (On-Screen-Display)"
6582 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
6583 "\n\t\t: (On-Screen-Display)"
6584 "\n\t\t: -selectable|-noselect Controls selection of objects."
6585 "\n\t\t: -trsfPers Sets a transform persistence flags."
6586 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
6587 "\n\t\t: -2d Displays object in screen coordinates."
6588 "\n\t\t: (DY looks up)"
6589 "\n\t\t: -dispmode Sets display mode for objects."
6590 "\n\t\t: -highmode Sets hilight mode for objects."
6591 "\n\t\t: -redisplay Recomputes presentation of objects."
6592 "\n\t\t: -noecho Avoid printing of command results."
6593 "\n\t\t: -autoTriang Enable/disable auto-triangulation for displayed shape."
6594 __FILE__, VDisplay2, group);
6596 theCommands.Add ("vnbdisplayed",
6598 "\n\t\t: Returns number of displayed objects",
6599 __FILE__, VNbDisplayed, group);
6601 theCommands.Add ("vupdate",
6602 "vupdate name1 [name2] ... [name n]"
6603 "\n\t\t: Updates named objects in interactive context",
6604 __FILE__, VUpdate, group);
6606 theCommands.Add("verase",
6607 "verase [-noupdate|-update] [-local] [name1] ... [name n] [-noerror]"
6608 "\n\t\t: Erases selected or named objects."
6609 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
6610 "\n\t\t: Option -local enables erasing of selected or named objects without"
6611 "\n\t\t: closing local selection context."
6612 "\n\t\t: Option -noerror prevents exception on non-existing objects.",
6613 __FILE__, VErase, group);
6615 theCommands.Add("vremove",
6616 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n] [-noerror]"
6617 "or vremove [-context] -all to remove all objects"
6618 "\n\t\t: Removes selected or named objects."
6619 "\n\t\t If -context is in arguments, the objects are not deleted"
6620 "\n\t\t from the map of objects and names."
6621 "\n\t\t: Option -local enables removing of selected or named objects without"
6622 "\n\t\t: closing local selection context. Empty local selection context will be"
6624 "\n\t\t: Option -noupdate suppresses viewer redraw call."
6625 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects."
6626 "\n\t\t: Option -noerror prevents exception on non-existing objects.",
6627 __FILE__, VRemove, group);
6629 theCommands.Add("vdonly",
6630 "vdonly [-noupdate|-update] [name1] ... [name n]"
6631 "\n\t\t: Displays only selected or named objects",
6632 __FILE__,VDonly2,group);
6634 theCommands.Add("vdisplayall",
6636 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
6637 __FILE__, VDisplayAll, group);
6639 theCommands.Add("veraseall",
6641 "\n\t\t: Erases all objects displayed in the viewer.",
6642 __FILE__, VErase, group);
6644 theCommands.Add("verasetype",
6646 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
6647 __FILE__, VEraseType, group);
6648 theCommands.Add("vbounding",
6649 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
6650 "\n\t\t: [-print] [-hide]"
6651 "\n\t\t: Temporarily display bounding box of specified Interactive"
6652 "\n\t\t: Objects, or print it to console if -print is specified."
6653 "\n\t\t: Already displayed box might be hidden by -hide option.",
6654 __FILE__,VBounding,group);
6656 theCommands.Add("vdisplaytype",
6657 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
6658 __FILE__,VDisplayType,group);
6660 theCommands.Add("vsetdispmode",
6661 "vsetdispmode [name] mode(1,2,..)"
6662 "\n\t\t: Sets display mode for all, selected or named objects.",
6663 __FILE__,VDispMode,group);
6665 theCommands.Add("vunsetdispmode",
6666 "vunsetdispmode [name]"
6667 "\n\t\t: Unsets custom display mode for selected or named objects.",
6668 __FILE__,VDispMode,group);
6670 theCommands.Add("vdir",
6671 "vdir [mask] [-list]"
6672 "\n\t\t: Lists all objects displayed in 3D viewer"
6673 "\n\t\t: mask - name filter like prefix*"
6674 "\n\t\t: -list - format list with new-line per name; OFF by default",
6675 __FILE__,VDir,group);
6677 #ifdef HAVE_FREEIMAGE
6678 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
6680 #define DUMP_FORMATS "{ppm}"
6682 theCommands.Add("vdump",
6683 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
6684 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
6685 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
6686 "\n\t\t: [-xrPose base|head|handLeft|handRight=base]"
6687 "\n\t\t: [-tileSize Size=0]"
6688 "\n\t\t: Dumps content of the active view into image file",
6689 __FILE__,VDump,group);
6691 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
6692 __FILE__,VSubInt,group);
6694 theCommands.Add("vaspects",
6695 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults] [-subshapes subname1 [subname2 [...]]]"
6696 "\n\t\t: [-visibility {0|1}]"
6697 "\n\t\t: [-color {ColorName | R G B}] [-unsetColor]"
6698 "\n\t\t: [-backfaceColor Color]"
6699 "\n\t\t: [-material MatName] [-unsetMaterial]"
6700 "\n\t\t: [-transparency Transp] [-unsetTransparency]"
6701 "\n\t\t: [-width LineWidth] [-unsetWidth]"
6702 "\n\t\t: [-lineType {solid|dash|dot|dotDash|0xHexPattern} [-stippleFactor factor]]"
6703 "\n\t\t: [-unsetLineType]"
6704 "\n\t\t: [-markerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
6705 "\n\t\t: [-unsetMarkerType]"
6706 "\n\t\t: [-markerSize Scale] [-unsetMarkerSize]"
6707 "\n\t\t: [-freeBoundary {0|1}]"
6708 "\n\t\t: [-freeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
6709 "\n\t\t: [-freeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
6710 "\n\t\t: [-isoOnTriangulation 0|1]"
6711 "\n\t\t: [-maxParamValue {value}]"
6712 "\n\t\t: [-sensitivity {selection_mode} {value}]"
6713 "\n\t\t: [-shadingModel {unlit|flat|gouraud|phong|pbr|pbr_facet}]"
6714 "\n\t\t: [-unsetShadingModel]"
6715 "\n\t\t: [-interior {solid|hatch|hidenline|point}] [-setHatch HatchStyle]"
6716 "\n\t\t: [-unsetInterior]"
6717 "\n\t\t: [-faceBoundaryDraw {0|1}] [-mostContinuity {c0|g1|c1|g2|c2|c3|cn}]"
6718 "\n\t\t: [-faceBoundaryWidth LineWidth] [-faceBoundaryColor R G B] [-faceBoundaryType LineType]"
6719 "\n\t\t: [-drawEdges {0|1}] [-edgeType LineType] [-edgeColor R G B] [-quadEdges {0|1}]"
6720 "\n\t\t: [-drawSilhouette {0|1}]"
6721 "\n\t\t: [-alphaMode {opaque|mask|blend|maskblend|blendauto} [alphaCutOff=0.5]]"
6722 "\n\t\t: [-dumpJson]"
6723 "\n\t\t: [-dumpCompact {0|1}]"
6724 "\n\t\t: [-dumpDepth depth]"
6725 "\n\t\t: Manage presentation properties of all, selected or named objects."
6726 "\n\t\t: When -subshapes is specified than following properties will be assigned to specified sub-shapes."
6727 "\n\t\t: When -defaults is specified than presentation properties will be"
6728 "\n\t\t: assigned to all objects that have not their own specified properties"
6729 "\n\t\t: and to all objects to be displayed in the future."
6730 "\n\t\t: If -defaults is used there should not be any objects' names nor -subshapes specifier."
6731 "\n\t\t: See also vlistcolors and vlistmaterials to list named colors and materials"
6732 "\n\t\t: accepted by arguments -material and -color",
6733 __FILE__,VAspects,group);
6735 theCommands.Add("vsetcolor",
6736 "vsetcolor [-noupdate|-update] [name] ColorName"
6737 "\n\t\t: Sets color for all, selected or named objects."
6738 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
6739 __FILE__,VAspects,group);
6741 theCommands.Add("vunsetcolor",
6742 "vunsetcolor [-noupdate|-update] [name]"
6743 "\n\t\t: Resets color for all, selected or named objects."
6744 "\n\t\t: Alias for vaspects -unsetcolor [name].",
6745 __FILE__,VAspects,group);
6747 theCommands.Add("vsettransparency",
6748 "vsettransparency [-noupdate|-update] [name] Coefficient"
6749 "\n\t\t: Sets transparency for all, selected or named objects."
6750 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
6751 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
6752 __FILE__,VAspects,group);
6754 theCommands.Add("vunsettransparency",
6755 "vunsettransparency [-noupdate|-update] [name]"
6756 "\n\t\t: Resets transparency for all, selected or named objects."
6757 "\n\t\t: Alias for vaspects -unsettransp [name].",
6758 __FILE__,VAspects,group);
6760 theCommands.Add("vsetmaterial",
6761 "vsetmaterial [-noupdate|-update] [name] MaterialName"
6762 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
6763 __FILE__,VAspects,group);
6765 theCommands.Add("vunsetmaterial",
6766 "vunsetmaterial [-noupdate|-update] [name]"
6767 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
6768 __FILE__,VAspects,group);
6770 theCommands.Add("vsetwidth",
6771 "vsetwidth [-noupdate|-update] [name] width(0->10)"
6772 "\n\t\t: Alias for vaspects -setwidth [name] width.",
6773 __FILE__,VAspects,group);
6775 theCommands.Add("vunsetwidth",
6776 "vunsetwidth [-noupdate|-update] [name]"
6777 "\n\t\t: Alias for vaspects -unsetwidth [name].",
6778 __FILE__,VAspects,group);
6780 theCommands.Add("vsetinteriorstyle",
6781 "vsetinteriorstyle [-noupdate|-update] [name] Style"
6782 "\n\t\t: Alias for vaspects -setInterior [name] Style.",
6783 __FILE__,VAspects,group);
6785 theCommands.Add ("vsetedgetype",
6786 "vsetedgetype [name] [-type {solid, dash, dot}] [-color R G B] [-width value]"
6787 "\n\t\t: Alias for vaspects [name] -setEdgeType Type.",
6788 __FILE__, VAspects, group);
6790 theCommands.Add ("vunsetedgetype",
6791 "vunsetedgetype [name]"
6792 "\n\t\t: Alias for vaspects [name] -unsetEdgeType.",
6793 __FILE__, VAspects, group);
6795 theCommands.Add ("vshowfaceboundary",
6796 "vshowfaceboundary [name]"
6797 "\n\t\t: Alias for vaspects [name] -setFaceBoundaryDraw on",
6798 __FILE__, VAspects, group);
6800 theCommands.Add("vsensdis",
6801 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
6802 "\n\t\t: Standard entity types are those defined in Select3D package:"
6803 "\n\t\t: - sensitive box"
6804 "\n\t\t: - sensitive face"
6805 "\n\t\t: - sensitive curve"
6806 "\n\t\t: - sensitive segment"
6807 "\n\t\t: - sensitive circle"
6808 "\n\t\t: - sensitive point"
6809 "\n\t\t: - sensitive triangulation"
6810 "\n\t\t: - sensitive triangle"
6811 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
6812 __FILE__,VDispSensi,group);
6814 theCommands.Add("vsensera",
6815 "vsensera : erase active entities",
6816 __FILE__,VClearSensi,group);
6818 theCommands.Add("vsetshading",
6819 "vsetshading : vsetshading name Quality(default=0.0008) "
6820 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
6821 __FILE__,VShading,group);
6823 theCommands.Add("vunsetshading",
6824 "vunsetshading :vunsetshading name "
6825 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
6826 __FILE__,VShading,group);
6828 theCommands.Add ("vtexture",
6829 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
6830 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
6831 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
6832 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
6833 "\n\t\t: [-modulate {on|off}] [-srgb {on|off}]=on"
6834 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
6835 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
6836 "\n\t\t: [-default]"
6837 "\n\t\t: The texture can be specified by filepath"
6838 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
6839 "\n\t\t: The options are:"
6840 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
6841 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
6842 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
6843 "\n\t\t: -modulate Enable or disable texture color modulation"
6844 "\n\t\t: -srgb Prefer sRGB texture format when applicable; TRUE by default"
6845 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
6846 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
6847 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
6848 "\n\t\t: -setFilter Setup texture filter"
6849 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
6850 "\n\t\t: -default Sets texture mapping default parameters",
6851 __FILE__, VTexture, group);
6853 theCommands.Add("vtexscale",
6854 "vtexscale name ScaleU ScaleV"
6855 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
6856 __FILE__,VTexture,group);
6858 theCommands.Add("vtexorigin",
6859 "vtexorigin name OriginU OriginV"
6860 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
6861 __FILE__,VTexture,group);
6863 theCommands.Add("vtexrepeat",
6864 "vtexrepeat name RepeatU RepeatV"
6865 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
6868 theCommands.Add("vtexdefault",
6870 "\n\t\t: Alias for vtexture name -default.",
6873 theCommands.Add("vstate",
6874 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6875 "\n\t\t: Reports show/hidden state for selected or named objects"
6876 "\n\t\t: -entities - print low-level information about detected entities"
6877 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6878 __FILE__,VState,group);
6880 theCommands.Add("vpickshapes",
6881 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6882 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6883 "\n\t\t: Hold also Shift for multiple selection.",
6884 __FILE__, VPickShape, group);
6886 theCommands.Add("vtypes",
6887 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6890 theCommands.Add("vselfilter",
6891 "vselfilter [-contextfilter {AND|OR}]"
6892 "\n [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}]"
6893 "\n [-secondtype {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}]"
6895 "\nSets selection shape type filter in context or remove all filters."
6896 "\n : Option -contextfilter : To define a selection filter for two or more types of entity,"
6897 "\n use value AND (OR by default)."
6898 "\n : Option -type set type of selection filter. Filters are applied with Or combination."
6899 "\n : Option -clear remove all filters in context",
6900 __FILE__,VSelFilter,group);
6902 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6903 __FILE__, VPickSelected, group);
6905 theCommands.Add ("vloadselection",
6906 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6907 "\n\t\t: primitives for the shapes with names given without displaying them.",
6908 __FILE__, VLoadSelection, group);
6910 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6911 "\nAdjusts parameters of material BSDF:"
6912 "\n -help : Shows this message"
6913 "\n -print : Print BSDF"
6914 "\n -kd : Weight of the Lambertian BRDF"
6915 "\n -kr : Weight of the reflection BRDF"
6916 "\n -kt : Weight of the transmission BTDF"
6917 "\n -ks : Weight of the glossy Blinn BRDF"
6918 "\n -le : Self-emitted radiance"
6919 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6920 "\n Schlick x y z, Dielectric x, Conductor x y"
6921 "\n -roughness : Roughness of material (Blinn's exponent)"
6922 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6923 "\n -absorpcolor : Absorption color (only for transparent material)"
6924 "\n -normalize : Normalize BSDF coefficients",
6925 __FILE__, VBsdf, group);
6929 //==============================================================================
6930 //function : splitParameter
6931 //purpose : Split parameter string to parameter name and parameter value
6932 //==============================================================================
6933 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6934 TCollection_AsciiString& theName,
6935 TCollection_AsciiString& theValue)
6937 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6939 if (aParamNameEnd == 0)
6941 return Standard_False;
6944 TCollection_AsciiString aString (theString);
6945 if (aParamNameEnd != 0)
6947 theValue = aString.Split (aParamNameEnd);
6948 aString.Split (aString.Length() - 1);
6952 return Standard_True;
6955 //==============================================================================
6956 // ViewerTest::Factory
6957 //==============================================================================
6958 void ViewerTest::Factory(Draw_Interpretor& theDI)
6960 // definition of Viewer Command
6961 ViewerTest::Commands(theDI);
6964 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6968 // Declare entry point PLUGINFACTORY