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 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
18 // Modified by Robert Coublanc [nov 16-17-18 1998]
19 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
20 // ViewerTest_ObjectCommands.cxx
21 // ViewerTest_RelationCommands.cxx
22 // -add Functions and commands for interactive selection of shapes and objects
23 // in AIS Viewers. (PickShape(s), PickObject(s),
25 #include <Standard_Stream.hxx>
27 #include <ViewerTest.hxx>
28 #include <ViewerTest_CmdParser.hxx>
31 #include <TopLoc_Location.hxx>
32 #include <TopTools_HArray1OfShape.hxx>
33 #include <TColStd_HArray1OfTransient.hxx>
34 #include <TColStd_SequenceOfAsciiString.hxx>
35 #include <TColStd_HSequenceOfAsciiString.hxx>
36 #include <TColStd_MapOfTransient.hxx>
37 #include <OSD_Timer.hxx>
38 #include <Geom_Axis2Placement.hxx>
39 #include <Geom_Axis1Placement.hxx>
40 #include <gp_Trsf.hxx>
41 #include <TopExp_Explorer.hxx>
42 #include <BRepAdaptor_Curve.hxx>
43 #include <StdSelect_ShapeTypeFilter.hxx>
45 #include <AIS_ColoredShape.hxx>
46 #include <AIS_InteractiveObject.hxx>
47 #include <AIS_Trihedron.hxx>
48 #include <AIS_Axis.hxx>
49 #include <AIS_Relation.hxx>
50 #include <AIS_TypeFilter.hxx>
51 #include <AIS_SignatureFilter.hxx>
52 #include <AIS_LocalContext.hxx>
53 #include <AIS_ListOfInteractive.hxx>
54 #include <AIS_ListIteratorOfListOfInteractive.hxx>
55 #include <Aspect_InteriorStyle.hxx>
56 #include <Aspect_Window.hxx>
57 #include <Graphic3d_AspectFillArea3d.hxx>
58 #include <Graphic3d_AspectLine3d.hxx>
59 #include <Graphic3d_CStructure.hxx>
60 #include <Graphic3d_TextureRoot.hxx>
61 #include <Image_AlienPixMap.hxx>
62 #include <Prs3d_Drawer.hxx>
63 #include <Prs3d_ShadingAspect.hxx>
64 #include <Prs3d_IsoAspect.hxx>
65 #include <Prs3d_PointAspect.hxx>
66 #include <Select3D_SensitiveWire.hxx>
67 #include <Select3D_SensitivePrimitiveArray.hxx>
68 #include <SelectMgr_EntityOwner.hxx>
69 #include <StdSelect_BRepOwner.hxx>
70 #include <StdSelect_ViewerSelector3d.hxx>
71 #include <TopTools_MapOfShape.hxx>
72 #include <ViewerTest_AutoUpdater.hxx>
76 #include <Draw_Interpretor.hxx>
77 #include <TCollection_AsciiString.hxx>
78 #include <Draw_PluginMacro.hxx>
80 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
82 #include <Quantity_Color.hxx>
83 #include <Quantity_NameOfColor.hxx>
85 #include <Graphic3d_NameOfMaterial.hxx>
87 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
88 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
89 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
91 //=======================================================================
92 //function : GetColorFromName
93 //purpose : get the Quantity_NameOfColor from a string
94 //=======================================================================
96 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
98 Quantity_NameOfColor aColor = DEFAULT_COLOR;
99 Quantity_Color::ColorFromName (theName, aColor);
103 //=======================================================================
104 //function : ParseColor
106 //=======================================================================
108 Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
109 const char** theArgVec,
110 Quantity_Color& theColor)
112 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
114 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
119 else if (theArgNb >= 3)
121 const TCollection_AsciiString anRgbStr[3] =
127 if (!anRgbStr[0].IsRealValue()
128 || !anRgbStr[1].IsRealValue()
129 || !anRgbStr[2].IsRealValue())
134 Graphic3d_Vec4d anRgb;
135 anRgb.x() = anRgbStr[0].RealValue();
136 anRgb.y() = anRgbStr[1].RealValue();
137 anRgb.z() = anRgbStr[2].RealValue();
138 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
139 || anRgb.y() < 0.0 || anRgb.y() > 1.0
140 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
142 std::cout << "Error: RGB color values should be within range 0..1!\n";
146 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
153 //=======================================================================
154 //function : ParseOnOff
156 //=======================================================================
157 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
158 Standard_Boolean& theIsOn)
160 TCollection_AsciiString aFlag(theArg);
165 theIsOn = Standard_True;
166 return Standard_True;
168 else if (aFlag == "off"
171 theIsOn = Standard_False;
172 return Standard_True;
174 return Standard_False;
177 //=======================================================================
178 //function : GetSelectedShapes
180 //=======================================================================
181 void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
183 for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
185 TopoDS_Shape aShape = GetAISContext()->SelectedShape();
186 if (!aShape.IsNull())
188 theSelectedShapes.Append (aShape);
193 //=======================================================================
194 //function : ParseLineType
196 //=======================================================================
197 Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
198 Aspect_TypeOfLine& theType)
200 TCollection_AsciiString aTypeStr (theArg);
201 aTypeStr.LowerCase();
202 if (aTypeStr == "empty")
204 theType = Aspect_TOL_EMPTY;
206 else if (aTypeStr == "solid")
208 theType = Aspect_TOL_SOLID;
210 else if (aTypeStr == "dot")
212 theType = Aspect_TOL_DOT;
214 else if (aTypeStr == "dash")
216 theType = Aspect_TOL_DASH;
218 else if (aTypeStr == "dotdash")
220 theType = Aspect_TOL_DOTDASH;
224 const int aTypeInt = Draw::Atoi (theArg);
225 if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
227 return Standard_False;
229 theType = (Aspect_TypeOfLine )aTypeInt;
231 return Standard_True;
234 //=======================================================================
235 //function : GetTypeNames
237 //=======================================================================
238 static const char** GetTypeNames()
240 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
241 "Shape","ConnectedShape","MultiConn.Shape",
242 "ConnectedInter.","MultiConn.",
243 "Constraint","Dimension"};
244 static const char** ThePointer = names;
248 //=======================================================================
249 //function : GetTypeAndSignfromString
251 //=======================================================================
252 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
254 const char ** thefullnames = GetTypeNames();
255 Standard_Integer index(-1);
257 for(Standard_Integer i=0;i<=13 && index==-1;i++)
258 if(!strcasecmp(name,thefullnames[i]))
262 TheType = AIS_KOI_None;
268 TheType = AIS_KOI_Datum;
272 TheType = AIS_KOI_Shape;
276 TheType = AIS_KOI_Object;
280 TheType = AIS_KOI_Relation;
289 #include <Draw_Interpretor.hxx>
291 #include <Draw_Appli.hxx>
295 #include <TCollection_AsciiString.hxx>
296 #include <V3d_Viewer.hxx>
297 #include <V3d_View.hxx>
300 #include <AIS_InteractiveContext.hxx>
301 #include <AIS_Shape.hxx>
302 #include <AIS_TexturedShape.hxx>
303 #include <AIS_DisplayMode.hxx>
304 #include <TColStd_MapOfInteger.hxx>
305 #include <AIS_MapOfInteractive.hxx>
306 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
307 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
308 #include <ViewerTest_EventManager.hxx>
310 #include <TopoDS_Solid.hxx>
311 #include <BRepTools.hxx>
312 #include <BRep_Builder.hxx>
313 #include <TopAbs_ShapeEnum.hxx>
315 #include <TopoDS.hxx>
316 #include <BRep_Tool.hxx>
319 #include <Draw_Window.hxx>
320 #include <AIS_ListIteratorOfListOfInteractive.hxx>
321 #include <AIS_ListOfInteractive.hxx>
322 #include <AIS_DisplayMode.hxx>
323 #include <TopTools_ListOfShape.hxx>
324 #include <BRepOffsetAPI_MakeThickSolid.hxx>
325 #include <BRepOffset.hxx>
327 //==============================================================================
328 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
329 //==============================================================================
330 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
331 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
335 //=======================================================================
338 //=======================================================================
339 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
340 const Handle(AIS_InteractiveObject)& theObject,
341 const Standard_Boolean theToUpdate,
342 const Standard_Boolean theReplaceIfExists)
344 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
345 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
348 std::cout << "Error: AIS context is not available.\n";
349 return Standard_False;
352 if (aMap.IsBound2 (theName))
354 if (!theReplaceIfExists)
356 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
357 << "Please use another name.\n";
358 return Standard_False;
361 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
362 if (!anOldObj.IsNull())
364 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
366 aMap.UnBind2 (theName);
369 if (theObject.IsNull())
371 // object with specified name has been already unbound
372 return Standard_True;
375 // unbind AIS object if it was bound with another name
376 aMap.UnBind1 (theObject);
378 // can be registered without rebinding
379 aMap.Bind (theObject, theName);
380 aCtx->Display (theObject, theToUpdate);
381 return Standard_True;
384 //! Alias for ViewerTest::Display(), compatibility with old code.
385 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
386 const Handle(AIS_InteractiveObject)& theObject,
387 Standard_Boolean theReplaceIfExists = Standard_True)
389 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
392 static TColStd_MapOfInteger theactivatedmodes(8);
393 static TColStd_ListOfTransient theEventMgrs;
395 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
396 const Handle(AIS_InteractiveContext)& Ctx)
398 theEventMgrs.Clear();
399 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
402 static Handle(V3d_View)& a3DView()
404 static Handle(V3d_View) Viou;
409 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
410 static Handle(AIS_InteractiveContext) aContext;
414 const Handle(V3d_View)& ViewerTest::CurrentView()
418 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
423 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
425 return TheAISContext();
428 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
430 TheAISContext() = aCtx;
431 ViewerTest::ResetEventManager();
434 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
436 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
439 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
441 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
445 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
446 theEventMgrs.Prepend(EM);
449 void ViewerTest::UnsetEventManager()
451 theEventMgrs.RemoveFirst();
455 void ViewerTest::ResetEventManager()
457 const Handle(V3d_View) aView = ViewerTest::CurrentView();
458 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
461 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
463 Handle(ViewerTest_EventManager) EM;
464 if(theEventMgrs.IsEmpty()) return EM;
465 Handle(Standard_Transient) Tr = theEventMgrs.First();
466 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
470 //=======================================================================
471 //function : Get Context and active view
473 //=======================================================================
474 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
475 Handle(V3d_View)& theView)
477 theCtx = ViewerTest::GetAISContext();
478 theView = ViewerTest::CurrentView();
482 std::cout << "Error: cannot find an active view!\n";
483 return Standard_False;
485 return Standard_True;
488 //==============================================================================
489 //function : GetShapeFromName
490 //purpose : Compute an Shape from a draw variable or a file name
491 //==============================================================================
493 static TopoDS_Shape GetShapeFromName(const char* name)
495 TopoDS_Shape S = DBRep::Get(name);
498 BRep_Builder aBuilder;
499 BRepTools::Read( S, name, aBuilder);
505 //==============================================================================
506 //function : GetAISShapeFromName
507 //purpose : Compute an AIS_Shape from a draw variable or a file name
508 //==============================================================================
509 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
511 Handle(AIS_Shape) retsh;
513 if(GetMapOfAIS().IsBound2(name)){
514 const Handle(AIS_InteractiveObject) IO =
515 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
517 if(IO->Type()==AIS_KOI_Shape) {
518 if(IO->Signature()==0){
519 retsh = Handle(AIS_Shape)::DownCast (IO);
522 cout << "an Object which is not an AIS_Shape "
523 "already has this name!!!"<<endl;
530 TopoDS_Shape S = GetShapeFromName(name);
532 retsh = new AIS_Shape(S);
538 //==============================================================================
540 //purpose : Remove all the object from the viewer
541 //==============================================================================
542 void ViewerTest::Clear()
544 if ( !a3DView().IsNull() ) {
545 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
546 while ( it.More() ) {
547 cout << "Remove " << it.Key2() << endl;
548 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
549 TheAISContext()->Remove(anObj,Standard_False);
552 TheAISContext()->RebuildSelectionStructs();
553 TheAISContext()->UpdateCurrentViewer();
554 GetMapOfAIS().Clear();
558 //==============================================================================
559 //function : StandardModesActivation
560 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
562 //==============================================================================
563 Standard_DISABLE_DEPRECATION_WARNINGS
564 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
566 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
568 if (TheAISContext()->HasOpenedContext())
570 aContext->CloseLocalContext();
574 if(!aContext->HasOpenedContext()) {
575 // To unhilight the preselected object
576 aContext->UnhilightSelected(Standard_False);
577 // Open a local Context in order to be able to select subshape from
578 // the selected shape if any or for all if there is no selection
579 if (!aContext->FirstSelectedObject().IsNull()){
580 aContext->OpenLocalContext(Standard_False);
582 for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
583 aContext->Load( aContext->SelectedInteractive(),-1,Standard_True);
588 aContext->OpenLocalContext();
592 const char *cmode="???";
595 case 0: cmode = "Shape"; break;
596 case 1: cmode = "Vertex"; break;
597 case 2: cmode = "Edge"; break;
598 case 3: cmode = "Wire"; break;
599 case 4: cmode = "Face"; break;
600 case 5: cmode = "Shell"; break;
601 case 6: cmode = "Solid"; break;
602 case 7: cmode = "Compsolid"; break;
603 case 8: cmode = "Compound"; break;
606 if(theactivatedmodes.Contains(mode))
608 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
609 theactivatedmodes.Remove(mode);
610 cout<<"Mode "<< cmode <<" OFF"<<endl;
614 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
615 theactivatedmodes.Add(mode);
616 cout<<"Mode "<< cmode << " ON" << endl;
620 Standard_ENABLE_DEPRECATION_WARNINGS
622 //==============================================================================
623 //function : CopyIsoAspect
624 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
625 //==============================================================================
626 static Handle(Prs3d_IsoAspect) CopyIsoAspect
627 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
628 const Standard_Integer theNbIsos)
630 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
631 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
632 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
634 Handle(Prs3d_IsoAspect) aResult =
635 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
640 //==============================================================================
642 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
643 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
644 //==============================================================================
645 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
647 if (TheAISContext().IsNull()) {
648 di << argv[0] << " Call 'vinit' before!\n";
653 di << "Current number of isos : " <<
654 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
655 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
656 di << "IsoOnPlane mode is " <<
657 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
658 di << "IsoOnTriangulation mode is " <<
659 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
663 Standard_Integer aLastInd = argc - 1;
664 Standard_Boolean isChanged = Standard_False;
665 Standard_Integer aNbUIsos = 0;
666 Standard_Integer aNbVIsos = 0;
669 Standard_Boolean isIsoOnPlane = Standard_False;
671 if (strcmp(argv[aLastInd], "1") == 0) {
672 isIsoOnPlane = Standard_True;
673 isChanged = Standard_True;
674 } else if (strcmp(argv[aLastInd], "0") == 0) {
675 isIsoOnPlane = Standard_False;
676 isChanged = Standard_True;
680 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
681 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
684 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
685 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
687 TheAISContext()->IsoOnPlane(isIsoOnPlane);
690 // If there are no shapes provided set the default numbers.
691 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
692 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
699 for (i = 1; i <= aLastInd; i++) {
700 TCollection_AsciiString name(argv[i]);
701 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
704 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
705 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
706 const Handle(AIS_InteractiveObject) aShape =
707 Handle(AIS_InteractiveObject)::DownCast (anObj);
708 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
709 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
710 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
713 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
714 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
715 TheAISContext()->SetLocalAttributes
716 (aShape, CurDrawer, Standard_False);
717 TheAISContext()->Redisplay (aShape, Standard_False);
719 di << "Number of isos for " << argv[i] << " : "
720 << aUIso->Number() << " " << aVIso->Number() << "\n";
723 di << argv[i] << ": Not an AIS interactive object!\n";
726 di << argv[i] << ": Use 'vdisplay' before\n";
731 TheAISContext()->UpdateCurrentViewer();
737 static Standard_Integer VDispSensi (Draw_Interpretor& ,
738 Standard_Integer theArgNb,
743 std::cout << "Error: wrong syntax!\n";
747 Handle(AIS_InteractiveContext) aCtx;
748 Handle(V3d_View) aView;
749 if (!getCtxAndView (aCtx, aView))
754 aCtx->DisplayActiveSensitive (aView);
759 static Standard_Integer VClearSensi (Draw_Interpretor& ,
760 Standard_Integer theArgNb,
765 std::cout << "Error: wrong syntax!\n";
769 Handle(AIS_InteractiveContext) aCtx;
770 Handle(V3d_View) aView;
771 if (!getCtxAndView (aCtx, aView))
775 aCtx->ClearActiveSensitive (aView);
779 //==============================================================================
781 //purpose : To list the displayed object with their attributes
782 //==============================================================================
783 static int VDir (Draw_Interpretor& theDI,
787 if (!a3DView().IsNull())
792 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
793 anIter.More(); anIter.Next())
795 theDI << "\t" << anIter.Key2().ToCString() << "\n";
800 //! Auxiliary enumeration
801 enum ViewerTest_StereoPair
803 ViewerTest_SP_Single,
804 ViewerTest_SP_SideBySide,
805 ViewerTest_SP_OverUnder
808 //==============================================================================
810 //purpose : To dump the active view snapshot to image file
811 //==============================================================================
812 static Standard_Integer VDump (Draw_Interpretor& theDI,
813 Standard_Integer theArgNb,
814 Standard_CString* theArgVec)
818 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
822 Standard_Integer anArgIter = 1;
823 Standard_CString aFilePath = theArgVec[anArgIter++];
824 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
825 V3d_ImageDumpOptions aParams;
826 aParams.BufferType = Graphic3d_BT_RGB;
827 aParams.StereoOptions = V3d_SDO_MONO;
828 for (; anArgIter < theArgNb; ++anArgIter)
830 TCollection_AsciiString anArg (theArgVec[anArgIter]);
832 if (anArg == "-buffer")
834 if (++anArgIter >= theArgNb)
836 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
840 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
842 if (aBufArg == "rgba")
844 aParams.BufferType = Graphic3d_BT_RGBA;
846 else if (aBufArg == "rgb")
848 aParams.BufferType = Graphic3d_BT_RGB;
850 else if (aBufArg == "depth")
852 aParams.BufferType = Graphic3d_BT_Depth;
856 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
860 else if (anArg == "-stereo")
862 if (++anArgIter >= theArgNb)
864 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
868 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
869 aStereoArg.LowerCase();
870 if (aStereoArg == "l"
871 || aStereoArg == "left")
873 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
875 else if (aStereoArg == "r"
876 || aStereoArg == "right")
878 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
880 else if (aStereoArg == "mono")
882 aParams.StereoOptions = V3d_SDO_MONO;
884 else if (aStereoArg == "blended"
885 || aStereoArg == "blend"
886 || aStereoArg == "stereo")
888 aParams.StereoOptions = V3d_SDO_BLENDED;
890 else if (aStereoArg == "sbs"
891 || aStereoArg == "sidebyside")
893 aStereoPair = ViewerTest_SP_SideBySide;
895 else if (aStereoArg == "ou"
896 || aStereoArg == "overunder")
898 aStereoPair = ViewerTest_SP_OverUnder;
902 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
906 else if (anArg == "-rgba"
909 aParams.BufferType = Graphic3d_BT_RGBA;
911 else if (anArg == "-rgb"
914 aParams.BufferType = Graphic3d_BT_RGB;
916 else if (anArg == "-depth"
919 aParams.BufferType = Graphic3d_BT_Depth;
921 else if (anArg == "-width"
925 if (aParams.Width != 0)
927 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
930 else if (++anArgIter >= theArgNb)
932 std::cout << "Error: integer value is expected right after 'width'\n";
935 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
937 else if (anArg == "-height"
939 || anArg == "-sizey")
941 if (aParams.Height != 0)
943 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
946 else if (++anArgIter >= theArgNb)
948 std::cout << "Error: integer value is expected right after 'height'\n";
951 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
953 else if (anArg == "-tile"
954 || anArg == "-tilesize")
956 if (++anArgIter >= theArgNb)
958 std::cout << "Error: integer value is expected right after 'tileSize'\n";
961 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
965 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
969 if ((aParams.Width <= 0 && aParams.Height > 0)
970 || (aParams.Width > 0 && aParams.Height <= 0))
972 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
976 Handle(V3d_View) aView = ViewerTest::CurrentView();
979 std::cout << "Error: cannot find an active view!\n";
983 if (aParams.Width <= 0 || aParams.Height <= 0)
985 aView->Window()->Size (aParams.Width, aParams.Height);
988 Image_AlienPixMap aPixMap;
989 Image_Format aFormat = Image_Format_UNKNOWN;
990 switch (aParams.BufferType)
992 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
993 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
994 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
999 case ViewerTest_SP_Single:
1001 if (!aView->ToPixMap (aPixMap, aParams))
1003 theDI << "Fail: view dump failed!\n";
1006 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1007 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1009 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1010 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1014 case ViewerTest_SP_SideBySide:
1016 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1018 theDI << "Fail: not enough memory for image allocation!\n";
1022 Image_PixMap aPixMapL, aPixMapR;
1023 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1024 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1025 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1026 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1028 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1029 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1030 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1031 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1034 theDI << "Fail: view dump failed!\n";
1039 case ViewerTest_SP_OverUnder:
1041 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1043 theDI << "Fail: not enough memory for image allocation!\n";
1047 Image_PixMap aPixMapL, aPixMapR;
1048 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1049 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1050 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1051 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1053 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1054 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1055 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1056 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1059 theDI << "Fail: view dump failed!\n";
1066 if (!aPixMap.Save (aFilePath))
1068 theDI << "Fail: image can not be saved!\n";
1073 enum TypeOfDispOperation
1075 TypeOfDispOperation_SetDispMode,
1076 TypeOfDispOperation_UnsetDispMode
1079 //! Displays,Erase...
1080 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1081 const Standard_Integer theMode,
1082 const TypeOfDispOperation theType,
1083 const Standard_Boolean theToUpdate)
1085 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1088 case TypeOfDispOperation_SetDispMode:
1090 if (!thePrs.IsNull())
1092 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1096 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1100 case TypeOfDispOperation_UnsetDispMode:
1102 if (!thePrs.IsNull())
1104 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1108 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1115 //=======================================================================
1118 //=======================================================================
1119 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1124 std::cout << "Syntax error: wrong number of arguments\n";
1128 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1129 ? TypeOfDispOperation_UnsetDispMode
1130 : TypeOfDispOperation_SetDispMode;
1131 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1132 if (aType == TypeOfDispOperation_UnsetDispMode)
1136 if (aCtx->NbSelected() == 0)
1138 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1142 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1144 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1147 aCtx->UpdateCurrentViewer();
1151 TCollection_AsciiString aName = argv[1];
1152 if (GetMapOfAIS().IsBound2 (aName))
1154 Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1157 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1164 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1165 if (aCtx->NbSelected() == 0
1166 && aType == TypeOfDispOperation_SetDispMode)
1168 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1170 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1172 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1174 aCtx->UpdateCurrentViewer();
1178 Handle(AIS_InteractiveObject) aPrs;
1179 TCollection_AsciiString aName (argv[1]);
1180 if (GetMapOfAIS().IsBound2 (aName))
1182 aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1186 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1193 //=======================================================================
1196 //=======================================================================
1197 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1199 if(argc==1) return 1;
1200 Standard_Integer On = Draw::Atoi(argv[1]);
1201 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1205 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1206 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1207 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1211 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1215 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1219 Ctx->UpdateCurrentViewer();
1222 Handle(AIS_InteractiveObject) IO;
1223 TCollection_AsciiString name = argv[2];
1224 if(GetMapOfAIS().IsBound2(name)){
1225 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1228 Ctx->SubIntensityOn(IO, Standard_True);
1230 Ctx->SubIntensityOff(IO, Standard_True);
1238 //! Auxiliary class to iterate presentations from different collections.
1239 class ViewTest_PrsIter
1243 //! Create and initialize iterator object.
1244 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1245 : mySource (IterSource_All)
1247 NCollection_Sequence<TCollection_AsciiString> aNames;
1248 if (!theName.IsEmpty())
1249 aNames.Append (theName);
1253 //! Create and initialize iterator object.
1254 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1255 : mySource (IterSource_All)
1260 //! Initialize the iterator.
1261 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1263 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1265 mySelIter.Nullify();
1266 myCurrent.Nullify();
1267 myCurrentTrs.Nullify();
1268 if (!mySeq.IsEmpty())
1270 mySource = IterSource_List;
1271 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1273 else if (aCtx->NbSelected() > 0)
1275 mySource = IterSource_Selected;
1277 mySelIter->InitSelected();
1281 mySource = IterSource_All;
1282 myMapIter.Initialize (GetMapOfAIS());
1287 const TCollection_AsciiString& CurrentName() const
1289 return myCurrentName;
1292 const Handle(AIS_InteractiveObject)& Current() const
1297 const Handle(Standard_Transient)& CurrentTrs() const
1299 return myCurrentTrs;
1302 //! @return true if iterator points to valid object within collection
1303 Standard_Boolean More() const
1307 case IterSource_All: return myMapIter.More();
1308 case IterSource_List: return mySeqIter.More();
1309 case IterSource_Selected: return mySelIter->MoreSelected();
1311 return Standard_False;
1314 //! Go to the next item.
1317 myCurrentName.Clear();
1318 myCurrentTrs.Nullify();
1319 myCurrent.Nullify();
1322 case IterSource_All:
1327 case IterSource_List:
1332 case IterSource_Selected:
1334 mySelIter->NextSelected();
1347 case IterSource_All:
1349 if (myMapIter.More())
1351 myCurrentName = myMapIter.Key2();
1352 myCurrentTrs = myMapIter.Key1();
1353 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1357 case IterSource_List:
1359 if (mySeqIter.More())
1361 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1363 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1366 myCurrentName = mySeqIter.Value();
1367 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1368 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1372 case IterSource_Selected:
1374 if (mySelIter->MoreSelected())
1376 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1377 myCurrent = mySelIter->SelectedInteractive();
1395 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1396 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1397 NCollection_Sequence<TCollection_AsciiString> mySeq;
1398 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1400 TCollection_AsciiString myCurrentName;//!< current item name
1401 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1402 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1404 IterSource mySource; //!< iterated collection
1408 //==============================================================================
1409 //function : VInteriorStyle
1410 //purpose : sets interior style of the a selected or named or displayed shape
1411 //==============================================================================
1412 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1413 Standard_Integer theArgNb,
1414 const char** theArgVec)
1416 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1417 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1420 std::cerr << "Error: no active view!\n";
1424 Standard_Integer anArgIter = 1;
1425 for (; anArgIter < theArgNb; ++anArgIter)
1427 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1432 TCollection_AsciiString aName;
1433 if (theArgNb - anArgIter == 2)
1435 aName = theArgVec[anArgIter++];
1437 else if (theArgNb - anArgIter != 1)
1439 std::cout << "Error: wrong number of arguments! See usage:\n";
1440 theDI.PrintHelp (theArgVec[0]);
1443 Aspect_InteriorStyle anInterStyle = Aspect_IS_SOLID;
1444 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1445 aStyleArg.LowerCase();
1446 if (aStyleArg == "empty")
1448 anInterStyle = Aspect_IS_EMPTY;
1450 else if (aStyleArg == "hollow")
1452 anInterStyle = Aspect_IS_HOLLOW;
1454 else if (aStyleArg == "hatch")
1456 anInterStyle = Aspect_IS_HATCH;
1458 else if (aStyleArg == "solid")
1460 anInterStyle = Aspect_IS_SOLID;
1462 else if (aStyleArg == "hiddenline")
1464 anInterStyle = Aspect_IS_HIDDENLINE;
1466 else if (aStyleArg == "point")
1468 anInterStyle = Aspect_IS_POINT;
1472 const Standard_Integer anIntStyle = aStyleArg.IntegerValue();
1473 if (anIntStyle < Aspect_IS_EMPTY
1474 || anIntStyle > Aspect_IS_POINT)
1476 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1477 << Aspect_IS_POINT << " (Aspect_IS_POINT)]\n";
1480 anInterStyle = (Aspect_InteriorStyle )anIntStyle;
1483 if (!aName.IsEmpty()
1484 && !GetMapOfAIS().IsBound2 (aName))
1486 std::cout << "Error: object " << aName << " is not displayed!\n";
1490 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1492 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1495 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1496 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1497 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1498 aFillAspect->SetInteriorStyle (anInterStyle);
1499 if (anInterStyle == Aspect_IS_HATCH
1500 && aFillAspect->HatchStyle().IsNull())
1502 aFillAspect->SetHatchStyle (Aspect_HS_VERTICAL);
1504 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1510 //! Auxiliary structure for VAspects
1511 struct ViewerTest_AspectsChangeSet
1513 Standard_Integer ToSetVisibility;
1514 Standard_Integer Visibility;
1516 Standard_Integer ToSetColor;
1517 Quantity_Color Color;
1519 Standard_Integer ToSetLineWidth;
1520 Standard_Real LineWidth;
1522 Standard_Integer ToSetTypeOfLine;
1523 Aspect_TypeOfLine TypeOfLine;
1525 Standard_Integer ToSetTransparency;
1526 Standard_Real Transparency;
1528 Standard_Integer ToSetMaterial;
1529 Graphic3d_NameOfMaterial Material;
1530 TCollection_AsciiString MatName;
1532 NCollection_Sequence<TopoDS_Shape> SubShapes;
1534 Standard_Integer ToSetShowFreeBoundary;
1535 Standard_Integer ToSetFreeBoundaryWidth;
1536 Standard_Real FreeBoundaryWidth;
1537 Standard_Integer ToSetFreeBoundaryColor;
1538 Quantity_Color FreeBoundaryColor;
1540 Standard_Integer ToEnableIsoOnTriangulation;
1542 Standard_Integer ToSetMaxParamValue;
1543 Standard_Real MaxParamValue;
1545 Standard_Integer ToSetSensitivity;
1546 Standard_Integer SelectionMode;
1547 Standard_Integer Sensitivity;
1549 Standard_Integer ToSetHatch;
1550 Standard_Integer StdHatchStyle;
1551 TCollection_AsciiString PathToHatchPattern;
1553 //! Empty constructor
1554 ViewerTest_AspectsChangeSet()
1555 : ToSetVisibility (0),
1558 Color (DEFAULT_COLOR),
1561 ToSetTypeOfLine (0),
1562 TypeOfLine (Aspect_TOL_SOLID),
1563 ToSetTransparency (0),
1566 Material (Graphic3d_NOM_DEFAULT),
1567 ToSetShowFreeBoundary (0),
1568 ToSetFreeBoundaryWidth (0),
1569 FreeBoundaryWidth (1.0),
1570 ToSetFreeBoundaryColor (0),
1571 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1572 ToEnableIsoOnTriangulation (-1),
1573 ToSetMaxParamValue (0),
1574 MaxParamValue (500000),
1575 ToSetSensitivity (0),
1582 //! @return true if no changes have been requested
1583 Standard_Boolean IsEmpty() const
1585 return ToSetVisibility == 0
1586 && ToSetLineWidth == 0
1587 && ToSetTransparency == 0
1589 && ToSetMaterial == 0
1590 && ToSetShowFreeBoundary == 0
1591 && ToSetFreeBoundaryColor == 0
1592 && ToSetFreeBoundaryWidth == 0
1593 && ToSetMaxParamValue == 0
1594 && ToSetSensitivity == 0
1598 //! @return true if properties are valid
1599 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1601 Standard_Boolean isOk = Standard_True;
1602 if (Visibility != 0 && Visibility != 1)
1604 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1605 isOk = Standard_False;
1607 if (LineWidth <= 0.0
1608 || LineWidth > 10.0)
1610 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1611 isOk = Standard_False;
1613 if (Transparency < 0.0
1614 || Transparency > 1.0)
1616 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1617 isOk = Standard_False;
1620 && ToSetTransparency)
1622 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1623 isOk = Standard_False;
1625 if (ToSetMaterial == 1
1626 && Material == Graphic3d_NOM_DEFAULT)
1628 std::cout << "Error: unknown material " << MatName << ".\n";
1629 isOk = Standard_False;
1631 if (FreeBoundaryWidth <= 0.0
1632 || FreeBoundaryWidth > 10.0)
1634 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1635 isOk = Standard_False;
1637 if (MaxParamValue < 0.0)
1639 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1640 isOk = Standard_False;
1642 if (Sensitivity <= 0 && ToSetSensitivity)
1644 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1645 isOk = Standard_False;
1647 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1649 std::cout << "Error: hatch style must be specified\n";
1650 isOk = Standard_False;
1657 //==============================================================================
1658 //function : VAspects
1660 //==============================================================================
1661 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1662 Standard_Integer theArgNb,
1663 const char** theArgVec)
1665 TCollection_AsciiString aCmdName (theArgVec[0]);
1666 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1667 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1670 std::cerr << "Error: no active view!\n";
1674 Standard_Integer anArgIter = 1;
1675 Standard_Boolean isDefaults = Standard_False;
1676 NCollection_Sequence<TCollection_AsciiString> aNames;
1677 for (; anArgIter < theArgNb; ++anArgIter)
1679 TCollection_AsciiString anArg = theArgVec[anArgIter];
1680 if (anUpdateTool.parseRedrawMode (anArg))
1684 else if (!anArg.IsEmpty()
1685 && anArg.Value (1) != '-')
1687 aNames.Append (anArg);
1691 if (anArg == "-defaults")
1693 isDefaults = Standard_True;
1700 if (!aNames.IsEmpty() && isDefaults)
1702 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1706 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1707 aChanges.Append (ViewerTest_AspectsChangeSet());
1708 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1710 // parse syntax of legacy commands
1711 if (aCmdName == "vsetwidth")
1713 if (aNames.IsEmpty()
1714 || !aNames.Last().IsRealValue())
1716 std::cout << "Error: not enough arguments!\n";
1719 aChangeSet->ToSetLineWidth = 1;
1720 aChangeSet->LineWidth = aNames.Last().RealValue();
1721 aNames.Remove (aNames.Length());
1723 else if (aCmdName == "vunsetwidth")
1725 aChangeSet->ToSetLineWidth = -1;
1727 else if (aCmdName == "vsetcolor")
1729 if (aNames.IsEmpty())
1731 std::cout << "Error: not enough arguments!\n";
1734 aChangeSet->ToSetColor = 1;
1736 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1737 Standard_Boolean isOk = Standard_False;
1738 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1740 aChangeSet->Color = aColor;
1741 aNames.Remove (aNames.Length());
1742 isOk = Standard_True;
1744 else if (aNames.Length() >= 3)
1746 const TCollection_AsciiString anRgbStr[3] =
1748 aNames.Value (aNames.Upper() - 2),
1749 aNames.Value (aNames.Upper() - 1),
1750 aNames.Value (aNames.Upper() - 0)
1752 isOk = anRgbStr[0].IsRealValue()
1753 && anRgbStr[1].IsRealValue()
1754 && anRgbStr[2].IsRealValue();
1757 Graphic3d_Vec4d anRgb;
1758 anRgb.x() = anRgbStr[0].RealValue();
1759 anRgb.y() = anRgbStr[1].RealValue();
1760 anRgb.z() = anRgbStr[2].RealValue();
1761 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1762 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1763 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1765 std::cout << "Error: RGB color values should be within range 0..1!\n";
1768 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1769 aNames.Remove (aNames.Length());
1770 aNames.Remove (aNames.Length());
1771 aNames.Remove (aNames.Length());
1776 std::cout << "Error: not enough arguments!\n";
1780 else if (aCmdName == "vunsetcolor")
1782 aChangeSet->ToSetColor = -1;
1784 else if (aCmdName == "vsettransparency")
1786 if (aNames.IsEmpty()
1787 || !aNames.Last().IsRealValue())
1789 std::cout << "Error: not enough arguments!\n";
1792 aChangeSet->ToSetTransparency = 1;
1793 aChangeSet->Transparency = aNames.Last().RealValue();
1794 aNames.Remove (aNames.Length());
1796 else if (aCmdName == "vunsettransparency")
1798 aChangeSet->ToSetTransparency = -1;
1800 else if (aCmdName == "vsetmaterial")
1802 if (aNames.IsEmpty())
1804 std::cout << "Error: not enough arguments!\n";
1807 aChangeSet->ToSetMaterial = 1;
1808 aChangeSet->MatName = aNames.Last();
1809 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1810 aNames.Remove (aNames.Length());
1812 else if (aCmdName == "vunsetmaterial")
1814 aChangeSet->ToSetMaterial = -1;
1816 else if (anArgIter >= theArgNb)
1818 std::cout << "Error: not enough arguments!\n";
1822 if (!aChangeSet->IsEmpty())
1824 anArgIter = theArgNb;
1826 for (; anArgIter < theArgNb; ++anArgIter)
1828 TCollection_AsciiString anArg = theArgVec[anArgIter];
1830 if (anArg == "-setwidth"
1831 || anArg == "-setlinewidth")
1833 if (++anArgIter >= theArgNb)
1835 std::cout << "Error: wrong syntax at " << anArg << "\n";
1838 aChangeSet->ToSetLineWidth = 1;
1839 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1841 else if (anArg == "-unsetwidth"
1842 || anArg == "-unsetlinewidth")
1844 aChangeSet->ToSetLineWidth = -1;
1845 aChangeSet->LineWidth = 1.0;
1847 else if (anArg == "-settransp"
1848 || anArg == "-settransparency")
1850 if (++anArgIter >= theArgNb)
1852 std::cout << "Error: wrong syntax at " << anArg << "\n";
1855 aChangeSet->ToSetTransparency = 1;
1856 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1857 if (aChangeSet->Transparency >= 0.0
1858 && aChangeSet->Transparency <= Precision::Confusion())
1860 aChangeSet->ToSetTransparency = -1;
1861 aChangeSet->Transparency = 0.0;
1864 else if (anArg == "-setvis"
1865 || anArg == "-setvisibility")
1867 if (++anArgIter >= theArgNb)
1869 std::cout << "Error: wrong syntax at " << anArg << "\n";
1873 aChangeSet->ToSetVisibility = 1;
1874 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1876 else if (anArg == "-setalpha")
1878 if (++anArgIter >= theArgNb)
1880 std::cout << "Error: wrong syntax at " << anArg << "\n";
1883 aChangeSet->ToSetTransparency = 1;
1884 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1885 if (aChangeSet->Transparency < 0.0
1886 || aChangeSet->Transparency > 1.0)
1888 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1891 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1892 if (aChangeSet->Transparency >= 0.0
1893 && aChangeSet->Transparency <= Precision::Confusion())
1895 aChangeSet->ToSetTransparency = -1;
1896 aChangeSet->Transparency = 0.0;
1899 else if (anArg == "-unsettransp"
1900 || anArg == "-unsettransparency"
1901 || anArg == "-unsetalpha"
1902 || anArg == "-opaque")
1904 aChangeSet->ToSetTransparency = -1;
1905 aChangeSet->Transparency = 0.0;
1907 else if (anArg == "-setcolor")
1909 Standard_Integer aNbComps = 0;
1910 Standard_Integer aCompIter = anArgIter + 1;
1911 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1913 if (theArgVec[aCompIter][0] == '-')
1922 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1923 Standard_CString aName = theArgVec[anArgIter + 1];
1924 if (!Quantity_Color::ColorFromName (aName, aColor))
1926 std::cout << "Error: unknown color name '" << aName << "'\n";
1929 aChangeSet->Color = aColor;
1934 Graphic3d_Vec3d anRgb;
1935 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1936 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1937 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1938 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1939 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1940 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1942 std::cout << "Error: RGB color values should be within range 0..1!\n";
1945 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1950 std::cout << "Error: wrong syntax at " << anArg << "\n";
1954 aChangeSet->ToSetColor = 1;
1955 anArgIter += aNbComps;
1957 else if (anArg == "-setlinetype")
1959 if (++anArgIter >= theArgNb)
1961 std::cout << "Error: wrong syntax at " << anArg << "\n";
1964 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aChangeSet->TypeOfLine))
1966 std::cout << "Error: wrong syntax at " << anArg << "\n";
1970 aChangeSet->ToSetTypeOfLine = 1;
1972 else if (anArg == "-unsetlinetype")
1974 aChangeSet->ToSetTypeOfLine = -1;
1976 else if (anArg == "-unsetcolor")
1978 aChangeSet->ToSetColor = -1;
1979 aChangeSet->Color = DEFAULT_COLOR;
1981 else if (anArg == "-setmat"
1982 || anArg == "-setmaterial")
1984 if (++anArgIter >= theArgNb)
1986 std::cout << "Error: wrong syntax at " << anArg << "\n";
1989 aChangeSet->ToSetMaterial = 1;
1990 aChangeSet->MatName = theArgVec[anArgIter];
1991 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1993 else if (anArg == "-unsetmat"
1994 || anArg == "-unsetmaterial")
1996 aChangeSet->ToSetMaterial = -1;
1997 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1999 else if (anArg == "-subshape"
2000 || anArg == "-subshapes")
2004 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2008 if (aNames.IsEmpty())
2010 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2014 aChanges.Append (ViewerTest_AspectsChangeSet());
2015 aChangeSet = &aChanges.ChangeLast();
2017 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2019 Standard_CString aSubShapeName = theArgVec[anArgIter];
2020 if (*aSubShapeName == '-')
2026 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2027 if (aSubShape.IsNull())
2029 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2032 aChangeSet->SubShapes.Append (aSubShape);
2035 if (aChangeSet->SubShapes.IsEmpty())
2037 std::cerr << "Error: empty list is specified after -subshapes!\n";
2041 else if (anArg == "-freeboundary"
2044 if (++anArgIter >= theArgNb)
2046 std::cout << "Error: wrong syntax at " << anArg << "\n";
2049 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2054 aChangeSet->ToSetShowFreeBoundary = 1;
2056 else if (aValue == "off"
2059 aChangeSet->ToSetShowFreeBoundary = -1;
2063 std::cout << "Error: wrong syntax at " << anArg << "\n";
2067 else if (anArg == "-setfreeboundarywidth"
2068 || anArg == "-setfbwidth")
2070 if (++anArgIter >= theArgNb)
2072 std::cout << "Error: wrong syntax at " << anArg << "\n";
2075 aChangeSet->ToSetFreeBoundaryWidth = 1;
2076 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2078 else if (anArg == "-unsetfreeboundarywidth"
2079 || anArg == "-unsetfbwidth")
2081 aChangeSet->ToSetFreeBoundaryWidth = -1;
2082 aChangeSet->FreeBoundaryWidth = 1.0;
2084 else if (anArg == "-setfreeboundarycolor"
2085 || anArg == "-setfbcolor")
2087 Standard_Integer aNbComps = 0;
2088 Standard_Integer aCompIter = anArgIter + 1;
2089 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2091 if (theArgVec[aCompIter][0] == '-')
2100 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2101 Standard_CString aName = theArgVec[anArgIter + 1];
2102 if (!Quantity_Color::ColorFromName (aName, aColor))
2104 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2107 aChangeSet->FreeBoundaryColor = aColor;
2112 Graphic3d_Vec3d anRgb;
2113 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2114 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2115 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2116 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2117 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2118 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2120 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2123 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2128 std::cout << "Error: wrong syntax at " << anArg << "\n";
2132 aChangeSet->ToSetFreeBoundaryColor = 1;
2133 anArgIter += aNbComps;
2135 else if (anArg == "-unsetfreeboundarycolor"
2136 || anArg == "-unsetfbcolor")
2138 aChangeSet->ToSetFreeBoundaryColor = -1;
2139 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2141 else if (anArg == "-unset")
2143 aChangeSet->ToSetVisibility = 1;
2144 aChangeSet->Visibility = 1;
2145 aChangeSet->ToSetLineWidth = -1;
2146 aChangeSet->LineWidth = 1.0;
2147 aChangeSet->ToSetTypeOfLine = -1;
2148 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2149 aChangeSet->ToSetTransparency = -1;
2150 aChangeSet->Transparency = 0.0;
2151 aChangeSet->ToSetColor = -1;
2152 aChangeSet->Color = DEFAULT_COLOR;
2153 aChangeSet->ToSetMaterial = -1;
2154 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2155 aChangeSet->ToSetShowFreeBoundary = -1;
2156 aChangeSet->ToSetFreeBoundaryColor = -1;
2157 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2158 aChangeSet->ToSetFreeBoundaryWidth = -1;
2159 aChangeSet->FreeBoundaryWidth = 1.0;
2160 aChangeSet->ToSetHatch = -1;
2161 aChangeSet->StdHatchStyle = -1;
2162 aChangeSet->PathToHatchPattern.Clear();
2164 else if (anArg == "-isoontriangulation"
2165 || anArg == "-isoontriang")
2167 if (++anArgIter >= theArgNb)
2169 std::cout << "Error: wrong syntax at " << anArg << "\n";
2172 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2177 aChangeSet->ToEnableIsoOnTriangulation = 1;
2179 else if (aValue == "off"
2182 aChangeSet->ToEnableIsoOnTriangulation = 0;
2186 std::cout << "Error: wrong syntax at " << anArg << "\n";
2190 else if (anArg == "-setmaxparamvalue")
2192 if (++anArgIter >= theArgNb)
2194 std::cout << "Error: wrong syntax at " << anArg << "\n";
2197 aChangeSet->ToSetMaxParamValue = 1;
2198 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2200 else if (anArg == "-setsensitivity")
2204 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2208 if (aNames.IsEmpty())
2210 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2214 if (anArgIter + 2 >= theArgNb)
2216 std::cout << "Error: wrong syntax at " << anArg << "\n";
2219 aChangeSet->ToSetSensitivity = 1;
2220 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2221 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2223 else if (anArg == "-sethatch")
2227 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2231 if (aNames.IsEmpty())
2233 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2237 aChangeSet->ToSetHatch = 1;
2238 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
2239 if (anArgHatch.Length() <= 2)
2241 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
2243 || anIntStyle >= Aspect_HS_NB)
2245 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
2248 aChangeSet->StdHatchStyle = anIntStyle;
2252 aChangeSet->PathToHatchPattern = anArgHatch;
2257 std::cout << "Error: wrong syntax at " << anArg << "\n";
2262 Standard_Boolean isFirst = Standard_True;
2263 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2264 aChangesIter.More(); aChangesIter.Next())
2266 if (!aChangesIter.Value().Validate (!isFirst))
2270 isFirst = Standard_False;
2273 // special case for -defaults parameter.
2274 // all changed values will be set to DefaultDrawer.
2277 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2279 if (aChangeSet->ToSetLineWidth != 0)
2281 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2282 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2283 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2284 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2286 if (aChangeSet->ToSetColor != 0)
2288 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2289 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2290 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2291 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2292 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2293 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2295 if (aChangeSet->ToSetTypeOfLine != 0)
2297 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2298 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2299 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2300 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2301 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2303 if (aChangeSet->ToSetTransparency != 0)
2305 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2307 if (aChangeSet->ToSetMaterial != 0)
2309 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2311 if (aChangeSet->ToSetShowFreeBoundary == 1)
2313 aDrawer->SetFreeBoundaryDraw (Standard_True);
2315 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2317 aDrawer->SetFreeBoundaryDraw (Standard_False);
2319 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2321 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2323 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2325 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2327 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2329 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2331 if (aChangeSet->ToSetMaxParamValue != 0)
2333 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2336 // redisplay all objects in context
2337 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2339 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2342 aCtx->Redisplay (aPrs, Standard_False);
2348 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2350 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2351 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2352 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2353 Handle(AIS_ColoredShape) aColoredPrs;
2354 Standard_Boolean toDisplay = Standard_False;
2355 Standard_Boolean toRedisplay = Standard_False;
2356 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2358 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2359 if (aShapePrs.IsNull())
2361 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2364 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2365 if (aColoredPrs.IsNull())
2367 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2368 if (aShapePrs->HasDisplayMode())
2370 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2372 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2373 aCtx->Remove (aShapePrs, Standard_False);
2374 GetMapOfAIS().UnBind2 (aName);
2375 GetMapOfAIS().Bind (aColoredPrs, aName);
2376 toDisplay = Standard_True;
2377 aShapePrs = aColoredPrs;
2384 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2385 aChangeSet = &aChangesIter.ChangeValue();
2386 if (aChangeSet->ToSetVisibility == 1)
2388 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2389 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2391 else if (aChangeSet->ToSetMaterial == 1)
2393 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2395 else if (aChangeSet->ToSetMaterial == -1)
2397 aCtx->UnsetMaterial (aPrs, Standard_False);
2399 if (aChangeSet->ToSetColor == 1)
2401 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2403 else if (aChangeSet->ToSetColor == -1)
2405 aCtx->UnsetColor (aPrs, Standard_False);
2407 if (aChangeSet->ToSetTransparency == 1)
2409 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2411 else if (aChangeSet->ToSetTransparency == -1)
2413 aCtx->UnsetTransparency (aPrs, Standard_False);
2415 if (aChangeSet->ToSetLineWidth == 1)
2417 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2419 else if (aChangeSet->ToSetLineWidth == -1)
2421 aCtx->UnsetWidth (aPrs, Standard_False);
2423 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2425 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2426 toRedisplay = Standard_True;
2428 else if (aChangeSet->ToSetSensitivity != 0)
2430 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2432 if (!aDrawer.IsNull())
2434 if (aChangeSet->ToSetShowFreeBoundary == 1)
2436 aDrawer->SetFreeBoundaryDraw (Standard_True);
2437 toRedisplay = Standard_True;
2439 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2441 aDrawer->SetFreeBoundaryDraw (Standard_False);
2442 toRedisplay = Standard_True;
2444 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2446 Handle(Prs3d_LineAspect) aBoundaryAspect =
2447 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2448 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2449 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2450 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2451 toRedisplay = Standard_True;
2453 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2455 Handle(Prs3d_LineAspect) aBoundaryAspect =
2456 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2457 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2458 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2459 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2460 toRedisplay = Standard_True;
2462 if (aChangeSet->ToSetTypeOfLine != 0)
2464 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2465 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2466 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2467 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2468 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2469 toRedisplay = Standard_True;
2471 if (aChangeSet->ToSetMaxParamValue != 0)
2473 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2475 if (aChangeSet->ToSetHatch != 0)
2477 if (!aDrawer->HasOwnShadingAspect())
2479 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2480 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2483 Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
2484 if (aChangeSet->ToSetHatch == -1)
2486 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2490 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2491 if (!aChangeSet->PathToHatchPattern.IsEmpty())
2493 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2494 if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
2496 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2500 std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
2504 else if (aChangeSet->StdHatchStyle != -1)
2506 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
2509 toRedisplay = Standard_True;
2513 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2515 aChangeSet = &aChangesIter.ChangeValue();
2516 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2517 aSubShapeIter.More(); aSubShapeIter.Next())
2519 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2520 if (aChangeSet->ToSetVisibility == 1)
2522 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2523 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2525 if (aChangeSet->ToSetColor == 1)
2527 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2529 if (aChangeSet->ToSetLineWidth == 1)
2531 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2533 if (aChangeSet->ToSetColor == -1
2534 || aChangeSet->ToSetLineWidth == -1)
2536 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2538 if (aChangeSet->ToSetMaxParamValue != 0)
2540 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2541 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2543 if (aChangeSet->ToSetSensitivity != 0)
2545 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2551 aCtx->Display (aPrs, Standard_False);
2555 aCtx->Redisplay (aPrs, Standard_False);
2557 else if (!aColoredPrs.IsNull())
2559 aCtx->Redisplay (aColoredPrs, Standard_False);
2566 //==============================================================================
2567 //function : VDonly2
2569 //purpose : Display only a selected or named object
2570 // if there is no selected or named object s, nothing is done
2571 //==============================================================================
2572 static int VDonly2 (Draw_Interpretor& ,
2573 Standard_Integer theArgNb,
2574 const char** theArgVec)
2576 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2577 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2580 std::cerr << "Error: no active view!\n";
2584 Standard_DISABLE_DEPRECATION_WARNINGS
2585 if (aCtx->HasOpenedContext())
2587 aCtx->CloseLocalContext();
2589 Standard_ENABLE_DEPRECATION_WARNINGS
2591 Standard_Integer anArgIter = 1;
2592 for (; anArgIter < theArgNb; ++anArgIter)
2594 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2600 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2601 if (anArgIter >= theArgNb)
2603 // display only selected objects
2604 if (aCtx->NbSelected() < 1)
2609 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2611 aDispSet.Add (aCtx->SelectedInteractive());
2616 // display only specified objects
2617 for (; anArgIter < theArgNb; ++anArgIter)
2619 TCollection_AsciiString aName = theArgVec[anArgIter];
2620 if (GetMapOfAIS().IsBound2 (aName))
2622 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2623 if (!aShape.IsNull())
2625 aCtx->Display (aShape, Standard_False);
2626 aDispSet.Add (aShape);
2632 // weed out other objects
2633 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2635 if (aDispSet.Contains (anIter.Key1()))
2640 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2641 if (aShape.IsNull())
2643 aCtx->Erase (aShape, Standard_False);
2649 //==============================================================================
2650 //function : VRemove
2651 //purpose : Removes selected or named objects.
2652 // If there is no selected or named objects,
2653 // all objects in the viewer can be removed with argument -all.
2654 // If -context is in arguments, the object is not deleted from the map of
2655 // objects (deleted only from the current context).
2656 //==============================================================================
2657 int VRemove (Draw_Interpretor& theDI,
2658 Standard_Integer theArgNb,
2659 const char** theArgVec)
2661 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2662 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2665 std::cerr << "Error: no active view!\n";
2669 Standard_Boolean isContextOnly = Standard_False;
2670 Standard_Boolean toRemoveAll = Standard_False;
2671 Standard_Boolean toPrintInfo = Standard_True;
2672 Standard_Boolean toRemoveLocal = Standard_False;
2674 Standard_Integer anArgIter = 1;
2675 for (; anArgIter < theArgNb; ++anArgIter)
2677 TCollection_AsciiString anArg = theArgVec[anArgIter];
2679 if (anArg == "-context")
2681 isContextOnly = Standard_True;
2683 else if (anArg == "-all")
2685 toRemoveAll = Standard_True;
2687 else if (anArg == "-noinfo")
2689 toPrintInfo = Standard_False;
2691 else if (anArg == "-local")
2693 toRemoveLocal = Standard_True;
2695 else if (anUpdateTool.parseRedrawMode (anArg))
2705 && anArgIter < theArgNb)
2707 std::cerr << "Error: wrong syntax!\n";
2711 Standard_DISABLE_DEPRECATION_WARNINGS
2712 if (toRemoveLocal && !aCtx->HasOpenedContext())
2714 std::cerr << "Error: local selection context is not open.\n";
2717 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2719 aCtx->CloseAllContexts (Standard_False);
2721 Standard_ENABLE_DEPRECATION_WARNINGS
2723 NCollection_List<TCollection_AsciiString> anIONameList;
2726 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2727 anIter.More(); anIter.Next())
2729 anIONameList.Append (anIter.Key2());
2732 else if (anArgIter < theArgNb) // removed objects names are in argument list
2734 for (; anArgIter < theArgNb; ++anArgIter)
2736 TCollection_AsciiString aName = theArgVec[anArgIter];
2737 if (!GetMapOfAIS().IsBound2 (aName))
2739 theDI << aName.ToCString() << " was not bound to some object.\n";
2743 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2744 if (anIO->GetContext() != aCtx)
2746 theDI << aName.ToCString() << " was not displayed in current context.\n";
2747 theDI << "Please activate view with this object displayed and try again.\n";
2751 anIONameList.Append (aName);
2755 else if (aCtx->NbSelected() > 0)
2757 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2758 anIter.More(); anIter.Next())
2760 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2761 if (!aCtx->IsSelected (anIO))
2766 anIONameList.Append (anIter.Key2());
2771 // Unbind all removed objects from the map of displayed IO.
2772 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2773 anIter.More(); anIter.Next())
2775 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2776 aCtx->Remove (anIO, Standard_False);
2779 theDI << anIter.Value().ToCString() << " was removed\n";
2783 GetMapOfAIS().UnBind2 (anIter.Value());
2787 // Close local context if it is empty
2788 TColStd_MapOfTransient aLocalIO;
2789 Standard_DISABLE_DEPRECATION_WARNINGS
2790 if (aCtx->HasOpenedContext()
2791 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2793 aCtx->CloseAllContexts (Standard_False);
2795 Standard_ENABLE_DEPRECATION_WARNINGS
2800 //==============================================================================
2802 //purpose : Erase some selected or named objects
2803 // if there is no selected or named objects, the whole viewer is erased
2804 //==============================================================================
2805 int VErase (Draw_Interpretor& theDI,
2806 Standard_Integer theArgNb,
2807 const char** theArgVec)
2809 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2810 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2811 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2814 std::cerr << "Error: no active view!\n";
2818 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2820 Standard_Integer anArgIter = 1;
2821 Standard_Boolean toEraseLocal = Standard_False;
2822 Standard_Boolean toEraseInView = Standard_False;
2823 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2824 for (; anArgIter < theArgNb; ++anArgIter)
2826 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2827 anArgCase.LowerCase();
2828 if (anUpdateTool.parseRedrawMode (anArgCase))
2832 else if (anArgCase == "-local")
2834 toEraseLocal = Standard_True;
2836 else if (anArgCase == "-view"
2837 || anArgCase == "-inview")
2839 toEraseInView = Standard_True;
2843 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2847 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2849 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2853 Standard_DISABLE_DEPRECATION_WARNINGS
2854 if (toEraseLocal && !aCtx->HasOpenedContext())
2856 std::cerr << "Error: local selection context is not open.\n";
2859 else if (!toEraseLocal && aCtx->HasOpenedContext())
2861 aCtx->CloseAllContexts (Standard_False);
2863 Standard_ENABLE_DEPRECATION_WARNINGS
2865 if (!aNamesOfEraseIO.IsEmpty())
2867 // Erase named objects
2868 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2870 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2871 if (!GetMapOfAIS().IsBound2 (aName))
2876 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2877 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2878 theDI << aName.ToCString() << " ";
2883 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2887 aCtx->Erase (anIO, Standard_False);
2892 else if (!toEraseAll && aCtx->NbSelected() > 0)
2894 // Erase selected objects
2895 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
2896 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2897 anIter.More(); anIter.Next())
2899 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2901 && aCtx->IsSelected (anIO))
2903 theDI << anIter.Key2().ToCString() << " ";
2906 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2908 else if (aHasOpenedContext)
2910 aCtx->Erase (anIO, Standard_False);
2917 aCtx->EraseSelected (Standard_False);
2922 // Erase all objects
2923 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2924 anIter.More(); anIter.Next())
2926 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2931 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2935 aCtx->Erase (anIO, Standard_False);
2944 //==============================================================================
2945 //function : VDisplayAll
2947 //purpose : Display all the objects of the Map
2948 //==============================================================================
2949 static int VDisplayAll (Draw_Interpretor& ,
2950 Standard_Integer theArgNb,
2951 const char** theArgVec)
2954 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2955 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2958 std::cerr << "Error: no active view!\n";
2962 Standard_Integer anArgIter = 1;
2963 Standard_Boolean toDisplayLocal = Standard_False;
2964 for (; anArgIter < theArgNb; ++anArgIter)
2966 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2967 anArgCase.LowerCase();
2968 if (anArgCase == "-local")
2970 toDisplayLocal = Standard_True;
2972 else if (anUpdateTool.parseRedrawMode (anArgCase))
2981 if (anArgIter < theArgNb)
2983 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2987 Standard_DISABLE_DEPRECATION_WARNINGS
2988 if (toDisplayLocal && !aCtx->HasOpenedContext())
2990 std::cerr << "Error: local selection context is not open.\n";
2993 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2995 aCtx->CloseLocalContext (Standard_False);
2997 Standard_ENABLE_DEPRECATION_WARNINGS
2999 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3000 anIter.More(); anIter.Next())
3002 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3003 aCtx->Erase (aShape, Standard_False);
3006 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3007 anIter.More(); anIter.Next())
3009 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3010 aCtx->Display (aShape, Standard_False);
3015 //! Auxiliary method to check if presentation exists
3016 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3017 const Handle(AIS_InteractiveObject)& theIO,
3018 const Standard_Integer theMode)
3020 if (theIO.IsNull() || theCtx.IsNull())
3027 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3032 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3034 return theIO->DisplayMode();
3036 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3038 return theCtx->DisplayMode();
3044 enum ViewerTest_BndAction
3051 //! Auxiliary method to print bounding box of presentation
3052 inline void bndPresentation (Draw_Interpretor& theDI,
3053 const Handle(PrsMgr_PresentationManager)& theMgr,
3054 const Handle(AIS_InteractiveObject)& theObj,
3055 const Standard_Integer theDispMode,
3056 const TCollection_AsciiString& theName,
3057 const ViewerTest_BndAction theAction,
3058 const Handle(Prs3d_Drawer)& theStyle)
3062 case BndAction_Hide:
3064 theMgr->Unhighlight (theObj);
3067 case BndAction_Show:
3069 theMgr->Color (theObj, theStyle, theDispMode);
3072 case BndAction_Print:
3075 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3077 if (aPrsIter.Value().Mode() != theDispMode)
3080 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3082 gp_Pnt aMin = aBox.CornerMin();
3083 gp_Pnt aMax = aBox.CornerMax();
3084 theDI << theName << "\n"
3085 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3086 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
3092 //==============================================================================
3093 //function : VBounding
3095 //==============================================================================
3096 int VBounding (Draw_Interpretor& theDI,
3097 Standard_Integer theArgNb,
3098 const char** theArgVec)
3100 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3101 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3104 std::cout << "Error: no active view!\n";
3108 ViewerTest_BndAction anAction = BndAction_Show;
3109 Standard_Integer aMode = -1;
3111 Handle(Prs3d_Drawer) aStyle;
3113 Standard_Integer anArgIter = 1;
3114 for (; anArgIter < theArgNb; ++anArgIter)
3116 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3118 if (anArg == "-print")
3120 anAction = BndAction_Print;
3122 else if (anArg == "-show")
3124 anAction = BndAction_Show;
3126 else if (anArg == "-hide")
3128 anAction = BndAction_Hide;
3130 else if (anArg == "-mode")
3132 if (++anArgIter >= theArgNb)
3134 std::cout << "Error: wrong syntax at " << anArg << "\n";
3137 aMode = Draw::Atoi (theArgVec[anArgIter]);
3139 else if (!anUpdateTool.parseRedrawMode (anArg))
3145 if (anAction == BndAction_Show)
3147 aStyle = new Prs3d_Drawer();
3148 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3149 aStyle->SetColor (Quantity_NOC_GRAY99);
3152 Standard_Integer aHighlightedMode = -1;
3153 if (anArgIter < theArgNb)
3155 // has a list of names
3156 for (; anArgIter < theArgNb; ++anArgIter)
3158 TCollection_AsciiString aName = theArgVec[anArgIter];
3159 if (!GetMapOfAIS().IsBound2 (aName))
3161 std::cout << "Error: presentation " << aName << " does not exist\n";
3165 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3166 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3167 if (aHighlightedMode == -1)
3169 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3172 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3175 else if (aCtx->NbSelected() > 0)
3177 // remove all currently selected objects
3178 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3180 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3181 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3182 if (aHighlightedMode != -1)
3184 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3185 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3192 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3193 anIter.More(); anIter.Next())
3195 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3196 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3197 if (aHighlightedMode != -1)
3199 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3206 //==============================================================================
3207 //function : VTexture
3209 //==============================================================================
3210 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
3212 TCollection_AsciiString aCommandName (theArgv[0]);
3214 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3215 if (aCommandName == "vtexture")
3219 std::cout << theArgv[0] << ": invalid arguments.\n";
3220 std::cout << "Type help for more information.\n";
3224 // look for options of vtexture command
3225 TCollection_AsciiString aParseKey;
3226 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3228 TCollection_AsciiString anArg (theArgv [anArgIt]);
3231 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3234 aParseKey.Remove (1);
3235 aParseKey.UpperCase();
3236 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3240 if (aParseKey.IsEmpty())
3245 aMapOfArgs(aParseKey)->Append (anArg);
3248 else if (aCommandName == "vtexscale"
3249 || aCommandName == "vtexorigin"
3250 || aCommandName == "vtexrepeat")
3252 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3253 // equal to -scale, -origin, -repeat options of vtexture command
3254 if (theArgsNb < 2 || theArgsNb > 4)
3256 std::cout << theArgv[0] << ": invalid arguments.\n";
3257 std::cout << "Type help for more information.\n";
3261 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
3264 anArgs->Append ("OFF");
3266 else if (theArgsNb == 4)
3268 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3269 anArgs->Append (TCollection_AsciiString (theArgv[3]));
3272 TCollection_AsciiString anArgKey;
3273 if (aCommandName == "vtexscale")
3277 else if (aCommandName == "vtexorigin")
3279 anArgKey = "ORIGIN";
3283 anArgKey = "REPEAT";
3286 aMapOfArgs.Bind (anArgKey, anArgs);
3288 else if (aCommandName == "vtexdefault")
3290 // scan for parameters of vtexdefault command
3291 // equal to -default option of vtexture command
3292 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
3295 // Check arguments for validity
3296 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3297 for (; aMapIt.More(); aMapIt.Next())
3299 const TCollection_AsciiString& aKey = aMapIt.Key();
3300 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3302 // -scale, -origin, -repeat: one argument "off", or two real values
3303 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3304 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3305 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3310 // -modulate: single argument "on" / "off"
3311 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3316 // -default: no arguments
3317 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3322 TCollection_AsciiString aLowerKey;
3325 aLowerKey.LowerCase();
3326 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3327 std::cout << "Type help for more information.\n";
3331 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3332 if (anAISContext.IsNull())
3334 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
3338 Standard_Integer aPreviousMode = 0;
3340 TCollection_AsciiString aShapeName (theArgv[1]);
3341 Handle(AIS_InteractiveObject) anIO;
3343 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3344 if (aMapOfIO.IsBound2 (aShapeName))
3346 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3351 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3355 Handle(AIS_TexturedShape) aTexturedIO;
3356 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3358 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3359 aPreviousMode = aTexturedIO->DisplayMode();
3363 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3365 if (anIO->HasTransformation())
3367 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3368 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3371 anAISContext->Remove (anIO, Standard_False);
3372 GetMapOfAIS().UnBind1 (anIO);
3373 GetMapOfAIS().UnBind2 (aShapeName);
3374 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3377 // -------------------------------------------
3378 // Turn texturing on/off - only for vtexture
3379 // -------------------------------------------
3381 if (aCommandName == "vtexture")
3383 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3385 if (aTextureArg.IsEmpty())
3387 std::cout << aCommandName << ": Texture mapping disabled.\n";
3388 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
3390 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3391 if (aPreviousMode == 3)
3393 anAISContext->RecomputePrsOnly (aTexturedIO, Standard_False);
3396 anAISContext->Display (aTexturedIO, Standard_True);
3399 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3401 if (aTextureArg == "?")
3403 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3405 theDi << "\n Files in current directory : \n\n";
3406 theDi.Eval ("glob -nocomplain *");
3408 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3409 aCmnd += aTextureFolder;
3412 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
3413 theDi.Eval (aCmnd.ToCString());
3418 aTexturedIO->SetTextureFileName (aTextureArg);
3423 // ------------------------------------
3424 // Process other options and commands
3425 // ------------------------------------
3427 Handle(TColStd_HSequenceOfAsciiString) aValues;
3428 if (aMapOfArgs.Find ("DEFAULT", aValues))
3430 aTexturedIO->SetTextureRepeat (Standard_False);
3431 aTexturedIO->SetTextureOrigin (Standard_False);
3432 aTexturedIO->SetTextureScale (Standard_False);
3433 aTexturedIO->EnableTextureModulate();
3437 if (aMapOfArgs.Find ("SCALE", aValues))
3439 if (aValues->Value(1) != "OFF")
3441 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3445 aTexturedIO->SetTextureScale (Standard_False);
3449 if (aMapOfArgs.Find ("ORIGIN", aValues))
3451 if (aValues->Value(1) != "OFF")
3453 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3457 aTexturedIO->SetTextureOrigin (Standard_False);
3461 if (aMapOfArgs.Find ("REPEAT", aValues))
3463 if (aValues->Value(1) != "OFF")
3465 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3469 aTexturedIO->SetTextureRepeat (Standard_False);
3473 if (aMapOfArgs.Find ("MODULATE", aValues))
3475 if (aValues->Value(1) == "ON")
3477 aTexturedIO->EnableTextureModulate();
3481 aTexturedIO->DisableTextureModulate();
3486 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3488 anAISContext->RecomputePrsOnly (aTexturedIO, Standard_True);
3492 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3493 anAISContext->Display (aTexturedIO, Standard_True);
3494 anAISContext->Update (aTexturedIO,Standard_True);
3500 //! Auxiliary method to parse transformation persistence flags
3501 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3502 Graphic3d_TransModeFlags& theFlags)
3504 if (theFlagString == "zoom")
3506 theFlags = Graphic3d_TMF_ZoomPers;
3508 else if (theFlagString == "rotate")
3510 theFlags = Graphic3d_TMF_RotatePers;
3512 else if (theFlagString == "zoomrotate")
3514 theFlags = Graphic3d_TMF_ZoomRotatePers;
3516 else if (theFlagString == "trihedron"
3517 || theFlagString == "triedron")
3519 theFlags = Graphic3d_TMF_TriedronPers;
3521 else if (theFlagString == "none")
3523 theFlags = Graphic3d_TMF_None;
3527 return Standard_False;
3530 return Standard_True;
3533 //! Auxiliary method to parse transformation persistence flags
3534 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
3535 Aspect_TypeOfTriedronPosition& theCorner)
3537 TCollection_AsciiString aString (theString);
3538 aString.LowerCase();
3539 if (aString == "center")
3541 theCorner = Aspect_TOTP_CENTER;
3543 else if (aString == "top"
3544 || aString == "upper")
3546 theCorner = Aspect_TOTP_TOP;
3548 else if (aString == "bottom"
3549 || aString == "lower")
3551 theCorner = Aspect_TOTP_BOTTOM;
3553 else if (aString == "left")
3555 theCorner = Aspect_TOTP_LEFT;
3557 else if (aString == "right")
3559 theCorner = Aspect_TOTP_RIGHT;
3561 else if (aString == "topleft"
3562 || aString == "leftupper"
3563 || aString == "upperleft")
3565 theCorner = Aspect_TOTP_LEFT_UPPER;
3567 else if (aString == "bottomleft"
3568 || aString == "leftlower"
3569 || aString == "lowerleft")
3571 theCorner = Aspect_TOTP_LEFT_LOWER;
3573 else if (aString == "topright"
3574 || aString == "rightupper"
3575 || aString == "upperright")
3577 theCorner = Aspect_TOTP_RIGHT_UPPER;
3579 else if (aString == "bottomright"
3580 || aString == "lowerright"
3581 || aString == "rightlower")
3583 theCorner = Aspect_TOTP_RIGHT_LOWER;
3587 return Standard_False;
3590 return Standard_True;
3593 //==============================================================================
3594 //function : VDisplay2
3596 //purpose : Display an object from its name
3597 //==============================================================================
3598 static int VDisplay2 (Draw_Interpretor& theDI,
3599 Standard_Integer theArgNb,
3600 const char** theArgVec)
3604 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3608 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3611 ViewerTest::ViewerInit();
3612 aCtx = ViewerTest::GetAISContext();
3615 // Parse input arguments
3616 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3617 Standard_Integer isMutable = -1;
3618 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3619 Standard_Boolean toDisplayLocal = Standard_False;
3620 Standard_Boolean toReDisplay = Standard_False;
3621 Standard_Integer isSelectable = -1;
3622 Standard_Integer anObjDispMode = -2;
3623 Standard_Integer anObjHighMode = -2;
3624 Standard_Boolean toSetTrsfPers = Standard_False;
3625 Handle(Graphic3d_TransformPers) aTrsfPers;
3626 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3627 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3628 Standard_Integer toDisplayInView = Standard_False;
3629 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3631 const TCollection_AsciiString aName = theArgVec[anArgIter];
3632 TCollection_AsciiString aNameCase = aName;
3633 aNameCase.LowerCase();
3634 if (anUpdateTool.parseRedrawMode (aName))
3638 else if (aNameCase == "-mutable")
3642 else if (aNameCase == "-neutral")
3644 aDispStatus = AIS_DS_Displayed;
3646 else if (aNameCase == "-immediate"
3647 || aNameCase == "-top")
3649 aZLayer = Graphic3d_ZLayerId_Top;
3651 else if (aNameCase == "-topmost")
3653 aZLayer = Graphic3d_ZLayerId_Topmost;
3655 else if (aNameCase == "-osd"
3656 || aNameCase == "-toposd"
3657 || aNameCase == "-overlay")
3659 aZLayer = Graphic3d_ZLayerId_TopOSD;
3661 else if (aNameCase == "-botosd"
3662 || aNameCase == "-underlay")
3664 aZLayer = Graphic3d_ZLayerId_BotOSD;
3666 else if (aNameCase == "-select"
3667 || aNameCase == "-selectable")
3671 else if (aNameCase == "-noselect"
3672 || aNameCase == "-noselection")
3676 else if (aNameCase == "-dispmode"
3677 || aNameCase == "-displaymode")
3679 if (++anArgIter >= theArgNb)
3681 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3685 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3687 else if (aNameCase == "-highmode"
3688 || aNameCase == "-highlightmode")
3690 if (++anArgIter >= theArgNb)
3692 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3696 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3698 else if (aNameCase == "-3d")
3700 toSetTrsfPers = Standard_True;
3701 aTrsfPers.Nullify();
3703 else if (aNameCase == "-2d"
3704 || aNameCase == "-trihedron"
3705 || aNameCase == "-triedron")
3707 toSetTrsfPers = Standard_True;
3708 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3710 if (anArgIter + 1 < theArgNb)
3712 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
3713 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
3716 aTrsfPers->SetCorner2d (aCorner);
3718 if (anArgIter + 2 < theArgNb)
3720 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
3721 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
3722 if (anX.IsIntegerValue()
3723 && anY.IsIntegerValue())
3726 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
3732 else if (aNameCase == "-trsfpers"
3733 || aNameCase == "-pers")
3735 if (++anArgIter >= theArgNb
3736 || !aTrsfPers.IsNull())
3738 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3742 toSetTrsfPers = Standard_True;
3743 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3744 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3745 aPersFlags.LowerCase();
3746 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3748 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3752 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
3754 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3756 else if (aTrsfPersFlags != Graphic3d_TMF_None)
3758 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
3761 else if (aNameCase == "-trsfperspos"
3762 || aNameCase == "-perspos")
3764 if (anArgIter + 2 >= theArgNb
3765 || aTrsfPers.IsNull())
3767 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3771 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3772 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3773 TCollection_AsciiString aZ = "0";
3774 if (!aX.IsRealValue()
3775 || !aY.IsRealValue())
3777 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3780 if (anArgIter + 1 < theArgNb)
3782 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3783 if (aTemp.IsRealValue())
3790 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
3791 if (aTrsfPers->IsZoomOrRotate())
3793 aTrsfPers->SetAnchorPoint (aPnt);
3795 else if (aTrsfPers->IsTrihedronOr2d())
3797 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
3800 else if (aNameCase == "-layer")
3802 if (++anArgIter >= theArgNb)
3804 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3808 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3809 if (!aValue.IsIntegerValue())
3811 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3815 aZLayer = aValue.IntegerValue();
3817 else if (aNameCase == "-view"
3818 || aNameCase == "-inview")
3820 toDisplayInView = Standard_True;
3822 else if (aNameCase == "-local")
3824 aDispStatus = AIS_DS_Temporary;
3825 toDisplayLocal = Standard_True;
3827 else if (aNameCase == "-redisplay")
3829 toReDisplay = Standard_True;
3833 aNamesOfDisplayIO.Append (aName);
3837 if (aNamesOfDisplayIO.IsEmpty())
3839 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3843 // Prepare context for display
3844 Standard_DISABLE_DEPRECATION_WARNINGS
3845 if (toDisplayLocal && !aCtx->HasOpenedContext())
3847 aCtx->OpenLocalContext (Standard_False);
3849 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3851 aCtx->CloseAllContexts (Standard_False);
3853 Standard_ENABLE_DEPRECATION_WARNINGS
3855 // Display interactive objects
3856 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3858 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3860 if (!GetMapOfAIS().IsBound2 (aName))
3862 // create the AIS_Shape from a name
3863 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3864 if (!aShape.IsNull())
3866 if (isMutable != -1)
3868 aShape->SetMutable (isMutable == 1);
3870 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3872 aShape->SetZLayer (aZLayer);
3876 aCtx->SetTransformPersistence (aShape, aTrsfPers);
3878 if (anObjDispMode != -2)
3880 aShape->SetDisplayMode (anObjDispMode);
3882 if (anObjHighMode != -2)
3884 aShape->SetHilightMode (anObjHighMode);
3886 if (!toDisplayLocal)
3887 GetMapOfAIS().Bind (aShape, aName);
3889 Standard_Integer aDispMode = aShape->HasDisplayMode()
3890 ? aShape->DisplayMode()
3891 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3892 ? aCtx->DisplayMode()
3894 Standard_Integer aSelMode = -1;
3895 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3897 aSelMode = aShape->GlobalSelectionMode();
3900 aCtx->Display (aShape, aDispMode, aSelMode,
3901 Standard_False, aShape->AcceptShapeDecomposition(),
3903 if (toDisplayInView)
3905 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
3907 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
3909 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3914 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3919 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3920 if (isMutable != -1)
3922 aShape->SetMutable (isMutable == 1);
3924 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3926 aShape->SetZLayer (aZLayer);
3930 aCtx->SetTransformPersistence (aShape, aTrsfPers);
3932 if (anObjDispMode != -2)
3934 aShape->SetDisplayMode (anObjDispMode);
3936 if (anObjHighMode != -2)
3938 aShape->SetHilightMode (anObjHighMode);
3940 Standard_Integer aDispMode = aShape->HasDisplayMode()
3941 ? aShape->DisplayMode()
3942 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3943 ? aCtx->DisplayMode()
3945 Standard_Integer aSelMode = -1;
3946 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3948 aSelMode = aShape->GlobalSelectionMode();
3951 if (aShape->Type() == AIS_KOI_Datum)
3953 aCtx->Display (aShape, Standard_False);
3957 theDI << "Display " << aName.ToCString() << "\n";
3959 // update the Shape in the AIS_Shape
3960 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3961 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3962 if (!aShapePrs.IsNull())
3964 if (!aShapePrs->Shape().IsEqual (aNewShape))
3966 toReDisplay = Standard_True;
3968 aShapePrs->Set (aNewShape);
3972 aCtx->Redisplay (aShape, Standard_False);
3977 aCtx->Erase (aShape, Standard_False);
3979 aCtx->Display (aShape, aDispMode, aSelMode,
3980 Standard_False, aShape->AcceptShapeDecomposition(),
3982 if (toDisplayInView)
3984 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3992 //===============================================================================================
3993 //function : VUpdate
3995 //===============================================================================================
3996 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3998 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3999 if (aContextAIS.IsNull())
4001 std::cout << theArgVec[0] << "AIS context is not available.\n";
4007 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
4011 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
4013 AIS_ListOfInteractive aListOfIO;
4015 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4017 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
4019 Handle(AIS_InteractiveObject) anAISObj;
4020 if (anAISMap.IsBound2 (aName))
4022 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
4025 if (anAISObj.IsNull())
4027 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
4031 aListOfIO.Append (anAISObj);
4034 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
4035 for (; anIOIt.More(); anIOIt.Next())
4037 aContextAIS->Update (anIOIt.Value(), Standard_False);
4040 aContextAIS->UpdateCurrentViewer();
4045 //==============================================================================
4046 //function : VShading
4047 //purpose : Sharpen or roughten the quality of the shading
4048 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4049 //==============================================================================
4050 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4052 Standard_Real myDevCoef;
4053 Handle(AIS_InteractiveObject) TheAisIO;
4056 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4060 myDevCoef =Draw::Atof(argv[2]);
4063 TCollection_AsciiString name=argv[1];
4064 if (GetMapOfAIS().IsBound2(name ))
4065 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4066 if (TheAisIO.IsNull())
4067 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4070 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4072 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4074 TheAISContext()->Redisplay (TheAisIO, Standard_True);
4077 //==============================================================================
4078 //function : HaveMode
4079 //use : VActivatedModes
4080 //==============================================================================
4081 #include <TColStd_ListIteratorOfListOfInteger.hxx>
4083 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
4085 TColStd_ListOfInteger List;
4086 TheAISContext()->ActivatedModes (TheAisIO,List);
4087 TColStd_ListIteratorOfListOfInteger it;
4088 Standard_Boolean Found=Standard_False;
4089 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4090 if (it.Value()==mode ) Found=Standard_True;
4097 //==============================================================================
4098 //function : VActivatedMode
4100 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
4101 // (edges,vertex...)qui lui est propre et le mode de selection standard.
4102 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4103 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4104 // qu'un nom et qu'un mode.
4105 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4106 //==============================================================================
4107 #include <AIS_ListIteratorOfListOfInteractive.hxx>
4109 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4112 Standard_Boolean ThereIsName = Standard_False ;
4114 if(!a3DView().IsNull()){
4116 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
4117 // verification des arguments
4119 if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
4120 ThereIsName = (argc == 3);
4124 Standard_DISABLE_DEPRECATION_WARNINGS
4126 if (argc>1) {di<<" Syntaxe error\n";return 1;}
4128 di<<" R.A.Z de tous les modes de selecion\n";
4129 di<<" Fermeture du Context local\n";
4130 if (TheAISContext()->HasOpenedContext())
4132 TheAISContext()->CloseLocalContext();
4135 Standard_ENABLE_DEPRECATION_WARNINGS
4138 // IL n'y a aps de nom de shape passe en argument
4139 if (HaveToSet && !ThereIsName){
4140 Standard_Integer aMode=Draw::Atoi(argv [1]);
4142 const char *cmode="???";
4144 case 0: cmode = "Shape"; break;
4145 case 1: cmode = "Vertex"; break;
4146 case 2: cmode = "Edge"; break;
4147 case 3: cmode = "Wire"; break;
4148 case 4: cmode = "Face"; break;
4149 case 5: cmode = "Shell"; break;
4150 case 6: cmode = "Solid"; break;
4151 case 7: cmode = "Compound"; break;
4154 if( !TheAISContext()->HasOpenedContext() ) {
4155 // il n'y a pas de Context local d'ouvert
4156 // on en ouvre un et on charge toutes les shapes displayees
4157 // on load tous les objets displayees et on Activate les objets de la liste
4158 AIS_ListOfInteractive ListOfIO;
4159 // on sauve dans une AISListOfInteractive tous les objets currents
4160 if (TheAISContext()->NbSelected()>0 ){
4161 TheAISContext()->UnhilightSelected(Standard_False);
4163 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4164 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
4168 Standard_DISABLE_DEPRECATION_WARNINGS
4169 TheAISContext()->OpenLocalContext(Standard_False);
4170 Standard_ENABLE_DEPRECATION_WARNINGS
4171 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4174 Handle(AIS_InteractiveObject) aIO =
4175 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4177 TheAISContext()->Load(aIO,0,Standard_False);
4180 // traitement des objets qui etaient currents dans le Contexte global
4181 if (!ListOfIO.IsEmpty() ) {
4182 // il y avait des objets currents
4183 AIS_ListIteratorOfListOfInteractive iter;
4184 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4185 Handle(AIS_InteractiveObject) aIO=iter.Value();
4186 TheAISContext()->Activate(aIO,aMode);
4187 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4191 // On applique le mode a tous les objets displayes
4192 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4193 it2 (GetMapOfAIS());
4195 Handle(AIS_InteractiveObject) aIO =
4196 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4197 if (!aIO.IsNull()) {
4198 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4199 TheAISContext()->Activate(aIO,aMode);
4208 // un Context local est deja ouvert
4209 // Traitement des objets du Context local
4210 if (TheAISContext()->NbSelected()>0 ){
4211 TheAISContext()->UnhilightSelected(Standard_False);
4212 // il y a des objets selected,on les parcourt
4213 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4214 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
4217 if (HaveMode(aIO,aMode) ) {
4218 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4219 TheAISContext()->Deactivate(aIO,aMode);
4222 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4223 TheAISContext()->Activate(aIO,aMode);
4229 // il n'y a pas d'objets selected
4230 // tous les objets diplayes sont traites
4231 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4234 Handle(AIS_InteractiveObject) aIO =
4235 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4236 if (!aIO.IsNull()) {
4237 if (HaveMode(aIO,aMode) ) {
4238 di<<" Mode: "<<cmode<<" OFF pour "
4239 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4240 TheAISContext()->Deactivate(aIO,aMode);
4243 di<<" Mode: "<<cmode<<" ON pour"
4244 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4245 TheAISContext()->Activate(aIO,aMode);
4253 else if (HaveToSet && ThereIsName){
4254 Standard_Integer aMode=Draw::Atoi(argv [2]);
4255 Handle(AIS_InteractiveObject) aIO =
4256 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4258 if (!aIO.IsNull()) {
4259 const char *cmode="???";
4262 case 0: cmode = "Shape"; break;
4263 case 1: cmode = "Vertex"; break;
4264 case 2: cmode = "Edge"; break;
4265 case 3: cmode = "Wire"; break;
4266 case 4: cmode = "Face"; break;
4267 case 5: cmode = "Shell"; break;
4268 case 6: cmode = "Solid"; break;
4269 case 7: cmode = "Compound"; break;
4272 if( !TheAISContext()->HasOpenedContext() ) {
4273 Standard_DISABLE_DEPRECATION_WARNINGS
4274 TheAISContext()->OpenLocalContext(Standard_False);
4275 Standard_ENABLE_DEPRECATION_WARNINGS
4276 // On charge tous les objets de la map
4277 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4279 Handle(AIS_InteractiveObject) aShape=
4280 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4281 if (!aShape.IsNull())
4282 TheAISContext()->Load(aShape,0,Standard_False);
4285 TheAISContext()->Activate(aIO,aMode);
4286 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4290 // un Context local est deja ouvert
4291 if (HaveMode(aIO,aMode) ) {
4292 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4293 TheAISContext()->Deactivate(aIO,aMode);
4296 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4297 TheAISContext()->Activate(aIO,aMode);
4306 //! Auxiliary method to print Interactive Object information
4307 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4308 const Handle(Standard_Transient)& theObject,
4309 Draw_Interpretor& theDI)
4311 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4314 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4318 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4319 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4320 << (theDetected.Contains (anObj) ? " Detected" : " ")
4322 if (anObj->Type() == AIS_KOI_Datum)
4325 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4326 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4327 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4328 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4329 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4330 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4331 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4334 else if (anObj->Type() == AIS_KOI_Shape
4335 && anObj->Signature() == 0)
4337 theDI << " AIS_Shape";
4339 else if (anObj->Type() == AIS_KOI_Relation)
4341 // AIS_Dimention and AIS_Relation
4342 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4343 switch (aRelation->KindOfDimension())
4345 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4346 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4347 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4348 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4349 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4350 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4351 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4352 default: theDI << " UNKNOWN dimension"; break;
4357 theDI << " UserPrs";
4359 theDI << " (" << theObject->DynamicType()->Name() << ")";
4362 //! Print information about locally selected sub-shapes
4363 template <typename T>
4364 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4366 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4367 TCollection_AsciiString aPrevName;
4368 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4370 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4371 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4372 if (aShapeIO.IsNull() || anOwner.IsNull())
4376 if (anOwner == aShapeIO->GlobalSelOwner())
4379 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4380 if (aSubShape.IsNull()
4381 || aShapeIO.IsNull()
4382 || !GetMapOfAIS().IsBound1 (aShapeIO))
4387 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4388 TopTools_MapOfShape aFilter;
4389 Standard_Integer aNumber = 0;
4390 const TopoDS_Shape aShape = aShapeIO->Shape();
4391 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4392 anIter.More(); anIter.Next())
4394 if (!aFilter.Add (anIter.Current()))
4396 continue; // filter duplicates
4400 if (!anIter.Current().IsSame (aSubShape))
4405 Standard_CString aShapeName = NULL;
4406 switch (aSubShape.ShapeType())
4408 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4409 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4410 case TopAbs_SOLID: aShapeName = " Solid"; break;
4411 case TopAbs_SHELL: aShapeName = " Shell"; break;
4412 case TopAbs_FACE: aShapeName = " Face"; break;
4413 case TopAbs_WIRE: aShapeName = " Wire"; break;
4414 case TopAbs_EDGE: aShapeName = " Edge"; break;
4415 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4417 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4420 if (aParentName != aPrevName)
4422 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4423 aPrevName = aParentName;
4425 theDI << " " << aShapeName << " #" << aNumber << "\n";
4431 //==============================================================================
4434 //==============================================================================
4435 static Standard_Integer VState (Draw_Interpretor& theDI,
4436 Standard_Integer theArgNb,
4437 Standard_CString* theArgVec)
4439 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4442 std::cerr << "Error: No opened viewer!\n";
4446 Standard_Boolean toPrintEntities = Standard_False;
4447 Standard_Boolean toCheckSelected = Standard_False;
4449 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4451 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4452 anOption.LowerCase();
4453 if (anOption == "-detectedentities"
4454 || anOption == "-entities")
4456 toPrintEntities = Standard_True;
4458 else if (anOption == "-hasselected")
4460 toCheckSelected = Standard_True;
4464 if (toCheckSelected)
4466 aCtx->InitSelected();
4467 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4468 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4473 if (toPrintEntities)
4475 theDI << "Detected entities:\n";
4476 Standard_DISABLE_DEPRECATION_WARNINGS
4477 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4478 Standard_ENABLE_DEPRECATION_WARNINGS
4479 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4480 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4482 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4483 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4484 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4485 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4486 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4487 aName.LeftJustify (20, ' ');
4488 char anInfoStr[512];
4490 " Depth: %g Distance: %g Point: %g %g %g",
4493 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4494 theDI << " " << aName
4496 << " (" << anEntity->DynamicType()->Name() << ")"
4499 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4500 if (!aBRepOwner.IsNull())
4502 theDI << " Detected Shape: "
4503 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4507 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4508 if (!aWire.IsNull())
4510 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4511 theDI << " Detected Child: "
4512 << aSen->DynamicType()->Name()
4516 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4517 if (!aPrimArr.IsNull())
4519 theDI << " Detected Element: "
4520 << aPrimArr->LastDetectedElement()
4527 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4528 Standard_DISABLE_DEPRECATION_WARNINGS
4529 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4531 aDetected.Add (aCtx->DetectedCurrentObject());
4533 Standard_ENABLE_DEPRECATION_WARNINGS
4535 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4539 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4541 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4542 if (!GetMapOfAIS().IsBound2 (anObjName))
4544 theDI << anObjName << " doesn't exist!\n";
4548 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4549 TCollection_AsciiString aName = anObjName;
4550 aName.LeftJustify (20, ' ');
4551 theDI << " " << aName << " ";
4552 objInfo (aDetected, anObjTrans, theDI);
4558 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4560 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4561 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4563 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4564 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4565 // handle whole object selection
4566 if (anOwner == anObj->GlobalSelOwner())
4568 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4569 aName.LeftJustify (20, ' ');
4570 theDI << aName << " ";
4571 objInfo (aDetected, anObj, theDI);
4576 // process selected sub-shapes
4577 printLocalSelectionInfo (aCtx, theDI);
4582 theDI << "Neutral-point state:\n";
4583 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4584 anObjIter.More(); anObjIter.Next())
4586 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4592 TCollection_AsciiString aName = anObjIter.Key2();
4593 aName.LeftJustify (20, ' ');
4594 theDI << " " << aName << " ";
4595 objInfo (aDetected, anObj, theDI);
4598 printLocalSelectionInfo (aCtx, theDI);
4599 Standard_DISABLE_DEPRECATION_WARNINGS
4600 if (aCtx->HasOpenedContext())
4601 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
4602 Standard_ENABLE_DEPRECATION_WARNINGS
4606 //=======================================================================
4607 //function : PickObjects
4609 //=======================================================================
4610 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4611 const AIS_KindOfInteractive TheType,
4612 const Standard_Integer TheSignature,
4613 const Standard_Integer MaxPick)
4615 Handle(AIS_InteractiveObject) IO;
4616 Standard_DISABLE_DEPRECATION_WARNINGS
4617 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4618 Standard_ENABLE_DEPRECATION_WARNINGS
4620 // step 1: prepare the data
4622 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4623 TheAISContext()->AddFilter(F1);
4626 // step 2 : wait for the selection...
4627 Standard_Integer NbPickGood (0),NbToReach(arr->Length());
4628 Standard_Integer NbPickFail(0);
4629 Standard_Integer argccc = 5;
4630 const char *bufff[] = { "A", "B", "C","D", "E" };
4631 const char **argvvv = (const char **) bufff;
4634 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4635 while(ViewerMainLoop(argccc,argvvv)){}
4636 Standard_Integer NbStored = TheAISContext()->NbSelected();
4637 if(NbStored != NbPickGood)
4638 NbPickGood= NbStored;
4641 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4644 // step3 get result.
4646 if (NbPickFail >= NbToReach)
4647 return Standard_False;
4649 Standard_Integer i(0);
4650 for(TheAISContext()->InitSelected();
4651 TheAISContext()->MoreSelected();
4652 TheAISContext()->NextSelected()){
4654 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4655 arr->SetValue(i,IO2);
4658 Standard_DISABLE_DEPRECATION_WARNINGS
4661 TheAISContext()->CloseLocalContext(curindex);
4663 Standard_ENABLE_DEPRECATION_WARNINGS
4665 return Standard_True;
4669 //=======================================================================
4670 //function : PickObject
4672 //=======================================================================
4673 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4674 const Standard_Integer TheSignature,
4675 const Standard_Integer MaxPick)
4677 Handle(AIS_InteractiveObject) IO;
4678 Standard_DISABLE_DEPRECATION_WARNINGS
4679 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4680 Standard_ENABLE_DEPRECATION_WARNINGS
4682 // step 1: prepare the data
4685 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4686 TheAISContext()->AddFilter(F1);
4689 // step 2 : wait for the selection...
4690 Standard_Boolean IsGood (Standard_False);
4691 Standard_Integer NbPick(0);
4692 Standard_Integer argccc = 5;
4693 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4694 const char **argvvv = (const char **) bufff;
4697 while(!IsGood && NbPick<= MaxPick){
4698 while(ViewerMainLoop(argccc,argvvv)){}
4699 IsGood = (TheAISContext()->NbSelected()>0) ;
4701 cout<<"Nb Pick :"<<NbPick<<endl;
4705 // step3 get result.
4707 TheAISContext()->InitSelected();
4708 IO = TheAISContext()->SelectedInteractive();
4711 Standard_DISABLE_DEPRECATION_WARNINGS
4714 TheAISContext()->CloseLocalContext(curindex);
4716 Standard_ENABLE_DEPRECATION_WARNINGS
4720 //=======================================================================
4721 //function : PickShape
4722 //purpose : First Activate the rightmode + Put Filters to be able to
4723 // pick objets that are of type <TheType>...
4724 //=======================================================================
4726 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4727 const Standard_Integer MaxPick)
4730 // step 1: prepare the data
4731 Standard_DISABLE_DEPRECATION_WARNINGS
4732 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4733 Standard_ENABLE_DEPRECATION_WARNINGS
4734 TopoDS_Shape result;
4736 if(TheType==TopAbs_SHAPE){
4737 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4738 TheAISContext()->AddFilter(F1);
4741 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4742 TheAISContext()->AddFilter(TF);
4743 Standard_DISABLE_DEPRECATION_WARNINGS
4744 TheAISContext()->ActivateStandardMode(TheType);
4745 Standard_ENABLE_DEPRECATION_WARNINGS
4749 // step 2 : wait for the selection...
4750 Standard_Boolean NoShape (Standard_True);
4751 Standard_Integer NbPick(0);
4752 Standard_Integer argccc = 5;
4753 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4754 const char **argvvv = (const char **) bufff;
4757 while(NoShape && NbPick<= MaxPick){
4758 while(ViewerMainLoop(argccc,argvvv)){}
4759 NoShape = (TheAISContext()->NbSelected()==0) ;
4761 cout<<"Nb Pick :"<<NbPick<<endl;
4764 // step3 get result.
4768 TheAISContext()->InitSelected();
4769 if(TheAISContext()->HasSelectedShape())
4770 result = TheAISContext()->SelectedShape();
4772 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4773 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
4777 Standard_DISABLE_DEPRECATION_WARNINGS
4780 TheAISContext()->CloseLocalContext(curindex);
4782 Standard_ENABLE_DEPRECATION_WARNINGS
4788 //=======================================================================
4789 //function : PickShapes
4791 //=======================================================================
4792 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4793 Handle(TopTools_HArray1OfShape)& thearr,
4794 const Standard_Integer MaxPick)
4797 Standard_Integer Taille = thearr->Length();
4799 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4801 // step 1: prepare the data
4802 Standard_DISABLE_DEPRECATION_WARNINGS
4803 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4804 Standard_ENABLE_DEPRECATION_WARNINGS
4805 if(TheType==TopAbs_SHAPE){
4806 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4807 TheAISContext()->AddFilter(F1);
4810 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4811 TheAISContext()->AddFilter(TF);
4812 Standard_DISABLE_DEPRECATION_WARNINGS
4813 TheAISContext()->ActivateStandardMode(TheType);
4814 Standard_ENABLE_DEPRECATION_WARNINGS
4817 // step 2 : wait for the selection...
4818 Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
4819 Standard_Integer NbPickFail(0);
4820 Standard_Integer argccc = 5;
4821 const char *bufff[] = { "A", "B", "C","D", "E" };
4822 const char **argvvv = (const char **) bufff;
4825 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4826 while(ViewerMainLoop(argccc,argvvv)){}
4827 Standard_Integer NbStored = TheAISContext()->NbSelected();
4828 if (NbStored != NbPickGood)
4829 NbPickGood= NbStored;
4832 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4835 // step3 get result.
4837 if (NbPickFail >= NbToReach)
4838 return Standard_False;
4840 Standard_Integer i(0);
4841 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4843 if(TheAISContext()->HasSelectedShape())
4844 thearr->SetValue(i,TheAISContext()->SelectedShape());
4846 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4847 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
4851 Standard_DISABLE_DEPRECATION_WARNINGS
4852 TheAISContext()->CloseLocalContext(curindex);
4853 Standard_ENABLE_DEPRECATION_WARNINGS
4854 return Standard_True;
4858 //=======================================================================
4859 //function : VPickShape
4861 //=======================================================================
4862 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4864 TopoDS_Shape PickSh;
4865 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4868 theType = TopAbs_SHAPE;
4870 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4871 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4872 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4873 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4874 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4875 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4876 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4879 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4880 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4882 TCollection_AsciiString name;
4885 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4887 PickSh = ViewerTest::PickShape(theType);
4896 if(!PickSh.IsNull()){
4897 nbOfSub[Standard_Integer(theType)]++;
4899 name += nameType[Standard_Integer(theType)];
4900 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4905 // si on avait une petite methode pour voir si la shape
4906 // est deja dans la Double map, ca eviterait de creer....
4907 DBRep::Set(name.ToCString(),PickSh);
4909 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4910 GetMapOfAIS().Bind(newsh, name);
4911 TheAISContext()->Display (newsh, Standard_True);
4912 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4915 // Plusieurs objets a picker, vite vite vite....
4918 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4919 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4920 if(ViewerTest::PickShapes(theType,arr)){
4921 for(Standard_Integer i=1;i<=NbToPick;i++){
4922 PickSh = arr->Value(i);
4923 if(!PickSh.IsNull()){
4925 nbOfSub[Standard_Integer(theType)]++;
4928 name += nameType[Standard_Integer(theType)];
4929 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4937 DBRep::Set(name.ToCString(),PickSh);
4938 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4939 GetMapOfAIS().Bind(newsh, name);
4940 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4941 TheAISContext()->Display (newsh, Standard_False);
4944 TheAISContext()->UpdateCurrentViewer();
4950 //=======================================================================
4951 //function : VSetFilter
4953 //=======================================================================
4954 static int VSetFilter(Draw_Interpretor& theDi, Standard_Integer theArgc,
4955 const char** theArgv)
4959 theDi << theArgv[0] << " error : wrong number of parameters.\n";
4963 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4964 if (aContext.IsNull())
4966 std::cout << "Error: AIS context is not available.\n";
4970 TCollection_AsciiString anArg(theArgv[1]);
4971 if (anArg.IsEqual("-clear")) {
4972 aContext->RemoveFilters();
4975 TCollection_AsciiString aPName, aPValue;
4976 if (!ViewerTest::SplitParameter (anArg, aPName, aPValue)) {
4977 std::cout << "Error: wrong command attribute name" << std::endl;
4981 TopAbs_ShapeEnum aType = TopAbs_COMPOUND;
4982 if(aPValue.IsEqual("VERTEX")) aType = TopAbs_VERTEX;
4983 else if (aPValue.IsEqual("EDGE")) aType = TopAbs_EDGE;
4984 else if (aPValue.IsEqual("WIRE")) aType = TopAbs_WIRE;
4985 else if (aPValue.IsEqual("FACE")) aType = TopAbs_FACE;
4986 else if(aPValue.IsEqual("SHAPE")) aType = TopAbs_SHAPE;
4987 else if (aPValue.IsEqual("SHELL")) aType = TopAbs_SHELL;
4988 else if (aPValue.IsEqual("SOLID")) aType = TopAbs_SOLID;
4990 std::cout << "Error: wrong command attribute value" << std::endl;
4994 if(aType==TopAbs_SHAPE){
4995 Handle(AIS_TypeFilter) aFilter = new AIS_TypeFilter(AIS_KOI_Shape);
4996 aContext->AddFilter(aFilter);
4999 Handle(StdSelect_ShapeTypeFilter) aFilter = new StdSelect_ShapeTypeFilter(aType);
5000 aContext->AddFilter(aFilter);
5006 //=======================================================================
5007 //function : VPickSelected
5009 //=======================================================================
5010 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5012 static Standard_Integer aCount = 0;
5013 TCollection_AsciiString aName = "PickedShape_";
5021 aName = aName + aCount++ + "_";
5024 Standard_Integer anIdx = 0;
5025 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5027 TopoDS_Shape aShape;
5028 if (TheAISContext()->HasSelectedShape())
5030 aShape = TheAISContext()->SelectedShape();
5034 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5035 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5038 TCollection_AsciiString aCurrentName = aName;
5041 aCurrentName += anIdx;
5044 DBRep::Set ((aCurrentName).ToCString(), aShape);
5046 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5047 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5048 TheAISContext()->Display (aNewShape, Standard_False);
5051 TheAISContext()->UpdateCurrentViewer();
5056 //=======================================================================
5057 //function : list of known objects
5059 //=======================================================================
5060 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5062 // 1234567890 12345678901234567 123456789
5063 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5064 TCollection_AsciiString BlankLine(64,'_');
5065 Standard_Integer i ;
5067 di<<"/n"<<BlankLine.ToCString()<<"\n";
5070 Colum[i].Center(20,' ');
5072 di<<"|"<<Colum[i].ToCString();
5075 di<<BlankLine.ToCString()<<"\n";
5077 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5078 const char ** names = GetTypeNames();
5080 TCollection_AsciiString curstring;
5081 TCollection_AsciiString curcolum[3];
5084 // les objets de type Datum..
5085 curcolum[1]+="Datum";
5087 curcolum[0].Clear();
5088 curcolum[0] += names[i];
5090 curcolum[2].Clear();
5091 curcolum[2]+=TCollection_AsciiString(i+1);
5093 for(Standard_Integer j =0;j<=2;j++){
5094 curcolum[j].Center(20,' ');
5095 di<<"|"<<curcolum[j].ToCString();
5099 di<<BlankLine.ToCString()<<"\n";
5101 // les objets de type shape
5102 curcolum[1].Clear();
5103 curcolum[1]+="Shape";
5104 curcolum[1].Center(20,' ');
5107 curcolum[0].Clear();
5108 curcolum[0] += names[7+i];
5109 curcolum[2].Clear();
5110 curcolum[2]+=TCollection_AsciiString(i);
5112 for(Standard_Integer j =0;j<=2;j++){
5113 curcolum[j].Center(20,' ');
5114 di<<"|"<<curcolum[j].ToCString();
5118 di<<BlankLine.ToCString()<<"\n";
5119 // les IO de type objet...
5120 curcolum[1].Clear();
5121 curcolum[1]+="Object";
5122 curcolum[1].Center(20,' ');
5124 curcolum[0].Clear();
5125 curcolum[0] += names[10+i];
5126 curcolum[2].Clear();
5127 curcolum[2]+=TCollection_AsciiString(i);
5129 for(Standard_Integer j =0;j<=2;j++){
5130 curcolum[j].Center(20,' ');
5131 di<<"|"<<curcolum[j].ToCString();
5135 di<<BlankLine.ToCString()<<"\n";
5136 // les contraintes et dimensions.
5137 // pour l'instant on separe juste contraintes et dimensions...
5138 // plus tard, on detaillera toutes les sortes...
5139 curcolum[1].Clear();
5140 curcolum[1]+="Relation";
5141 curcolum[1].Center(20,' ');
5143 curcolum[0].Clear();
5144 curcolum[0] += names[12+i];
5145 curcolum[2].Clear();
5146 curcolum[2]+=TCollection_AsciiString(i);
5148 for(Standard_Integer j =0;j<=2;j++){
5149 curcolum[j].Center(20,' ');
5150 di<<"|"<<curcolum[j].ToCString();
5154 di<<BlankLine.ToCString()<<"\n";
5161 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5163 if(argc!=2) return 1;
5165 AIS_KindOfInteractive TheType;
5166 Standard_Integer TheSign(-1);
5167 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5170 AIS_ListOfInteractive LIO;
5172 // en attendant l'amelioration ais pour les dimensions...
5174 Standard_Integer dimension_status(-1);
5175 if(TheType==AIS_KOI_Relation){
5176 dimension_status = TheSign ==1 ? 1 : 0;
5180 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5181 Handle(AIS_InteractiveObject) curio;
5182 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5185 if(dimension_status == -1)
5186 TheAISContext()->Erase(curio,Standard_False);
5188 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5189 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5190 (dimension_status==1 && KOD != AIS_KOD_NONE))
5191 TheAISContext()->Erase(curio,Standard_False);
5194 TheAISContext()->UpdateCurrentViewer();
5197 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5199 if(argc!=2) return 1;
5201 AIS_KindOfInteractive TheType;
5202 Standard_Integer TheSign(-1);
5203 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5205 // en attendant l'amelioration ais pour les dimensions...
5207 Standard_Integer dimension_status(-1);
5208 if(TheType==AIS_KOI_Relation){
5209 dimension_status = TheSign ==1 ? 1 : 0;
5213 AIS_ListOfInteractive LIO;
5214 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5215 Handle(AIS_InteractiveObject) curio;
5216 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5218 if(dimension_status == -1)
5219 TheAISContext()->Display(curio,Standard_False);
5221 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5222 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5223 (dimension_status==1 && KOD != AIS_KOD_NONE))
5224 TheAISContext()->Display(curio,Standard_False);
5229 TheAISContext()->UpdateCurrentViewer();
5233 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5236 BRep_Builder builder;
5238 BRepTools::Read(shape, s, builder);
5239 DBRep::Set(a[1], shape);
5240 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5241 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5242 Ctx->Display (ais, Standard_True);
5246 //===============================================================================================
5249 //===============================================================================================
5250 static int VBsdf (Draw_Interpretor& theDi,
5251 Standard_Integer theArgsNb,
5252 const char** theArgVec)
5254 Handle(V3d_View) aView = ViewerTest::CurrentView();
5255 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5257 || aViewer.IsNull())
5259 std::cerr << "No active viewer!\n";
5263 ViewerTest_CmdParser aCmd;
5265 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5266 aCmd.AddOption ("print|echo|p", "Print BSDF");
5268 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5269 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5270 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5271 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5272 aCmd.AddOption ("le", "Self-emitted radiance");
5274 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5276 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
5277 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5278 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5280 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5282 aCmd.Parse (theArgsNb, theArgVec);
5284 if (aCmd.HasOption ("help"))
5286 theDi.PrintHelp (theArgVec[0]);
5290 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5293 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5294 if (!aMap.IsBound2 (aName) )
5296 std::cerr << "Use 'vdisplay' before\n";
5300 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5301 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5302 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5304 if (aCmd.HasOption ("print"))
5306 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5309 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5310 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5311 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5312 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5313 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5316 if (aFresnel.x() >= 0.f)
5319 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5321 else if (aFresnel.x() >= -1.5f)
5324 << "|Constant| " << aFresnel.z() << "\n";
5326 else if (aFresnel.x() >= -2.5f)
5329 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5334 << "|Dielectric| " << aFresnel.y() << "\n";
5339 << "Roughness: " << aBSDF.Roughness << "\n"
5340 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
5341 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5342 << aBSDF.AbsorptionColor.g() << ", "
5343 << aBSDF.AbsorptionColor.b() << "\n";
5348 if (aCmd.HasOption ("roughness", 1, Standard_True))
5350 aCmd.Arg ("roughness", 0);
5351 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5354 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5356 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5359 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5361 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5364 if (aCmd.HasOption ("kd", 3))
5366 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5368 else if (aCmd.HasOption ("kd", 1, Standard_True))
5370 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5373 if (aCmd.HasOption ("kr", 3))
5375 aBSDF.Kr = aCmd.ArgVec3f ("kr");
5377 else if (aCmd.HasOption ("kr", 1, Standard_True))
5379 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5382 if (aCmd.HasOption ("kt", 3))
5384 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5386 else if (aCmd.HasOption ("kt", 1, Standard_True))
5388 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5391 if (aCmd.HasOption ("ks", 3))
5393 aBSDF.Ks = aCmd.ArgVec3f ("ks");
5395 else if (aCmd.HasOption ("ks", 1, Standard_True))
5397 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5400 if (aCmd.HasOption ("le", 3))
5402 aBSDF.Le = aCmd.ArgVec3f ("le");
5404 else if (aCmd.HasOption ("le", 1, Standard_True))
5406 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5409 const std::string aFresnelErrorMessage =
5410 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5412 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5414 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5415 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5417 if (aFresnelType == "schlick")
5419 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5420 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5421 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5422 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5426 std::cout << aFresnelErrorMessage;
5429 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5431 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5432 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5434 if (aFresnelType == "conductor")
5436 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5437 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5438 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5442 std::cout << aFresnelErrorMessage;
5445 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5447 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5448 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5450 if (aFresnelType == "dielectric")
5452 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5453 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5455 else if (aFresnelType == "constant")
5457 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5458 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5462 std::cout << aFresnelErrorMessage;
5466 if (aCmd.HasOption ("normalize"))
5471 aMaterial.SetBSDF (aBSDF);
5472 anIObj->SetMaterial (aMaterial);
5479 //==============================================================================
5480 //function : VLoadSelection
5481 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5482 //==============================================================================
5483 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5484 Standard_Integer theArgNb,
5485 const char** theArgVec)
5489 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5493 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5496 ViewerTest::ViewerInit();
5497 aCtx = ViewerTest::GetAISContext();
5500 // Parse input arguments
5501 TColStd_SequenceOfAsciiString aNamesOfIO;
5502 Standard_Boolean isLocal = Standard_False;
5503 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5505 const TCollection_AsciiString aName = theArgVec[anArgIter];
5506 TCollection_AsciiString aNameCase = aName;
5507 aNameCase.LowerCase();
5508 if (aNameCase == "-local")
5510 isLocal = Standard_True;
5514 aNamesOfIO.Append (aName);
5518 if (aNamesOfIO.IsEmpty())
5520 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5525 Standard_DISABLE_DEPRECATION_WARNINGS
5526 if (isLocal && !aCtx->HasOpenedContext())
5528 aCtx->OpenLocalContext (Standard_False);
5530 else if (!isLocal && aCtx->HasOpenedContext())
5532 aCtx->CloseAllContexts (Standard_False);
5534 Standard_ENABLE_DEPRECATION_WARNINGS
5536 // Load selection of interactive objects
5537 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5539 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5541 Handle(AIS_InteractiveObject) aShape;
5542 if (GetMapOfAIS().IsBound2 (aName))
5543 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5545 aShape = GetAISShapeFromName (aName.ToCString());
5547 if (!aShape.IsNull())
5549 if (!GetMapOfAIS().IsBound2 (aName))
5551 GetMapOfAIS().Bind (aShape, aName);
5554 aCtx->Load (aShape, -1, Standard_False);
5555 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5562 //==============================================================================
5563 //function : ViewerTest::Commands
5564 //purpose : Add all the viewer command in the Draw_Interpretor
5565 //==============================================================================
5567 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5569 ViewerTest::ViewerCommands(theCommands);
5570 ViewerTest::RelationCommands(theCommands);
5571 ViewerTest::ObjectCommands(theCommands);
5572 ViewerTest::FilletCommands(theCommands);
5573 ViewerTest::OpenGlCommands(theCommands);
5575 const char *group = "AIS_Display";
5578 theCommands.Add("visos",
5579 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5580 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5581 __FILE__, visos, group);
5583 theCommands.Add("vdisplay",
5584 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5585 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5586 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5587 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5588 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5589 "\n\t\t: [offsetX offsetY]]]"
5590 "\n\t\t: [-dispMode mode] [-highMode mode]"
5591 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5592 "\n\t\t: [-redisplay]"
5593 "\n\t\t: name1 [name2] ... [name n]"
5594 "\n\t\t: Displays named objects."
5595 "\n\t\t: Option -local enables displaying of objects in local"
5596 "\n\t\t: selection context. Local selection context will be opened"
5597 "\n\t\t: if there is not any."
5598 "\n\t\t: -noupdate Suppresses viewer redraw call."
5599 "\n\t\t: -mutable Enables optimizations for mutable objects."
5600 "\n\t\t: -neutral Draws objects in main viewer."
5601 "\n\t\t: -layer Sets z-layer for objects."
5602 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5603 "\n\t\t: options can be used for the default z-layers."
5604 "\n\t\t: -top Draws object on top of main presentations"
5605 "\n\t\t: but below topmost."
5606 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5607 "\n\t\t: with independent Depth."
5608 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5609 "\n\t\t: (On-Screen-Display)"
5610 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5611 "\n\t\t: (On-Screen-Display)"
5612 "\n\t\t: -selectable|-noselect Controls selection of objects."
5613 "\n\t\t: -trsfPers Sets a transform persistence flags."
5614 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5615 "\n\t\t: -2d Displays object in screen coordinates."
5616 "\n\t\t: (DY looks up)"
5617 "\n\t\t: -dispmode Sets display mode for objects."
5618 "\n\t\t: -highmode Sets hilight mode for objects."
5619 "\n\t\t: -redisplay Recomputes presentation of objects.",
5620 __FILE__, VDisplay2, group);
5622 theCommands.Add ("vupdate",
5623 "vupdate name1 [name2] ... [name n]"
5624 "\n\t\t: Updates named objects in interactive context",
5625 __FILE__, VUpdate, group);
5627 theCommands.Add("verase",
5628 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5629 "\n\t\t: Erases selected or named objects."
5630 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5631 "\n\t\t: Option -local enables erasing of selected or named objects without"
5632 "\n\t\t: closing local selection context.",
5633 __FILE__, VErase, group);
5635 theCommands.Add("vremove",
5636 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5637 "or vremove [-context] -all to remove all objects"
5638 "\n\t\t: Removes selected or named objects."
5639 "\n\t\t If -context is in arguments, the objects are not deleted"
5640 "\n\t\t from the map of objects and names."
5641 "\n\t\t: Option -local enables removing of selected or named objects without"
5642 "\n\t\t: closing local selection context. Empty local selection context will be"
5644 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5645 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5646 __FILE__, VRemove, group);
5648 theCommands.Add("vdonly",
5649 "vdonly [-noupdate|-update] [name1] ... [name n]"
5650 "\n\t\t: Displays only selected or named objects",
5651 __FILE__,VDonly2,group);
5653 theCommands.Add("vdisplayall",
5654 "vidsplayall [-local]"
5655 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5656 "\n\t\t: Option -local enables displaying of the objects in local"
5657 "\n\t\t: selection context.",
5658 __FILE__, VDisplayAll, group);
5660 theCommands.Add("veraseall",
5661 "veraseall [-local]"
5662 "\n\t\t: Erases all objects displayed in the viewer."
5663 "\n\t\t: Option -local enables erasing of the objects in local"
5664 "\n\t\t: selection context.",
5665 __FILE__, VErase, group);
5667 theCommands.Add("verasetype",
5669 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5670 __FILE__, VEraseType, group);
5671 theCommands.Add("vbounding",
5672 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5673 "\n\t\t: [-print] [-hide]"
5674 "\n\t\t: Temporarily display bounding box of specified Interactive"
5675 "\n\t\t: Objects, or print it to console if -print is specified."
5676 "\n\t\t: Already displayed box might be hidden by -hide option.",
5677 __FILE__,VBounding,group);
5679 theCommands.Add("vdisplaytype",
5680 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5681 __FILE__,VDisplayType,group);
5683 theCommands.Add("vsetdispmode",
5684 "vsetdispmode [name] mode(1,2,..)"
5685 "\n\t\t: Sets display mode for all, selected or named objects.",
5686 __FILE__,VDispMode,group);
5688 theCommands.Add("vunsetdispmode",
5689 "vunsetdispmode [name]"
5690 "\n\t\t: Unsets custom display mode for selected or named objects.",
5691 __FILE__,VDispMode,group);
5693 theCommands.Add("vdir",
5694 "Lists all objects displayed in 3D viewer",
5695 __FILE__,VDir,group);
5697 #ifdef HAVE_FREEIMAGE
5698 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5700 #define DUMP_FORMATS "{ppm}"
5702 theCommands.Add("vdump",
5703 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5704 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5705 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5706 "\n\t\t: [-tileSize Size=0]"
5707 "\n\t\t: Dumps content of the active view into image file",
5708 __FILE__,VDump,group);
5710 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5711 __FILE__,VSubInt,group);
5713 theCommands.Add("vaspects",
5714 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5715 "\n\t\t: [-setVisibility 0|1]"
5716 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5717 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5718 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5719 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5720 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5721 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5722 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5723 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5724 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5725 "\n\t\t: [-isoontriangulation 0|1]"
5726 "\n\t\t: [-setMaxParamValue {value}]"
5727 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5728 "\n\t\t: [-setHatch HatchStyle]"
5729 "\n\t\t: Manage presentation properties of all, selected or named objects."
5730 "\n\t\t: When -subshapes is specified than following properties will be"
5731 "\n\t\t: assigned to specified sub-shapes."
5732 "\n\t\t: When -defaults is specified than presentation properties will be"
5733 "\n\t\t: assigned to all objects that have not their own specified properties"
5734 "\n\t\t: and to all objects to be displayed in the future."
5735 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5736 __FILE__,VAspects,group);
5738 theCommands.Add("vsetcolor",
5739 "vsetcolor [-noupdate|-update] [name] ColorName"
5740 "\n\t\t: Sets color for all, selected or named objects."
5741 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5742 __FILE__,VAspects,group);
5744 theCommands.Add("vunsetcolor",
5745 "vunsetcolor [-noupdate|-update] [name]"
5746 "\n\t\t: Resets color for all, selected or named objects."
5747 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5748 __FILE__,VAspects,group);
5750 theCommands.Add("vsettransparency",
5751 "vsettransparency [-noupdate|-update] [name] Coefficient"
5752 "\n\t\t: Sets transparency for all, selected or named objects."
5753 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5754 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5755 __FILE__,VAspects,group);
5757 theCommands.Add("vunsettransparency",
5758 "vunsettransparency [-noupdate|-update] [name]"
5759 "\n\t\t: Resets transparency for all, selected or named objects."
5760 "\n\t\t: Alias for vaspects -unsettransp [name].",
5761 __FILE__,VAspects,group);
5763 theCommands.Add("vsetmaterial",
5764 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5765 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5766 __FILE__,VAspects,group);
5768 theCommands.Add("vunsetmaterial",
5769 "vunsetmaterial [-noupdate|-update] [name]"
5770 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5771 __FILE__,VAspects,group);
5773 theCommands.Add("vsetwidth",
5774 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5775 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5776 __FILE__,VAspects,group);
5778 theCommands.Add("vunsetwidth",
5779 "vunsetwidth [-noupdate|-update] [name]"
5780 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5781 __FILE__,VAspects,group);
5783 theCommands.Add("vsetinteriorstyle",
5784 "vsetinteriorstyle [-noupdate|-update] [name] style"
5785 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5786 __FILE__,VSetInteriorStyle,group);
5788 theCommands.Add("vsensdis",
5789 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5790 "\n\t\t: Standard entity types are those defined in Select3D package:"
5791 "\n\t\t: - sensitive box"
5792 "\n\t\t: - sensitive face"
5793 "\n\t\t: - sensitive curve"
5794 "\n\t\t: - sensitive segment"
5795 "\n\t\t: - sensitive circle"
5796 "\n\t\t: - sensitive point"
5797 "\n\t\t: - sensitive triangulation"
5798 "\n\t\t: - sensitive triangle"
5799 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5800 __FILE__,VDispSensi,group);
5802 theCommands.Add("vsensera",
5803 "vsensera : erase active entities",
5804 __FILE__,VClearSensi,group);
5806 theCommands.Add("vsetshading",
5807 "vsetshading : vsetshading name Quality(default=0.0008) "
5808 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5809 __FILE__,VShading,group);
5811 theCommands.Add("vunsetshading",
5812 "vunsetshading :vunsetshading name "
5813 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5814 __FILE__,VShading,group);
5816 theCommands.Add ("vtexture",
5817 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5818 " [-scale u v] [-scale off]\n"
5819 " [-origin u v] [-origin off]\n"
5820 " [-repeat u v] [-repeat off]\n"
5821 " [-modulate {on | off}]"
5823 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5824 " specifying one of the predefined textures.\n"
5825 " The options are: \n"
5826 " -scale u v : enable texture scaling and set scale factors\n"
5827 " -scale off : disable texture scaling\n"
5828 " -origin u v : enable texture origin positioning and set the origin\n"
5829 " -origin off : disable texture origin positioning\n"
5830 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5831 " -repeat off : disable texture repeat\n"
5832 " -modulate {on | off} : enable or disable texture modulation\n"
5833 " -default : sets texture mapping default parameters\n"
5834 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5835 "or 'vtexture NameOfShape ?' to list available textures\n",
5836 __FILE__, VTexture, group);
5838 theCommands.Add("vtexscale",
5839 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5840 or 'vtexscale NameOfShape ScaleUV' \n \
5841 or 'vtexscale NameOfShape' to disable scaling\n ",
5842 __FILE__,VTexture,group);
5844 theCommands.Add("vtexorigin",
5845 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5846 or 'vtexorigin NameOfShape UVOrigin' \n \
5847 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5848 __FILE__,VTexture,group);
5850 theCommands.Add("vtexrepeat",
5851 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5852 or 'vtexrepeat NameOfShape UVRepeat \n \
5853 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5856 theCommands.Add("vtexdefault",
5857 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5860 theCommands.Add("vsetam",
5861 "vsetam [shapename] mode"
5862 "\n\t\t: Activates selection mode for all selected or named shapes."
5863 "\n\t\t: Mod can be:"
5864 "\n\t\t: 0 - for shape itself"
5865 "\n\t\t: 1 - vertices"
5869 "\n\t\t: 5 - shells"
5870 "\n\t\t: 6 - solids"
5871 "\n\t\t: 7 - compounds"
5872 __FILE__,VActivatedMode,group);
5874 theCommands.Add("vunsetam",
5875 "vunsetam : Deactivates all selection modes for all shapes.",
5876 __FILE__,VActivatedMode,group);
5878 theCommands.Add("vstate",
5879 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5880 "\n\t\t: Reports show/hidden state for selected or named objects"
5881 "\n\t\t: -entities - print low-level information about detected entities"
5882 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5883 __FILE__,VState,group);
5885 theCommands.Add("vpickshapes",
5886 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5887 __FILE__,VPickShape,group);
5889 theCommands.Add("vtypes",
5890 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5893 theCommands.Add("vr",
5895 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
5896 __FILE__,vr, group);
5898 theCommands.Add("vsetfilter",
5899 "vsetfilter [-type={VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
5900 "\nSets selection shape type filter in context or remove all filters."
5901 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
5902 "\n : Option -clear remove all filters in context",
5903 __FILE__,VSetFilter,group);
5905 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5906 __FILE__, VPickSelected, group);
5908 theCommands.Add ("vloadselection",
5909 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5910 "\n\t\t: primitives for the shapes with names given without displaying them."
5911 "\n\t\t: -local - open local context before selection computation",
5912 __FILE__, VLoadSelection, group);
5914 theCommands.Add("vbsdf", "vbsdf [name] [options]"
5915 "\nAdjusts parameters of material BSDF:"
5916 "\n -help : Shows this message"
5917 "\n -print : Print BSDF"
5918 "\n -kd : Weight of the Lambertian BRDF"
5919 "\n -kr : Weight of the reflection BRDF"
5920 "\n -kt : Weight of the transmission BTDF"
5921 "\n -ks : Weight of the glossy Blinn BRDF"
5922 "\n -le : Self-emitted radiance"
5923 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5924 "\n Schlick x y z, Dielectric x, Conductor x y"
5925 "\n -roughness : Roughness of material (Blinn's exponent)"
5926 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
5927 "\n -absorpcolor : Absorption color (only for transparent material)"
5928 "\n -normalize : Normalize BSDF coefficients",
5929 __FILE__, VBsdf, group);
5933 //=====================================================================
5934 //========================= for testing Draft and Rib =================
5935 //=====================================================================
5936 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5937 #include <DBRep.hxx>
5938 #include <TopoDS_Face.hxx>
5939 #include <gp_Pln.hxx>
5940 #include <AIS_KindOfSurface.hxx>
5941 #include <BRepOffsetAPI_DraftAngle.hxx>
5942 #include <Precision.hxx>
5943 #include <BRepAlgo.hxx>
5944 #include <OSD_Environment.hxx>
5945 #include <DrawTrSurf.hxx>
5946 //#include <DbgTools.hxx>
5947 //#include <FeatAlgo_MakeLinearForm.hxx>
5952 //=======================================================================
5953 //function : IsValid
5955 //=======================================================================
5956 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5957 const TopoDS_Shape& theResult,
5958 const Standard_Boolean closedSolid,
5959 const Standard_Boolean GeomCtrl)
5961 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5962 TCollection_AsciiString checkValid = check.Value();
5963 Standard_Boolean ToCheck = Standard_True;
5964 if (!checkValid.IsEmpty()) {
5966 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5968 if ( checkValid=="true" || checkValid=="TRUE" ) {
5969 ToCheck= Standard_False;
5973 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
5976 Standard_Boolean IsValid = Standard_True;
5978 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5983 //===============================================================================
5984 // TDraft : test draft, uses AIS Viewer
5985 // Solid Face Plane Angle Reverse
5986 //===============================================================================
5987 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5989 if (argc < 5) return 1;
5990 // argv[1] - TopoDS_Shape Solid
5991 // argv[2] - TopoDS_Shape Face
5992 // argv[3] - TopoDS_Shape Plane
5993 // argv[4] - Standard_Real Angle
5994 // argv[5] - Standard_Integer Reverse
5996 // Sprintf(prefix, argv[1]);
5997 Standard_Real anAngle = 0;
5998 Standard_Boolean Rev = Standard_False;
5999 Standard_Integer rev = 0;
6000 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
6001 TopoDS_Shape face = GetShapeFromName(argv[2]);
6002 TopoDS_Face Face = TopoDS::Face(face);
6003 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
6004 if (Plane.IsNull ()) {
6005 di << "TEST : Plane is NULL\n";
6008 anAngle = Draw::Atof(argv[4]);
6009 anAngle = 2*M_PI * anAngle / 360.0;
6011 Handle( Geom_Surface )aSurf;
6012 AIS_KindOfSurface aSurfType;
6013 Standard_Real Offset;
6015 if(argc > 4) { // == 5
6016 rev = Draw::Atoi(argv[5]);
6017 Rev = (rev)? Standard_True : Standard_False;
6020 TopoDS_Face face2 = TopoDS::Face(Plane);
6021 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6023 di << "TEST : Can't find plane\n";
6027 aDir = aPln.Axis().Direction();
6030 if (Plane.Orientation() == TopAbs_REVERSED)
6032 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6034 BRepOffsetAPI_DraftAngle Draft (Solid);
6036 if(Abs(anAngle)< Precision::Angular()) {
6037 di << "TEST : NULL angle\n";
6040 if(Rev) anAngle = - anAngle;
6041 Draft.Add (Face, aDir, anAngle, aPln);
6043 if (!Draft.IsDone()) {
6044 di << "TEST : Draft Not DONE \n";
6047 TopTools_ListOfShape Larg;
6049 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6050 di << "TEST : DesignAlgo returns Not valid\n";
6054 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6055 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6057 if ( !ais.IsNull() ) {
6058 ais->SetColor(DEFAULT_COLOR);
6059 ais->SetMaterial(DEFAULT_MATERIAL);
6060 // Display the AIS_Shape without redraw
6061 Ctx->Display(ais, Standard_False);
6063 const char *Name = "draft1";
6064 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6066 Handle(AIS_InteractiveObject) an_object =
6067 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6068 if (!an_object.IsNull()) {
6069 Ctx->Remove(an_object,
6071 GetMapOfAIS().UnBind2(Name) ;
6074 GetMapOfAIS().Bind(ais, Name);
6075 // DBRep::Set("draft", ais->Shape());
6077 Ctx->Display(ais, Standard_True);
6081 //==============================================================================
6082 //function : splitParameter
6083 //purpose : Split parameter string to parameter name and parameter value
6084 //==============================================================================
6085 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6086 TCollection_AsciiString& theName,
6087 TCollection_AsciiString& theValue)
6089 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6091 if (aParamNameEnd == 0)
6093 return Standard_False;
6096 TCollection_AsciiString aString (theString);
6097 if (aParamNameEnd != 0)
6099 theValue = aString.Split (aParamNameEnd);
6100 aString.Split (aString.Length() - 1);
6104 return Standard_True;
6107 //============================================================================
6109 //============================================================================
6110 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6113 DrawTrSurf::BasicCommands(theCommands);
6114 const char* group = "Check Features Operations commands";
6116 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6118 &TDraft,group); //Draft_Modification
6121 //==============================================================================
6122 // ViewerTest::Factory
6123 //==============================================================================
6124 void ViewerTest::Factory(Draw_Interpretor& theDI)
6126 // definition of Viewer Command
6127 ViewerTest::Commands(theDI);
6130 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6134 // Declare entry point PLUGINFACTORY