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 Standard_Boolean theIsSubPart) 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;
1733 && ToSetTransparency != 0)
1735 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1736 isOk = Standard_False;
1738 if (ToSetAlphaMode == 1
1739 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1741 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1742 isOk = Standard_False;
1744 if (ToSetMaterial == 1
1745 && Material == Graphic3d_NOM_DEFAULT)
1747 std::cout << "Error: unknown material " << MatName << ".\n";
1748 isOk = Standard_False;
1750 if (FreeBoundaryWidth <= 0.0
1751 || FreeBoundaryWidth > 10.0)
1753 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1754 isOk = Standard_False;
1756 if (MaxParamValue < 0.0)
1758 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1759 isOk = Standard_False;
1761 if (Sensitivity <= 0 && ToSetSensitivity)
1763 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1764 isOk = Standard_False;
1766 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1768 std::cout << "Error: hatch style must be specified\n";
1769 isOk = Standard_False;
1771 if (ToSetShadingModel == 1
1772 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
1774 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1775 isOk = Standard_False;
1782 //==============================================================================
1783 //function : VAspects
1785 //==============================================================================
1786 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1787 Standard_Integer theArgNb,
1788 const char** theArgVec)
1790 TCollection_AsciiString aCmdName (theArgVec[0]);
1791 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1792 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1795 std::cerr << "Error: no active view!\n";
1799 Standard_Integer anArgIter = 1;
1800 Standard_Boolean isDefaults = Standard_False;
1801 NCollection_Sequence<TCollection_AsciiString> aNames;
1802 for (; anArgIter < theArgNb; ++anArgIter)
1804 TCollection_AsciiString anArg = theArgVec[anArgIter];
1805 if (anUpdateTool.parseRedrawMode (anArg))
1809 else if (!anArg.IsEmpty()
1810 && anArg.Value (1) != '-')
1812 aNames.Append (anArg);
1816 if (anArg == "-defaults")
1818 isDefaults = Standard_True;
1825 if (!aNames.IsEmpty() && isDefaults)
1827 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1831 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1832 aChanges.Append (ViewerTest_AspectsChangeSet());
1833 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1835 // parse syntax of legacy commands
1836 if (aCmdName == "vsetwidth")
1838 if (aNames.IsEmpty()
1839 || !aNames.Last().IsRealValue())
1841 std::cout << "Error: not enough arguments!\n";
1844 aChangeSet->ToSetLineWidth = 1;
1845 aChangeSet->LineWidth = aNames.Last().RealValue();
1846 aNames.Remove (aNames.Length());
1848 else if (aCmdName == "vunsetwidth")
1850 aChangeSet->ToSetLineWidth = -1;
1852 else if (aCmdName == "vsetcolor")
1854 if (aNames.IsEmpty())
1856 std::cout << "Error: not enough arguments!\n";
1859 aChangeSet->ToSetColor = 1;
1861 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1862 Standard_Boolean isOk = Standard_False;
1863 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1865 aChangeSet->Color = aColor;
1866 aNames.Remove (aNames.Length());
1867 isOk = Standard_True;
1869 else if (aNames.Length() >= 3)
1871 const TCollection_AsciiString anRgbStr[3] =
1873 aNames.Value (aNames.Upper() - 2),
1874 aNames.Value (aNames.Upper() - 1),
1875 aNames.Value (aNames.Upper() - 0)
1877 isOk = anRgbStr[0].IsRealValue()
1878 && anRgbStr[1].IsRealValue()
1879 && anRgbStr[2].IsRealValue();
1882 Graphic3d_Vec4d anRgb;
1883 anRgb.x() = anRgbStr[0].RealValue();
1884 anRgb.y() = anRgbStr[1].RealValue();
1885 anRgb.z() = anRgbStr[2].RealValue();
1886 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1887 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1888 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1890 std::cout << "Error: RGB color values should be within range 0..1!\n";
1893 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1894 aNames.Remove (aNames.Length());
1895 aNames.Remove (aNames.Length());
1896 aNames.Remove (aNames.Length());
1901 std::cout << "Error: not enough arguments!\n";
1905 else if (aCmdName == "vunsetcolor")
1907 aChangeSet->ToSetColor = -1;
1909 else if (aCmdName == "vsettransparency")
1911 if (aNames.IsEmpty()
1912 || !aNames.Last().IsRealValue())
1914 std::cout << "Error: not enough arguments!\n";
1917 aChangeSet->ToSetTransparency = 1;
1918 aChangeSet->Transparency = aNames.Last().RealValue();
1919 aNames.Remove (aNames.Length());
1921 else if (aCmdName == "vunsettransparency")
1923 aChangeSet->ToSetTransparency = -1;
1925 else if (aCmdName == "vsetmaterial")
1927 if (aNames.IsEmpty())
1929 std::cout << "Error: not enough arguments!\n";
1932 aChangeSet->ToSetMaterial = 1;
1933 aChangeSet->MatName = aNames.Last();
1934 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1935 aNames.Remove (aNames.Length());
1937 else if (aCmdName == "vunsetmaterial")
1939 aChangeSet->ToSetMaterial = -1;
1941 else if (anArgIter >= theArgNb)
1943 std::cout << "Error: not enough arguments!\n";
1947 if (!aChangeSet->IsEmpty())
1949 anArgIter = theArgNb;
1951 for (; anArgIter < theArgNb; ++anArgIter)
1953 TCollection_AsciiString anArg = theArgVec[anArgIter];
1955 if (anArg == "-setwidth"
1956 || anArg == "-setlinewidth")
1958 if (++anArgIter >= theArgNb)
1960 std::cout << "Error: wrong syntax at " << anArg << "\n";
1963 aChangeSet->ToSetLineWidth = 1;
1964 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1966 else if (anArg == "-unsetwidth"
1967 || anArg == "-unsetlinewidth")
1969 aChangeSet->ToSetLineWidth = -1;
1970 aChangeSet->LineWidth = 1.0;
1972 else if (anArg == "-settransp"
1973 || anArg == "-settransparency")
1975 if (++anArgIter >= theArgNb)
1977 std::cout << "Error: wrong syntax at " << anArg << "\n";
1980 aChangeSet->ToSetTransparency = 1;
1981 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1982 if (aChangeSet->Transparency >= 0.0
1983 && aChangeSet->Transparency <= Precision::Confusion())
1985 aChangeSet->ToSetTransparency = -1;
1986 aChangeSet->Transparency = 0.0;
1989 else if (anArg == "-setalphamode")
1991 if (++anArgIter >= theArgNb)
1993 std::cout << "Error: wrong syntax at " << anArg << "\n";
1996 aChangeSet->ToSetAlphaMode = 1;
1997 aChangeSet->AlphaCutoff = 0.5f;
1999 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2001 if (aParam == "opaque")
2003 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2005 else if (aParam == "mask")
2007 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2009 else if (aParam == "blend")
2011 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2013 else if (aParam == "blendauto"
2014 || aParam == "auto")
2016 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2020 std::cout << "Error: wrong syntax at " << aParam << "\n";
2025 if (anArgIter + 1 < theArgNb
2026 && theArgVec[anArgIter + 1][0] != '-')
2028 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2029 if (aParam2.IsRealValue())
2031 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2036 else if (anArg == "-setvis"
2037 || anArg == "-setvisibility")
2039 if (++anArgIter >= theArgNb)
2041 std::cout << "Error: wrong syntax at " << anArg << "\n";
2045 aChangeSet->ToSetVisibility = 1;
2046 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2048 else if (anArg == "-setalpha")
2050 if (++anArgIter >= theArgNb)
2052 std::cout << "Error: wrong syntax at " << anArg << "\n";
2055 aChangeSet->ToSetTransparency = 1;
2056 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2057 if (aChangeSet->Transparency < 0.0
2058 || aChangeSet->Transparency > 1.0)
2060 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2063 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2064 if (aChangeSet->Transparency >= 0.0
2065 && aChangeSet->Transparency <= Precision::Confusion())
2067 aChangeSet->ToSetTransparency = -1;
2068 aChangeSet->Transparency = 0.0;
2071 else if (anArg == "-unsettransp"
2072 || anArg == "-unsettransparency"
2073 || anArg == "-unsetalpha"
2074 || anArg == "-opaque")
2076 aChangeSet->ToSetTransparency = -1;
2077 aChangeSet->Transparency = 0.0;
2079 else if (anArg == "-setcolor")
2081 Standard_Integer aNbComps = 0;
2082 Standard_Integer aCompIter = anArgIter + 1;
2083 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2085 if (theArgVec[aCompIter][0] == '-')
2094 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2095 Standard_CString aName = theArgVec[anArgIter + 1];
2096 if (!Quantity_Color::ColorFromName (aName, aColor))
2098 std::cout << "Error: unknown color name '" << aName << "'\n";
2101 aChangeSet->Color = aColor;
2106 Graphic3d_Vec3d anRgb;
2107 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2108 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2109 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2110 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2111 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2112 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2114 std::cout << "Error: RGB color values should be within range 0..1!\n";
2117 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2122 std::cout << "Error: wrong syntax at " << anArg << "\n";
2126 aChangeSet->ToSetColor = 1;
2127 anArgIter += aNbComps;
2129 else if (anArg == "-setlinetype")
2131 if (++anArgIter >= theArgNb)
2133 std::cout << "Error: wrong syntax at " << anArg << "\n";
2136 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aChangeSet->TypeOfLine))
2138 std::cout << "Error: wrong syntax at " << anArg << "\n";
2142 aChangeSet->ToSetTypeOfLine = 1;
2144 else if (anArg == "-unsetlinetype")
2146 aChangeSet->ToSetTypeOfLine = -1;
2148 else if (anArg == "-setmarkertype"
2149 || anArg == "-setpointtype")
2151 if (++anArgIter >= theArgNb)
2153 std::cout << "Error: wrong syntax at " << anArg << "\n";
2156 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2158 std::cout << "Error: wrong syntax at " << anArg << "\n";
2162 aChangeSet->ToSetTypeOfMarker = 1;
2164 else if (anArg == "-unsetmarkertype"
2165 || anArg == "-unsetpointtype")
2167 aChangeSet->ToSetTypeOfMarker = -1;
2169 else if (anArg == "-setmarkersize"
2170 || anArg == "-setpointsize")
2172 if (++anArgIter >= theArgNb)
2174 std::cout << "Error: wrong syntax at " << anArg << "\n";
2177 aChangeSet->ToSetMarkerSize = 1;
2178 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2180 else if (anArg == "-unsetmarkersize"
2181 || anArg == "-unsetpointsize")
2183 aChangeSet->ToSetMarkerSize = -1;
2184 aChangeSet->MarkerSize = 1.0;
2186 else if (anArg == "-unsetcolor")
2188 aChangeSet->ToSetColor = -1;
2189 aChangeSet->Color = DEFAULT_COLOR;
2191 else if (anArg == "-setmat"
2192 || anArg == "-setmaterial")
2194 if (++anArgIter >= theArgNb)
2196 std::cout << "Error: wrong syntax at " << anArg << "\n";
2199 aChangeSet->ToSetMaterial = 1;
2200 aChangeSet->MatName = theArgVec[anArgIter];
2201 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2203 else if (anArg == "-unsetmat"
2204 || anArg == "-unsetmaterial")
2206 aChangeSet->ToSetMaterial = -1;
2207 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2209 else if (anArg == "-subshape"
2210 || anArg == "-subshapes")
2214 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2218 if (aNames.IsEmpty())
2220 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2224 aChanges.Append (ViewerTest_AspectsChangeSet());
2225 aChangeSet = &aChanges.ChangeLast();
2227 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2229 Standard_CString aSubShapeName = theArgVec[anArgIter];
2230 if (*aSubShapeName == '-')
2236 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2237 if (aSubShape.IsNull())
2239 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2242 aChangeSet->SubShapes.Append (aSubShape);
2245 if (aChangeSet->SubShapes.IsEmpty())
2247 std::cerr << "Error: empty list is specified after -subshapes!\n";
2251 else if (anArg == "-freeboundary"
2254 if (++anArgIter >= theArgNb)
2256 std::cout << "Error: wrong syntax at " << anArg << "\n";
2259 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2264 aChangeSet->ToSetShowFreeBoundary = 1;
2266 else if (aValue == "off"
2269 aChangeSet->ToSetShowFreeBoundary = -1;
2273 std::cout << "Error: wrong syntax at " << anArg << "\n";
2277 else if (anArg == "-setfreeboundarywidth"
2278 || anArg == "-setfbwidth")
2280 if (++anArgIter >= theArgNb)
2282 std::cout << "Error: wrong syntax at " << anArg << "\n";
2285 aChangeSet->ToSetFreeBoundaryWidth = 1;
2286 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2288 else if (anArg == "-unsetfreeboundarywidth"
2289 || anArg == "-unsetfbwidth")
2291 aChangeSet->ToSetFreeBoundaryWidth = -1;
2292 aChangeSet->FreeBoundaryWidth = 1.0;
2294 else if (anArg == "-setfreeboundarycolor"
2295 || anArg == "-setfbcolor")
2297 Standard_Integer aNbComps = 0;
2298 Standard_Integer aCompIter = anArgIter + 1;
2299 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2301 if (theArgVec[aCompIter][0] == '-')
2310 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2311 Standard_CString aName = theArgVec[anArgIter + 1];
2312 if (!Quantity_Color::ColorFromName (aName, aColor))
2314 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2317 aChangeSet->FreeBoundaryColor = aColor;
2322 Graphic3d_Vec3d anRgb;
2323 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2324 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2325 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2326 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2327 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2328 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2330 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2333 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2338 std::cout << "Error: wrong syntax at " << anArg << "\n";
2342 aChangeSet->ToSetFreeBoundaryColor = 1;
2343 anArgIter += aNbComps;
2345 else if (anArg == "-unsetfreeboundarycolor"
2346 || anArg == "-unsetfbcolor")
2348 aChangeSet->ToSetFreeBoundaryColor = -1;
2349 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2351 else if (anArg == "-unset")
2353 aChangeSet->ToSetVisibility = 1;
2354 aChangeSet->Visibility = 1;
2355 aChangeSet->ToSetLineWidth = -1;
2356 aChangeSet->LineWidth = 1.0;
2357 aChangeSet->ToSetTypeOfLine = -1;
2358 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2359 aChangeSet->ToSetTypeOfMarker = -1;
2360 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
2361 aChangeSet->ToSetMarkerSize = -1;
2362 aChangeSet->MarkerSize = 1.0;
2363 aChangeSet->ToSetTransparency = -1;
2364 aChangeSet->Transparency = 0.0;
2365 aChangeSet->ToSetAlphaMode = -1;
2366 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2367 aChangeSet->AlphaCutoff = 0.5f;
2368 aChangeSet->ToSetColor = -1;
2369 aChangeSet->Color = DEFAULT_COLOR;
2370 aChangeSet->ToSetMaterial = -1;
2371 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2372 aChangeSet->ToSetShowFreeBoundary = -1;
2373 aChangeSet->ToSetFreeBoundaryColor = -1;
2374 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2375 aChangeSet->ToSetFreeBoundaryWidth = -1;
2376 aChangeSet->FreeBoundaryWidth = 1.0;
2377 aChangeSet->ToSetHatch = -1;
2378 aChangeSet->StdHatchStyle = -1;
2379 aChangeSet->PathToHatchPattern.Clear();
2380 aChangeSet->ToSetShadingModel = -1;
2381 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2383 else if (anArg == "-isoontriangulation"
2384 || anArg == "-isoontriang")
2386 if (++anArgIter >= theArgNb)
2388 std::cout << "Error: wrong syntax at " << anArg << "\n";
2391 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2396 aChangeSet->ToEnableIsoOnTriangulation = 1;
2398 else if (aValue == "off"
2401 aChangeSet->ToEnableIsoOnTriangulation = 0;
2405 std::cout << "Error: wrong syntax at " << anArg << "\n";
2409 else if (anArg == "-setmaxparamvalue")
2411 if (++anArgIter >= theArgNb)
2413 std::cout << "Error: wrong syntax at " << anArg << "\n";
2416 aChangeSet->ToSetMaxParamValue = 1;
2417 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2419 else if (anArg == "-setsensitivity")
2423 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2427 if (aNames.IsEmpty())
2429 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2433 if (anArgIter + 2 >= theArgNb)
2435 std::cout << "Error: wrong syntax at " << anArg << "\n";
2438 aChangeSet->ToSetSensitivity = 1;
2439 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2440 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2442 else if (anArg == "-sethatch")
2446 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2450 if (aNames.IsEmpty())
2452 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2456 aChangeSet->ToSetHatch = 1;
2457 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
2458 if (anArgHatch.Length() <= 2)
2460 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
2462 || anIntStyle >= Aspect_HS_NB)
2464 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
2467 aChangeSet->StdHatchStyle = anIntStyle;
2471 aChangeSet->PathToHatchPattern = anArgHatch;
2474 else if (anArg == "-setshadingmodel")
2476 if (++anArgIter >= theArgNb)
2478 std::cout << "Error: wrong syntax at " << anArg << "\n";
2481 aChangeSet->ToSetShadingModel = 1;
2482 aChangeSet->ShadingModelName = theArgVec[anArgIter];
2483 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
2485 std::cout << "Error: wrong syntax at " << anArg << "\n";
2489 else if (anArg == "-unsetshadingmodel")
2491 aChangeSet->ToSetShadingModel = -1;
2492 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2496 std::cout << "Error: wrong syntax at " << anArg << "\n";
2501 Standard_Boolean isFirst = Standard_True;
2502 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2503 aChangesIter.More(); aChangesIter.Next())
2505 if (!aChangesIter.Value().Validate (!isFirst))
2509 isFirst = Standard_False;
2512 // special case for -defaults parameter.
2513 // all changed values will be set to DefaultDrawer.
2516 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2518 if (aChangeSet->ToSetLineWidth != 0)
2520 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2521 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2522 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2523 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2525 if (aChangeSet->ToSetColor != 0)
2527 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2528 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2529 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2530 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2531 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2532 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2534 if (aChangeSet->ToSetTypeOfLine != 0)
2536 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2537 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2538 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2539 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2540 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2542 if (aChangeSet->ToSetTypeOfMarker != 0)
2544 aDrawer->PointAspect()->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2545 aDrawer->PointAspect()->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2546 ? Handle(Graphic3d_MarkerImage)()
2547 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2549 if (aChangeSet->ToSetMarkerSize != 0)
2551 aDrawer->PointAspect()->SetScale (aChangeSet->MarkerSize);
2553 if (aChangeSet->ToSetTransparency != 0)
2555 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2557 if (aChangeSet->ToSetAlphaMode != 0)
2559 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2561 if (aChangeSet->ToSetMaterial != 0)
2563 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2565 if (aChangeSet->ToSetShowFreeBoundary == 1)
2567 aDrawer->SetFreeBoundaryDraw (Standard_True);
2569 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2571 aDrawer->SetFreeBoundaryDraw (Standard_False);
2573 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2575 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2577 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2579 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2581 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2583 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2585 if (aChangeSet->ToSetMaxParamValue != 0)
2587 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2589 if (aChangeSet->ToSetShadingModel == 1)
2591 aDrawer->ShadingAspect()->Aspect()->SetShadingModel (aChangeSet->ShadingModel);
2594 // redisplay all objects in context
2595 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2597 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2600 aCtx->Redisplay (aPrs, Standard_False);
2606 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2608 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2609 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2615 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2616 Handle(AIS_ColoredShape) aColoredPrs;
2617 Standard_Boolean toDisplay = Standard_False;
2618 Standard_Boolean toRedisplay = Standard_False;
2619 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2621 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2622 if (aShapePrs.IsNull())
2624 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2627 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2628 if (aColoredPrs.IsNull())
2630 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2631 if (aShapePrs->HasDisplayMode())
2633 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2635 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2636 aCtx->Remove (aShapePrs, Standard_False);
2637 GetMapOfAIS().UnBind2 (aName);
2638 GetMapOfAIS().Bind (aColoredPrs, aName);
2639 toDisplay = Standard_True;
2640 aShapePrs = aColoredPrs;
2647 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2648 aChangeSet = &aChangesIter.ChangeValue();
2649 if (aChangeSet->ToSetVisibility == 1)
2651 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2652 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2654 else if (aChangeSet->ToSetMaterial == 1)
2656 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2658 else if (aChangeSet->ToSetMaterial == -1)
2660 aCtx->UnsetMaterial (aPrs, Standard_False);
2662 if (aChangeSet->ToSetColor == 1)
2664 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2666 else if (aChangeSet->ToSetColor == -1)
2668 aCtx->UnsetColor (aPrs, Standard_False);
2670 if (aChangeSet->ToSetTransparency == 1)
2672 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2674 else if (aChangeSet->ToSetTransparency == -1)
2676 aCtx->UnsetTransparency (aPrs, Standard_False);
2678 if (aChangeSet->ToSetLineWidth == 1)
2680 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2682 else if (aChangeSet->ToSetLineWidth == -1)
2684 aCtx->UnsetWidth (aPrs, Standard_False);
2686 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2688 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2689 toRedisplay = Standard_True;
2691 else if (aChangeSet->ToSetSensitivity != 0)
2693 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2695 if (!aDrawer.IsNull())
2697 if (aChangeSet->ToSetShowFreeBoundary == 1)
2699 aDrawer->SetFreeBoundaryDraw (Standard_True);
2700 toRedisplay = Standard_True;
2702 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2704 aDrawer->SetFreeBoundaryDraw (Standard_False);
2705 toRedisplay = Standard_True;
2707 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2709 Handle(Prs3d_LineAspect) aBoundaryAspect =
2710 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2711 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2712 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2713 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2714 toRedisplay = Standard_True;
2716 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2718 Handle(Prs3d_LineAspect) aBoundaryAspect =
2719 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2720 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2721 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2722 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2723 toRedisplay = Standard_True;
2725 if (aChangeSet->ToSetTypeOfLine != 0)
2727 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2728 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2729 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2730 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2731 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2732 toRedisplay = Standard_True;
2734 if (aChangeSet->ToSetTypeOfMarker != 0)
2736 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2737 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2738 aMarkerAspect->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2739 aMarkerAspect->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2740 ? Handle(Graphic3d_MarkerImage)()
2741 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2742 aDrawer->SetPointAspect (aMarkerAspect);
2743 toRedisplay = Standard_True;
2745 if (aChangeSet->ToSetMarkerSize != 0)
2747 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2748 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2749 aMarkerAspect->SetScale (aChangeSet->MarkerSize);
2750 aDrawer->SetPointAspect (aMarkerAspect);
2751 toRedisplay = Standard_True;
2753 if (aChangeSet->ToSetMaxParamValue != 0)
2755 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2757 if (aChangeSet->ToSetHatch != 0)
2759 if (!aDrawer->HasOwnShadingAspect())
2761 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2762 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2765 Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
2766 if (aChangeSet->ToSetHatch == -1)
2768 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2772 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2773 if (!aChangeSet->PathToHatchPattern.IsEmpty())
2775 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2776 if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
2778 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2782 std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
2786 else if (aChangeSet->StdHatchStyle != -1)
2788 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
2791 toRedisplay = Standard_True;
2793 if (aChangeSet->ToSetShadingModel != 0)
2795 aDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2796 toRedisplay = Standard_True;
2798 if (aChangeSet->ToSetAlphaMode != 0)
2800 if (!aDrawer->HasOwnShadingAspect())
2802 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2803 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2805 aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
2806 toRedisplay = Standard_True;
2810 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2812 aChangeSet = &aChangesIter.ChangeValue();
2813 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2814 aSubShapeIter.More(); aSubShapeIter.Next())
2816 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2817 if (aChangeSet->ToSetVisibility == 1)
2819 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2820 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2822 if (aChangeSet->ToSetColor == 1)
2824 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2826 if (aChangeSet->ToSetLineWidth == 1)
2828 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2830 if (aChangeSet->ToSetColor == -1
2831 || aChangeSet->ToSetLineWidth == -1)
2833 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2835 if (aChangeSet->ToSetMaxParamValue != 0)
2837 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2838 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2840 if (aChangeSet->ToSetSensitivity != 0)
2842 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2844 if (aChangeSet->ToSetShadingModel != 0)
2846 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2847 aCurColDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
2853 aCtx->Display (aPrs, Standard_False);
2857 aCtx->Redisplay (aPrs, Standard_False);
2859 else if (!aColoredPrs.IsNull())
2861 aCtx->Redisplay (aColoredPrs, Standard_False);
2868 //==============================================================================
2869 //function : VDonly2
2871 //purpose : Display only a selected or named object
2872 // if there is no selected or named object s, nothing is done
2873 //==============================================================================
2874 static int VDonly2 (Draw_Interpretor& ,
2875 Standard_Integer theArgNb,
2876 const char** theArgVec)
2878 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2879 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2882 std::cerr << "Error: no active view!\n";
2886 Standard_Integer anArgIter = 1;
2887 for (; anArgIter < theArgNb; ++anArgIter)
2889 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2895 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2896 if (anArgIter >= theArgNb)
2898 // display only selected objects
2899 if (aCtx->NbSelected() < 1)
2904 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2906 aDispSet.Add (aCtx->SelectedInteractive());
2911 // display only specified objects
2912 for (; anArgIter < theArgNb; ++anArgIter)
2914 TCollection_AsciiString aName = theArgVec[anArgIter];
2915 Handle(AIS_InteractiveObject) aShape;
2916 if (GetMapOfAIS().Find2 (aName, aShape)
2917 && !aShape.IsNull())
2919 aCtx->Display (aShape, Standard_False);
2920 aDispSet.Add (aShape);
2925 // weed out other objects
2926 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2928 if (aDispSet.Contains (anIter.Key1()))
2933 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
2935 aCtx->Erase (aShape, Standard_False);
2941 //==============================================================================
2942 //function : VRemove
2943 //purpose : Removes selected or named objects.
2944 // If there is no selected or named objects,
2945 // all objects in the viewer can be removed with argument -all.
2946 // If -context is in arguments, the object is not deleted from the map of
2947 // objects (deleted only from the current context).
2948 //==============================================================================
2949 int VRemove (Draw_Interpretor& theDI,
2950 Standard_Integer theArgNb,
2951 const char** theArgVec)
2953 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2954 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2957 std::cerr << "Error: no active view!\n";
2961 Standard_Boolean isContextOnly = Standard_False;
2962 Standard_Boolean toRemoveAll = Standard_False;
2963 Standard_Boolean toPrintInfo = Standard_True;
2965 Standard_Integer anArgIter = 1;
2966 for (; anArgIter < theArgNb; ++anArgIter)
2968 TCollection_AsciiString anArg = theArgVec[anArgIter];
2970 if (anArg == "-context")
2972 isContextOnly = Standard_True;
2974 else if (anArg == "-all")
2976 toRemoveAll = Standard_True;
2978 else if (anArg == "-noinfo")
2980 toPrintInfo = Standard_False;
2982 else if (anUpdateTool.parseRedrawMode (anArg))
2992 && anArgIter < theArgNb)
2994 std::cerr << "Error: wrong syntax!\n";
2998 NCollection_List<TCollection_AsciiString> anIONameList;
3001 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3002 anIter.More(); anIter.Next())
3004 anIONameList.Append (anIter.Key2());
3007 else if (anArgIter < theArgNb) // removed objects names are in argument list
3009 for (; anArgIter < theArgNb; ++anArgIter)
3011 TCollection_AsciiString aName = theArgVec[anArgIter];
3012 Handle(AIS_InteractiveObject) anIO;
3013 if (!GetMapOfAIS().Find2 (aName, anIO))
3015 theDI << aName << " was not bound to some object.\n";
3019 if (anIO->GetContext() != aCtx)
3021 theDI << aName << " was not displayed in current context.\n";
3022 theDI << "Please activate view with this object displayed and try again.\n";
3026 anIONameList.Append (aName);
3030 else if (aCtx->NbSelected() > 0)
3032 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3033 anIter.More(); anIter.Next())
3035 if (!aCtx->IsSelected (anIter.Key1()))
3040 anIONameList.Append (anIter.Key2());
3045 // Unbind all removed objects from the map of displayed IO.
3046 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3047 anIter.More(); anIter.Next())
3049 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
3050 aCtx->Remove (anIO, Standard_False);
3053 theDI << anIter.Value() << " was removed\n";
3057 GetMapOfAIS().UnBind2 (anIter.Value());
3063 //==============================================================================
3065 //purpose : Erase some selected or named objects
3066 // if there is no selected or named objects, the whole viewer is erased
3067 //==============================================================================
3068 int VErase (Draw_Interpretor& theDI,
3069 Standard_Integer theArgNb,
3070 const char** theArgVec)
3072 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3073 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3074 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3077 std::cerr << "Error: no active view!\n";
3081 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3083 Standard_Integer anArgIter = 1;
3084 Standard_Boolean toEraseInView = Standard_False;
3085 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3086 for (; anArgIter < theArgNb; ++anArgIter)
3088 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3089 anArgCase.LowerCase();
3090 if (anUpdateTool.parseRedrawMode (anArgCase))
3094 else if (anArgCase == "-view"
3095 || anArgCase == "-inview")
3097 toEraseInView = Standard_True;
3101 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3105 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3107 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3111 if (!aNamesOfEraseIO.IsEmpty())
3113 // Erase named objects
3114 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
3116 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
3117 Handle(AIS_InteractiveObject) anIO;
3118 if (!GetMapOfAIS().Find2 (aName, anIO))
3123 theDI << aName << " ";
3128 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3132 aCtx->Erase (anIO, Standard_False);
3137 else if (!toEraseAll && aCtx->NbSelected() > 0)
3139 // Erase selected objects
3140 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3141 anIter.More(); anIter.Next())
3143 const Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3145 && aCtx->IsSelected (anIO))
3147 theDI << anIter.Key2() << " ";
3150 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3157 aCtx->EraseSelected (Standard_False);
3162 // Erase all objects
3163 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3164 anIter.More(); anIter.Next())
3166 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3171 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3175 aCtx->Erase (anIO, Standard_False);
3184 //==============================================================================
3185 //function : VDisplayAll
3186 //purpose : Display all the objects of the Map
3187 //==============================================================================
3188 static int VDisplayAll (Draw_Interpretor& ,
3189 Standard_Integer theArgNb,
3190 const char** theArgVec)
3193 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3194 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3197 std::cerr << "Error: no active view!\n";
3201 Standard_Integer anArgIter = 1;
3202 for (; anArgIter < theArgNb; ++anArgIter)
3204 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3205 anArgCase.LowerCase();
3206 if (anUpdateTool.parseRedrawMode (anArgCase))
3215 if (anArgIter < theArgNb)
3217 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3221 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3222 anIter.More(); anIter.Next())
3224 aCtx->Erase (anIter.Key1(), Standard_False);
3227 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3228 anIter.More(); anIter.Next())
3230 aCtx->Display (anIter.Key1(), Standard_False);
3235 //! Auxiliary method to check if presentation exists
3236 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3237 const Handle(AIS_InteractiveObject)& theIO,
3238 const Standard_Integer theMode)
3240 if (theIO.IsNull() || theCtx.IsNull())
3247 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3252 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3254 return theIO->DisplayMode();
3256 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3258 return theCtx->DisplayMode();
3264 enum ViewerTest_BndAction
3271 //! Auxiliary method to print bounding box of presentation
3272 inline void bndPresentation (Draw_Interpretor& theDI,
3273 const Handle(PrsMgr_PresentationManager)& theMgr,
3274 const Handle(AIS_InteractiveObject)& theObj,
3275 const Standard_Integer theDispMode,
3276 const TCollection_AsciiString& theName,
3277 const ViewerTest_BndAction theAction,
3278 const Handle(Prs3d_Drawer)& theStyle)
3282 case BndAction_Hide:
3284 theMgr->Unhighlight (theObj);
3287 case BndAction_Show:
3289 theMgr->Color (theObj, theStyle, theDispMode);
3292 case BndAction_Print:
3295 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3297 if (aPrsIter.Value().Mode() != theDispMode)
3300 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3302 gp_Pnt aMin = aBox.CornerMin();
3303 gp_Pnt aMax = aBox.CornerMax();
3304 theDI << theName << "\n"
3305 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3306 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
3312 //==============================================================================
3313 //function : VBounding
3315 //==============================================================================
3316 int VBounding (Draw_Interpretor& theDI,
3317 Standard_Integer theArgNb,
3318 const char** theArgVec)
3320 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3321 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3324 std::cout << "Error: no active view!\n";
3328 ViewerTest_BndAction anAction = BndAction_Show;
3329 Standard_Integer aMode = -1;
3331 Handle(Prs3d_Drawer) aStyle;
3333 Standard_Integer anArgIter = 1;
3334 for (; anArgIter < theArgNb; ++anArgIter)
3336 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3338 if (anArg == "-print")
3340 anAction = BndAction_Print;
3342 else if (anArg == "-show")
3344 anAction = BndAction_Show;
3346 else if (anArg == "-hide")
3348 anAction = BndAction_Hide;
3350 else if (anArg == "-mode")
3352 if (++anArgIter >= theArgNb)
3354 std::cout << "Error: wrong syntax at " << anArg << "\n";
3357 aMode = Draw::Atoi (theArgVec[anArgIter]);
3359 else if (!anUpdateTool.parseRedrawMode (anArg))
3365 if (anAction == BndAction_Show)
3367 aStyle = new Prs3d_Drawer();
3368 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3369 aStyle->SetColor (Quantity_NOC_GRAY99);
3372 Standard_Integer aHighlightedMode = -1;
3373 if (anArgIter < theArgNb)
3375 // has a list of names
3376 for (; anArgIter < theArgNb; ++anArgIter)
3378 TCollection_AsciiString aName = theArgVec[anArgIter];
3379 Handle(AIS_InteractiveObject) anIO;
3380 if (!GetMapOfAIS().Find2 (aName, anIO))
3382 std::cout << "Error: presentation " << aName << " does not exist\n";
3386 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3387 if (aHighlightedMode == -1)
3389 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3392 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3395 else if (aCtx->NbSelected() > 0)
3397 // remove all currently selected objects
3398 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3400 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3401 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3402 if (aHighlightedMode != -1)
3404 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3405 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3412 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3413 anIter.More(); anIter.Next())
3415 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
3416 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3417 if (aHighlightedMode != -1)
3419 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3426 //==============================================================================
3427 //function : VTexture
3429 //==============================================================================
3430 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
3432 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3435 std::cout << "Error: no active view!\n";
3439 int toModulate = -1;
3440 bool toSetFilter = false;
3441 bool toSetAniso = false;
3442 bool toSetTrsfAngle = false;
3443 bool toSetTrsfTrans = false;
3444 bool toSetTrsfScale = false;
3445 Standard_ShortReal aTrsfRotAngle = 0.0f;
3446 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
3447 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
3448 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
3449 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
3451 Handle(AIS_InteractiveObject) aTexturedIO;
3452 Handle(AIS_Shape) aTexturedShape;
3453 Handle(Graphic3d_TextureSet) aTextureSetOld;
3454 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
3455 bool toSetGenRepeat = false;
3456 bool toSetGenScale = false;
3457 bool toSetGenOrigin = false;
3458 bool toSetImage = false;
3459 bool toComputeUV = false;
3461 const TCollection_AsciiString aCommandName (theArgVec[0]);
3462 bool toSetDefaults = aCommandName == "vtexdefault";
3464 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3465 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
3467 const TCollection_AsciiString aName = theArgVec[anArgIter];
3468 TCollection_AsciiString aNameCase = aName;
3469 aNameCase.LowerCase();
3470 if (anUpdateTool.parseRedrawMode (aName))
3474 else if (aTexturedIO.IsNull())
3476 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3477 if (aMapOfIO.IsBound2 (aName))
3479 aTexturedIO = aMapOfIO.Find2 (aName);
3480 aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO);
3482 if (aTexturedIO.IsNull())
3484 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
3488 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
3490 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
3493 else if (!aTexturedShape.IsNull()
3494 && (aNameCase == "-scale"
3495 || aNameCase == "-setscale"
3496 || aCommandName == "vtexscale"))
3498 if (aCommandName != "vtexscale")
3502 if (anArgIter < theArgsNb)
3504 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3505 TCollection_AsciiString aValUCase = aValU;
3506 aValUCase.LowerCase();
3507 toSetGenScale = true;
3508 if (aValUCase == "off")
3510 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3513 else if (anArgIter + 1 < theArgsNb)
3515 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3516 if (aValU.IsRealValue()
3517 && aValV.IsRealValue())
3519 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3525 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3528 else if (!aTexturedShape.IsNull()
3529 && (aNameCase == "-origin"
3530 || aNameCase == "-setorigin"
3531 || aCommandName == "vtexorigin"))
3533 if (aCommandName != "vtexorigin")
3537 if (anArgIter < theArgsNb)
3539 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3540 TCollection_AsciiString aValUCase = aValU;
3541 aValUCase.LowerCase();
3542 toSetGenOrigin = true;
3543 if (aValUCase == "off")
3545 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3548 else if (anArgIter + 1 < theArgsNb)
3550 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3551 if (aValU.IsRealValue()
3552 && aValV.IsRealValue())
3554 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3560 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3563 else if (!aTexturedShape.IsNull()
3564 && (aNameCase == "-repeat"
3565 || aNameCase == "-setrepeat"
3566 || aCommandName == "vtexrepeat"))
3568 if (aCommandName != "vtexrepeat")
3572 if (anArgIter < theArgsNb)
3574 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3575 TCollection_AsciiString aValUCase = aValU;
3576 aValUCase.LowerCase();
3577 toSetGenRepeat = true;
3578 if (aValUCase == "off")
3580 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3583 else if (anArgIter + 1 < theArgsNb)
3585 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3586 if (aValU.IsRealValue()
3587 && aValV.IsRealValue())
3589 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3595 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3598 else if (aNameCase == "-modulate")
3600 bool toModulateBool = true;
3601 if (anArgIter + 1 < theArgsNb
3602 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
3606 toModulate = toModulateBool ? 1 : 0;
3608 else if ((aNameCase == "-setfilter"
3609 || aNameCase == "-filter")
3610 && anArgIter + 1 < theArgsNb)
3612 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3616 if (aValue == "nearest")
3618 aFilter = Graphic3d_TOTF_NEAREST;
3620 else if (aValue == "bilinear")
3622 aFilter = Graphic3d_TOTF_BILINEAR;
3624 else if (aValue == "trilinear")
3626 aFilter = Graphic3d_TOTF_TRILINEAR;
3630 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3634 else if ((aNameCase == "-setaniso"
3635 || aNameCase == "-setanisofilter"
3636 || aNameCase == "-aniso"
3637 || aNameCase == "-anisofilter")
3638 && anArgIter + 1 < theArgsNb)
3640 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3644 if (aValue == "off")
3646 anAnisoFilter = Graphic3d_LOTA_OFF;
3648 else if (aValue == "fast")
3650 anAnisoFilter = Graphic3d_LOTA_FAST;
3652 else if (aValue == "middle")
3654 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
3656 else if (aValue == "quality"
3657 || aValue == "high")
3659 anAnisoFilter = Graphic3d_LOTA_QUALITY;
3663 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3667 else if ((aNameCase == "-rotateangle"
3668 || aNameCase == "-rotangle"
3669 || aNameCase == "-rotate"
3670 || aNameCase == "-angle"
3671 || aNameCase == "-trsfangle")
3672 && anArgIter + 1 < theArgsNb)
3674 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3675 toSetTrsfAngle = true;
3678 else if ((aNameCase == "-trsftrans"
3679 || aNameCase == "-trsftranslate"
3680 || aNameCase == "-translate"
3681 || aNameCase == "-translation")
3682 && anArgIter + 2 < theArgsNb)
3684 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3685 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3686 toSetTrsfTrans = true;
3689 else if ((aNameCase == "-trsfscale")
3690 && anArgIter + 2 < theArgsNb)
3692 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3693 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3694 toSetTrsfScale = true;
3697 else if (aNameCase == "-default"
3698 || aNameCase == "-defaults")
3700 toSetDefaults = true;
3702 else if (aCommandName == "vtexture"
3703 && (aTextureVecNew.IsEmpty()
3704 || aNameCase.StartsWith ("-tex")))
3706 Standard_Integer aTexIndex = 0;
3707 TCollection_AsciiString aTexName = aName;
3708 if (aNameCase.StartsWith ("-tex"))
3710 if (anArgIter + 1 >= theArgsNb
3711 || aNameCase.Length() < 5)
3713 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3717 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
3718 if (!aTexIndexStr.IsIntegerValue())
3720 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3724 aTexIndex = aTexIndexStr.IntegerValue();
3725 aTexName = theArgVec[anArgIter + 1];
3728 if (aTexIndex >= Graphic3d_TextureUnit_NB
3729 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
3731 std::cout << "Error: too many textures specified\n";
3736 if (aTexName.IsIntegerValue())
3738 const Standard_Integer aValue = aTexName.IntegerValue();
3739 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
3741 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
3744 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
3746 else if (aTexName == "?")
3748 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3750 theDi << "\n Files in current directory : \n\n";
3751 theDi.Eval ("glob -nocomplain *");
3753 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3754 aCmnd += aTextureFolder;
3757 theDi << "Files in " << aTextureFolder << " : \n\n";
3758 theDi.Eval (aCmnd.ToCString());
3761 else if (aTexName != "off")
3763 if (!OSD_File (aTexName).Exists())
3765 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
3768 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
3772 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
3775 if (aTextureVecNew.Value (aTexIndex))
3777 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
3782 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3789 // check if new image set is equal to already set one
3790 Standard_Integer aNbChanged = 0;
3791 Handle(Graphic3d_TextureSet) aTextureSetNew;
3792 if (!aTextureVecNew.IsEmpty())
3794 aNbChanged = aTextureVecNew.Size();
3795 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
3796 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
3798 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
3799 Handle(Graphic3d_TextureRoot) aTextureOld;
3800 if (!aTextureSetOld.IsNull()
3801 && aTexIter < aTextureSetOld->Size())
3803 aTextureOld = aTextureSetOld->Value (aTexIter);
3806 if (!aTextureOld.IsNull()
3807 && !aTextureNew.IsNull())
3809 *aTextureNew->GetParams() = *aTextureOld->GetParams();
3810 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
3812 TCollection_AsciiString aFilePathOld, aFilePathNew;
3813 aTextureOld->Path().SystemName (aFilePathOld);
3814 aTextureNew->Path().SystemName (aFilePathNew);
3815 if (aTextureNew->Name() == anOldManualTex->Name()
3816 && aFilePathOld == aFilePathNew
3817 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
3820 aTextureNew = anOldManualTex;
3824 aTextureSetNew->SetValue (aTexIter, aTextureNew);
3828 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
3829 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
3831 aTextureSetNew = aTextureSetOld;
3834 if (!aTexturedIO->Attributes()->HasOwnShadingAspect())
3836 if (aTexturedShape.IsNull())
3838 aTexturedIO->SetToUpdate();
3840 aTexturedIO->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
3841 *aTexturedIO->Attributes()->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
3844 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
3845 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
3846 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
3847 aTextureSetOld.Nullify();
3852 if (toModulate != -1)
3859 aFilter = Graphic3d_TOTF_BILINEAR;
3864 anAnisoFilter = Graphic3d_LOTA_OFF;
3866 if (!toSetTrsfAngle)
3868 toSetTrsfAngle = true;
3869 aTrsfRotAngle = 0.0f;
3871 if (!toSetTrsfTrans)
3873 toSetTrsfTrans = true;
3874 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
3876 if (!toSetTrsfScale)
3878 toSetTrsfScale = true;
3879 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
3883 if (aCommandName == "vtexture"
3886 if (!aTextureSetOld.IsNull())
3888 //toComputeUV = true; // we can keep UV vertex attributes
3889 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
3890 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
3891 aTextureSetOld.Nullify();
3895 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
3896 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
3898 if (toModulate != -1)
3900 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
3904 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
3908 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
3912 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
3916 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
3920 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
3924 // set default values if requested
3926 && (aCommandName == "vtexrepeat"
3929 if (!aTexturedShape.IsNull())
3931 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3933 toSetGenRepeat = true;
3936 && (aCommandName == "vtexorigin"
3939 if (!aTexturedShape.IsNull())
3941 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3943 toSetGenOrigin = true;
3946 && (aCommandName == "vtexscale"
3949 if (!aTexturedShape.IsNull())
3951 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3953 toSetGenScale = true;
3956 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
3958 if (!aTexturedShape.IsNull())
3960 aTexturedShape->SetToUpdate (AIS_Shaded);
3963 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
3964 || aCtx->DisplayMode() != AIS_Shaded)
3966 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
3971 aCtx->Display (aTexturedIO, false);
3972 aTexturedIO->SynchronizeAspects();
3976 //! Auxiliary method to parse transformation persistence flags
3977 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3978 Graphic3d_TransModeFlags& theFlags)
3980 if (theFlagString == "zoom")
3982 theFlags = Graphic3d_TMF_ZoomPers;
3984 else if (theFlagString == "rotate")
3986 theFlags = Graphic3d_TMF_RotatePers;
3988 else if (theFlagString == "zoomrotate")
3990 theFlags = Graphic3d_TMF_ZoomRotatePers;
3992 else if (theFlagString == "trihedron"
3993 || theFlagString == "triedron")
3995 theFlags = Graphic3d_TMF_TriedronPers;
3997 else if (theFlagString == "none")
3999 theFlags = Graphic3d_TMF_None;
4003 return Standard_False;
4006 return Standard_True;
4009 //! Auxiliary method to parse transformation persistence flags
4010 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4011 Aspect_TypeOfTriedronPosition& theCorner)
4013 TCollection_AsciiString aString (theString);
4014 aString.LowerCase();
4015 if (aString == "center")
4017 theCorner = Aspect_TOTP_CENTER;
4019 else if (aString == "top"
4020 || aString == "upper")
4022 theCorner = Aspect_TOTP_TOP;
4024 else if (aString == "bottom"
4025 || aString == "lower")
4027 theCorner = Aspect_TOTP_BOTTOM;
4029 else if (aString == "left")
4031 theCorner = Aspect_TOTP_LEFT;
4033 else if (aString == "right")
4035 theCorner = Aspect_TOTP_RIGHT;
4037 else if (aString == "topleft"
4038 || aString == "leftupper"
4039 || aString == "upperleft")
4041 theCorner = Aspect_TOTP_LEFT_UPPER;
4043 else if (aString == "bottomleft"
4044 || aString == "leftlower"
4045 || aString == "lowerleft")
4047 theCorner = Aspect_TOTP_LEFT_LOWER;
4049 else if (aString == "topright"
4050 || aString == "rightupper"
4051 || aString == "upperright")
4053 theCorner = Aspect_TOTP_RIGHT_UPPER;
4055 else if (aString == "bottomright"
4056 || aString == "lowerright"
4057 || aString == "rightlower")
4059 theCorner = Aspect_TOTP_RIGHT_LOWER;
4063 return Standard_False;
4066 return Standard_True;
4069 //==============================================================================
4070 //function : VDisplay2
4072 //purpose : Display an object from its name
4073 //==============================================================================
4074 static int VDisplay2 (Draw_Interpretor& theDI,
4075 Standard_Integer theArgNb,
4076 const char** theArgVec)
4080 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4084 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4087 ViewerTest::ViewerInit();
4088 aCtx = ViewerTest::GetAISContext();
4091 // Parse input arguments
4092 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4093 Standard_Integer isMutable = -1;
4094 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4095 Standard_Boolean toReDisplay = Standard_False;
4096 Standard_Integer isSelectable = -1;
4097 Standard_Integer anObjDispMode = -2;
4098 Standard_Integer anObjHighMode = -2;
4099 Standard_Boolean toSetTrsfPers = Standard_False;
4100 Handle(Graphic3d_TransformPers) aTrsfPers;
4101 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4102 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4103 Standard_Integer toDisplayInView = Standard_False;
4104 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4106 const TCollection_AsciiString aName = theArgVec[anArgIter];
4107 TCollection_AsciiString aNameCase = aName;
4108 aNameCase.LowerCase();
4109 if (anUpdateTool.parseRedrawMode (aName))
4113 else if (aNameCase == "-mutable")
4117 else if (aNameCase == "-neutral")
4119 aDispStatus = AIS_DS_Displayed;
4121 else if (aNameCase == "-immediate"
4122 || aNameCase == "-top")
4124 aZLayer = Graphic3d_ZLayerId_Top;
4126 else if (aNameCase == "-topmost")
4128 aZLayer = Graphic3d_ZLayerId_Topmost;
4130 else if (aNameCase == "-osd"
4131 || aNameCase == "-toposd"
4132 || aNameCase == "-overlay")
4134 aZLayer = Graphic3d_ZLayerId_TopOSD;
4136 else if (aNameCase == "-botosd"
4137 || aNameCase == "-underlay")
4139 aZLayer = Graphic3d_ZLayerId_BotOSD;
4141 else if (aNameCase == "-select"
4142 || aNameCase == "-selectable")
4146 else if (aNameCase == "-noselect"
4147 || aNameCase == "-noselection")
4151 else if (aNameCase == "-dispmode"
4152 || aNameCase == "-displaymode")
4154 if (++anArgIter >= theArgNb)
4156 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4160 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4162 else if (aNameCase == "-highmode"
4163 || aNameCase == "-highlightmode")
4165 if (++anArgIter >= theArgNb)
4167 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4171 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4173 else if (aNameCase == "-3d")
4175 toSetTrsfPers = Standard_True;
4176 aTrsfPers.Nullify();
4178 else if (aNameCase == "-2d"
4179 || aNameCase == "-trihedron"
4180 || aNameCase == "-triedron")
4182 toSetTrsfPers = Standard_True;
4183 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4185 if (anArgIter + 1 < theArgNb)
4187 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4188 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4191 aTrsfPers->SetCorner2d (aCorner);
4193 if (anArgIter + 2 < theArgNb)
4195 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4196 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4197 if (anX.IsIntegerValue()
4198 && anY.IsIntegerValue())
4201 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4207 else if (aNameCase == "-trsfpers"
4208 || aNameCase == "-pers")
4210 if (++anArgIter >= theArgNb
4211 || !aTrsfPers.IsNull())
4213 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4217 toSetTrsfPers = Standard_True;
4218 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4219 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4220 aPersFlags.LowerCase();
4221 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
4223 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
4227 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4229 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4231 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4233 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
4236 else if (aNameCase == "-trsfperspos"
4237 || aNameCase == "-perspos")
4239 if (anArgIter + 2 >= theArgNb
4240 || aTrsfPers.IsNull())
4242 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4246 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4247 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4248 TCollection_AsciiString aZ = "0";
4249 if (!aX.IsRealValue()
4250 || !aY.IsRealValue())
4252 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4255 if (anArgIter + 1 < theArgNb)
4257 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
4258 if (aTemp.IsRealValue())
4265 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
4266 if (aTrsfPers->IsZoomOrRotate())
4268 aTrsfPers->SetAnchorPoint (aPnt);
4270 else if (aTrsfPers->IsTrihedronOr2d())
4272 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
4275 else if (aNameCase == "-layer")
4277 if (++anArgIter >= theArgNb)
4279 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4283 TCollection_AsciiString aValue (theArgVec[anArgIter]);
4284 if (!aValue.IsIntegerValue())
4286 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4290 aZLayer = aValue.IntegerValue();
4292 else if (aNameCase == "-view"
4293 || aNameCase == "-inview")
4295 toDisplayInView = Standard_True;
4297 else if (aNameCase == "-redisplay")
4299 toReDisplay = Standard_True;
4301 else if (aNameCase == "-erased"
4302 || aNameCase == "-load")
4304 aDispStatus = AIS_DS_Erased;
4308 aNamesOfDisplayIO.Append (aName);
4312 if (aNamesOfDisplayIO.IsEmpty())
4314 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4318 // Display interactive objects
4319 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
4321 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
4322 Handle(AIS_InteractiveObject) aShape;
4323 if (!GetMapOfAIS().Find2 (aName, aShape))
4325 // create the AIS_Shape from a name
4326 aShape = GetAISShapeFromName (aName.ToCString());
4327 if (!aShape.IsNull())
4329 if (isMutable != -1)
4331 aShape->SetMutable (isMutable == 1);
4333 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4335 aShape->SetZLayer (aZLayer);
4339 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4341 if (anObjDispMode != -2)
4343 aShape->SetDisplayMode (anObjDispMode);
4345 if (anObjHighMode != -2)
4347 aShape->SetHilightMode (anObjHighMode);
4350 GetMapOfAIS().Bind (aShape, aName);
4351 Standard_Integer aDispMode = aShape->HasDisplayMode()
4352 ? aShape->DisplayMode()
4353 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4354 ? aCtx->DisplayMode()
4356 Standard_Integer aSelMode = -1;
4357 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4359 aSelMode = aShape->GlobalSelectionMode();
4362 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
4363 if (toDisplayInView)
4365 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
4367 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
4369 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4374 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
4379 if (isMutable != -1)
4381 aShape->SetMutable (isMutable == 1);
4383 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4385 aShape->SetZLayer (aZLayer);
4389 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4391 if (anObjDispMode != -2)
4393 aShape->SetDisplayMode (anObjDispMode);
4395 if (anObjHighMode != -2)
4397 aShape->SetHilightMode (anObjHighMode);
4399 Standard_Integer aDispMode = aShape->HasDisplayMode()
4400 ? aShape->DisplayMode()
4401 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4402 ? aCtx->DisplayMode()
4404 Standard_Integer aSelMode = -1;
4405 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4407 aSelMode = aShape->GlobalSelectionMode();
4410 if (aShape->Type() == AIS_KOI_Datum)
4412 aCtx->Display (aShape, Standard_False);
4416 theDI << "Display " << aName.ToCString() << "\n";
4418 // update the Shape in the AIS_Shape
4419 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
4420 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
4421 if (!aShapePrs.IsNull())
4423 if (!aShapePrs->Shape().IsEqual (aNewShape))
4425 toReDisplay = Standard_True;
4427 aShapePrs->Set (aNewShape);
4431 aCtx->Redisplay (aShape, Standard_False);
4436 aCtx->Erase (aShape, Standard_False);
4438 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
4439 if (toDisplayInView)
4441 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4449 //=======================================================================
4450 //function : VNbDisplayed
4451 //purpose : Returns number of displayed objects
4452 //=======================================================================
4453 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
4454 Standard_Integer theArgsNb,
4455 const char** theArgVec)
4459 theDi << "Usage : " << theArgVec[0] << "\n";
4463 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4464 if (aContextAIS.IsNull())
4466 std::cout << theArgVec[0] << "AIS context is not available.\n";
4470 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4471 if(aContext.IsNull())
4473 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
4477 AIS_ListOfInteractive aListOfIO;
4478 aContextAIS->DisplayedObjects (aListOfIO);
4480 theDi << aListOfIO.Extent() << "\n";
4484 //===============================================================================================
4485 //function : VUpdate
4487 //===============================================================================================
4488 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
4490 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4491 if (aContextAIS.IsNull())
4493 std::cout << theArgVec[0] << "AIS context is not available.\n";
4499 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
4503 AIS_ListOfInteractive aListOfIO;
4504 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4506 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
4508 Handle(AIS_InteractiveObject) anAISObj;
4509 GetMapOfAIS().Find2 (aName, anAISObj);
4510 if (anAISObj.IsNull())
4512 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
4516 aListOfIO.Append (anAISObj);
4519 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
4520 for (; anIOIt.More(); anIOIt.Next())
4522 aContextAIS->Update (anIOIt.Value(), Standard_False);
4525 aContextAIS->UpdateCurrentViewer();
4530 //==============================================================================
4531 //function : VShading
4532 //purpose : Sharpen or roughten the quality of the shading
4533 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4534 //==============================================================================
4535 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4537 Standard_Real myDevCoef;
4538 Handle(AIS_InteractiveObject) TheAisIO;
4541 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4545 myDevCoef =Draw::Atof(argv[2]);
4548 TCollection_AsciiString name=argv[1];
4549 GetMapOfAIS().Find2(name, TheAisIO);
4550 if (TheAisIO.IsNull())
4551 TheAisIO=GetAISShapeFromName(name.ToCString());
4554 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4556 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4558 TheAISContext()->Redisplay (TheAisIO, Standard_True);
4562 //! Auxiliary method to print Interactive Object information
4563 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4564 const Handle(AIS_InteractiveObject)& theObj,
4565 Draw_Interpretor& theDI)
4567 if (theObj.IsNull())
4569 theDI << "NULL presentation\n";
4573 theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ")
4574 << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ")
4575 << (theDetected.Contains (theObj) ? " Detected" : " ")
4577 if (theObj->Type() == AIS_KOI_Datum)
4580 if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4581 else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; }
4582 else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; }
4583 else if (theObj->Signature() == 5) { theDI << " AIS_Line"; }
4584 else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; }
4585 else if (theObj->Signature() == 1) { theDI << " AIS_Point"; }
4586 else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4589 else if (theObj->Type() == AIS_KOI_Shape
4590 && theObj->Signature() == 0)
4592 theDI << " AIS_Shape";
4594 else if (theObj->Type() == AIS_KOI_Relation)
4596 // AIS_Dimention and AIS_Relation
4597 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (theObj);
4598 switch (aRelation->KindOfDimension())
4600 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4601 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4602 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4603 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4604 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4605 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4606 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4607 default: theDI << " UNKNOWN dimension"; break;
4612 theDI << " UserPrs";
4614 theDI << " (" << theObj->DynamicType()->Name() << ")";
4617 //! Print information about locally selected sub-shapes
4618 template <typename T>
4619 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4621 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4622 TCollection_AsciiString aPrevName;
4623 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4625 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4626 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4627 if (aShapeIO.IsNull() || anOwner.IsNull())
4631 if (anOwner == aShapeIO->GlobalSelOwner())
4634 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4635 if (aSubShape.IsNull()
4636 || aShapeIO.IsNull()
4637 || !GetMapOfAIS().IsBound1 (aShapeIO))
4642 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4643 TopTools_MapOfShape aFilter;
4644 Standard_Integer aNumber = 0;
4645 const TopoDS_Shape aShape = aShapeIO->Shape();
4646 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4647 anIter.More(); anIter.Next())
4649 if (!aFilter.Add (anIter.Current()))
4651 continue; // filter duplicates
4655 if (!anIter.Current().IsSame (aSubShape))
4660 Standard_CString aShapeName = NULL;
4661 switch (aSubShape.ShapeType())
4663 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4664 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4665 case TopAbs_SOLID: aShapeName = " Solid"; break;
4666 case TopAbs_SHELL: aShapeName = " Shell"; break;
4667 case TopAbs_FACE: aShapeName = " Face"; break;
4668 case TopAbs_WIRE: aShapeName = " Wire"; break;
4669 case TopAbs_EDGE: aShapeName = " Edge"; break;
4670 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4672 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4675 if (aParentName != aPrevName)
4677 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4678 aPrevName = aParentName;
4680 theDI << " " << aShapeName << " #" << aNumber << "\n";
4686 //==============================================================================
4689 //==============================================================================
4690 static Standard_Integer VState (Draw_Interpretor& theDI,
4691 Standard_Integer theArgNb,
4692 Standard_CString* theArgVec)
4694 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4697 std::cerr << "Error: No opened viewer!\n";
4701 Standard_Boolean toPrintEntities = Standard_False;
4702 Standard_Boolean toCheckSelected = Standard_False;
4704 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4706 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4707 anOption.LowerCase();
4708 if (anOption == "-detectedentities"
4709 || anOption == "-entities")
4711 toPrintEntities = Standard_True;
4713 else if (anOption == "-hasselected")
4715 toCheckSelected = Standard_True;
4719 if (toCheckSelected)
4721 aCtx->InitSelected();
4722 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4723 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4728 if (toPrintEntities)
4730 theDI << "Detected entities:\n";
4731 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
4733 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4734 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4736 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4737 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4738 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4739 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4740 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4741 aName.LeftJustify (20, ' ');
4742 char anInfoStr[512];
4744 " Depth: %g Distance: %g Point: %g %g %g",
4747 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4748 theDI << " " << aName
4750 << " (" << anEntity->DynamicType()->Name() << ")"
4753 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4754 if (!aBRepOwner.IsNull())
4756 theDI << " Detected Shape: "
4757 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4761 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4762 if (!aWire.IsNull())
4764 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4765 theDI << " Detected Child: "
4766 << aSen->DynamicType()->Name()
4770 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4771 if (!aPrimArr.IsNull())
4773 theDI << " Detected Element: "
4774 << aPrimArr->LastDetectedElement()
4781 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4782 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4784 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
4787 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4791 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4793 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4794 Handle(AIS_InteractiveObject) anObj;
4795 if (!GetMapOfAIS().Find2 (anObjName, anObj))
4797 theDI << anObjName << " doesn't exist!\n";
4801 TCollection_AsciiString aName = anObjName;
4802 aName.LeftJustify (20, ' ');
4803 theDI << " " << aName << " ";
4804 objInfo (aDetected, anObj, theDI);
4810 if (aCtx->NbSelected() > 0 && !toShowAll)
4812 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4813 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4815 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4816 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4817 // handle whole object selection
4818 if (anOwner == anObj->GlobalSelOwner())
4820 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4821 aName.LeftJustify (20, ' ');
4822 theDI << aName << " ";
4823 objInfo (aDetected, anObj, theDI);
4828 // process selected sub-shapes
4829 printLocalSelectionInfo (aCtx, theDI);
4834 theDI << "Neutral-point state:\n";
4835 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4836 anObjIter.More(); anObjIter.Next())
4838 if (anObjIter.Key1().IsNull())
4843 TCollection_AsciiString aName = anObjIter.Key2();
4844 aName.LeftJustify (20, ' ');
4845 theDI << " " << aName << " ";
4846 objInfo (aDetected, anObjIter.Key1(), theDI);
4849 printLocalSelectionInfo (aCtx, theDI);
4853 //=======================================================================
4854 //function : PickShape
4855 //purpose : First Activate the rightmode + Put Filters to be able to
4856 // pick objets that are of type <TheType>...
4857 //=======================================================================
4859 TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
4860 const Standard_Integer theMaxPick)
4862 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
4863 PickShapes (theShapeType, aResArray, theMaxPick);
4864 return aResArray->First();
4867 //=======================================================================
4868 //function : PickShapes
4870 //=======================================================================
4871 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
4872 Handle(TopTools_HArray1OfShape)& theResArray,
4873 const Standard_Integer theMaxPick)
4875 const Standard_Integer aNbToReach = theResArray->Length();
4878 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4881 // step 1: prepare the data
4882 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4883 aCtx->RemoveFilters();
4884 AIS_ListOfInteractive aDispObjects;
4885 aCtx->DisplayedObjects (aDispObjects);
4886 if (theShapeType == TopAbs_SHAPE)
4888 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
4892 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
4895 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
4896 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
4898 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
4900 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
4904 // step 2 : wait for the selection...
4905 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
4906 Standard_Integer argccc = 5;
4907 const char *bufff[] = { "A", "B", "C", "D", "E" };
4908 const char **argvvv = (const char** )bufff;
4909 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
4911 while (ViewerMainLoop (argccc, argvvv)) {}
4912 Standard_Integer aNbStored = aCtx->NbSelected();
4913 if (aNbStored != aNbPickGood)
4915 aNbPickGood = aNbStored;
4921 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
4924 // step3 get result.
4925 if (aNbPickFail >= aNbToReach)
4927 return Standard_False;
4930 Standard_Integer anIndex = theResArray->Lower();
4931 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
4933 if (aCtx->HasSelectedShape())
4935 theResArray->SetValue (anIndex, aCtx->SelectedShape());
4939 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
4940 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
4944 aCtx->RemoveFilters();
4945 if (theShapeType != TopAbs_SHAPE)
4947 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
4949 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
4951 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
4955 return Standard_True;
4958 //=======================================================================
4959 //function : VPickShape
4961 //=======================================================================
4962 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4964 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4967 TCollection_AsciiString aShapeArg (argv[1]);
4968 aShapeArg.LowerCase();
4969 aShapeType = TopAbs_COMPOUND;
4970 if (aShapeArg == "v"
4971 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
4972 else if (aShapeArg == "e"
4973 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
4974 else if (aShapeArg == "w"
4975 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
4976 else if (aShapeArg == "f"
4977 || aShapeArg == "face") aShapeType = TopAbs_FACE;
4978 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
4979 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
4980 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
4983 std::cout << "Syntax error at '" << argv[1] << "'\n";
4988 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4989 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4991 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
4994 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
4995 if (aPickedShape.IsNull())
5000 TCollection_AsciiString aName;
5007 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5008 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5011 DBRep::Set (aName.ToCString(), aPickedShape);
5012 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5013 ViewerTest::Display (aName, aShapePrs, false, true);
5014 di << "Name of picked shape: " << aName <<"\n";
5018 TCollection_AsciiString aName (argv[2]);
5020 const Standard_Boolean isAutoNaming = aName == ".";
5021 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5022 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5024 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5026 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5028 if (!aPickedShape.IsNull()
5031 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5032 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5036 aName = argv[1 + aPickedIter];
5039 DBRep::Set (aName.ToCString(), aPickedShape);
5040 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5041 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5042 ViewerTest::Display (aName, aShapePrs, false, true);
5046 TheAISContext()->UpdateCurrentViewer();
5050 //=======================================================================
5051 //function : VSelFilter
5053 //=======================================================================
5054 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5055 const char** theArgv)
5057 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5058 if (aContext.IsNull())
5060 std::cout << "Error: AIS context is not available.\n";
5064 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5066 TCollection_AsciiString anArg (theArgv[anArgIter]);
5068 if (anArg == "-clear")
5070 aContext->RemoveFilters();
5072 else if (anArg == "-type"
5073 && anArgIter + 1 < theArgc)
5075 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5076 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5077 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5079 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5083 Handle(SelectMgr_Filter) aFilter;
5084 if (aShapeType == TopAbs_SHAPE)
5086 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5090 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5092 aContext->AddFilter (aFilter);
5096 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5103 //=======================================================================
5104 //function : VPickSelected
5106 //=======================================================================
5107 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5109 static Standard_Integer aCount = 0;
5110 TCollection_AsciiString aName = "PickedShape_";
5118 aName = aName + aCount++ + "_";
5121 Standard_Integer anIdx = 0;
5122 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5124 TopoDS_Shape aShape;
5125 if (TheAISContext()->HasSelectedShape())
5127 aShape = TheAISContext()->SelectedShape();
5131 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5132 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5135 TCollection_AsciiString aCurrentName = aName;
5138 aCurrentName += anIdx;
5141 DBRep::Set ((aCurrentName).ToCString(), aShape);
5143 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5144 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5145 TheAISContext()->Display (aNewShape, Standard_False);
5148 TheAISContext()->UpdateCurrentViewer();
5153 //=======================================================================
5154 //function : list of known objects
5156 //=======================================================================
5157 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5159 // 1234567890 12345678901234567 123456789
5160 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5161 TCollection_AsciiString BlankLine(64,'_');
5162 Standard_Integer i ;
5164 di<<"/n"<<BlankLine.ToCString()<<"\n";
5167 Colum[i].Center(20,' ');
5169 di<<"|"<<Colum[i].ToCString();
5172 di<<BlankLine.ToCString()<<"\n";
5174 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5175 const char ** names = GetTypeNames();
5177 TCollection_AsciiString curstring;
5178 TCollection_AsciiString curcolum[3];
5181 // les objets de type Datum..
5182 curcolum[1]+="Datum";
5184 curcolum[0].Clear();
5185 curcolum[0] += names[i];
5187 curcolum[2].Clear();
5188 curcolum[2]+=TCollection_AsciiString(i+1);
5190 for(Standard_Integer j =0;j<=2;j++){
5191 curcolum[j].Center(20,' ');
5192 di<<"|"<<curcolum[j].ToCString();
5196 di<<BlankLine.ToCString()<<"\n";
5198 // les objets de type shape
5199 curcolum[1].Clear();
5200 curcolum[1]+="Shape";
5201 curcolum[1].Center(20,' ');
5204 curcolum[0].Clear();
5205 curcolum[0] += names[7+i];
5206 curcolum[2].Clear();
5207 curcolum[2]+=TCollection_AsciiString(i);
5209 for(Standard_Integer j =0;j<=2;j++){
5210 curcolum[j].Center(20,' ');
5211 di<<"|"<<curcolum[j].ToCString();
5215 di<<BlankLine.ToCString()<<"\n";
5216 // les IO de type objet...
5217 curcolum[1].Clear();
5218 curcolum[1]+="Object";
5219 curcolum[1].Center(20,' ');
5221 curcolum[0].Clear();
5222 curcolum[0] += names[10+i];
5223 curcolum[2].Clear();
5224 curcolum[2]+=TCollection_AsciiString(i);
5226 for(Standard_Integer j =0;j<=2;j++){
5227 curcolum[j].Center(20,' ');
5228 di<<"|"<<curcolum[j].ToCString();
5232 di<<BlankLine.ToCString()<<"\n";
5233 // les contraintes et dimensions.
5234 // pour l'instant on separe juste contraintes et dimensions...
5235 // plus tard, on detaillera toutes les sortes...
5236 curcolum[1].Clear();
5237 curcolum[1]+="Relation";
5238 curcolum[1].Center(20,' ');
5240 curcolum[0].Clear();
5241 curcolum[0] += names[12+i];
5242 curcolum[2].Clear();
5243 curcolum[2]+=TCollection_AsciiString(i);
5245 for(Standard_Integer j =0;j<=2;j++){
5246 curcolum[j].Center(20,' ');
5247 di<<"|"<<curcolum[j].ToCString();
5251 di<<BlankLine.ToCString()<<"\n";
5258 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5260 if(argc!=2) return 1;
5262 AIS_KindOfInteractive TheType;
5263 Standard_Integer TheSign(-1);
5264 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5267 AIS_ListOfInteractive LIO;
5269 // en attendant l'amelioration ais pour les dimensions...
5271 Standard_Integer dimension_status(-1);
5272 if(TheType==AIS_KOI_Relation){
5273 dimension_status = TheSign ==1 ? 1 : 0;
5277 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5278 Handle(AIS_InteractiveObject) curio;
5279 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5282 if(dimension_status == -1)
5283 TheAISContext()->Erase(curio,Standard_False);
5285 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5286 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5287 (dimension_status==1 && KOD != AIS_KOD_NONE))
5288 TheAISContext()->Erase(curio,Standard_False);
5291 TheAISContext()->UpdateCurrentViewer();
5294 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5296 if(argc!=2) return 1;
5298 AIS_KindOfInteractive TheType;
5299 Standard_Integer TheSign(-1);
5300 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5302 // en attendant l'amelioration ais pour les dimensions...
5304 Standard_Integer dimension_status(-1);
5305 if(TheType==AIS_KOI_Relation){
5306 dimension_status = TheSign ==1 ? 1 : 0;
5310 AIS_ListOfInteractive LIO;
5311 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5312 Handle(AIS_InteractiveObject) curio;
5313 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5315 if(dimension_status == -1)
5316 TheAISContext()->Display(curio,Standard_False);
5318 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5319 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5320 (dimension_status==1 && KOD != AIS_KOD_NONE))
5321 TheAISContext()->Display(curio,Standard_False);
5326 TheAISContext()->UpdateCurrentViewer();
5330 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5333 BRep_Builder builder;
5335 BRepTools::Read(shape, s, builder);
5336 DBRep::Set(a[1], shape);
5337 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5338 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5339 Ctx->Display (ais, Standard_True);
5343 //===============================================================================================
5346 //===============================================================================================
5347 static int VBsdf (Draw_Interpretor& theDI,
5348 Standard_Integer theArgsNb,
5349 const char** theArgVec)
5351 Handle(V3d_View) aView = ViewerTest::CurrentView();
5352 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5354 || aViewer.IsNull())
5356 std::cerr << "No active viewer!\n";
5360 ViewerTest_CmdParser aCmd;
5362 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5364 aCmd.AddOption ("print|echo|p", "Prints BSDF");
5366 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
5368 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
5369 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
5370 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
5371 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
5372 aCmd.AddOption ("le", "Radiance emitted by surface");
5374 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5375 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5377 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
5378 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
5380 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
5381 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
5383 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
5385 aCmd.Parse (theArgsNb, theArgVec);
5387 if (aCmd.HasOption ("help"))
5389 theDI.PrintHelp (theArgVec[0]);
5393 // check viewer update mode
5394 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
5395 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5397 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5404 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5405 Handle(AIS_InteractiveObject) anIObj;
5406 if (!GetMapOfAIS().Find2 (aName, anIObj))
5408 std::cerr << "Use 'vdisplay' before\n";
5412 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5413 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5415 if (aCmd.HasOption ("print"))
5418 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
5419 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5420 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5421 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5422 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
5424 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5426 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
5427 : aBSDF.FresnelBase.Serialize();
5429 theDI << (aLayerID < 1 ? "Coat Fresnel: "
5430 : "Base Fresnel: ");
5432 if (aFresnel.x() >= 0.f)
5434 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
5435 << "G = " << aFresnel.g() << ", "
5436 << "B = " << aFresnel.b() << "\n";
5438 else if (aFresnel.x() >= -1.5f)
5440 theDI << "Constant " << aFresnel.z() << "\n";
5442 else if (aFresnel.x() >= -2.5f)
5444 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
5445 << "K = " << aFresnel.z() << "\n";
5449 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
5453 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
5454 << "Base roughness: " << aBSDF.Ks.w() << "\n"
5455 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
5456 << "Absorption color: " << aBSDF.Absorption.r() << ", "
5457 << aBSDF.Absorption.g() << ", "
5458 << aBSDF.Absorption.b() << "\n";
5463 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
5465 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
5468 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
5470 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
5473 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5475 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
5478 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5480 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
5482 aBSDF.Absorption.r() = aRGB.r();
5483 aBSDF.Absorption.g() = aRGB.g();
5484 aBSDF.Absorption.b() = aRGB.b();
5487 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
5491 if (aCmd.HasOption ("kc", 3))
5493 aKc = aCmd.ArgVec3f ("kc");
5497 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
5500 aBSDF.Kc.r() = aKc.r();
5501 aBSDF.Kc.g() = aKc.g();
5502 aBSDF.Kc.b() = aKc.b();
5505 if (aCmd.HasOption ("kd", 3))
5507 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5509 else if (aCmd.HasOption ("kd", 1, Standard_True))
5511 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5514 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
5518 if (aCmd.HasOption ("ks", 3))
5520 aKs = aCmd.ArgVec3f ("ks");
5524 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5527 aBSDF.Ks.r() = aKs.r();
5528 aBSDF.Ks.g() = aKs.g();
5529 aBSDF.Ks.b() = aKs.b();
5532 if (aCmd.HasOption ("kt", 3))
5534 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5536 else if (aCmd.HasOption ("kt", 1, Standard_True))
5538 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5541 if (aCmd.HasOption ("le", 3))
5543 aBSDF.Le = aCmd.ArgVec3f ("le");
5545 else if (aCmd.HasOption ("le", 1, Standard_True))
5547 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5550 const std::string aFresnelErrorMessage =
5551 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
5553 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5555 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
5558 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
5560 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5561 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5563 if (aFresnelType == "schlick")
5565 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
5566 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
5567 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
5569 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
5570 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
5571 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
5573 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
5577 theDI << aFresnelErrorMessage.c_str() << "\n";
5580 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
5582 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5583 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5585 if (aFresnelType == "conductor")
5587 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5588 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
5590 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
5594 theDI << aFresnelErrorMessage.c_str() << "\n";
5597 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
5599 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5600 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5602 if (aFresnelType == "constant")
5604 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5606 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
5608 else if (aFresnelType == "dielectric")
5610 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5612 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
5616 theDI << aFresnelErrorMessage.c_str() << "\n";
5621 if (aCmd.HasOption ("normalize"))
5626 aMaterial.SetBSDF (aBSDF);
5627 anIObj->SetMaterial (aMaterial);
5632 //==============================================================================
5633 //function : VLoadSelection
5634 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5635 //==============================================================================
5636 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5637 Standard_Integer theArgNb,
5638 const char** theArgVec)
5642 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5646 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5649 ViewerTest::ViewerInit();
5650 aCtx = ViewerTest::GetAISContext();
5653 // Parse input arguments
5654 TColStd_SequenceOfAsciiString aNamesOfIO;
5655 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5657 const TCollection_AsciiString aName = theArgVec[anArgIter];
5658 aNamesOfIO.Append (aName);
5661 if (aNamesOfIO.IsEmpty())
5663 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5667 // Load selection of interactive objects
5668 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5670 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5672 Handle(AIS_InteractiveObject) aShape;
5673 if (!GetMapOfAIS().Find2 (aName, aShape))
5675 aShape = GetAISShapeFromName (aName.ToCString());
5678 if (!aShape.IsNull())
5680 if (!GetMapOfAIS().IsBound2 (aName))
5682 GetMapOfAIS().Bind (aShape, aName);
5685 aCtx->Load (aShape, -1);
5686 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5693 //==============================================================================
5694 //function : ViewerTest::Commands
5695 //purpose : Add all the viewer command in the Draw_Interpretor
5696 //==============================================================================
5698 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5700 ViewerTest::ViewerCommands(theCommands);
5701 ViewerTest::RelationCommands(theCommands);
5702 ViewerTest::ObjectCommands(theCommands);
5703 ViewerTest::FilletCommands(theCommands);
5704 ViewerTest::OpenGlCommands(theCommands);
5706 const char *group = "AIS_Display";
5709 theCommands.Add("visos",
5710 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5711 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5712 __FILE__, visos, group);
5714 theCommands.Add("vdisplay",
5715 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5716 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5717 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5718 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5719 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5720 "\n\t\t: [offsetX offsetY]]]"
5721 "\n\t\t: [-dispMode mode] [-highMode mode]"
5722 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5723 "\n\t\t: [-redisplay] [-erased]"
5724 "\n\t\t: name1 [name2] ... [name n]"
5725 "\n\t\t: Displays named objects."
5726 "\n\t\t: Option -local enables displaying of objects in local"
5727 "\n\t\t: selection context. Local selection context will be opened"
5728 "\n\t\t: if there is not any."
5729 "\n\t\t: -noupdate Suppresses viewer redraw call."
5730 "\n\t\t: -mutable Enables optimizations for mutable objects."
5731 "\n\t\t: -neutral Draws objects in main viewer."
5732 "\n\t\t: -erased Loads the object into context, but does not display it."
5733 "\n\t\t: -layer Sets z-layer for objects."
5734 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5735 "\n\t\t: options can be used for the default z-layers."
5736 "\n\t\t: -top Draws object on top of main presentations"
5737 "\n\t\t: but below topmost."
5738 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5739 "\n\t\t: with independent Depth."
5740 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5741 "\n\t\t: (On-Screen-Display)"
5742 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5743 "\n\t\t: (On-Screen-Display)"
5744 "\n\t\t: -selectable|-noselect Controls selection of objects."
5745 "\n\t\t: -trsfPers Sets a transform persistence flags."
5746 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5747 "\n\t\t: -2d Displays object in screen coordinates."
5748 "\n\t\t: (DY looks up)"
5749 "\n\t\t: -dispmode Sets display mode for objects."
5750 "\n\t\t: -highmode Sets hilight mode for objects."
5751 "\n\t\t: -redisplay Recomputes presentation of objects.",
5752 __FILE__, VDisplay2, group);
5754 theCommands.Add ("vnbdisplayed",
5756 "\n\t\t: Returns number of displayed objects",
5757 __FILE__, VNbDisplayed, group);
5759 theCommands.Add ("vupdate",
5760 "vupdate name1 [name2] ... [name n]"
5761 "\n\t\t: Updates named objects in interactive context",
5762 __FILE__, VUpdate, group);
5764 theCommands.Add("verase",
5765 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5766 "\n\t\t: Erases selected or named objects."
5767 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5768 "\n\t\t: Option -local enables erasing of selected or named objects without"
5769 "\n\t\t: closing local selection context.",
5770 __FILE__, VErase, group);
5772 theCommands.Add("vremove",
5773 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5774 "or vremove [-context] -all to remove all objects"
5775 "\n\t\t: Removes selected or named objects."
5776 "\n\t\t If -context is in arguments, the objects are not deleted"
5777 "\n\t\t from the map of objects and names."
5778 "\n\t\t: Option -local enables removing of selected or named objects without"
5779 "\n\t\t: closing local selection context. Empty local selection context will be"
5781 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5782 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5783 __FILE__, VRemove, group);
5785 theCommands.Add("vdonly",
5786 "vdonly [-noupdate|-update] [name1] ... [name n]"
5787 "\n\t\t: Displays only selected or named objects",
5788 __FILE__,VDonly2,group);
5790 theCommands.Add("vdisplayall",
5792 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
5793 __FILE__, VDisplayAll, group);
5795 theCommands.Add("veraseall",
5797 "\n\t\t: Erases all objects displayed in the viewer.",
5798 __FILE__, VErase, group);
5800 theCommands.Add("verasetype",
5802 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5803 __FILE__, VEraseType, group);
5804 theCommands.Add("vbounding",
5805 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5806 "\n\t\t: [-print] [-hide]"
5807 "\n\t\t: Temporarily display bounding box of specified Interactive"
5808 "\n\t\t: Objects, or print it to console if -print is specified."
5809 "\n\t\t: Already displayed box might be hidden by -hide option.",
5810 __FILE__,VBounding,group);
5812 theCommands.Add("vdisplaytype",
5813 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5814 __FILE__,VDisplayType,group);
5816 theCommands.Add("vsetdispmode",
5817 "vsetdispmode [name] mode(1,2,..)"
5818 "\n\t\t: Sets display mode for all, selected or named objects.",
5819 __FILE__,VDispMode,group);
5821 theCommands.Add("vunsetdispmode",
5822 "vunsetdispmode [name]"
5823 "\n\t\t: Unsets custom display mode for selected or named objects.",
5824 __FILE__,VDispMode,group);
5826 theCommands.Add("vdir",
5827 "Lists all objects displayed in 3D viewer",
5828 __FILE__,VDir,group);
5830 #ifdef HAVE_FREEIMAGE
5831 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5833 #define DUMP_FORMATS "{ppm}"
5835 theCommands.Add("vdump",
5836 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5837 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5838 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5839 "\n\t\t: [-tileSize Size=0]"
5840 "\n\t\t: Dumps content of the active view into image file",
5841 __FILE__,VDump,group);
5843 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5844 __FILE__,VSubInt,group);
5846 theCommands.Add("vaspects",
5847 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5848 "\n\t\t: [-setVisibility 0|1]"
5849 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5850 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5851 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5852 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5853 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5854 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
5855 "\n\t\t: [-unsetMarkerType]"
5856 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
5857 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5858 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5859 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5860 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5861 "\n\t\t: [-isoontriangulation 0|1]"
5862 "\n\t\t: [-setMaxParamValue {value}]"
5863 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5864 "\n\t\t: [-setHatch HatchStyle]"
5865 "\n\t\t: [-setShadingModel {color|flat|gouraud|phong}]"
5866 "\n\t\t: [-unsetShadingModel]"
5867 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
5868 "\n\t\t: Manage presentation properties of all, selected or named objects."
5869 "\n\t\t: When -subshapes is specified than following properties will be"
5870 "\n\t\t: assigned to specified sub-shapes."
5871 "\n\t\t: When -defaults is specified than presentation properties will be"
5872 "\n\t\t: assigned to all objects that have not their own specified properties"
5873 "\n\t\t: and to all objects to be displayed in the future."
5874 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5875 __FILE__,VAspects,group);
5877 theCommands.Add("vsetcolor",
5878 "vsetcolor [-noupdate|-update] [name] ColorName"
5879 "\n\t\t: Sets color for all, selected or named objects."
5880 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5881 __FILE__,VAspects,group);
5883 theCommands.Add("vunsetcolor",
5884 "vunsetcolor [-noupdate|-update] [name]"
5885 "\n\t\t: Resets color for all, selected or named objects."
5886 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5887 __FILE__,VAspects,group);
5889 theCommands.Add("vsettransparency",
5890 "vsettransparency [-noupdate|-update] [name] Coefficient"
5891 "\n\t\t: Sets transparency for all, selected or named objects."
5892 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5893 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5894 __FILE__,VAspects,group);
5896 theCommands.Add("vunsettransparency",
5897 "vunsettransparency [-noupdate|-update] [name]"
5898 "\n\t\t: Resets transparency for all, selected or named objects."
5899 "\n\t\t: Alias for vaspects -unsettransp [name].",
5900 __FILE__,VAspects,group);
5902 theCommands.Add("vsetmaterial",
5903 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5904 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5905 __FILE__,VAspects,group);
5907 theCommands.Add("vunsetmaterial",
5908 "vunsetmaterial [-noupdate|-update] [name]"
5909 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5910 __FILE__,VAspects,group);
5912 theCommands.Add("vsetwidth",
5913 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5914 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5915 __FILE__,VAspects,group);
5917 theCommands.Add("vunsetwidth",
5918 "vunsetwidth [-noupdate|-update] [name]"
5919 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5920 __FILE__,VAspects,group);
5922 theCommands.Add("vsetinteriorstyle",
5923 "vsetinteriorstyle [-noupdate|-update] [name] style"
5924 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5925 __FILE__,VSetInteriorStyle,group);
5927 theCommands.Add("vsensdis",
5928 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5929 "\n\t\t: Standard entity types are those defined in Select3D package:"
5930 "\n\t\t: - sensitive box"
5931 "\n\t\t: - sensitive face"
5932 "\n\t\t: - sensitive curve"
5933 "\n\t\t: - sensitive segment"
5934 "\n\t\t: - sensitive circle"
5935 "\n\t\t: - sensitive point"
5936 "\n\t\t: - sensitive triangulation"
5937 "\n\t\t: - sensitive triangle"
5938 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5939 __FILE__,VDispSensi,group);
5941 theCommands.Add("vsensera",
5942 "vsensera : erase active entities",
5943 __FILE__,VClearSensi,group);
5945 theCommands.Add("vsetshading",
5946 "vsetshading : vsetshading name Quality(default=0.0008) "
5947 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5948 __FILE__,VShading,group);
5950 theCommands.Add("vunsetshading",
5951 "vunsetshading :vunsetshading name "
5952 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5953 __FILE__,VShading,group);
5955 theCommands.Add ("vtexture",
5956 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
5957 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
5958 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
5959 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
5960 "\n\t\t: [-modulate {on|off}]"
5961 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
5962 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
5963 "\n\t\t: [-default]"
5964 "\n\t\t: The texture can be specified by filepath"
5965 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
5966 "\n\t\t: The options are:"
5967 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
5968 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
5969 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
5970 "\n\t\t: -modulate Enable or disable texture color modulation"
5971 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
5972 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
5973 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
5974 "\n\t\t: -setFilter Setup texture filter"
5975 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
5976 "\n\t\t: -default Sets texture mapping default parameters",
5977 __FILE__, VTexture, group);
5979 theCommands.Add("vtexscale",
5980 "vtexscale name ScaleU ScaleV"
5981 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
5982 __FILE__,VTexture,group);
5984 theCommands.Add("vtexorigin",
5985 "vtexorigin name OriginU OriginV"
5986 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
5987 __FILE__,VTexture,group);
5989 theCommands.Add("vtexrepeat",
5990 "vtexrepeat name RepeatU RepeatV"
5991 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
5994 theCommands.Add("vtexdefault",
5996 "\n\t\t: Alias for vtexture name -default.",
5999 theCommands.Add("vstate",
6000 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6001 "\n\t\t: Reports show/hidden state for selected or named objects"
6002 "\n\t\t: -entities - print low-level information about detected entities"
6003 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6004 __FILE__,VState,group);
6006 theCommands.Add("vpickshapes",
6007 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6008 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6009 "\n\t\t: Hold also Shift for multiple selection.",
6010 __FILE__, VPickShape, group);
6012 theCommands.Add("vtypes",
6013 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6016 theCommands.Add("vr",
6018 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6019 __FILE__,vr, group);
6021 theCommands.Add("vselfilter",
6022 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6023 "\nSets selection shape type filter in context or remove all filters."
6024 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6025 "\n : Option -clear remove all filters in context",
6026 __FILE__,VSelFilter,group);
6028 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6029 __FILE__, VPickSelected, group);
6031 theCommands.Add ("vloadselection",
6032 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6033 "\n\t\t: primitives for the shapes with names given without displaying them.",
6034 __FILE__, VLoadSelection, group);
6036 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6037 "\nAdjusts parameters of material BSDF:"
6038 "\n -help : Shows this message"
6039 "\n -print : Print BSDF"
6040 "\n -kd : Weight of the Lambertian BRDF"
6041 "\n -kr : Weight of the reflection BRDF"
6042 "\n -kt : Weight of the transmission BTDF"
6043 "\n -ks : Weight of the glossy Blinn BRDF"
6044 "\n -le : Self-emitted radiance"
6045 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6046 "\n Schlick x y z, Dielectric x, Conductor x y"
6047 "\n -roughness : Roughness of material (Blinn's exponent)"
6048 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6049 "\n -absorpcolor : Absorption color (only for transparent material)"
6050 "\n -normalize : Normalize BSDF coefficients",
6051 __FILE__, VBsdf, group);
6055 //=====================================================================
6056 //========================= for testing Draft and Rib =================
6057 //=====================================================================
6058 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6059 #include <DBRep.hxx>
6060 #include <TopoDS_Face.hxx>
6061 #include <gp_Pln.hxx>
6062 #include <AIS_KindOfSurface.hxx>
6063 #include <BRepOffsetAPI_DraftAngle.hxx>
6064 #include <Precision.hxx>
6065 #include <BRepAlgo.hxx>
6066 #include <OSD_Environment.hxx>
6067 #include <DrawTrSurf.hxx>
6068 //#include <DbgTools.hxx>
6069 //#include <FeatAlgo_MakeLinearForm.hxx>
6074 //=======================================================================
6075 //function : IsValid
6077 //=======================================================================
6078 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6079 const TopoDS_Shape& theResult,
6080 const Standard_Boolean closedSolid,
6081 const Standard_Boolean GeomCtrl)
6083 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6084 TCollection_AsciiString checkValid = check.Value();
6085 Standard_Boolean ToCheck = Standard_True;
6086 if (!checkValid.IsEmpty()) {
6088 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6090 if ( checkValid=="true" || checkValid=="TRUE" ) {
6091 ToCheck= Standard_False;
6095 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6098 Standard_Boolean IsValid = Standard_True;
6100 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6105 //===============================================================================
6106 // TDraft : test draft, uses AIS Viewer
6107 // Solid Face Plane Angle Reverse
6108 //===============================================================================
6109 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6111 if (argc < 5) return 1;
6112 // argv[1] - TopoDS_Shape Solid
6113 // argv[2] - TopoDS_Shape Face
6114 // argv[3] - TopoDS_Shape Plane
6115 // argv[4] - Standard_Real Angle
6116 // argv[5] - Standard_Integer Reverse
6118 // Sprintf(prefix, argv[1]);
6119 Standard_Real anAngle = 0;
6120 Standard_Boolean Rev = Standard_False;
6121 Standard_Integer rev = 0;
6122 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
6123 TopoDS_Shape face = GetShapeFromName(argv[2]);
6124 TopoDS_Face Face = TopoDS::Face(face);
6125 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
6126 if (Plane.IsNull ()) {
6127 di << "TEST : Plane is NULL\n";
6130 anAngle = Draw::Atof(argv[4]);
6131 anAngle = 2*M_PI * anAngle / 360.0;
6133 Handle( Geom_Surface )aSurf;
6134 AIS_KindOfSurface aSurfType;
6135 Standard_Real Offset;
6137 if(argc > 4) { // == 5
6138 rev = Draw::Atoi(argv[5]);
6139 Rev = (rev)? Standard_True : Standard_False;
6142 TopoDS_Face face2 = TopoDS::Face(Plane);
6143 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6145 di << "TEST : Can't find plane\n";
6149 aDir = aPln.Axis().Direction();
6152 if (Plane.Orientation() == TopAbs_REVERSED)
6154 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6156 BRepOffsetAPI_DraftAngle Draft (Solid);
6158 if(Abs(anAngle)< Precision::Angular()) {
6159 di << "TEST : NULL angle\n";
6162 if(Rev) anAngle = - anAngle;
6163 Draft.Add (Face, aDir, anAngle, aPln);
6165 if (!Draft.IsDone()) {
6166 di << "TEST : Draft Not DONE \n";
6169 TopTools_ListOfShape Larg;
6171 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6172 di << "TEST : DesignAlgo returns Not valid\n";
6176 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6177 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6179 if ( !ais.IsNull() ) {
6180 ais->SetColor(DEFAULT_COLOR);
6181 ais->SetMaterial(DEFAULT_MATERIAL);
6182 // Display the AIS_Shape without redraw
6183 Ctx->Display(ais, Standard_False);
6185 const char *Name = "draft1";
6186 Handle(AIS_InteractiveObject) an_object;
6187 if (GetMapOfAIS().Find2(Name, an_object))
6189 if (!an_object.IsNull())
6191 Ctx->Remove (an_object, Standard_True);
6193 GetMapOfAIS().UnBind2 (Name);
6195 GetMapOfAIS().Bind(ais, Name);
6196 // DBRep::Set("draft", ais->Shape());
6198 Ctx->Display(ais, Standard_True);
6202 //==============================================================================
6203 //function : splitParameter
6204 //purpose : Split parameter string to parameter name and parameter value
6205 //==============================================================================
6206 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6207 TCollection_AsciiString& theName,
6208 TCollection_AsciiString& theValue)
6210 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6212 if (aParamNameEnd == 0)
6214 return Standard_False;
6217 TCollection_AsciiString aString (theString);
6218 if (aParamNameEnd != 0)
6220 theValue = aString.Split (aParamNameEnd);
6221 aString.Split (aString.Length() - 1);
6225 return Standard_True;
6228 //============================================================================
6230 //============================================================================
6231 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6234 DrawTrSurf::BasicCommands(theCommands);
6235 const char* group = "Check Features Operations commands";
6237 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6239 &TDraft,group); //Draft_Modification
6242 //==============================================================================
6243 // ViewerTest::Factory
6244 //==============================================================================
6245 void ViewerTest::Factory(Draw_Interpretor& theDI)
6247 // definition of Viewer Command
6248 ViewerTest::Commands(theDI);
6251 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6255 // Declare entry point PLUGINFACTORY