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 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
885 anIter.More(); anIter.Next())
887 theDI << "\t" << anIter.Key2() << "\n";
892 //! Auxiliary enumeration
893 enum ViewerTest_StereoPair
895 ViewerTest_SP_Single,
896 ViewerTest_SP_SideBySide,
897 ViewerTest_SP_OverUnder
900 //==============================================================================
902 //purpose : To dump the active view snapshot to image file
903 //==============================================================================
904 static Standard_Integer VDump (Draw_Interpretor& theDI,
905 Standard_Integer theArgNb,
906 Standard_CString* theArgVec)
910 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
914 Standard_Integer anArgIter = 1;
915 Standard_CString aFilePath = theArgVec[anArgIter++];
916 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
917 V3d_ImageDumpOptions aParams;
918 aParams.BufferType = Graphic3d_BT_RGB;
919 aParams.StereoOptions = V3d_SDO_MONO;
920 for (; anArgIter < theArgNb; ++anArgIter)
922 TCollection_AsciiString anArg (theArgVec[anArgIter]);
924 if (anArg == "-buffer")
926 if (++anArgIter >= theArgNb)
928 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
932 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
934 if (aBufArg == "rgba")
936 aParams.BufferType = Graphic3d_BT_RGBA;
938 else if (aBufArg == "rgb")
940 aParams.BufferType = Graphic3d_BT_RGB;
942 else if (aBufArg == "depth")
944 aParams.BufferType = Graphic3d_BT_Depth;
948 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
952 else if (anArg == "-stereo")
954 if (++anArgIter >= theArgNb)
956 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
960 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
961 aStereoArg.LowerCase();
962 if (aStereoArg == "l"
963 || aStereoArg == "left")
965 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
967 else if (aStereoArg == "r"
968 || aStereoArg == "right")
970 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
972 else if (aStereoArg == "mono")
974 aParams.StereoOptions = V3d_SDO_MONO;
976 else if (aStereoArg == "blended"
977 || aStereoArg == "blend"
978 || aStereoArg == "stereo")
980 aParams.StereoOptions = V3d_SDO_BLENDED;
982 else if (aStereoArg == "sbs"
983 || aStereoArg == "sidebyside")
985 aStereoPair = ViewerTest_SP_SideBySide;
987 else if (aStereoArg == "ou"
988 || aStereoArg == "overunder")
990 aStereoPair = ViewerTest_SP_OverUnder;
994 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
998 else if (anArg == "-rgba"
1001 aParams.BufferType = Graphic3d_BT_RGBA;
1003 else if (anArg == "-rgb"
1006 aParams.BufferType = Graphic3d_BT_RGB;
1008 else if (anArg == "-depth"
1009 || anArg == "depth")
1011 aParams.BufferType = Graphic3d_BT_Depth;
1013 else if (anArg == "-width"
1015 || anArg == "sizex")
1017 if (aParams.Width != 0)
1019 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1022 else if (++anArgIter >= theArgNb)
1024 std::cout << "Error: integer value is expected right after 'width'\n";
1027 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1029 else if (anArg == "-height"
1030 || anArg == "height"
1031 || anArg == "-sizey")
1033 if (aParams.Height != 0)
1035 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1038 else if (++anArgIter >= theArgNb)
1040 std::cout << "Error: integer value is expected right after 'height'\n";
1043 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1045 else if (anArg == "-tile"
1046 || anArg == "-tilesize")
1048 if (++anArgIter >= theArgNb)
1050 std::cout << "Error: integer value is expected right after 'tileSize'\n";
1053 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1057 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
1061 if ((aParams.Width <= 0 && aParams.Height > 0)
1062 || (aParams.Width > 0 && aParams.Height <= 0))
1064 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
1068 Handle(V3d_View) aView = ViewerTest::CurrentView();
1071 std::cout << "Error: cannot find an active view!\n";
1075 if (aParams.Width <= 0 || aParams.Height <= 0)
1077 aView->Window()->Size (aParams.Width, aParams.Height);
1080 Image_AlienPixMap aPixMap;
1081 Image_Format aFormat = Image_Format_UNKNOWN;
1082 switch (aParams.BufferType)
1084 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1085 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1086 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1087 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1090 switch (aStereoPair)
1092 case ViewerTest_SP_Single:
1094 if (!aView->ToPixMap (aPixMap, aParams))
1096 theDI << "Fail: view dump failed!\n";
1099 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1100 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1102 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1103 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1107 case ViewerTest_SP_SideBySide:
1109 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1111 theDI << "Fail: not enough memory for image allocation!\n";
1115 Image_PixMap aPixMapL, aPixMapR;
1116 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1117 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1118 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1119 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1121 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1122 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1123 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1124 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1127 theDI << "Fail: view dump failed!\n";
1132 case ViewerTest_SP_OverUnder:
1134 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1136 theDI << "Fail: not enough memory for image allocation!\n";
1140 Image_PixMap aPixMapL, aPixMapR;
1141 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1142 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1143 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1144 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1146 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1147 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1148 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1149 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1152 theDI << "Fail: view dump failed!\n";
1159 if (!aPixMap.Save (aFilePath))
1161 theDI << "Fail: image can not be saved!\n";
1166 enum TypeOfDispOperation
1168 TypeOfDispOperation_SetDispMode,
1169 TypeOfDispOperation_UnsetDispMode
1172 //! Displays,Erase...
1173 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1174 const Standard_Integer theMode,
1175 const TypeOfDispOperation theType,
1176 const Standard_Boolean theToUpdate)
1178 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1181 case TypeOfDispOperation_SetDispMode:
1183 if (!thePrs.IsNull())
1185 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1189 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1193 case TypeOfDispOperation_UnsetDispMode:
1195 if (!thePrs.IsNull())
1197 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1201 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1208 //=======================================================================
1211 //=======================================================================
1212 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1217 std::cout << "Syntax error: wrong number of arguments\n";
1221 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1222 ? TypeOfDispOperation_UnsetDispMode
1223 : TypeOfDispOperation_SetDispMode;
1224 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1225 if (aType == TypeOfDispOperation_UnsetDispMode)
1229 if (aCtx->NbSelected() == 0)
1231 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1235 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1237 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1240 aCtx->UpdateCurrentViewer();
1244 TCollection_AsciiString aName = argv[1];
1245 Handle(AIS_InteractiveObject) aPrs;
1246 if (GetMapOfAIS().Find2 (aName, aPrs)
1249 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1255 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1256 if (aCtx->NbSelected() == 0
1257 && aType == TypeOfDispOperation_SetDispMode)
1259 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1261 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1263 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1265 aCtx->UpdateCurrentViewer();
1269 Handle(AIS_InteractiveObject) aPrs;
1270 TCollection_AsciiString aName (argv[1]);
1271 if (GetMapOfAIS().Find2 (aName, aPrs)
1274 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1281 //=======================================================================
1284 //=======================================================================
1285 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1287 if(argc==1) return 1;
1288 Standard_Integer On = Draw::Atoi(argv[1]);
1289 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1293 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1294 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1295 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1299 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1303 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1307 Ctx->UpdateCurrentViewer();
1310 Handle(AIS_InteractiveObject) IO;
1311 TCollection_AsciiString name = argv[2];
1312 if (GetMapOfAIS().Find2 (name, IO)
1316 Ctx->SubIntensityOn(IO, Standard_True);
1318 Ctx->SubIntensityOff(IO, Standard_True);
1325 //! Auxiliary class to iterate presentations from different collections.
1326 class ViewTest_PrsIter
1330 //! Create and initialize iterator object.
1331 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1332 : mySource (IterSource_All)
1334 NCollection_Sequence<TCollection_AsciiString> aNames;
1335 if (!theName.IsEmpty())
1336 aNames.Append (theName);
1340 //! Create and initialize iterator object.
1341 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1342 : mySource (IterSource_All)
1347 //! Initialize the iterator.
1348 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1350 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1352 mySelIter.Nullify();
1353 myCurrent.Nullify();
1354 myCurrentTrs.Nullify();
1355 if (!mySeq.IsEmpty())
1357 mySource = IterSource_List;
1358 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1360 else if (aCtx->NbSelected() > 0)
1362 mySource = IterSource_Selected;
1364 mySelIter->InitSelected();
1368 mySource = IterSource_All;
1369 myMapIter.Initialize (GetMapOfAIS());
1374 const TCollection_AsciiString& CurrentName() const
1376 return myCurrentName;
1379 const Handle(AIS_InteractiveObject)& Current() const
1384 const Handle(Standard_Transient)& CurrentTrs() const
1386 return myCurrentTrs;
1389 //! @return true if iterator points to valid object within collection
1390 Standard_Boolean More() const
1394 case IterSource_All: return myMapIter.More();
1395 case IterSource_List: return mySeqIter.More();
1396 case IterSource_Selected: return mySelIter->MoreSelected();
1398 return Standard_False;
1401 //! Go to the next item.
1404 myCurrentName.Clear();
1405 myCurrentTrs.Nullify();
1406 myCurrent.Nullify();
1409 case IterSource_All:
1414 case IterSource_List:
1419 case IterSource_Selected:
1421 mySelIter->NextSelected();
1434 case IterSource_All:
1436 if (myMapIter.More())
1438 myCurrentName = myMapIter.Key2();
1439 myCurrentTrs = myMapIter.Key1();
1440 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1444 case IterSource_List:
1446 if (mySeqIter.More())
1448 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1450 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1453 myCurrentName = mySeqIter.Value();
1454 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1455 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1459 case IterSource_Selected:
1461 if (mySelIter->MoreSelected())
1463 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1464 myCurrent = mySelIter->SelectedInteractive();
1482 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1483 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1484 NCollection_Sequence<TCollection_AsciiString> mySeq;
1485 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1487 TCollection_AsciiString myCurrentName;//!< current item name
1488 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1489 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1491 IterSource mySource; //!< iterated collection
1495 //==============================================================================
1496 //function : VInteriorStyle
1497 //purpose : sets interior style of the a selected or named or displayed shape
1498 //==============================================================================
1499 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1500 Standard_Integer theArgNb,
1501 const char** theArgVec)
1503 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1504 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1507 std::cerr << "Error: no active view!\n";
1511 Standard_Integer anArgIter = 1;
1512 for (; anArgIter < theArgNb; ++anArgIter)
1514 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1519 TCollection_AsciiString aName;
1520 if (theArgNb - anArgIter == 2)
1522 aName = theArgVec[anArgIter++];
1524 else if (theArgNb - anArgIter != 1)
1526 std::cout << "Error: wrong number of arguments! See usage:\n";
1527 theDI.PrintHelp (theArgVec[0]);
1530 Aspect_InteriorStyle anInterStyle = Aspect_IS_SOLID;
1531 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1532 aStyleArg.LowerCase();
1533 if (aStyleArg == "empty")
1535 anInterStyle = Aspect_IS_EMPTY;
1537 else if (aStyleArg == "hollow")
1539 anInterStyle = Aspect_IS_HOLLOW;
1541 else if (aStyleArg == "hatch")
1543 anInterStyle = Aspect_IS_HATCH;
1545 else if (aStyleArg == "solid")
1547 anInterStyle = Aspect_IS_SOLID;
1549 else if (aStyleArg == "hiddenline")
1551 anInterStyle = Aspect_IS_HIDDENLINE;
1553 else if (aStyleArg == "point")
1555 anInterStyle = Aspect_IS_POINT;
1559 const Standard_Integer anIntStyle = aStyleArg.IntegerValue();
1560 if (anIntStyle < Aspect_IS_EMPTY
1561 || anIntStyle > Aspect_IS_POINT)
1563 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1564 << Aspect_IS_POINT << " (Aspect_IS_POINT)]\n";
1567 anInterStyle = (Aspect_InteriorStyle )anIntStyle;
1570 if (!aName.IsEmpty()
1571 && !GetMapOfAIS().IsBound2 (aName))
1573 std::cout << "Error: object " << aName << " is not displayed!\n";
1577 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1579 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1582 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1583 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1584 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1585 aFillAspect->SetInteriorStyle (anInterStyle);
1586 if (anInterStyle == Aspect_IS_HATCH
1587 && aFillAspect->HatchStyle().IsNull())
1589 aFillAspect->SetHatchStyle (Aspect_HS_VERTICAL);
1591 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1597 //! Auxiliary structure for VAspects
1598 struct ViewerTest_AspectsChangeSet
1600 Standard_Integer ToSetVisibility;
1601 Standard_Integer Visibility;
1603 Standard_Integer ToSetColor;
1604 Quantity_Color Color;
1606 Standard_Integer ToSetLineWidth;
1607 Standard_Real LineWidth;
1609 Standard_Integer ToSetTypeOfLine;
1610 Aspect_TypeOfLine TypeOfLine;
1612 Standard_Integer ToSetTypeOfMarker;
1613 Aspect_TypeOfMarker TypeOfMarker;
1614 Handle(Image_PixMap) MarkerImage;
1616 Standard_Integer ToSetMarkerSize;
1617 Standard_Real MarkerSize;
1619 Standard_Integer ToSetTransparency;
1620 Standard_Real Transparency;
1622 Standard_Integer ToSetAlphaMode;
1623 Graphic3d_AlphaMode AlphaMode;
1624 Standard_ShortReal AlphaCutoff;
1626 Standard_Integer ToSetMaterial;
1627 Graphic3d_NameOfMaterial Material;
1628 TCollection_AsciiString MatName;
1630 NCollection_Sequence<TopoDS_Shape> SubShapes;
1632 Standard_Integer ToSetShowFreeBoundary;
1633 Standard_Integer ToSetFreeBoundaryWidth;
1634 Standard_Real FreeBoundaryWidth;
1635 Standard_Integer ToSetFreeBoundaryColor;
1636 Quantity_Color FreeBoundaryColor;
1638 Standard_Integer ToEnableIsoOnTriangulation;
1640 Standard_Integer ToSetMaxParamValue;
1641 Standard_Real MaxParamValue;
1643 Standard_Integer ToSetSensitivity;
1644 Standard_Integer SelectionMode;
1645 Standard_Integer Sensitivity;
1647 Standard_Integer ToSetHatch;
1648 Standard_Integer StdHatchStyle;
1649 TCollection_AsciiString PathToHatchPattern;
1651 Standard_Integer ToSetShadingModel;
1652 Graphic3d_TypeOfShadingModel ShadingModel;
1653 TCollection_AsciiString ShadingModelName;
1655 //! Empty constructor
1656 ViewerTest_AspectsChangeSet()
1657 : ToSetVisibility (0),
1660 Color (DEFAULT_COLOR),
1663 ToSetTypeOfLine (0),
1664 TypeOfLine (Aspect_TOL_SOLID),
1665 ToSetTypeOfMarker (0),
1666 TypeOfMarker (Aspect_TOM_PLUS),
1667 ToSetMarkerSize (0),
1669 ToSetTransparency (0),
1672 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1675 Material (Graphic3d_NOM_DEFAULT),
1676 ToSetShowFreeBoundary (0),
1677 ToSetFreeBoundaryWidth (0),
1678 FreeBoundaryWidth (1.0),
1679 ToSetFreeBoundaryColor (0),
1680 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1681 ToEnableIsoOnTriangulation (-1),
1682 ToSetMaxParamValue (0),
1683 MaxParamValue (500000),
1684 ToSetSensitivity (0),
1689 ToSetShadingModel (0),
1690 ShadingModel (Graphic3d_TOSM_DEFAULT)
1693 //! @return true if no changes have been requested
1694 Standard_Boolean IsEmpty() const
1696 return ToSetVisibility == 0
1697 && ToSetLineWidth == 0
1698 && ToSetTransparency == 0
1699 && ToSetAlphaMode == 0
1701 && ToSetMaterial == 0
1702 && ToSetShowFreeBoundary == 0
1703 && ToSetFreeBoundaryColor == 0
1704 && ToSetFreeBoundaryWidth == 0
1705 && ToSetMaxParamValue == 0
1706 && ToSetSensitivity == 0
1708 && ToSetShadingModel == 0;
1711 //! @return true if properties are valid
1712 Standard_Boolean Validate() const
1714 Standard_Boolean isOk = Standard_True;
1715 if (Visibility != 0 && Visibility != 1)
1717 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1718 isOk = Standard_False;
1720 if (LineWidth <= 0.0
1721 || LineWidth > 10.0)
1723 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1724 isOk = Standard_False;
1726 if (Transparency < 0.0
1727 || Transparency > 1.0)
1729 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1730 isOk = Standard_False;
1732 if (ToSetAlphaMode == 1
1733 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1735 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1736 isOk = Standard_False;
1738 if (ToSetMaterial == 1
1739 && Material == Graphic3d_NOM_DEFAULT)
1741 std::cout << "Error: unknown material " << MatName << ".\n";
1742 isOk = Standard_False;
1744 if (FreeBoundaryWidth <= 0.0
1745 || FreeBoundaryWidth > 10.0)
1747 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1748 isOk = Standard_False;
1750 if (MaxParamValue < 0.0)
1752 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1753 isOk = Standard_False;
1755 if (Sensitivity <= 0 && ToSetSensitivity)
1757 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1758 isOk = Standard_False;
1760 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1762 std::cout << "Error: hatch style must be specified\n";
1763 isOk = Standard_False;
1765 if (ToSetShadingModel == 1
1766 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
1768 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1769 isOk = Standard_False;
1776 //==============================================================================
1777 //function : VAspects
1779 //==============================================================================
1780 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1781 Standard_Integer theArgNb,
1782 const char** theArgVec)
1784 TCollection_AsciiString aCmdName (theArgVec[0]);
1785 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1786 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1789 std::cerr << "Error: no active view!\n";
1793 Standard_Integer anArgIter = 1;
1794 Standard_Boolean isDefaults = Standard_False;
1795 NCollection_Sequence<TCollection_AsciiString> aNames;
1796 for (; anArgIter < theArgNb; ++anArgIter)
1798 TCollection_AsciiString anArg = theArgVec[anArgIter];
1799 if (anUpdateTool.parseRedrawMode (anArg))
1803 else if (!anArg.IsEmpty()
1804 && anArg.Value (1) != '-')
1806 aNames.Append (anArg);
1810 if (anArg == "-defaults")
1812 isDefaults = Standard_True;
1819 if (!aNames.IsEmpty() && isDefaults)
1821 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1825 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1826 aChanges.Append (ViewerTest_AspectsChangeSet());
1827 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1829 // parse syntax of legacy commands
1830 if (aCmdName == "vsetwidth")
1832 if (aNames.IsEmpty()
1833 || !aNames.Last().IsRealValue())
1835 std::cout << "Error: not enough arguments!\n";
1838 aChangeSet->ToSetLineWidth = 1;
1839 aChangeSet->LineWidth = aNames.Last().RealValue();
1840 aNames.Remove (aNames.Length());
1842 else if (aCmdName == "vunsetwidth")
1844 aChangeSet->ToSetLineWidth = -1;
1846 else if (aCmdName == "vsetcolor")
1848 if (aNames.IsEmpty())
1850 std::cout << "Error: not enough arguments!\n";
1853 aChangeSet->ToSetColor = 1;
1855 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1856 Standard_Boolean isOk = Standard_False;
1857 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1859 aChangeSet->Color = aColor;
1860 aNames.Remove (aNames.Length());
1861 isOk = Standard_True;
1863 else if (aNames.Length() >= 3)
1865 const TCollection_AsciiString anRgbStr[3] =
1867 aNames.Value (aNames.Upper() - 2),
1868 aNames.Value (aNames.Upper() - 1),
1869 aNames.Value (aNames.Upper() - 0)
1871 isOk = anRgbStr[0].IsRealValue()
1872 && anRgbStr[1].IsRealValue()
1873 && anRgbStr[2].IsRealValue();
1876 Graphic3d_Vec4d anRgb;
1877 anRgb.x() = anRgbStr[0].RealValue();
1878 anRgb.y() = anRgbStr[1].RealValue();
1879 anRgb.z() = anRgbStr[2].RealValue();
1880 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1881 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1882 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1884 std::cout << "Error: RGB color values should be within range 0..1!\n";
1887 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1888 aNames.Remove (aNames.Length());
1889 aNames.Remove (aNames.Length());
1890 aNames.Remove (aNames.Length());
1895 std::cout << "Error: not enough arguments!\n";
1899 else if (aCmdName == "vunsetcolor")
1901 aChangeSet->ToSetColor = -1;
1903 else if (aCmdName == "vsettransparency")
1905 if (aNames.IsEmpty()
1906 || !aNames.Last().IsRealValue())
1908 std::cout << "Error: not enough arguments!\n";
1911 aChangeSet->ToSetTransparency = 1;
1912 aChangeSet->Transparency = aNames.Last().RealValue();
1913 aNames.Remove (aNames.Length());
1915 else if (aCmdName == "vunsettransparency")
1917 aChangeSet->ToSetTransparency = -1;
1919 else if (aCmdName == "vsetmaterial")
1921 if (aNames.IsEmpty())
1923 std::cout << "Error: not enough arguments!\n";
1926 aChangeSet->ToSetMaterial = 1;
1927 aChangeSet->MatName = aNames.Last();
1928 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1929 aNames.Remove (aNames.Length());
1931 else if (aCmdName == "vunsetmaterial")
1933 aChangeSet->ToSetMaterial = -1;
1935 else if (anArgIter >= theArgNb)
1937 std::cout << "Error: not enough arguments!\n";
1941 if (!aChangeSet->IsEmpty())
1943 anArgIter = theArgNb;
1945 for (; anArgIter < theArgNb; ++anArgIter)
1947 TCollection_AsciiString anArg = theArgVec[anArgIter];
1949 if (anArg == "-setwidth"
1950 || anArg == "-setlinewidth")
1952 if (++anArgIter >= theArgNb)
1954 std::cout << "Error: wrong syntax at " << anArg << "\n";
1957 aChangeSet->ToSetLineWidth = 1;
1958 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1960 else if (anArg == "-unsetwidth"
1961 || anArg == "-unsetlinewidth")
1963 aChangeSet->ToSetLineWidth = -1;
1964 aChangeSet->LineWidth = 1.0;
1966 else if (anArg == "-settransp"
1967 || anArg == "-settransparency")
1969 if (++anArgIter >= theArgNb)
1971 std::cout << "Error: wrong syntax at " << anArg << "\n";
1974 aChangeSet->ToSetTransparency = 1;
1975 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1976 if (aChangeSet->Transparency >= 0.0
1977 && aChangeSet->Transparency <= Precision::Confusion())
1979 aChangeSet->ToSetTransparency = -1;
1980 aChangeSet->Transparency = 0.0;
1983 else if (anArg == "-setalphamode")
1985 if (++anArgIter >= theArgNb)
1987 std::cout << "Error: wrong syntax at " << anArg << "\n";
1990 aChangeSet->ToSetAlphaMode = 1;
1991 aChangeSet->AlphaCutoff = 0.5f;
1993 TCollection_AsciiString aParam (theArgVec[anArgIter]);
1995 if (aParam == "opaque")
1997 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
1999 else if (aParam == "mask")
2001 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2003 else if (aParam == "blend")
2005 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2007 else if (aParam == "blendauto"
2008 || aParam == "auto")
2010 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2014 std::cout << "Error: wrong syntax at " << aParam << "\n";
2019 if (anArgIter + 1 < theArgNb
2020 && theArgVec[anArgIter + 1][0] != '-')
2022 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2023 if (aParam2.IsRealValue())
2025 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2030 else if (anArg == "-setvis"
2031 || anArg == "-setvisibility")
2033 if (++anArgIter >= theArgNb)
2035 std::cout << "Error: wrong syntax at " << anArg << "\n";
2039 aChangeSet->ToSetVisibility = 1;
2040 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2042 else if (anArg == "-setalpha")
2044 if (++anArgIter >= theArgNb)
2046 std::cout << "Error: wrong syntax at " << anArg << "\n";
2049 aChangeSet->ToSetTransparency = 1;
2050 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2051 if (aChangeSet->Transparency < 0.0
2052 || aChangeSet->Transparency > 1.0)
2054 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2057 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2058 if (aChangeSet->Transparency >= 0.0
2059 && aChangeSet->Transparency <= Precision::Confusion())
2061 aChangeSet->ToSetTransparency = -1;
2062 aChangeSet->Transparency = 0.0;
2065 else if (anArg == "-unsettransp"
2066 || anArg == "-unsettransparency"
2067 || anArg == "-unsetalpha"
2068 || anArg == "-opaque")
2070 aChangeSet->ToSetTransparency = -1;
2071 aChangeSet->Transparency = 0.0;
2073 else if (anArg == "-setcolor")
2075 Standard_Integer aNbComps = 0;
2076 Standard_Integer aCompIter = anArgIter + 1;
2077 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2079 if (theArgVec[aCompIter][0] == '-')
2088 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2089 Standard_CString aName = theArgVec[anArgIter + 1];
2090 if (!Quantity_Color::ColorFromName (aName, aColor))
2092 std::cout << "Error: unknown color name '" << aName << "'\n";
2095 aChangeSet->Color = aColor;
2100 Graphic3d_Vec3d anRgb;
2101 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2102 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2103 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2104 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2105 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2106 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2108 std::cout << "Error: RGB color values should be within range 0..1!\n";
2111 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2116 std::cout << "Error: wrong syntax at " << anArg << "\n";
2120 aChangeSet->ToSetColor = 1;
2121 anArgIter += aNbComps;
2123 else if (anArg == "-setlinetype")
2125 if (++anArgIter >= theArgNb)
2127 std::cout << "Error: wrong syntax at " << anArg << "\n";
2130 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aChangeSet->TypeOfLine))
2132 std::cout << "Error: wrong syntax at " << anArg << "\n";
2136 aChangeSet->ToSetTypeOfLine = 1;
2138 else if (anArg == "-unsetlinetype")
2140 aChangeSet->ToSetTypeOfLine = -1;
2142 else if (anArg == "-setmarkertype"
2143 || anArg == "-setpointtype")
2145 if (++anArgIter >= theArgNb)
2147 std::cout << "Error: wrong syntax at " << anArg << "\n";
2150 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2152 std::cout << "Error: wrong syntax at " << anArg << "\n";
2156 aChangeSet->ToSetTypeOfMarker = 1;
2158 else if (anArg == "-unsetmarkertype"
2159 || anArg == "-unsetpointtype")
2161 aChangeSet->ToSetTypeOfMarker = -1;
2163 else if (anArg == "-setmarkersize"
2164 || anArg == "-setpointsize")
2166 if (++anArgIter >= theArgNb)
2168 std::cout << "Error: wrong syntax at " << anArg << "\n";
2171 aChangeSet->ToSetMarkerSize = 1;
2172 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2174 else if (anArg == "-unsetmarkersize"
2175 || anArg == "-unsetpointsize")
2177 aChangeSet->ToSetMarkerSize = -1;
2178 aChangeSet->MarkerSize = 1.0;
2180 else if (anArg == "-unsetcolor")
2182 aChangeSet->ToSetColor = -1;
2183 aChangeSet->Color = DEFAULT_COLOR;
2185 else if (anArg == "-setmat"
2186 || anArg == "-setmaterial")
2188 if (++anArgIter >= theArgNb)
2190 std::cout << "Error: wrong syntax at " << anArg << "\n";
2193 aChangeSet->ToSetMaterial = 1;
2194 aChangeSet->MatName = theArgVec[anArgIter];
2195 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2197 else if (anArg == "-unsetmat"
2198 || anArg == "-unsetmaterial")
2200 aChangeSet->ToSetMaterial = -1;
2201 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2203 else if (anArg == "-subshape"
2204 || anArg == "-subshapes")
2208 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2212 if (aNames.IsEmpty())
2214 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2218 aChanges.Append (ViewerTest_AspectsChangeSet());
2219 aChangeSet = &aChanges.ChangeLast();
2221 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2223 Standard_CString aSubShapeName = theArgVec[anArgIter];
2224 if (*aSubShapeName == '-')
2230 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2231 if (aSubShape.IsNull())
2233 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2236 aChangeSet->SubShapes.Append (aSubShape);
2239 if (aChangeSet->SubShapes.IsEmpty())
2241 std::cerr << "Error: empty list is specified after -subshapes!\n";
2245 else if (anArg == "-freeboundary"
2248 if (++anArgIter >= theArgNb)
2250 std::cout << "Error: wrong syntax at " << anArg << "\n";
2253 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2258 aChangeSet->ToSetShowFreeBoundary = 1;
2260 else if (aValue == "off"
2263 aChangeSet->ToSetShowFreeBoundary = -1;
2267 std::cout << "Error: wrong syntax at " << anArg << "\n";
2271 else if (anArg == "-setfreeboundarywidth"
2272 || anArg == "-setfbwidth")
2274 if (++anArgIter >= theArgNb)
2276 std::cout << "Error: wrong syntax at " << anArg << "\n";
2279 aChangeSet->ToSetFreeBoundaryWidth = 1;
2280 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2282 else if (anArg == "-unsetfreeboundarywidth"
2283 || anArg == "-unsetfbwidth")
2285 aChangeSet->ToSetFreeBoundaryWidth = -1;
2286 aChangeSet->FreeBoundaryWidth = 1.0;
2288 else if (anArg == "-setfreeboundarycolor"
2289 || anArg == "-setfbcolor")
2291 Standard_Integer aNbComps = 0;
2292 Standard_Integer aCompIter = anArgIter + 1;
2293 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2295 if (theArgVec[aCompIter][0] == '-')
2304 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2305 Standard_CString aName = theArgVec[anArgIter + 1];
2306 if (!Quantity_Color::ColorFromName (aName, aColor))
2308 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2311 aChangeSet->FreeBoundaryColor = aColor;
2316 Graphic3d_Vec3d anRgb;
2317 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2318 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2319 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2320 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2321 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2322 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2324 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2327 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2332 std::cout << "Error: wrong syntax at " << anArg << "\n";
2336 aChangeSet->ToSetFreeBoundaryColor = 1;
2337 anArgIter += aNbComps;
2339 else if (anArg == "-unsetfreeboundarycolor"
2340 || anArg == "-unsetfbcolor")
2342 aChangeSet->ToSetFreeBoundaryColor = -1;
2343 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2345 else if (anArg == "-unset")
2347 aChangeSet->ToSetVisibility = 1;
2348 aChangeSet->Visibility = 1;
2349 aChangeSet->ToSetLineWidth = -1;
2350 aChangeSet->LineWidth = 1.0;
2351 aChangeSet->ToSetTypeOfLine = -1;
2352 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2353 aChangeSet->ToSetTypeOfMarker = -1;
2354 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
2355 aChangeSet->ToSetMarkerSize = -1;
2356 aChangeSet->MarkerSize = 1.0;
2357 aChangeSet->ToSetTransparency = -1;
2358 aChangeSet->Transparency = 0.0;
2359 aChangeSet->ToSetAlphaMode = -1;
2360 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2361 aChangeSet->AlphaCutoff = 0.5f;
2362 aChangeSet->ToSetColor = -1;
2363 aChangeSet->Color = DEFAULT_COLOR;
2364 aChangeSet->ToSetMaterial = -1;
2365 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2366 aChangeSet->ToSetShowFreeBoundary = -1;
2367 aChangeSet->ToSetFreeBoundaryColor = -1;
2368 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2369 aChangeSet->ToSetFreeBoundaryWidth = -1;
2370 aChangeSet->FreeBoundaryWidth = 1.0;
2371 aChangeSet->ToSetHatch = -1;
2372 aChangeSet->StdHatchStyle = -1;
2373 aChangeSet->PathToHatchPattern.Clear();
2374 aChangeSet->ToSetShadingModel = -1;
2375 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2377 else if (anArg == "-isoontriangulation"
2378 || anArg == "-isoontriang")
2380 if (++anArgIter >= theArgNb)
2382 std::cout << "Error: wrong syntax at " << anArg << "\n";
2385 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2390 aChangeSet->ToEnableIsoOnTriangulation = 1;
2392 else if (aValue == "off"
2395 aChangeSet->ToEnableIsoOnTriangulation = 0;
2399 std::cout << "Error: wrong syntax at " << anArg << "\n";
2403 else if (anArg == "-setmaxparamvalue")
2405 if (++anArgIter >= theArgNb)
2407 std::cout << "Error: wrong syntax at " << anArg << "\n";
2410 aChangeSet->ToSetMaxParamValue = 1;
2411 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2413 else if (anArg == "-setsensitivity")
2417 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2421 if (aNames.IsEmpty())
2423 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2427 if (anArgIter + 2 >= theArgNb)
2429 std::cout << "Error: wrong syntax at " << anArg << "\n";
2432 aChangeSet->ToSetSensitivity = 1;
2433 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2434 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2436 else if (anArg == "-sethatch")
2440 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2444 if (aNames.IsEmpty())
2446 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2450 aChangeSet->ToSetHatch = 1;
2451 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
2452 if (anArgHatch.Length() <= 2)
2454 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
2456 || anIntStyle >= Aspect_HS_NB)
2458 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
2461 aChangeSet->StdHatchStyle = anIntStyle;
2465 aChangeSet->PathToHatchPattern = anArgHatch;
2468 else if (anArg == "-setshadingmodel")
2470 if (++anArgIter >= theArgNb)
2472 std::cout << "Error: wrong syntax at " << anArg << "\n";
2475 aChangeSet->ToSetShadingModel = 1;
2476 aChangeSet->ShadingModelName = theArgVec[anArgIter];
2477 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
2479 std::cout << "Error: wrong syntax at " << anArg << "\n";
2483 else if (anArg == "-unsetshadingmodel")
2485 aChangeSet->ToSetShadingModel = -1;
2486 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2490 std::cout << "Error: wrong syntax at " << anArg << "\n";
2495 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2496 aChangesIter.More(); aChangesIter.Next())
2498 if (!aChangesIter.Value().Validate())
2504 // special case for -defaults parameter.
2505 // all changed values will be set to DefaultDrawer.
2508 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2510 if (aChangeSet->ToSetLineWidth != 0)
2512 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2513 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2514 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2515 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2517 if (aChangeSet->ToSetColor != 0)
2519 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2520 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2521 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2522 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2523 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2524 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2526 if (aChangeSet->ToSetTypeOfLine != 0)
2528 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2529 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2530 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2531 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2532 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2534 if (aChangeSet->ToSetTypeOfMarker != 0)
2536 aDrawer->PointAspect()->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2537 aDrawer->PointAspect()->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2538 ? Handle(Graphic3d_MarkerImage)()
2539 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2541 if (aChangeSet->ToSetMarkerSize != 0)
2543 aDrawer->PointAspect()->SetScale (aChangeSet->MarkerSize);
2545 if (aChangeSet->ToSetTransparency != 0)
2547 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2549 if (aChangeSet->ToSetAlphaMode != 0)
2551 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2553 if (aChangeSet->ToSetMaterial != 0)
2555 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2557 if (aChangeSet->ToSetShowFreeBoundary == 1)
2559 aDrawer->SetFreeBoundaryDraw (Standard_True);
2561 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2563 aDrawer->SetFreeBoundaryDraw (Standard_False);
2565 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2567 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2569 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2571 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2573 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2575 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2577 if (aChangeSet->ToSetMaxParamValue != 0)
2579 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2581 if (aChangeSet->ToSetShadingModel == 1)
2583 aDrawer->ShadingAspect()->Aspect()->SetShadingModel (aChangeSet->ShadingModel);
2586 // redisplay all objects in context
2587 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2589 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2592 aCtx->Redisplay (aPrs, Standard_False);
2598 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2600 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2601 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2607 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2608 Handle(AIS_ColoredShape) aColoredPrs;
2609 Standard_Boolean toDisplay = Standard_False;
2610 Standard_Boolean toRedisplay = Standard_False;
2611 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2613 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2614 if (aShapePrs.IsNull())
2616 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2619 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2620 if (aColoredPrs.IsNull())
2622 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2623 if (aShapePrs->HasDisplayMode())
2625 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2627 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2628 aCtx->Remove (aShapePrs, Standard_False);
2629 GetMapOfAIS().UnBind2 (aName);
2630 GetMapOfAIS().Bind (aColoredPrs, aName);
2631 toDisplay = Standard_True;
2632 aShapePrs = aColoredPrs;
2639 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2640 aChangeSet = &aChangesIter.ChangeValue();
2641 if (aChangeSet->ToSetVisibility == 1)
2643 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2644 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2646 else if (aChangeSet->ToSetMaterial == 1)
2648 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2650 else if (aChangeSet->ToSetMaterial == -1)
2652 aCtx->UnsetMaterial (aPrs, Standard_False);
2654 if (aChangeSet->ToSetColor == 1)
2656 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2658 else if (aChangeSet->ToSetColor == -1)
2660 aCtx->UnsetColor (aPrs, Standard_False);
2662 if (aChangeSet->ToSetTransparency == 1)
2664 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2666 else if (aChangeSet->ToSetTransparency == -1)
2668 aCtx->UnsetTransparency (aPrs, Standard_False);
2670 if (aChangeSet->ToSetLineWidth == 1)
2672 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2674 else if (aChangeSet->ToSetLineWidth == -1)
2676 aCtx->UnsetWidth (aPrs, Standard_False);
2678 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2680 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2681 toRedisplay = Standard_True;
2683 else if (aChangeSet->ToSetSensitivity != 0)
2685 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2687 if (!aDrawer.IsNull())
2689 if (aChangeSet->ToSetShowFreeBoundary == 1)
2691 aDrawer->SetFreeBoundaryDraw (Standard_True);
2692 toRedisplay = Standard_True;
2694 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2696 aDrawer->SetFreeBoundaryDraw (Standard_False);
2697 toRedisplay = Standard_True;
2699 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2701 Handle(Prs3d_LineAspect) aBoundaryAspect =
2702 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2703 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2704 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2705 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2706 toRedisplay = Standard_True;
2708 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2710 Handle(Prs3d_LineAspect) aBoundaryAspect =
2711 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2712 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2713 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2714 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2715 toRedisplay = Standard_True;
2717 if (aChangeSet->ToSetTypeOfLine != 0)
2719 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2720 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2721 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2722 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2723 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2724 toRedisplay = Standard_True;
2726 if (aChangeSet->ToSetTypeOfMarker != 0)
2728 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2729 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2730 aMarkerAspect->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2731 aMarkerAspect->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2732 ? Handle(Graphic3d_MarkerImage)()
2733 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2734 aDrawer->SetPointAspect (aMarkerAspect);
2735 toRedisplay = Standard_True;
2737 if (aChangeSet->ToSetMarkerSize != 0)
2739 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2740 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2741 aMarkerAspect->SetScale (aChangeSet->MarkerSize);
2742 aDrawer->SetPointAspect (aMarkerAspect);
2743 toRedisplay = Standard_True;
2745 if (aChangeSet->ToSetMaxParamValue != 0)
2747 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2749 if (aChangeSet->ToSetHatch != 0)
2751 if (!aDrawer->HasOwnShadingAspect())
2753 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2754 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2757 Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
2758 if (aChangeSet->ToSetHatch == -1)
2760 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2764 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2765 if (!aChangeSet->PathToHatchPattern.IsEmpty())
2767 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2768 if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
2770 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2774 std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
2778 else if (aChangeSet->StdHatchStyle != -1)
2780 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
2783 toRedisplay = Standard_True;
2785 if (aChangeSet->ToSetShadingModel != 0)
2787 aDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2788 toRedisplay = Standard_True;
2790 if (aChangeSet->ToSetAlphaMode != 0)
2792 if (!aDrawer->HasOwnShadingAspect())
2794 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2795 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2797 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2798 toRedisplay = Standard_True;
2802 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2804 aChangeSet = &aChangesIter.ChangeValue();
2805 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2806 aSubShapeIter.More(); aSubShapeIter.Next())
2808 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2809 if (aChangeSet->ToSetVisibility == 1)
2811 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2812 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2814 if (aChangeSet->ToSetColor == 1)
2816 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2818 if (aChangeSet->ToSetTransparency == 1)
2820 aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency);
2822 if (aChangeSet->ToSetLineWidth == 1)
2824 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2826 if (aChangeSet->ToSetColor == -1
2827 || aChangeSet->ToSetLineWidth == -1)
2829 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2831 if (aChangeSet->ToSetMaxParamValue != 0)
2833 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2834 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2836 if (aChangeSet->ToSetSensitivity != 0)
2838 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2840 if (aChangeSet->ToSetShadingModel != 0)
2842 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2843 aCurColDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2849 aCtx->Display (aPrs, Standard_False);
2853 aCtx->Redisplay (aPrs, Standard_False);
2855 else if (!aColoredPrs.IsNull())
2857 aCtx->Redisplay (aColoredPrs, Standard_False);
2864 //==============================================================================
2865 //function : VDonly2
2867 //purpose : Display only a selected or named object
2868 // if there is no selected or named object s, nothing is done
2869 //==============================================================================
2870 static int VDonly2 (Draw_Interpretor& ,
2871 Standard_Integer theArgNb,
2872 const char** theArgVec)
2874 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2875 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2878 std::cerr << "Error: no active view!\n";
2882 Standard_Integer anArgIter = 1;
2883 for (; anArgIter < theArgNb; ++anArgIter)
2885 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2891 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2892 if (anArgIter >= theArgNb)
2894 // display only selected objects
2895 if (aCtx->NbSelected() < 1)
2900 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2902 aDispSet.Add (aCtx->SelectedInteractive());
2907 // display only specified objects
2908 for (; anArgIter < theArgNb; ++anArgIter)
2910 TCollection_AsciiString aName = theArgVec[anArgIter];
2911 Handle(AIS_InteractiveObject) aShape;
2912 if (GetMapOfAIS().Find2 (aName, aShape)
2913 && !aShape.IsNull())
2915 aCtx->Display (aShape, Standard_False);
2916 aDispSet.Add (aShape);
2921 // weed out other objects
2922 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2924 if (aDispSet.Contains (anIter.Key1()))
2929 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
2931 aCtx->Erase (aShape, Standard_False);
2937 //==============================================================================
2938 //function : VRemove
2939 //purpose : Removes selected or named objects.
2940 // If there is no selected or named objects,
2941 // all objects in the viewer can be removed with argument -all.
2942 // If -context is in arguments, the object is not deleted from the map of
2943 // objects (deleted only from the current context).
2944 //==============================================================================
2945 int VRemove (Draw_Interpretor& theDI,
2946 Standard_Integer theArgNb,
2947 const char** theArgVec)
2949 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2950 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2953 std::cerr << "Error: no active view!\n";
2957 Standard_Boolean isContextOnly = Standard_False;
2958 Standard_Boolean toRemoveAll = Standard_False;
2959 Standard_Boolean toPrintInfo = Standard_True;
2961 Standard_Integer anArgIter = 1;
2962 for (; anArgIter < theArgNb; ++anArgIter)
2964 TCollection_AsciiString anArg = theArgVec[anArgIter];
2966 if (anArg == "-context")
2968 isContextOnly = Standard_True;
2970 else if (anArg == "-all")
2972 toRemoveAll = Standard_True;
2974 else if (anArg == "-noinfo")
2976 toPrintInfo = Standard_False;
2978 else if (anUpdateTool.parseRedrawMode (anArg))
2988 && anArgIter < theArgNb)
2990 std::cerr << "Error: wrong syntax!\n";
2994 NCollection_List<TCollection_AsciiString> anIONameList;
2997 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2998 anIter.More(); anIter.Next())
3000 anIONameList.Append (anIter.Key2());
3003 else if (anArgIter < theArgNb) // removed objects names are in argument list
3005 for (; anArgIter < theArgNb; ++anArgIter)
3007 TCollection_AsciiString aName = theArgVec[anArgIter];
3008 Handle(AIS_InteractiveObject) anIO;
3009 if (!GetMapOfAIS().Find2 (aName, anIO))
3011 theDI << aName << " was not bound to some object.\n";
3015 if (anIO->GetContext() != aCtx)
3017 theDI << aName << " was not displayed in current context.\n";
3018 theDI << "Please activate view with this object displayed and try again.\n";
3022 anIONameList.Append (aName);
3026 else if (aCtx->NbSelected() > 0)
3028 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3029 anIter.More(); anIter.Next())
3031 if (!aCtx->IsSelected (anIter.Key1()))
3036 anIONameList.Append (anIter.Key2());
3041 // Unbind all removed objects from the map of displayed IO.
3042 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3043 anIter.More(); anIter.Next())
3045 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
3046 aCtx->Remove (anIO, Standard_False);
3049 theDI << anIter.Value() << " was removed\n";
3053 GetMapOfAIS().UnBind2 (anIter.Value());
3059 //==============================================================================
3061 //purpose : Erase some selected or named objects
3062 // if there is no selected or named objects, the whole viewer is erased
3063 //==============================================================================
3064 int VErase (Draw_Interpretor& theDI,
3065 Standard_Integer theArgNb,
3066 const char** theArgVec)
3068 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3069 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3070 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3073 std::cerr << "Error: no active view!\n";
3077 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3079 Standard_Integer anArgIter = 1;
3080 Standard_Boolean toEraseInView = Standard_False;
3081 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3082 for (; anArgIter < theArgNb; ++anArgIter)
3084 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3085 anArgCase.LowerCase();
3086 if (anUpdateTool.parseRedrawMode (anArgCase))
3090 else if (anArgCase == "-view"
3091 || anArgCase == "-inview")
3093 toEraseInView = Standard_True;
3097 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3101 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3103 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3107 if (!aNamesOfEraseIO.IsEmpty())
3109 // Erase named objects
3110 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
3112 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
3113 Handle(AIS_InteractiveObject) anIO;
3114 if (!GetMapOfAIS().Find2 (aName, anIO))
3119 theDI << aName << " ";
3124 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3128 aCtx->Erase (anIO, Standard_False);
3133 else if (!toEraseAll && aCtx->NbSelected() > 0)
3135 // Erase selected objects
3136 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3137 anIter.More(); anIter.Next())
3139 const Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3141 && aCtx->IsSelected (anIO))
3143 theDI << anIter.Key2() << " ";
3146 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3153 aCtx->EraseSelected (Standard_False);
3158 // Erase all objects
3159 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3160 anIter.More(); anIter.Next())
3162 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3167 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3171 aCtx->Erase (anIO, Standard_False);
3180 //==============================================================================
3181 //function : VDisplayAll
3182 //purpose : Display all the objects of the Map
3183 //==============================================================================
3184 static int VDisplayAll (Draw_Interpretor& ,
3185 Standard_Integer theArgNb,
3186 const char** theArgVec)
3189 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3190 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3193 std::cerr << "Error: no active view!\n";
3197 Standard_Integer anArgIter = 1;
3198 for (; anArgIter < theArgNb; ++anArgIter)
3200 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3201 anArgCase.LowerCase();
3202 if (anUpdateTool.parseRedrawMode (anArgCase))
3211 if (anArgIter < theArgNb)
3213 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3217 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3218 anIter.More(); anIter.Next())
3220 aCtx->Erase (anIter.Key1(), Standard_False);
3223 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3224 anIter.More(); anIter.Next())
3226 aCtx->Display (anIter.Key1(), Standard_False);
3231 //! Auxiliary method to check if presentation exists
3232 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3233 const Handle(AIS_InteractiveObject)& theIO,
3234 const Standard_Integer theMode)
3236 if (theIO.IsNull() || theCtx.IsNull())
3243 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3248 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3250 return theIO->DisplayMode();
3252 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3254 return theCtx->DisplayMode();
3260 enum ViewerTest_BndAction
3267 //! Auxiliary method to print bounding box of presentation
3268 inline void bndPresentation (Draw_Interpretor& theDI,
3269 const Handle(PrsMgr_PresentationManager)& theMgr,
3270 const Handle(AIS_InteractiveObject)& theObj,
3271 const Standard_Integer theDispMode,
3272 const TCollection_AsciiString& theName,
3273 const ViewerTest_BndAction theAction,
3274 const Handle(Prs3d_Drawer)& theStyle)
3278 case BndAction_Hide:
3280 theMgr->Unhighlight (theObj);
3283 case BndAction_Show:
3285 theMgr->Color (theObj, theStyle, theDispMode);
3288 case BndAction_Print:
3291 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3293 if (aPrsIter.Value().Mode() != theDispMode)
3296 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3298 gp_Pnt aMin = aBox.CornerMin();
3299 gp_Pnt aMax = aBox.CornerMax();
3300 theDI << theName << "\n"
3301 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3302 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
3308 //==============================================================================
3309 //function : VBounding
3311 //==============================================================================
3312 int VBounding (Draw_Interpretor& theDI,
3313 Standard_Integer theArgNb,
3314 const char** theArgVec)
3316 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3317 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3320 std::cout << "Error: no active view!\n";
3324 ViewerTest_BndAction anAction = BndAction_Show;
3325 Standard_Integer aMode = -1;
3327 Handle(Prs3d_Drawer) aStyle;
3329 Standard_Integer anArgIter = 1;
3330 for (; anArgIter < theArgNb; ++anArgIter)
3332 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3334 if (anArg == "-print")
3336 anAction = BndAction_Print;
3338 else if (anArg == "-show")
3340 anAction = BndAction_Show;
3342 else if (anArg == "-hide")
3344 anAction = BndAction_Hide;
3346 else if (anArg == "-mode")
3348 if (++anArgIter >= theArgNb)
3350 std::cout << "Error: wrong syntax at " << anArg << "\n";
3353 aMode = Draw::Atoi (theArgVec[anArgIter]);
3355 else if (!anUpdateTool.parseRedrawMode (anArg))
3361 if (anAction == BndAction_Show)
3363 aStyle = new Prs3d_Drawer();
3364 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3365 aStyle->SetColor (Quantity_NOC_GRAY99);
3368 Standard_Integer aHighlightedMode = -1;
3369 if (anArgIter < theArgNb)
3371 // has a list of names
3372 for (; anArgIter < theArgNb; ++anArgIter)
3374 TCollection_AsciiString aName = theArgVec[anArgIter];
3375 Handle(AIS_InteractiveObject) anIO;
3376 if (!GetMapOfAIS().Find2 (aName, anIO))
3378 std::cout << "Error: presentation " << aName << " does not exist\n";
3382 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3383 if (aHighlightedMode == -1)
3385 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3388 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3391 else if (aCtx->NbSelected() > 0)
3393 // remove all currently selected objects
3394 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3396 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3397 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3398 if (aHighlightedMode != -1)
3400 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3401 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3408 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3409 anIter.More(); anIter.Next())
3411 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3412 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3413 if (aHighlightedMode != -1)
3415 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3422 //==============================================================================
3423 //function : VTexture
3425 //==============================================================================
3426 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
3428 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3431 std::cout << "Error: no active view!\n";
3435 int toModulate = -1;
3436 bool toSetFilter = false;
3437 bool toSetAniso = false;
3438 bool toSetTrsfAngle = false;
3439 bool toSetTrsfTrans = false;
3440 bool toSetTrsfScale = false;
3441 Standard_ShortReal aTrsfRotAngle = 0.0f;
3442 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
3443 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
3444 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
3445 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
3447 Handle(AIS_InteractiveObject) aTexturedIO;
3448 Handle(AIS_Shape) aTexturedShape;
3449 Handle(Graphic3d_TextureSet) aTextureSetOld;
3450 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
3451 bool toSetGenRepeat = false;
3452 bool toSetGenScale = false;
3453 bool toSetGenOrigin = false;
3454 bool toSetImage = false;
3455 bool toComputeUV = false;
3457 const TCollection_AsciiString aCommandName (theArgVec[0]);
3458 bool toSetDefaults = aCommandName == "vtexdefault";
3460 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3461 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
3463 const TCollection_AsciiString aName = theArgVec[anArgIter];
3464 TCollection_AsciiString aNameCase = aName;
3465 aNameCase.LowerCase();
3466 if (anUpdateTool.parseRedrawMode (aName))
3470 else if (aTexturedIO.IsNull())
3472 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3473 if (aMapOfIO.IsBound2 (aName))
3475 aTexturedIO = aMapOfIO.Find2 (aName);
3476 aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO);
3478 if (aTexturedIO.IsNull())
3480 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
3484 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
3486 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
3489 else if (!aTexturedShape.IsNull()
3490 && (aNameCase == "-scale"
3491 || aNameCase == "-setscale"
3492 || aCommandName == "vtexscale"))
3494 if (aCommandName != "vtexscale")
3498 if (anArgIter < theArgsNb)
3500 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3501 TCollection_AsciiString aValUCase = aValU;
3502 aValUCase.LowerCase();
3503 toSetGenScale = true;
3504 if (aValUCase == "off")
3506 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3509 else if (anArgIter + 1 < theArgsNb)
3511 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3512 if (aValU.IsRealValue()
3513 && aValV.IsRealValue())
3515 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3521 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3524 else if (!aTexturedShape.IsNull()
3525 && (aNameCase == "-origin"
3526 || aNameCase == "-setorigin"
3527 || aCommandName == "vtexorigin"))
3529 if (aCommandName != "vtexorigin")
3533 if (anArgIter < theArgsNb)
3535 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3536 TCollection_AsciiString aValUCase = aValU;
3537 aValUCase.LowerCase();
3538 toSetGenOrigin = true;
3539 if (aValUCase == "off")
3541 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3544 else if (anArgIter + 1 < theArgsNb)
3546 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3547 if (aValU.IsRealValue()
3548 && aValV.IsRealValue())
3550 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3556 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3559 else if (!aTexturedShape.IsNull()
3560 && (aNameCase == "-repeat"
3561 || aNameCase == "-setrepeat"
3562 || aCommandName == "vtexrepeat"))
3564 if (aCommandName != "vtexrepeat")
3568 if (anArgIter < theArgsNb)
3570 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3571 TCollection_AsciiString aValUCase = aValU;
3572 aValUCase.LowerCase();
3573 toSetGenRepeat = true;
3574 if (aValUCase == "off")
3576 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3579 else if (anArgIter + 1 < theArgsNb)
3581 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3582 if (aValU.IsRealValue()
3583 && aValV.IsRealValue())
3585 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3591 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3594 else if (aNameCase == "-modulate")
3596 bool toModulateBool = true;
3597 if (anArgIter + 1 < theArgsNb
3598 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
3602 toModulate = toModulateBool ? 1 : 0;
3604 else if ((aNameCase == "-setfilter"
3605 || aNameCase == "-filter")
3606 && anArgIter + 1 < theArgsNb)
3608 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3612 if (aValue == "nearest")
3614 aFilter = Graphic3d_TOTF_NEAREST;
3616 else if (aValue == "bilinear")
3618 aFilter = Graphic3d_TOTF_BILINEAR;
3620 else if (aValue == "trilinear")
3622 aFilter = Graphic3d_TOTF_TRILINEAR;
3626 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3630 else if ((aNameCase == "-setaniso"
3631 || aNameCase == "-setanisofilter"
3632 || aNameCase == "-aniso"
3633 || aNameCase == "-anisofilter")
3634 && anArgIter + 1 < theArgsNb)
3636 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3640 if (aValue == "off")
3642 anAnisoFilter = Graphic3d_LOTA_OFF;
3644 else if (aValue == "fast")
3646 anAnisoFilter = Graphic3d_LOTA_FAST;
3648 else if (aValue == "middle")
3650 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
3652 else if (aValue == "quality"
3653 || aValue == "high")
3655 anAnisoFilter = Graphic3d_LOTA_QUALITY;
3659 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3663 else if ((aNameCase == "-rotateangle"
3664 || aNameCase == "-rotangle"
3665 || aNameCase == "-rotate"
3666 || aNameCase == "-angle"
3667 || aNameCase == "-trsfangle")
3668 && anArgIter + 1 < theArgsNb)
3670 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3671 toSetTrsfAngle = true;
3674 else if ((aNameCase == "-trsftrans"
3675 || aNameCase == "-trsftranslate"
3676 || aNameCase == "-translate"
3677 || aNameCase == "-translation")
3678 && anArgIter + 2 < theArgsNb)
3680 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3681 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3682 toSetTrsfTrans = true;
3685 else if ((aNameCase == "-trsfscale")
3686 && anArgIter + 2 < theArgsNb)
3688 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3689 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3690 toSetTrsfScale = true;
3693 else if (aNameCase == "-default"
3694 || aNameCase == "-defaults")
3696 toSetDefaults = true;
3698 else if (aCommandName == "vtexture"
3699 && (aTextureVecNew.IsEmpty()
3700 || aNameCase.StartsWith ("-tex")))
3702 Standard_Integer aTexIndex = 0;
3703 TCollection_AsciiString aTexName = aName;
3704 if (aNameCase.StartsWith ("-tex"))
3706 if (anArgIter + 1 >= theArgsNb
3707 || aNameCase.Length() < 5)
3709 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3713 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
3714 if (!aTexIndexStr.IsIntegerValue())
3716 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3720 aTexIndex = aTexIndexStr.IntegerValue();
3721 aTexName = theArgVec[anArgIter + 1];
3724 if (aTexIndex >= Graphic3d_TextureUnit_NB
3725 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
3727 std::cout << "Error: too many textures specified\n";
3732 if (aTexName.IsIntegerValue())
3734 const Standard_Integer aValue = aTexName.IntegerValue();
3735 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
3737 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
3740 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
3742 else if (aTexName == "?")
3744 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3746 theDi << "\n Files in current directory : \n\n";
3747 theDi.Eval ("glob -nocomplain *");
3749 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3750 aCmnd += aTextureFolder;
3753 theDi << "Files in " << aTextureFolder << " : \n\n";
3754 theDi.Eval (aCmnd.ToCString());
3757 else if (aTexName != "off")
3759 if (!OSD_File (aTexName).Exists())
3761 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
3764 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
3768 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
3771 if (aTextureVecNew.Value (aTexIndex))
3773 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
3778 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3785 // check if new image set is equal to already set one
3786 Standard_Integer aNbChanged = 0;
3787 Handle(Graphic3d_TextureSet) aTextureSetNew;
3788 if (!aTextureVecNew.IsEmpty())
3790 aNbChanged = aTextureVecNew.Size();
3791 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
3792 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
3794 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
3795 Handle(Graphic3d_TextureRoot) aTextureOld;
3796 if (!aTextureSetOld.IsNull()
3797 && aTexIter < aTextureSetOld->Size())
3799 aTextureOld = aTextureSetOld->Value (aTexIter);
3802 if (!aTextureOld.IsNull()
3803 && !aTextureNew.IsNull())
3805 *aTextureNew->GetParams() = *aTextureOld->GetParams();
3806 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
3808 TCollection_AsciiString aFilePathOld, aFilePathNew;
3809 aTextureOld->Path().SystemName (aFilePathOld);
3810 aTextureNew->Path().SystemName (aFilePathNew);
3811 if (aTextureNew->Name() == anOldManualTex->Name()
3812 && aFilePathOld == aFilePathNew
3813 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
3816 aTextureNew = anOldManualTex;
3820 aTextureSetNew->SetValue (aTexIter, aTextureNew);
3824 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
3825 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
3827 aTextureSetNew = aTextureSetOld;
3830 if (!aTexturedIO->Attributes()->HasOwnShadingAspect())
3832 if (aTexturedShape.IsNull())
3834 aTexturedIO->SetToUpdate();
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 if (!aTexturedShape.IsNull())
3927 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3929 toSetGenRepeat = true;
3932 && (aCommandName == "vtexorigin"
3935 if (!aTexturedShape.IsNull())
3937 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3939 toSetGenOrigin = true;
3942 && (aCommandName == "vtexscale"
3945 if (!aTexturedShape.IsNull())
3947 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3949 toSetGenScale = true;
3952 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
3954 if (!aTexturedShape.IsNull())
3956 aTexturedShape->SetToUpdate (AIS_Shaded);
3959 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
3960 || aCtx->DisplayMode() != AIS_Shaded)
3962 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
3967 aCtx->Display (aTexturedIO, false);
3968 aTexturedIO->SynchronizeAspects();
3972 //! Auxiliary method to parse transformation persistence flags
3973 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3974 Graphic3d_TransModeFlags& theFlags)
3976 if (theFlagString == "zoom")
3978 theFlags = Graphic3d_TMF_ZoomPers;
3980 else if (theFlagString == "rotate")
3982 theFlags = Graphic3d_TMF_RotatePers;
3984 else if (theFlagString == "zoomrotate")
3986 theFlags = Graphic3d_TMF_ZoomRotatePers;
3988 else if (theFlagString == "trihedron"
3989 || theFlagString == "triedron")
3991 theFlags = Graphic3d_TMF_TriedronPers;
3993 else if (theFlagString == "none")
3995 theFlags = Graphic3d_TMF_None;
3999 return Standard_False;
4002 return Standard_True;
4005 //! Auxiliary method to parse transformation persistence flags
4006 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4007 Aspect_TypeOfTriedronPosition& theCorner)
4009 TCollection_AsciiString aString (theString);
4010 aString.LowerCase();
4011 if (aString == "center")
4013 theCorner = Aspect_TOTP_CENTER;
4015 else if (aString == "top"
4016 || aString == "upper")
4018 theCorner = Aspect_TOTP_TOP;
4020 else if (aString == "bottom"
4021 || aString == "lower")
4023 theCorner = Aspect_TOTP_BOTTOM;
4025 else if (aString == "left")
4027 theCorner = Aspect_TOTP_LEFT;
4029 else if (aString == "right")
4031 theCorner = Aspect_TOTP_RIGHT;
4033 else if (aString == "topleft"
4034 || aString == "leftupper"
4035 || aString == "upperleft")
4037 theCorner = Aspect_TOTP_LEFT_UPPER;
4039 else if (aString == "bottomleft"
4040 || aString == "leftlower"
4041 || aString == "lowerleft")
4043 theCorner = Aspect_TOTP_LEFT_LOWER;
4045 else if (aString == "topright"
4046 || aString == "rightupper"
4047 || aString == "upperright")
4049 theCorner = Aspect_TOTP_RIGHT_UPPER;
4051 else if (aString == "bottomright"
4052 || aString == "lowerright"
4053 || aString == "rightlower")
4055 theCorner = Aspect_TOTP_RIGHT_LOWER;
4059 return Standard_False;
4062 return Standard_True;
4065 //==============================================================================
4066 //function : VDisplay2
4068 //purpose : Display an object from its name
4069 //==============================================================================
4070 static int VDisplay2 (Draw_Interpretor& theDI,
4071 Standard_Integer theArgNb,
4072 const char** theArgVec)
4076 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4080 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4083 ViewerTest::ViewerInit();
4084 aCtx = ViewerTest::GetAISContext();
4087 // Parse input arguments
4088 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4089 Standard_Integer isMutable = -1;
4090 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4091 Standard_Boolean toReDisplay = Standard_False;
4092 Standard_Integer isSelectable = -1;
4093 Standard_Integer anObjDispMode = -2;
4094 Standard_Integer anObjHighMode = -2;
4095 Standard_Boolean toSetTrsfPers = Standard_False;
4096 Handle(Graphic3d_TransformPers) aTrsfPers;
4097 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4098 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4099 Standard_Integer toDisplayInView = Standard_False;
4100 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4102 const TCollection_AsciiString aName = theArgVec[anArgIter];
4103 TCollection_AsciiString aNameCase = aName;
4104 aNameCase.LowerCase();
4105 if (anUpdateTool.parseRedrawMode (aName))
4109 else if (aNameCase == "-mutable")
4113 else if (aNameCase == "-neutral")
4115 aDispStatus = AIS_DS_Displayed;
4117 else if (aNameCase == "-immediate"
4118 || aNameCase == "-top")
4120 aZLayer = Graphic3d_ZLayerId_Top;
4122 else if (aNameCase == "-topmost")
4124 aZLayer = Graphic3d_ZLayerId_Topmost;
4126 else if (aNameCase == "-osd"
4127 || aNameCase == "-toposd"
4128 || aNameCase == "-overlay")
4130 aZLayer = Graphic3d_ZLayerId_TopOSD;
4132 else if (aNameCase == "-botosd"
4133 || aNameCase == "-underlay")
4135 aZLayer = Graphic3d_ZLayerId_BotOSD;
4137 else if (aNameCase == "-select"
4138 || aNameCase == "-selectable")
4142 else if (aNameCase == "-noselect"
4143 || aNameCase == "-noselection")
4147 else if (aNameCase == "-dispmode"
4148 || aNameCase == "-displaymode")
4150 if (++anArgIter >= theArgNb)
4152 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4156 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4158 else if (aNameCase == "-highmode"
4159 || aNameCase == "-highlightmode")
4161 if (++anArgIter >= theArgNb)
4163 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4167 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4169 else if (aNameCase == "-3d")
4171 toSetTrsfPers = Standard_True;
4172 aTrsfPers.Nullify();
4174 else if (aNameCase == "-2d"
4175 || aNameCase == "-trihedron"
4176 || aNameCase == "-triedron")
4178 toSetTrsfPers = Standard_True;
4179 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4181 if (anArgIter + 1 < theArgNb)
4183 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4184 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4187 aTrsfPers->SetCorner2d (aCorner);
4189 if (anArgIter + 2 < theArgNb)
4191 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4192 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4193 if (anX.IsIntegerValue()
4194 && anY.IsIntegerValue())
4197 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4203 else if (aNameCase == "-trsfpers"
4204 || aNameCase == "-pers")
4206 if (++anArgIter >= theArgNb
4207 || !aTrsfPers.IsNull())
4209 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4213 toSetTrsfPers = Standard_True;
4214 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4215 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4216 aPersFlags.LowerCase();
4217 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
4219 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
4223 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4225 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4227 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4229 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
4232 else if (aNameCase == "-trsfperspos"
4233 || aNameCase == "-perspos")
4235 if (anArgIter + 2 >= theArgNb
4236 || aTrsfPers.IsNull())
4238 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4242 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4243 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4244 TCollection_AsciiString aZ = "0";
4245 if (!aX.IsRealValue()
4246 || !aY.IsRealValue())
4248 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4251 if (anArgIter + 1 < theArgNb)
4253 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
4254 if (aTemp.IsRealValue())
4261 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
4262 if (aTrsfPers->IsZoomOrRotate())
4264 aTrsfPers->SetAnchorPoint (aPnt);
4266 else if (aTrsfPers->IsTrihedronOr2d())
4268 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
4271 else if (aNameCase == "-layer")
4273 if (++anArgIter >= theArgNb)
4275 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4279 TCollection_AsciiString aValue (theArgVec[anArgIter]);
4280 if (!aValue.IsIntegerValue())
4282 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4286 aZLayer = aValue.IntegerValue();
4288 else if (aNameCase == "-view"
4289 || aNameCase == "-inview")
4291 toDisplayInView = Standard_True;
4293 else if (aNameCase == "-redisplay")
4295 toReDisplay = Standard_True;
4297 else if (aNameCase == "-erased"
4298 || aNameCase == "-load")
4300 aDispStatus = AIS_DS_Erased;
4304 aNamesOfDisplayIO.Append (aName);
4308 if (aNamesOfDisplayIO.IsEmpty())
4310 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4314 // Display interactive objects
4315 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
4317 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
4318 Handle(AIS_InteractiveObject) aShape;
4319 if (!GetMapOfAIS().Find2 (aName, aShape))
4321 // create the AIS_Shape from a name
4322 aShape = GetAISShapeFromName (aName.ToCString());
4323 if (!aShape.IsNull())
4325 if (isMutable != -1)
4327 aShape->SetMutable (isMutable == 1);
4329 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4331 aShape->SetZLayer (aZLayer);
4335 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4337 if (anObjDispMode != -2)
4339 aShape->SetDisplayMode (anObjDispMode);
4341 if (anObjHighMode != -2)
4343 aShape->SetHilightMode (anObjHighMode);
4346 GetMapOfAIS().Bind (aShape, aName);
4347 Standard_Integer aDispMode = aShape->HasDisplayMode()
4348 ? aShape->DisplayMode()
4349 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4350 ? aCtx->DisplayMode()
4352 Standard_Integer aSelMode = -1;
4353 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4355 aSelMode = aShape->GlobalSelectionMode();
4358 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
4359 if (toDisplayInView)
4361 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
4363 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
4365 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4370 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
4375 if (isMutable != -1)
4377 aShape->SetMutable (isMutable == 1);
4379 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4381 aShape->SetZLayer (aZLayer);
4385 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4387 if (anObjDispMode != -2)
4389 aShape->SetDisplayMode (anObjDispMode);
4391 if (anObjHighMode != -2)
4393 aShape->SetHilightMode (anObjHighMode);
4395 Standard_Integer aDispMode = aShape->HasDisplayMode()
4396 ? aShape->DisplayMode()
4397 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4398 ? aCtx->DisplayMode()
4400 Standard_Integer aSelMode = -1;
4401 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4403 aSelMode = aShape->GlobalSelectionMode();
4406 if (aShape->Type() == AIS_KOI_Datum)
4408 aCtx->Display (aShape, Standard_False);
4412 theDI << "Display " << aName.ToCString() << "\n";
4414 // update the Shape in the AIS_Shape
4415 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
4416 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
4417 if (!aShapePrs.IsNull())
4419 if (!aShapePrs->Shape().IsEqual (aNewShape))
4421 toReDisplay = Standard_True;
4423 aShapePrs->Set (aNewShape);
4427 aCtx->Redisplay (aShape, Standard_False);
4432 aCtx->Erase (aShape, Standard_False);
4434 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
4435 if (toDisplayInView)
4437 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4445 //=======================================================================
4446 //function : VNbDisplayed
4447 //purpose : Returns number of displayed objects
4448 //=======================================================================
4449 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
4450 Standard_Integer theArgsNb,
4451 const char** theArgVec)
4455 theDi << "Usage : " << theArgVec[0] << "\n";
4459 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4460 if (aContextAIS.IsNull())
4462 std::cout << theArgVec[0] << "AIS context is not available.\n";
4466 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4467 if(aContext.IsNull())
4469 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
4473 AIS_ListOfInteractive aListOfIO;
4474 aContextAIS->DisplayedObjects (aListOfIO);
4476 theDi << aListOfIO.Extent() << "\n";
4480 //===============================================================================================
4481 //function : VUpdate
4483 //===============================================================================================
4484 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
4486 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4487 if (aContextAIS.IsNull())
4489 std::cout << theArgVec[0] << "AIS context is not available.\n";
4495 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
4499 AIS_ListOfInteractive aListOfIO;
4500 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4502 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
4504 Handle(AIS_InteractiveObject) anAISObj;
4505 GetMapOfAIS().Find2 (aName, anAISObj);
4506 if (anAISObj.IsNull())
4508 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
4512 aListOfIO.Append (anAISObj);
4515 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
4516 for (; anIOIt.More(); anIOIt.Next())
4518 aContextAIS->Update (anIOIt.Value(), Standard_False);
4521 aContextAIS->UpdateCurrentViewer();
4526 //==============================================================================
4527 //function : VShading
4528 //purpose : Sharpen or roughten the quality of the shading
4529 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4530 //==============================================================================
4531 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4533 Standard_Real myDevCoef;
4534 Handle(AIS_InteractiveObject) TheAisIO;
4537 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4541 myDevCoef =Draw::Atof(argv[2]);
4544 TCollection_AsciiString name=argv[1];
4545 GetMapOfAIS().Find2(name, TheAisIO);
4546 if (TheAisIO.IsNull())
4547 TheAisIO=GetAISShapeFromName(name.ToCString());
4550 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4552 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4554 TheAISContext()->Redisplay (TheAisIO, Standard_True);
4558 //! Auxiliary method to print Interactive Object information
4559 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4560 const Handle(AIS_InteractiveObject)& theObj,
4561 Draw_Interpretor& theDI)
4563 if (theObj.IsNull())
4565 theDI << "NULL presentation\n";
4569 theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ")
4570 << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ")
4571 << (theDetected.Contains (theObj) ? " Detected" : " ")
4573 if (theObj->Type() == AIS_KOI_Datum)
4576 if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4577 else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; }
4578 else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; }
4579 else if (theObj->Signature() == 5) { theDI << " AIS_Line"; }
4580 else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; }
4581 else if (theObj->Signature() == 1) { theDI << " AIS_Point"; }
4582 else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4585 else if (theObj->Type() == AIS_KOI_Shape
4586 && theObj->Signature() == 0)
4588 theDI << " AIS_Shape";
4590 else if (theObj->Type() == AIS_KOI_Relation)
4592 // AIS_Dimention and AIS_Relation
4593 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (theObj);
4594 switch (aRelation->KindOfDimension())
4596 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4597 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4598 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4599 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4600 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4601 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4602 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4603 default: theDI << " UNKNOWN dimension"; break;
4608 theDI << " UserPrs";
4610 theDI << " (" << theObj->DynamicType()->Name() << ")";
4613 //! Print information about locally selected sub-shapes
4614 template <typename T>
4615 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4617 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4618 TCollection_AsciiString aPrevName;
4619 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4621 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4622 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4623 if (aShapeIO.IsNull() || anOwner.IsNull())
4627 if (anOwner == aShapeIO->GlobalSelOwner())
4630 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4631 if (aSubShape.IsNull()
4632 || aShapeIO.IsNull()
4633 || !GetMapOfAIS().IsBound1 (aShapeIO))
4638 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4639 TopTools_MapOfShape aFilter;
4640 Standard_Integer aNumber = 0;
4641 const TopoDS_Shape aShape = aShapeIO->Shape();
4642 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4643 anIter.More(); anIter.Next())
4645 if (!aFilter.Add (anIter.Current()))
4647 continue; // filter duplicates
4651 if (!anIter.Current().IsSame (aSubShape))
4656 Standard_CString aShapeName = NULL;
4657 switch (aSubShape.ShapeType())
4659 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4660 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4661 case TopAbs_SOLID: aShapeName = " Solid"; break;
4662 case TopAbs_SHELL: aShapeName = " Shell"; break;
4663 case TopAbs_FACE: aShapeName = " Face"; break;
4664 case TopAbs_WIRE: aShapeName = " Wire"; break;
4665 case TopAbs_EDGE: aShapeName = " Edge"; break;
4666 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4668 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4671 if (aParentName != aPrevName)
4673 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4674 aPrevName = aParentName;
4676 theDI << " " << aShapeName << " #" << aNumber << "\n";
4682 //==============================================================================
4685 //==============================================================================
4686 static Standard_Integer VState (Draw_Interpretor& theDI,
4687 Standard_Integer theArgNb,
4688 Standard_CString* theArgVec)
4690 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4693 std::cerr << "Error: No opened viewer!\n";
4697 Standard_Boolean toPrintEntities = Standard_False;
4698 Standard_Boolean toCheckSelected = Standard_False;
4700 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4702 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4703 anOption.LowerCase();
4704 if (anOption == "-detectedentities"
4705 || anOption == "-entities")
4707 toPrintEntities = Standard_True;
4709 else if (anOption == "-hasselected")
4711 toCheckSelected = Standard_True;
4715 if (toCheckSelected)
4717 aCtx->InitSelected();
4718 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4719 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4724 if (toPrintEntities)
4726 theDI << "Detected entities:\n";
4727 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
4729 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4730 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4732 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4733 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4734 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4735 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4736 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4737 aName.LeftJustify (20, ' ');
4738 char anInfoStr[512];
4740 " Depth: %g Distance: %g Point: %g %g %g",
4743 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4744 theDI << " " << aName
4746 << " (" << anEntity->DynamicType()->Name() << ")"
4749 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4750 if (!aBRepOwner.IsNull())
4752 theDI << " Detected Shape: "
4753 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4757 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4758 if (!aWire.IsNull())
4760 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4761 theDI << " Detected Child: "
4762 << aSen->DynamicType()->Name()
4766 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4767 if (!aPrimArr.IsNull())
4769 theDI << " Detected Element: "
4770 << aPrimArr->LastDetectedElement()
4777 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4778 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4780 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
4783 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4787 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4789 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4790 Handle(AIS_InteractiveObject) anObj;
4791 if (!GetMapOfAIS().Find2 (anObjName, anObj))
4793 theDI << anObjName << " doesn't exist!\n";
4797 TCollection_AsciiString aName = anObjName;
4798 aName.LeftJustify (20, ' ');
4799 theDI << " " << aName << " ";
4800 objInfo (aDetected, anObj, theDI);
4806 if (aCtx->NbSelected() > 0 && !toShowAll)
4808 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4809 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4811 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4812 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4813 // handle whole object selection
4814 if (anOwner == anObj->GlobalSelOwner())
4816 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4817 aName.LeftJustify (20, ' ');
4818 theDI << aName << " ";
4819 objInfo (aDetected, anObj, theDI);
4824 // process selected sub-shapes
4825 printLocalSelectionInfo (aCtx, theDI);
4830 theDI << "Neutral-point state:\n";
4831 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4832 anObjIter.More(); anObjIter.Next())
4834 if (anObjIter.Key1().IsNull())
4839 TCollection_AsciiString aName = anObjIter.Key2();
4840 aName.LeftJustify (20, ' ');
4841 theDI << " " << aName << " ";
4842 objInfo (aDetected, anObjIter.Key1(), theDI);
4845 printLocalSelectionInfo (aCtx, theDI);
4849 //=======================================================================
4850 //function : PickShape
4851 //purpose : First Activate the rightmode + Put Filters to be able to
4852 // pick objets that are of type <TheType>...
4853 //=======================================================================
4855 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
4856 const Standard_Integer theMaxPick)
4858 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
4859 PickShapes (theShapeType, aResArray, theMaxPick);
4860 return aResArray->First();
4863 //=======================================================================
4864 //function : PickShapes
4866 //=======================================================================
4867 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
4868 Handle(TopTools_HArray1OfShape)& theResArray,
4869 const Standard_Integer theMaxPick)
4871 const Standard_Integer aNbToReach = theResArray->Length();
4874 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4877 // step 1: prepare the data
4878 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4879 aCtx->RemoveFilters();
4880 AIS_ListOfInteractive aDispObjects;
4881 aCtx->DisplayedObjects (aDispObjects);
4882 if (theShapeType == TopAbs_SHAPE)
4884 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
4888 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
4891 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
4892 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
4894 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
4896 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
4900 // step 2 : wait for the selection...
4901 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
4902 Standard_Integer argccc = 5;
4903 const char *bufff[] = { "A", "B", "C", "D", "E" };
4904 const char **argvvv = (const char** )bufff;
4905 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
4907 while (ViewerMainLoop (argccc, argvvv)) {}
4908 Standard_Integer aNbStored = aCtx->NbSelected();
4909 if (aNbStored != aNbPickGood)
4911 aNbPickGood = aNbStored;
4917 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
4920 // step3 get result.
4921 if (aNbPickFail >= aNbToReach)
4923 return Standard_False;
4926 Standard_Integer anIndex = theResArray->Lower();
4927 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
4929 if (aCtx->HasSelectedShape())
4931 theResArray->SetValue (anIndex, aCtx->SelectedShape());
4935 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
4936 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
4940 aCtx->RemoveFilters();
4941 if (theShapeType != TopAbs_SHAPE)
4943 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
4945 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
4947 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
4951 return Standard_True;
4954 //=======================================================================
4955 //function : VPickShape
4957 //=======================================================================
4958 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4960 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4963 TCollection_AsciiString aShapeArg (argv[1]);
4964 aShapeArg.LowerCase();
4965 aShapeType = TopAbs_COMPOUND;
4966 if (aShapeArg == "v"
4967 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
4968 else if (aShapeArg == "e"
4969 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
4970 else if (aShapeArg == "w"
4971 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
4972 else if (aShapeArg == "f"
4973 || aShapeArg == "face") aShapeType = TopAbs_FACE;
4974 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
4975 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
4976 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
4979 std::cout << "Syntax error at '" << argv[1] << "'\n";
4984 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4985 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4987 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
4990 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
4991 if (aPickedShape.IsNull())
4996 TCollection_AsciiString aName;
5003 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5004 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5007 DBRep::Set (aName.ToCString(), aPickedShape);
5008 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5009 ViewerTest::Display (aName, aShapePrs, false, true);
5010 di << "Name of picked shape: " << aName <<"\n";
5014 TCollection_AsciiString aName (argv[2]);
5016 const Standard_Boolean isAutoNaming = aName == ".";
5017 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5018 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5020 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5022 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5024 if (!aPickedShape.IsNull()
5027 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5028 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5032 aName = argv[1 + aPickedIter];
5035 DBRep::Set (aName.ToCString(), aPickedShape);
5036 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5037 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5038 ViewerTest::Display (aName, aShapePrs, false, true);
5042 TheAISContext()->UpdateCurrentViewer();
5046 //=======================================================================
5047 //function : VSelFilter
5049 //=======================================================================
5050 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5051 const char** theArgv)
5053 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5054 if (aContext.IsNull())
5056 std::cout << "Error: AIS context is not available.\n";
5060 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5062 TCollection_AsciiString anArg (theArgv[anArgIter]);
5064 if (anArg == "-clear")
5066 aContext->RemoveFilters();
5068 else if (anArg == "-type"
5069 && anArgIter + 1 < theArgc)
5071 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5072 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5073 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5075 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5079 Handle(SelectMgr_Filter) aFilter;
5080 if (aShapeType == TopAbs_SHAPE)
5082 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5086 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5088 aContext->AddFilter (aFilter);
5092 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5099 //=======================================================================
5100 //function : VPickSelected
5102 //=======================================================================
5103 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5105 static Standard_Integer aCount = 0;
5106 TCollection_AsciiString aName = "PickedShape_";
5114 aName = aName + aCount++ + "_";
5117 Standard_Integer anIdx = 0;
5118 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5120 TopoDS_Shape aShape;
5121 if (TheAISContext()->HasSelectedShape())
5123 aShape = TheAISContext()->SelectedShape();
5127 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5128 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5131 TCollection_AsciiString aCurrentName = aName;
5134 aCurrentName += anIdx;
5137 DBRep::Set ((aCurrentName).ToCString(), aShape);
5139 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5140 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5141 TheAISContext()->Display (aNewShape, Standard_False);
5144 TheAISContext()->UpdateCurrentViewer();
5149 //=======================================================================
5150 //function : list of known objects
5152 //=======================================================================
5153 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5155 // 1234567890 12345678901234567 123456789
5156 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5157 TCollection_AsciiString BlankLine(64,'_');
5158 Standard_Integer i ;
5160 di<<"/n"<<BlankLine.ToCString()<<"\n";
5163 Colum[i].Center(20,' ');
5165 di<<"|"<<Colum[i].ToCString();
5168 di<<BlankLine.ToCString()<<"\n";
5170 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5171 const char ** names = GetTypeNames();
5173 TCollection_AsciiString curstring;
5174 TCollection_AsciiString curcolum[3];
5177 // les objets de type Datum..
5178 curcolum[1]+="Datum";
5180 curcolum[0].Clear();
5181 curcolum[0] += names[i];
5183 curcolum[2].Clear();
5184 curcolum[2]+=TCollection_AsciiString(i+1);
5186 for(Standard_Integer j =0;j<=2;j++){
5187 curcolum[j].Center(20,' ');
5188 di<<"|"<<curcolum[j].ToCString();
5192 di<<BlankLine.ToCString()<<"\n";
5194 // les objets de type shape
5195 curcolum[1].Clear();
5196 curcolum[1]+="Shape";
5197 curcolum[1].Center(20,' ');
5200 curcolum[0].Clear();
5201 curcolum[0] += names[7+i];
5202 curcolum[2].Clear();
5203 curcolum[2]+=TCollection_AsciiString(i);
5205 for(Standard_Integer j =0;j<=2;j++){
5206 curcolum[j].Center(20,' ');
5207 di<<"|"<<curcolum[j].ToCString();
5211 di<<BlankLine.ToCString()<<"\n";
5212 // les IO de type objet...
5213 curcolum[1].Clear();
5214 curcolum[1]+="Object";
5215 curcolum[1].Center(20,' ');
5217 curcolum[0].Clear();
5218 curcolum[0] += names[10+i];
5219 curcolum[2].Clear();
5220 curcolum[2]+=TCollection_AsciiString(i);
5222 for(Standard_Integer j =0;j<=2;j++){
5223 curcolum[j].Center(20,' ');
5224 di<<"|"<<curcolum[j].ToCString();
5228 di<<BlankLine.ToCString()<<"\n";
5229 // les contraintes et dimensions.
5230 // pour l'instant on separe juste contraintes et dimensions...
5231 // plus tard, on detaillera toutes les sortes...
5232 curcolum[1].Clear();
5233 curcolum[1]+="Relation";
5234 curcolum[1].Center(20,' ');
5236 curcolum[0].Clear();
5237 curcolum[0] += names[12+i];
5238 curcolum[2].Clear();
5239 curcolum[2]+=TCollection_AsciiString(i);
5241 for(Standard_Integer j =0;j<=2;j++){
5242 curcolum[j].Center(20,' ');
5243 di<<"|"<<curcolum[j].ToCString();
5247 di<<BlankLine.ToCString()<<"\n";
5254 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5256 if(argc!=2) return 1;
5258 AIS_KindOfInteractive TheType;
5259 Standard_Integer TheSign(-1);
5260 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5263 AIS_ListOfInteractive LIO;
5265 // en attendant l'amelioration ais pour les dimensions...
5267 Standard_Integer dimension_status(-1);
5268 if(TheType==AIS_KOI_Relation){
5269 dimension_status = TheSign ==1 ? 1 : 0;
5273 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5274 Handle(AIS_InteractiveObject) curio;
5275 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5278 if(dimension_status == -1)
5279 TheAISContext()->Erase(curio,Standard_False);
5281 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5282 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5283 (dimension_status==1 && KOD != AIS_KOD_NONE))
5284 TheAISContext()->Erase(curio,Standard_False);
5287 TheAISContext()->UpdateCurrentViewer();
5290 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5292 if(argc!=2) return 1;
5294 AIS_KindOfInteractive TheType;
5295 Standard_Integer TheSign(-1);
5296 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5298 // en attendant l'amelioration ais pour les dimensions...
5300 Standard_Integer dimension_status(-1);
5301 if(TheType==AIS_KOI_Relation){
5302 dimension_status = TheSign ==1 ? 1 : 0;
5306 AIS_ListOfInteractive LIO;
5307 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5308 Handle(AIS_InteractiveObject) curio;
5309 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5311 if(dimension_status == -1)
5312 TheAISContext()->Display(curio,Standard_False);
5314 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5315 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5316 (dimension_status==1 && KOD != AIS_KOD_NONE))
5317 TheAISContext()->Display(curio,Standard_False);
5322 TheAISContext()->UpdateCurrentViewer();
5326 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5329 BRep_Builder builder;
5331 BRepTools::Read(shape, s, builder);
5332 DBRep::Set(a[1], shape);
5333 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5334 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5335 Ctx->Display (ais, Standard_True);
5339 //===============================================================================================
5342 //===============================================================================================
5343 static int VBsdf (Draw_Interpretor& theDI,
5344 Standard_Integer theArgsNb,
5345 const char** theArgVec)
5347 Handle(V3d_View) aView = ViewerTest::CurrentView();
5348 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5350 || aViewer.IsNull())
5352 std::cerr << "No active viewer!\n";
5356 ViewerTest_CmdParser aCmd;
5358 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5360 aCmd.AddOption ("print|echo|p", "Prints BSDF");
5362 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
5364 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
5365 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
5366 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
5367 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
5368 aCmd.AddOption ("le", "Radiance emitted by surface");
5370 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5371 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5373 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
5374 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
5376 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
5377 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
5379 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
5381 aCmd.Parse (theArgsNb, theArgVec);
5383 if (aCmd.HasOption ("help"))
5385 theDI.PrintHelp (theArgVec[0]);
5389 // check viewer update mode
5390 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
5391 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5393 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5400 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5401 Handle(AIS_InteractiveObject) anIObj;
5402 if (!GetMapOfAIS().Find2 (aName, anIObj))
5404 std::cerr << "Use 'vdisplay' before\n";
5408 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5409 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5411 if (aCmd.HasOption ("print"))
5414 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
5415 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5416 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5417 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5418 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
5420 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5422 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
5423 : aBSDF.FresnelBase.Serialize();
5425 theDI << (aLayerID < 1 ? "Coat Fresnel: "
5426 : "Base Fresnel: ");
5428 if (aFresnel.x() >= 0.f)
5430 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
5431 << "G = " << aFresnel.g() << ", "
5432 << "B = " << aFresnel.b() << "\n";
5434 else if (aFresnel.x() >= -1.5f)
5436 theDI << "Constant " << aFresnel.z() << "\n";
5438 else if (aFresnel.x() >= -2.5f)
5440 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
5441 << "K = " << aFresnel.z() << "\n";
5445 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
5449 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
5450 << "Base roughness: " << aBSDF.Ks.w() << "\n"
5451 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
5452 << "Absorption color: " << aBSDF.Absorption.r() << ", "
5453 << aBSDF.Absorption.g() << ", "
5454 << aBSDF.Absorption.b() << "\n";
5459 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
5461 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
5464 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
5466 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
5469 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5471 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
5474 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5476 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
5478 aBSDF.Absorption.r() = aRGB.r();
5479 aBSDF.Absorption.g() = aRGB.g();
5480 aBSDF.Absorption.b() = aRGB.b();
5483 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
5487 if (aCmd.HasOption ("kc", 3))
5489 aKc = aCmd.ArgVec3f ("kc");
5493 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
5496 aBSDF.Kc.r() = aKc.r();
5497 aBSDF.Kc.g() = aKc.g();
5498 aBSDF.Kc.b() = aKc.b();
5501 if (aCmd.HasOption ("kd", 3))
5503 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5505 else if (aCmd.HasOption ("kd", 1, Standard_True))
5507 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5510 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
5514 if (aCmd.HasOption ("ks", 3))
5516 aKs = aCmd.ArgVec3f ("ks");
5520 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5523 aBSDF.Ks.r() = aKs.r();
5524 aBSDF.Ks.g() = aKs.g();
5525 aBSDF.Ks.b() = aKs.b();
5528 if (aCmd.HasOption ("kt", 3))
5530 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5532 else if (aCmd.HasOption ("kt", 1, Standard_True))
5534 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5537 if (aCmd.HasOption ("le", 3))
5539 aBSDF.Le = aCmd.ArgVec3f ("le");
5541 else if (aCmd.HasOption ("le", 1, Standard_True))
5543 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5546 const std::string aFresnelErrorMessage =
5547 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
5549 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5551 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
5554 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
5556 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5557 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5559 if (aFresnelType == "schlick")
5561 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
5562 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
5563 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
5565 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
5566 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
5567 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
5569 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
5573 theDI << aFresnelErrorMessage.c_str() << "\n";
5576 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
5578 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5579 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5581 if (aFresnelType == "conductor")
5583 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5584 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
5586 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
5590 theDI << aFresnelErrorMessage.c_str() << "\n";
5593 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
5595 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5596 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5598 if (aFresnelType == "constant")
5600 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5602 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
5604 else if (aFresnelType == "dielectric")
5606 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5608 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
5612 theDI << aFresnelErrorMessage.c_str() << "\n";
5617 if (aCmd.HasOption ("normalize"))
5622 aMaterial.SetBSDF (aBSDF);
5623 anIObj->SetMaterial (aMaterial);
5628 //==============================================================================
5629 //function : VLoadSelection
5630 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5631 //==============================================================================
5632 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5633 Standard_Integer theArgNb,
5634 const char** theArgVec)
5638 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5642 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5645 ViewerTest::ViewerInit();
5646 aCtx = ViewerTest::GetAISContext();
5649 // Parse input arguments
5650 TColStd_SequenceOfAsciiString aNamesOfIO;
5651 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5653 const TCollection_AsciiString aName = theArgVec[anArgIter];
5654 aNamesOfIO.Append (aName);
5657 if (aNamesOfIO.IsEmpty())
5659 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5663 // Load selection of interactive objects
5664 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5666 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5668 Handle(AIS_InteractiveObject) aShape;
5669 if (!GetMapOfAIS().Find2 (aName, aShape))
5671 aShape = GetAISShapeFromName (aName.ToCString());
5674 if (!aShape.IsNull())
5676 if (!GetMapOfAIS().IsBound2 (aName))
5678 GetMapOfAIS().Bind (aShape, aName);
5681 aCtx->Load (aShape, -1);
5682 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5689 //==============================================================================
5690 //function : ViewerTest::Commands
5691 //purpose : Add all the viewer command in the Draw_Interpretor
5692 //==============================================================================
5694 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5696 ViewerTest::ViewerCommands(theCommands);
5697 ViewerTest::RelationCommands(theCommands);
5698 ViewerTest::ObjectCommands(theCommands);
5699 ViewerTest::FilletCommands(theCommands);
5700 ViewerTest::OpenGlCommands(theCommands);
5702 const char *group = "AIS_Display";
5705 theCommands.Add("visos",
5706 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5707 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5708 __FILE__, visos, group);
5710 theCommands.Add("vdisplay",
5711 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5712 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5713 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5714 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5715 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5716 "\n\t\t: [offsetX offsetY]]]"
5717 "\n\t\t: [-dispMode mode] [-highMode mode]"
5718 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5719 "\n\t\t: [-redisplay] [-erased]"
5720 "\n\t\t: name1 [name2] ... [name n]"
5721 "\n\t\t: Displays named objects."
5722 "\n\t\t: Option -local enables displaying of objects in local"
5723 "\n\t\t: selection context. Local selection context will be opened"
5724 "\n\t\t: if there is not any."
5725 "\n\t\t: -noupdate Suppresses viewer redraw call."
5726 "\n\t\t: -mutable Enables optimizations for mutable objects."
5727 "\n\t\t: -neutral Draws objects in main viewer."
5728 "\n\t\t: -erased Loads the object into context, but does not display it."
5729 "\n\t\t: -layer Sets z-layer for objects."
5730 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5731 "\n\t\t: options can be used for the default z-layers."
5732 "\n\t\t: -top Draws object on top of main presentations"
5733 "\n\t\t: but below topmost."
5734 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5735 "\n\t\t: with independent Depth."
5736 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5737 "\n\t\t: (On-Screen-Display)"
5738 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5739 "\n\t\t: (On-Screen-Display)"
5740 "\n\t\t: -selectable|-noselect Controls selection of objects."
5741 "\n\t\t: -trsfPers Sets a transform persistence flags."
5742 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5743 "\n\t\t: -2d Displays object in screen coordinates."
5744 "\n\t\t: (DY looks up)"
5745 "\n\t\t: -dispmode Sets display mode for objects."
5746 "\n\t\t: -highmode Sets hilight mode for objects."
5747 "\n\t\t: -redisplay Recomputes presentation of objects.",
5748 __FILE__, VDisplay2, group);
5750 theCommands.Add ("vnbdisplayed",
5752 "\n\t\t: Returns number of displayed objects",
5753 __FILE__, VNbDisplayed, group);
5755 theCommands.Add ("vupdate",
5756 "vupdate name1 [name2] ... [name n]"
5757 "\n\t\t: Updates named objects in interactive context",
5758 __FILE__, VUpdate, group);
5760 theCommands.Add("verase",
5761 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5762 "\n\t\t: Erases selected or named objects."
5763 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5764 "\n\t\t: Option -local enables erasing of selected or named objects without"
5765 "\n\t\t: closing local selection context.",
5766 __FILE__, VErase, group);
5768 theCommands.Add("vremove",
5769 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5770 "or vremove [-context] -all to remove all objects"
5771 "\n\t\t: Removes selected or named objects."
5772 "\n\t\t If -context is in arguments, the objects are not deleted"
5773 "\n\t\t from the map of objects and names."
5774 "\n\t\t: Option -local enables removing of selected or named objects without"
5775 "\n\t\t: closing local selection context. Empty local selection context will be"
5777 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5778 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5779 __FILE__, VRemove, group);
5781 theCommands.Add("vdonly",
5782 "vdonly [-noupdate|-update] [name1] ... [name n]"
5783 "\n\t\t: Displays only selected or named objects",
5784 __FILE__,VDonly2,group);
5786 theCommands.Add("vdisplayall",
5788 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
5789 __FILE__, VDisplayAll, group);
5791 theCommands.Add("veraseall",
5793 "\n\t\t: Erases all objects displayed in the viewer.",
5794 __FILE__, VErase, group);
5796 theCommands.Add("verasetype",
5798 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5799 __FILE__, VEraseType, group);
5800 theCommands.Add("vbounding",
5801 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5802 "\n\t\t: [-print] [-hide]"
5803 "\n\t\t: Temporarily display bounding box of specified Interactive"
5804 "\n\t\t: Objects, or print it to console if -print is specified."
5805 "\n\t\t: Already displayed box might be hidden by -hide option.",
5806 __FILE__,VBounding,group);
5808 theCommands.Add("vdisplaytype",
5809 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5810 __FILE__,VDisplayType,group);
5812 theCommands.Add("vsetdispmode",
5813 "vsetdispmode [name] mode(1,2,..)"
5814 "\n\t\t: Sets display mode for all, selected or named objects.",
5815 __FILE__,VDispMode,group);
5817 theCommands.Add("vunsetdispmode",
5818 "vunsetdispmode [name]"
5819 "\n\t\t: Unsets custom display mode for selected or named objects.",
5820 __FILE__,VDispMode,group);
5822 theCommands.Add("vdir",
5823 "Lists all objects displayed in 3D viewer",
5824 __FILE__,VDir,group);
5826 #ifdef HAVE_FREEIMAGE
5827 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5829 #define DUMP_FORMATS "{ppm}"
5831 theCommands.Add("vdump",
5832 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5833 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5834 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5835 "\n\t\t: [-tileSize Size=0]"
5836 "\n\t\t: Dumps content of the active view into image file",
5837 __FILE__,VDump,group);
5839 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5840 __FILE__,VSubInt,group);
5842 theCommands.Add("vaspects",
5843 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5844 "\n\t\t: [-setVisibility 0|1]"
5845 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5846 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5847 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5848 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5849 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5850 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
5851 "\n\t\t: [-unsetMarkerType]"
5852 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
5853 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5854 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5855 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5856 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5857 "\n\t\t: [-isoontriangulation 0|1]"
5858 "\n\t\t: [-setMaxParamValue {value}]"
5859 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5860 "\n\t\t: [-setHatch HatchStyle]"
5861 "\n\t\t: [-setShadingModel {color|flat|gouraud|phong}]"
5862 "\n\t\t: [-unsetShadingModel]"
5863 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
5864 "\n\t\t: Manage presentation properties of all, selected or named objects."
5865 "\n\t\t: When -subshapes is specified than following properties will be"
5866 "\n\t\t: assigned to specified sub-shapes."
5867 "\n\t\t: When -defaults is specified than presentation properties will be"
5868 "\n\t\t: assigned to all objects that have not their own specified properties"
5869 "\n\t\t: and to all objects to be displayed in the future."
5870 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5871 __FILE__,VAspects,group);
5873 theCommands.Add("vsetcolor",
5874 "vsetcolor [-noupdate|-update] [name] ColorName"
5875 "\n\t\t: Sets color for all, selected or named objects."
5876 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5877 __FILE__,VAspects,group);
5879 theCommands.Add("vunsetcolor",
5880 "vunsetcolor [-noupdate|-update] [name]"
5881 "\n\t\t: Resets color for all, selected or named objects."
5882 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5883 __FILE__,VAspects,group);
5885 theCommands.Add("vsettransparency",
5886 "vsettransparency [-noupdate|-update] [name] Coefficient"
5887 "\n\t\t: Sets transparency for all, selected or named objects."
5888 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5889 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5890 __FILE__,VAspects,group);
5892 theCommands.Add("vunsettransparency",
5893 "vunsettransparency [-noupdate|-update] [name]"
5894 "\n\t\t: Resets transparency for all, selected or named objects."
5895 "\n\t\t: Alias for vaspects -unsettransp [name].",
5896 __FILE__,VAspects,group);
5898 theCommands.Add("vsetmaterial",
5899 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5900 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5901 __FILE__,VAspects,group);
5903 theCommands.Add("vunsetmaterial",
5904 "vunsetmaterial [-noupdate|-update] [name]"
5905 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5906 __FILE__,VAspects,group);
5908 theCommands.Add("vsetwidth",
5909 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5910 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5911 __FILE__,VAspects,group);
5913 theCommands.Add("vunsetwidth",
5914 "vunsetwidth [-noupdate|-update] [name]"
5915 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5916 __FILE__,VAspects,group);
5918 theCommands.Add("vsetinteriorstyle",
5919 "vsetinteriorstyle [-noupdate|-update] [name] style"
5920 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5921 __FILE__,VSetInteriorStyle,group);
5923 theCommands.Add("vsensdis",
5924 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5925 "\n\t\t: Standard entity types are those defined in Select3D package:"
5926 "\n\t\t: - sensitive box"
5927 "\n\t\t: - sensitive face"
5928 "\n\t\t: - sensitive curve"
5929 "\n\t\t: - sensitive segment"
5930 "\n\t\t: - sensitive circle"
5931 "\n\t\t: - sensitive point"
5932 "\n\t\t: - sensitive triangulation"
5933 "\n\t\t: - sensitive triangle"
5934 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5935 __FILE__,VDispSensi,group);
5937 theCommands.Add("vsensera",
5938 "vsensera : erase active entities",
5939 __FILE__,VClearSensi,group);
5941 theCommands.Add("vsetshading",
5942 "vsetshading : vsetshading name Quality(default=0.0008) "
5943 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5944 __FILE__,VShading,group);
5946 theCommands.Add("vunsetshading",
5947 "vunsetshading :vunsetshading name "
5948 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5949 __FILE__,VShading,group);
5951 theCommands.Add ("vtexture",
5952 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
5953 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
5954 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
5955 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
5956 "\n\t\t: [-modulate {on|off}]"
5957 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
5958 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
5959 "\n\t\t: [-default]"
5960 "\n\t\t: The texture can be specified by filepath"
5961 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
5962 "\n\t\t: The options are:"
5963 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
5964 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
5965 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
5966 "\n\t\t: -modulate Enable or disable texture color modulation"
5967 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
5968 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
5969 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
5970 "\n\t\t: -setFilter Setup texture filter"
5971 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
5972 "\n\t\t: -default Sets texture mapping default parameters",
5973 __FILE__, VTexture, group);
5975 theCommands.Add("vtexscale",
5976 "vtexscale name ScaleU ScaleV"
5977 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
5978 __FILE__,VTexture,group);
5980 theCommands.Add("vtexorigin",
5981 "vtexorigin name OriginU OriginV"
5982 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
5983 __FILE__,VTexture,group);
5985 theCommands.Add("vtexrepeat",
5986 "vtexrepeat name RepeatU RepeatV"
5987 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
5990 theCommands.Add("vtexdefault",
5992 "\n\t\t: Alias for vtexture name -default.",
5995 theCommands.Add("vstate",
5996 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5997 "\n\t\t: Reports show/hidden state for selected or named objects"
5998 "\n\t\t: -entities - print low-level information about detected entities"
5999 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6000 __FILE__,VState,group);
6002 theCommands.Add("vpickshapes",
6003 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6004 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6005 "\n\t\t: Hold also Shift for multiple selection.",
6006 __FILE__, VPickShape, group);
6008 theCommands.Add("vtypes",
6009 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6012 theCommands.Add("vr",
6014 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6015 __FILE__,vr, group);
6017 theCommands.Add("vselfilter",
6018 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6019 "\nSets selection shape type filter in context or remove all filters."
6020 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6021 "\n : Option -clear remove all filters in context",
6022 __FILE__,VSelFilter,group);
6024 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6025 __FILE__, VPickSelected, group);
6027 theCommands.Add ("vloadselection",
6028 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6029 "\n\t\t: primitives for the shapes with names given without displaying them.",
6030 __FILE__, VLoadSelection, group);
6032 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6033 "\nAdjusts parameters of material BSDF:"
6034 "\n -help : Shows this message"
6035 "\n -print : Print BSDF"
6036 "\n -kd : Weight of the Lambertian BRDF"
6037 "\n -kr : Weight of the reflection BRDF"
6038 "\n -kt : Weight of the transmission BTDF"
6039 "\n -ks : Weight of the glossy Blinn BRDF"
6040 "\n -le : Self-emitted radiance"
6041 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6042 "\n Schlick x y z, Dielectric x, Conductor x y"
6043 "\n -roughness : Roughness of material (Blinn's exponent)"
6044 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6045 "\n -absorpcolor : Absorption color (only for transparent material)"
6046 "\n -normalize : Normalize BSDF coefficients",
6047 __FILE__, VBsdf, group);
6051 //=====================================================================
6052 //========================= for testing Draft and Rib =================
6053 //=====================================================================
6054 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6055 #include <DBRep.hxx>
6056 #include <TopoDS_Face.hxx>
6057 #include <gp_Pln.hxx>
6058 #include <AIS_KindOfSurface.hxx>
6059 #include <BRepOffsetAPI_DraftAngle.hxx>
6060 #include <Precision.hxx>
6061 #include <BRepAlgo.hxx>
6062 #include <OSD_Environment.hxx>
6063 #include <DrawTrSurf.hxx>
6064 //#include <DbgTools.hxx>
6065 //#include <FeatAlgo_MakeLinearForm.hxx>
6070 //=======================================================================
6071 //function : IsValid
6073 //=======================================================================
6074 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6075 const TopoDS_Shape& theResult,
6076 const Standard_Boolean closedSolid,
6077 const Standard_Boolean GeomCtrl)
6079 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6080 TCollection_AsciiString checkValid = check.Value();
6081 Standard_Boolean ToCheck = Standard_True;
6082 if (!checkValid.IsEmpty()) {
6084 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6086 if ( checkValid=="true" || checkValid=="TRUE" ) {
6087 ToCheck= Standard_False;
6091 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6094 Standard_Boolean IsValid = Standard_True;
6096 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6101 //===============================================================================
6102 // TDraft : test draft, uses AIS Viewer
6103 // Solid Face Plane Angle Reverse
6104 //===============================================================================
6105 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6107 if (argc < 5) return 1;
6108 // argv[1] - TopoDS_Shape Solid
6109 // argv[2] - TopoDS_Shape Face
6110 // argv[3] - TopoDS_Shape Plane
6111 // argv[4] - Standard_Real Angle
6112 // argv[5] - Standard_Integer Reverse
6114 // Sprintf(prefix, argv[1]);
6115 Standard_Real anAngle = 0;
6116 Standard_Boolean Rev = Standard_False;
6117 Standard_Integer rev = 0;
6118 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
6119 TopoDS_Shape face = GetShapeFromName(argv[2]);
6120 TopoDS_Face Face = TopoDS::Face(face);
6121 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
6122 if (Plane.IsNull ()) {
6123 di << "TEST : Plane is NULL\n";
6126 anAngle = Draw::Atof(argv[4]);
6127 anAngle = 2*M_PI * anAngle / 360.0;
6129 Handle( Geom_Surface )aSurf;
6130 AIS_KindOfSurface aSurfType;
6131 Standard_Real Offset;
6133 if(argc > 4) { // == 5
6134 rev = Draw::Atoi(argv[5]);
6135 Rev = (rev)? Standard_True : Standard_False;
6138 TopoDS_Face face2 = TopoDS::Face(Plane);
6139 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6141 di << "TEST : Can't find plane\n";
6145 aDir = aPln.Axis().Direction();
6148 if (Plane.Orientation() == TopAbs_REVERSED)
6150 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6152 BRepOffsetAPI_DraftAngle Draft (Solid);
6154 if(Abs(anAngle)< Precision::Angular()) {
6155 di << "TEST : NULL angle\n";
6158 if(Rev) anAngle = - anAngle;
6159 Draft.Add (Face, aDir, anAngle, aPln);
6161 if (!Draft.IsDone()) {
6162 di << "TEST : Draft Not DONE \n";
6165 TopTools_ListOfShape Larg;
6167 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6168 di << "TEST : DesignAlgo returns Not valid\n";
6172 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6173 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6175 if ( !ais.IsNull() ) {
6176 ais->SetColor(DEFAULT_COLOR);
6177 ais->SetMaterial(DEFAULT_MATERIAL);
6178 // Display the AIS_Shape without redraw
6179 Ctx->Display(ais, Standard_False);
6181 const char *Name = "draft1";
6182 Handle(AIS_InteractiveObject) an_object;
6183 if (GetMapOfAIS().Find2(Name, an_object))
6185 if (!an_object.IsNull())
6187 Ctx->Remove (an_object, Standard_True);
6189 GetMapOfAIS().UnBind2 (Name);
6191 GetMapOfAIS().Bind(ais, Name);
6192 // DBRep::Set("draft", ais->Shape());
6194 Ctx->Display(ais, Standard_True);
6198 //==============================================================================
6199 //function : splitParameter
6200 //purpose : Split parameter string to parameter name and parameter value
6201 //==============================================================================
6202 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6203 TCollection_AsciiString& theName,
6204 TCollection_AsciiString& theValue)
6206 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6208 if (aParamNameEnd == 0)
6210 return Standard_False;
6213 TCollection_AsciiString aString (theString);
6214 if (aParamNameEnd != 0)
6216 theValue = aString.Split (aParamNameEnd);
6217 aString.Split (aString.Length() - 1);
6221 return Standard_True;
6224 //============================================================================
6226 //============================================================================
6227 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6230 DrawTrSurf::BasicCommands(theCommands);
6231 const char* group = "Check Features Operations commands";
6233 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6235 &TDraft,group); //Draft_Modification
6238 //==============================================================================
6239 // ViewerTest::Factory
6240 //==============================================================================
6241 void ViewerTest::Factory(Draw_Interpretor& theDI)
6243 // definition of Viewer Command
6244 ViewerTest::Commands(theDI);
6247 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6251 // Declare entry point PLUGINFACTORY