1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Standard_Stream.hxx>
19 #include <ViewerTest.hxx>
20 #include <ViewerTest_CmdParser.hxx>
23 #include <TopLoc_Location.hxx>
24 #include <TopTools_HArray1OfShape.hxx>
25 #include <TColStd_HArray1OfTransient.hxx>
26 #include <TColStd_SequenceOfAsciiString.hxx>
27 #include <TColStd_HSequenceOfAsciiString.hxx>
28 #include <TColStd_MapOfTransient.hxx>
29 #include <OSD_Timer.hxx>
30 #include <Geom_Axis2Placement.hxx>
31 #include <Geom_Axis1Placement.hxx>
32 #include <gp_Trsf.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include <StdSelect_ShapeTypeFilter.hxx>
37 #include <AIS_ColoredShape.hxx>
38 #include <AIS_InteractiveObject.hxx>
39 #include <AIS_Trihedron.hxx>
40 #include <AIS_Axis.hxx>
41 #include <AIS_Relation.hxx>
42 #include <AIS_TypeFilter.hxx>
43 #include <AIS_SignatureFilter.hxx>
44 #include <AIS_ListOfInteractive.hxx>
45 #include <AIS_ListIteratorOfListOfInteractive.hxx>
46 #include <Aspect_InteriorStyle.hxx>
47 #include <Aspect_Window.hxx>
48 #include <Graphic3d_AspectFillArea3d.hxx>
49 #include <Graphic3d_AspectLine3d.hxx>
50 #include <Graphic3d_CStructure.hxx>
51 #include <Graphic3d_Texture2Dmanual.hxx>
52 #include <Graphic3d_GraphicDriver.hxx>
53 #include <Image_AlienPixMap.hxx>
54 #include <OSD_File.hxx>
55 #include <Prs3d_Drawer.hxx>
56 #include <Prs3d_ShadingAspect.hxx>
57 #include <Prs3d_IsoAspect.hxx>
58 #include <Prs3d_PointAspect.hxx>
59 #include <Select3D_SensitiveWire.hxx>
60 #include <Select3D_SensitivePrimitiveArray.hxx>
61 #include <SelectMgr_EntityOwner.hxx>
62 #include <StdSelect_BRepOwner.hxx>
63 #include <StdSelect_ViewerSelector3d.hxx>
64 #include <TopTools_MapOfShape.hxx>
65 #include <ViewerTest_AutoUpdater.hxx>
69 #include <Draw_Interpretor.hxx>
70 #include <TCollection_AsciiString.hxx>
71 #include <Draw_PluginMacro.hxx>
73 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
75 #include <Quantity_Color.hxx>
76 #include <Quantity_NameOfColor.hxx>
78 #include <Graphic3d_NameOfMaterial.hxx>
80 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
81 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
82 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
84 //=======================================================================
85 //function : GetColorFromName
86 //purpose : get the Quantity_NameOfColor from a string
87 //=======================================================================
89 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
91 Quantity_NameOfColor aColor = DEFAULT_COLOR;
92 Quantity_Color::ColorFromName (theName, aColor);
96 //=======================================================================
97 //function : ParseColor
99 //=======================================================================
101 Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
102 const char** theArgVec,
103 Quantity_Color& theColor)
105 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
107 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
112 else if (theArgNb >= 3)
114 const TCollection_AsciiString anRgbStr[3] =
120 if (!anRgbStr[0].IsRealValue()
121 || !anRgbStr[1].IsRealValue()
122 || !anRgbStr[2].IsRealValue())
127 Graphic3d_Vec4d anRgb;
128 anRgb.x() = anRgbStr[0].RealValue();
129 anRgb.y() = anRgbStr[1].RealValue();
130 anRgb.z() = anRgbStr[2].RealValue();
131 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
132 || anRgb.y() < 0.0 || anRgb.y() > 1.0
133 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
135 std::cout << "Error: RGB color values should be within range 0..1!\n";
139 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
146 //=======================================================================
147 //function : ParseOnOff
149 //=======================================================================
150 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
151 Standard_Boolean& theIsOn)
153 TCollection_AsciiString aFlag(theArg);
158 theIsOn = Standard_True;
159 return Standard_True;
161 else if (aFlag == "off"
164 theIsOn = Standard_False;
165 return Standard_True;
167 return Standard_False;
170 //=======================================================================
171 //function : GetSelectedShapes
173 //=======================================================================
174 void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
176 for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
178 TopoDS_Shape aShape = GetAISContext()->SelectedShape();
179 if (!aShape.IsNull())
181 theSelectedShapes.Append (aShape);
186 //=======================================================================
187 //function : ParseLineType
189 //=======================================================================
190 Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
191 Aspect_TypeOfLine& theType)
193 TCollection_AsciiString aTypeStr (theArg);
194 aTypeStr.LowerCase();
195 if (aTypeStr == "empty")
197 theType = Aspect_TOL_EMPTY;
199 else if (aTypeStr == "solid")
201 theType = Aspect_TOL_SOLID;
203 else if (aTypeStr == "dot")
205 theType = Aspect_TOL_DOT;
207 else if (aTypeStr == "dash")
209 theType = Aspect_TOL_DASH;
211 else if (aTypeStr == "dotdash")
213 theType = Aspect_TOL_DOTDASH;
217 const int aTypeInt = Draw::Atoi (theArg);
218 if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
220 return Standard_False;
222 theType = (Aspect_TypeOfLine )aTypeInt;
224 return Standard_True;
227 //=======================================================================
228 //function : ParseMarkerType
230 //=======================================================================
231 Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
232 Aspect_TypeOfMarker& theType,
233 Handle(Image_PixMap)& theImage)
236 TCollection_AsciiString aTypeStr (theArg);
237 aTypeStr.LowerCase();
238 if (aTypeStr == "empty")
240 theType = Aspect_TOM_EMPTY;
242 else if (aTypeStr == "point"
246 theType = Aspect_TOM_POINT;
248 else if (aTypeStr == "plus"
251 theType = Aspect_TOM_PLUS;
253 else if (aTypeStr == "star"
256 theType = Aspect_TOM_STAR;
258 else if (aTypeStr == "cross"
261 theType = Aspect_TOM_X;
263 else if (aTypeStr == "circle"
266 theType = Aspect_TOM_O;
268 else if (aTypeStr == "pointincircle")
270 theType = Aspect_TOM_O_POINT;
272 else if (aTypeStr == "plusincircle")
274 theType = Aspect_TOM_O_PLUS;
276 else if (aTypeStr == "starincircle")
278 theType = Aspect_TOM_O_STAR;
280 else if (aTypeStr == "crossincircle"
281 || aTypeStr == "xcircle")
283 theType = Aspect_TOM_O_X;
285 else if (aTypeStr == "ring1")
287 theType = Aspect_TOM_RING1;
289 else if (aTypeStr == "ring2")
291 theType = Aspect_TOM_RING2;
293 else if (aTypeStr == "ring"
294 || aTypeStr == "ring3")
296 theType = Aspect_TOM_RING3;
298 else if (aTypeStr == "ball")
300 theType = Aspect_TOM_BALL;
302 else if (aTypeStr.IsIntegerValue())
304 const int aTypeInt = aTypeStr.IntegerValue();
305 if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED)
307 return Standard_False;
309 theType = (Aspect_TypeOfMarker )aTypeInt;
313 theType = Aspect_TOM_USERDEFINED;
314 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
315 if (!anImage->Load (theArg))
317 return Standard_False;
319 if (anImage->Format() == Image_Format_Gray)
321 anImage->SetFormat (Image_Format_Alpha);
323 else if (anImage->Format() == Image_Format_GrayF)
325 anImage->SetFormat (Image_Format_AlphaF);
329 return Standard_True;
332 //=======================================================================
333 //function : ParseShadingModel
335 //=======================================================================
336 Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg,
337 Graphic3d_TypeOfShadingModel& theModel)
339 TCollection_AsciiString aTypeStr (theArg);
340 aTypeStr.LowerCase();
341 if (aTypeStr == "unlit"
342 || aTypeStr == "color"
343 || aTypeStr == "none")
345 theModel = Graphic3d_TOSM_UNLIT;
347 else if (aTypeStr == "flat"
348 || aTypeStr == "facet")
350 theModel = Graphic3d_TOSM_FACET;
352 else if (aTypeStr == "gouraud"
353 || aTypeStr == "vertex"
354 || aTypeStr == "vert")
356 theModel = Graphic3d_TOSM_VERTEX;
358 else if (aTypeStr == "phong"
359 || aTypeStr == "fragment"
360 || aTypeStr == "frag"
361 || aTypeStr == "pixel")
363 theModel = Graphic3d_TOSM_FRAGMENT;
365 else if (aTypeStr == "default"
366 || aTypeStr == "def")
368 theModel = Graphic3d_TOSM_DEFAULT;
370 else if (aTypeStr.IsIntegerValue())
372 const int aTypeInt = aTypeStr.IntegerValue();
373 if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
375 return Standard_False;
377 theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
381 return Standard_False;
383 return Standard_True;
386 //=======================================================================
387 //function : GetTypeNames
389 //=======================================================================
390 static const char** GetTypeNames()
392 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
393 "Shape","ConnectedShape","MultiConn.Shape",
394 "ConnectedInter.","MultiConn.",
395 "Constraint","Dimension"};
396 static const char** ThePointer = names;
400 //=======================================================================
401 //function : GetTypeAndSignfromString
403 //=======================================================================
404 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
406 const char ** thefullnames = GetTypeNames();
407 Standard_Integer index(-1);
409 for(Standard_Integer i=0;i<=13 && index==-1;i++)
410 if(!strcasecmp(name,thefullnames[i]))
414 TheType = AIS_KOI_None;
420 TheType = AIS_KOI_Datum;
424 TheType = AIS_KOI_Shape;
428 TheType = AIS_KOI_Object;
432 TheType = AIS_KOI_Relation;
441 #include <Draw_Interpretor.hxx>
443 #include <Draw_Appli.hxx>
447 #include <TCollection_AsciiString.hxx>
448 #include <V3d_Viewer.hxx>
449 #include <V3d_View.hxx>
452 #include <AIS_InteractiveContext.hxx>
453 #include <AIS_Shape.hxx>
454 #include <AIS_DisplayMode.hxx>
455 #include <TColStd_MapOfInteger.hxx>
456 #include <AIS_MapOfInteractive.hxx>
457 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
458 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
459 #include <ViewerTest_EventManager.hxx>
461 #include <TopoDS_Solid.hxx>
462 #include <BRepTools.hxx>
463 #include <BRep_Builder.hxx>
464 #include <TopAbs_ShapeEnum.hxx>
466 #include <TopoDS.hxx>
467 #include <BRep_Tool.hxx>
470 #include <Draw_Window.hxx>
471 #include <AIS_ListIteratorOfListOfInteractive.hxx>
472 #include <AIS_ListOfInteractive.hxx>
473 #include <AIS_DisplayMode.hxx>
474 #include <TopTools_ListOfShape.hxx>
475 #include <BRepOffsetAPI_MakeThickSolid.hxx>
477 //==============================================================================
478 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
479 //==============================================================================
480 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
481 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
485 //=======================================================================
488 //=======================================================================
489 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
490 const Handle(AIS_InteractiveObject)& theObject,
491 const Standard_Boolean theToUpdate,
492 const Standard_Boolean theReplaceIfExists)
494 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
495 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
498 std::cout << "Error: AIS context is not available.\n";
499 return Standard_False;
502 if (aMap.IsBound2 (theName))
504 if (!theReplaceIfExists)
506 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
507 << "Please use another name.\n";
508 return Standard_False;
511 if (Handle(AIS_InteractiveObject) anOldObj = aMap.Find2 (theName))
513 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
515 aMap.UnBind2 (theName);
518 if (theObject.IsNull())
520 // object with specified name has been already unbound
521 return Standard_True;
524 // unbind AIS object if it was bound with another name
525 aMap.UnBind1 (theObject);
527 // can be registered without rebinding
528 aMap.Bind (theObject, theName);
529 aCtx->Display (theObject, theToUpdate);
530 return Standard_True;
533 //! Alias for ViewerTest::Display(), compatibility with old code.
534 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
535 const Handle(AIS_InteractiveObject)& theObject,
536 Standard_Boolean theReplaceIfExists = Standard_True)
538 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
541 static TColStd_MapOfInteger theactivatedmodes(8);
542 static TColStd_ListOfTransient theEventMgrs;
544 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
545 const Handle(AIS_InteractiveContext)& Ctx)
547 theEventMgrs.Clear();
548 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
551 static Handle(V3d_View)& a3DView()
553 static Handle(V3d_View) Viou;
558 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
559 static Handle(AIS_InteractiveContext) aContext;
563 const Handle(V3d_View)& ViewerTest::CurrentView()
567 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
572 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
574 return TheAISContext();
577 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
579 TheAISContext() = aCtx;
580 ViewerTest::ResetEventManager();
583 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
585 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
588 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
590 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
594 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
595 theEventMgrs.Prepend(EM);
598 void ViewerTest::UnsetEventManager()
600 theEventMgrs.RemoveFirst();
604 void ViewerTest::ResetEventManager()
606 const Handle(V3d_View) aView = ViewerTest::CurrentView();
607 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
610 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
612 Handle(ViewerTest_EventManager) EM;
613 if(theEventMgrs.IsEmpty()) return EM;
614 Handle(Standard_Transient) Tr = theEventMgrs.First();
615 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
619 //=======================================================================
620 //function : Get Context and active view
622 //=======================================================================
623 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
624 Handle(V3d_View)& theView)
626 theCtx = ViewerTest::GetAISContext();
627 theView = ViewerTest::CurrentView();
631 std::cout << "Error: cannot find an active view!\n";
632 return Standard_False;
634 return Standard_True;
637 //==============================================================================
638 //function : GetShapeFromName
639 //purpose : Compute an Shape from a draw variable or a file name
640 //==============================================================================
642 static TopoDS_Shape GetShapeFromName(const char* name)
644 TopoDS_Shape S = DBRep::Get(name);
647 BRep_Builder aBuilder;
648 BRepTools::Read( S, name, aBuilder);
654 //==============================================================================
655 //function : GetAISShapeFromName
656 //purpose : Compute an AIS_Shape from a draw variable or a file name
657 //==============================================================================
658 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
660 Handle(AIS_InteractiveObject) aPrs;
661 if (GetMapOfAIS().Find2 (name, aPrs)
664 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs))
669 std::cout << "an Object which is not an AIS_Shape already has this name!!!\n";
670 return Handle(AIS_Shape)();
673 TopoDS_Shape aShape = GetShapeFromName (name);
674 if (!aShape.IsNull())
676 return new AIS_Shape(aShape);
678 return Handle(AIS_Shape)();
682 //==============================================================================
684 //purpose : Remove all the object from the viewer
685 //==============================================================================
686 void ViewerTest::Clear()
688 if (a3DView().IsNull())
693 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
694 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
696 const Handle(AIS_InteractiveObject) anObj = anObjIter.Key1();
697 if (anObj->GetContext() != TheAISContext())
702 std::cout << "Remove " << anObjIter.Key2() << std::endl;
703 TheAISContext()->Remove (anObj, Standard_False);
704 aListRemoved.Append (anObj);
707 TheAISContext()->RebuildSelectionStructs();
708 TheAISContext()->UpdateCurrentViewer();
709 if (aListRemoved.Size() == GetMapOfAIS().Extent())
711 GetMapOfAIS().Clear();
715 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
717 GetMapOfAIS().UnBind1 (anObjIter.Value());
722 //==============================================================================
723 //function : CopyIsoAspect
724 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
725 //==============================================================================
726 static Handle(Prs3d_IsoAspect) CopyIsoAspect
727 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
728 const Standard_Integer theNbIsos)
730 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
731 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
732 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
734 Handle(Prs3d_IsoAspect) aResult =
735 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
740 //==============================================================================
742 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
743 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
744 //==============================================================================
745 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
747 if (TheAISContext().IsNull()) {
748 di << argv[0] << " Call 'vinit' before!\n";
753 di << "Current number of isos : " <<
754 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
755 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
756 di << "IsoOnPlane mode is " <<
757 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
758 di << "IsoOnTriangulation mode is " <<
759 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
763 Standard_Integer aLastInd = argc - 1;
764 Standard_Boolean isChanged = Standard_False;
765 Standard_Integer aNbUIsos = 0;
766 Standard_Integer aNbVIsos = 0;
769 Standard_Boolean isIsoOnPlane = Standard_False;
771 if (strcmp(argv[aLastInd], "1") == 0) {
772 isIsoOnPlane = Standard_True;
773 isChanged = Standard_True;
774 } else if (strcmp(argv[aLastInd], "0") == 0) {
775 isIsoOnPlane = Standard_False;
776 isChanged = Standard_True;
780 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
781 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
784 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
785 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
787 TheAISContext()->IsoOnPlane(isIsoOnPlane);
790 // If there are no shapes provided set the default numbers.
791 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
792 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
799 for (i = 1; i <= aLastInd; i++)
801 TCollection_AsciiString name(argv[i]);
802 Handle(AIS_InteractiveObject) aShape;
803 GetMapOfAIS().Find2(name, aShape);
806 std::cout << "Syntax error: object '" << name << "' is not found\n";
810 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
811 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
812 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
815 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
816 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
817 TheAISContext()->SetLocalAttributes (aShape, CurDrawer, Standard_False);
818 TheAISContext()->Redisplay (aShape, Standard_False);
822 di << "Number of isos for " << argv[i] << " : "
823 << aUIso->Number() << " " << aVIso->Number() << "\n";
828 TheAISContext()->UpdateCurrentViewer();
834 static Standard_Integer VDispSensi (Draw_Interpretor& ,
835 Standard_Integer theArgNb,
840 std::cout << "Error: wrong syntax!\n";
844 Handle(AIS_InteractiveContext) aCtx;
845 Handle(V3d_View) aView;
846 if (!getCtxAndView (aCtx, aView))
851 aCtx->DisplayActiveSensitive (aView);
856 static Standard_Integer VClearSensi (Draw_Interpretor& ,
857 Standard_Integer theArgNb,
862 std::cout << "Error: wrong syntax!\n";
866 Handle(AIS_InteractiveContext) aCtx;
867 Handle(V3d_View) aView;
868 if (!getCtxAndView (aCtx, aView))
872 aCtx->ClearActiveSensitive (aView);
876 //==============================================================================
878 //purpose : To list the displayed object with their attributes
879 //==============================================================================
880 static int VDir (Draw_Interpretor& theDI,
884 if (!a3DView().IsNull())
889 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
890 anIter.More(); anIter.Next())
892 theDI << "\t" << anIter.Key2().ToCString() << "\n";
897 //! Auxiliary enumeration
898 enum ViewerTest_StereoPair
900 ViewerTest_SP_Single,
901 ViewerTest_SP_SideBySide,
902 ViewerTest_SP_OverUnder
905 //==============================================================================
907 //purpose : To dump the active view snapshot to image file
908 //==============================================================================
909 static Standard_Integer VDump (Draw_Interpretor& theDI,
910 Standard_Integer theArgNb,
911 Standard_CString* theArgVec)
915 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
919 Standard_Integer anArgIter = 1;
920 Standard_CString aFilePath = theArgVec[anArgIter++];
921 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
922 V3d_ImageDumpOptions aParams;
923 aParams.BufferType = Graphic3d_BT_RGB;
924 aParams.StereoOptions = V3d_SDO_MONO;
925 for (; anArgIter < theArgNb; ++anArgIter)
927 TCollection_AsciiString anArg (theArgVec[anArgIter]);
929 if (anArg == "-buffer")
931 if (++anArgIter >= theArgNb)
933 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
937 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
939 if (aBufArg == "rgba")
941 aParams.BufferType = Graphic3d_BT_RGBA;
943 else if (aBufArg == "rgb")
945 aParams.BufferType = Graphic3d_BT_RGB;
947 else if (aBufArg == "depth")
949 aParams.BufferType = Graphic3d_BT_Depth;
953 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
957 else if (anArg == "-stereo")
959 if (++anArgIter >= theArgNb)
961 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
965 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
966 aStereoArg.LowerCase();
967 if (aStereoArg == "l"
968 || aStereoArg == "left")
970 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
972 else if (aStereoArg == "r"
973 || aStereoArg == "right")
975 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
977 else if (aStereoArg == "mono")
979 aParams.StereoOptions = V3d_SDO_MONO;
981 else if (aStereoArg == "blended"
982 || aStereoArg == "blend"
983 || aStereoArg == "stereo")
985 aParams.StereoOptions = V3d_SDO_BLENDED;
987 else if (aStereoArg == "sbs"
988 || aStereoArg == "sidebyside")
990 aStereoPair = ViewerTest_SP_SideBySide;
992 else if (aStereoArg == "ou"
993 || aStereoArg == "overunder")
995 aStereoPair = ViewerTest_SP_OverUnder;
999 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
1003 else if (anArg == "-rgba"
1006 aParams.BufferType = Graphic3d_BT_RGBA;
1008 else if (anArg == "-rgb"
1011 aParams.BufferType = Graphic3d_BT_RGB;
1013 else if (anArg == "-depth"
1014 || anArg == "depth")
1016 aParams.BufferType = Graphic3d_BT_Depth;
1018 else if (anArg == "-width"
1020 || anArg == "sizex")
1022 if (aParams.Width != 0)
1024 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1027 else if (++anArgIter >= theArgNb)
1029 std::cout << "Error: integer value is expected right after 'width'\n";
1032 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1034 else if (anArg == "-height"
1035 || anArg == "height"
1036 || anArg == "-sizey")
1038 if (aParams.Height != 0)
1040 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1043 else if (++anArgIter >= theArgNb)
1045 std::cout << "Error: integer value is expected right after 'height'\n";
1048 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1050 else if (anArg == "-tile"
1051 || anArg == "-tilesize")
1053 if (++anArgIter >= theArgNb)
1055 std::cout << "Error: integer value is expected right after 'tileSize'\n";
1058 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1062 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
1066 if ((aParams.Width <= 0 && aParams.Height > 0)
1067 || (aParams.Width > 0 && aParams.Height <= 0))
1069 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
1073 Handle(V3d_View) aView = ViewerTest::CurrentView();
1076 std::cout << "Error: cannot find an active view!\n";
1080 if (aParams.Width <= 0 || aParams.Height <= 0)
1082 aView->Window()->Size (aParams.Width, aParams.Height);
1085 Image_AlienPixMap aPixMap;
1086 Image_Format aFormat = Image_Format_UNKNOWN;
1087 switch (aParams.BufferType)
1089 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1090 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1091 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1092 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1095 switch (aStereoPair)
1097 case ViewerTest_SP_Single:
1099 if (!aView->ToPixMap (aPixMap, aParams))
1101 theDI << "Fail: view dump failed!\n";
1104 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1105 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1107 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1108 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1112 case ViewerTest_SP_SideBySide:
1114 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1116 theDI << "Fail: not enough memory for image allocation!\n";
1120 Image_PixMap aPixMapL, aPixMapR;
1121 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1122 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1123 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1124 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1126 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1127 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1128 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1129 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1132 theDI << "Fail: view dump failed!\n";
1137 case ViewerTest_SP_OverUnder:
1139 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1141 theDI << "Fail: not enough memory for image allocation!\n";
1145 Image_PixMap aPixMapL, aPixMapR;
1146 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1147 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1148 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1149 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1151 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1152 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1153 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1154 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1157 theDI << "Fail: view dump failed!\n";
1164 if (!aPixMap.Save (aFilePath))
1166 theDI << "Fail: image can not be saved!\n";
1171 enum TypeOfDispOperation
1173 TypeOfDispOperation_SetDispMode,
1174 TypeOfDispOperation_UnsetDispMode
1177 //! Displays,Erase...
1178 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1179 const Standard_Integer theMode,
1180 const TypeOfDispOperation theType,
1181 const Standard_Boolean theToUpdate)
1183 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1186 case TypeOfDispOperation_SetDispMode:
1188 if (!thePrs.IsNull())
1190 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1194 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1198 case TypeOfDispOperation_UnsetDispMode:
1200 if (!thePrs.IsNull())
1202 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1206 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1213 //=======================================================================
1216 //=======================================================================
1217 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1222 std::cout << "Syntax error: wrong number of arguments\n";
1226 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1227 ? TypeOfDispOperation_UnsetDispMode
1228 : TypeOfDispOperation_SetDispMode;
1229 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1230 if (aType == TypeOfDispOperation_UnsetDispMode)
1234 if (aCtx->NbSelected() == 0)
1236 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1240 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1242 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1245 aCtx->UpdateCurrentViewer();
1249 TCollection_AsciiString aName = argv[1];
1250 Handle(AIS_InteractiveObject) aPrs;
1251 if (GetMapOfAIS().Find2 (aName, aPrs)
1254 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1260 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1261 if (aCtx->NbSelected() == 0
1262 && aType == TypeOfDispOperation_SetDispMode)
1264 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1266 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1268 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1270 aCtx->UpdateCurrentViewer();
1274 Handle(AIS_InteractiveObject) aPrs;
1275 TCollection_AsciiString aName (argv[1]);
1276 if (GetMapOfAIS().Find2 (aName, aPrs)
1279 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1286 //=======================================================================
1289 //=======================================================================
1290 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1292 if(argc==1) return 1;
1293 Standard_Integer On = Draw::Atoi(argv[1]);
1294 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1298 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1299 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1300 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1304 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1308 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1312 Ctx->UpdateCurrentViewer();
1315 Handle(AIS_InteractiveObject) IO;
1316 TCollection_AsciiString name = argv[2];
1317 if (GetMapOfAIS().Find2 (name, IO)
1321 Ctx->SubIntensityOn(IO, Standard_True);
1323 Ctx->SubIntensityOff(IO, Standard_True);
1330 //! Auxiliary class to iterate presentations from different collections.
1331 class ViewTest_PrsIter
1335 //! Create and initialize iterator object.
1336 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1337 : mySource (IterSource_All)
1339 NCollection_Sequence<TCollection_AsciiString> aNames;
1340 if (!theName.IsEmpty())
1341 aNames.Append (theName);
1345 //! Create and initialize iterator object.
1346 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1347 : mySource (IterSource_All)
1352 //! Initialize the iterator.
1353 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1355 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1357 mySelIter.Nullify();
1358 myCurrent.Nullify();
1359 myCurrentTrs.Nullify();
1360 if (!mySeq.IsEmpty())
1362 mySource = IterSource_List;
1363 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1365 else if (aCtx->NbSelected() > 0)
1367 mySource = IterSource_Selected;
1369 mySelIter->InitSelected();
1373 mySource = IterSource_All;
1374 myMapIter.Initialize (GetMapOfAIS());
1379 const TCollection_AsciiString& CurrentName() const
1381 return myCurrentName;
1384 const Handle(AIS_InteractiveObject)& Current() const
1389 const Handle(Standard_Transient)& CurrentTrs() const
1391 return myCurrentTrs;
1394 //! @return true if iterator points to valid object within collection
1395 Standard_Boolean More() const
1399 case IterSource_All: return myMapIter.More();
1400 case IterSource_List: return mySeqIter.More();
1401 case IterSource_Selected: return mySelIter->MoreSelected();
1403 return Standard_False;
1406 //! Go to the next item.
1409 myCurrentName.Clear();
1410 myCurrentTrs.Nullify();
1411 myCurrent.Nullify();
1414 case IterSource_All:
1419 case IterSource_List:
1424 case IterSource_Selected:
1426 mySelIter->NextSelected();
1439 case IterSource_All:
1441 if (myMapIter.More())
1443 myCurrentName = myMapIter.Key2();
1444 myCurrentTrs = myMapIter.Key1();
1445 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1449 case IterSource_List:
1451 if (mySeqIter.More())
1453 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1455 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1458 myCurrentName = mySeqIter.Value();
1459 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1460 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1464 case IterSource_Selected:
1466 if (mySelIter->MoreSelected())
1468 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1469 myCurrent = mySelIter->SelectedInteractive();
1487 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1488 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1489 NCollection_Sequence<TCollection_AsciiString> mySeq;
1490 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1492 TCollection_AsciiString myCurrentName;//!< current item name
1493 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1494 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1496 IterSource mySource; //!< iterated collection
1500 //==============================================================================
1501 //function : VInteriorStyle
1502 //purpose : sets interior style of the a selected or named or displayed shape
1503 //==============================================================================
1504 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1505 Standard_Integer theArgNb,
1506 const char** theArgVec)
1508 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1509 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1512 std::cerr << "Error: no active view!\n";
1516 Standard_Integer anArgIter = 1;
1517 for (; anArgIter < theArgNb; ++anArgIter)
1519 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1524 TCollection_AsciiString aName;
1525 if (theArgNb - anArgIter == 2)
1527 aName = theArgVec[anArgIter++];
1529 else if (theArgNb - anArgIter != 1)
1531 std::cout << "Error: wrong number of arguments! See usage:\n";
1532 theDI.PrintHelp (theArgVec[0]);
1535 Aspect_InteriorStyle anInterStyle = Aspect_IS_SOLID;
1536 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1537 aStyleArg.LowerCase();
1538 if (aStyleArg == "empty")
1540 anInterStyle = Aspect_IS_EMPTY;
1542 else if (aStyleArg == "hollow")
1544 anInterStyle = Aspect_IS_HOLLOW;
1546 else if (aStyleArg == "hatch")
1548 anInterStyle = Aspect_IS_HATCH;
1550 else if (aStyleArg == "solid")
1552 anInterStyle = Aspect_IS_SOLID;
1554 else if (aStyleArg == "hiddenline")
1556 anInterStyle = Aspect_IS_HIDDENLINE;
1558 else if (aStyleArg == "point")
1560 anInterStyle = Aspect_IS_POINT;
1564 const Standard_Integer anIntStyle = aStyleArg.IntegerValue();
1565 if (anIntStyle < Aspect_IS_EMPTY
1566 || anIntStyle > Aspect_IS_POINT)
1568 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1569 << Aspect_IS_POINT << " (Aspect_IS_POINT)]\n";
1572 anInterStyle = (Aspect_InteriorStyle )anIntStyle;
1575 if (!aName.IsEmpty()
1576 && !GetMapOfAIS().IsBound2 (aName))
1578 std::cout << "Error: object " << aName << " is not displayed!\n";
1582 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1584 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1587 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1588 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1589 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1590 aFillAspect->SetInteriorStyle (anInterStyle);
1591 if (anInterStyle == Aspect_IS_HATCH
1592 && aFillAspect->HatchStyle().IsNull())
1594 aFillAspect->SetHatchStyle (Aspect_HS_VERTICAL);
1596 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1602 //! Auxiliary structure for VAspects
1603 struct ViewerTest_AspectsChangeSet
1605 Standard_Integer ToSetVisibility;
1606 Standard_Integer Visibility;
1608 Standard_Integer ToSetColor;
1609 Quantity_Color Color;
1611 Standard_Integer ToSetLineWidth;
1612 Standard_Real LineWidth;
1614 Standard_Integer ToSetTypeOfLine;
1615 Aspect_TypeOfLine TypeOfLine;
1617 Standard_Integer ToSetTypeOfMarker;
1618 Aspect_TypeOfMarker TypeOfMarker;
1619 Handle(Image_PixMap) MarkerImage;
1621 Standard_Integer ToSetMarkerSize;
1622 Standard_Real MarkerSize;
1624 Standard_Integer ToSetTransparency;
1625 Standard_Real Transparency;
1627 Standard_Integer ToSetAlphaMode;
1628 Graphic3d_AlphaMode AlphaMode;
1629 Standard_ShortReal AlphaCutoff;
1631 Standard_Integer ToSetMaterial;
1632 Graphic3d_NameOfMaterial Material;
1633 TCollection_AsciiString MatName;
1635 NCollection_Sequence<TopoDS_Shape> SubShapes;
1637 Standard_Integer ToSetShowFreeBoundary;
1638 Standard_Integer ToSetFreeBoundaryWidth;
1639 Standard_Real FreeBoundaryWidth;
1640 Standard_Integer ToSetFreeBoundaryColor;
1641 Quantity_Color FreeBoundaryColor;
1643 Standard_Integer ToEnableIsoOnTriangulation;
1645 Standard_Integer ToSetMaxParamValue;
1646 Standard_Real MaxParamValue;
1648 Standard_Integer ToSetSensitivity;
1649 Standard_Integer SelectionMode;
1650 Standard_Integer Sensitivity;
1652 Standard_Integer ToSetHatch;
1653 Standard_Integer StdHatchStyle;
1654 TCollection_AsciiString PathToHatchPattern;
1656 Standard_Integer ToSetShadingModel;
1657 Graphic3d_TypeOfShadingModel ShadingModel;
1658 TCollection_AsciiString ShadingModelName;
1660 //! Empty constructor
1661 ViewerTest_AspectsChangeSet()
1662 : ToSetVisibility (0),
1665 Color (DEFAULT_COLOR),
1668 ToSetTypeOfLine (0),
1669 TypeOfLine (Aspect_TOL_SOLID),
1670 ToSetTypeOfMarker (0),
1671 TypeOfMarker (Aspect_TOM_PLUS),
1672 ToSetMarkerSize (0),
1674 ToSetTransparency (0),
1677 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1680 Material (Graphic3d_NOM_DEFAULT),
1681 ToSetShowFreeBoundary (0),
1682 ToSetFreeBoundaryWidth (0),
1683 FreeBoundaryWidth (1.0),
1684 ToSetFreeBoundaryColor (0),
1685 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1686 ToEnableIsoOnTriangulation (-1),
1687 ToSetMaxParamValue (0),
1688 MaxParamValue (500000),
1689 ToSetSensitivity (0),
1694 ToSetShadingModel (0),
1695 ShadingModel (Graphic3d_TOSM_DEFAULT)
1698 //! @return true if no changes have been requested
1699 Standard_Boolean IsEmpty() const
1701 return ToSetVisibility == 0
1702 && ToSetLineWidth == 0
1703 && ToSetTransparency == 0
1704 && ToSetAlphaMode == 0
1706 && ToSetMaterial == 0
1707 && ToSetShowFreeBoundary == 0
1708 && ToSetFreeBoundaryColor == 0
1709 && ToSetFreeBoundaryWidth == 0
1710 && ToSetMaxParamValue == 0
1711 && ToSetSensitivity == 0
1713 && ToSetShadingModel == 0;
1716 //! @return true if properties are valid
1717 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1719 Standard_Boolean isOk = Standard_True;
1720 if (Visibility != 0 && Visibility != 1)
1722 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1723 isOk = Standard_False;
1725 if (LineWidth <= 0.0
1726 || LineWidth > 10.0)
1728 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1729 isOk = Standard_False;
1731 if (Transparency < 0.0
1732 || Transparency > 1.0)
1734 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1735 isOk = Standard_False;
1738 && ToSetTransparency != 0)
1740 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1741 isOk = Standard_False;
1743 if (ToSetAlphaMode == 1
1744 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1746 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1747 isOk = Standard_False;
1749 if (ToSetMaterial == 1
1750 && Material == Graphic3d_NOM_DEFAULT)
1752 std::cout << "Error: unknown material " << MatName << ".\n";
1753 isOk = Standard_False;
1755 if (FreeBoundaryWidth <= 0.0
1756 || FreeBoundaryWidth > 10.0)
1758 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1759 isOk = Standard_False;
1761 if (MaxParamValue < 0.0)
1763 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1764 isOk = Standard_False;
1766 if (Sensitivity <= 0 && ToSetSensitivity)
1768 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1769 isOk = Standard_False;
1771 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1773 std::cout << "Error: hatch style must be specified\n";
1774 isOk = Standard_False;
1776 if (ToSetShadingModel == 1
1777 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
1779 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1780 isOk = Standard_False;
1787 //==============================================================================
1788 //function : VAspects
1790 //==============================================================================
1791 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1792 Standard_Integer theArgNb,
1793 const char** theArgVec)
1795 TCollection_AsciiString aCmdName (theArgVec[0]);
1796 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1797 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1800 std::cerr << "Error: no active view!\n";
1804 Standard_Integer anArgIter = 1;
1805 Standard_Boolean isDefaults = Standard_False;
1806 NCollection_Sequence<TCollection_AsciiString> aNames;
1807 for (; anArgIter < theArgNb; ++anArgIter)
1809 TCollection_AsciiString anArg = theArgVec[anArgIter];
1810 if (anUpdateTool.parseRedrawMode (anArg))
1814 else if (!anArg.IsEmpty()
1815 && anArg.Value (1) != '-')
1817 aNames.Append (anArg);
1821 if (anArg == "-defaults")
1823 isDefaults = Standard_True;
1830 if (!aNames.IsEmpty() && isDefaults)
1832 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1836 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1837 aChanges.Append (ViewerTest_AspectsChangeSet());
1838 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1840 // parse syntax of legacy commands
1841 if (aCmdName == "vsetwidth")
1843 if (aNames.IsEmpty()
1844 || !aNames.Last().IsRealValue())
1846 std::cout << "Error: not enough arguments!\n";
1849 aChangeSet->ToSetLineWidth = 1;
1850 aChangeSet->LineWidth = aNames.Last().RealValue();
1851 aNames.Remove (aNames.Length());
1853 else if (aCmdName == "vunsetwidth")
1855 aChangeSet->ToSetLineWidth = -1;
1857 else if (aCmdName == "vsetcolor")
1859 if (aNames.IsEmpty())
1861 std::cout << "Error: not enough arguments!\n";
1864 aChangeSet->ToSetColor = 1;
1866 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1867 Standard_Boolean isOk = Standard_False;
1868 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1870 aChangeSet->Color = aColor;
1871 aNames.Remove (aNames.Length());
1872 isOk = Standard_True;
1874 else if (aNames.Length() >= 3)
1876 const TCollection_AsciiString anRgbStr[3] =
1878 aNames.Value (aNames.Upper() - 2),
1879 aNames.Value (aNames.Upper() - 1),
1880 aNames.Value (aNames.Upper() - 0)
1882 isOk = anRgbStr[0].IsRealValue()
1883 && anRgbStr[1].IsRealValue()
1884 && anRgbStr[2].IsRealValue();
1887 Graphic3d_Vec4d anRgb;
1888 anRgb.x() = anRgbStr[0].RealValue();
1889 anRgb.y() = anRgbStr[1].RealValue();
1890 anRgb.z() = anRgbStr[2].RealValue();
1891 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1892 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1893 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1895 std::cout << "Error: RGB color values should be within range 0..1!\n";
1898 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1899 aNames.Remove (aNames.Length());
1900 aNames.Remove (aNames.Length());
1901 aNames.Remove (aNames.Length());
1906 std::cout << "Error: not enough arguments!\n";
1910 else if (aCmdName == "vunsetcolor")
1912 aChangeSet->ToSetColor = -1;
1914 else if (aCmdName == "vsettransparency")
1916 if (aNames.IsEmpty()
1917 || !aNames.Last().IsRealValue())
1919 std::cout << "Error: not enough arguments!\n";
1922 aChangeSet->ToSetTransparency = 1;
1923 aChangeSet->Transparency = aNames.Last().RealValue();
1924 aNames.Remove (aNames.Length());
1926 else if (aCmdName == "vunsettransparency")
1928 aChangeSet->ToSetTransparency = -1;
1930 else if (aCmdName == "vsetmaterial")
1932 if (aNames.IsEmpty())
1934 std::cout << "Error: not enough arguments!\n";
1937 aChangeSet->ToSetMaterial = 1;
1938 aChangeSet->MatName = aNames.Last();
1939 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1940 aNames.Remove (aNames.Length());
1942 else if (aCmdName == "vunsetmaterial")
1944 aChangeSet->ToSetMaterial = -1;
1946 else if (anArgIter >= theArgNb)
1948 std::cout << "Error: not enough arguments!\n";
1952 if (!aChangeSet->IsEmpty())
1954 anArgIter = theArgNb;
1956 for (; anArgIter < theArgNb; ++anArgIter)
1958 TCollection_AsciiString anArg = theArgVec[anArgIter];
1960 if (anArg == "-setwidth"
1961 || anArg == "-setlinewidth")
1963 if (++anArgIter >= theArgNb)
1965 std::cout << "Error: wrong syntax at " << anArg << "\n";
1968 aChangeSet->ToSetLineWidth = 1;
1969 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1971 else if (anArg == "-unsetwidth"
1972 || anArg == "-unsetlinewidth")
1974 aChangeSet->ToSetLineWidth = -1;
1975 aChangeSet->LineWidth = 1.0;
1977 else if (anArg == "-settransp"
1978 || anArg == "-settransparency")
1980 if (++anArgIter >= theArgNb)
1982 std::cout << "Error: wrong syntax at " << anArg << "\n";
1985 aChangeSet->ToSetTransparency = 1;
1986 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1987 if (aChangeSet->Transparency >= 0.0
1988 && aChangeSet->Transparency <= Precision::Confusion())
1990 aChangeSet->ToSetTransparency = -1;
1991 aChangeSet->Transparency = 0.0;
1994 else if (anArg == "-setalphamode")
1996 if (++anArgIter >= theArgNb)
1998 std::cout << "Error: wrong syntax at " << anArg << "\n";
2001 aChangeSet->ToSetAlphaMode = 1;
2002 aChangeSet->AlphaCutoff = 0.5f;
2004 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2006 if (aParam == "opaque")
2008 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2010 else if (aParam == "mask")
2012 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2014 else if (aParam == "blend")
2016 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2018 else if (aParam == "blendauto"
2019 || aParam == "auto")
2021 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2025 std::cout << "Error: wrong syntax at " << aParam << "\n";
2030 if (anArgIter + 1 < theArgNb
2031 && theArgVec[anArgIter + 1][0] != '-')
2033 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2034 if (aParam2.IsRealValue())
2036 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2041 else if (anArg == "-setvis"
2042 || anArg == "-setvisibility")
2044 if (++anArgIter >= theArgNb)
2046 std::cout << "Error: wrong syntax at " << anArg << "\n";
2050 aChangeSet->ToSetVisibility = 1;
2051 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2053 else if (anArg == "-setalpha")
2055 if (++anArgIter >= theArgNb)
2057 std::cout << "Error: wrong syntax at " << anArg << "\n";
2060 aChangeSet->ToSetTransparency = 1;
2061 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2062 if (aChangeSet->Transparency < 0.0
2063 || aChangeSet->Transparency > 1.0)
2065 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2068 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2069 if (aChangeSet->Transparency >= 0.0
2070 && aChangeSet->Transparency <= Precision::Confusion())
2072 aChangeSet->ToSetTransparency = -1;
2073 aChangeSet->Transparency = 0.0;
2076 else if (anArg == "-unsettransp"
2077 || anArg == "-unsettransparency"
2078 || anArg == "-unsetalpha"
2079 || anArg == "-opaque")
2081 aChangeSet->ToSetTransparency = -1;
2082 aChangeSet->Transparency = 0.0;
2084 else if (anArg == "-setcolor")
2086 Standard_Integer aNbComps = 0;
2087 Standard_Integer aCompIter = anArgIter + 1;
2088 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2090 if (theArgVec[aCompIter][0] == '-')
2099 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2100 Standard_CString aName = theArgVec[anArgIter + 1];
2101 if (!Quantity_Color::ColorFromName (aName, aColor))
2103 std::cout << "Error: unknown color name '" << aName << "'\n";
2106 aChangeSet->Color = aColor;
2111 Graphic3d_Vec3d anRgb;
2112 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2113 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2114 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2115 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2116 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2117 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2119 std::cout << "Error: RGB color values should be within range 0..1!\n";
2122 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2127 std::cout << "Error: wrong syntax at " << anArg << "\n";
2131 aChangeSet->ToSetColor = 1;
2132 anArgIter += aNbComps;
2134 else if (anArg == "-setlinetype")
2136 if (++anArgIter >= theArgNb)
2138 std::cout << "Error: wrong syntax at " << anArg << "\n";
2141 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aChangeSet->TypeOfLine))
2143 std::cout << "Error: wrong syntax at " << anArg << "\n";
2147 aChangeSet->ToSetTypeOfLine = 1;
2149 else if (anArg == "-unsetlinetype")
2151 aChangeSet->ToSetTypeOfLine = -1;
2153 else if (anArg == "-setmarkertype"
2154 || anArg == "-setpointtype")
2156 if (++anArgIter >= theArgNb)
2158 std::cout << "Error: wrong syntax at " << anArg << "\n";
2161 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2163 std::cout << "Error: wrong syntax at " << anArg << "\n";
2167 aChangeSet->ToSetTypeOfMarker = 1;
2169 else if (anArg == "-unsetmarkertype"
2170 || anArg == "-unsetpointtype")
2172 aChangeSet->ToSetTypeOfMarker = -1;
2174 else if (anArg == "-setmarkersize"
2175 || anArg == "-setpointsize")
2177 if (++anArgIter >= theArgNb)
2179 std::cout << "Error: wrong syntax at " << anArg << "\n";
2182 aChangeSet->ToSetMarkerSize = 1;
2183 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2185 else if (anArg == "-unsetmarkersize"
2186 || anArg == "-unsetpointsize")
2188 aChangeSet->ToSetMarkerSize = -1;
2189 aChangeSet->MarkerSize = 1.0;
2191 else if (anArg == "-unsetcolor")
2193 aChangeSet->ToSetColor = -1;
2194 aChangeSet->Color = DEFAULT_COLOR;
2196 else if (anArg == "-setmat"
2197 || anArg == "-setmaterial")
2199 if (++anArgIter >= theArgNb)
2201 std::cout << "Error: wrong syntax at " << anArg << "\n";
2204 aChangeSet->ToSetMaterial = 1;
2205 aChangeSet->MatName = theArgVec[anArgIter];
2206 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2208 else if (anArg == "-unsetmat"
2209 || anArg == "-unsetmaterial")
2211 aChangeSet->ToSetMaterial = -1;
2212 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2214 else if (anArg == "-subshape"
2215 || anArg == "-subshapes")
2219 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2223 if (aNames.IsEmpty())
2225 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2229 aChanges.Append (ViewerTest_AspectsChangeSet());
2230 aChangeSet = &aChanges.ChangeLast();
2232 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2234 Standard_CString aSubShapeName = theArgVec[anArgIter];
2235 if (*aSubShapeName == '-')
2241 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2242 if (aSubShape.IsNull())
2244 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2247 aChangeSet->SubShapes.Append (aSubShape);
2250 if (aChangeSet->SubShapes.IsEmpty())
2252 std::cerr << "Error: empty list is specified after -subshapes!\n";
2256 else if (anArg == "-freeboundary"
2259 if (++anArgIter >= theArgNb)
2261 std::cout << "Error: wrong syntax at " << anArg << "\n";
2264 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2269 aChangeSet->ToSetShowFreeBoundary = 1;
2271 else if (aValue == "off"
2274 aChangeSet->ToSetShowFreeBoundary = -1;
2278 std::cout << "Error: wrong syntax at " << anArg << "\n";
2282 else if (anArg == "-setfreeboundarywidth"
2283 || anArg == "-setfbwidth")
2285 if (++anArgIter >= theArgNb)
2287 std::cout << "Error: wrong syntax at " << anArg << "\n";
2290 aChangeSet->ToSetFreeBoundaryWidth = 1;
2291 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2293 else if (anArg == "-unsetfreeboundarywidth"
2294 || anArg == "-unsetfbwidth")
2296 aChangeSet->ToSetFreeBoundaryWidth = -1;
2297 aChangeSet->FreeBoundaryWidth = 1.0;
2299 else if (anArg == "-setfreeboundarycolor"
2300 || anArg == "-setfbcolor")
2302 Standard_Integer aNbComps = 0;
2303 Standard_Integer aCompIter = anArgIter + 1;
2304 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2306 if (theArgVec[aCompIter][0] == '-')
2315 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2316 Standard_CString aName = theArgVec[anArgIter + 1];
2317 if (!Quantity_Color::ColorFromName (aName, aColor))
2319 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2322 aChangeSet->FreeBoundaryColor = aColor;
2327 Graphic3d_Vec3d anRgb;
2328 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2329 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2330 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2331 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2332 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2333 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2335 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2338 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2343 std::cout << "Error: wrong syntax at " << anArg << "\n";
2347 aChangeSet->ToSetFreeBoundaryColor = 1;
2348 anArgIter += aNbComps;
2350 else if (anArg == "-unsetfreeboundarycolor"
2351 || anArg == "-unsetfbcolor")
2353 aChangeSet->ToSetFreeBoundaryColor = -1;
2354 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2356 else if (anArg == "-unset")
2358 aChangeSet->ToSetVisibility = 1;
2359 aChangeSet->Visibility = 1;
2360 aChangeSet->ToSetLineWidth = -1;
2361 aChangeSet->LineWidth = 1.0;
2362 aChangeSet->ToSetTypeOfLine = -1;
2363 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2364 aChangeSet->ToSetTypeOfMarker = -1;
2365 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
2366 aChangeSet->ToSetMarkerSize = -1;
2367 aChangeSet->MarkerSize = 1.0;
2368 aChangeSet->ToSetTransparency = -1;
2369 aChangeSet->Transparency = 0.0;
2370 aChangeSet->ToSetAlphaMode = -1;
2371 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2372 aChangeSet->AlphaCutoff = 0.5f;
2373 aChangeSet->ToSetColor = -1;
2374 aChangeSet->Color = DEFAULT_COLOR;
2375 aChangeSet->ToSetMaterial = -1;
2376 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2377 aChangeSet->ToSetShowFreeBoundary = -1;
2378 aChangeSet->ToSetFreeBoundaryColor = -1;
2379 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2380 aChangeSet->ToSetFreeBoundaryWidth = -1;
2381 aChangeSet->FreeBoundaryWidth = 1.0;
2382 aChangeSet->ToSetHatch = -1;
2383 aChangeSet->StdHatchStyle = -1;
2384 aChangeSet->PathToHatchPattern.Clear();
2385 aChangeSet->ToSetShadingModel = -1;
2386 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2388 else if (anArg == "-isoontriangulation"
2389 || anArg == "-isoontriang")
2391 if (++anArgIter >= theArgNb)
2393 std::cout << "Error: wrong syntax at " << anArg << "\n";
2396 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2401 aChangeSet->ToEnableIsoOnTriangulation = 1;
2403 else if (aValue == "off"
2406 aChangeSet->ToEnableIsoOnTriangulation = 0;
2410 std::cout << "Error: wrong syntax at " << anArg << "\n";
2414 else if (anArg == "-setmaxparamvalue")
2416 if (++anArgIter >= theArgNb)
2418 std::cout << "Error: wrong syntax at " << anArg << "\n";
2421 aChangeSet->ToSetMaxParamValue = 1;
2422 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2424 else if (anArg == "-setsensitivity")
2428 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2432 if (aNames.IsEmpty())
2434 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2438 if (anArgIter + 2 >= theArgNb)
2440 std::cout << "Error: wrong syntax at " << anArg << "\n";
2443 aChangeSet->ToSetSensitivity = 1;
2444 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2445 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2447 else if (anArg == "-sethatch")
2451 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2455 if (aNames.IsEmpty())
2457 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2461 aChangeSet->ToSetHatch = 1;
2462 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
2463 if (anArgHatch.Length() <= 2)
2465 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
2467 || anIntStyle >= Aspect_HS_NB)
2469 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
2472 aChangeSet->StdHatchStyle = anIntStyle;
2476 aChangeSet->PathToHatchPattern = anArgHatch;
2479 else if (anArg == "-setshadingmodel")
2481 if (++anArgIter >= theArgNb)
2483 std::cout << "Error: wrong syntax at " << anArg << "\n";
2486 aChangeSet->ToSetShadingModel = 1;
2487 aChangeSet->ShadingModelName = theArgVec[anArgIter];
2488 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
2490 std::cout << "Error: wrong syntax at " << anArg << "\n";
2494 else if (anArg == "-unsetshadingmodel")
2496 aChangeSet->ToSetShadingModel = -1;
2497 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2501 std::cout << "Error: wrong syntax at " << anArg << "\n";
2506 Standard_Boolean isFirst = Standard_True;
2507 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2508 aChangesIter.More(); aChangesIter.Next())
2510 if (!aChangesIter.Value().Validate (!isFirst))
2514 isFirst = Standard_False;
2517 // special case for -defaults parameter.
2518 // all changed values will be set to DefaultDrawer.
2521 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2523 if (aChangeSet->ToSetLineWidth != 0)
2525 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2526 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2527 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2528 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2530 if (aChangeSet->ToSetColor != 0)
2532 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2533 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2534 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2535 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2536 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2537 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2539 if (aChangeSet->ToSetTypeOfLine != 0)
2541 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2542 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2543 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2544 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2545 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2547 if (aChangeSet->ToSetTypeOfMarker != 0)
2549 aDrawer->PointAspect()->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2550 aDrawer->PointAspect()->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2551 ? Handle(Graphic3d_MarkerImage)()
2552 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2554 if (aChangeSet->ToSetMarkerSize != 0)
2556 aDrawer->PointAspect()->SetScale (aChangeSet->MarkerSize);
2558 if (aChangeSet->ToSetTransparency != 0)
2560 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2562 if (aChangeSet->ToSetAlphaMode != 0)
2564 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2566 if (aChangeSet->ToSetMaterial != 0)
2568 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2570 if (aChangeSet->ToSetShowFreeBoundary == 1)
2572 aDrawer->SetFreeBoundaryDraw (Standard_True);
2574 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2576 aDrawer->SetFreeBoundaryDraw (Standard_False);
2578 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2580 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2582 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2584 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2586 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2588 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2590 if (aChangeSet->ToSetMaxParamValue != 0)
2592 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2594 if (aChangeSet->ToSetShadingModel == 1)
2596 aDrawer->ShadingAspect()->Aspect()->SetShadingModel (aChangeSet->ShadingModel);
2599 // redisplay all objects in context
2600 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2602 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2605 aCtx->Redisplay (aPrs, Standard_False);
2611 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2613 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2614 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2620 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2621 Handle(AIS_ColoredShape) aColoredPrs;
2622 Standard_Boolean toDisplay = Standard_False;
2623 Standard_Boolean toRedisplay = Standard_False;
2624 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2626 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2627 if (aShapePrs.IsNull())
2629 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2632 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2633 if (aColoredPrs.IsNull())
2635 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2636 if (aShapePrs->HasDisplayMode())
2638 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2640 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2641 aCtx->Remove (aShapePrs, Standard_False);
2642 GetMapOfAIS().UnBind2 (aName);
2643 GetMapOfAIS().Bind (aColoredPrs, aName);
2644 toDisplay = Standard_True;
2645 aShapePrs = aColoredPrs;
2652 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2653 aChangeSet = &aChangesIter.ChangeValue();
2654 if (aChangeSet->ToSetVisibility == 1)
2656 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2657 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2659 else if (aChangeSet->ToSetMaterial == 1)
2661 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2663 else if (aChangeSet->ToSetMaterial == -1)
2665 aCtx->UnsetMaterial (aPrs, Standard_False);
2667 if (aChangeSet->ToSetColor == 1)
2669 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2671 else if (aChangeSet->ToSetColor == -1)
2673 aCtx->UnsetColor (aPrs, Standard_False);
2675 if (aChangeSet->ToSetTransparency == 1)
2677 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2679 else if (aChangeSet->ToSetTransparency == -1)
2681 aCtx->UnsetTransparency (aPrs, Standard_False);
2683 if (aChangeSet->ToSetLineWidth == 1)
2685 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2687 else if (aChangeSet->ToSetLineWidth == -1)
2689 aCtx->UnsetWidth (aPrs, Standard_False);
2691 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2693 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2694 toRedisplay = Standard_True;
2696 else if (aChangeSet->ToSetSensitivity != 0)
2698 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2700 if (!aDrawer.IsNull())
2702 if (aChangeSet->ToSetShowFreeBoundary == 1)
2704 aDrawer->SetFreeBoundaryDraw (Standard_True);
2705 toRedisplay = Standard_True;
2707 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2709 aDrawer->SetFreeBoundaryDraw (Standard_False);
2710 toRedisplay = Standard_True;
2712 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2714 Handle(Prs3d_LineAspect) aBoundaryAspect =
2715 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2716 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2717 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2718 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2719 toRedisplay = Standard_True;
2721 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2723 Handle(Prs3d_LineAspect) aBoundaryAspect =
2724 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2725 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2726 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2727 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2728 toRedisplay = Standard_True;
2730 if (aChangeSet->ToSetTypeOfLine != 0)
2732 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2733 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2734 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2735 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2736 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2737 toRedisplay = Standard_True;
2739 if (aChangeSet->ToSetTypeOfMarker != 0)
2741 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2742 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2743 aMarkerAspect->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2744 aMarkerAspect->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2745 ? Handle(Graphic3d_MarkerImage)()
2746 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2747 aDrawer->SetPointAspect (aMarkerAspect);
2748 toRedisplay = Standard_True;
2750 if (aChangeSet->ToSetMarkerSize != 0)
2752 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2753 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2754 aMarkerAspect->SetScale (aChangeSet->MarkerSize);
2755 aDrawer->SetPointAspect (aMarkerAspect);
2756 toRedisplay = Standard_True;
2758 if (aChangeSet->ToSetMaxParamValue != 0)
2760 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2762 if (aChangeSet->ToSetHatch != 0)
2764 if (!aDrawer->HasOwnShadingAspect())
2766 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2767 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2770 Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
2771 if (aChangeSet->ToSetHatch == -1)
2773 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2777 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2778 if (!aChangeSet->PathToHatchPattern.IsEmpty())
2780 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2781 if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
2783 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2787 std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
2791 else if (aChangeSet->StdHatchStyle != -1)
2793 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
2796 toRedisplay = Standard_True;
2798 if (aChangeSet->ToSetShadingModel != 0)
2800 aDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2801 toRedisplay = Standard_True;
2803 if (aChangeSet->ToSetAlphaMode != 0)
2805 if (!aDrawer->HasOwnShadingAspect())
2807 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2808 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2810 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2811 toRedisplay = Standard_True;
2815 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2817 aChangeSet = &aChangesIter.ChangeValue();
2818 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2819 aSubShapeIter.More(); aSubShapeIter.Next())
2821 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2822 if (aChangeSet->ToSetVisibility == 1)
2824 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2825 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2827 if (aChangeSet->ToSetColor == 1)
2829 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2831 if (aChangeSet->ToSetLineWidth == 1)
2833 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2835 if (aChangeSet->ToSetColor == -1
2836 || aChangeSet->ToSetLineWidth == -1)
2838 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2840 if (aChangeSet->ToSetMaxParamValue != 0)
2842 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2843 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2845 if (aChangeSet->ToSetSensitivity != 0)
2847 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2849 if (aChangeSet->ToSetShadingModel != 0)
2851 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2852 aCurColDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2858 aCtx->Display (aPrs, Standard_False);
2862 aCtx->Redisplay (aPrs, Standard_False);
2864 else if (!aColoredPrs.IsNull())
2866 aCtx->Redisplay (aColoredPrs, Standard_False);
2873 //==============================================================================
2874 //function : VDonly2
2876 //purpose : Display only a selected or named object
2877 // if there is no selected or named object s, nothing is done
2878 //==============================================================================
2879 static int VDonly2 (Draw_Interpretor& ,
2880 Standard_Integer theArgNb,
2881 const char** theArgVec)
2883 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2884 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2887 std::cerr << "Error: no active view!\n";
2891 Standard_Integer anArgIter = 1;
2892 for (; anArgIter < theArgNb; ++anArgIter)
2894 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2900 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2901 if (anArgIter >= theArgNb)
2903 // display only selected objects
2904 if (aCtx->NbSelected() < 1)
2909 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2911 aDispSet.Add (aCtx->SelectedInteractive());
2916 // display only specified objects
2917 for (; anArgIter < theArgNb; ++anArgIter)
2919 TCollection_AsciiString aName = theArgVec[anArgIter];
2920 Handle(AIS_InteractiveObject) aShape;
2921 if (GetMapOfAIS().Find2 (aName, aShape)
2922 && !aShape.IsNull())
2924 aCtx->Display (aShape, Standard_False);
2925 aDispSet.Add (aShape);
2930 // weed out other objects
2931 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2933 if (aDispSet.Contains (anIter.Key1()))
2938 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
2940 aCtx->Erase (aShape, Standard_False);
2946 //==============================================================================
2947 //function : VRemove
2948 //purpose : Removes selected or named objects.
2949 // If there is no selected or named objects,
2950 // all objects in the viewer can be removed with argument -all.
2951 // If -context is in arguments, the object is not deleted from the map of
2952 // objects (deleted only from the current context).
2953 //==============================================================================
2954 int VRemove (Draw_Interpretor& theDI,
2955 Standard_Integer theArgNb,
2956 const char** theArgVec)
2958 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2959 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2962 std::cerr << "Error: no active view!\n";
2966 Standard_Boolean isContextOnly = Standard_False;
2967 Standard_Boolean toRemoveAll = Standard_False;
2968 Standard_Boolean toPrintInfo = Standard_True;
2970 Standard_Integer anArgIter = 1;
2971 for (; anArgIter < theArgNb; ++anArgIter)
2973 TCollection_AsciiString anArg = theArgVec[anArgIter];
2975 if (anArg == "-context")
2977 isContextOnly = Standard_True;
2979 else if (anArg == "-all")
2981 toRemoveAll = Standard_True;
2983 else if (anArg == "-noinfo")
2985 toPrintInfo = Standard_False;
2987 else if (anUpdateTool.parseRedrawMode (anArg))
2997 && anArgIter < theArgNb)
2999 std::cerr << "Error: wrong syntax!\n";
3003 NCollection_List<TCollection_AsciiString> anIONameList;
3006 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3007 anIter.More(); anIter.Next())
3009 anIONameList.Append (anIter.Key2());
3012 else if (anArgIter < theArgNb) // removed objects names are in argument list
3014 for (; anArgIter < theArgNb; ++anArgIter)
3016 TCollection_AsciiString aName = theArgVec[anArgIter];
3017 Handle(AIS_InteractiveObject) anIO;
3018 if (!GetMapOfAIS().Find2 (aName, anIO))
3020 theDI << aName << " was not bound to some object.\n";
3024 if (anIO->GetContext() != aCtx)
3026 theDI << aName << " was not displayed in current context.\n";
3027 theDI << "Please activate view with this object displayed and try again.\n";
3031 anIONameList.Append (aName);
3035 else if (aCtx->NbSelected() > 0)
3037 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3038 anIter.More(); anIter.Next())
3040 if (!aCtx->IsSelected (anIter.Key1()))
3045 anIONameList.Append (anIter.Key2());
3050 // Unbind all removed objects from the map of displayed IO.
3051 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3052 anIter.More(); anIter.Next())
3054 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
3055 aCtx->Remove (anIO, Standard_False);
3058 theDI << anIter.Value() << " was removed\n";
3062 GetMapOfAIS().UnBind2 (anIter.Value());
3068 //==============================================================================
3070 //purpose : Erase some selected or named objects
3071 // if there is no selected or named objects, the whole viewer is erased
3072 //==============================================================================
3073 int VErase (Draw_Interpretor& theDI,
3074 Standard_Integer theArgNb,
3075 const char** theArgVec)
3077 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3078 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3079 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3082 std::cerr << "Error: no active view!\n";
3086 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3088 Standard_Integer anArgIter = 1;
3089 Standard_Boolean toEraseInView = Standard_False;
3090 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3091 for (; anArgIter < theArgNb; ++anArgIter)
3093 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3094 anArgCase.LowerCase();
3095 if (anUpdateTool.parseRedrawMode (anArgCase))
3099 else if (anArgCase == "-view"
3100 || anArgCase == "-inview")
3102 toEraseInView = Standard_True;
3106 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3110 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3112 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3116 if (!aNamesOfEraseIO.IsEmpty())
3118 // Erase named objects
3119 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
3121 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
3122 Handle(AIS_InteractiveObject) anIO;
3123 if (!GetMapOfAIS().Find2 (aName, anIO))
3128 theDI << aName << " ";
3133 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3137 aCtx->Erase (anIO, Standard_False);
3142 else if (!toEraseAll && aCtx->NbSelected() > 0)
3144 // Erase selected objects
3145 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3146 anIter.More(); anIter.Next())
3148 const Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3150 && aCtx->IsSelected (anIO))
3152 theDI << anIter.Key2() << " ";
3155 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3162 aCtx->EraseSelected (Standard_False);
3167 // Erase all objects
3168 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3169 anIter.More(); anIter.Next())
3171 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3176 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3180 aCtx->Erase (anIO, Standard_False);
3189 //==============================================================================
3190 //function : VDisplayAll
3191 //purpose : Display all the objects of the Map
3192 //==============================================================================
3193 static int VDisplayAll (Draw_Interpretor& ,
3194 Standard_Integer theArgNb,
3195 const char** theArgVec)
3198 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3199 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3202 std::cerr << "Error: no active view!\n";
3206 Standard_Integer anArgIter = 1;
3207 for (; anArgIter < theArgNb; ++anArgIter)
3209 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3210 anArgCase.LowerCase();
3211 if (anUpdateTool.parseRedrawMode (anArgCase))
3220 if (anArgIter < theArgNb)
3222 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3226 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3227 anIter.More(); anIter.Next())
3229 aCtx->Erase (anIter.Key1(), Standard_False);
3232 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3233 anIter.More(); anIter.Next())
3235 aCtx->Display (anIter.Key1(), Standard_False);
3240 //! Auxiliary method to check if presentation exists
3241 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3242 const Handle(AIS_InteractiveObject)& theIO,
3243 const Standard_Integer theMode)
3245 if (theIO.IsNull() || theCtx.IsNull())
3252 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3257 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3259 return theIO->DisplayMode();
3261 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3263 return theCtx->DisplayMode();
3269 enum ViewerTest_BndAction
3276 //! Auxiliary method to print bounding box of presentation
3277 inline void bndPresentation (Draw_Interpretor& theDI,
3278 const Handle(PrsMgr_PresentationManager)& theMgr,
3279 const Handle(AIS_InteractiveObject)& theObj,
3280 const Standard_Integer theDispMode,
3281 const TCollection_AsciiString& theName,
3282 const ViewerTest_BndAction theAction,
3283 const Handle(Prs3d_Drawer)& theStyle)
3287 case BndAction_Hide:
3289 theMgr->Unhighlight (theObj);
3292 case BndAction_Show:
3294 theMgr->Color (theObj, theStyle, theDispMode);
3297 case BndAction_Print:
3300 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3302 if (aPrsIter.Value().Mode() != theDispMode)
3305 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3307 gp_Pnt aMin = aBox.CornerMin();
3308 gp_Pnt aMax = aBox.CornerMax();
3309 theDI << theName << "\n"
3310 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3311 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
3317 //==============================================================================
3318 //function : VBounding
3320 //==============================================================================
3321 int VBounding (Draw_Interpretor& theDI,
3322 Standard_Integer theArgNb,
3323 const char** theArgVec)
3325 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3326 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3329 std::cout << "Error: no active view!\n";
3333 ViewerTest_BndAction anAction = BndAction_Show;
3334 Standard_Integer aMode = -1;
3336 Handle(Prs3d_Drawer) aStyle;
3338 Standard_Integer anArgIter = 1;
3339 for (; anArgIter < theArgNb; ++anArgIter)
3341 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3343 if (anArg == "-print")
3345 anAction = BndAction_Print;
3347 else if (anArg == "-show")
3349 anAction = BndAction_Show;
3351 else if (anArg == "-hide")
3353 anAction = BndAction_Hide;
3355 else if (anArg == "-mode")
3357 if (++anArgIter >= theArgNb)
3359 std::cout << "Error: wrong syntax at " << anArg << "\n";
3362 aMode = Draw::Atoi (theArgVec[anArgIter]);
3364 else if (!anUpdateTool.parseRedrawMode (anArg))
3370 if (anAction == BndAction_Show)
3372 aStyle = new Prs3d_Drawer();
3373 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3374 aStyle->SetColor (Quantity_NOC_GRAY99);
3377 Standard_Integer aHighlightedMode = -1;
3378 if (anArgIter < theArgNb)
3380 // has a list of names
3381 for (; anArgIter < theArgNb; ++anArgIter)
3383 TCollection_AsciiString aName = theArgVec[anArgIter];
3384 Handle(AIS_InteractiveObject) anIO;
3385 if (!GetMapOfAIS().Find2 (aName, anIO))
3387 std::cout << "Error: presentation " << aName << " does not exist\n";
3391 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3392 if (aHighlightedMode == -1)
3394 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3397 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3400 else if (aCtx->NbSelected() > 0)
3402 // remove all currently selected objects
3403 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3405 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3406 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3407 if (aHighlightedMode != -1)
3409 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3410 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3417 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3418 anIter.More(); anIter.Next())
3420 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3421 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3422 if (aHighlightedMode != -1)
3424 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3431 //==============================================================================
3432 //function : VTexture
3434 //==============================================================================
3435 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
3437 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3440 std::cout << "Error: no active view!\n";
3444 int toModulate = -1;
3445 bool toSetFilter = false;
3446 bool toSetAniso = false;
3447 bool toSetTrsfAngle = false;
3448 bool toSetTrsfTrans = false;
3449 bool toSetTrsfScale = false;
3450 Standard_ShortReal aTrsfRotAngle = 0.0f;
3451 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
3452 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
3453 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
3454 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
3456 Handle(AIS_Shape) aTexturedIO;
3457 Handle(Graphic3d_TextureSet) aTextureSetOld;
3458 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
3459 bool toSetGenRepeat = false;
3460 bool toSetGenScale = false;
3461 bool toSetGenOrigin = false;
3462 bool toSetImage = false;
3463 bool toComputeUV = false;
3465 const TCollection_AsciiString aCommandName (theArgVec[0]);
3466 bool toSetDefaults = aCommandName == "vtexdefault";
3468 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3469 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
3471 const TCollection_AsciiString aName = theArgVec[anArgIter];
3472 TCollection_AsciiString aNameCase = aName;
3473 aNameCase.LowerCase();
3474 if (anUpdateTool.parseRedrawMode (aName))
3478 else if (aTexturedIO.IsNull())
3480 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3481 if (aMapOfIO.IsBound2 (aName))
3483 aTexturedIO = Handle(AIS_Shape)::DownCast (aMapOfIO.Find2 (aName));
3485 if (aTexturedIO.IsNull())
3487 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
3491 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
3493 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
3496 else if (aNameCase == "-scale"
3497 || aNameCase == "-setscale"
3498 || aCommandName == "vtexscale")
3500 if (aCommandName != "vtexscale")
3504 if (anArgIter < theArgsNb)
3506 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3507 TCollection_AsciiString aValUCase = aValU;
3508 aValUCase.LowerCase();
3509 toSetGenScale = true;
3510 if (aValUCase == "off")
3512 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3515 else if (anArgIter + 1 < theArgsNb)
3517 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3518 if (aValU.IsRealValue()
3519 && aValV.IsRealValue())
3521 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3527 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3530 else if (aNameCase == "-origin"
3531 || aNameCase == "-setorigin"
3532 || aCommandName == "vtexorigin")
3534 if (aCommandName != "vtexorigin")
3538 if (anArgIter < theArgsNb)
3540 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3541 TCollection_AsciiString aValUCase = aValU;
3542 aValUCase.LowerCase();
3543 toSetGenOrigin = true;
3544 if (aValUCase == "off")
3546 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3549 else if (anArgIter + 1 < theArgsNb)
3551 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3552 if (aValU.IsRealValue()
3553 && aValV.IsRealValue())
3555 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3561 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3564 else if (aNameCase == "-repeat"
3565 || aNameCase == "-setrepeat"
3566 || aCommandName == "vtexrepeat")
3568 if (aCommandName != "vtexrepeat")
3572 if (anArgIter < theArgsNb)
3574 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3575 TCollection_AsciiString aValUCase = aValU;
3576 aValUCase.LowerCase();
3577 toSetGenRepeat = true;
3578 if (aValUCase == "off")
3580 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3583 else if (anArgIter + 1 < theArgsNb)
3585 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3586 if (aValU.IsRealValue()
3587 && aValV.IsRealValue())
3589 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3595 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3598 else if (aNameCase == "-modulate")
3600 bool toModulateBool = true;
3601 if (anArgIter + 1 < theArgsNb
3602 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
3606 toModulate = toModulateBool ? 1 : 0;
3608 else if ((aNameCase == "-setfilter"
3609 || aNameCase == "-filter")
3610 && anArgIter + 1 < theArgsNb)
3612 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3616 if (aValue == "nearest")
3618 aFilter = Graphic3d_TOTF_NEAREST;
3620 else if (aValue == "bilinear")
3622 aFilter = Graphic3d_TOTF_BILINEAR;
3624 else if (aValue == "trilinear")
3626 aFilter = Graphic3d_TOTF_TRILINEAR;
3630 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3634 else if ((aNameCase == "-setaniso"
3635 || aNameCase == "-setanisofilter"
3636 || aNameCase == "-aniso"
3637 || aNameCase == "-anisofilter")
3638 && anArgIter + 1 < theArgsNb)
3640 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3644 if (aValue == "off")
3646 anAnisoFilter = Graphic3d_LOTA_OFF;
3648 else if (aValue == "fast")
3650 anAnisoFilter = Graphic3d_LOTA_FAST;
3652 else if (aValue == "middle")
3654 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
3656 else if (aValue == "quality"
3657 || aValue == "high")
3659 anAnisoFilter = Graphic3d_LOTA_QUALITY;
3663 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3667 else if ((aNameCase == "-rotateangle"
3668 || aNameCase == "-rotangle"
3669 || aNameCase == "-rotate"
3670 || aNameCase == "-angle"
3671 || aNameCase == "-trsfangle")
3672 && anArgIter + 1 < theArgsNb)
3674 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3675 toSetTrsfAngle = true;
3678 else if ((aNameCase == "-trsftrans"
3679 || aNameCase == "-trsftranslate"
3680 || aNameCase == "-translate"
3681 || aNameCase == "-translation")
3682 && anArgIter + 2 < theArgsNb)
3684 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3685 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3686 toSetTrsfTrans = true;
3689 else if ((aNameCase == "-trsfscale")
3690 && anArgIter + 2 < theArgsNb)
3692 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3693 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3694 toSetTrsfScale = true;
3697 else if (aNameCase == "-default"
3698 || aNameCase == "-defaults")
3700 toSetDefaults = true;
3702 else if (aCommandName == "vtexture"
3703 && (aTextureVecNew.IsEmpty()
3704 || aNameCase.StartsWith ("-tex")))
3706 Standard_Integer aTexIndex = 0;
3707 TCollection_AsciiString aTexName = aName;
3708 if (aNameCase.StartsWith ("-tex"))
3710 if (anArgIter + 1 >= theArgsNb
3711 || aNameCase.Length() < 5)
3713 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3717 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
3718 if (!aTexIndexStr.IsIntegerValue())
3720 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3724 aTexIndex = aTexIndexStr.IntegerValue();
3725 aTexName = theArgVec[anArgIter + 1];
3728 if (aTexIndex >= Graphic3d_TextureUnit_NB
3729 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
3731 std::cout << "Error: too many textures specified\n";
3736 if (aTexName.IsIntegerValue())
3738 const Standard_Integer aValue = aTexName.IntegerValue();
3739 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
3741 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
3744 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
3746 else if (aTexName == "?")
3748 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3750 theDi << "\n Files in current directory : \n\n";
3751 theDi.Eval ("glob -nocomplain *");
3753 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3754 aCmnd += aTextureFolder;
3757 theDi << "Files in " << aTextureFolder << " : \n\n";
3758 theDi.Eval (aCmnd.ToCString());
3761 else if (aTexName != "off")
3763 if (!OSD_File (aTexName).Exists())
3765 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
3768 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
3772 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
3775 if (aTextureVecNew.Value (aTexIndex))
3777 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
3782 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3789 // check if new image set is equal to already set one
3790 Standard_Integer aNbChanged = 0;
3791 Handle(Graphic3d_TextureSet) aTextureSetNew;
3792 if (!aTextureVecNew.IsEmpty())
3794 aNbChanged = aTextureVecNew.Size();
3795 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
3796 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
3798 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
3799 Handle(Graphic3d_TextureRoot) aTextureOld;
3800 if (!aTextureSetOld.IsNull()
3801 && aTexIter < aTextureSetOld->Size())
3803 aTextureOld = aTextureSetOld->Value (aTexIter);
3806 if (!aTextureOld.IsNull()
3807 && !aTextureNew.IsNull())
3809 *aTextureNew->GetParams() = *aTextureOld->GetParams();
3810 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
3812 TCollection_AsciiString aFilePathOld, aFilePathNew;
3813 aTextureOld->Path().SystemName (aFilePathOld);
3814 aTextureNew->Path().SystemName (aFilePathNew);
3815 if (aTextureNew->Name() == anOldManualTex->Name()
3816 && aFilePathOld == aFilePathNew
3817 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
3820 aTextureNew = anOldManualTex;
3824 aTextureSetNew->SetValue (aTexIter, aTextureNew);
3828 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
3829 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
3831 aTextureSetNew = aTextureSetOld;
3834 if (!aTexturedIO->Attributes()->HasOwnShadingAspect())
3836 aTexturedIO->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
3837 *aTexturedIO->Attributes()->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
3840 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
3841 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
3842 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
3843 aTextureSetOld.Nullify();
3848 if (toModulate != -1)
3855 aFilter = Graphic3d_TOTF_BILINEAR;
3860 anAnisoFilter = Graphic3d_LOTA_OFF;
3862 if (!toSetTrsfAngle)
3864 toSetTrsfAngle = true;
3865 aTrsfRotAngle = 0.0f;
3867 if (!toSetTrsfTrans)
3869 toSetTrsfTrans = true;
3870 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
3872 if (!toSetTrsfScale)
3874 toSetTrsfScale = true;
3875 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
3879 if (aCommandName == "vtexture"
3882 if (!aTextureSetOld.IsNull())
3884 //toComputeUV = true; // we can keep UV vertex attributes
3885 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
3886 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
3887 aTextureSetOld.Nullify();
3891 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
3892 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
3894 if (toModulate != -1)
3896 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
3900 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
3904 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
3908 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
3912 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
3916 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
3920 // set default values if requested
3922 && (aCommandName == "vtexrepeat"
3925 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3926 toSetGenRepeat = true;
3929 && (aCommandName == "vtexorigin"
3932 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3933 toSetGenOrigin = true;
3936 && (aCommandName == "vtexscale"
3939 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3940 toSetGenScale = true;
3943 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
3945 aTexturedIO->SetToUpdate (AIS_Shaded);
3948 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
3949 || aCtx->DisplayMode() != AIS_Shaded)
3951 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
3955 aCtx->Display (aTexturedIO, false);
3956 aTexturedIO->SynchronizeAspects();
3960 //! Auxiliary method to parse transformation persistence flags
3961 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3962 Graphic3d_TransModeFlags& theFlags)
3964 if (theFlagString == "zoom")
3966 theFlags = Graphic3d_TMF_ZoomPers;
3968 else if (theFlagString == "rotate")
3970 theFlags = Graphic3d_TMF_RotatePers;
3972 else if (theFlagString == "zoomrotate")
3974 theFlags = Graphic3d_TMF_ZoomRotatePers;
3976 else if (theFlagString == "trihedron"
3977 || theFlagString == "triedron")
3979 theFlags = Graphic3d_TMF_TriedronPers;
3981 else if (theFlagString == "none")
3983 theFlags = Graphic3d_TMF_None;
3987 return Standard_False;
3990 return Standard_True;
3993 //! Auxiliary method to parse transformation persistence flags
3994 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
3995 Aspect_TypeOfTriedronPosition& theCorner)
3997 TCollection_AsciiString aString (theString);
3998 aString.LowerCase();
3999 if (aString == "center")
4001 theCorner = Aspect_TOTP_CENTER;
4003 else if (aString == "top"
4004 || aString == "upper")
4006 theCorner = Aspect_TOTP_TOP;
4008 else if (aString == "bottom"
4009 || aString == "lower")
4011 theCorner = Aspect_TOTP_BOTTOM;
4013 else if (aString == "left")
4015 theCorner = Aspect_TOTP_LEFT;
4017 else if (aString == "right")
4019 theCorner = Aspect_TOTP_RIGHT;
4021 else if (aString == "topleft"
4022 || aString == "leftupper"
4023 || aString == "upperleft")
4025 theCorner = Aspect_TOTP_LEFT_UPPER;
4027 else if (aString == "bottomleft"
4028 || aString == "leftlower"
4029 || aString == "lowerleft")
4031 theCorner = Aspect_TOTP_LEFT_LOWER;
4033 else if (aString == "topright"
4034 || aString == "rightupper"
4035 || aString == "upperright")
4037 theCorner = Aspect_TOTP_RIGHT_UPPER;
4039 else if (aString == "bottomright"
4040 || aString == "lowerright"
4041 || aString == "rightlower")
4043 theCorner = Aspect_TOTP_RIGHT_LOWER;
4047 return Standard_False;
4050 return Standard_True;
4053 //==============================================================================
4054 //function : VDisplay2
4056 //purpose : Display an object from its name
4057 //==============================================================================
4058 static int VDisplay2 (Draw_Interpretor& theDI,
4059 Standard_Integer theArgNb,
4060 const char** theArgVec)
4064 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4068 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4071 ViewerTest::ViewerInit();
4072 aCtx = ViewerTest::GetAISContext();
4075 // Parse input arguments
4076 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4077 Standard_Integer isMutable = -1;
4078 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4079 Standard_Boolean toReDisplay = Standard_False;
4080 Standard_Integer isSelectable = -1;
4081 Standard_Integer anObjDispMode = -2;
4082 Standard_Integer anObjHighMode = -2;
4083 Standard_Boolean toSetTrsfPers = Standard_False;
4084 Handle(Graphic3d_TransformPers) aTrsfPers;
4085 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4086 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4087 Standard_Integer toDisplayInView = Standard_False;
4088 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4090 const TCollection_AsciiString aName = theArgVec[anArgIter];
4091 TCollection_AsciiString aNameCase = aName;
4092 aNameCase.LowerCase();
4093 if (anUpdateTool.parseRedrawMode (aName))
4097 else if (aNameCase == "-mutable")
4101 else if (aNameCase == "-neutral")
4103 aDispStatus = AIS_DS_Displayed;
4105 else if (aNameCase == "-immediate"
4106 || aNameCase == "-top")
4108 aZLayer = Graphic3d_ZLayerId_Top;
4110 else if (aNameCase == "-topmost")
4112 aZLayer = Graphic3d_ZLayerId_Topmost;
4114 else if (aNameCase == "-osd"
4115 || aNameCase == "-toposd"
4116 || aNameCase == "-overlay")
4118 aZLayer = Graphic3d_ZLayerId_TopOSD;
4120 else if (aNameCase == "-botosd"
4121 || aNameCase == "-underlay")
4123 aZLayer = Graphic3d_ZLayerId_BotOSD;
4125 else if (aNameCase == "-select"
4126 || aNameCase == "-selectable")
4130 else if (aNameCase == "-noselect"
4131 || aNameCase == "-noselection")
4135 else if (aNameCase == "-dispmode"
4136 || aNameCase == "-displaymode")
4138 if (++anArgIter >= theArgNb)
4140 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4144 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4146 else if (aNameCase == "-highmode"
4147 || aNameCase == "-highlightmode")
4149 if (++anArgIter >= theArgNb)
4151 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4155 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4157 else if (aNameCase == "-3d")
4159 toSetTrsfPers = Standard_True;
4160 aTrsfPers.Nullify();
4162 else if (aNameCase == "-2d"
4163 || aNameCase == "-trihedron"
4164 || aNameCase == "-triedron")
4166 toSetTrsfPers = Standard_True;
4167 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4169 if (anArgIter + 1 < theArgNb)
4171 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4172 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4175 aTrsfPers->SetCorner2d (aCorner);
4177 if (anArgIter + 2 < theArgNb)
4179 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4180 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4181 if (anX.IsIntegerValue()
4182 && anY.IsIntegerValue())
4185 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4191 else if (aNameCase == "-trsfpers"
4192 || aNameCase == "-pers")
4194 if (++anArgIter >= theArgNb
4195 || !aTrsfPers.IsNull())
4197 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4201 toSetTrsfPers = Standard_True;
4202 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4203 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4204 aPersFlags.LowerCase();
4205 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
4207 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
4211 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4213 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4215 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4217 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
4220 else if (aNameCase == "-trsfperspos"
4221 || aNameCase == "-perspos")
4223 if (anArgIter + 2 >= theArgNb
4224 || aTrsfPers.IsNull())
4226 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4230 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4231 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4232 TCollection_AsciiString aZ = "0";
4233 if (!aX.IsRealValue()
4234 || !aY.IsRealValue())
4236 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4239 if (anArgIter + 1 < theArgNb)
4241 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
4242 if (aTemp.IsRealValue())
4249 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
4250 if (aTrsfPers->IsZoomOrRotate())
4252 aTrsfPers->SetAnchorPoint (aPnt);
4254 else if (aTrsfPers->IsTrihedronOr2d())
4256 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
4259 else if (aNameCase == "-layer")
4261 if (++anArgIter >= theArgNb)
4263 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4267 TCollection_AsciiString aValue (theArgVec[anArgIter]);
4268 if (!aValue.IsIntegerValue())
4270 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4274 aZLayer = aValue.IntegerValue();
4276 else if (aNameCase == "-view"
4277 || aNameCase == "-inview")
4279 toDisplayInView = Standard_True;
4281 else if (aNameCase == "-redisplay")
4283 toReDisplay = Standard_True;
4285 else if (aNameCase == "-erased"
4286 || aNameCase == "-load")
4288 aDispStatus = AIS_DS_Erased;
4292 aNamesOfDisplayIO.Append (aName);
4296 if (aNamesOfDisplayIO.IsEmpty())
4298 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4302 // Display interactive objects
4303 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
4305 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
4306 Handle(AIS_InteractiveObject) aShape;
4307 if (!GetMapOfAIS().Find2 (aName, aShape))
4309 // create the AIS_Shape from a name
4310 aShape = GetAISShapeFromName (aName.ToCString());
4311 if (!aShape.IsNull())
4313 if (isMutable != -1)
4315 aShape->SetMutable (isMutable == 1);
4317 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4319 aShape->SetZLayer (aZLayer);
4323 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4325 if (anObjDispMode != -2)
4327 aShape->SetDisplayMode (anObjDispMode);
4329 if (anObjHighMode != -2)
4331 aShape->SetHilightMode (anObjHighMode);
4334 GetMapOfAIS().Bind (aShape, aName);
4335 Standard_Integer aDispMode = aShape->HasDisplayMode()
4336 ? aShape->DisplayMode()
4337 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4338 ? aCtx->DisplayMode()
4340 Standard_Integer aSelMode = -1;
4341 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4343 aSelMode = aShape->GlobalSelectionMode();
4346 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
4347 if (toDisplayInView)
4349 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
4351 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
4353 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4358 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
4363 if (isMutable != -1)
4365 aShape->SetMutable (isMutable == 1);
4367 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4369 aShape->SetZLayer (aZLayer);
4373 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4375 if (anObjDispMode != -2)
4377 aShape->SetDisplayMode (anObjDispMode);
4379 if (anObjHighMode != -2)
4381 aShape->SetHilightMode (anObjHighMode);
4383 Standard_Integer aDispMode = aShape->HasDisplayMode()
4384 ? aShape->DisplayMode()
4385 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4386 ? aCtx->DisplayMode()
4388 Standard_Integer aSelMode = -1;
4389 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4391 aSelMode = aShape->GlobalSelectionMode();
4394 if (aShape->Type() == AIS_KOI_Datum)
4396 aCtx->Display (aShape, Standard_False);
4400 theDI << "Display " << aName.ToCString() << "\n";
4402 // update the Shape in the AIS_Shape
4403 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
4404 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
4405 if (!aShapePrs.IsNull())
4407 if (!aShapePrs->Shape().IsEqual (aNewShape))
4409 toReDisplay = Standard_True;
4411 aShapePrs->Set (aNewShape);
4415 aCtx->Redisplay (aShape, Standard_False);
4420 aCtx->Erase (aShape, Standard_False);
4422 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
4423 if (toDisplayInView)
4425 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4433 //=======================================================================
4434 //function : VNbDisplayed
4435 //purpose : Returns number of displayed objects
4436 //=======================================================================
4437 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
4438 Standard_Integer theArgsNb,
4439 const char** theArgVec)
4443 theDi << "Usage : " << theArgVec[0] << "\n";
4447 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4448 if (aContextAIS.IsNull())
4450 std::cout << theArgVec[0] << "AIS context is not available.\n";
4454 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4455 if(aContext.IsNull())
4457 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
4461 AIS_ListOfInteractive aListOfIO;
4462 aContextAIS->DisplayedObjects (aListOfIO);
4464 theDi << aListOfIO.Extent() << "\n";
4468 //===============================================================================================
4469 //function : VUpdate
4471 //===============================================================================================
4472 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
4474 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4475 if (aContextAIS.IsNull())
4477 std::cout << theArgVec[0] << "AIS context is not available.\n";
4483 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
4487 AIS_ListOfInteractive aListOfIO;
4488 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4490 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
4492 Handle(AIS_InteractiveObject) anAISObj;
4493 GetMapOfAIS().Find2 (aName, anAISObj);
4494 if (anAISObj.IsNull())
4496 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
4500 aListOfIO.Append (anAISObj);
4503 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
4504 for (; anIOIt.More(); anIOIt.Next())
4506 aContextAIS->Update (anIOIt.Value(), Standard_False);
4509 aContextAIS->UpdateCurrentViewer();
4514 //==============================================================================
4515 //function : VShading
4516 //purpose : Sharpen or roughten the quality of the shading
4517 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4518 //==============================================================================
4519 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4521 Standard_Real myDevCoef;
4522 Handle(AIS_InteractiveObject) TheAisIO;
4525 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4529 myDevCoef =Draw::Atof(argv[2]);
4532 TCollection_AsciiString name=argv[1];
4533 GetMapOfAIS().Find2(name, TheAisIO);
4534 if (TheAisIO.IsNull())
4535 TheAisIO=GetAISShapeFromName(name.ToCString());
4538 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4540 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4542 TheAISContext()->Redisplay (TheAisIO, Standard_True);
4546 //! Auxiliary method to print Interactive Object information
4547 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4548 const Handle(AIS_InteractiveObject)& theObj,
4549 Draw_Interpretor& theDI)
4551 if (theObj.IsNull())
4553 theDI << "NULL presentation\n";
4557 theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ")
4558 << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ")
4559 << (theDetected.Contains (theObj) ? " Detected" : " ")
4561 if (theObj->Type() == AIS_KOI_Datum)
4564 if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4565 else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; }
4566 else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; }
4567 else if (theObj->Signature() == 5) { theDI << " AIS_Line"; }
4568 else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; }
4569 else if (theObj->Signature() == 1) { theDI << " AIS_Point"; }
4570 else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4573 else if (theObj->Type() == AIS_KOI_Shape
4574 && theObj->Signature() == 0)
4576 theDI << " AIS_Shape";
4578 else if (theObj->Type() == AIS_KOI_Relation)
4580 // AIS_Dimention and AIS_Relation
4581 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (theObj);
4582 switch (aRelation->KindOfDimension())
4584 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4585 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4586 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4587 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4588 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4589 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4590 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4591 default: theDI << " UNKNOWN dimension"; break;
4596 theDI << " UserPrs";
4598 theDI << " (" << theObj->DynamicType()->Name() << ")";
4601 //! Print information about locally selected sub-shapes
4602 template <typename T>
4603 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4605 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4606 TCollection_AsciiString aPrevName;
4607 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4609 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4610 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4611 if (aShapeIO.IsNull() || anOwner.IsNull())
4615 if (anOwner == aShapeIO->GlobalSelOwner())
4618 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4619 if (aSubShape.IsNull()
4620 || aShapeIO.IsNull()
4621 || !GetMapOfAIS().IsBound1 (aShapeIO))
4626 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4627 TopTools_MapOfShape aFilter;
4628 Standard_Integer aNumber = 0;
4629 const TopoDS_Shape aShape = aShapeIO->Shape();
4630 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4631 anIter.More(); anIter.Next())
4633 if (!aFilter.Add (anIter.Current()))
4635 continue; // filter duplicates
4639 if (!anIter.Current().IsSame (aSubShape))
4644 Standard_CString aShapeName = NULL;
4645 switch (aSubShape.ShapeType())
4647 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4648 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4649 case TopAbs_SOLID: aShapeName = " Solid"; break;
4650 case TopAbs_SHELL: aShapeName = " Shell"; break;
4651 case TopAbs_FACE: aShapeName = " Face"; break;
4652 case TopAbs_WIRE: aShapeName = " Wire"; break;
4653 case TopAbs_EDGE: aShapeName = " Edge"; break;
4654 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4656 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4659 if (aParentName != aPrevName)
4661 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4662 aPrevName = aParentName;
4664 theDI << " " << aShapeName << " #" << aNumber << "\n";
4670 //==============================================================================
4673 //==============================================================================
4674 static Standard_Integer VState (Draw_Interpretor& theDI,
4675 Standard_Integer theArgNb,
4676 Standard_CString* theArgVec)
4678 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4681 std::cerr << "Error: No opened viewer!\n";
4685 Standard_Boolean toPrintEntities = Standard_False;
4686 Standard_Boolean toCheckSelected = Standard_False;
4688 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4690 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4691 anOption.LowerCase();
4692 if (anOption == "-detectedentities"
4693 || anOption == "-entities")
4695 toPrintEntities = Standard_True;
4697 else if (anOption == "-hasselected")
4699 toCheckSelected = Standard_True;
4703 if (toCheckSelected)
4705 aCtx->InitSelected();
4706 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4707 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4712 if (toPrintEntities)
4714 theDI << "Detected entities:\n";
4715 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
4717 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4718 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4720 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4721 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4722 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4723 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4724 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4725 aName.LeftJustify (20, ' ');
4726 char anInfoStr[512];
4728 " Depth: %g Distance: %g Point: %g %g %g",
4731 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4732 theDI << " " << aName
4734 << " (" << anEntity->DynamicType()->Name() << ")"
4737 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4738 if (!aBRepOwner.IsNull())
4740 theDI << " Detected Shape: "
4741 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4745 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4746 if (!aWire.IsNull())
4748 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4749 theDI << " Detected Child: "
4750 << aSen->DynamicType()->Name()
4754 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4755 if (!aPrimArr.IsNull())
4757 theDI << " Detected Element: "
4758 << aPrimArr->LastDetectedElement()
4765 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4766 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4768 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
4771 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4775 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4777 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4778 Handle(AIS_InteractiveObject) anObj;
4779 if (!GetMapOfAIS().Find2 (anObjName, anObj))
4781 theDI << anObjName << " doesn't exist!\n";
4785 TCollection_AsciiString aName = anObjName;
4786 aName.LeftJustify (20, ' ');
4787 theDI << " " << aName << " ";
4788 objInfo (aDetected, anObj, theDI);
4794 if (aCtx->NbSelected() > 0 && !toShowAll)
4796 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4797 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4799 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4800 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4801 // handle whole object selection
4802 if (anOwner == anObj->GlobalSelOwner())
4804 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4805 aName.LeftJustify (20, ' ');
4806 theDI << aName << " ";
4807 objInfo (aDetected, anObj, theDI);
4812 // process selected sub-shapes
4813 printLocalSelectionInfo (aCtx, theDI);
4818 theDI << "Neutral-point state:\n";
4819 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4820 anObjIter.More(); anObjIter.Next())
4822 if (anObjIter.Key1().IsNull())
4827 TCollection_AsciiString aName = anObjIter.Key2();
4828 aName.LeftJustify (20, ' ');
4829 theDI << " " << aName << " ";
4830 objInfo (aDetected, anObjIter.Key1(), theDI);
4833 printLocalSelectionInfo (aCtx, theDI);
4837 //=======================================================================
4838 //function : PickShape
4839 //purpose : First Activate the rightmode + Put Filters to be able to
4840 // pick objets that are of type <TheType>...
4841 //=======================================================================
4843 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
4844 const Standard_Integer theMaxPick)
4846 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
4847 PickShapes (theShapeType, aResArray, theMaxPick);
4848 return aResArray->First();
4851 //=======================================================================
4852 //function : PickShapes
4854 //=======================================================================
4855 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
4856 Handle(TopTools_HArray1OfShape)& theResArray,
4857 const Standard_Integer theMaxPick)
4859 const Standard_Integer aNbToReach = theResArray->Length();
4862 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4865 // step 1: prepare the data
4866 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4867 aCtx->RemoveFilters();
4868 AIS_ListOfInteractive aDispObjects;
4869 aCtx->DisplayedObjects (aDispObjects);
4870 if (theShapeType == TopAbs_SHAPE)
4872 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
4876 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
4879 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
4880 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
4882 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
4884 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
4888 // step 2 : wait for the selection...
4889 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
4890 Standard_Integer argccc = 5;
4891 const char *bufff[] = { "A", "B", "C", "D", "E" };
4892 const char **argvvv = (const char** )bufff;
4893 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
4895 while (ViewerMainLoop (argccc, argvvv)) {}
4896 Standard_Integer aNbStored = aCtx->NbSelected();
4897 if (aNbStored != aNbPickGood)
4899 aNbPickGood = aNbStored;
4905 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
4908 // step3 get result.
4909 if (aNbPickFail >= aNbToReach)
4911 return Standard_False;
4914 Standard_Integer anIndex = theResArray->Lower();
4915 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
4917 if (aCtx->HasSelectedShape())
4919 theResArray->SetValue (anIndex, aCtx->SelectedShape());
4923 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
4924 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
4928 aCtx->RemoveFilters();
4929 if (theShapeType != TopAbs_SHAPE)
4931 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
4933 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
4935 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
4939 return Standard_True;
4942 //=======================================================================
4943 //function : VPickShape
4945 //=======================================================================
4946 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4948 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4951 TCollection_AsciiString aShapeArg (argv[1]);
4952 aShapeArg.LowerCase();
4953 aShapeType = TopAbs_COMPOUND;
4954 if (aShapeArg == "v"
4955 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
4956 else if (aShapeArg == "e"
4957 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
4958 else if (aShapeArg == "w"
4959 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
4960 else if (aShapeArg == "f"
4961 || aShapeArg == "face") aShapeType = TopAbs_FACE;
4962 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
4963 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
4964 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
4967 std::cout << "Syntax error at '" << argv[1] << "'\n";
4972 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4973 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4975 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
4978 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
4979 if (aPickedShape.IsNull())
4984 TCollection_AsciiString aName;
4991 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
4992 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
4995 DBRep::Set (aName.ToCString(), aPickedShape);
4996 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
4997 ViewerTest::Display (aName, aShapePrs, false, true);
4998 di << "Name of picked shape: " << aName <<"\n";
5002 TCollection_AsciiString aName (argv[2]);
5004 const Standard_Boolean isAutoNaming = aName == ".";
5005 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5006 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5008 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5010 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5012 if (!aPickedShape.IsNull()
5015 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5016 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5020 aName = argv[1 + aPickedIter];
5023 DBRep::Set (aName.ToCString(), aPickedShape);
5024 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5025 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5026 ViewerTest::Display (aName, aShapePrs, false, true);
5030 TheAISContext()->UpdateCurrentViewer();
5034 //=======================================================================
5035 //function : VSelFilter
5037 //=======================================================================
5038 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5039 const char** theArgv)
5041 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5042 if (aContext.IsNull())
5044 std::cout << "Error: AIS context is not available.\n";
5048 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5050 TCollection_AsciiString anArg (theArgv[anArgIter]);
5052 if (anArg == "-clear")
5054 aContext->RemoveFilters();
5056 else if (anArg == "-type"
5057 && anArgIter + 1 < theArgc)
5059 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5060 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5061 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5063 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5067 Handle(SelectMgr_Filter) aFilter;
5068 if (aShapeType == TopAbs_SHAPE)
5070 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5074 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5076 aContext->AddFilter (aFilter);
5080 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5087 //=======================================================================
5088 //function : VPickSelected
5090 //=======================================================================
5091 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5093 static Standard_Integer aCount = 0;
5094 TCollection_AsciiString aName = "PickedShape_";
5102 aName = aName + aCount++ + "_";
5105 Standard_Integer anIdx = 0;
5106 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5108 TopoDS_Shape aShape;
5109 if (TheAISContext()->HasSelectedShape())
5111 aShape = TheAISContext()->SelectedShape();
5115 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5116 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5119 TCollection_AsciiString aCurrentName = aName;
5122 aCurrentName += anIdx;
5125 DBRep::Set ((aCurrentName).ToCString(), aShape);
5127 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5128 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5129 TheAISContext()->Display (aNewShape, Standard_False);
5132 TheAISContext()->UpdateCurrentViewer();
5137 //=======================================================================
5138 //function : list of known objects
5140 //=======================================================================
5141 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5143 // 1234567890 12345678901234567 123456789
5144 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5145 TCollection_AsciiString BlankLine(64,'_');
5146 Standard_Integer i ;
5148 di<<"/n"<<BlankLine.ToCString()<<"\n";
5151 Colum[i].Center(20,' ');
5153 di<<"|"<<Colum[i].ToCString();
5156 di<<BlankLine.ToCString()<<"\n";
5158 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5159 const char ** names = GetTypeNames();
5161 TCollection_AsciiString curstring;
5162 TCollection_AsciiString curcolum[3];
5165 // les objets de type Datum..
5166 curcolum[1]+="Datum";
5168 curcolum[0].Clear();
5169 curcolum[0] += names[i];
5171 curcolum[2].Clear();
5172 curcolum[2]+=TCollection_AsciiString(i+1);
5174 for(Standard_Integer j =0;j<=2;j++){
5175 curcolum[j].Center(20,' ');
5176 di<<"|"<<curcolum[j].ToCString();
5180 di<<BlankLine.ToCString()<<"\n";
5182 // les objets de type shape
5183 curcolum[1].Clear();
5184 curcolum[1]+="Shape";
5185 curcolum[1].Center(20,' ');
5188 curcolum[0].Clear();
5189 curcolum[0] += names[7+i];
5190 curcolum[2].Clear();
5191 curcolum[2]+=TCollection_AsciiString(i);
5193 for(Standard_Integer j =0;j<=2;j++){
5194 curcolum[j].Center(20,' ');
5195 di<<"|"<<curcolum[j].ToCString();
5199 di<<BlankLine.ToCString()<<"\n";
5200 // les IO de type objet...
5201 curcolum[1].Clear();
5202 curcolum[1]+="Object";
5203 curcolum[1].Center(20,' ');
5205 curcolum[0].Clear();
5206 curcolum[0] += names[10+i];
5207 curcolum[2].Clear();
5208 curcolum[2]+=TCollection_AsciiString(i);
5210 for(Standard_Integer j =0;j<=2;j++){
5211 curcolum[j].Center(20,' ');
5212 di<<"|"<<curcolum[j].ToCString();
5216 di<<BlankLine.ToCString()<<"\n";
5217 // les contraintes et dimensions.
5218 // pour l'instant on separe juste contraintes et dimensions...
5219 // plus tard, on detaillera toutes les sortes...
5220 curcolum[1].Clear();
5221 curcolum[1]+="Relation";
5222 curcolum[1].Center(20,' ');
5224 curcolum[0].Clear();
5225 curcolum[0] += names[12+i];
5226 curcolum[2].Clear();
5227 curcolum[2]+=TCollection_AsciiString(i);
5229 for(Standard_Integer j =0;j<=2;j++){
5230 curcolum[j].Center(20,' ');
5231 di<<"|"<<curcolum[j].ToCString();
5235 di<<BlankLine.ToCString()<<"\n";
5242 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5244 if(argc!=2) return 1;
5246 AIS_KindOfInteractive TheType;
5247 Standard_Integer TheSign(-1);
5248 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5251 AIS_ListOfInteractive LIO;
5253 // en attendant l'amelioration ais pour les dimensions...
5255 Standard_Integer dimension_status(-1);
5256 if(TheType==AIS_KOI_Relation){
5257 dimension_status = TheSign ==1 ? 1 : 0;
5261 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5262 Handle(AIS_InteractiveObject) curio;
5263 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5266 if(dimension_status == -1)
5267 TheAISContext()->Erase(curio,Standard_False);
5269 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5270 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5271 (dimension_status==1 && KOD != AIS_KOD_NONE))
5272 TheAISContext()->Erase(curio,Standard_False);
5275 TheAISContext()->UpdateCurrentViewer();
5278 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5280 if(argc!=2) return 1;
5282 AIS_KindOfInteractive TheType;
5283 Standard_Integer TheSign(-1);
5284 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5286 // en attendant l'amelioration ais pour les dimensions...
5288 Standard_Integer dimension_status(-1);
5289 if(TheType==AIS_KOI_Relation){
5290 dimension_status = TheSign ==1 ? 1 : 0;
5294 AIS_ListOfInteractive LIO;
5295 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5296 Handle(AIS_InteractiveObject) curio;
5297 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5299 if(dimension_status == -1)
5300 TheAISContext()->Display(curio,Standard_False);
5302 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5303 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5304 (dimension_status==1 && KOD != AIS_KOD_NONE))
5305 TheAISContext()->Display(curio,Standard_False);
5310 TheAISContext()->UpdateCurrentViewer();
5314 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5317 BRep_Builder builder;
5319 BRepTools::Read(shape, s, builder);
5320 DBRep::Set(a[1], shape);
5321 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5322 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5323 Ctx->Display (ais, Standard_True);
5327 //===============================================================================================
5330 //===============================================================================================
5331 static int VBsdf (Draw_Interpretor& theDI,
5332 Standard_Integer theArgsNb,
5333 const char** theArgVec)
5335 Handle(V3d_View) aView = ViewerTest::CurrentView();
5336 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5338 || aViewer.IsNull())
5340 std::cerr << "No active viewer!\n";
5344 ViewerTest_CmdParser aCmd;
5346 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5348 aCmd.AddOption ("print|echo|p", "Prints BSDF");
5350 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
5352 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
5353 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
5354 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
5355 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
5356 aCmd.AddOption ("le", "Radiance emitted by surface");
5358 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5359 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5361 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
5362 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
5364 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
5365 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
5367 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
5369 aCmd.Parse (theArgsNb, theArgVec);
5371 if (aCmd.HasOption ("help"))
5373 theDI.PrintHelp (theArgVec[0]);
5377 // check viewer update mode
5378 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
5379 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5381 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5388 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5389 Handle(AIS_InteractiveObject) anIObj;
5390 if (!GetMapOfAIS().Find2 (aName, anIObj))
5392 std::cerr << "Use 'vdisplay' before\n";
5396 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5397 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5399 if (aCmd.HasOption ("print"))
5402 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
5403 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5404 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5405 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5406 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
5408 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5410 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
5411 : aBSDF.FresnelBase.Serialize();
5413 theDI << (aLayerID < 1 ? "Coat Fresnel: "
5414 : "Base Fresnel: ");
5416 if (aFresnel.x() >= 0.f)
5418 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
5419 << "G = " << aFresnel.g() << ", "
5420 << "B = " << aFresnel.b() << "\n";
5422 else if (aFresnel.x() >= -1.5f)
5424 theDI << "Constant " << aFresnel.z() << "\n";
5426 else if (aFresnel.x() >= -2.5f)
5428 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
5429 << "K = " << aFresnel.z() << "\n";
5433 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
5437 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
5438 << "Base roughness: " << aBSDF.Ks.w() << "\n"
5439 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
5440 << "Absorption color: " << aBSDF.Absorption.r() << ", "
5441 << aBSDF.Absorption.g() << ", "
5442 << aBSDF.Absorption.b() << "\n";
5447 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
5449 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
5452 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
5454 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
5457 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5459 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
5462 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5464 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
5466 aBSDF.Absorption.r() = aRGB.r();
5467 aBSDF.Absorption.g() = aRGB.g();
5468 aBSDF.Absorption.b() = aRGB.b();
5471 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
5475 if (aCmd.HasOption ("kc", 3))
5477 aKc = aCmd.ArgVec3f ("kc");
5481 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
5484 aBSDF.Kc.r() = aKc.r();
5485 aBSDF.Kc.g() = aKc.g();
5486 aBSDF.Kc.b() = aKc.b();
5489 if (aCmd.HasOption ("kd", 3))
5491 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5493 else if (aCmd.HasOption ("kd", 1, Standard_True))
5495 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5498 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
5502 if (aCmd.HasOption ("ks", 3))
5504 aKs = aCmd.ArgVec3f ("ks");
5508 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5511 aBSDF.Ks.r() = aKs.r();
5512 aBSDF.Ks.g() = aKs.g();
5513 aBSDF.Ks.b() = aKs.b();
5516 if (aCmd.HasOption ("kt", 3))
5518 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5520 else if (aCmd.HasOption ("kt", 1, Standard_True))
5522 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5525 if (aCmd.HasOption ("le", 3))
5527 aBSDF.Le = aCmd.ArgVec3f ("le");
5529 else if (aCmd.HasOption ("le", 1, Standard_True))
5531 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5534 const std::string aFresnelErrorMessage =
5535 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
5537 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5539 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
5542 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
5544 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5545 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5547 if (aFresnelType == "schlick")
5549 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
5550 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
5551 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
5553 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
5554 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
5555 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
5557 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
5561 theDI << aFresnelErrorMessage.c_str() << "\n";
5564 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
5566 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5567 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5569 if (aFresnelType == "conductor")
5571 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5572 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
5574 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
5578 theDI << aFresnelErrorMessage.c_str() << "\n";
5581 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
5583 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5584 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5586 if (aFresnelType == "constant")
5588 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5590 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
5592 else if (aFresnelType == "dielectric")
5594 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5596 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
5600 theDI << aFresnelErrorMessage.c_str() << "\n";
5605 if (aCmd.HasOption ("normalize"))
5610 aMaterial.SetBSDF (aBSDF);
5611 anIObj->SetMaterial (aMaterial);
5616 //==============================================================================
5617 //function : VLoadSelection
5618 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5619 //==============================================================================
5620 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5621 Standard_Integer theArgNb,
5622 const char** theArgVec)
5626 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5630 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5633 ViewerTest::ViewerInit();
5634 aCtx = ViewerTest::GetAISContext();
5637 // Parse input arguments
5638 TColStd_SequenceOfAsciiString aNamesOfIO;
5639 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5641 const TCollection_AsciiString aName = theArgVec[anArgIter];
5642 aNamesOfIO.Append (aName);
5645 if (aNamesOfIO.IsEmpty())
5647 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5651 // Load selection of interactive objects
5652 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5654 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5656 Handle(AIS_InteractiveObject) aShape;
5657 if (!GetMapOfAIS().Find2 (aName, aShape))
5659 aShape = GetAISShapeFromName (aName.ToCString());
5662 if (!aShape.IsNull())
5664 if (!GetMapOfAIS().IsBound2 (aName))
5666 GetMapOfAIS().Bind (aShape, aName);
5669 aCtx->Load (aShape, -1);
5670 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5677 //==============================================================================
5678 //function : ViewerTest::Commands
5679 //purpose : Add all the viewer command in the Draw_Interpretor
5680 //==============================================================================
5682 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5684 ViewerTest::ViewerCommands(theCommands);
5685 ViewerTest::RelationCommands(theCommands);
5686 ViewerTest::ObjectCommands(theCommands);
5687 ViewerTest::FilletCommands(theCommands);
5688 ViewerTest::OpenGlCommands(theCommands);
5690 const char *group = "AIS_Display";
5693 theCommands.Add("visos",
5694 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5695 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5696 __FILE__, visos, group);
5698 theCommands.Add("vdisplay",
5699 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5700 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5701 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5702 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5703 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5704 "\n\t\t: [offsetX offsetY]]]"
5705 "\n\t\t: [-dispMode mode] [-highMode mode]"
5706 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5707 "\n\t\t: [-redisplay] [-erased]"
5708 "\n\t\t: name1 [name2] ... [name n]"
5709 "\n\t\t: Displays named objects."
5710 "\n\t\t: Option -local enables displaying of objects in local"
5711 "\n\t\t: selection context. Local selection context will be opened"
5712 "\n\t\t: if there is not any."
5713 "\n\t\t: -noupdate Suppresses viewer redraw call."
5714 "\n\t\t: -mutable Enables optimizations for mutable objects."
5715 "\n\t\t: -neutral Draws objects in main viewer."
5716 "\n\t\t: -erased Loads the object into context, but does not display it."
5717 "\n\t\t: -layer Sets z-layer for objects."
5718 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5719 "\n\t\t: options can be used for the default z-layers."
5720 "\n\t\t: -top Draws object on top of main presentations"
5721 "\n\t\t: but below topmost."
5722 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5723 "\n\t\t: with independent Depth."
5724 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5725 "\n\t\t: (On-Screen-Display)"
5726 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5727 "\n\t\t: (On-Screen-Display)"
5728 "\n\t\t: -selectable|-noselect Controls selection of objects."
5729 "\n\t\t: -trsfPers Sets a transform persistence flags."
5730 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5731 "\n\t\t: -2d Displays object in screen coordinates."
5732 "\n\t\t: (DY looks up)"
5733 "\n\t\t: -dispmode Sets display mode for objects."
5734 "\n\t\t: -highmode Sets hilight mode for objects."
5735 "\n\t\t: -redisplay Recomputes presentation of objects.",
5736 __FILE__, VDisplay2, group);
5738 theCommands.Add ("vnbdisplayed",
5740 "\n\t\t: Returns number of displayed objects",
5741 __FILE__, VNbDisplayed, group);
5743 theCommands.Add ("vupdate",
5744 "vupdate name1 [name2] ... [name n]"
5745 "\n\t\t: Updates named objects in interactive context",
5746 __FILE__, VUpdate, group);
5748 theCommands.Add("verase",
5749 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5750 "\n\t\t: Erases selected or named objects."
5751 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5752 "\n\t\t: Option -local enables erasing of selected or named objects without"
5753 "\n\t\t: closing local selection context.",
5754 __FILE__, VErase, group);
5756 theCommands.Add("vremove",
5757 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5758 "or vremove [-context] -all to remove all objects"
5759 "\n\t\t: Removes selected or named objects."
5760 "\n\t\t If -context is in arguments, the objects are not deleted"
5761 "\n\t\t from the map of objects and names."
5762 "\n\t\t: Option -local enables removing of selected or named objects without"
5763 "\n\t\t: closing local selection context. Empty local selection context will be"
5765 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5766 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5767 __FILE__, VRemove, group);
5769 theCommands.Add("vdonly",
5770 "vdonly [-noupdate|-update] [name1] ... [name n]"
5771 "\n\t\t: Displays only selected or named objects",
5772 __FILE__,VDonly2,group);
5774 theCommands.Add("vdisplayall",
5776 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
5777 __FILE__, VDisplayAll, group);
5779 theCommands.Add("veraseall",
5781 "\n\t\t: Erases all objects displayed in the viewer.",
5782 __FILE__, VErase, group);
5784 theCommands.Add("verasetype",
5786 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5787 __FILE__, VEraseType, group);
5788 theCommands.Add("vbounding",
5789 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5790 "\n\t\t: [-print] [-hide]"
5791 "\n\t\t: Temporarily display bounding box of specified Interactive"
5792 "\n\t\t: Objects, or print it to console if -print is specified."
5793 "\n\t\t: Already displayed box might be hidden by -hide option.",
5794 __FILE__,VBounding,group);
5796 theCommands.Add("vdisplaytype",
5797 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5798 __FILE__,VDisplayType,group);
5800 theCommands.Add("vsetdispmode",
5801 "vsetdispmode [name] mode(1,2,..)"
5802 "\n\t\t: Sets display mode for all, selected or named objects.",
5803 __FILE__,VDispMode,group);
5805 theCommands.Add("vunsetdispmode",
5806 "vunsetdispmode [name]"
5807 "\n\t\t: Unsets custom display mode for selected or named objects.",
5808 __FILE__,VDispMode,group);
5810 theCommands.Add("vdir",
5811 "Lists all objects displayed in 3D viewer",
5812 __FILE__,VDir,group);
5814 #ifdef HAVE_FREEIMAGE
5815 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5817 #define DUMP_FORMATS "{ppm}"
5819 theCommands.Add("vdump",
5820 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5821 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5822 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5823 "\n\t\t: [-tileSize Size=0]"
5824 "\n\t\t: Dumps content of the active view into image file",
5825 __FILE__,VDump,group);
5827 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5828 __FILE__,VSubInt,group);
5830 theCommands.Add("vaspects",
5831 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5832 "\n\t\t: [-setVisibility 0|1]"
5833 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5834 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5835 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5836 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5837 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5838 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
5839 "\n\t\t: [-unsetMarkerType]"
5840 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
5841 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5842 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5843 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5844 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5845 "\n\t\t: [-isoontriangulation 0|1]"
5846 "\n\t\t: [-setMaxParamValue {value}]"
5847 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5848 "\n\t\t: [-setHatch HatchStyle]"
5849 "\n\t\t: [-setShadingModel {color|flat|gouraud|phong}]"
5850 "\n\t\t: [-unsetShadingModel]"
5851 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
5852 "\n\t\t: Manage presentation properties of all, selected or named objects."
5853 "\n\t\t: When -subshapes is specified than following properties will be"
5854 "\n\t\t: assigned to specified sub-shapes."
5855 "\n\t\t: When -defaults is specified than presentation properties will be"
5856 "\n\t\t: assigned to all objects that have not their own specified properties"
5857 "\n\t\t: and to all objects to be displayed in the future."
5858 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5859 __FILE__,VAspects,group);
5861 theCommands.Add("vsetcolor",
5862 "vsetcolor [-noupdate|-update] [name] ColorName"
5863 "\n\t\t: Sets color for all, selected or named objects."
5864 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5865 __FILE__,VAspects,group);
5867 theCommands.Add("vunsetcolor",
5868 "vunsetcolor [-noupdate|-update] [name]"
5869 "\n\t\t: Resets color for all, selected or named objects."
5870 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5871 __FILE__,VAspects,group);
5873 theCommands.Add("vsettransparency",
5874 "vsettransparency [-noupdate|-update] [name] Coefficient"
5875 "\n\t\t: Sets transparency for all, selected or named objects."
5876 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5877 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5878 __FILE__,VAspects,group);
5880 theCommands.Add("vunsettransparency",
5881 "vunsettransparency [-noupdate|-update] [name]"
5882 "\n\t\t: Resets transparency for all, selected or named objects."
5883 "\n\t\t: Alias for vaspects -unsettransp [name].",
5884 __FILE__,VAspects,group);
5886 theCommands.Add("vsetmaterial",
5887 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5888 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5889 __FILE__,VAspects,group);
5891 theCommands.Add("vunsetmaterial",
5892 "vunsetmaterial [-noupdate|-update] [name]"
5893 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5894 __FILE__,VAspects,group);
5896 theCommands.Add("vsetwidth",
5897 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5898 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5899 __FILE__,VAspects,group);
5901 theCommands.Add("vunsetwidth",
5902 "vunsetwidth [-noupdate|-update] [name]"
5903 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5904 __FILE__,VAspects,group);
5906 theCommands.Add("vsetinteriorstyle",
5907 "vsetinteriorstyle [-noupdate|-update] [name] style"
5908 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5909 __FILE__,VSetInteriorStyle,group);
5911 theCommands.Add("vsensdis",
5912 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5913 "\n\t\t: Standard entity types are those defined in Select3D package:"
5914 "\n\t\t: - sensitive box"
5915 "\n\t\t: - sensitive face"
5916 "\n\t\t: - sensitive curve"
5917 "\n\t\t: - sensitive segment"
5918 "\n\t\t: - sensitive circle"
5919 "\n\t\t: - sensitive point"
5920 "\n\t\t: - sensitive triangulation"
5921 "\n\t\t: - sensitive triangle"
5922 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5923 __FILE__,VDispSensi,group);
5925 theCommands.Add("vsensera",
5926 "vsensera : erase active entities",
5927 __FILE__,VClearSensi,group);
5929 theCommands.Add("vsetshading",
5930 "vsetshading : vsetshading name Quality(default=0.0008) "
5931 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5932 __FILE__,VShading,group);
5934 theCommands.Add("vunsetshading",
5935 "vunsetshading :vunsetshading name "
5936 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5937 __FILE__,VShading,group);
5939 theCommands.Add ("vtexture",
5940 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
5941 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
5942 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
5943 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
5944 "\n\t\t: [-modulate {on|off}]"
5945 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
5946 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
5947 "\n\t\t: [-default]"
5948 "\n\t\t: The texture can be specified by filepath"
5949 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
5950 "\n\t\t: The options are:"
5951 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
5952 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
5953 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
5954 "\n\t\t: -modulate Enable or disable texture color modulation"
5955 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
5956 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
5957 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
5958 "\n\t\t: -setFilter Setup texture filter"
5959 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
5960 "\n\t\t: -default Sets texture mapping default parameters",
5961 __FILE__, VTexture, group);
5963 theCommands.Add("vtexscale",
5964 "vtexscale name ScaleU ScaleV"
5965 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
5966 __FILE__,VTexture,group);
5968 theCommands.Add("vtexorigin",
5969 "vtexorigin name OriginU OriginV"
5970 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
5971 __FILE__,VTexture,group);
5973 theCommands.Add("vtexrepeat",
5974 "vtexrepeat name RepeatU RepeatV"
5975 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
5978 theCommands.Add("vtexdefault",
5980 "\n\t\t: Alias for vtexture name -default.",
5983 theCommands.Add("vstate",
5984 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5985 "\n\t\t: Reports show/hidden state for selected or named objects"
5986 "\n\t\t: -entities - print low-level information about detected entities"
5987 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5988 __FILE__,VState,group);
5990 theCommands.Add("vpickshapes",
5991 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
5992 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
5993 "\n\t\t: Hold also Shift for multiple selection.",
5994 __FILE__, VPickShape, group);
5996 theCommands.Add("vtypes",
5997 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6000 theCommands.Add("vr",
6002 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6003 __FILE__,vr, group);
6005 theCommands.Add("vselfilter",
6006 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6007 "\nSets selection shape type filter in context or remove all filters."
6008 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6009 "\n : Option -clear remove all filters in context",
6010 __FILE__,VSelFilter,group);
6012 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6013 __FILE__, VPickSelected, group);
6015 theCommands.Add ("vloadselection",
6016 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6017 "\n\t\t: primitives for the shapes with names given without displaying them.",
6018 __FILE__, VLoadSelection, group);
6020 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6021 "\nAdjusts parameters of material BSDF:"
6022 "\n -help : Shows this message"
6023 "\n -print : Print BSDF"
6024 "\n -kd : Weight of the Lambertian BRDF"
6025 "\n -kr : Weight of the reflection BRDF"
6026 "\n -kt : Weight of the transmission BTDF"
6027 "\n -ks : Weight of the glossy Blinn BRDF"
6028 "\n -le : Self-emitted radiance"
6029 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6030 "\n Schlick x y z, Dielectric x, Conductor x y"
6031 "\n -roughness : Roughness of material (Blinn's exponent)"
6032 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6033 "\n -absorpcolor : Absorption color (only for transparent material)"
6034 "\n -normalize : Normalize BSDF coefficients",
6035 __FILE__, VBsdf, group);
6039 //=====================================================================
6040 //========================= for testing Draft and Rib =================
6041 //=====================================================================
6042 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6043 #include <DBRep.hxx>
6044 #include <TopoDS_Face.hxx>
6045 #include <gp_Pln.hxx>
6046 #include <AIS_KindOfSurface.hxx>
6047 #include <BRepOffsetAPI_DraftAngle.hxx>
6048 #include <Precision.hxx>
6049 #include <BRepAlgo.hxx>
6050 #include <OSD_Environment.hxx>
6051 #include <DrawTrSurf.hxx>
6052 //#include <DbgTools.hxx>
6053 //#include <FeatAlgo_MakeLinearForm.hxx>
6058 //=======================================================================
6059 //function : IsValid
6061 //=======================================================================
6062 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6063 const TopoDS_Shape& theResult,
6064 const Standard_Boolean closedSolid,
6065 const Standard_Boolean GeomCtrl)
6067 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6068 TCollection_AsciiString checkValid = check.Value();
6069 Standard_Boolean ToCheck = Standard_True;
6070 if (!checkValid.IsEmpty()) {
6072 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6074 if ( checkValid=="true" || checkValid=="TRUE" ) {
6075 ToCheck= Standard_False;
6079 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6082 Standard_Boolean IsValid = Standard_True;
6084 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6089 //===============================================================================
6090 // TDraft : test draft, uses AIS Viewer
6091 // Solid Face Plane Angle Reverse
6092 //===============================================================================
6093 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6095 if (argc < 5) return 1;
6096 // argv[1] - TopoDS_Shape Solid
6097 // argv[2] - TopoDS_Shape Face
6098 // argv[3] - TopoDS_Shape Plane
6099 // argv[4] - Standard_Real Angle
6100 // argv[5] - Standard_Integer Reverse
6102 // Sprintf(prefix, argv[1]);
6103 Standard_Real anAngle = 0;
6104 Standard_Boolean Rev = Standard_False;
6105 Standard_Integer rev = 0;
6106 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
6107 TopoDS_Shape face = GetShapeFromName(argv[2]);
6108 TopoDS_Face Face = TopoDS::Face(face);
6109 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
6110 if (Plane.IsNull ()) {
6111 di << "TEST : Plane is NULL\n";
6114 anAngle = Draw::Atof(argv[4]);
6115 anAngle = 2*M_PI * anAngle / 360.0;
6117 Handle( Geom_Surface )aSurf;
6118 AIS_KindOfSurface aSurfType;
6119 Standard_Real Offset;
6121 if(argc > 4) { // == 5
6122 rev = Draw::Atoi(argv[5]);
6123 Rev = (rev)? Standard_True : Standard_False;
6126 TopoDS_Face face2 = TopoDS::Face(Plane);
6127 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6129 di << "TEST : Can't find plane\n";
6133 aDir = aPln.Axis().Direction();
6136 if (Plane.Orientation() == TopAbs_REVERSED)
6138 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6140 BRepOffsetAPI_DraftAngle Draft (Solid);
6142 if(Abs(anAngle)< Precision::Angular()) {
6143 di << "TEST : NULL angle\n";
6146 if(Rev) anAngle = - anAngle;
6147 Draft.Add (Face, aDir, anAngle, aPln);
6149 if (!Draft.IsDone()) {
6150 di << "TEST : Draft Not DONE \n";
6153 TopTools_ListOfShape Larg;
6155 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6156 di << "TEST : DesignAlgo returns Not valid\n";
6160 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6161 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6163 if ( !ais.IsNull() ) {
6164 ais->SetColor(DEFAULT_COLOR);
6165 ais->SetMaterial(DEFAULT_MATERIAL);
6166 // Display the AIS_Shape without redraw
6167 Ctx->Display(ais, Standard_False);
6169 const char *Name = "draft1";
6170 Handle(AIS_InteractiveObject) an_object;
6171 if (GetMapOfAIS().Find2(Name, an_object))
6173 if (!an_object.IsNull())
6175 Ctx->Remove (an_object, Standard_True);
6177 GetMapOfAIS().UnBind2 (Name);
6179 GetMapOfAIS().Bind(ais, Name);
6180 // DBRep::Set("draft", ais->Shape());
6182 Ctx->Display(ais, Standard_True);
6186 //==============================================================================
6187 //function : splitParameter
6188 //purpose : Split parameter string to parameter name and parameter value
6189 //==============================================================================
6190 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6191 TCollection_AsciiString& theName,
6192 TCollection_AsciiString& theValue)
6194 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6196 if (aParamNameEnd == 0)
6198 return Standard_False;
6201 TCollection_AsciiString aString (theString);
6202 if (aParamNameEnd != 0)
6204 theValue = aString.Split (aParamNameEnd);
6205 aString.Split (aString.Length() - 1);
6209 return Standard_True;
6212 //============================================================================
6214 //============================================================================
6215 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6218 DrawTrSurf::BasicCommands(theCommands);
6219 const char* group = "Check Features Operations commands";
6221 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6223 &TDraft,group); //Draft_Modification
6226 //==============================================================================
6227 // ViewerTest::Factory
6228 //==============================================================================
6229 void ViewerTest::Factory(Draw_Interpretor& theDI)
6231 // definition of Viewer Command
6232 ViewerTest::Commands(theDI);
6235 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6239 // Declare entry point PLUGINFACTORY