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 <AIS_MapOfInteractive.hxx>
539 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
540 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
541 #include <ViewerTest_EventManager.hxx>
543 #include <TopoDS_Solid.hxx>
544 #include <BRepTools.hxx>
545 #include <BRep_Builder.hxx>
546 #include <TopAbs_ShapeEnum.hxx>
548 #include <TopoDS.hxx>
549 #include <BRep_Tool.hxx>
552 #include <Draw_Window.hxx>
553 #include <AIS_ListIteratorOfListOfInteractive.hxx>
554 #include <AIS_ListOfInteractive.hxx>
555 #include <AIS_DisplayMode.hxx>
556 #include <TopTools_ListOfShape.hxx>
557 #include <BRepOffsetAPI_MakeThickSolid.hxx>
559 //==============================================================================
560 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
561 //==============================================================================
562 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
563 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
567 //=======================================================================
570 //=======================================================================
571 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
572 const Handle(AIS_InteractiveObject)& theObject,
573 const Standard_Boolean theToUpdate,
574 const Standard_Boolean theReplaceIfExists)
576 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
577 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
580 Message::SendFail ("Error: AIS context is not available.");
581 return Standard_False;
584 if (aMap.IsBound2 (theName))
586 if (!theReplaceIfExists)
588 Message::SendFail() << "Error: other interactive object has been already registered with name: " << theName << ".\n"
589 << "Please use another name.";
590 return Standard_False;
593 if (Handle(AIS_InteractiveObject) anOldObj = aMap.Find2 (theName))
595 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
597 aMap.UnBind2 (theName);
600 if (theObject.IsNull())
602 // object with specified name has been already unbound
603 return Standard_True;
606 // unbind AIS object if it was bound with another name
607 aMap.UnBind1 (theObject);
609 // can be registered without rebinding
610 aMap.Bind (theObject, theName);
611 aCtx->Display (theObject, theToUpdate);
612 return Standard_True;
615 //! Alias for ViewerTest::Display(), compatibility with old code.
616 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
617 const Handle(AIS_InteractiveObject)& theObject,
618 Standard_Boolean theReplaceIfExists = Standard_True)
620 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
623 static NCollection_List<Handle(ViewerTest_EventManager)> theEventMgrs;
625 static Handle(V3d_View)& a3DView()
627 static Handle(V3d_View) Viou;
632 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
633 static Handle(AIS_InteractiveContext) aContext;
637 const Handle(V3d_View)& ViewerTest::CurrentView()
641 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
646 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
648 return TheAISContext();
651 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
653 TheAISContext() = aCtx;
654 ViewerTest::ResetEventManager();
657 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
659 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
662 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
664 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
668 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
669 theEventMgrs.Prepend(EM);
672 void ViewerTest::UnsetEventManager()
674 theEventMgrs.RemoveFirst();
678 void ViewerTest::ResetEventManager()
680 theEventMgrs.Clear();
681 theEventMgrs.Prepend (new ViewerTest_EventManager (ViewerTest::CurrentView(), ViewerTest::GetAISContext()));
684 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
686 return !theEventMgrs.IsEmpty()
687 ? theEventMgrs.First()
688 : Handle(ViewerTest_EventManager)();
691 //=======================================================================
692 //function : Get Context and active view
694 //=======================================================================
695 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
696 Handle(V3d_View)& theView)
698 theCtx = ViewerTest::GetAISContext();
699 theView = ViewerTest::CurrentView();
703 Message::SendFail ("Error: cannot find an active view!");
704 return Standard_False;
706 return Standard_True;
709 //==============================================================================
711 //purpose : Remove all the object from the viewer
712 //==============================================================================
713 void ViewerTest::Clear()
715 if (a3DView().IsNull())
720 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
721 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
723 const Handle(AIS_InteractiveObject) anObj = anObjIter.Key1();
724 if (anObj->GetContext() != TheAISContext())
729 Message::SendInfo() << "Remove " << anObjIter.Key2();
730 TheAISContext()->Remove (anObj, Standard_False);
731 aListRemoved.Append (anObj);
734 TheAISContext()->RebuildSelectionStructs();
735 TheAISContext()->UpdateCurrentViewer();
736 if (aListRemoved.Size() == GetMapOfAIS().Extent())
738 GetMapOfAIS().Clear();
742 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
744 GetMapOfAIS().UnBind1 (anObjIter.Value());
749 //==============================================================================
750 //function : CopyIsoAspect
751 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
752 //==============================================================================
753 static Handle(Prs3d_IsoAspect) CopyIsoAspect
754 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
755 const Standard_Integer theNbIsos)
757 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
758 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
759 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
761 Handle(Prs3d_IsoAspect) aResult =
762 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
767 //==============================================================================
769 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
770 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
771 //==============================================================================
772 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
774 if (TheAISContext().IsNull()) {
775 di << argv[0] << " Call 'vinit' before!\n";
780 di << "Current number of isos : " <<
781 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
782 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
783 di << "IsoOnPlane mode is " <<
784 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
785 di << "IsoOnTriangulation mode is " <<
786 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
790 Standard_Integer aLastInd = argc - 1;
791 Standard_Boolean isChanged = Standard_False;
792 Standard_Integer aNbUIsos = 0;
793 Standard_Integer aNbVIsos = 0;
796 Standard_Boolean isIsoOnPlane = Standard_False;
798 if (strcmp(argv[aLastInd], "1") == 0) {
799 isIsoOnPlane = Standard_True;
800 isChanged = Standard_True;
801 } else if (strcmp(argv[aLastInd], "0") == 0) {
802 isIsoOnPlane = Standard_False;
803 isChanged = Standard_True;
807 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
808 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
811 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
812 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
814 TheAISContext()->IsoOnPlane(isIsoOnPlane);
817 // If there are no shapes provided set the default numbers.
818 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
819 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
826 for (i = 1; i <= aLastInd; i++)
828 TCollection_AsciiString name(argv[i]);
829 Handle(AIS_InteractiveObject) aShape;
830 GetMapOfAIS().Find2(name, aShape);
833 Message::SendFail() << "Syntax error: object '" << name << "' is not found";
837 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
838 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
839 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
842 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
843 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
844 TheAISContext()->SetLocalAttributes (aShape, CurDrawer, Standard_False);
845 TheAISContext()->Redisplay (aShape, Standard_False);
849 di << "Number of isos for " << argv[i] << " : "
850 << aUIso->Number() << " " << aVIso->Number() << "\n";
855 TheAISContext()->UpdateCurrentViewer();
861 static Standard_Integer VDispSensi (Draw_Interpretor& ,
862 Standard_Integer theArgNb,
867 Message::SendFail ("Error: wrong syntax!");
871 Handle(AIS_InteractiveContext) aCtx;
872 Handle(V3d_View) aView;
873 if (!getCtxAndView (aCtx, aView))
878 aCtx->DisplayActiveSensitive (aView);
883 static Standard_Integer VClearSensi (Draw_Interpretor& ,
884 Standard_Integer theArgNb,
889 Message::SendFail ("Error: wrong syntax!");
893 Handle(AIS_InteractiveContext) aCtx;
894 Handle(V3d_View) aView;
895 if (!getCtxAndView (aCtx, aView))
899 aCtx->ClearActiveSensitive (aView);
903 //==============================================================================
905 //purpose : To list the displayed object with their attributes
906 //==============================================================================
907 static int VDir (Draw_Interpretor& theDI,
908 Standard_Integer theNbArgs,
909 const char** theArgVec)
911 TCollection_AsciiString aMatch;
912 Standard_Boolean toFormat = Standard_False;
913 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
915 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
916 anArgCase.LowerCase();
917 if (anArgCase == "-list"
918 || anArgCase == "-format")
920 toFormat = Standard_True;
922 else if (aMatch.IsEmpty())
924 aMatch = theArgVec[anArgIter];
928 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
933 TCollection_AsciiString aRes;
934 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
936 if (!aMatch.IsEmpty())
938 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aMatch + "' '" + anIter.Key2() + "'";
939 if (theDI.Eval (aCheck.ToCString()) == 0
940 && *theDI.Result() != '1')
948 aRes += TCollection_AsciiString("\t") + anIter.Key2() + "\n";
952 aRes += anIter.Key2() + " ";
960 //! Auxiliary enumeration
961 enum ViewerTest_StereoPair
963 ViewerTest_SP_Single,
964 ViewerTest_SP_SideBySide,
965 ViewerTest_SP_OverUnder
968 //==============================================================================
970 //purpose : To dump the active view snapshot to image file
971 //==============================================================================
972 static Standard_Integer VDump (Draw_Interpretor& theDI,
973 Standard_Integer theArgNb,
974 Standard_CString* theArgVec)
976 Handle(V3d_View) aView = ViewerTest::CurrentView();
979 Message::SendFail ("Error: wrong number of arguments! Image file name should be specified at least.");
984 Message::SendFail() << "Error: cannot find an active view!";
988 Standard_Integer anArgIter = 1;
989 Standard_CString aFilePath = theArgVec[anArgIter++];
990 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
991 V3d_ImageDumpOptions aParams;
992 Handle(Graphic3d_Camera) aCustomCam;
993 aParams.BufferType = Graphic3d_BT_RGB;
994 aParams.StereoOptions = V3d_SDO_MONO;
995 for (; anArgIter < theArgNb; ++anArgIter)
997 TCollection_AsciiString anArg (theArgVec[anArgIter]);
999 if (anArg == "-buffer")
1001 if (++anArgIter >= theArgNb)
1003 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
1007 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
1008 aBufArg.LowerCase();
1009 if (aBufArg == "rgba")
1011 aParams.BufferType = Graphic3d_BT_RGBA;
1013 else if (aBufArg == "rgb")
1015 aParams.BufferType = Graphic3d_BT_RGB;
1017 else if (aBufArg == "red")
1019 aParams.BufferType = Graphic3d_BT_Red;
1021 else if (aBufArg == "depth")
1023 aParams.BufferType = Graphic3d_BT_Depth;
1027 Message::SendFail() << "Error: unknown buffer '" << aBufArg << "'";
1031 else if (anArgIter + 1 < theArgNb
1032 && anArg == "-xrpose")
1034 TCollection_AsciiString anXRArg (theArgVec[++anArgIter]);
1035 anXRArg.LowerCase();
1036 if (anXRArg == "base")
1038 aCustomCam = aView->View()->BaseXRCamera();
1040 else if (anXRArg == "head")
1042 aCustomCam = aView->View()->PosedXRCamera();
1044 else if (anXRArg == "handleft"
1045 || anXRArg == "handright")
1047 if (aView->View()->IsActiveXR())
1049 aCustomCam = new Graphic3d_Camera();
1050 aView->View()->ComputeXRPosedCameraFromBase (*aCustomCam, anXRArg == "handleft"
1051 ? aView->View()->XRSession()->LeftHandPose()
1052 : aView->View()->XRSession()->RightHandPose());
1057 Message::SendFail() << "Syntax error: unknown XR pose '" << anXRArg << "'";
1060 if (aCustomCam.IsNull())
1062 Message::SendFail() << "Error: undefined XR pose";
1066 else if (anArg == "-stereo")
1068 if (++anArgIter >= theArgNb)
1070 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
1074 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
1075 aStereoArg.LowerCase();
1076 if (aStereoArg == "l"
1077 || aStereoArg == "left")
1079 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1081 else if (aStereoArg == "r"
1082 || aStereoArg == "right")
1084 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1086 else if (aStereoArg == "mono")
1088 aParams.StereoOptions = V3d_SDO_MONO;
1090 else if (aStereoArg == "blended"
1091 || aStereoArg == "blend"
1092 || aStereoArg == "stereo")
1094 aParams.StereoOptions = V3d_SDO_BLENDED;
1096 else if (aStereoArg == "sbs"
1097 || aStereoArg == "sidebyside")
1099 aStereoPair = ViewerTest_SP_SideBySide;
1101 else if (aStereoArg == "ou"
1102 || aStereoArg == "overunder")
1104 aStereoPair = ViewerTest_SP_OverUnder;
1108 Message::SendFail() << "Error: unknown stereo format '" << aStereoArg << "'";
1112 else if (anArg == "-rgba"
1115 aParams.BufferType = Graphic3d_BT_RGBA;
1117 else if (anArg == "-rgb"
1120 aParams.BufferType = Graphic3d_BT_RGB;
1122 else if (anArg == "-red"
1125 aParams.BufferType = Graphic3d_BT_Red;
1127 else if (anArg == "-depth"
1128 || anArg == "depth")
1130 aParams.BufferType = Graphic3d_BT_Depth;
1132 else if (anArg == "-width"
1134 || anArg == "sizex")
1136 if (aParams.Width != 0)
1138 Message::SendFail() << "Error: wrong syntax at " << theArgVec[anArgIter];
1141 else if (++anArgIter >= theArgNb)
1143 Message::SendFail() << "Error: integer value is expected right after 'width'";
1146 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1148 else if (anArg == "-height"
1149 || anArg == "height"
1150 || anArg == "-sizey")
1152 if (aParams.Height != 0)
1154 Message::SendFail() << "Error: wrong syntax at " << theArgVec[anArgIter];
1157 else if (++anArgIter >= theArgNb)
1159 Message::SendFail() << "Error: integer value is expected right after 'height'";
1162 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1164 else if (anArg == "-tile"
1165 || anArg == "-tilesize")
1167 if (++anArgIter >= theArgNb)
1169 Message::SendFail() << "Error: integer value is expected right after 'tileSize'";
1172 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1176 Message::SendFail() << "Error: unknown argument '" << theArgVec[anArgIter] << "'";
1180 if ((aParams.Width <= 0 && aParams.Height > 0)
1181 || (aParams.Width > 0 && aParams.Height <= 0))
1183 Message::SendFail() << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect";
1187 if (aParams.Width <= 0 || aParams.Height <= 0)
1189 aView->Window()->Size (aParams.Width, aParams.Height);
1192 Image_AlienPixMap aPixMap;
1193 Image_Format aFormat = Image_Format_UNKNOWN;
1194 switch (aParams.BufferType)
1196 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1197 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1198 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1199 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1200 case Graphic3d_BT_Red: aFormat = Image_Format_Gray; break;
1203 const bool wasImmUpdate = aView->SetImmediateUpdate (false);
1204 Handle(Graphic3d_Camera) aCamBack = aView->Camera();
1205 if (!aCustomCam.IsNull())
1207 aView->SetCamera (aCustomCam);
1209 switch (aStereoPair)
1211 case ViewerTest_SP_Single:
1213 if (!aView->ToPixMap (aPixMap, aParams))
1215 theDI << "Fail: view dump failed!\n";
1218 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1219 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1221 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1222 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1226 case ViewerTest_SP_SideBySide:
1228 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1230 theDI << "Fail: not enough memory for image allocation!\n";
1234 Image_PixMap aPixMapL, aPixMapR;
1235 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1236 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1237 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1238 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1240 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1241 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1242 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1243 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1246 theDI << "Fail: view dump failed!\n";
1251 case ViewerTest_SP_OverUnder:
1253 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1255 theDI << "Fail: not enough memory for image allocation!\n";
1259 Image_PixMap aPixMapL, aPixMapR;
1260 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1261 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1262 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1263 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1265 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1266 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1267 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1268 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1271 theDI << "Fail: view dump failed!\n";
1277 if (!aCustomCam.IsNull())
1279 aView->SetCamera (aCamBack);
1281 aView->SetImmediateUpdate (wasImmUpdate);
1283 if (!aPixMap.Save (aFilePath))
1285 theDI << "Fail: image can not be saved!\n";
1290 enum TypeOfDispOperation
1292 TypeOfDispOperation_SetDispMode,
1293 TypeOfDispOperation_UnsetDispMode
1296 //! Displays,Erase...
1297 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1298 const Standard_Integer theMode,
1299 const TypeOfDispOperation theType,
1300 const Standard_Boolean theToUpdate)
1302 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1305 case TypeOfDispOperation_SetDispMode:
1307 if (!thePrs.IsNull())
1309 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1313 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1317 case TypeOfDispOperation_UnsetDispMode:
1319 if (!thePrs.IsNull())
1321 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1325 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1332 //=======================================================================
1335 //=======================================================================
1336 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1341 Message::SendFail() << "Syntax error: wrong number of arguments";
1345 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1346 ? TypeOfDispOperation_UnsetDispMode
1347 : TypeOfDispOperation_SetDispMode;
1348 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1351 Message::SendFail ("Error: no active viewer");
1355 if (aType == TypeOfDispOperation_UnsetDispMode)
1359 if (aCtx->NbSelected() == 0)
1361 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1365 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1367 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1370 aCtx->UpdateCurrentViewer();
1374 TCollection_AsciiString aName = argv[1];
1375 Handle(AIS_InteractiveObject) aPrs;
1376 if (GetMapOfAIS().Find2 (aName, aPrs)
1379 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1385 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1386 if (aCtx->NbSelected() == 0
1387 && aType == TypeOfDispOperation_SetDispMode)
1389 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1391 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1393 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1395 aCtx->UpdateCurrentViewer();
1399 Handle(AIS_InteractiveObject) aPrs;
1400 TCollection_AsciiString aName (argv[1]);
1401 if (GetMapOfAIS().Find2 (aName, aPrs)
1404 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1411 //=======================================================================
1414 //=======================================================================
1415 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1417 if(argc==1) return 1;
1418 Standard_Integer On = Draw::Atoi(argv[1]);
1419 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1422 Message::SendFail ("Error: no active viewer");
1428 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1429 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1430 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1434 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1438 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1442 Ctx->UpdateCurrentViewer();
1445 Handle(AIS_InteractiveObject) IO;
1446 TCollection_AsciiString name = argv[2];
1447 if (GetMapOfAIS().Find2 (name, IO)
1451 Ctx->SubIntensityOn(IO, Standard_True);
1453 Ctx->SubIntensityOff(IO, Standard_True);
1460 //! Auxiliary class to iterate presentations from different collections.
1461 class ViewTest_PrsIter
1465 //! Create and initialize iterator object.
1466 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1467 : mySource (IterSource_All)
1469 NCollection_Sequence<TCollection_AsciiString> aNames;
1470 if (!theName.IsEmpty())
1471 aNames.Append (theName);
1475 //! Create and initialize iterator object.
1476 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1477 : mySource (IterSource_All)
1482 //! Initialize the iterator.
1483 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1485 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1487 mySelIter.Nullify();
1488 myCurrent.Nullify();
1489 myCurrentTrs.Nullify();
1490 if (!mySeq.IsEmpty())
1492 mySource = IterSource_List;
1493 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1495 else if (aCtx->NbSelected() > 0)
1497 mySource = IterSource_Selected;
1499 mySelIter->InitSelected();
1503 mySource = IterSource_All;
1504 myMapIter.Initialize (GetMapOfAIS());
1509 const TCollection_AsciiString& CurrentName() const
1511 return myCurrentName;
1514 const Handle(AIS_InteractiveObject)& Current() const
1519 const Handle(Standard_Transient)& CurrentTrs() const
1521 return myCurrentTrs;
1524 //! @return true if iterator points to valid object within collection
1525 Standard_Boolean More() const
1529 case IterSource_All: return myMapIter.More();
1530 case IterSource_List: return mySeqIter.More();
1531 case IterSource_Selected: return mySelIter->MoreSelected();
1533 return Standard_False;
1536 //! Go to the next item.
1539 myCurrentName.Clear();
1540 myCurrentTrs.Nullify();
1541 myCurrent.Nullify();
1544 case IterSource_All:
1549 case IterSource_List:
1554 case IterSource_Selected:
1556 mySelIter->NextSelected();
1569 case IterSource_All:
1571 if (myMapIter.More())
1573 myCurrentName = myMapIter.Key2();
1574 myCurrentTrs = myMapIter.Key1();
1575 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1579 case IterSource_List:
1581 if (mySeqIter.More())
1583 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1585 Message::SendFail() << "Error: object " << mySeqIter.Value() << " is not displayed!";
1588 myCurrentName = mySeqIter.Value();
1589 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1590 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1594 case IterSource_Selected:
1596 if (mySelIter->MoreSelected())
1598 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1599 myCurrent = mySelIter->SelectedInteractive();
1617 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1618 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1619 NCollection_Sequence<TCollection_AsciiString> mySeq;
1620 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1622 TCollection_AsciiString myCurrentName;//!< current item name
1623 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1624 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1626 IterSource mySource; //!< iterated collection
1630 //! Parse interior style name.
1631 static bool parseInteriorStyle (const TCollection_AsciiString& theArg,
1632 Aspect_InteriorStyle& theStyle)
1634 TCollection_AsciiString anArg (theArg);
1636 if (anArg == "empty")
1638 theStyle = Aspect_IS_EMPTY;
1640 else if (anArg == "hollow")
1642 theStyle = Aspect_IS_HOLLOW;
1644 else if (anArg == "solid")
1646 theStyle = Aspect_IS_SOLID;
1648 else if (anArg == "hatch")
1650 theStyle = Aspect_IS_HATCH;
1652 else if (anArg == "hiddenline"
1653 || anArg == "hidden-line"
1654 || anArg == "hidden_line")
1656 theStyle = Aspect_IS_HIDDENLINE;
1658 else if (anArg == "point")
1660 theStyle = Aspect_IS_POINT;
1662 else if (theArg.IsIntegerValue())
1664 const Standard_Integer anIntStyle = theArg.IntegerValue();
1665 if (anIntStyle < Aspect_IS_EMPTY || anIntStyle > Aspect_IS_POINT)
1669 theStyle = (Aspect_InteriorStyle)anIntStyle;
1678 //! Auxiliary structure for VAspects
1679 struct ViewerTest_AspectsChangeSet
1681 Standard_Integer ToSetVisibility;
1682 Standard_Integer Visibility;
1684 Standard_Integer ToSetColor;
1685 Quantity_Color Color;
1686 Standard_Integer ToSetBackFaceColor;
1687 Quantity_Color BackFaceColor;
1689 Standard_Integer ToSetLineWidth;
1690 Standard_Real LineWidth;
1692 Standard_Integer ToSetTypeOfLine;
1693 uint16_t StippleLinePattern;
1694 uint16_t StippleLineFactor;
1696 Standard_Integer ToSetTypeOfMarker;
1697 Aspect_TypeOfMarker TypeOfMarker;
1698 Handle(Image_PixMap) MarkerImage;
1700 Standard_Integer ToSetMarkerSize;
1701 Standard_Real MarkerSize;
1703 Standard_Integer ToSetTransparency;
1704 Standard_Real Transparency;
1706 Standard_Integer ToSetAlphaMode;
1707 Graphic3d_AlphaMode AlphaMode;
1708 Standard_ShortReal AlphaCutoff;
1710 Standard_Integer ToSetMaterial;
1711 Graphic3d_NameOfMaterial Material;
1712 TCollection_AsciiString MatName;
1714 NCollection_Sequence<TopoDS_Shape> SubShapes;
1716 Standard_Integer ToSetShowFreeBoundary;
1717 Standard_Integer ToSetFreeBoundaryWidth;
1718 Standard_Real FreeBoundaryWidth;
1719 Standard_Integer ToSetFreeBoundaryColor;
1720 Quantity_Color FreeBoundaryColor;
1722 Standard_Integer ToEnableIsoOnTriangulation;
1724 Standard_Integer ToSetFaceBoundaryDraw;
1725 Standard_Integer ToSetFaceBoundaryUpperContinuity;
1726 GeomAbs_Shape FaceBoundaryUpperContinuity;
1728 Standard_Integer ToSetFaceBoundaryColor;
1729 Quantity_Color FaceBoundaryColor;
1731 Standard_Integer ToSetFaceBoundaryWidth;
1732 Standard_Real FaceBoundaryWidth;
1734 Standard_Integer ToSetTypeOfFaceBoundaryLine;
1735 Aspect_TypeOfLine TypeOfFaceBoundaryLine;
1737 Standard_Integer ToSetMaxParamValue;
1738 Standard_Real MaxParamValue;
1740 Standard_Integer ToSetSensitivity;
1741 Standard_Integer SelectionMode;
1742 Standard_Integer Sensitivity;
1744 Standard_Integer ToSetHatch;
1745 Standard_Integer StdHatchStyle;
1746 TCollection_AsciiString PathToHatchPattern;
1748 Standard_Integer ToSetShadingModel;
1749 Graphic3d_TypeOfShadingModel ShadingModel;
1750 TCollection_AsciiString ShadingModelName;
1752 Standard_Integer ToSetInterior;
1753 Aspect_InteriorStyle InteriorStyle;
1755 Standard_Integer ToSetDrawSilhouette;
1757 Standard_Integer ToSetDrawEdges;
1758 Standard_Integer ToSetQuadEdges;
1760 Standard_Integer ToSetEdgeColor;
1761 Quantity_ColorRGBA EdgeColor;
1763 Standard_Integer ToSetEdgeWidth;
1764 Standard_Real EdgeWidth;
1766 Standard_Integer ToSetTypeOfEdge;
1767 Aspect_TypeOfLine TypeOfEdge;
1769 //! Empty constructor
1770 ViewerTest_AspectsChangeSet()
1771 : ToSetVisibility (0),
1774 Color (DEFAULT_COLOR),
1775 ToSetBackFaceColor(0),
1776 BackFaceColor (DEFAULT_COLOR),
1779 ToSetTypeOfLine (0),
1780 StippleLinePattern(0xFFFF),
1781 StippleLineFactor (1),
1782 ToSetTypeOfMarker (0),
1783 TypeOfMarker (Aspect_TOM_PLUS),
1784 ToSetMarkerSize (0),
1786 ToSetTransparency (0),
1789 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1792 Material (Graphic3d_NameOfMaterial_DEFAULT),
1793 ToSetShowFreeBoundary (0),
1794 ToSetFreeBoundaryWidth (0),
1795 FreeBoundaryWidth (1.0),
1796 ToSetFreeBoundaryColor (0),
1797 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1798 ToEnableIsoOnTriangulation (0),
1800 ToSetFaceBoundaryDraw (0),
1801 ToSetFaceBoundaryUpperContinuity (0),
1802 FaceBoundaryUpperContinuity(GeomAbs_CN),
1803 ToSetFaceBoundaryColor (0),
1804 FaceBoundaryColor (Quantity_NOC_BLACK),
1805 ToSetFaceBoundaryWidth (0),
1806 FaceBoundaryWidth (1.0f),
1807 ToSetTypeOfFaceBoundaryLine(0),
1808 TypeOfFaceBoundaryLine (Aspect_TOL_SOLID),
1810 ToSetMaxParamValue (0),
1811 MaxParamValue (500000),
1812 ToSetSensitivity (0),
1817 ToSetShadingModel (0),
1818 ShadingModel (Graphic3d_TypeOfShadingModel_DEFAULT),
1820 InteriorStyle (Aspect_IS_SOLID),
1821 ToSetDrawSilhouette (0),
1827 ToSetTypeOfEdge (0),
1828 TypeOfEdge (Aspect_TOL_SOLID)
1831 //! @return true if no changes have been requested
1832 Standard_Boolean IsEmpty() const
1834 return ToSetVisibility == 0
1835 && ToSetLineWidth == 0
1836 && ToSetTransparency == 0
1837 && ToSetAlphaMode == 0
1839 && ToSetBackFaceColor == 0
1840 && ToSetMaterial == 0
1841 && ToSetShowFreeBoundary == 0
1842 && ToSetFreeBoundaryColor == 0
1843 && ToSetFreeBoundaryWidth == 0
1844 && ToEnableIsoOnTriangulation == 0
1845 && ToSetFaceBoundaryDraw == 0
1846 && ToSetFaceBoundaryUpperContinuity == 0
1847 && ToSetFaceBoundaryColor == 0
1848 && ToSetFaceBoundaryWidth == 0
1849 && ToSetTypeOfFaceBoundaryLine == 0
1850 && ToSetMaxParamValue == 0
1851 && ToSetSensitivity == 0
1853 && ToSetShadingModel == 0
1854 && ToSetInterior == 0
1855 && ToSetDrawSilhouette == 0
1856 && ToSetDrawEdges == 0
1857 && ToSetQuadEdges == 0
1858 && ToSetEdgeColor == 0
1859 && ToSetEdgeWidth == 0
1860 && ToSetTypeOfEdge == 0;
1863 //! @return true if properties are valid
1864 Standard_Boolean Validate() const
1866 Standard_Boolean isOk = Standard_True;
1867 if (Visibility != 0 && Visibility != 1)
1869 Message::SendFail() << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")";
1870 isOk = Standard_False;
1872 if (LineWidth <= 0.0
1873 || LineWidth > 10.0)
1875 Message::SendFail() << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")";
1876 isOk = Standard_False;
1878 if (Transparency < 0.0
1879 || Transparency > 1.0)
1881 Message::SendFail() << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")";
1882 isOk = Standard_False;
1884 if (ToSetAlphaMode == 1
1885 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1887 Message::SendFail() << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")";
1888 isOk = Standard_False;
1890 if (FreeBoundaryWidth <= 0.0
1891 || FreeBoundaryWidth > 10.0)
1893 Message::SendFail() << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")";
1894 isOk = Standard_False;
1896 if (MaxParamValue < 0.0)
1898 Message::SendFail() << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")";
1899 isOk = Standard_False;
1901 if (Sensitivity < 0 && ToSetSensitivity)
1903 Message::SendFail() << "Error: sensitivity parameter value should not be negative (specified " << Sensitivity << ")";
1904 isOk = Standard_False;
1906 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1908 Message::SendFail ("Error: hatch style must be specified");
1909 isOk = Standard_False;
1911 if (ToSetShadingModel == 1
1912 && (ShadingModel < Graphic3d_TypeOfShadingModel_DEFAULT || ShadingModel > Graphic3d_TypeOfShadingModel_PbrFacet))
1914 Message::SendFail() << "Error: unknown shading model " << ShadingModelName << ".";
1915 isOk = Standard_False;
1920 //! Apply aspects to specified drawer.
1921 bool Apply (const Handle(Prs3d_Drawer)& theDrawer)
1923 bool toRecompute = false;
1924 const Handle(Prs3d_Drawer)& aDefDrawer = ViewerTest::GetAISContext()->DefaultDrawer();
1925 if (ToSetShowFreeBoundary != 0)
1927 theDrawer->SetFreeBoundaryDraw (ToSetShowFreeBoundary == 1);
1930 if (ToSetFreeBoundaryWidth != 0)
1932 if (ToSetFreeBoundaryWidth != -1
1933 || theDrawer->HasOwnFreeBoundaryAspect())
1935 if (!theDrawer->HasOwnFreeBoundaryAspect())
1937 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
1938 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
1939 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
1942 theDrawer->FreeBoundaryAspect()->SetWidth (FreeBoundaryWidth);
1945 if (ToSetFreeBoundaryColor != 0)
1947 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
1948 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
1949 aBoundaryAspect->SetColor (FreeBoundaryColor);
1950 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
1953 if (ToSetTypeOfLine != 0)
1955 if (ToSetTypeOfLine != -1
1956 || theDrawer->HasOwnLineAspect()
1957 || theDrawer->HasOwnWireAspect()
1958 || theDrawer->HasOwnFreeBoundaryAspect()
1959 || theDrawer->HasOwnUnFreeBoundaryAspect()
1960 || theDrawer->HasOwnSeenLineAspect())
1962 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
1963 theDrawer->LineAspect()->Aspect()->SetLinePattern (StippleLinePattern);
1964 theDrawer->LineAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor);
1965 theDrawer->WireAspect()->Aspect()->SetLinePattern (StippleLinePattern);
1966 theDrawer->WireAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor);
1967 theDrawer->FreeBoundaryAspect()->Aspect()->SetLinePattern (StippleLinePattern);
1968 theDrawer->FreeBoundaryAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor);
1969 theDrawer->UnFreeBoundaryAspect()->Aspect()->SetLinePattern (StippleLinePattern);
1970 theDrawer->UnFreeBoundaryAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor);
1971 theDrawer->SeenLineAspect()->Aspect()->SetLinePattern (StippleLinePattern);
1972 theDrawer->SeenLineAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor);
1975 if (ToSetTypeOfMarker != 0)
1977 if (ToSetTypeOfMarker != -1
1978 || theDrawer->HasOwnPointAspect())
1980 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
1981 theDrawer->PointAspect()->SetTypeOfMarker (TypeOfMarker);
1982 theDrawer->PointAspect()->Aspect()->SetMarkerImage (MarkerImage.IsNull() ? Handle(Graphic3d_MarkerImage)() : new Graphic3d_MarkerImage (MarkerImage));
1985 if (ToSetMarkerSize != 0)
1987 if (ToSetMarkerSize != -1
1988 || theDrawer->HasOwnPointAspect())
1990 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
1991 theDrawer->PointAspect()->SetScale (MarkerSize);
1995 if (ToSetMaxParamValue != 0)
1997 if (ToSetMaxParamValue != -1
1998 || theDrawer->HasOwnMaximalParameterValue())
2000 theDrawer->SetMaximalParameterValue (MaxParamValue);
2004 if (ToSetFaceBoundaryDraw != 0)
2006 if (ToSetFaceBoundaryDraw != -1
2007 || theDrawer->HasOwnFaceBoundaryDraw())
2010 theDrawer->SetFaceBoundaryDraw (ToSetFaceBoundaryDraw == 1);
2013 if (ToSetFaceBoundaryUpperContinuity != 0)
2015 if (ToSetFaceBoundaryUpperContinuity != -1
2016 || theDrawer->HasOwnFaceBoundaryUpperContinuity())
2019 if (ToSetFaceBoundaryUpperContinuity == -1)
2021 theDrawer->UnsetFaceBoundaryUpperContinuity();
2025 theDrawer->SetFaceBoundaryUpperContinuity (FaceBoundaryUpperContinuity);
2029 if (ToSetFaceBoundaryColor != 0)
2031 if (ToSetFaceBoundaryColor != -1
2032 || theDrawer->HasOwnFaceBoundaryAspect())
2034 if (ToSetFaceBoundaryColor == -1)
2037 theDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
2041 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2042 theDrawer->FaceBoundaryAspect()->SetColor (FaceBoundaryColor);
2046 if (ToSetFaceBoundaryWidth != 0)
2048 if (ToSetFaceBoundaryWidth != -1
2049 || theDrawer->HasOwnFaceBoundaryAspect())
2051 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2052 theDrawer->FaceBoundaryAspect()->SetWidth (FaceBoundaryWidth);
2055 if (ToSetTypeOfFaceBoundaryLine != 0)
2057 if (ToSetTypeOfFaceBoundaryLine != -1
2058 || theDrawer->HasOwnFaceBoundaryAspect())
2060 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
2061 theDrawer->FaceBoundaryAspect()->SetTypeOfLine (TypeOfFaceBoundaryLine);
2064 if (ToSetShadingModel != 0)
2066 if (ToSetShadingModel != -1
2067 || theDrawer->HasOwnShadingAspect())
2069 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2070 theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel);
2073 if (ToSetBackFaceColor != 0)
2075 if (ToSetBackFaceColor != -1
2076 || theDrawer->HasOwnShadingAspect())
2078 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2079 theDrawer->ShadingAspect()->SetColor (BackFaceColor, Aspect_TOFM_BACK_SIDE);
2082 if (ToSetAlphaMode != 0)
2084 if (ToSetAlphaMode != -1
2085 || theDrawer->HasOwnShadingAspect())
2087 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2088 theDrawer->ShadingAspect()->Aspect()->SetAlphaMode (AlphaMode, AlphaCutoff);
2091 if (ToSetHatch != 0)
2093 if (ToSetHatch != -1
2094 || theDrawer->HasOwnShadingAspect())
2096 theDrawer->SetupOwnShadingAspect (aDefDrawer);
2097 Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect();
2098 if (ToSetHatch == -1)
2100 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2104 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2105 if (!PathToHatchPattern.IsEmpty())
2107 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2108 if (anImage->Load (TCollection_AsciiString (PathToHatchPattern.ToCString())))
2110 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2114 Message::SendFail() << "Error: cannot load the following image: " << PathToHatchPattern;
2117 else if (StdHatchStyle != -1)
2119 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)StdHatchStyle));
2125 if (ToSetInterior != 0)
2127 if (ToSetInterior != -1
2128 || theDrawer->HasOwnShadingAspect())
2130 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2131 theDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (InteriorStyle);
2132 if (InteriorStyle == Aspect_IS_HATCH
2133 && theDrawer->ShadingAspect()->Aspect()->HatchStyle().IsNull())
2135 theDrawer->ShadingAspect()->Aspect()->SetHatchStyle (Aspect_HS_VERTICAL);
2139 if (ToSetDrawSilhouette != 0)
2141 if (ToSetDrawSilhouette != -1
2142 || theDrawer->HasOwnShadingAspect())
2144 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2145 theDrawer->ShadingAspect()->Aspect()->SetDrawSilhouette (ToSetDrawSilhouette == 1);
2148 if (ToSetDrawEdges != 0)
2150 if (ToSetDrawEdges != -1
2151 || theDrawer->HasOwnShadingAspect())
2153 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2154 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetDrawEdges == 1);
2157 if (ToSetQuadEdges != 0)
2159 if (ToSetQuadEdges != -1
2160 || theDrawer->HasOwnShadingAspect())
2162 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2163 theDrawer->ShadingAspect()->Aspect()->SetSkipFirstEdge (ToSetQuadEdges == 1);
2166 if (ToSetEdgeWidth != 0)
2168 if (ToSetEdgeWidth != -1
2169 || theDrawer->HasOwnShadingAspect())
2171 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2172 theDrawer->ShadingAspect()->Aspect()->SetEdgeWidth (EdgeWidth);
2175 if (ToSetTypeOfEdge != 0)
2177 if (ToSetTypeOfEdge != -1
2178 || theDrawer->HasOwnShadingAspect())
2180 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2181 theDrawer->ShadingAspect()->Aspect()->SetEdgeLineType (TypeOfEdge);
2182 if (ToSetInterior == 0)
2184 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetTypeOfEdge == 1
2185 && TypeOfEdge != Aspect_TOL_EMPTY);
2189 if (ToSetEdgeColor != 0)
2191 if (ToSetEdgeColor != -1
2192 || theDrawer->HasOwnShadingAspect())
2194 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2195 if (ToSetEdgeColor == -1)
2197 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (theDrawer->ShadingAspect()->Aspect()->InteriorColor());
2201 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (EdgeColor);
2209 //==============================================================================
2210 //function : VAspects
2212 //==============================================================================
2213 static Standard_Integer VAspects (Draw_Interpretor& theDI,
2214 Standard_Integer theArgNb,
2215 const char** theArgVec)
2217 TCollection_AsciiString aCmdName (theArgVec[0]);
2218 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2219 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2222 Message::SendFail ("Error: no active view!");
2226 Standard_Integer anArgIter = 1;
2227 Standard_Boolean isDefaults = Standard_False;
2228 NCollection_Sequence<TCollection_AsciiString> aNames;
2229 for (; anArgIter < theArgNb; ++anArgIter)
2231 TCollection_AsciiString anArg = theArgVec[anArgIter];
2232 if (anUpdateTool.parseRedrawMode (anArg))
2236 else if (!anArg.IsEmpty()
2237 && anArg.Value (1) != '-')
2239 aNames.Append (anArg);
2243 if (anArg == "-defaults")
2245 isDefaults = Standard_True;
2252 if (!aNames.IsEmpty() && isDefaults)
2254 Message::SendFail ("Error: wrong syntax. If -defaults is used there should not be any objects' names!");
2258 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
2259 aChanges.Append (ViewerTest_AspectsChangeSet());
2260 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
2262 // parse syntax of legacy commands
2263 bool toParseAliasArgs = false;
2264 Standard_Boolean toDump = 0;
2265 Standard_Boolean toCompactDump = 0;
2266 Standard_Integer aDumpDepth = -1;
2267 if (aCmdName == "vsetwidth")
2269 if (aNames.IsEmpty()
2270 || !aNames.Last().IsRealValue (Standard_True))
2272 Message::SendFail ("Error: not enough arguments!");
2275 aChangeSet->ToSetLineWidth = 1;
2276 aChangeSet->LineWidth = aNames.Last().RealValue();
2277 aNames.Remove (aNames.Length());
2279 else if (aCmdName == "vunsetwidth")
2281 aChangeSet->ToSetLineWidth = -1;
2283 else if (aCmdName == "vsetcolor")
2285 if (aNames.IsEmpty())
2287 Message::SendFail ("Error: not enough arguments!");
2290 aChangeSet->ToSetColor = 1;
2292 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2293 Standard_Boolean isOk = Standard_False;
2294 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
2296 aChangeSet->Color = aColor;
2297 aNames.Remove (aNames.Length());
2298 isOk = Standard_True;
2300 else if (Quantity_Color::ColorFromHex (aNames.Last().ToCString(), aChangeSet->Color))
2302 aNames.Remove (aNames.Length());
2303 isOk = Standard_True;
2305 else if (aNames.Length() >= 3)
2307 const char* anArgVec[3] =
2309 aNames.Value (aNames.Upper() - 2).ToCString(),
2310 aNames.Value (aNames.Upper() - 1).ToCString(),
2311 aNames.Value (aNames.Upper() - 0).ToCString(),
2314 Standard_Integer aNbParsed = Draw::ParseColor (3, anArgVec, aChangeSet->Color);
2315 isOk = aNbParsed == 3;
2316 aNames.Remove (aNames.Length());
2317 aNames.Remove (aNames.Length());
2318 aNames.Remove (aNames.Length());
2322 Message::SendFail ("Error: not enough arguments!");
2326 else if (aCmdName == "vunsetcolor")
2328 aChangeSet->ToSetColor = -1;
2330 else if (aCmdName == "vsettransparency")
2332 if (aNames.IsEmpty()
2333 || !aNames.Last().IsRealValue (Standard_True))
2335 Message::SendFail ("Error: not enough arguments!");
2338 aChangeSet->ToSetTransparency = 1;
2339 aChangeSet->Transparency = aNames.Last().RealValue();
2340 aNames.Remove (aNames.Length());
2342 else if (aCmdName == "vunsettransparency")
2344 aChangeSet->ToSetTransparency = -1;
2346 else if (aCmdName == "vsetmaterial")
2348 if (aNames.IsEmpty())
2350 Message::SendFail ("Error: not enough arguments!");
2353 aChangeSet->ToSetMaterial = 1;
2354 aChangeSet->MatName = aNames.Last();
2355 aNames.Remove (aNames.Length());
2356 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
2358 Message::SendFail() << "Syntax error: unknown material '" << aChangeSet->MatName << "'.";
2362 else if (aCmdName == "vunsetmaterial")
2364 aChangeSet->ToSetMaterial = -1;
2366 else if (aCmdName == "vsetinteriorstyle")
2368 if (aNames.IsEmpty()
2369 || !aNames.Last().IsRealValue (Standard_True))
2371 Message::SendFail ("Error: not enough arguments!");
2374 aChangeSet->ToSetInterior = 1;
2375 if (!parseInteriorStyle (aNames.Last(), aChangeSet->InteriorStyle))
2377 Message::SendFail() << "Error: wrong syntax at " << aNames.Last();
2380 aNames.Remove (aNames.Length());
2382 else if (aCmdName == "vsetedgetype")
2384 aChangeSet->ToSetDrawEdges = 1;
2385 toParseAliasArgs = true;
2387 else if (aCmdName == "vunsetedgetype")
2389 aChangeSet->ToSetDrawEdges = -1;
2390 aChangeSet->ToSetEdgeColor = -1;
2391 aChangeSet->ToSetTypeOfEdge = -1;
2392 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
2394 else if (aCmdName == "vshowfaceboundary")
2396 aChangeSet->ToSetFaceBoundaryDraw = 1;
2397 toParseAliasArgs = true;
2398 if (aNames.Size() >= 2
2399 && aNames.Value (2).IsIntegerValue())
2401 if (aNames.Size() == 7)
2403 if (ViewerTest::ParseLineType (aNames.Value (7).ToCString(), aChangeSet->TypeOfFaceBoundaryLine))
2405 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2409 if (aNames.Size() == 6
2410 && aNames.Value (6).IsRealValue (Standard_True))
2412 aChangeSet->ToSetFaceBoundaryWidth = 1;
2413 aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue();
2416 if (aNames.Size() == 5
2417 && aNames.Value (3).IsIntegerValue()
2418 && aNames.Value (4).IsIntegerValue()
2419 && aNames.Value (5).IsIntegerValue())
2421 aChangeSet->ToSetFaceBoundaryColor = 1;
2422 aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0,
2423 aNames.Value (4).IntegerValue() / 255.0,
2424 aNames.Value (5).IntegerValue() / 255.0,
2430 if (aNames.Size() == 2)
2432 toParseAliasArgs = false;
2433 aChangeSet->ToSetFaceBoundaryDraw = aNames.Value (2).IntegerValue() == 1 ? 1 : -1;
2438 else if (anArgIter >= theArgNb)
2440 Message::SendFail ("Error: not enough arguments!");
2444 if (!aChangeSet->IsEmpty()
2445 && !toParseAliasArgs)
2447 anArgIter = theArgNb;
2449 for (; anArgIter < theArgNb; ++anArgIter)
2451 TCollection_AsciiString anArg = theArgVec[anArgIter];
2453 if (anArg == "-setwidth"
2454 || anArg == "-width"
2455 || anArg == "-setlinewidth"
2456 || anArg == "-linewidth"
2457 || anArg == "-setedgewidth"
2458 || anArg == "-setedgeswidth"
2459 || anArg == "-edgewidth"
2460 || anArg == "-edgeswidth"
2461 || anArg == "-setfaceboundarywidth"
2462 || anArg == "-setboundarywidth"
2463 || anArg == "-faceboundarywidth"
2464 || anArg == "-boundarywidth")
2466 if (++anArgIter >= theArgNb)
2468 Message::SendFail() << "Error: wrong syntax at " << anArg;
2472 const Standard_Real aWidth = Draw::Atof (theArgVec[anArgIter]);
2473 if (anArg == "-setedgewidth"
2474 || anArg == "-setedgeswidth"
2475 || anArg == "-edgewidth"
2476 || anArg == "-edgeswidth"
2477 || aCmdName == "vsetedgetype")
2479 aChangeSet->ToSetEdgeWidth = 1;
2480 aChangeSet->EdgeWidth = aWidth;
2482 else if (anArg == "-setfaceboundarywidth"
2483 || anArg == "-setboundarywidth"
2484 || anArg == "-faceboundarywidth"
2485 || anArg == "-boundarywidth"
2486 || aCmdName == "vshowfaceboundary")
2488 aChangeSet->ToSetFaceBoundaryWidth = 1;
2489 aChangeSet->FaceBoundaryWidth = aWidth;
2493 aChangeSet->ToSetLineWidth = 1;
2494 aChangeSet->LineWidth = aWidth;
2497 else if (anArg == "-unsetwidth"
2498 || anArg == "-unsetlinewidth"
2499 || anArg == "-unsetedgewidth")
2501 if (anArg == "-unsetedgewidth")
2503 aChangeSet->ToSetEdgeWidth = -1;
2504 aChangeSet->EdgeWidth = 1.0;
2508 aChangeSet->ToSetLineWidth = -1;
2509 aChangeSet->LineWidth = 1.0;
2512 else if (anArg == "-settransp"
2513 || anArg == "-settransparency"
2514 || anArg == "-transparency"
2515 || anArg == "-transp")
2517 if (++anArgIter >= theArgNb)
2519 Message::SendFail() << "Error: wrong syntax at " << anArg;
2522 aChangeSet->ToSetTransparency = 1;
2523 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2524 if (aChangeSet->Transparency >= 0.0
2525 && aChangeSet->Transparency <= Precision::Confusion())
2527 aChangeSet->ToSetTransparency = -1;
2528 aChangeSet->Transparency = 0.0;
2531 else if (anArg == "-setalphamode"
2532 || anArg == "-alphamode")
2534 if (++anArgIter >= theArgNb)
2536 Message::SendFail() << "Error: wrong syntax at " << anArg;
2539 aChangeSet->ToSetAlphaMode = 1;
2540 aChangeSet->AlphaCutoff = 0.5f;
2542 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2544 if (aParam == "opaque")
2546 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2548 else if (aParam == "mask")
2550 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2552 else if (aParam == "blend")
2554 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2556 else if (aParam == "maskblend"
2557 || aParam == "blendmask")
2559 aChangeSet->AlphaMode = Graphic3d_AlphaMode_MaskBlend;
2561 else if (aParam == "blendauto"
2562 || aParam == "auto")
2564 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2568 Message::SendFail() << "Error: wrong syntax at " << aParam;
2573 if (anArgIter + 1 < theArgNb
2574 && theArgVec[anArgIter + 1][0] != '-')
2576 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2577 if (aParam2.IsRealValue (Standard_True))
2579 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2584 else if (anArg == "-setvis"
2585 || anArg == "-setvisibility"
2586 || anArg == "-visibility")
2588 if (++anArgIter >= theArgNb)
2590 Message::SendFail() << "Error: wrong syntax at " << anArg;
2594 aChangeSet->ToSetVisibility = 1;
2595 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2597 else if (anArg == "-setalpha"
2598 || anArg == "-alpha")
2600 if (++anArgIter >= theArgNb)
2602 Message::SendFail() << "Error: wrong syntax at " << anArg;
2605 aChangeSet->ToSetTransparency = 1;
2606 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2607 if (aChangeSet->Transparency < 0.0
2608 || aChangeSet->Transparency > 1.0)
2610 Message::SendFail() << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")";
2613 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2614 if (aChangeSet->Transparency >= 0.0
2615 && aChangeSet->Transparency <= Precision::Confusion())
2617 aChangeSet->ToSetTransparency = -1;
2618 aChangeSet->Transparency = 0.0;
2621 else if (anArg == "-unsettransp"
2622 || anArg == "-unsettransparency"
2623 || anArg == "-unsetalpha"
2624 || anArg == "-opaque")
2626 aChangeSet->ToSetTransparency = -1;
2627 aChangeSet->Transparency = 0.0;
2629 else if (anArg == "-setcolor"
2630 || anArg == "-color"
2631 || anArg == "-setbackfacecolor"
2632 || anArg == "-backfacecolor"
2633 || anArg == "-setbackcolor"
2634 || anArg == "-backcolor"
2635 || anArg == "-setfaceboundarycolor"
2636 || anArg == "-setboundarycolor"
2637 || anArg == "-faceboundarycolor"
2638 || anArg == "-boundarycolor")
2640 Quantity_Color aColor;
2641 Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1,
2642 theArgVec + anArgIter + 1,
2646 Message::SendFail() << "Syntax error at '" << anArg << "'";
2649 anArgIter += aNbParsed;
2650 if (aCmdName == "vsetedgetype")
2652 aChangeSet->ToSetEdgeColor = 1;
2653 aChangeSet->EdgeColor = Quantity_ColorRGBA (aColor);
2655 else if (aCmdName == "vshowfaceboundary"
2656 || anArg == "-setfaceboundarycolor"
2657 || anArg == "-setboundarycolor"
2658 || anArg == "-faceboundarycolor"
2659 || anArg == "-boundarycolor")
2661 aChangeSet->ToSetFaceBoundaryColor = 1;
2662 aChangeSet->FaceBoundaryColor = aColor;
2664 else if (anArg == "-setbackfacecolor"
2665 || anArg == "-backfacecolor"
2666 || anArg == "-setbackcolor"
2667 || anArg == "-backcolor")
2669 aChangeSet->ToSetBackFaceColor = 1;
2670 aChangeSet->BackFaceColor = aColor;
2674 aChangeSet->ToSetColor = 1;
2675 aChangeSet->Color = aColor;
2678 else if (anArg == "-setlinetype"
2679 || anArg == "-linetype"
2680 || anArg == "-setedgetype"
2681 || anArg == "-setedgestype"
2682 || anArg == "-edgetype"
2683 || anArg == "-edgestype"
2684 || anArg == "-setfaceboundarystyle"
2685 || anArg == "-faceboundarystyle"
2686 || anArg == "-boundarystyle"
2687 || anArg == "-setfaceboundarytype"
2688 || anArg == "-faceboundarytype"
2689 || anArg == "-setboundarytype"
2690 || anArg == "-boundarytype"
2691 || anArg == "-type")
2693 if (++anArgIter >= theArgNb)
2695 Message::SendFail() << "Error: wrong syntax at " << anArg;
2698 Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY;
2699 uint16_t aLinePattern = 0xFFFF;
2700 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType, aLinePattern))
2702 Message::SendFail() << "Error: wrong syntax at " << anArg;
2706 if (anArg == "-setedgetype"
2707 || anArg == "-setedgestype"
2708 || anArg == "-edgetype"
2709 || anArg == "-edgestype"
2710 || aCmdName == "vsetedgetype")
2712 aChangeSet->TypeOfEdge = Graphic3d_Aspects::DefaultLineTypeForPattern (aLinePattern);
2713 aChangeSet->ToSetTypeOfEdge = 1;
2715 else if (anArg == "-setfaceboundarystyle"
2716 || anArg == "-faceboundarystyle"
2717 || anArg == "-boundarystyle"
2718 || anArg == "-setfaceboundarytype"
2719 || anArg == "-faceboundarytype"
2720 || anArg == "-setboundarytype"
2721 || anArg == "-boundarytype"
2722 || aCmdName == "vshowfaceboundary")
2724 aChangeSet->TypeOfFaceBoundaryLine = Graphic3d_Aspects::DefaultLineTypeForPattern (aLinePattern);
2725 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2729 aChangeSet->StippleLinePattern = aLinePattern;
2730 aChangeSet->ToSetTypeOfLine = 1;
2733 else if (anArg == "-unsetlinetype"
2734 || anArg == "-unsetedgetype"
2735 || anArg == "-unsetedgestype")
2737 if (anArg == "-unsetedgetype"
2738 || anArg == "-unsetedgestype")
2740 aChangeSet->ToSetTypeOfEdge = -1;
2744 aChangeSet->ToSetTypeOfLine = -1;
2747 else if (anArg == "-setstipplelinefactor"
2748 || anArg == "-setstipplefactor"
2749 || anArg == "-setlinefactor"
2750 || anArg == "-stipplelinefactor"
2751 || anArg == "-stipplefactor"
2752 || anArg == "-linefactor")
2754 if (aChangeSet->ToSetTypeOfLine == -1)
2756 Message::SendFail() << "Error: -setStippleLineFactor requires -setLineType";
2759 if (++anArgIter >= theArgNb)
2761 Message::SendFail() << "Error: wrong syntax at " << anArg;
2764 aChangeSet->StippleLineFactor = (uint16_t )Draw::Atoi (theArgVec[anArgIter]);
2766 else if (anArg == "-setmarkertype"
2767 || anArg == "-markertype"
2768 || anArg == "-setpointtype"
2769 || anArg == "-pointtype")
2771 if (++anArgIter >= theArgNb)
2773 Message::SendFail() << "Error: wrong syntax at " << anArg;
2776 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2778 Message::SendFail() << "Error: wrong syntax at " << anArg;
2782 aChangeSet->ToSetTypeOfMarker = 1;
2784 else if (anArg == "-unsetmarkertype"
2785 || anArg == "-unsetpointtype")
2787 aChangeSet->ToSetTypeOfMarker = -1;
2789 else if (anArg == "-setmarkersize"
2790 || anArg == "-markersize"
2791 || anArg == "-setpointsize"
2792 || anArg == "-pointsize")
2794 if (++anArgIter >= theArgNb)
2796 Message::SendFail() << "Error: wrong syntax at " << anArg;
2799 aChangeSet->ToSetMarkerSize = 1;
2800 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2802 else if (anArg == "-unsetmarkersize"
2803 || anArg == "-unsetpointsize")
2805 aChangeSet->ToSetMarkerSize = -1;
2806 aChangeSet->MarkerSize = 1.0;
2808 else if (anArg == "-unsetcolor")
2810 aChangeSet->ToSetColor = -1;
2811 aChangeSet->Color = DEFAULT_COLOR;
2813 else if (anArg == "-setmat"
2815 || anArg == "-setmaterial"
2816 || anArg == "-material")
2818 if (++anArgIter >= theArgNb)
2820 Message::SendFail() << "Error: wrong syntax at " << anArg;
2823 aChangeSet->ToSetMaterial = 1;
2824 aChangeSet->MatName = theArgVec[anArgIter];
2825 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
2827 Message::SendFail() << "Syntax error: unknown material '" << aChangeSet->MatName << "'.";
2831 else if (anArg == "-unsetmat"
2832 || anArg == "-unsetmaterial")
2834 aChangeSet->ToSetMaterial = -1;
2835 aChangeSet->Material = Graphic3d_NameOfMaterial_DEFAULT;
2837 else if (anArg == "-subshape"
2838 || anArg == "-subshapes")
2842 Message::SendFail() << "Error: wrong syntax. -subshapes can not be used together with -defaults call!";
2846 if (aNames.IsEmpty())
2848 Message::SendFail() << "Error: main objects should specified explicitly when -subshapes is used!";
2852 aChanges.Append (ViewerTest_AspectsChangeSet());
2853 aChangeSet = &aChanges.ChangeLast();
2855 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2857 Standard_CString aSubShapeName = theArgVec[anArgIter];
2858 if (*aSubShapeName == '-')
2864 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2865 if (aSubShape.IsNull())
2867 Message::SendFail() << "Error: shape " << aSubShapeName << " doesn't found!";
2870 aChangeSet->SubShapes.Append (aSubShape);
2873 if (aChangeSet->SubShapes.IsEmpty())
2875 Message::SendFail() << "Error: empty list is specified after -subshapes!";
2879 else if (anArg == "-setfreeboundary"
2880 || anArg == "-freeboundary"
2881 || anArg == "-setfb"
2884 bool toEnable = true;
2885 if (!Draw::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2887 Message::SendFail() << "Error: wrong syntax at " << anArg;
2891 aChangeSet->ToSetShowFreeBoundary = toEnable ? 1 : -1;
2893 else if (anArg == "-setfreeboundarywidth"
2894 || anArg == "-freeboundarywidth"
2895 || anArg == "-setfbwidth"
2896 || anArg == "-fbwidth")
2898 if (++anArgIter >= theArgNb)
2900 Message::SendFail() << "Error: wrong syntax at " << anArg;
2903 aChangeSet->ToSetFreeBoundaryWidth = 1;
2904 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2906 else if (anArg == "-unsetfreeboundarywidth"
2907 || anArg == "-unsetfbwidth")
2909 aChangeSet->ToSetFreeBoundaryWidth = -1;
2910 aChangeSet->FreeBoundaryWidth = 1.0;
2912 else if (anArg == "-setfreeboundarycolor"
2913 || anArg == "-freeboundarycolor"
2914 || anArg == "-setfbcolor"
2915 || anArg == "-fbcolor")
2917 Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1,
2918 theArgVec + anArgIter + 1,
2919 aChangeSet->FreeBoundaryColor);
2922 Message::SendFail() << "Syntax error at '" << anArg << "'";
2925 anArgIter += aNbParsed;
2926 aChangeSet->ToSetFreeBoundaryColor = 1;
2928 else if (anArg == "-unsetfreeboundarycolor"
2929 || anArg == "-unsetfbcolor")
2931 aChangeSet->ToSetFreeBoundaryColor = -1;
2932 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2934 else if (anArg == "-setisoontriangulation"
2935 || anArg == "-isoontriangulation"
2936 || anArg == "-setisoontriang"
2937 || anArg == "-isoontriang")
2939 bool toEnable = true;
2940 if (!Draw::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2942 Message::SendFail() << "Error: wrong syntax at " << anArg;
2946 aChangeSet->ToEnableIsoOnTriangulation = toEnable ? 1 : -1;
2948 else if (anArg == "-setfaceboundarydraw"
2949 || anArg == "-setdrawfaceboundary"
2950 || anArg == "-setdrawfaceboundaries"
2951 || anArg == "-setshowfaceboundary"
2952 || anArg == "-setshowfaceboundaries"
2953 || anArg == "-setdrawfaceedges"
2954 || anArg == "-faceboundarydraw"
2955 || anArg == "-drawfaceboundary"
2956 || anArg == "-drawfaceboundaries"
2957 || anArg == "-showfaceboundary"
2958 || anArg == "-showfaceboundaries"
2959 || anArg == "-drawfaceedges"
2960 || anArg == "-faceboundary"
2961 || anArg == "-faceboundaries"
2962 || anArg == "-faceedges")
2964 bool toEnable = true;
2965 if (!Draw::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2967 Message::SendFail() << "Error: wrong syntax at " << anArg;
2971 aChangeSet->ToSetFaceBoundaryDraw = toEnable ? 1 : -1;
2973 else if (anArg == "-unsetfaceboundary"
2974 || anArg == "-unsetboundary")
2976 aChangeSet->ToSetFaceBoundaryDraw = -1;
2977 aChangeSet->ToSetFaceBoundaryColor = -1;
2979 else if (anArg == "-setmostcontinuity"
2980 || anArg == "-mostcontinuity")
2982 TCollection_AsciiString aClassArg (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "");
2983 aClassArg.LowerCase();
2984 GeomAbs_Shape aClass = GeomAbs_CN;
2985 if (aClassArg == "c0"
2986 || aClassArg == "0")
2988 aClass = GeomAbs_C0;
2990 else if (aClassArg == "g1")
2992 aClass = GeomAbs_G1;
2994 else if (aClassArg == "c1"
2995 || aClassArg == "1")
2997 aClass = GeomAbs_C1;
2999 else if (aClassArg == "g2")
3001 aClass = GeomAbs_G2;
3003 else if (aClassArg == "c2"
3004 || aClassArg == "2")
3006 aClass = GeomAbs_C2;
3008 else if (aClassArg == "c3"
3009 || aClassArg == "3")
3011 aClass = GeomAbs_C3;
3013 else if (aClassArg == "cn"
3014 || aClassArg == "n")
3016 aClass = GeomAbs_CN;
3020 Message::SendFail() << "Syntax error at '" << anArg << "'";
3025 aChangeSet->ToSetFaceBoundaryUpperContinuity = 1;
3026 aChangeSet->FaceBoundaryUpperContinuity = aClass;
3028 else if (anArg == "-setmaxparamvalue"
3029 || anArg == "-maxparamvalue")
3031 if (++anArgIter >= theArgNb)
3033 Message::SendFail() << "Error: wrong syntax at " << anArg;
3036 aChangeSet->ToSetMaxParamValue = 1;
3037 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
3039 else if (anArg == "-setsensitivity"
3040 || anArg == "-sensitivity")
3044 Message::SendFail() << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!";
3048 if (aNames.IsEmpty())
3050 Message::SendFail() << "Error: object and selection mode should specified explicitly when -setSensitivity is used!";
3054 if (anArgIter + 2 >= theArgNb)
3056 Message::SendFail() << "Error: wrong syntax at " << anArg;
3059 aChangeSet->ToSetSensitivity = 1;
3060 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
3061 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
3063 else if (anArg == "-sethatch"
3064 || anArg == "-hatch")
3068 Message::SendFail() << "Error: wrong syntax. -setHatch can not be used together with -defaults call!";
3072 if (aNames.IsEmpty())
3074 Message::SendFail() << "Error: object should be specified explicitly when -setHatch is used!";
3078 aChangeSet->ToSetHatch = 1;
3079 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
3080 if (anArgHatch.Length() <= 2)
3082 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
3084 || anIntStyle >= Aspect_HS_NB)
3086 Message::SendFail() << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!";
3089 aChangeSet->StdHatchStyle = anIntStyle;
3093 aChangeSet->PathToHatchPattern = anArgHatch;
3096 else if (anArg == "-setshadingmodel"
3097 || anArg == "-setshading"
3098 || anArg == "-shadingmodel"
3099 || anArg == "-shading")
3101 if (++anArgIter >= theArgNb)
3103 Message::SendFail() << "Error: wrong syntax at " << anArg;
3106 aChangeSet->ToSetShadingModel = 1;
3107 aChangeSet->ShadingModelName = theArgVec[anArgIter];
3108 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
3110 Message::SendFail() << "Error: wrong syntax at " << anArg;
3114 else if (anArg == "-unsetshadingmodel")
3116 aChangeSet->ToSetShadingModel = -1;
3117 aChangeSet->ShadingModel = Graphic3d_TypeOfShadingModel_DEFAULT;
3119 else if (anArg == "-setinterior"
3120 || anArg == "-setinteriorstyle"
3121 || anArg == "-interior"
3122 || anArg == "-interiorstyle")
3124 if (++anArgIter >= theArgNb)
3126 Message::SendFail() << "Error: wrong syntax at " << anArg;
3129 aChangeSet->ToSetInterior = 1;
3130 if (!parseInteriorStyle (theArgVec[anArgIter], aChangeSet->InteriorStyle))
3132 Message::SendFail() << "Error: wrong syntax at " << anArg;
3136 else if (anArg == "-unsetinterior")
3138 aChangeSet->ToSetInterior = -1;
3139 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3141 else if (anArg == "-setdrawoutline"
3142 || anArg == "-setdrawsilhouette"
3143 || anArg == "-setoutline"
3144 || anArg == "-setsilhouette"
3145 || anArg == "-outline"
3146 || anArg == "-outlined"
3147 || anArg == "-drawsilhouette"
3148 || anArg == "-silhouette")
3150 bool toDrawOutline = true;
3151 if (anArgIter + 1 < theArgNb
3152 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toDrawOutline))
3156 aChangeSet->ToSetDrawSilhouette = toDrawOutline ? 1 : -1;
3158 else if (anArg == "-setdrawedges"
3159 || anArg == "-setdrawedge"
3160 || anArg == "-drawedges"
3161 || anArg == "-drawedge"
3162 || anArg == "-edges")
3164 bool toDrawEdges = true;
3165 if (anArgIter + 1 < theArgNb
3166 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toDrawEdges))
3170 aChangeSet->ToSetDrawEdges = toDrawEdges ? 1 : -1;
3172 else if (anArg == "-setquadedges"
3173 || anArg == "-setquads"
3174 || anArg == "-quads"
3175 || anArg == "-skipfirstedge")
3177 bool isQuadMode = true;
3178 if (anArgIter + 1 < theArgNb
3179 && Draw::ParseOnOff (theArgVec[anArgIter + 1], isQuadMode))
3183 aChangeSet->ToSetQuadEdges = isQuadMode ? 1 : -1;
3185 else if (anArg == "-setedgecolor"
3186 || anArg == "-setedgescolor"
3187 || anArg == "-edgecolor"
3188 || anArg == "-edgescolor")
3190 Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1,
3191 theArgVec + anArgIter + 1,
3192 aChangeSet->EdgeColor);
3195 Message::SendFail() << "Syntax error at '" << anArg << "'";
3198 anArgIter += aNbParsed;
3199 aChangeSet->ToSetEdgeColor = 1;
3201 else if (anArg == "-unset")
3203 aChangeSet->ToSetVisibility = 1;
3204 aChangeSet->Visibility = 1;
3205 aChangeSet->ToSetLineWidth = -1;
3206 aChangeSet->LineWidth = 1.0;
3207 aChangeSet->ToSetTypeOfLine = -1;
3208 aChangeSet->StippleLinePattern = 0xFFFF;
3209 aChangeSet->StippleLineFactor = 1;
3210 aChangeSet->ToSetTypeOfMarker = -1;
3211 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
3212 aChangeSet->ToSetMarkerSize = -1;
3213 aChangeSet->MarkerSize = 1.0;
3214 aChangeSet->ToSetTransparency = -1;
3215 aChangeSet->Transparency = 0.0;
3216 aChangeSet->ToSetAlphaMode = -1;
3217 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
3218 aChangeSet->AlphaCutoff = 0.5f;
3219 aChangeSet->ToSetColor = -1;
3220 aChangeSet->Color = DEFAULT_COLOR;
3221 //aChangeSet->ToSetBackFaceColor = -1; // should be reset by ToSetColor
3222 //aChangeSet->BackFaceColor = DEFAULT_COLOR;
3223 aChangeSet->ToSetMaterial = -1;
3224 aChangeSet->Material = Graphic3d_NameOfMaterial_DEFAULT;
3225 aChangeSet->ToSetShowFreeBoundary = -1;
3226 aChangeSet->ToSetFreeBoundaryColor = -1;
3227 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
3228 aChangeSet->ToSetFreeBoundaryWidth = -1;
3229 aChangeSet->FreeBoundaryWidth = 1.0;
3230 aChangeSet->ToEnableIsoOnTriangulation = -1;
3232 aChangeSet->ToSetFaceBoundaryDraw = -1;
3233 aChangeSet->ToSetFaceBoundaryUpperContinuity = -1;
3234 aChangeSet->FaceBoundaryUpperContinuity = GeomAbs_CN;
3235 aChangeSet->ToSetFaceBoundaryColor = -1;
3236 aChangeSet->FaceBoundaryColor = Quantity_NOC_BLACK;
3237 aChangeSet->ToSetFaceBoundaryWidth = -1;
3238 aChangeSet->FaceBoundaryWidth = 1.0f;
3239 aChangeSet->ToSetTypeOfFaceBoundaryLine = -1;
3240 aChangeSet->TypeOfFaceBoundaryLine = Aspect_TOL_SOLID;
3242 aChangeSet->ToSetHatch = -1;
3243 aChangeSet->StdHatchStyle = -1;
3244 aChangeSet->PathToHatchPattern.Clear();
3245 aChangeSet->ToSetShadingModel = -1;
3246 aChangeSet->ShadingModel = Graphic3d_TypeOfShadingModel_DEFAULT;
3247 aChangeSet->ToSetInterior = -1;
3248 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
3249 aChangeSet->ToSetDrawSilhouette = -1;
3250 aChangeSet->ToSetDrawEdges = -1;
3251 aChangeSet->ToSetQuadEdges = -1;
3252 aChangeSet->ToSetEdgeColor = -1;
3253 aChangeSet->EdgeColor = Quantity_ColorRGBA (DEFAULT_COLOR);
3254 aChangeSet->ToSetEdgeWidth = -1;
3255 aChangeSet->EdgeWidth = 1.0;
3256 aChangeSet->ToSetTypeOfEdge = -1;
3257 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
3259 else if (anArg == "-dumpjson")
3261 toDump = Standard_True;
3263 else if (anArg == "-dumpcompact")
3265 toCompactDump = Standard_False;
3266 if (++anArgIter >= theArgNb && Draw::ParseOnOff (theArgVec[anArgIter + 1], toCompactDump))
3269 else if (anArg == "-dumpdepth")
3271 if (++anArgIter >= theArgNb)
3273 Message::SendFail() << "Error: wrong syntax at " << anArg;
3276 aDumpDepth = Draw::Atoi (theArgVec[anArgIter]);
3280 Message::SendFail() << "Error: wrong syntax at " << anArg;
3285 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3286 aChangesIter.More(); aChangesIter.Next())
3288 if (!aChangesIter.Value().Validate())
3294 // special case for -defaults parameter.
3295 // all changed values will be set to DefaultDrawer.
3298 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
3299 aChangeSet->Apply (aDrawer);
3300 if (aChangeSet->ToSetLineWidth != 0)
3302 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
3303 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
3304 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
3305 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
3307 if (aChangeSet->ToSetColor != 0)
3309 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
3310 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
3311 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
3312 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
3313 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
3314 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
3316 if (aChangeSet->ToSetTransparency != 0)
3318 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
3320 if (aChangeSet->ToSetMaterial != 0)
3322 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
3324 if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3326 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
3329 // redisplay all objects in context
3330 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3332 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3335 aCtx->Redisplay (aPrs, Standard_False);
3340 Standard_SStream aStream;
3341 aDrawer->DumpJson (aStream, aDumpDepth);
3344 theDI << Standard_Dump::Text (aStream);
3346 theDI << Standard_Dump::FormatJson (aStream);
3351 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3353 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
3354 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3360 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
3361 Handle(AIS_ColoredShape) aColoredPrs;
3362 Standard_Boolean toDisplay = Standard_False;
3363 Standard_Boolean toRedisplay = Standard_False;
3364 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
3366 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
3367 if (aShapePrs.IsNull())
3369 Message::SendFail() << "Error: an object " << aName << " is not an AIS_Shape presentation!";
3372 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
3373 if (aColoredPrs.IsNull())
3375 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3376 if (aShapePrs->HasDisplayMode())
3378 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
3380 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
3381 aCtx->Remove (aShapePrs, Standard_False);
3382 GetMapOfAIS().UnBind2 (aName);
3383 GetMapOfAIS().Bind (aColoredPrs, aName);
3384 toDisplay = Standard_True;
3385 aShapePrs = aColoredPrs;
3392 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3393 aChangeSet = &aChangesIter.ChangeValue();
3394 if (aChangeSet->ToSetVisibility == 1)
3396 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
3397 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
3399 else if (aChangeSet->ToSetMaterial == 1)
3401 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
3403 else if (aChangeSet->ToSetMaterial == -1)
3405 aCtx->UnsetMaterial (aPrs, Standard_False);
3407 if (aChangeSet->ToSetColor == 1)
3409 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
3411 else if (aChangeSet->ToSetColor == -1)
3413 aCtx->UnsetColor (aPrs, Standard_False);
3415 if (aChangeSet->ToSetTransparency == 1)
3417 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
3419 else if (aChangeSet->ToSetTransparency == -1)
3421 aCtx->UnsetTransparency (aPrs, Standard_False);
3423 if (aChangeSet->ToSetLineWidth == 1)
3425 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
3427 else if (aChangeSet->ToSetLineWidth == -1)
3429 aCtx->UnsetWidth (aPrs, Standard_False);
3431 else if (aChangeSet->ToEnableIsoOnTriangulation != 0)
3433 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
3434 toRedisplay = Standard_True;
3436 else if (aChangeSet->ToSetSensitivity != 0)
3438 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3440 if (!aDrawer.IsNull())
3442 toRedisplay = aChangeSet->Apply (aDrawer) || toRedisplay;
3445 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
3447 aChangeSet = &aChangesIter.ChangeValue();
3448 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
3449 aSubShapeIter.More(); aSubShapeIter.Next())
3451 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
3452 if (!aChangeSet->IsEmpty())
3454 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3455 aChangeSet->Apply (aCurColDrawer);
3457 if (aChangeSet->ToSetVisibility == 1)
3459 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3460 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
3462 if (aChangeSet->ToSetColor == 1)
3464 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
3466 if (aChangeSet->ToSetTransparency == 1)
3468 aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency);
3470 if (aChangeSet->ToSetLineWidth == 1)
3472 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
3474 if (aChangeSet->ToSetColor == -1
3475 || aChangeSet->ToSetLineWidth == -1)
3477 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
3479 if (aChangeSet->ToSetSensitivity != 0)
3481 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3487 aCtx->Display (aPrs, Standard_False);
3491 aCtx->Redisplay (aPrs, Standard_False);
3493 else if (!aColoredPrs.IsNull())
3495 aCtx->Redisplay (aColoredPrs, Standard_False);
3499 aPrs->SynchronizeAspects();
3504 Standard_SStream aStream;
3505 aDrawer->DumpJson (aStream);
3507 theDI << aName << ": \n";
3508 theDI << Standard_Dump::FormatJson (aStream);
3516 //==============================================================================
3517 //function : VDonly2
3519 //purpose : Display only a selected or named object
3520 // if there is no selected or named object s, nothing is done
3521 //==============================================================================
3522 static int VDonly2 (Draw_Interpretor& ,
3523 Standard_Integer theArgNb,
3524 const char** theArgVec)
3526 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3527 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3530 Message::SendFail ("Error: no active view!");
3534 Standard_Integer anArgIter = 1;
3535 for (; anArgIter < theArgNb; ++anArgIter)
3537 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3543 NCollection_Map<Handle(Standard_Transient)> aDispSet;
3544 if (anArgIter >= theArgNb)
3546 // display only selected objects
3547 if (aCtx->NbSelected() < 1)
3552 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3554 aDispSet.Add (aCtx->SelectedInteractive());
3559 // display only specified objects
3560 for (; anArgIter < theArgNb; ++anArgIter)
3562 TCollection_AsciiString aName = theArgVec[anArgIter];
3563 Handle(AIS_InteractiveObject) aShape;
3564 if (GetMapOfAIS().Find2 (aName, aShape)
3565 && !aShape.IsNull())
3567 aCtx->Display (aShape, Standard_False);
3568 aDispSet.Add (aShape);
3573 // weed out other objects
3574 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
3576 if (aDispSet.Contains (anIter.Key1()))
3581 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
3583 aCtx->Erase (aShape, Standard_False);
3589 //==============================================================================
3590 //function : VRemove
3591 //purpose : Removes selected or named objects.
3592 // If there is no selected or named objects,
3593 // all objects in the viewer can be removed with argument -all.
3594 // If -context is in arguments, the object is not deleted from the map of
3595 // objects (deleted only from the current context).
3596 //==============================================================================
3597 int VRemove (Draw_Interpretor& theDI,
3598 Standard_Integer theArgNb,
3599 const char** theArgVec)
3601 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3602 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3605 Message::SendFail ("Error: no active view!");
3609 Standard_Boolean isContextOnly = Standard_False;
3610 Standard_Boolean toRemoveAll = Standard_False;
3611 Standard_Boolean toPrintInfo = Standard_True;
3612 Standard_Boolean toFailOnError = Standard_True;
3614 Standard_Integer anArgIter = 1;
3615 for (; anArgIter < theArgNb; ++anArgIter)
3617 TCollection_AsciiString anArg = theArgVec[anArgIter];
3619 if (anArg == "-context")
3621 isContextOnly = Standard_True;
3623 else if (anArg == "-all")
3625 toRemoveAll = Standard_True;
3627 else if (anArg == "-noinfo")
3629 toPrintInfo = Standard_False;
3631 else if (anArg == "-noerror"
3632 || anArg == "-nofail")
3634 toFailOnError = Standard_False;
3636 else if (anUpdateTool.parseRedrawMode (anArg))
3646 && anArgIter < theArgNb)
3648 Message::SendFail ("Error: wrong syntax!");
3652 NCollection_List<TCollection_AsciiString> anIONameList;
3655 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3656 anIter.More(); anIter.Next())
3658 anIONameList.Append (anIter.Key2());
3661 else if (anArgIter < theArgNb) // removed objects names are in argument list
3663 for (; anArgIter < theArgNb; ++anArgIter)
3665 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3666 if (aName.Search ("*") != -1)
3668 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
3670 if (aPrsIter.Key1()->GetContext() != aCtx)
3674 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
3675 if (theDI.Eval (aCheck.ToCString()) == 0
3676 && *theDI.Result() == '1')
3678 anIONameList.Append (aPrsIter.Key2());
3685 Handle(AIS_InteractiveObject) anIO;
3686 if (!GetMapOfAIS().Find2 (aName, anIO))
3690 Message::SendFail() << "Syntax error: '" << aName << "' was not bound to some object.";
3694 else if (anIO->GetContext() != aCtx)
3698 Message::SendFail() << "Syntax error: '" << aName << "' was not displayed in current context.\n"
3699 << "Please activate view with this object displayed and try again.";
3705 anIONameList.Append (aName);
3709 else if (aCtx->NbSelected() > 0)
3711 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3712 anIter.More(); anIter.Next())
3714 if (!aCtx->IsSelected (anIter.Key1()))
3719 anIONameList.Append (anIter.Key2());
3724 // Unbind all removed objects from the map of displayed IO.
3725 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3726 anIter.More(); anIter.Next())
3728 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
3729 aCtx->Remove (anIO, Standard_False);
3732 theDI << anIter.Value() << " ";
3736 GetMapOfAIS().UnBind2 (anIter.Value());
3742 //==============================================================================
3744 //purpose : Erase some selected or named objects
3745 // if there is no selected or named objects, the whole viewer is erased
3746 //==============================================================================
3747 int VErase (Draw_Interpretor& theDI,
3748 Standard_Integer theArgNb,
3749 const char** theArgVec)
3751 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3752 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3753 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3756 Message::SendFail ("Error: no active view!");
3760 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3762 Standard_Integer anArgIter = 1;
3763 Standard_Boolean toEraseInView = Standard_False;
3764 Standard_Boolean toFailOnError = Standard_True;
3765 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3766 for (; anArgIter < theArgNb; ++anArgIter)
3768 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3769 anArgCase.LowerCase();
3770 if (anUpdateTool.parseRedrawMode (anArgCase))
3774 else if (anArgCase == "-view"
3775 || anArgCase == "-inview")
3777 toEraseInView = Standard_True;
3779 else if (anArgCase == "-noerror"
3780 || anArgCase == "-nofail")
3782 toFailOnError = Standard_False;
3786 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3790 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3792 Message::SendFail() << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.";
3796 if (!aNamesOfEraseIO.IsEmpty())
3798 // Erase named objects
3799 NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString> aPrsList;
3800 for (TColStd_SequenceOfAsciiString::Iterator anIter (aNamesOfEraseIO); anIter.More(); anIter.Next())
3802 const TCollection_AsciiString& aName = anIter.Value();
3803 if (aName.Search ("*") != -1)
3805 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
3807 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
3808 if (theDI.Eval (aCheck.ToCString()) == 0
3809 && *theDI.Result() == '1')
3811 aPrsList.Add (aPrsIter.Key1(), aPrsIter.Key2());
3818 Handle(AIS_InteractiveObject) anIO;
3819 if (!GetMapOfAIS().Find2 (aName, anIO))
3823 Message::SendFail() << "Syntax error: '" << aName << "' is not found";
3829 aPrsList.Add (anIO, aName);
3834 for (NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString>::Iterator anIter (aPrsList); anIter.More(); anIter.Next())
3836 theDI << anIter.Value() << " ";
3839 aCtx->SetViewAffinity (anIter.Key(), aView, Standard_False);
3843 aCtx->Erase (anIter.Key(), Standard_False);
3847 else if (!toEraseAll && aCtx->NbSelected() > 0)
3849 // Erase selected objects
3850 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3851 anIter.More(); anIter.Next())
3853 const Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3855 && aCtx->IsSelected (anIO))
3857 theDI << anIter.Key2() << " ";
3860 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3867 aCtx->EraseSelected (Standard_False);
3872 // Erase all objects
3873 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3874 anIter.More(); anIter.Next())
3876 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3881 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3885 aCtx->Erase (anIO, Standard_False);
3894 //==============================================================================
3895 //function : VDisplayAll
3896 //purpose : Display all the objects of the Map
3897 //==============================================================================
3898 static int VDisplayAll (Draw_Interpretor& ,
3899 Standard_Integer theArgNb,
3900 const char** theArgVec)
3903 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3904 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3907 Message::SendFail ("Error: no active view!");
3911 Standard_Integer anArgIter = 1;
3912 for (; anArgIter < theArgNb; ++anArgIter)
3914 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3915 anArgCase.LowerCase();
3916 if (anUpdateTool.parseRedrawMode (anArgCase))
3925 if (anArgIter < theArgNb)
3927 Message::SendFail() << theArgVec[0] << "Error: wrong syntax";
3931 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3932 anIter.More(); anIter.Next())
3934 aCtx->Erase (anIter.Key1(), Standard_False);
3937 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3938 anIter.More(); anIter.Next())
3940 aCtx->Display (anIter.Key1(), Standard_False);
3945 //! Auxiliary method to check if presentation exists
3946 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3947 const Handle(AIS_InteractiveObject)& theIO,
3948 const Standard_Integer theMode)
3950 if (theIO.IsNull() || theCtx.IsNull())
3957 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3962 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3964 return theIO->DisplayMode();
3966 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3968 return theCtx->DisplayMode();
3974 enum ViewerTest_BndAction
3981 //! Auxiliary method to print bounding box of presentation
3982 inline void bndPresentation (Draw_Interpretor& theDI,
3983 const Handle(PrsMgr_PresentationManager)& theMgr,
3984 const Handle(AIS_InteractiveObject)& theObj,
3985 const Standard_Integer theDispMode,
3986 const TCollection_AsciiString& theName,
3987 const ViewerTest_BndAction theAction,
3988 const Handle(Prs3d_Drawer)& theStyle)
3992 case BndAction_Hide:
3994 theMgr->Unhighlight (theObj);
3997 case BndAction_Show:
3999 theMgr->Color (theObj, theStyle, theDispMode);
4002 case BndAction_Print:
4005 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
4007 if (aPrsIter.Value()->Mode() != theDispMode)
4010 aBox = aPrsIter.Value()->MinMaxValues();
4012 gp_Pnt aMin = aBox.CornerMin();
4013 gp_Pnt aMax = aBox.CornerMax();
4014 theDI << theName << "\n"
4015 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
4016 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
4022 //==============================================================================
4023 //function : VBounding
4025 //==============================================================================
4026 int VBounding (Draw_Interpretor& theDI,
4027 Standard_Integer theArgNb,
4028 const char** theArgVec)
4030 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4031 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4034 Message::SendFail ("Error: no active view!");
4038 ViewerTest_BndAction anAction = BndAction_Show;
4039 Standard_Integer aMode = -1;
4041 Handle(Prs3d_Drawer) aStyle;
4043 Standard_Integer anArgIter = 1;
4044 for (; anArgIter < theArgNb; ++anArgIter)
4046 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4048 if (anArg == "-print")
4050 anAction = BndAction_Print;
4052 else if (anArg == "-show")
4054 anAction = BndAction_Show;
4056 else if (anArg == "-hide")
4058 anAction = BndAction_Hide;
4060 else if (anArg == "-mode")
4062 if (++anArgIter >= theArgNb)
4064 Message::SendFail() << "Error: wrong syntax at " << anArg;
4067 aMode = Draw::Atoi (theArgVec[anArgIter]);
4069 else if (!anUpdateTool.parseRedrawMode (anArg))
4075 if (anAction == BndAction_Show)
4077 aStyle = new Prs3d_Drawer();
4078 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
4079 aStyle->SetColor (Quantity_NOC_GRAY99);
4082 Standard_Integer aHighlightedMode = -1;
4083 if (anArgIter < theArgNb)
4085 // has a list of names
4086 for (; anArgIter < theArgNb; ++anArgIter)
4088 TCollection_AsciiString aName = theArgVec[anArgIter];
4089 Handle(AIS_InteractiveObject) anIO;
4090 if (!GetMapOfAIS().Find2 (aName, anIO))
4092 Message::SendFail() << "Error: presentation " << aName << " does not exist";
4096 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4097 if (aHighlightedMode == -1)
4099 Message::SendFail() << "Error: object " << aName << " has no presentation with mode " << aMode;
4102 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
4105 else if (aCtx->NbSelected() > 0)
4107 // remove all currently selected objects
4108 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4110 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
4111 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4112 if (aHighlightedMode != -1)
4114 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
4115 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
4122 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
4123 anIter.More(); anIter.Next())
4125 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
4126 aHighlightedMode = checkMode (aCtx, anIO, aMode);
4127 if (aHighlightedMode != -1)
4129 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
4136 //==============================================================================
4137 //function : VTexture
4139 //==============================================================================
4140 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4142 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4145 Message::SendFail() << "Error: no active view!";
4149 int toModulate = -1;
4151 bool toSetFilter = false;
4152 bool toSetAniso = false;
4153 bool toSetTrsfAngle = false;
4154 bool toSetTrsfTrans = false;
4155 bool toSetTrsfScale = false;
4156 Standard_ShortReal aTrsfRotAngle = 0.0f;
4157 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
4158 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
4159 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
4160 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
4162 Handle(AIS_InteractiveObject) aTexturedIO;
4163 Handle(AIS_Shape) aTexturedShape;
4164 Handle(Graphic3d_TextureSet) aTextureSetOld;
4165 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
4166 bool toSetGenRepeat = false;
4167 bool toSetGenScale = false;
4168 bool toSetGenOrigin = false;
4169 bool toSetImage = false;
4170 bool toComputeUV = false;
4172 const TCollection_AsciiString aCommandName (theArgVec[0]);
4173 bool toSetDefaults = aCommandName == "vtexdefault";
4175 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4176 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
4178 const TCollection_AsciiString aName = theArgVec[anArgIter];
4179 TCollection_AsciiString aNameCase = aName;
4180 aNameCase.LowerCase();
4181 if (anUpdateTool.parseRedrawMode (aName))
4185 else if (aTexturedIO.IsNull())
4187 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
4188 if (aMapOfIO.IsBound2 (aName))
4190 aTexturedIO = aMapOfIO.Find2 (aName);
4191 aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO);
4193 if (aTexturedIO.IsNull())
4195 Message::SendFail() << "Syntax error: shape " << aName << " does not exists in the viewer.";
4199 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
4201 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
4204 else if (!aTexturedShape.IsNull()
4205 && (aNameCase == "-scale"
4206 || aNameCase == "-setscale"
4207 || aCommandName == "vtexscale"))
4209 if (aCommandName != "vtexscale")
4213 if (anArgIter < theArgsNb)
4215 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4216 TCollection_AsciiString aValUCase = aValU;
4217 aValUCase.LowerCase();
4218 toSetGenScale = true;
4219 if (aValUCase == "off")
4221 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4224 else if (anArgIter + 1 < theArgsNb)
4226 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4227 if (aValU.IsRealValue (Standard_True)
4228 && aValV.IsRealValue (Standard_True))
4230 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4236 Message::SendFail() << "Syntax error: unexpected argument '" << aName << "'";
4239 else if (!aTexturedShape.IsNull()
4240 && (aNameCase == "-origin"
4241 || aNameCase == "-setorigin"
4242 || aCommandName == "vtexorigin"))
4244 if (aCommandName != "vtexorigin")
4248 if (anArgIter < theArgsNb)
4250 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4251 TCollection_AsciiString aValUCase = aValU;
4252 aValUCase.LowerCase();
4253 toSetGenOrigin = true;
4254 if (aValUCase == "off")
4256 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4259 else if (anArgIter + 1 < theArgsNb)
4261 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4262 if (aValU.IsRealValue (Standard_True)
4263 && aValV.IsRealValue (Standard_True))
4265 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4271 Message::SendFail() << "Syntax error: unexpected argument '" << aName << "'";
4274 else if (!aTexturedShape.IsNull()
4275 && (aNameCase == "-repeat"
4276 || aNameCase == "-setrepeat"
4277 || aCommandName == "vtexrepeat"))
4279 if (aCommandName != "vtexrepeat")
4283 if (anArgIter < theArgsNb)
4285 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4286 TCollection_AsciiString aValUCase = aValU;
4287 aValUCase.LowerCase();
4288 toSetGenRepeat = true;
4289 if (aValUCase == "off")
4291 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4294 else if (anArgIter + 1 < theArgsNb)
4296 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4297 if (aValU.IsRealValue (Standard_True)
4298 && aValV.IsRealValue (Standard_True))
4300 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
4306 Message::SendFail() << "Syntax error: unexpected argument '" << aName << "'";
4309 else if (aNameCase == "-modulate"
4310 || aNameCase == "-nomodulate")
4312 toModulate = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0;
4314 else if (aNameCase == "-srgb"
4315 || aNameCase == "-nosrgb")
4317 toSetSRgb = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0;
4319 else if ((aNameCase == "-setfilter"
4320 || aNameCase == "-filter")
4321 && anArgIter + 1 < theArgsNb)
4323 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4327 if (aValue == "nearest")
4329 aFilter = Graphic3d_TOTF_NEAREST;
4331 else if (aValue == "bilinear")
4333 aFilter = Graphic3d_TOTF_BILINEAR;
4335 else if (aValue == "trilinear")
4337 aFilter = Graphic3d_TOTF_TRILINEAR;
4341 Message::SendFail() << "Syntax error: unexpected argument '" << aValue << "'";
4345 else if ((aNameCase == "-setaniso"
4346 || aNameCase == "-setanisofilter"
4347 || aNameCase == "-aniso"
4348 || aNameCase == "-anisofilter")
4349 && anArgIter + 1 < theArgsNb)
4351 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4355 if (aValue == "off")
4357 anAnisoFilter = Graphic3d_LOTA_OFF;
4359 else if (aValue == "fast")
4361 anAnisoFilter = Graphic3d_LOTA_FAST;
4363 else if (aValue == "middle")
4365 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
4367 else if (aValue == "quality"
4368 || aValue == "high")
4370 anAnisoFilter = Graphic3d_LOTA_QUALITY;
4374 Message::SendFail() << "Syntax error: unexpected argument '" << aValue << "'";
4378 else if ((aNameCase == "-rotateangle"
4379 || aNameCase == "-rotangle"
4380 || aNameCase == "-rotate"
4381 || aNameCase == "-angle"
4382 || aNameCase == "-trsfangle")
4383 && anArgIter + 1 < theArgsNb)
4385 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4386 toSetTrsfAngle = true;
4389 else if ((aNameCase == "-trsftrans"
4390 || aNameCase == "-trsftranslate"
4391 || aNameCase == "-translate"
4392 || aNameCase == "-translation")
4393 && anArgIter + 2 < theArgsNb)
4395 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4396 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4397 toSetTrsfTrans = true;
4400 else if ((aNameCase == "-trsfscale")
4401 && anArgIter + 2 < theArgsNb)
4403 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4404 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4405 toSetTrsfScale = true;
4408 else if (aNameCase == "-default"
4409 || aNameCase == "-defaults")
4411 toSetDefaults = true;
4413 else if ((aNameCase == "-video")
4414 && anArgIter + 1 < theArgsNb)
4416 const TCollection_AsciiString anInput (theArgVec[++anArgIter]);
4417 Handle(Graphic3d_MediaTextureSet) aMedia = Handle(Graphic3d_MediaTextureSet)::DownCast (aTextureSetOld);
4418 if (aMedia.IsNull())
4420 aMedia = new Graphic3d_MediaTextureSet();
4422 if (aMedia->Input() != anInput)
4424 aMedia->OpenInput (anInput, false);
4428 if (aMedia->SwapFrames()
4429 && !aCtx->CurrentViewer()->ZLayerSettings (aTexturedIO->ZLayer()).IsImmediate())
4431 ViewerTest::CurrentView()->Invalidate();
4434 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4435 && aTexturedShape.IsNull())
4437 aTexturedIO->SetToUpdate();
4440 toComputeUV = aTextureSetOld.IsNull();
4441 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (true);
4442 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia);
4443 aTextureSetOld.Nullify();
4445 else if (aCommandName == "vtexture"
4446 && (aTextureVecNew.IsEmpty()
4447 || aNameCase.StartsWith ("-tex")))
4449 Standard_Integer aTexIndex = 0;
4450 TCollection_AsciiString aTexName = aName;
4451 if (aNameCase.StartsWith ("-tex"))
4453 if (anArgIter + 1 >= theArgsNb
4454 || aNameCase.Length() < 5)
4456 Message::SendFail() << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'";
4460 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
4461 if (!aTexIndexStr.IsIntegerValue())
4463 Message::SendFail() << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'";
4467 aTexIndex = aTexIndexStr.IntegerValue();
4468 aTexName = theArgVec[anArgIter + 1];
4471 if (aTexIndex >= Graphic3d_TextureUnit_NB
4472 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
4474 Message::SendFail ("Error: too many textures specified");
4479 if (aTexName.IsIntegerValue())
4481 const Standard_Integer aValue = aTexName.IntegerValue();
4482 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
4484 Message::SendFail() << "Syntax error: texture with ID " << aValue << " is undefined!";
4487 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
4489 else if (aTexName == "?")
4491 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
4493 theDi << "\n Files in current directory : \n\n";
4494 theDi.Eval ("glob -nocomplain *");
4496 TCollection_AsciiString aCmnd ("glob -nocomplain ");
4497 aCmnd += aTextureFolder;
4500 theDi << "Files in " << aTextureFolder << " : \n\n";
4501 theDi.Eval (aCmnd.ToCString());
4504 else if (aTexName != "off")
4506 if (!OSD_File (aTexName).Exists())
4508 Message::SendFail() << "Syntax error: non-existing image file has been specified '" << aTexName << "'.";
4511 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
4515 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
4518 if (aTextureVecNew.Value (aTexIndex))
4520 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
4525 Message::SendFail() << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'";
4532 // check if new image set is equal to already set one
4533 Standard_Integer aNbChanged = 0;
4534 Handle(Graphic3d_TextureSet) aTextureSetNew;
4535 if (!aTextureVecNew.IsEmpty())
4537 aNbChanged = aTextureVecNew.Size();
4538 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
4539 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
4541 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
4542 Handle(Graphic3d_TextureRoot) aTextureOld;
4543 if (!aTextureSetOld.IsNull()
4544 && aTexIter < aTextureSetOld->Size())
4546 aTextureOld = aTextureSetOld->Value (aTexIter);
4549 if (!aTextureOld.IsNull()
4550 && !aTextureNew.IsNull())
4552 *aTextureNew->GetParams() = *aTextureOld->GetParams();
4553 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
4555 TCollection_AsciiString aFilePathOld, aFilePathNew;
4556 aTextureOld->Path().SystemName (aFilePathOld);
4557 aTextureNew->Path().SystemName (aFilePathNew);
4558 if (aTextureNew->Name() == anOldManualTex->Name()
4559 && aFilePathOld == aFilePathNew
4560 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
4563 aTextureNew = anOldManualTex;
4567 aTextureSetNew->SetValue (aTexIter, aTextureNew);
4571 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
4572 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
4574 aTextureSetNew = aTextureSetOld;
4577 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4578 && aTexturedShape.IsNull())
4580 aTexturedIO->SetToUpdate();
4583 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
4584 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
4585 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
4586 aTextureSetOld.Nullify();
4591 if (toModulate != -1)
4598 aFilter = Graphic3d_TOTF_BILINEAR;
4603 anAnisoFilter = Graphic3d_LOTA_OFF;
4605 if (!toSetTrsfAngle)
4607 toSetTrsfAngle = true;
4608 aTrsfRotAngle = 0.0f;
4610 if (!toSetTrsfTrans)
4612 toSetTrsfTrans = true;
4613 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
4615 if (!toSetTrsfScale)
4617 toSetTrsfScale = true;
4618 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
4622 if (aCommandName == "vtexture"
4625 if (!aTextureSetOld.IsNull())
4627 //toComputeUV = true; // we can keep UV vertex attributes
4628 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
4629 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
4630 aTextureSetOld.Nullify();
4634 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
4635 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
4637 if (toModulate != -1)
4639 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
4641 if (toSetSRgb != -1)
4643 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->SetColorMap (toSetSRgb == 1);
4647 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
4651 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
4655 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
4659 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
4663 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
4667 // set default values if requested
4669 && (aCommandName == "vtexrepeat"
4672 if (!aTexturedShape.IsNull())
4674 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4676 toSetGenRepeat = true;
4679 && (aCommandName == "vtexorigin"
4682 if (!aTexturedShape.IsNull())
4684 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4686 toSetGenOrigin = true;
4689 && (aCommandName == "vtexscale"
4692 if (!aTexturedShape.IsNull())
4694 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4696 toSetGenScale = true;
4699 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
4701 if (!aTexturedShape.IsNull())
4703 aTexturedShape->SetToUpdate (AIS_Shaded);
4706 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
4707 || aCtx->DisplayMode() != AIS_Shaded)
4709 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
4714 aCtx->Display (aTexturedIO, false);
4715 aTexturedIO->SynchronizeAspects();
4719 //! Auxiliary method to parse transformation persistence flags
4720 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
4721 Graphic3d_TransModeFlags& theFlags)
4723 if (theFlagString == "zoom")
4725 theFlags = Graphic3d_TMF_ZoomPers;
4727 else if (theFlagString == "rotate")
4729 theFlags = Graphic3d_TMF_RotatePers;
4731 else if (theFlagString == "zoomrotate")
4733 theFlags = Graphic3d_TMF_ZoomRotatePers;
4735 else if (theFlagString == "trihedron"
4736 || theFlagString == "triedron")
4738 theFlags = Graphic3d_TMF_TriedronPers;
4740 else if (theFlagString == "none")
4742 theFlags = Graphic3d_TMF_None;
4746 return Standard_False;
4749 return Standard_True;
4752 //! Auxiliary method to parse transformation persistence flags
4753 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4754 Aspect_TypeOfTriedronPosition& theCorner)
4756 TCollection_AsciiString aString (theString);
4757 aString.LowerCase();
4758 if (aString == "center")
4760 theCorner = Aspect_TOTP_CENTER;
4762 else if (aString == "top"
4763 || aString == "upper")
4765 theCorner = Aspect_TOTP_TOP;
4767 else if (aString == "bottom"
4768 || aString == "lower")
4770 theCorner = Aspect_TOTP_BOTTOM;
4772 else if (aString == "left")
4774 theCorner = Aspect_TOTP_LEFT;
4776 else if (aString == "right")
4778 theCorner = Aspect_TOTP_RIGHT;
4780 else if (aString == "topleft"
4781 || aString == "leftupper"
4782 || aString == "upperleft")
4784 theCorner = Aspect_TOTP_LEFT_UPPER;
4786 else if (aString == "bottomleft"
4787 || aString == "leftlower"
4788 || aString == "lowerleft")
4790 theCorner = Aspect_TOTP_LEFT_LOWER;
4792 else if (aString == "topright"
4793 || aString == "rightupper"
4794 || aString == "upperright")
4796 theCorner = Aspect_TOTP_RIGHT_UPPER;
4798 else if (aString == "bottomright"
4799 || aString == "lowerright"
4800 || aString == "rightlower")
4802 theCorner = Aspect_TOTP_RIGHT_LOWER;
4806 return Standard_False;
4809 return Standard_True;
4812 //==============================================================================
4813 //function : VDisplay2
4815 //purpose : Display an object from its name
4816 //==============================================================================
4817 static int VDisplay2 (Draw_Interpretor& theDI,
4818 Standard_Integer theArgNb,
4819 const char** theArgVec)
4823 Message::SendFail ("Syntax error: wrong number of arguments.");
4827 && TCollection_AsciiString (theArgVec[1]) == "*")
4830 return VDisplayAll (theDI, 1, theArgVec);
4833 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4836 ViewerTest::ViewerInit();
4837 aCtx = ViewerTest::GetAISContext();
4840 // Parse input arguments
4841 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4842 Standard_Integer isMutable = -1;
4843 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4844 Standard_Boolean toReDisplay = Standard_False;
4845 Standard_Integer isSelectable = -1;
4846 Standard_Integer anObjDispMode = -2;
4847 Standard_Integer anObjHighMode = -2;
4848 Standard_Boolean toSetTrsfPers = Standard_False;
4849 Standard_Boolean toEcho = Standard_True;
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 == "-erased"
5052 || aNameCase == "-load")
5054 aDispStatus = AIS_DS_Erased;
5056 else if (aNameCase == "-noecho")
5062 aNamesOfDisplayIO.Append (aName);
5066 if (aNamesOfDisplayIO.IsEmpty())
5068 Message::SendFail ("Syntax error: wrong number of arguments.");
5072 // Display interactive objects
5073 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
5075 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value (anIter);
5076 Handle(AIS_InteractiveObject) aShape;
5077 if (!GetMapOfAIS().Find2 (aName, aShape))
5079 // create the AIS_Shape from a name
5080 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
5081 if (!aDrawShape.IsNull())
5083 aShape = new AIS_Shape (aDrawShape);
5084 if (isMutable != -1)
5086 aShape->SetMutable (isMutable == 1);
5088 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
5090 aShape->SetZLayer (aZLayer);
5094 aCtx->SetTransformPersistence (aShape, aTrsfPers);
5096 if (anObjDispMode != -2)
5098 if (anObjDispMode == -1)
5100 aShape->UnsetDisplayMode();
5102 if (!aShape->AcceptDisplayMode (anObjDispMode))
5104 Message::SendFail() << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjDispMode << " display mode";
5109 aShape->SetDisplayMode (anObjDispMode);
5112 if (anObjHighMode != -2)
5114 if (anObjHighMode != -1
5115 && !aShape->AcceptDisplayMode (anObjHighMode))
5117 Message::SendFail() << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjHighMode << " display mode";
5120 aShape->SetHilightMode (anObjHighMode);
5123 GetMapOfAIS().Bind (aShape, aName);
5124 Standard_Integer aDispMode = aShape->HasDisplayMode()
5125 ? aShape->DisplayMode()
5126 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5127 ? aCtx->DisplayMode()
5129 Standard_Integer aSelMode = -1;
5130 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5132 aSelMode = aShape->GlobalSelectionMode();
5135 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5136 if (toDisplayInView)
5138 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
5140 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
5142 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5147 Message::SendFail() << "Error: object with name '" << aName << "' does not exist!";
5152 if (isMutable != -1)
5154 aShape->SetMutable (isMutable == 1);
5156 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
5158 aShape->SetZLayer (aZLayer);
5162 aCtx->SetTransformPersistence (aShape, aTrsfPers);
5164 if (anObjDispMode != -2)
5166 aShape->SetDisplayMode (anObjDispMode);
5168 if (anObjHighMode != -2)
5170 aShape->SetHilightMode (anObjHighMode);
5172 Standard_Integer aDispMode = aShape->HasDisplayMode()
5173 ? aShape->DisplayMode()
5174 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
5175 ? aCtx->DisplayMode()
5177 Standard_Integer aSelMode = -1;
5178 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
5180 aSelMode = aShape->GlobalSelectionMode();
5183 if (aShape->Type() == AIS_KindOfInteractive_Datum)
5185 aCtx->Display (aShape, Standard_False);
5191 theDI << "Display " << aName << "\n";
5194 // update the Shape in the AIS_Shape
5195 TopoDS_Shape aNewShape = DBRep::GetExisting (aName);
5196 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
5197 if (!aShapePrs.IsNull())
5199 if (!aShapePrs->Shape().IsEqual (aNewShape))
5201 toReDisplay = Standard_True;
5203 aShapePrs->Set (aNewShape);
5207 aCtx->Redisplay (aShape, Standard_False);
5212 aCtx->Erase (aShape, Standard_False);
5214 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
5215 if (toDisplayInView)
5217 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
5225 //=======================================================================
5226 //function : VNbDisplayed
5227 //purpose : Returns number of displayed objects
5228 //=======================================================================
5229 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
5230 Standard_Integer theArgsNb,
5231 const char** theArgVec)
5235 theDi << "Usage : " << theArgVec[0] << "\n";
5239 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5240 if (aContextAIS.IsNull())
5242 Message::SendFail ("Syntax error: AIS context is not available.");
5246 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5247 if(aContext.IsNull())
5249 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
5253 AIS_ListOfInteractive aListOfIO;
5254 aContextAIS->DisplayedObjects (aListOfIO);
5256 theDi << aListOfIO.Extent() << "\n";
5260 //===============================================================================================
5261 //function : VUpdate
5263 //===============================================================================================
5264 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
5266 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5267 if (aContextAIS.IsNull())
5269 Message::SendFail ("Syntax error: AIS context is not available.");
5275 Message::SendFail ("Syntax error: insufficient arguments. Type help for more information.");
5279 AIS_ListOfInteractive aListOfIO;
5280 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5282 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
5284 Handle(AIS_InteractiveObject) anAISObj;
5285 GetMapOfAIS().Find2 (aName, anAISObj);
5286 if (anAISObj.IsNull())
5288 Message::SendFail() << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".";
5292 aListOfIO.Append (anAISObj);
5295 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
5296 for (; anIOIt.More(); anIOIt.Next())
5298 aContextAIS->Update (anIOIt.Value(), Standard_False);
5301 aContextAIS->UpdateCurrentViewer();
5306 //==============================================================================
5307 //function : VShading
5308 //purpose : Sharpen or roughten the quality of the shading
5309 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
5310 //==============================================================================
5311 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
5313 Standard_Real myDevCoef;
5314 Handle(AIS_InteractiveObject) TheAisIO;
5317 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
5321 myDevCoef =Draw::Atof(argv[2]);
5324 TCollection_AsciiString name=argv[1];
5325 GetMapOfAIS().Find2(name, TheAisIO);
5326 if (TheAisIO.IsNull())
5328 TopoDS_Shape aDrawShape = DBRep::GetExisting (name);
5329 if (!aDrawShape.IsNull())
5331 TheAisIO = new AIS_Shape (aDrawShape);
5336 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5338 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
5340 TheAISContext()->Redisplay (TheAisIO, Standard_True);
5344 //! Auxiliary method to print Interactive Object information
5345 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
5346 const Handle(AIS_InteractiveObject)& theObj,
5347 Draw_Interpretor& theDI)
5349 if (theObj.IsNull())
5351 theDI << "NULL presentation\n";
5355 theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ")
5356 << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ")
5357 << (theDetected.Contains (theObj) ? " Detected" : " ")
5359 if (theObj->Type() == AIS_KindOfInteractive_Datum)
5362 if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
5363 else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; }
5364 else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; }
5365 else if (theObj->Signature() == 5) { theDI << " AIS_Line"; }
5366 else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; }
5367 else if (theObj->Signature() == 1) { theDI << " AIS_Point"; }
5368 else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
5371 else if (theObj->Type() == AIS_KindOfInteractive_Shape
5372 && theObj->Signature() == 0)
5374 theDI << " AIS_Shape";
5376 else if (theObj->Type() == AIS_KindOfInteractive_Relation)
5378 // PrsDim_Dimension and AIS_Relation
5379 Handle(PrsDim_Relation) aRelation = Handle(PrsDim_Relation)::DownCast (theObj);
5380 switch (aRelation->KindOfDimension())
5382 case PrsDim_KOD_PLANEANGLE: theDI << " PrsDim_AngleDimension"; break;
5383 case PrsDim_KOD_LENGTH: theDI << " PrsDim_Chamf2/3dDimension/PrsDim_LengthDimension"; break;
5384 case PrsDim_KOD_DIAMETER: theDI << " PrsDim_DiameterDimension"; break;
5385 case PrsDim_KOD_ELLIPSERADIUS: theDI << " PrsDim_EllipseRadiusDimension"; break;
5386 //case PrsDim_KOD_FILLETRADIUS: theDI << " PrsDim_FilletRadiusDimension "; break;
5387 case PrsDim_KOD_OFFSET: theDI << " PrsDim_OffsetDimension"; break;
5388 case PrsDim_KOD_RADIUS: theDI << " PrsDim_RadiusDimension"; break;
5389 default: theDI << " UNKNOWN dimension"; break;
5394 theDI << " UserPrs";
5396 theDI << " (" << theObj->DynamicType()->Name() << ")";
5399 //! Print information about locally selected sub-shapes
5400 template <typename T>
5401 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
5403 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
5404 TCollection_AsciiString aPrevName;
5405 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
5407 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
5408 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
5409 if (aShapeIO.IsNull() || anOwner.IsNull())
5413 if (anOwner == aShapeIO->GlobalSelOwner())
5416 const TopoDS_Shape aSubShape = theContext->SelectedShape();
5417 if (aSubShape.IsNull()
5418 || aShapeIO.IsNull()
5419 || !GetMapOfAIS().IsBound1 (aShapeIO))
5424 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
5425 TopTools_MapOfShape aFilter;
5426 Standard_Integer aNumber = 0;
5427 const TopoDS_Shape aShape = aShapeIO->Shape();
5428 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
5429 anIter.More(); anIter.Next())
5431 if (!aFilter.Add (anIter.Current()))
5433 continue; // filter duplicates
5437 if (!anIter.Current().IsSame (aSubShape))
5442 Standard_CString aShapeName = NULL;
5443 switch (aSubShape.ShapeType())
5445 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
5446 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
5447 case TopAbs_SOLID: aShapeName = " Solid"; break;
5448 case TopAbs_SHELL: aShapeName = " Shell"; break;
5449 case TopAbs_FACE: aShapeName = " Face"; break;
5450 case TopAbs_WIRE: aShapeName = " Wire"; break;
5451 case TopAbs_EDGE: aShapeName = " Edge"; break;
5452 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
5454 case TopAbs_SHAPE: aShapeName = " Shape"; break;
5457 if (aParentName != aPrevName)
5459 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
5460 aPrevName = aParentName;
5462 theDI << " " << aShapeName << " #" << aNumber << "\n";
5468 //==============================================================================
5471 //==============================================================================
5472 static Standard_Integer VState (Draw_Interpretor& theDI,
5473 Standard_Integer theArgNb,
5474 Standard_CString* theArgVec)
5476 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
5479 Message::SendFail ("Error: No opened viewer!");
5483 Standard_Boolean toPrintEntities = Standard_False;
5484 Standard_Boolean toCheckSelected = Standard_False;
5486 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
5488 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
5489 anOption.LowerCase();
5490 if (anOption == "-detectedentities"
5491 || anOption == "-entities")
5493 toPrintEntities = Standard_True;
5495 else if (anOption == "-hasselected")
5497 toCheckSelected = Standard_True;
5501 if (toCheckSelected)
5503 aCtx->InitSelected();
5504 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
5505 theDI << "Check if context has selected shape: " << hasSelected << "\n";
5510 if (toPrintEntities)
5512 theDI << "Detected entities:\n";
5513 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
5515 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
5516 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
5518 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
5519 const Handle(Select3D_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
5520 const Handle(SelectMgr_EntityOwner)& anOwner = anEntity->OwnerId();
5521 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5523 TCollection_AsciiString aName;
5524 GetMapOfAIS().Find1 (anObj, aName);
5525 aName.LeftJustify (20, ' ');
5526 char anInfoStr[512];
5527 if (aPickData.Normal.SquareModulus() > ShortRealEpsilon())
5530 " Depth: %g Distance: %g Point: %g %g %g Normal: %g %g %g",
5533 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z(),
5534 aPickData.Normal.x(), aPickData.Normal.y(), aPickData.Normal.z());
5539 " Depth: %g Distance: %g Point: %g %g %g",
5542 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
5544 theDI << " " << aName
5546 << " (" << anEntity->DynamicType()->Name() << ")"
5549 if (Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner))
5551 theDI << " Detected Shape: "
5552 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
5556 if (Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity))
5558 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
5559 theDI << " Detected Child: "
5560 << aSen->DynamicType()->Name()
5563 else if (Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity))
5565 theDI << " Detected Element: "
5566 << aPrimArr->LastDetectedElement()
5569 else if (Handle(Select3D_SensitiveTriangulation) aTriSens = Handle(Select3D_SensitiveTriangulation)::DownCast (anEntity))
5571 theDI << " Detected Triangle: "
5572 << aTriSens->LastDetectedTriangleIndex()
5579 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
5580 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
5582 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
5585 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
5589 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5591 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
5592 Handle(AIS_InteractiveObject) anObj;
5593 if (!GetMapOfAIS().Find2 (anObjName, anObj))
5595 theDI << anObjName << " doesn't exist!\n";
5599 TCollection_AsciiString aName = anObjName;
5600 aName.LeftJustify (20, ' ');
5601 theDI << " " << aName << " ";
5602 objInfo (aDetected, anObj, theDI);
5608 if (aCtx->NbSelected() > 0 && !toShowAll)
5610 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
5611 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
5613 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
5614 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5615 // handle whole object selection
5616 if (anOwner == anObj->GlobalSelOwner())
5618 TCollection_AsciiString aName;
5619 GetMapOfAIS().Find1 (anObj, aName);
5620 aName.LeftJustify (20, ' ');
5621 theDI << aName << " ";
5622 objInfo (aDetected, anObj, theDI);
5627 // process selected sub-shapes
5628 printLocalSelectionInfo (aCtx, theDI);
5633 theDI << "Neutral-point state:\n";
5634 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5635 anObjIter.More(); anObjIter.Next())
5637 if (anObjIter.Key1().IsNull())
5642 TCollection_AsciiString aName = anObjIter.Key2();
5643 aName.LeftJustify (20, ' ');
5644 theDI << " " << aName << " ";
5645 objInfo (aDetected, anObjIter.Key1(), theDI);
5648 printLocalSelectionInfo (aCtx, theDI);
5652 //=======================================================================
5653 //function : PickShape
5654 //purpose : First Activate the rightmode + Put Filters to be able to
5655 // pick objets that are of type <TheType>...
5656 //=======================================================================
5658 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
5659 const Standard_Integer theMaxPick)
5661 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
5662 PickShapes (theShapeType, aResArray, theMaxPick);
5663 return aResArray->First();
5666 //=======================================================================
5667 //function : PickShapes
5669 //=======================================================================
5670 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
5671 Handle(TopTools_HArray1OfShape)& theResArray,
5672 const Standard_Integer theMaxPick)
5674 const Standard_Integer aNbToReach = theResArray->Length();
5677 Message::SendWarning ("WARNING : Pick with Shift+ MB1 for Selection of more than 1 object");
5680 // step 1: prepare the data
5681 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5684 Message::SendFail ("Error: no active viewer");
5685 return Standard_False;
5688 aCtx->RemoveFilters();
5689 AIS_ListOfInteractive aDispObjects;
5690 aCtx->DisplayedObjects (aDispObjects);
5691 if (theShapeType == TopAbs_SHAPE)
5693 aCtx->AddFilter (new AIS_TypeFilter (AIS_KindOfInteractive_Shape));
5697 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
5700 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
5701 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5703 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5705 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5709 // step 2 : wait for the selection...
5710 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
5711 Standard_Integer argccc = 5;
5712 const char *bufff[] = { "A", "B", "C", "D", "E" };
5713 const char **argvvv = (const char** )bufff;
5714 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
5716 while (ViewerMainLoop (argccc, argvvv)) {}
5717 Standard_Integer aNbStored = aCtx->NbSelected();
5718 if (aNbStored != aNbPickGood)
5720 aNbPickGood = aNbStored;
5726 Message::SendInfo() << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail;
5729 // step3 get result.
5730 if (aNbPickFail >= aNbToReach)
5732 return Standard_False;
5735 Standard_Integer anIndex = theResArray->Lower();
5736 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
5738 if (aCtx->HasSelectedShape())
5740 theResArray->SetValue (anIndex, aCtx->SelectedShape());
5744 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
5745 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
5749 aCtx->RemoveFilters();
5750 if (theShapeType != TopAbs_SHAPE)
5752 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5754 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5756 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5760 return Standard_True;
5763 //=======================================================================
5764 //function : VPickShape
5766 //=======================================================================
5767 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5769 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
5772 TCollection_AsciiString aShapeArg (argv[1]);
5773 aShapeArg.LowerCase();
5774 aShapeType = TopAbs_COMPOUND;
5775 if (aShapeArg == "v"
5776 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
5777 else if (aShapeArg == "e"
5778 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
5779 else if (aShapeArg == "w"
5780 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
5781 else if (aShapeArg == "f"
5782 || aShapeArg == "face") aShapeType = TopAbs_FACE;
5783 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
5784 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
5785 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
5788 Message::SendFail() << "Syntax error at '" << argv[1] << "'";
5793 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5794 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
5796 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
5799 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
5800 if (aPickedShape.IsNull())
5805 TCollection_AsciiString aName;
5812 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5813 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5816 DBRep::Set (aName.ToCString(), aPickedShape);
5817 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5818 ViewerTest::Display (aName, aShapePrs, false, true);
5819 di << "Name of picked shape: " << aName <<"\n";
5823 TCollection_AsciiString aName (argv[2]);
5825 const Standard_Boolean isAutoNaming = aName == ".";
5826 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5827 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5829 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5831 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5833 if (!aPickedShape.IsNull()
5836 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5837 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5841 aName = argv[1 + aPickedIter];
5844 DBRep::Set (aName.ToCString(), aPickedShape);
5845 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5846 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5847 ViewerTest::Display (aName, aShapePrs, false, true);
5851 TheAISContext()->UpdateCurrentViewer();
5855 //=======================================================================
5856 //function : VSelFilter
5858 //=======================================================================
5859 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5860 const char** theArgv)
5862 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5863 if (aContext.IsNull())
5865 Message::SendFail ("Error: AIS context is not available.");
5869 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5871 TCollection_AsciiString anArg (theArgv[anArgIter]);
5873 if (anArg == "-clear")
5875 aContext->RemoveFilters();
5877 else if (anArg == "-contextfilter" && anArgIter + 1 < theArgc)
5879 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5883 aContext->SetFilterType (SelectMgr_FilterType_AND);
5885 else if (aVal == "or")
5887 aContext->SetFilterType (SelectMgr_FilterType_OR);
5891 Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'";
5895 else if (anArg == "-type"
5896 && anArgIter + 1 < theArgc)
5898 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5899 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5900 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5902 Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'";
5906 Handle(SelectMgr_Filter) aFilter;
5907 if (aShapeType == TopAbs_SHAPE)
5909 aFilter = new AIS_TypeFilter (AIS_KindOfInteractive_Shape);
5913 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5915 aContext->AddFilter (aFilter);
5917 else if (anArg == "-secondtype"
5918 && anArgIter + 1 < theArgc)
5920 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5921 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5922 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5924 Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'";
5928 Handle(SelectMgr_Filter) aFilter;
5929 if (aShapeType == TopAbs_SHAPE)
5931 aFilter = new AIS_TypeFilter (AIS_KindOfInteractive_Shape);
5935 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5937 aContext->AddFilter (aFilter);
5941 Message::SendFail() << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'";
5948 //=======================================================================
5949 //function : VPickSelected
5951 //=======================================================================
5952 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5954 static Standard_Integer aCount = 0;
5955 TCollection_AsciiString aName = "PickedShape_";
5963 aName = aName + aCount++ + "_";
5966 Standard_Integer anIdx = 0;
5967 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5969 TopoDS_Shape aShape;
5970 if (TheAISContext()->HasSelectedShape())
5972 aShape = TheAISContext()->SelectedShape();
5976 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5977 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5980 TCollection_AsciiString aCurrentName = aName;
5983 aCurrentName += anIdx;
5986 DBRep::Set ((aCurrentName).ToCString(), aShape);
5988 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5989 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5990 TheAISContext()->Display (aNewShape, Standard_False);
5993 TheAISContext()->UpdateCurrentViewer();
5998 //=======================================================================
5999 //function : list of known objects
6001 //=======================================================================
6002 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
6004 // 1234567890 12345678901234567 123456789
6005 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
6006 TCollection_AsciiString BlankLine(64,'_');
6007 Standard_Integer i ;
6009 di<<"/n"<<BlankLine.ToCString()<<"\n";
6012 Colum[i].Center(20,' ');
6014 di<<"|"<<Colum[i].ToCString();
6017 di<<BlankLine.ToCString()<<"\n";
6019 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
6020 const char ** names = GetTypeNames();
6022 TCollection_AsciiString curstring;
6023 TCollection_AsciiString curcolum[3];
6026 // les objets de type Datum..
6027 curcolum[1]+="Datum";
6029 curcolum[0].Clear();
6030 curcolum[0] += names[i];
6032 curcolum[2].Clear();
6033 curcolum[2]+=TCollection_AsciiString(i+1);
6035 for(Standard_Integer j =0;j<=2;j++){
6036 curcolum[j].Center(20,' ');
6037 di<<"|"<<curcolum[j].ToCString();
6041 di<<BlankLine.ToCString()<<"\n";
6043 // les objets de type shape
6044 curcolum[1].Clear();
6045 curcolum[1]+="Shape";
6046 curcolum[1].Center(20,' ');
6049 curcolum[0].Clear();
6050 curcolum[0] += names[7+i];
6051 curcolum[2].Clear();
6052 curcolum[2]+=TCollection_AsciiString(i);
6054 for(Standard_Integer j =0;j<=2;j++){
6055 curcolum[j].Center(20,' ');
6056 di<<"|"<<curcolum[j].ToCString();
6060 di<<BlankLine.ToCString()<<"\n";
6061 // les IO de type objet...
6062 curcolum[1].Clear();
6063 curcolum[1]+="Object";
6064 curcolum[1].Center(20,' ');
6066 curcolum[0].Clear();
6067 curcolum[0] += names[10+i];
6068 curcolum[2].Clear();
6069 curcolum[2]+=TCollection_AsciiString(i);
6071 for(Standard_Integer j =0;j<=2;j++){
6072 curcolum[j].Center(20,' ');
6073 di<<"|"<<curcolum[j].ToCString();
6077 di<<BlankLine.ToCString()<<"\n";
6078 // les contraintes et dimensions.
6079 // pour l'instant on separe juste contraintes et dimensions...
6080 // plus tard, on detaillera toutes les sortes...
6081 curcolum[1].Clear();
6082 curcolum[1]+="Relation";
6083 curcolum[1].Center(20,' ');
6085 curcolum[0].Clear();
6086 curcolum[0] += names[12+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";
6103 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
6105 if(argc!=2) return 1;
6107 AIS_KindOfInteractive TheType;
6108 Standard_Integer TheSign(-1);
6109 GetTypeAndSignfromString(argv[1],TheType,TheSign);
6112 AIS_ListOfInteractive LIO;
6114 // en attendant l'amelioration ais pour les dimensions...
6116 Standard_Integer dimension_status(-1);
6117 if (TheType==AIS_KindOfInteractive_Relation)
6119 dimension_status = TheSign == 1 ? 1 : 0;
6123 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
6124 Handle(AIS_InteractiveObject) curio;
6125 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
6128 if(dimension_status == -1)
6129 TheAISContext()->Erase(curio,Standard_False);
6131 PrsDim_KindOfDimension KOD = Handle(PrsDim_Relation)::DownCast (curio)->KindOfDimension();
6132 if ((dimension_status==0 && KOD == PrsDim_KOD_NONE)||
6133 (dimension_status==1 && KOD != PrsDim_KOD_NONE))
6134 TheAISContext()->Erase(curio,Standard_False);
6137 TheAISContext()->UpdateCurrentViewer();
6140 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
6142 if(argc!=2) return 1;
6144 AIS_KindOfInteractive TheType;
6145 Standard_Integer TheSign(-1);
6146 GetTypeAndSignfromString(argv[1],TheType,TheSign);
6148 // en attendant l'amelioration ais pour les dimensions...
6150 Standard_Integer dimension_status(-1);
6151 if (TheType==AIS_KindOfInteractive_Relation)
6153 dimension_status = TheSign == 1 ? 1 : 0;
6157 AIS_ListOfInteractive LIO;
6158 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
6159 Handle(AIS_InteractiveObject) curio;
6160 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
6162 if(dimension_status == -1)
6163 TheAISContext()->Display(curio,Standard_False);
6165 PrsDim_KindOfDimension KOD = Handle(PrsDim_Relation)::DownCast (curio)->KindOfDimension();
6166 if ((dimension_status==0 && KOD == PrsDim_KOD_NONE)||
6167 (dimension_status==1 && KOD != PrsDim_KOD_NONE))
6168 TheAISContext()->Display(curio,Standard_False);
6173 TheAISContext()->UpdateCurrentViewer();
6177 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
6179 std::ifstream s(a[1]);
6180 BRep_Builder builder;
6182 BRepTools::Read(shape, s, builder);
6183 DBRep::Set(a[1], shape);
6184 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6185 Handle(AIS_Shape) ais = new AIS_Shape(shape);
6186 Ctx->Display (ais, Standard_True);
6190 //===============================================================================================
6193 //===============================================================================================
6194 static int VBsdf (Draw_Interpretor& theDI,
6195 Standard_Integer theArgsNb,
6196 const char** theArgVec)
6198 Handle(V3d_View) aView = ViewerTest::CurrentView();
6199 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6201 || aViewer.IsNull())
6203 Message::SendFail ("Error: No active viewer!");
6207 ViewerTest_CmdParser aCmd;
6209 aCmd.SetDescription ("Adjusts parameters of material BSDF:");
6211 aCmd.AddOption ("print|echo|p", "Prints BSDF");
6213 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
6215 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
6216 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
6217 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
6218 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
6219 aCmd.AddOption ("le", "Radiance emitted by surface");
6221 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
6222 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
6224 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
6225 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
6227 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
6228 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
6230 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
6232 aCmd.Parse (theArgsNb, theArgVec);
6234 if (aCmd.HasOption ("help"))
6236 theDI.PrintHelp (theArgVec[0]);
6240 // check viewer update mode
6241 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
6242 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6244 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
6251 TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
6252 Handle(AIS_InteractiveObject) anIObj;
6253 if (!GetMapOfAIS().Find2 (aName, anIObj))
6255 Message::SendFail ("Error: no active viewer");
6259 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
6260 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
6262 if (aCmd.HasOption ("print"))
6265 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
6266 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
6267 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
6268 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
6269 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
6271 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6273 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
6274 : aBSDF.FresnelBase.Serialize();
6276 theDI << (aLayerID < 1 ? "Coat Fresnel: "
6277 : "Base Fresnel: ");
6279 if (aFresnel.x() >= 0.f)
6281 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
6282 << "G = " << aFresnel.g() << ", "
6283 << "B = " << aFresnel.b() << "\n";
6285 else if (aFresnel.x() >= -1.5f)
6287 theDI << "Constant " << aFresnel.z() << "\n";
6289 else if (aFresnel.x() >= -2.5f)
6291 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
6292 << "K = " << aFresnel.z() << "\n";
6296 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
6300 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
6301 << "Base roughness: " << aBSDF.Ks.w() << "\n"
6302 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
6303 << "Absorption color: " << aBSDF.Absorption.r() << ", "
6304 << aBSDF.Absorption.g() << ", "
6305 << aBSDF.Absorption.b() << "\n";
6310 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
6312 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
6315 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
6317 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
6320 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
6322 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
6325 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
6327 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
6329 aBSDF.Absorption.r() = aRGB.r();
6330 aBSDF.Absorption.g() = aRGB.g();
6331 aBSDF.Absorption.b() = aRGB.b();
6334 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
6338 if (aCmd.HasOption ("kc", 3))
6340 aKc = aCmd.ArgVec3f ("kc");
6344 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
6347 aBSDF.Kc.r() = aKc.r();
6348 aBSDF.Kc.g() = aKc.g();
6349 aBSDF.Kc.b() = aKc.b();
6352 if (aCmd.HasOption ("kd", 3))
6354 aBSDF.Kd = aCmd.ArgVec3f ("kd");
6356 else if (aCmd.HasOption ("kd", 1, Standard_True))
6358 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
6361 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
6365 if (aCmd.HasOption ("ks", 3))
6367 aKs = aCmd.ArgVec3f ("ks");
6371 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
6374 aBSDF.Ks.r() = aKs.r();
6375 aBSDF.Ks.g() = aKs.g();
6376 aBSDF.Ks.b() = aKs.b();
6379 if (aCmd.HasOption ("kt", 3))
6381 aBSDF.Kt = aCmd.ArgVec3f ("kt");
6383 else if (aCmd.HasOption ("kt", 1, Standard_True))
6385 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
6388 if (aCmd.HasOption ("le", 3))
6390 aBSDF.Le = aCmd.ArgVec3f ("le");
6392 else if (aCmd.HasOption ("le", 1, Standard_True))
6394 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
6397 const std::string aFresnelErrorMessage =
6398 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
6400 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
6402 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
6405 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
6407 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6408 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6410 if (aFresnelType == "schlick")
6412 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
6413 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
6414 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
6416 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
6417 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
6418 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
6420 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
6424 theDI << aFresnelErrorMessage.c_str() << "\n";
6427 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
6429 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6430 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6432 if (aFresnelType == "conductor")
6434 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6435 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
6437 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
6441 theDI << aFresnelErrorMessage.c_str() << "\n";
6444 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
6446 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
6447 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
6449 if (aFresnelType == "constant")
6451 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6453 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
6455 else if (aFresnelType == "dielectric")
6457 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6459 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
6463 theDI << aFresnelErrorMessage.c_str() << "\n";
6468 if (aCmd.HasOption ("normalize"))
6473 aMaterial.SetBSDF (aBSDF);
6474 anIObj->SetMaterial (aMaterial);
6479 //==============================================================================
6480 //function : VLoadSelection
6481 //purpose : Adds given objects to map of AIS and loads selection primitives for them
6482 //==============================================================================
6483 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
6484 Standard_Integer theArgNb,
6485 const char** theArgVec)
6489 Message::SendFail ("Syntax error: wrong number of arguments.");
6493 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
6496 ViewerTest::ViewerInit();
6497 aCtx = ViewerTest::GetAISContext();
6500 // Parse input arguments
6501 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6503 const TCollection_AsciiString aName = theArgVec[anArgIter];
6504 Handle(AIS_InteractiveObject) aShape;
6505 if (!GetMapOfAIS().Find2 (aName, aShape))
6507 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
6508 if (!aDrawShape.IsNull())
6510 aShape = new AIS_Shape (aDrawShape);
6511 GetMapOfAIS().Bind (aShape, aName);
6514 if (aShape.IsNull())
6516 Message::SendFail() << "Syntax error: presentation '" << aName << "' not found";
6520 aCtx->Load (aShape, -1);
6521 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
6526 //==============================================================================
6527 //function : ViewerTest::Commands
6528 //purpose : Add all the viewer command in the Draw_Interpretor
6529 //==============================================================================
6531 void ViewerTest::Commands(Draw_Interpretor& theCommands)
6533 ViewerTest::ViewerCommands(theCommands);
6534 ViewerTest::RelationCommands(theCommands);
6535 ViewerTest::ObjectCommands(theCommands);
6536 ViewerTest::FilletCommands(theCommands);
6537 ViewerTest::OpenGlCommands(theCommands);
6539 const char *group = "AIS_Display";
6542 theCommands.Add("visos",
6543 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
6544 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
6545 __FILE__, visos, group);
6547 theCommands.Add("vdisplay",
6548 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
6549 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
6550 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
6551 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
6552 "\n\t\t: |topRight|bottomLeft|bottomRight}"
6553 "\n\t\t: [offsetX offsetY]]]"
6554 "\n\t\t: [-dispMode mode] [-highMode mode]"
6555 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
6556 "\n\t\t: [-redisplay] [-erased]"
6558 "\n\t\t: name1 [name2] ... [name n]"
6559 "\n\t\t: Displays named objects."
6560 "\n\t\t: Option -local enables displaying of objects in local"
6561 "\n\t\t: selection context. Local selection context will be opened"
6562 "\n\t\t: if there is not any."
6563 "\n\t\t: -noupdate Suppresses viewer redraw call."
6564 "\n\t\t: -mutable Enables optimizations for mutable objects."
6565 "\n\t\t: -neutral Draws objects in main viewer."
6566 "\n\t\t: -erased Loads the object into context, but does not display it."
6567 "\n\t\t: -layer Sets z-layer for objects."
6568 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
6569 "\n\t\t: options can be used for the default z-layers."
6570 "\n\t\t: -top Draws object on top of main presentations"
6571 "\n\t\t: but below topmost."
6572 "\n\t\t: -topmost Draws in overlay for 3D presentations."
6573 "\n\t\t: with independent Depth."
6574 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
6575 "\n\t\t: (On-Screen-Display)"
6576 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
6577 "\n\t\t: (On-Screen-Display)"
6578 "\n\t\t: -selectable|-noselect Controls selection of objects."
6579 "\n\t\t: -trsfPers Sets a transform persistence flags."
6580 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
6581 "\n\t\t: -2d Displays object in screen coordinates."
6582 "\n\t\t: (DY looks up)"
6583 "\n\t\t: -dispmode Sets display mode for objects."
6584 "\n\t\t: -highmode Sets hilight mode for objects."
6585 "\n\t\t: -redisplay Recomputes presentation of objects."
6586 "\n\t\t: -noecho Avoid printing of command results.",
6587 __FILE__, VDisplay2, group);
6589 theCommands.Add ("vnbdisplayed",
6591 "\n\t\t: Returns number of displayed objects",
6592 __FILE__, VNbDisplayed, group);
6594 theCommands.Add ("vupdate",
6595 "vupdate name1 [name2] ... [name n]"
6596 "\n\t\t: Updates named objects in interactive context",
6597 __FILE__, VUpdate, group);
6599 theCommands.Add("verase",
6600 "verase [-noupdate|-update] [-local] [name1] ... [name n] [-noerror]"
6601 "\n\t\t: Erases selected or named objects."
6602 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
6603 "\n\t\t: Option -local enables erasing of selected or named objects without"
6604 "\n\t\t: closing local selection context."
6605 "\n\t\t: Option -noerror prevents exception on non-existing objects.",
6606 __FILE__, VErase, group);
6608 theCommands.Add("vremove",
6609 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n] [-noerror]"
6610 "or vremove [-context] -all to remove all objects"
6611 "\n\t\t: Removes selected or named objects."
6612 "\n\t\t If -context is in arguments, the objects are not deleted"
6613 "\n\t\t from the map of objects and names."
6614 "\n\t\t: Option -local enables removing of selected or named objects without"
6615 "\n\t\t: closing local selection context. Empty local selection context will be"
6617 "\n\t\t: Option -noupdate suppresses viewer redraw call."
6618 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects."
6619 "\n\t\t: Option -noerror prevents exception on non-existing objects.",
6620 __FILE__, VRemove, group);
6622 theCommands.Add("vdonly",
6623 "vdonly [-noupdate|-update] [name1] ... [name n]"
6624 "\n\t\t: Displays only selected or named objects",
6625 __FILE__,VDonly2,group);
6627 theCommands.Add("vdisplayall",
6629 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
6630 __FILE__, VDisplayAll, group);
6632 theCommands.Add("veraseall",
6634 "\n\t\t: Erases all objects displayed in the viewer.",
6635 __FILE__, VErase, group);
6637 theCommands.Add("verasetype",
6639 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
6640 __FILE__, VEraseType, group);
6641 theCommands.Add("vbounding",
6642 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
6643 "\n\t\t: [-print] [-hide]"
6644 "\n\t\t: Temporarily display bounding box of specified Interactive"
6645 "\n\t\t: Objects, or print it to console if -print is specified."
6646 "\n\t\t: Already displayed box might be hidden by -hide option.",
6647 __FILE__,VBounding,group);
6649 theCommands.Add("vdisplaytype",
6650 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
6651 __FILE__,VDisplayType,group);
6653 theCommands.Add("vsetdispmode",
6654 "vsetdispmode [name] mode(1,2,..)"
6655 "\n\t\t: Sets display mode for all, selected or named objects.",
6656 __FILE__,VDispMode,group);
6658 theCommands.Add("vunsetdispmode",
6659 "vunsetdispmode [name]"
6660 "\n\t\t: Unsets custom display mode for selected or named objects.",
6661 __FILE__,VDispMode,group);
6663 theCommands.Add("vdir",
6664 "vdir [mask] [-list]"
6665 "\n\t\t: Lists all objects displayed in 3D viewer"
6666 "\n\t\t: mask - name filter like prefix*"
6667 "\n\t\t: -list - format list with new-line per name; OFF by default",
6668 __FILE__,VDir,group);
6670 #ifdef HAVE_FREEIMAGE
6671 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
6673 #define DUMP_FORMATS "{ppm}"
6675 theCommands.Add("vdump",
6676 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
6677 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
6678 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
6679 "\n\t\t: [-xrPose base|head|handLeft|handRight=base]"
6680 "\n\t\t: [-tileSize Size=0]"
6681 "\n\t\t: Dumps content of the active view into image file",
6682 __FILE__,VDump,group);
6684 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
6685 __FILE__,VSubInt,group);
6687 theCommands.Add("vaspects",
6688 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults] [-subshapes subname1 [subname2 [...]]]"
6689 "\n\t\t: [-visibility {0|1}]"
6690 "\n\t\t: [-color {ColorName | R G B}] [-unsetColor]"
6691 "\n\t\t: [-backfaceColor Color]"
6692 "\n\t\t: [-material MatName] [-unsetMaterial]"
6693 "\n\t\t: [-transparency Transp] [-unsetTransparency]"
6694 "\n\t\t: [-width LineWidth] [-unsetWidth]"
6695 "\n\t\t: [-lineType {solid|dash|dot|dotDash|0xHexPattern} [-stippleFactor factor]]"
6696 "\n\t\t: [-unsetLineType]"
6697 "\n\t\t: [-markerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
6698 "\n\t\t: [-unsetMarkerType]"
6699 "\n\t\t: [-markerSize Scale] [-unsetMarkerSize]"
6700 "\n\t\t: [-freeBoundary {0|1}]"
6701 "\n\t\t: [-freeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
6702 "\n\t\t: [-freeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
6703 "\n\t\t: [-isoOnTriangulation 0|1]"
6704 "\n\t\t: [-maxParamValue {value}]"
6705 "\n\t\t: [-sensitivity {selection_mode} {value}]"
6706 "\n\t\t: [-shadingModel {unlit|flat|gouraud|phong|pbr|pbr_facet}]"
6707 "\n\t\t: [-unsetShadingModel]"
6708 "\n\t\t: [-interior {solid|hatch|hidenline|point}] [-setHatch HatchStyle]"
6709 "\n\t\t: [-unsetInterior]"
6710 "\n\t\t: [-faceBoundaryDraw {0|1}] [-mostContinuity {c0|g1|c1|g2|c2|c3|cn}]"
6711 "\n\t\t: [-faceBoundaryWidth LineWidth] [-faceBoundaryColor R G B] [-faceBoundaryType LineType]"
6712 "\n\t\t: [-drawEdges {0|1}] [-edgeType LineType] [-edgeColor R G B] [-quadEdges {0|1}]"
6713 "\n\t\t: [-drawSilhouette {0|1}]"
6714 "\n\t\t: [-alphaMode {opaque|mask|blend|maskblend|blendauto} [alphaCutOff=0.5]]"
6715 "\n\t\t: [-dumpJson]"
6716 "\n\t\t: [-dumpCompact {0|1}]"
6717 "\n\t\t: [-dumpDepth depth]"
6718 "\n\t\t: Manage presentation properties of all, selected or named objects."
6719 "\n\t\t: When -subshapes is specified than following properties will be assigned to specified sub-shapes."
6720 "\n\t\t: When -defaults is specified than presentation properties will be"
6721 "\n\t\t: assigned to all objects that have not their own specified properties"
6722 "\n\t\t: and to all objects to be displayed in the future."
6723 "\n\t\t: If -defaults is used there should not be any objects' names nor -subshapes specifier."
6724 "\n\t\t: See also vlistcolors and vlistmaterials to list named colors and materials"
6725 "\n\t\t: accepted by arguments -material and -color",
6726 __FILE__,VAspects,group);
6728 theCommands.Add("vsetcolor",
6729 "vsetcolor [-noupdate|-update] [name] ColorName"
6730 "\n\t\t: Sets color for all, selected or named objects."
6731 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
6732 __FILE__,VAspects,group);
6734 theCommands.Add("vunsetcolor",
6735 "vunsetcolor [-noupdate|-update] [name]"
6736 "\n\t\t: Resets color for all, selected or named objects."
6737 "\n\t\t: Alias for vaspects -unsetcolor [name].",
6738 __FILE__,VAspects,group);
6740 theCommands.Add("vsettransparency",
6741 "vsettransparency [-noupdate|-update] [name] Coefficient"
6742 "\n\t\t: Sets transparency for all, selected or named objects."
6743 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
6744 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
6745 __FILE__,VAspects,group);
6747 theCommands.Add("vunsettransparency",
6748 "vunsettransparency [-noupdate|-update] [name]"
6749 "\n\t\t: Resets transparency for all, selected or named objects."
6750 "\n\t\t: Alias for vaspects -unsettransp [name].",
6751 __FILE__,VAspects,group);
6753 theCommands.Add("vsetmaterial",
6754 "vsetmaterial [-noupdate|-update] [name] MaterialName"
6755 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
6756 __FILE__,VAspects,group);
6758 theCommands.Add("vunsetmaterial",
6759 "vunsetmaterial [-noupdate|-update] [name]"
6760 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
6761 __FILE__,VAspects,group);
6763 theCommands.Add("vsetwidth",
6764 "vsetwidth [-noupdate|-update] [name] width(0->10)"
6765 "\n\t\t: Alias for vaspects -setwidth [name] width.",
6766 __FILE__,VAspects,group);
6768 theCommands.Add("vunsetwidth",
6769 "vunsetwidth [-noupdate|-update] [name]"
6770 "\n\t\t: Alias for vaspects -unsetwidth [name].",
6771 __FILE__,VAspects,group);
6773 theCommands.Add("vsetinteriorstyle",
6774 "vsetinteriorstyle [-noupdate|-update] [name] Style"
6775 "\n\t\t: Alias for vaspects -setInterior [name] Style.",
6776 __FILE__,VAspects,group);
6778 theCommands.Add ("vsetedgetype",
6779 "vsetedgetype [name] [-type {solid, dash, dot}] [-color R G B] [-width value]"
6780 "\n\t\t: Alias for vaspects [name] -setEdgeType Type.",
6781 __FILE__, VAspects, group);
6783 theCommands.Add ("vunsetedgetype",
6784 "vunsetedgetype [name]"
6785 "\n\t\t: Alias for vaspects [name] -unsetEdgeType.",
6786 __FILE__, VAspects, group);
6788 theCommands.Add ("vshowfaceboundary",
6789 "vshowfaceboundary [name]"
6790 "\n\t\t: Alias for vaspects [name] -setFaceBoundaryDraw on",
6791 __FILE__, VAspects, group);
6793 theCommands.Add("vsensdis",
6794 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
6795 "\n\t\t: Standard entity types are those defined in Select3D package:"
6796 "\n\t\t: - sensitive box"
6797 "\n\t\t: - sensitive face"
6798 "\n\t\t: - sensitive curve"
6799 "\n\t\t: - sensitive segment"
6800 "\n\t\t: - sensitive circle"
6801 "\n\t\t: - sensitive point"
6802 "\n\t\t: - sensitive triangulation"
6803 "\n\t\t: - sensitive triangle"
6804 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
6805 __FILE__,VDispSensi,group);
6807 theCommands.Add("vsensera",
6808 "vsensera : erase active entities",
6809 __FILE__,VClearSensi,group);
6811 theCommands.Add("vsetshading",
6812 "vsetshading : vsetshading name Quality(default=0.0008) "
6813 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
6814 __FILE__,VShading,group);
6816 theCommands.Add("vunsetshading",
6817 "vunsetshading :vunsetshading name "
6818 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
6819 __FILE__,VShading,group);
6821 theCommands.Add ("vtexture",
6822 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
6823 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
6824 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
6825 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
6826 "\n\t\t: [-modulate {on|off}] [-srgb {on|off}]=on"
6827 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
6828 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
6829 "\n\t\t: [-default]"
6830 "\n\t\t: The texture can be specified by filepath"
6831 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
6832 "\n\t\t: The options are:"
6833 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
6834 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
6835 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
6836 "\n\t\t: -modulate Enable or disable texture color modulation"
6837 "\n\t\t: -srgb Prefer sRGB texture format when applicable; TRUE by default"
6838 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
6839 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
6840 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
6841 "\n\t\t: -setFilter Setup texture filter"
6842 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
6843 "\n\t\t: -default Sets texture mapping default parameters",
6844 __FILE__, VTexture, group);
6846 theCommands.Add("vtexscale",
6847 "vtexscale name ScaleU ScaleV"
6848 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
6849 __FILE__,VTexture,group);
6851 theCommands.Add("vtexorigin",
6852 "vtexorigin name OriginU OriginV"
6853 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
6854 __FILE__,VTexture,group);
6856 theCommands.Add("vtexrepeat",
6857 "vtexrepeat name RepeatU RepeatV"
6858 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
6861 theCommands.Add("vtexdefault",
6863 "\n\t\t: Alias for vtexture name -default.",
6866 theCommands.Add("vstate",
6867 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6868 "\n\t\t: Reports show/hidden state for selected or named objects"
6869 "\n\t\t: -entities - print low-level information about detected entities"
6870 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6871 __FILE__,VState,group);
6873 theCommands.Add("vpickshapes",
6874 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6875 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6876 "\n\t\t: Hold also Shift for multiple selection.",
6877 __FILE__, VPickShape, group);
6879 theCommands.Add("vtypes",
6880 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6883 theCommands.Add("vr",
6885 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6886 __FILE__,vr, group);
6888 theCommands.Add("vselfilter",
6889 "vselfilter [-contextfilter {AND|OR}]"
6890 "\n [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}]"
6891 "\n [-secondtype {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}]"
6893 "\nSets selection shape type filter in context or remove all filters."
6894 "\n : Option -contextfilter : To define a selection filter for two or more types of entity,"
6895 "\n use value AND (OR by default)."
6896 "\n : Option -type set type of selection filter. Filters are applied with Or combination."
6897 "\n : Option -clear remove all filters in context",
6898 __FILE__,VSelFilter,group);
6900 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6901 __FILE__, VPickSelected, group);
6903 theCommands.Add ("vloadselection",
6904 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6905 "\n\t\t: primitives for the shapes with names given without displaying them.",
6906 __FILE__, VLoadSelection, group);
6908 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6909 "\nAdjusts parameters of material BSDF:"
6910 "\n -help : Shows this message"
6911 "\n -print : Print BSDF"
6912 "\n -kd : Weight of the Lambertian BRDF"
6913 "\n -kr : Weight of the reflection BRDF"
6914 "\n -kt : Weight of the transmission BTDF"
6915 "\n -ks : Weight of the glossy Blinn BRDF"
6916 "\n -le : Self-emitted radiance"
6917 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6918 "\n Schlick x y z, Dielectric x, Conductor x y"
6919 "\n -roughness : Roughness of material (Blinn's exponent)"
6920 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6921 "\n -absorpcolor : Absorption color (only for transparent material)"
6922 "\n -normalize : Normalize BSDF coefficients",
6923 __FILE__, VBsdf, group);
6927 //=====================================================================
6928 //========================= for testing Draft and Rib =================
6929 //=====================================================================
6930 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6931 #include <DBRep.hxx>
6932 #include <TopoDS_Face.hxx>
6933 #include <gp_Pln.hxx>
6934 #include <BRepOffsetAPI_DraftAngle.hxx>
6935 #include <Precision.hxx>
6936 #include <BRepAlgo.hxx>
6937 #include <OSD_Environment.hxx>
6938 #include <DrawTrSurf.hxx>
6940 //=======================================================================
6941 //function : IsValid
6943 //=======================================================================
6944 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6945 const TopoDS_Shape& theResult,
6946 const Standard_Boolean closedSolid,
6947 const Standard_Boolean GeomCtrl)
6949 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6950 TCollection_AsciiString checkValid = check.Value();
6951 Standard_Boolean ToCheck = Standard_True;
6952 if (!checkValid.IsEmpty()) {
6954 std::cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6956 if ( checkValid=="true" || checkValid=="TRUE" ) {
6957 ToCheck= Standard_False;
6961 std::cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6964 Standard_Boolean IsValid = Standard_True;
6966 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6971 //===============================================================================
6972 // TDraft : test draft, uses AIS Viewer
6973 // Solid Face Plane Angle Reverse
6974 //===============================================================================
6975 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6977 if (argc < 5) return 1;
6978 // argv[1] - TopoDS_Shape Solid
6979 // argv[2] - TopoDS_Shape Face
6980 // argv[3] - TopoDS_Shape Plane
6981 // argv[4] - Standard_Real Angle
6982 // argv[5] - Standard_Integer Reverse
6984 // Sprintf(prefix, argv[1]);
6985 Standard_Real anAngle = 0;
6986 Standard_Boolean Rev = Standard_False;
6987 Standard_Integer rev = 0;
6988 TopoDS_Shape Solid = DBRep::Get (argv[1]);
6989 TopoDS_Shape face = DBRep::Get (argv[2]);
6990 TopoDS_Face Face = TopoDS::Face(face);
6991 TopoDS_Shape Plane = DBRep::Get (argv[3]);
6992 if (Plane.IsNull ()) {
6993 di << "TEST : Plane is NULL\n";
6996 anAngle = Draw::Atof(argv[4]);
6997 anAngle = 2*M_PI * anAngle / 360.0;
6999 Handle( Geom_Surface )aSurf;
7000 PrsDim_KindOfSurface aSurfType;
7001 Standard_Real Offset;
7003 if(argc > 4) { // == 5
7004 rev = Draw::Atoi(argv[5]);
7005 Rev = (rev)? Standard_True : Standard_False;
7008 TopoDS_Face face2 = TopoDS::Face(Plane);
7009 if(!PrsDim::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
7011 di << "TEST : Can't find plane\n";
7015 aDir = aPln.Axis().Direction();
7018 if (Plane.Orientation() == TopAbs_REVERSED)
7020 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
7022 BRepOffsetAPI_DraftAngle Draft (Solid);
7024 if(Abs(anAngle)< Precision::Angular()) {
7025 di << "TEST : NULL angle\n";
7028 if(Rev) anAngle = - anAngle;
7029 Draft.Add (Face, aDir, anAngle, aPln);
7031 if (!Draft.IsDone()) {
7032 di << "TEST : Draft Not DONE \n";
7035 TopTools_ListOfShape Larg;
7037 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
7038 di << "TEST : DesignAlgo returns Not valid\n";
7042 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
7043 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
7045 if ( !ais.IsNull() ) {
7046 ais->SetColor(DEFAULT_COLOR);
7047 ais->SetMaterial(DEFAULT_MATERIAL);
7048 // Display the AIS_Shape without redraw
7049 Ctx->Display(ais, Standard_False);
7051 const char *Name = "draft1";
7052 Handle(AIS_InteractiveObject) an_object;
7053 if (GetMapOfAIS().Find2(Name, an_object))
7055 if (!an_object.IsNull())
7057 Ctx->Remove (an_object, Standard_True);
7059 GetMapOfAIS().UnBind2 (Name);
7061 GetMapOfAIS().Bind(ais, Name);
7062 // DBRep::Set("draft", ais->Shape());
7064 Ctx->Display(ais, Standard_True);
7068 //==============================================================================
7069 //function : splitParameter
7070 //purpose : Split parameter string to parameter name and parameter value
7071 //==============================================================================
7072 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
7073 TCollection_AsciiString& theName,
7074 TCollection_AsciiString& theValue)
7076 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
7078 if (aParamNameEnd == 0)
7080 return Standard_False;
7083 TCollection_AsciiString aString (theString);
7084 if (aParamNameEnd != 0)
7086 theValue = aString.Split (aParamNameEnd);
7087 aString.Split (aString.Length() - 1);
7091 return Standard_True;
7094 //============================================================================
7096 //============================================================================
7097 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
7100 DrawTrSurf::BasicCommands(theCommands);
7101 const char* group = "Check Features Operations commands";
7103 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
7105 &TDraft,group); //Draft_Modification
7108 //==============================================================================
7109 // ViewerTest::Factory
7110 //==============================================================================
7111 void ViewerTest::Factory(Draw_Interpretor& theDI)
7113 // definition of Viewer Command
7114 ViewerTest::Commands(theDI);
7117 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
7121 // Declare entry point PLUGINFACTORY