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);
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_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
990 switch (aParams.BufferType)
992 case Graphic3d_BT_RGB: aFormat = Image_PixMap::ImgRGB; break;
993 case Graphic3d_BT_RGBA: aFormat = Image_PixMap::ImgRGBA; break;
994 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; 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);
1230 Ctx->SubIntensityOff(IO);
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 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1444 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1445 aStyleArg.LowerCase();
1446 if (aStyleArg == "empty")
1450 else if (aStyleArg == "hollow")
1454 else if (aStyleArg == "hatch")
1458 else if (aStyleArg == "solid")
1462 else if (aStyleArg == "hiddenline")
1468 anInterStyle = aStyleArg.IntegerValue();
1470 if (anInterStyle < Aspect_IS_EMPTY
1471 || anInterStyle > Aspect_IS_HIDDENLINE)
1473 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1474 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1478 if (!aName.IsEmpty()
1479 && !GetMapOfAIS().IsBound2 (aName))
1481 std::cout << "Error: object " << aName << " is not displayed!\n";
1485 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1487 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1490 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1491 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1492 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1493 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1494 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1500 //! Auxiliary structure for VAspects
1501 struct ViewerTest_AspectsChangeSet
1503 Standard_Integer ToSetVisibility;
1504 Standard_Integer Visibility;
1506 Standard_Integer ToSetColor;
1507 Quantity_Color Color;
1509 Standard_Integer ToSetLineWidth;
1510 Standard_Real LineWidth;
1512 Standard_Integer ToSetTypeOfLine;
1513 Aspect_TypeOfLine TypeOfLine;
1515 Standard_Integer ToSetTransparency;
1516 Standard_Real Transparency;
1518 Standard_Integer ToSetMaterial;
1519 Graphic3d_NameOfMaterial Material;
1520 TCollection_AsciiString MatName;
1522 NCollection_Sequence<TopoDS_Shape> SubShapes;
1524 Standard_Integer ToSetShowFreeBoundary;
1525 Standard_Integer ToSetFreeBoundaryWidth;
1526 Standard_Real FreeBoundaryWidth;
1527 Standard_Integer ToSetFreeBoundaryColor;
1528 Quantity_Color FreeBoundaryColor;
1530 Standard_Integer ToEnableIsoOnTriangulation;
1532 Standard_Integer ToSetMaxParamValue;
1533 Standard_Real MaxParamValue;
1535 Standard_Integer ToSetSensitivity;
1536 Standard_Integer SelectionMode;
1537 Standard_Integer Sensitivity;
1539 Standard_Integer ToSetHatch;
1540 Standard_Integer StdHatchStyle;
1541 TCollection_AsciiString PathToHatchPattern;
1543 //! Empty constructor
1544 ViewerTest_AspectsChangeSet()
1545 : ToSetVisibility (0),
1548 Color (DEFAULT_COLOR),
1551 ToSetTypeOfLine (0),
1552 TypeOfLine (Aspect_TOL_SOLID),
1553 ToSetTransparency (0),
1556 Material (Graphic3d_NOM_DEFAULT),
1557 ToSetShowFreeBoundary (0),
1558 ToSetFreeBoundaryWidth (0),
1559 FreeBoundaryWidth (1.0),
1560 ToSetFreeBoundaryColor (0),
1561 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1562 ToEnableIsoOnTriangulation (-1),
1563 ToSetMaxParamValue (0),
1564 MaxParamValue (500000),
1565 ToSetSensitivity (0),
1572 //! @return true if no changes have been requested
1573 Standard_Boolean IsEmpty() const
1575 return ToSetVisibility == 0
1576 && ToSetLineWidth == 0
1577 && ToSetTransparency == 0
1579 && ToSetMaterial == 0
1580 && ToSetShowFreeBoundary == 0
1581 && ToSetFreeBoundaryColor == 0
1582 && ToSetFreeBoundaryWidth == 0
1583 && ToSetMaxParamValue == 0
1584 && ToSetSensitivity == 0
1588 //! @return true if properties are valid
1589 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1591 Standard_Boolean isOk = Standard_True;
1592 if (Visibility != 0 && Visibility != 1)
1594 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1595 isOk = Standard_False;
1597 if (LineWidth <= 0.0
1598 || LineWidth > 10.0)
1600 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1601 isOk = Standard_False;
1603 if (Transparency < 0.0
1604 || Transparency > 1.0)
1606 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1607 isOk = Standard_False;
1610 && ToSetTransparency)
1612 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1613 isOk = Standard_False;
1615 if (ToSetMaterial == 1
1616 && Material == Graphic3d_NOM_DEFAULT)
1618 std::cout << "Error: unknown material " << MatName << ".\n";
1619 isOk = Standard_False;
1621 if (FreeBoundaryWidth <= 0.0
1622 || FreeBoundaryWidth > 10.0)
1624 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1625 isOk = Standard_False;
1627 if (MaxParamValue < 0.0)
1629 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1630 isOk = Standard_False;
1632 if (Sensitivity <= 0 && ToSetSensitivity)
1634 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1635 isOk = Standard_False;
1637 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1639 std::cout << "Error: hatch style must be specified\n";
1640 isOk = Standard_False;
1647 //==============================================================================
1648 //function : VAspects
1650 //==============================================================================
1651 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1652 Standard_Integer theArgNb,
1653 const char** theArgVec)
1655 TCollection_AsciiString aCmdName (theArgVec[0]);
1656 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1657 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1660 std::cerr << "Error: no active view!\n";
1664 Standard_Integer anArgIter = 1;
1665 Standard_Boolean isDefaults = Standard_False;
1666 NCollection_Sequence<TCollection_AsciiString> aNames;
1667 for (; anArgIter < theArgNb; ++anArgIter)
1669 TCollection_AsciiString anArg = theArgVec[anArgIter];
1670 if (anUpdateTool.parseRedrawMode (anArg))
1674 else if (!anArg.IsEmpty()
1675 && anArg.Value (1) != '-')
1677 aNames.Append (anArg);
1681 if (anArg == "-defaults")
1683 isDefaults = Standard_True;
1690 if (!aNames.IsEmpty() && isDefaults)
1692 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1696 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1697 aChanges.Append (ViewerTest_AspectsChangeSet());
1698 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1700 // parse syntax of legacy commands
1701 if (aCmdName == "vsetwidth")
1703 if (aNames.IsEmpty()
1704 || !aNames.Last().IsRealValue())
1706 std::cout << "Error: not enough arguments!\n";
1709 aChangeSet->ToSetLineWidth = 1;
1710 aChangeSet->LineWidth = aNames.Last().RealValue();
1711 aNames.Remove (aNames.Length());
1713 else if (aCmdName == "vunsetwidth")
1715 aChangeSet->ToSetLineWidth = -1;
1717 else if (aCmdName == "vsetcolor")
1719 if (aNames.IsEmpty())
1721 std::cout << "Error: not enough arguments!\n";
1724 aChangeSet->ToSetColor = 1;
1726 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1727 Standard_Boolean isOk = Standard_False;
1728 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1730 aChangeSet->Color = aColor;
1731 aNames.Remove (aNames.Length());
1732 isOk = Standard_True;
1734 else if (aNames.Length() >= 3)
1736 const TCollection_AsciiString anRgbStr[3] =
1738 aNames.Value (aNames.Upper() - 2),
1739 aNames.Value (aNames.Upper() - 1),
1740 aNames.Value (aNames.Upper() - 0)
1742 isOk = anRgbStr[0].IsRealValue()
1743 && anRgbStr[1].IsRealValue()
1744 && anRgbStr[2].IsRealValue();
1747 Graphic3d_Vec4d anRgb;
1748 anRgb.x() = anRgbStr[0].RealValue();
1749 anRgb.y() = anRgbStr[1].RealValue();
1750 anRgb.z() = anRgbStr[2].RealValue();
1751 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1752 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1753 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1755 std::cout << "Error: RGB color values should be within range 0..1!\n";
1758 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1759 aNames.Remove (aNames.Length());
1760 aNames.Remove (aNames.Length());
1761 aNames.Remove (aNames.Length());
1766 std::cout << "Error: not enough arguments!\n";
1770 else if (aCmdName == "vunsetcolor")
1772 aChangeSet->ToSetColor = -1;
1774 else if (aCmdName == "vsettransparency")
1776 if (aNames.IsEmpty()
1777 || !aNames.Last().IsRealValue())
1779 std::cout << "Error: not enough arguments!\n";
1782 aChangeSet->ToSetTransparency = 1;
1783 aChangeSet->Transparency = aNames.Last().RealValue();
1784 aNames.Remove (aNames.Length());
1786 else if (aCmdName == "vunsettransparency")
1788 aChangeSet->ToSetTransparency = -1;
1790 else if (aCmdName == "vsetmaterial")
1792 if (aNames.IsEmpty())
1794 std::cout << "Error: not enough arguments!\n";
1797 aChangeSet->ToSetMaterial = 1;
1798 aChangeSet->MatName = aNames.Last();
1799 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1800 aNames.Remove (aNames.Length());
1802 else if (aCmdName == "vunsetmaterial")
1804 aChangeSet->ToSetMaterial = -1;
1806 else if (anArgIter >= theArgNb)
1808 std::cout << "Error: not enough arguments!\n";
1812 if (!aChangeSet->IsEmpty())
1814 anArgIter = theArgNb;
1816 for (; anArgIter < theArgNb; ++anArgIter)
1818 TCollection_AsciiString anArg = theArgVec[anArgIter];
1820 if (anArg == "-setwidth"
1821 || anArg == "-setlinewidth")
1823 if (++anArgIter >= theArgNb)
1825 std::cout << "Error: wrong syntax at " << anArg << "\n";
1828 aChangeSet->ToSetLineWidth = 1;
1829 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1831 else if (anArg == "-unsetwidth"
1832 || anArg == "-unsetlinewidth")
1834 aChangeSet->ToSetLineWidth = -1;
1835 aChangeSet->LineWidth = 1.0;
1837 else if (anArg == "-settransp"
1838 || anArg == "-settransparency")
1840 if (++anArgIter >= theArgNb)
1842 std::cout << "Error: wrong syntax at " << anArg << "\n";
1845 aChangeSet->ToSetTransparency = 1;
1846 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1847 if (aChangeSet->Transparency >= 0.0
1848 && aChangeSet->Transparency <= Precision::Confusion())
1850 aChangeSet->ToSetTransparency = -1;
1851 aChangeSet->Transparency = 0.0;
1854 else if (anArg == "-setvis"
1855 || anArg == "-setvisibility")
1857 if (++anArgIter >= theArgNb)
1859 std::cout << "Error: wrong syntax at " << anArg << "\n";
1863 aChangeSet->ToSetVisibility = 1;
1864 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1866 else if (anArg == "-setalpha")
1868 if (++anArgIter >= theArgNb)
1870 std::cout << "Error: wrong syntax at " << anArg << "\n";
1873 aChangeSet->ToSetTransparency = 1;
1874 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1875 if (aChangeSet->Transparency < 0.0
1876 || aChangeSet->Transparency > 1.0)
1878 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1881 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1882 if (aChangeSet->Transparency >= 0.0
1883 && aChangeSet->Transparency <= Precision::Confusion())
1885 aChangeSet->ToSetTransparency = -1;
1886 aChangeSet->Transparency = 0.0;
1889 else if (anArg == "-unsettransp"
1890 || anArg == "-unsettransparency"
1891 || anArg == "-unsetalpha"
1892 || anArg == "-opaque")
1894 aChangeSet->ToSetTransparency = -1;
1895 aChangeSet->Transparency = 0.0;
1897 else if (anArg == "-setcolor")
1899 Standard_Integer aNbComps = 0;
1900 Standard_Integer aCompIter = anArgIter + 1;
1901 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1903 if (theArgVec[aCompIter][0] == '-')
1912 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1913 Standard_CString aName = theArgVec[anArgIter + 1];
1914 if (!Quantity_Color::ColorFromName (aName, aColor))
1916 std::cout << "Error: unknown color name '" << aName << "'\n";
1919 aChangeSet->Color = aColor;
1924 Graphic3d_Vec3d anRgb;
1925 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1926 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1927 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1928 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1929 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1930 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1932 std::cout << "Error: RGB color values should be within range 0..1!\n";
1935 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1940 std::cout << "Error: wrong syntax at " << anArg << "\n";
1944 aChangeSet->ToSetColor = 1;
1945 anArgIter += aNbComps;
1947 else if (anArg == "-setlinetype")
1949 if (++anArgIter >= theArgNb)
1951 std::cout << "Error: wrong syntax at " << anArg << "\n";
1954 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aChangeSet->TypeOfLine))
1956 std::cout << "Error: wrong syntax at " << anArg << "\n";
1960 aChangeSet->ToSetTypeOfLine = 1;
1962 else if (anArg == "-unsetlinetype")
1964 aChangeSet->ToSetTypeOfLine = -1;
1966 else if (anArg == "-unsetcolor")
1968 aChangeSet->ToSetColor = -1;
1969 aChangeSet->Color = DEFAULT_COLOR;
1971 else if (anArg == "-setmat"
1972 || anArg == "-setmaterial")
1974 if (++anArgIter >= theArgNb)
1976 std::cout << "Error: wrong syntax at " << anArg << "\n";
1979 aChangeSet->ToSetMaterial = 1;
1980 aChangeSet->MatName = theArgVec[anArgIter];
1981 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1983 else if (anArg == "-unsetmat"
1984 || anArg == "-unsetmaterial")
1986 aChangeSet->ToSetMaterial = -1;
1987 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1989 else if (anArg == "-subshape"
1990 || anArg == "-subshapes")
1994 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1998 if (aNames.IsEmpty())
2000 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2004 aChanges.Append (ViewerTest_AspectsChangeSet());
2005 aChangeSet = &aChanges.ChangeLast();
2007 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2009 Standard_CString aSubShapeName = theArgVec[anArgIter];
2010 if (*aSubShapeName == '-')
2016 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2017 if (aSubShape.IsNull())
2019 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2022 aChangeSet->SubShapes.Append (aSubShape);
2025 if (aChangeSet->SubShapes.IsEmpty())
2027 std::cerr << "Error: empty list is specified after -subshapes!\n";
2031 else if (anArg == "-freeboundary"
2034 if (++anArgIter >= theArgNb)
2036 std::cout << "Error: wrong syntax at " << anArg << "\n";
2039 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2044 aChangeSet->ToSetShowFreeBoundary = 1;
2046 else if (aValue == "off"
2049 aChangeSet->ToSetShowFreeBoundary = -1;
2053 std::cout << "Error: wrong syntax at " << anArg << "\n";
2057 else if (anArg == "-setfreeboundarywidth"
2058 || anArg == "-setfbwidth")
2060 if (++anArgIter >= theArgNb)
2062 std::cout << "Error: wrong syntax at " << anArg << "\n";
2065 aChangeSet->ToSetFreeBoundaryWidth = 1;
2066 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2068 else if (anArg == "-unsetfreeboundarywidth"
2069 || anArg == "-unsetfbwidth")
2071 aChangeSet->ToSetFreeBoundaryWidth = -1;
2072 aChangeSet->FreeBoundaryWidth = 1.0;
2074 else if (anArg == "-setfreeboundarycolor"
2075 || anArg == "-setfbcolor")
2077 Standard_Integer aNbComps = 0;
2078 Standard_Integer aCompIter = anArgIter + 1;
2079 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2081 if (theArgVec[aCompIter][0] == '-')
2090 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2091 Standard_CString aName = theArgVec[anArgIter + 1];
2092 if (!Quantity_Color::ColorFromName (aName, aColor))
2094 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2097 aChangeSet->FreeBoundaryColor = aColor;
2102 Graphic3d_Vec3d anRgb;
2103 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2104 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2105 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2106 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2107 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2108 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2110 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2113 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2118 std::cout << "Error: wrong syntax at " << anArg << "\n";
2122 aChangeSet->ToSetFreeBoundaryColor = 1;
2123 anArgIter += aNbComps;
2125 else if (anArg == "-unsetfreeboundarycolor"
2126 || anArg == "-unsetfbcolor")
2128 aChangeSet->ToSetFreeBoundaryColor = -1;
2129 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2131 else if (anArg == "-unset")
2133 aChangeSet->ToSetVisibility = 1;
2134 aChangeSet->Visibility = 1;
2135 aChangeSet->ToSetLineWidth = -1;
2136 aChangeSet->LineWidth = 1.0;
2137 aChangeSet->ToSetTypeOfLine = -1;
2138 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2139 aChangeSet->ToSetTransparency = -1;
2140 aChangeSet->Transparency = 0.0;
2141 aChangeSet->ToSetColor = -1;
2142 aChangeSet->Color = DEFAULT_COLOR;
2143 aChangeSet->ToSetMaterial = -1;
2144 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2145 aChangeSet->ToSetShowFreeBoundary = -1;
2146 aChangeSet->ToSetFreeBoundaryColor = -1;
2147 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2148 aChangeSet->ToSetFreeBoundaryWidth = -1;
2149 aChangeSet->FreeBoundaryWidth = 1.0;
2150 aChangeSet->ToSetHatch = -1;
2151 aChangeSet->StdHatchStyle = -1;
2152 aChangeSet->PathToHatchPattern.Clear();
2154 else if (anArg == "-isoontriangulation"
2155 || anArg == "-isoontriang")
2157 if (++anArgIter >= theArgNb)
2159 std::cout << "Error: wrong syntax at " << anArg << "\n";
2162 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2167 aChangeSet->ToEnableIsoOnTriangulation = 1;
2169 else if (aValue == "off"
2172 aChangeSet->ToEnableIsoOnTriangulation = 0;
2176 std::cout << "Error: wrong syntax at " << anArg << "\n";
2180 else if (anArg == "-setmaxparamvalue")
2182 if (++anArgIter >= theArgNb)
2184 std::cout << "Error: wrong syntax at " << anArg << "\n";
2187 aChangeSet->ToSetMaxParamValue = 1;
2188 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2190 else if (anArg == "-setsensitivity")
2194 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2198 if (aNames.IsEmpty())
2200 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2204 if (anArgIter + 2 >= theArgNb)
2206 std::cout << "Error: wrong syntax at " << anArg << "\n";
2209 aChangeSet->ToSetSensitivity = 1;
2210 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2211 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2213 else if (anArg == "-sethatch")
2217 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2221 if (aNames.IsEmpty())
2223 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2227 aChangeSet->ToSetHatch = 1;
2228 TCollection_AsciiString anArg (theArgVec[++anArgIter]);
2229 if (anArg.Length() <= 2)
2231 aChangeSet->StdHatchStyle = Draw::Atoi (anArg.ToCString());
2235 aChangeSet->PathToHatchPattern = anArg;
2240 std::cout << "Error: wrong syntax at " << anArg << "\n";
2245 Standard_Boolean isFirst = Standard_True;
2246 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2247 aChangesIter.More(); aChangesIter.Next())
2249 if (!aChangesIter.Value().Validate (!isFirst))
2253 isFirst = Standard_False;
2256 // special case for -defaults parameter.
2257 // all changed values will be set to DefaultDrawer.
2260 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2262 if (aChangeSet->ToSetLineWidth != 0)
2264 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2265 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2266 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2267 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2269 if (aChangeSet->ToSetColor != 0)
2271 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2272 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2273 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2274 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2275 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2276 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2278 if (aChangeSet->ToSetTypeOfLine != 0)
2280 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2281 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2282 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2283 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2284 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2286 if (aChangeSet->ToSetTransparency != 0)
2288 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2290 if (aChangeSet->ToSetMaterial != 0)
2292 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2294 if (aChangeSet->ToSetShowFreeBoundary == 1)
2296 aDrawer->SetFreeBoundaryDraw (Standard_True);
2298 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2300 aDrawer->SetFreeBoundaryDraw (Standard_False);
2302 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2304 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2306 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2308 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2310 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2312 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2314 if (aChangeSet->ToSetMaxParamValue != 0)
2316 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2319 // redisplay all objects in context
2320 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2322 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2325 aCtx->Redisplay (aPrs, Standard_False);
2331 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2333 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2334 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2335 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2336 Handle(AIS_ColoredShape) aColoredPrs;
2337 Standard_Boolean toDisplay = Standard_False;
2338 Standard_Boolean toRedisplay = Standard_False;
2339 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2341 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2342 if (aShapePrs.IsNull())
2344 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2347 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2348 if (aColoredPrs.IsNull())
2350 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2351 if (aShapePrs->HasDisplayMode())
2353 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2355 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2356 aCtx->Remove (aShapePrs, Standard_False);
2357 GetMapOfAIS().UnBind2 (aName);
2358 GetMapOfAIS().Bind (aColoredPrs, aName);
2359 toDisplay = Standard_True;
2360 aShapePrs = aColoredPrs;
2367 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2368 aChangeSet = &aChangesIter.ChangeValue();
2369 if (aChangeSet->ToSetVisibility == 1)
2371 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2372 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2374 else if (aChangeSet->ToSetMaterial == 1)
2376 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2378 else if (aChangeSet->ToSetMaterial == -1)
2380 aCtx->UnsetMaterial (aPrs, Standard_False);
2382 if (aChangeSet->ToSetColor == 1)
2384 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2386 else if (aChangeSet->ToSetColor == -1)
2388 aCtx->UnsetColor (aPrs, Standard_False);
2390 if (aChangeSet->ToSetTransparency == 1)
2392 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2394 else if (aChangeSet->ToSetTransparency == -1)
2396 aCtx->UnsetTransparency (aPrs, Standard_False);
2398 if (aChangeSet->ToSetLineWidth == 1)
2400 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2402 else if (aChangeSet->ToSetLineWidth == -1)
2404 aCtx->UnsetWidth (aPrs, Standard_False);
2406 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2408 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2409 toRedisplay = Standard_True;
2411 else if (aChangeSet->ToSetSensitivity != 0)
2413 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2415 if (!aDrawer.IsNull())
2417 if (aChangeSet->ToSetShowFreeBoundary == 1)
2419 aDrawer->SetFreeBoundaryDraw (Standard_True);
2420 toRedisplay = Standard_True;
2422 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2424 aDrawer->SetFreeBoundaryDraw (Standard_False);
2425 toRedisplay = Standard_True;
2427 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2429 Handle(Prs3d_LineAspect) aBoundaryAspect =
2430 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2431 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2432 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2433 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2434 toRedisplay = Standard_True;
2436 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2438 Handle(Prs3d_LineAspect) aBoundaryAspect =
2439 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2440 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2441 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2442 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2443 toRedisplay = Standard_True;
2445 if (aChangeSet->ToSetTypeOfLine != 0)
2447 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2448 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2449 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2450 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2451 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2452 toRedisplay = Standard_True;
2454 if (aChangeSet->ToSetMaxParamValue != 0)
2456 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2458 if (aChangeSet->ToSetHatch != 0)
2460 if (!aDrawer->HasOwnShadingAspect())
2462 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2463 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2466 Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
2467 if (aChangeSet->ToSetHatch == -1)
2469 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2473 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2474 if (!aChangeSet->PathToHatchPattern.IsEmpty())
2476 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2477 if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
2479 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2483 std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
2487 else if (aChangeSet->StdHatchStyle != -1)
2489 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
2492 toRedisplay = Standard_True;
2496 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2498 aChangeSet = &aChangesIter.ChangeValue();
2499 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2500 aSubShapeIter.More(); aSubShapeIter.Next())
2502 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2503 if (aChangeSet->ToSetVisibility == 1)
2505 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2506 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2508 if (aChangeSet->ToSetColor == 1)
2510 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2512 if (aChangeSet->ToSetLineWidth == 1)
2514 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2516 if (aChangeSet->ToSetColor == -1
2517 || aChangeSet->ToSetLineWidth == -1)
2519 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2521 if (aChangeSet->ToSetMaxParamValue != 0)
2523 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2524 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2526 if (aChangeSet->ToSetSensitivity != 0)
2528 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2534 aCtx->Display (aPrs, Standard_False);
2538 aCtx->Redisplay (aPrs, Standard_False);
2540 else if (!aColoredPrs.IsNull())
2542 aCtx->Redisplay (aColoredPrs, Standard_False);
2549 //==============================================================================
2550 //function : VDonly2
2552 //purpose : Display only a selected or named object
2553 // if there is no selected or named object s, nothing is done
2554 //==============================================================================
2555 static int VDonly2 (Draw_Interpretor& ,
2556 Standard_Integer theArgNb,
2557 const char** theArgVec)
2559 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2560 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2563 std::cerr << "Error: no active view!\n";
2567 Standard_DISABLE_DEPRECATION_WARNINGS
2568 if (aCtx->HasOpenedContext())
2570 aCtx->CloseLocalContext();
2572 Standard_ENABLE_DEPRECATION_WARNINGS
2574 Standard_Integer anArgIter = 1;
2575 for (; anArgIter < theArgNb; ++anArgIter)
2577 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2583 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2584 if (anArgIter >= theArgNb)
2586 // display only selected objects
2587 if (aCtx->NbSelected() < 1)
2592 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2594 aDispSet.Add (aCtx->SelectedInteractive());
2599 // display only specified objects
2600 for (; anArgIter < theArgNb; ++anArgIter)
2602 TCollection_AsciiString aName = theArgVec[anArgIter];
2603 if (GetMapOfAIS().IsBound2 (aName))
2605 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2606 if (!aShape.IsNull())
2608 aCtx->Display (aShape, Standard_False);
2609 aDispSet.Add (aShape);
2615 // weed out other objects
2616 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2618 if (aDispSet.Contains (anIter.Key1()))
2623 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2624 if (aShape.IsNull())
2626 aCtx->Erase (aShape, Standard_False);
2632 //==============================================================================
2633 //function : VRemove
2634 //purpose : Removes selected or named objects.
2635 // If there is no selected or named objects,
2636 // all objects in the viewer can be removed with argument -all.
2637 // If -context is in arguments, the object is not deleted from the map of
2638 // objects (deleted only from the current context).
2639 //==============================================================================
2640 int VRemove (Draw_Interpretor& theDI,
2641 Standard_Integer theArgNb,
2642 const char** theArgVec)
2644 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2645 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2648 std::cerr << "Error: no active view!\n";
2652 Standard_Boolean isContextOnly = Standard_False;
2653 Standard_Boolean toRemoveAll = Standard_False;
2654 Standard_Boolean toPrintInfo = Standard_True;
2655 Standard_Boolean toRemoveLocal = Standard_False;
2657 Standard_Integer anArgIter = 1;
2658 for (; anArgIter < theArgNb; ++anArgIter)
2660 TCollection_AsciiString anArg = theArgVec[anArgIter];
2662 if (anArg == "-context")
2664 isContextOnly = Standard_True;
2666 else if (anArg == "-all")
2668 toRemoveAll = Standard_True;
2670 else if (anArg == "-noinfo")
2672 toPrintInfo = Standard_False;
2674 else if (anArg == "-local")
2676 toRemoveLocal = Standard_True;
2678 else if (anUpdateTool.parseRedrawMode (anArg))
2688 && anArgIter < theArgNb)
2690 std::cerr << "Error: wrong syntax!\n";
2694 Standard_DISABLE_DEPRECATION_WARNINGS
2695 if (toRemoveLocal && !aCtx->HasOpenedContext())
2697 std::cerr << "Error: local selection context is not open.\n";
2700 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2702 aCtx->CloseAllContexts (Standard_False);
2704 Standard_ENABLE_DEPRECATION_WARNINGS
2706 NCollection_List<TCollection_AsciiString> anIONameList;
2709 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2710 anIter.More(); anIter.Next())
2712 anIONameList.Append (anIter.Key2());
2715 else if (anArgIter < theArgNb) // removed objects names are in argument list
2717 for (; anArgIter < theArgNb; ++anArgIter)
2719 TCollection_AsciiString aName = theArgVec[anArgIter];
2720 if (!GetMapOfAIS().IsBound2 (aName))
2722 theDI << aName.ToCString() << " was not bound to some object.\n";
2726 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2727 if (anIO->GetContext() != aCtx)
2729 theDI << aName.ToCString() << " was not displayed in current context.\n";
2730 theDI << "Please activate view with this object displayed and try again.\n";
2734 anIONameList.Append (aName);
2738 else if (aCtx->NbSelected() > 0)
2740 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2741 anIter.More(); anIter.Next())
2743 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2744 if (!aCtx->IsSelected (anIO))
2749 anIONameList.Append (anIter.Key2());
2754 // Unbind all removed objects from the map of displayed IO.
2755 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2756 anIter.More(); anIter.Next())
2758 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2759 aCtx->Remove (anIO, Standard_False);
2762 theDI << anIter.Value().ToCString() << " was removed\n";
2766 GetMapOfAIS().UnBind2 (anIter.Value());
2770 // Close local context if it is empty
2771 TColStd_MapOfTransient aLocalIO;
2772 Standard_DISABLE_DEPRECATION_WARNINGS
2773 if (aCtx->HasOpenedContext()
2774 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2776 aCtx->CloseAllContexts (Standard_False);
2778 Standard_ENABLE_DEPRECATION_WARNINGS
2783 //==============================================================================
2785 //purpose : Erase some selected or named objects
2786 // if there is no selected or named objects, the whole viewer is erased
2787 //==============================================================================
2788 int VErase (Draw_Interpretor& theDI,
2789 Standard_Integer theArgNb,
2790 const char** theArgVec)
2792 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2793 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2794 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2797 std::cerr << "Error: no active view!\n";
2801 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2803 Standard_Integer anArgIter = 1;
2804 Standard_Boolean toEraseLocal = Standard_False;
2805 Standard_Boolean toEraseInView = Standard_False;
2806 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2807 for (; anArgIter < theArgNb; ++anArgIter)
2809 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2810 anArgCase.LowerCase();
2811 if (anUpdateTool.parseRedrawMode (anArgCase))
2815 else if (anArgCase == "-local")
2817 toEraseLocal = Standard_True;
2819 else if (anArgCase == "-view"
2820 || anArgCase == "-inview")
2822 toEraseInView = Standard_True;
2826 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2830 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2832 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2836 Standard_DISABLE_DEPRECATION_WARNINGS
2837 if (toEraseLocal && !aCtx->HasOpenedContext())
2839 std::cerr << "Error: local selection context is not open.\n";
2842 else if (!toEraseLocal && aCtx->HasOpenedContext())
2844 aCtx->CloseAllContexts (Standard_False);
2846 Standard_ENABLE_DEPRECATION_WARNINGS
2848 if (!aNamesOfEraseIO.IsEmpty())
2850 // Erase named objects
2851 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2853 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2854 if (!GetMapOfAIS().IsBound2 (aName))
2859 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2860 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2861 theDI << aName.ToCString() << " ";
2866 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2870 aCtx->Erase (anIO, Standard_False);
2875 else if (!toEraseAll && aCtx->NbSelected() > 0)
2877 // Erase selected objects
2878 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
2879 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2880 anIter.More(); anIter.Next())
2882 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2884 && aCtx->IsSelected (anIO))
2886 theDI << anIter.Key2().ToCString() << " ";
2889 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2891 else if (aHasOpenedContext)
2893 aCtx->Erase (anIO, Standard_False);
2900 aCtx->EraseSelected (Standard_False);
2905 // Erase all objects
2906 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2907 anIter.More(); anIter.Next())
2909 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2914 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2918 aCtx->Erase (anIO, Standard_False);
2927 //==============================================================================
2928 //function : VDisplayAll
2930 //purpose : Display all the objects of the Map
2931 //==============================================================================
2932 static int VDisplayAll (Draw_Interpretor& ,
2933 Standard_Integer theArgNb,
2934 const char** theArgVec)
2937 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2938 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2941 std::cerr << "Error: no active view!\n";
2945 Standard_Integer anArgIter = 1;
2946 Standard_Boolean toDisplayLocal = Standard_False;
2947 for (; anArgIter < theArgNb; ++anArgIter)
2949 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2950 anArgCase.LowerCase();
2951 if (anArgCase == "-local")
2953 toDisplayLocal = Standard_True;
2955 else if (anUpdateTool.parseRedrawMode (anArgCase))
2964 if (anArgIter < theArgNb)
2966 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2970 Standard_DISABLE_DEPRECATION_WARNINGS
2971 if (toDisplayLocal && !aCtx->HasOpenedContext())
2973 std::cerr << "Error: local selection context is not open.\n";
2976 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2978 aCtx->CloseLocalContext (Standard_False);
2980 Standard_ENABLE_DEPRECATION_WARNINGS
2982 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2983 anIter.More(); anIter.Next())
2985 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2986 aCtx->Erase (aShape, Standard_False);
2989 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2990 anIter.More(); anIter.Next())
2992 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2993 aCtx->Display (aShape, Standard_False);
2998 //! Auxiliary method to check if presentation exists
2999 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3000 const Handle(AIS_InteractiveObject)& theIO,
3001 const Standard_Integer theMode)
3003 if (theIO.IsNull() || theCtx.IsNull())
3010 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3015 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3017 return theIO->DisplayMode();
3019 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3021 return theCtx->DisplayMode();
3027 enum ViewerTest_BndAction
3034 //! Auxiliary method to print bounding box of presentation
3035 inline void bndPresentation (Draw_Interpretor& theDI,
3036 const Handle(PrsMgr_PresentationManager)& theMgr,
3037 const Handle(AIS_InteractiveObject)& theObj,
3038 const Standard_Integer theDispMode,
3039 const TCollection_AsciiString& theName,
3040 const ViewerTest_BndAction theAction,
3041 const Handle(Prs3d_Drawer)& theStyle)
3045 case BndAction_Hide:
3047 theMgr->Unhighlight (theObj);
3050 case BndAction_Show:
3052 theMgr->Color (theObj, theStyle, theDispMode);
3055 case BndAction_Print:
3058 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3060 if (aPrsIter.Value().Mode() != theDispMode)
3063 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3065 gp_Pnt aMin = aBox.CornerMin();
3066 gp_Pnt aMax = aBox.CornerMax();
3067 theDI << theName << "\n"
3068 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3069 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
3075 //==============================================================================
3076 //function : VBounding
3078 //==============================================================================
3079 int VBounding (Draw_Interpretor& theDI,
3080 Standard_Integer theArgNb,
3081 const char** theArgVec)
3083 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3084 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3087 std::cout << "Error: no active view!\n";
3091 ViewerTest_BndAction anAction = BndAction_Show;
3092 Standard_Integer aMode = -1;
3094 Handle(Prs3d_Drawer) aStyle;
3096 Standard_Integer anArgIter = 1;
3097 for (; anArgIter < theArgNb; ++anArgIter)
3099 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3101 if (anArg == "-print")
3103 anAction = BndAction_Print;
3105 else if (anArg == "-show")
3107 anAction = BndAction_Show;
3109 else if (anArg == "-hide")
3111 anAction = BndAction_Hide;
3113 else if (anArg == "-mode")
3115 if (++anArgIter >= theArgNb)
3117 std::cout << "Error: wrong syntax at " << anArg << "\n";
3120 aMode = Draw::Atoi (theArgVec[anArgIter]);
3122 else if (!anUpdateTool.parseRedrawMode (anArg))
3128 if (anAction == BndAction_Show)
3130 aStyle = new Prs3d_Drawer();
3131 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3132 aStyle->SetColor (Quantity_NOC_GRAY99);
3135 Standard_Integer aHighlightedMode = -1;
3136 if (anArgIter < theArgNb)
3138 // has a list of names
3139 for (; anArgIter < theArgNb; ++anArgIter)
3141 TCollection_AsciiString aName = theArgVec[anArgIter];
3142 if (!GetMapOfAIS().IsBound2 (aName))
3144 std::cout << "Error: presentation " << aName << " does not exist\n";
3148 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3149 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3150 if (aHighlightedMode == -1)
3152 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3155 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3158 else if (aCtx->NbSelected() > 0)
3160 // remove all currently selected objects
3161 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3163 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3164 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3165 if (aHighlightedMode != -1)
3167 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3168 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3175 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3176 anIter.More(); anIter.Next())
3178 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3179 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3180 if (aHighlightedMode != -1)
3182 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3189 //==============================================================================
3190 //function : VTexture
3192 //==============================================================================
3193 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
3195 TCollection_AsciiString aCommandName (theArgv[0]);
3197 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3198 if (aCommandName == "vtexture")
3202 std::cout << theArgv[0] << ": invalid arguments.\n";
3203 std::cout << "Type help for more information.\n";
3207 // look for options of vtexture command
3208 TCollection_AsciiString aParseKey;
3209 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3211 TCollection_AsciiString anArg (theArgv [anArgIt]);
3214 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3217 aParseKey.Remove (1);
3218 aParseKey.UpperCase();
3219 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3223 if (aParseKey.IsEmpty())
3228 aMapOfArgs(aParseKey)->Append (anArg);
3231 else if (aCommandName == "vtexscale"
3232 || aCommandName == "vtexorigin"
3233 || aCommandName == "vtexrepeat")
3235 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3236 // equal to -scale, -origin, -repeat options of vtexture command
3237 if (theArgsNb < 2 || theArgsNb > 4)
3239 std::cout << theArgv[0] << ": invalid arguments.\n";
3240 std::cout << "Type help for more information.\n";
3244 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
3247 anArgs->Append ("OFF");
3249 else if (theArgsNb == 4)
3251 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3252 anArgs->Append (TCollection_AsciiString (theArgv[3]));
3255 TCollection_AsciiString anArgKey;
3256 if (aCommandName == "vtexscale")
3260 else if (aCommandName == "vtexorigin")
3262 anArgKey = "ORIGIN";
3266 anArgKey = "REPEAT";
3269 aMapOfArgs.Bind (anArgKey, anArgs);
3271 else if (aCommandName == "vtexdefault")
3273 // scan for parameters of vtexdefault command
3274 // equal to -default option of vtexture command
3275 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
3278 // Check arguments for validity
3279 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3280 for (; aMapIt.More(); aMapIt.Next())
3282 const TCollection_AsciiString& aKey = aMapIt.Key();
3283 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3285 // -scale, -origin, -repeat: one argument "off", or two real values
3286 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3287 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3288 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3293 // -modulate: single argument "on" / "off"
3294 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3299 // -default: no arguments
3300 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3305 TCollection_AsciiString aLowerKey;
3308 aLowerKey.LowerCase();
3309 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3310 std::cout << "Type help for more information.\n";
3314 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3315 if (anAISContext.IsNull())
3317 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
3321 Standard_Integer aPreviousMode = 0;
3323 TCollection_AsciiString aShapeName (theArgv[1]);
3324 Handle(AIS_InteractiveObject) anIO;
3326 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3327 if (aMapOfIO.IsBound2 (aShapeName))
3329 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3334 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3338 Handle(AIS_TexturedShape) aTexturedIO;
3339 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3341 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3342 aPreviousMode = aTexturedIO->DisplayMode();
3346 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3348 if (anIO->HasTransformation())
3350 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3351 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3354 anAISContext->Remove (anIO, Standard_False);
3355 GetMapOfAIS().UnBind1 (anIO);
3356 GetMapOfAIS().UnBind2 (aShapeName);
3357 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3360 // -------------------------------------------
3361 // Turn texturing on/off - only for vtexture
3362 // -------------------------------------------
3364 if (aCommandName == "vtexture")
3366 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3368 if (aTextureArg.IsEmpty())
3370 std::cout << aCommandName << ": Texture mapping disabled.\n";
3371 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
3373 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3374 if (aPreviousMode == 3)
3376 anAISContext->RecomputePrsOnly (aTexturedIO);
3379 anAISContext->Display (aTexturedIO, Standard_True);
3382 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3384 if (aTextureArg == "?")
3386 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3388 theDi << "\n Files in current directory : \n\n";
3389 theDi.Eval ("glob -nocomplain *");
3391 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3392 aCmnd += aTextureFolder;
3395 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
3396 theDi.Eval (aCmnd.ToCString());
3401 aTexturedIO->SetTextureFileName (aTextureArg);
3406 // ------------------------------------
3407 // Process other options and commands
3408 // ------------------------------------
3410 Handle(TColStd_HSequenceOfAsciiString) aValues;
3411 if (aMapOfArgs.Find ("DEFAULT", aValues))
3413 aTexturedIO->SetTextureRepeat (Standard_False);
3414 aTexturedIO->SetTextureOrigin (Standard_False);
3415 aTexturedIO->SetTextureScale (Standard_False);
3416 aTexturedIO->EnableTextureModulate();
3420 if (aMapOfArgs.Find ("SCALE", aValues))
3422 if (aValues->Value(1) != "OFF")
3424 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3428 aTexturedIO->SetTextureScale (Standard_False);
3432 if (aMapOfArgs.Find ("ORIGIN", aValues))
3434 if (aValues->Value(1) != "OFF")
3436 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3440 aTexturedIO->SetTextureOrigin (Standard_False);
3444 if (aMapOfArgs.Find ("REPEAT", aValues))
3446 if (aValues->Value(1) != "OFF")
3448 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3452 aTexturedIO->SetTextureRepeat (Standard_False);
3456 if (aMapOfArgs.Find ("MODULATE", aValues))
3458 if (aValues->Value(1) == "ON")
3460 aTexturedIO->EnableTextureModulate();
3464 aTexturedIO->DisableTextureModulate();
3469 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3471 anAISContext->RecomputePrsOnly (aTexturedIO);
3475 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3476 anAISContext->Display (aTexturedIO, Standard_True);
3477 anAISContext->Update (aTexturedIO,Standard_True);
3483 //! Auxiliary method to parse transformation persistence flags
3484 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3485 Graphic3d_TransModeFlags& theFlags)
3487 if (theFlagString == "zoom")
3489 theFlags = Graphic3d_TMF_ZoomPers;
3491 else if (theFlagString == "rotate")
3493 theFlags = Graphic3d_TMF_RotatePers;
3495 else if (theFlagString == "zoomrotate")
3497 theFlags = Graphic3d_TMF_ZoomRotatePers;
3499 else if (theFlagString == "trihedron"
3500 || theFlagString == "triedron")
3502 theFlags = Graphic3d_TMF_TriedronPers;
3504 else if (theFlagString == "none")
3506 theFlags = Graphic3d_TMF_None;
3510 return Standard_False;
3513 return Standard_True;
3516 //! Auxiliary method to parse transformation persistence flags
3517 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
3518 Aspect_TypeOfTriedronPosition& theCorner)
3520 TCollection_AsciiString aString (theString);
3521 aString.LowerCase();
3522 if (aString == "center")
3524 theCorner = Aspect_TOTP_CENTER;
3526 else if (aString == "top"
3527 || aString == "upper")
3529 theCorner = Aspect_TOTP_TOP;
3531 else if (aString == "bottom"
3532 || aString == "lower")
3534 theCorner = Aspect_TOTP_BOTTOM;
3536 else if (aString == "left")
3538 theCorner = Aspect_TOTP_LEFT;
3540 else if (aString == "right")
3542 theCorner = Aspect_TOTP_RIGHT;
3544 else if (aString == "topleft"
3545 || aString == "leftupper"
3546 || aString == "upperleft")
3548 theCorner = Aspect_TOTP_LEFT_UPPER;
3550 else if (aString == "bottomleft"
3551 || aString == "leftlower"
3552 || aString == "lowerleft")
3554 theCorner = Aspect_TOTP_LEFT_LOWER;
3556 else if (aString == "topright"
3557 || aString == "rightupper"
3558 || aString == "upperright")
3560 theCorner = Aspect_TOTP_RIGHT_UPPER;
3562 else if (aString == "bottomright"
3563 || aString == "lowerright"
3564 || aString == "rightlower")
3566 theCorner = Aspect_TOTP_RIGHT_LOWER;
3570 return Standard_False;
3573 return Standard_True;
3576 //==============================================================================
3577 //function : VDisplay2
3579 //purpose : Display an object from its name
3580 //==============================================================================
3581 static int VDisplay2 (Draw_Interpretor& theDI,
3582 Standard_Integer theArgNb,
3583 const char** theArgVec)
3587 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3591 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3594 ViewerTest::ViewerInit();
3595 aCtx = ViewerTest::GetAISContext();
3598 // Parse input arguments
3599 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3600 Standard_Integer isMutable = -1;
3601 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3602 Standard_Boolean toDisplayLocal = Standard_False;
3603 Standard_Boolean toReDisplay = Standard_False;
3604 Standard_Integer isSelectable = -1;
3605 Standard_Integer anObjDispMode = -2;
3606 Standard_Integer anObjHighMode = -2;
3607 Standard_Boolean toSetTrsfPers = Standard_False;
3608 Handle(Graphic3d_TransformPers) aTrsfPers;
3609 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3610 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3611 Standard_Integer toDisplayInView = Standard_False;
3612 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3614 const TCollection_AsciiString aName = theArgVec[anArgIter];
3615 TCollection_AsciiString aNameCase = aName;
3616 aNameCase.LowerCase();
3617 if (anUpdateTool.parseRedrawMode (aName))
3621 else if (aNameCase == "-mutable")
3625 else if (aNameCase == "-neutral")
3627 aDispStatus = AIS_DS_Displayed;
3629 else if (aNameCase == "-immediate"
3630 || aNameCase == "-top")
3632 aZLayer = Graphic3d_ZLayerId_Top;
3634 else if (aNameCase == "-topmost")
3636 aZLayer = Graphic3d_ZLayerId_Topmost;
3638 else if (aNameCase == "-osd"
3639 || aNameCase == "-toposd"
3640 || aNameCase == "-overlay")
3642 aZLayer = Graphic3d_ZLayerId_TopOSD;
3644 else if (aNameCase == "-botosd"
3645 || aNameCase == "-underlay")
3647 aZLayer = Graphic3d_ZLayerId_BotOSD;
3649 else if (aNameCase == "-select"
3650 || aNameCase == "-selectable")
3654 else if (aNameCase == "-noselect"
3655 || aNameCase == "-noselection")
3659 else if (aNameCase == "-dispmode"
3660 || aNameCase == "-displaymode")
3662 if (++anArgIter >= theArgNb)
3664 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3668 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3670 else if (aNameCase == "-highmode"
3671 || aNameCase == "-highlightmode")
3673 if (++anArgIter >= theArgNb)
3675 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3679 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3681 else if (aNameCase == "-3d")
3683 toSetTrsfPers = Standard_True;
3684 aTrsfPers.Nullify();
3686 else if (aNameCase == "-2d"
3687 || aNameCase == "-trihedron"
3688 || aNameCase == "-triedron")
3690 toSetTrsfPers = Standard_True;
3691 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3693 if (anArgIter + 1 < theArgNb)
3695 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
3696 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
3699 aTrsfPers->SetCorner2d (aCorner);
3701 if (anArgIter + 2 < theArgNb)
3703 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
3704 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
3705 if (anX.IsIntegerValue()
3706 && anY.IsIntegerValue())
3709 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
3715 else if (aNameCase == "-trsfpers"
3716 || aNameCase == "-pers")
3718 if (++anArgIter >= theArgNb
3719 || !aTrsfPers.IsNull())
3721 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3725 toSetTrsfPers = Standard_True;
3726 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3727 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3728 aPersFlags.LowerCase();
3729 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3731 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3735 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
3737 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3739 else if (aTrsfPersFlags != Graphic3d_TMF_None)
3741 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
3744 else if (aNameCase == "-trsfperspos"
3745 || aNameCase == "-perspos")
3747 if (anArgIter + 2 >= theArgNb
3748 || aTrsfPers.IsNull())
3750 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3754 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3755 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3756 TCollection_AsciiString aZ = "0";
3757 if (!aX.IsRealValue()
3758 || !aY.IsRealValue())
3760 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3763 if (anArgIter + 1 < theArgNb)
3765 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3766 if (aTemp.IsRealValue())
3773 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
3774 if (aTrsfPers->IsZoomOrRotate())
3776 aTrsfPers->SetAnchorPoint (aPnt);
3778 else if (aTrsfPers->IsTrihedronOr2d())
3780 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
3783 else if (aNameCase == "-layer")
3785 if (++anArgIter >= theArgNb)
3787 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3791 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3792 if (!aValue.IsIntegerValue())
3794 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3798 aZLayer = aValue.IntegerValue();
3800 else if (aNameCase == "-view"
3801 || aNameCase == "-inview")
3803 toDisplayInView = Standard_True;
3805 else if (aNameCase == "-local")
3807 aDispStatus = AIS_DS_Temporary;
3808 toDisplayLocal = Standard_True;
3810 else if (aNameCase == "-redisplay")
3812 toReDisplay = Standard_True;
3816 aNamesOfDisplayIO.Append (aName);
3820 if (aNamesOfDisplayIO.IsEmpty())
3822 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3826 // Prepare context for display
3827 Standard_DISABLE_DEPRECATION_WARNINGS
3828 if (toDisplayLocal && !aCtx->HasOpenedContext())
3830 aCtx->OpenLocalContext (Standard_False);
3832 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3834 aCtx->CloseAllContexts (Standard_False);
3836 Standard_ENABLE_DEPRECATION_WARNINGS
3838 // Display interactive objects
3839 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3841 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3843 if (!GetMapOfAIS().IsBound2 (aName))
3845 // create the AIS_Shape from a name
3846 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3847 if (!aShape.IsNull())
3849 if (isMutable != -1)
3851 aShape->SetMutable (isMutable == 1);
3853 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3855 aShape->SetZLayer (aZLayer);
3859 aCtx->SetTransformPersistence (aShape, aTrsfPers);
3861 if (anObjDispMode != -2)
3863 aShape->SetDisplayMode (anObjDispMode);
3865 if (anObjHighMode != -2)
3867 aShape->SetHilightMode (anObjHighMode);
3869 if (!toDisplayLocal)
3870 GetMapOfAIS().Bind (aShape, aName);
3872 Standard_Integer aDispMode = aShape->HasDisplayMode()
3873 ? aShape->DisplayMode()
3874 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3875 ? aCtx->DisplayMode()
3877 Standard_Integer aSelMode = -1;
3878 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3880 aSelMode = aShape->GlobalSelectionMode();
3883 aCtx->Display (aShape, aDispMode, aSelMode,
3884 Standard_False, aShape->AcceptShapeDecomposition(),
3886 if (toDisplayInView)
3888 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
3890 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
3892 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3897 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3902 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3903 if (isMutable != -1)
3905 aShape->SetMutable (isMutable == 1);
3907 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3909 aShape->SetZLayer (aZLayer);
3913 aCtx->SetTransformPersistence (aShape, aTrsfPers);
3915 if (anObjDispMode != -2)
3917 aShape->SetDisplayMode (anObjDispMode);
3919 if (anObjHighMode != -2)
3921 aShape->SetHilightMode (anObjHighMode);
3923 Standard_Integer aDispMode = aShape->HasDisplayMode()
3924 ? aShape->DisplayMode()
3925 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3926 ? aCtx->DisplayMode()
3928 Standard_Integer aSelMode = -1;
3929 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3931 aSelMode = aShape->GlobalSelectionMode();
3934 if (aShape->Type() == AIS_KOI_Datum)
3936 aCtx->Display (aShape, Standard_False);
3940 theDI << "Display " << aName.ToCString() << "\n";
3942 // update the Shape in the AIS_Shape
3943 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3944 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3945 if (!aShapePrs.IsNull())
3947 if (!aShapePrs->Shape().IsEqual (aNewShape))
3949 toReDisplay = Standard_True;
3951 aShapePrs->Set (aNewShape);
3955 aCtx->Redisplay (aShape, Standard_False);
3960 aCtx->Erase (aShape);
3962 aCtx->Display (aShape, aDispMode, aSelMode,
3963 Standard_False, aShape->AcceptShapeDecomposition(),
3965 if (toDisplayInView)
3967 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3975 //===============================================================================================
3976 //function : VUpdate
3978 //===============================================================================================
3979 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3981 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3982 if (aContextAIS.IsNull())
3984 std::cout << theArgVec[0] << "AIS context is not available.\n";
3990 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3994 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3996 AIS_ListOfInteractive aListOfIO;
3998 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4000 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
4002 Handle(AIS_InteractiveObject) anAISObj;
4003 if (anAISMap.IsBound2 (aName))
4005 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
4008 if (anAISObj.IsNull())
4010 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
4014 aListOfIO.Append (anAISObj);
4017 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
4018 for (; anIOIt.More(); anIOIt.Next())
4020 aContextAIS->Update (anIOIt.Value(), Standard_False);
4023 aContextAIS->UpdateCurrentViewer();
4028 //==============================================================================
4030 //purpose : Test the annimation of an object along a
4031 // predifined trajectory
4032 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
4033 //==============================================================================
4035 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
4038 Standard_Real Step=4*M_PI/180;
4039 Standard_Real Angle=0;
4041 Handle(AIS_InteractiveObject) aIO;
4042 if (GetMapOfAIS().IsBound2(argv[1]))
4043 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4047 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
4051 if (Draw::Atoi(argv[3])==1 ) {
4052 di<<" Primitives sensibles OFF\n";
4053 TheAISContext()->Deactivate(aIO);
4056 di<<" Primitives sensibles ON\n";
4058 // Movement par transformation
4059 if(Draw::Atoi(argv[2]) ==1) {
4060 di<<" Calcul par Transformation\n";
4061 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
4065 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
4066 TheAISContext()->SetLocation(aShape,myTransfo);
4067 TheAISContext() ->UpdateCurrentViewer();
4072 di<<" Calcul par Locations\n";
4073 gp_Trsf myAngleTrsf;
4074 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
4075 TopLoc_Location myDeltaAngle (myAngleTrsf);
4076 TopLoc_Location myTrueLoc;
4078 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
4081 myTrueLoc=myTrueLoc*myDeltaAngle;
4082 TheAISContext()->SetLocation(aShape,myTrueLoc );
4083 TheAISContext() ->UpdateCurrentViewer();
4086 if (Draw::Atoi(argv[3])==1 ){
4087 // On reactive la selection des primitives sensibles
4088 TheAISContext()->Activate(aIO,0);
4090 a3DView() -> Redraw();
4092 di<<" Temps ecoule \n";
4097 //==============================================================================
4098 //function : VShading
4099 //purpose : Sharpen or roughten the quality of the shading
4100 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4101 //==============================================================================
4102 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4104 Standard_Real myDevCoef;
4105 Handle(AIS_InteractiveObject) TheAisIO;
4108 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4112 myDevCoef =Draw::Atof(argv[2]);
4115 TCollection_AsciiString name=argv[1];
4116 if (GetMapOfAIS().IsBound2(name ))
4117 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4118 if (TheAisIO.IsNull())
4119 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4122 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4124 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4126 TheAISContext()->Redisplay(TheAisIO);
4129 //==============================================================================
4130 //function : HaveMode
4131 //use : VActivatedModes
4132 //==============================================================================
4133 #include <TColStd_ListIteratorOfListOfInteger.hxx>
4135 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
4137 TColStd_ListOfInteger List;
4138 TheAISContext()->ActivatedModes (TheAisIO,List);
4139 TColStd_ListIteratorOfListOfInteger it;
4140 Standard_Boolean Found=Standard_False;
4141 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4142 if (it.Value()==mode ) Found=Standard_True;
4149 //==============================================================================
4150 //function : VActivatedMode
4152 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
4153 // (edges,vertex...)qui lui est propre et le mode de selection standard.
4154 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4155 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4156 // qu'un nom et qu'un mode.
4157 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4158 //==============================================================================
4159 #include <AIS_ListIteratorOfListOfInteractive.hxx>
4161 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4164 Standard_Boolean ThereIsName = Standard_False ;
4166 if(!a3DView().IsNull()){
4168 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
4169 // verification des arguments
4171 if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
4172 ThereIsName = (argc == 3);
4176 Standard_DISABLE_DEPRECATION_WARNINGS
4178 if (argc>1) {di<<" Syntaxe error\n";return 1;}
4180 di<<" R.A.Z de tous les modes de selecion\n";
4181 di<<" Fermeture du Context local\n";
4182 if (TheAISContext()->HasOpenedContext())
4184 TheAISContext()->CloseLocalContext();
4187 Standard_ENABLE_DEPRECATION_WARNINGS
4190 // IL n'y a aps de nom de shape passe en argument
4191 if (HaveToSet && !ThereIsName){
4192 Standard_Integer aMode=Draw::Atoi(argv [1]);
4194 const char *cmode="???";
4196 case 0: cmode = "Shape"; break;
4197 case 1: cmode = "Vertex"; break;
4198 case 2: cmode = "Edge"; break;
4199 case 3: cmode = "Wire"; break;
4200 case 4: cmode = "Face"; break;
4201 case 5: cmode = "Shell"; break;
4202 case 6: cmode = "Solid"; break;
4203 case 7: cmode = "Compound"; break;
4206 if( !TheAISContext()->HasOpenedContext() ) {
4207 // il n'y a pas de Context local d'ouvert
4208 // on en ouvre un et on charge toutes les shapes displayees
4209 // on load tous les objets displayees et on Activate les objets de la liste
4210 AIS_ListOfInteractive ListOfIO;
4211 // on sauve dans une AISListOfInteractive tous les objets currents
4212 if (TheAISContext()->NbSelected()>0 ){
4213 TheAISContext()->UnhilightSelected(Standard_False);
4215 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4216 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
4220 Standard_DISABLE_DEPRECATION_WARNINGS
4221 TheAISContext()->OpenLocalContext(Standard_False);
4222 Standard_ENABLE_DEPRECATION_WARNINGS
4223 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4226 Handle(AIS_InteractiveObject) aIO =
4227 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4229 TheAISContext()->Load(aIO,0,Standard_False);
4232 // traitement des objets qui etaient currents dans le Contexte global
4233 if (!ListOfIO.IsEmpty() ) {
4234 // il y avait des objets currents
4235 AIS_ListIteratorOfListOfInteractive iter;
4236 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4237 Handle(AIS_InteractiveObject) aIO=iter.Value();
4238 TheAISContext()->Activate(aIO,aMode);
4239 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4243 // On applique le mode a tous les objets displayes
4244 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4245 it2 (GetMapOfAIS());
4247 Handle(AIS_InteractiveObject) aIO =
4248 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4249 if (!aIO.IsNull()) {
4250 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4251 TheAISContext()->Activate(aIO,aMode);
4260 // un Context local est deja ouvert
4261 // Traitement des objets du Context local
4262 if (TheAISContext()->NbSelected()>0 ){
4263 TheAISContext()->UnhilightSelected(Standard_False);
4264 // il y a des objets selected,on les parcourt
4265 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4266 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
4269 if (HaveMode(aIO,aMode) ) {
4270 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4271 TheAISContext()->Deactivate(aIO,aMode);
4274 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4275 TheAISContext()->Activate(aIO,aMode);
4281 // il n'y a pas d'objets selected
4282 // tous les objets diplayes sont traites
4283 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4286 Handle(AIS_InteractiveObject) aIO =
4287 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4288 if (!aIO.IsNull()) {
4289 if (HaveMode(aIO,aMode) ) {
4290 di<<" Mode: "<<cmode<<" OFF pour "
4291 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4292 TheAISContext()->Deactivate(aIO,aMode);
4295 di<<" Mode: "<<cmode<<" ON pour"
4296 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4297 TheAISContext()->Activate(aIO,aMode);
4305 else if (HaveToSet && ThereIsName){
4306 Standard_Integer aMode=Draw::Atoi(argv [2]);
4307 Handle(AIS_InteractiveObject) aIO =
4308 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4310 if (!aIO.IsNull()) {
4311 const char *cmode="???";
4314 case 0: cmode = "Shape"; break;
4315 case 1: cmode = "Vertex"; break;
4316 case 2: cmode = "Edge"; break;
4317 case 3: cmode = "Wire"; break;
4318 case 4: cmode = "Face"; break;
4319 case 5: cmode = "Shell"; break;
4320 case 6: cmode = "Solid"; break;
4321 case 7: cmode = "Compound"; break;
4324 if( !TheAISContext()->HasOpenedContext() ) {
4325 Standard_DISABLE_DEPRECATION_WARNINGS
4326 TheAISContext()->OpenLocalContext(Standard_False);
4327 Standard_ENABLE_DEPRECATION_WARNINGS
4328 // On charge tous les objets de la map
4329 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4331 Handle(AIS_InteractiveObject) aShape=
4332 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4333 if (!aShape.IsNull())
4334 TheAISContext()->Load(aShape,0,Standard_False);
4337 TheAISContext()->Activate(aIO,aMode);
4338 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4342 // un Context local est deja ouvert
4343 if (HaveMode(aIO,aMode) ) {
4344 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4345 TheAISContext()->Deactivate(aIO,aMode);
4348 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4349 TheAISContext()->Activate(aIO,aMode);
4358 //! Auxiliary method to print Interactive Object information
4359 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4360 const Handle(Standard_Transient)& theObject,
4361 Draw_Interpretor& theDI)
4363 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4366 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4370 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4371 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4372 << (theDetected.Contains (anObj) ? " Detected" : " ")
4374 if (anObj->Type() == AIS_KOI_Datum)
4377 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4378 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4379 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4380 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4381 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4382 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4383 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4386 else if (anObj->Type() == AIS_KOI_Shape
4387 && anObj->Signature() == 0)
4389 theDI << " AIS_Shape";
4391 else if (anObj->Type() == AIS_KOI_Relation)
4393 // AIS_Dimention and AIS_Relation
4394 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4395 switch (aRelation->KindOfDimension())
4397 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4398 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4399 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4400 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4401 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4402 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4403 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4404 default: theDI << " UNKNOWN dimension"; break;
4409 theDI << " UserPrs";
4411 theDI << " (" << theObject->DynamicType()->Name() << ")";
4414 //! Print information about locally selected sub-shapes
4415 template <typename T>
4416 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4418 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4419 TCollection_AsciiString aPrevName;
4420 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4422 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4423 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4424 if (aShapeIO.IsNull() || anOwner.IsNull())
4428 if (anOwner == aShapeIO->GlobalSelOwner())
4431 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4432 if (aSubShape.IsNull()
4433 || aShapeIO.IsNull()
4434 || !GetMapOfAIS().IsBound1 (aShapeIO))
4439 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4440 TopTools_MapOfShape aFilter;
4441 Standard_Integer aNumber = 0;
4442 const TopoDS_Shape aShape = aShapeIO->Shape();
4443 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4444 anIter.More(); anIter.Next())
4446 if (!aFilter.Add (anIter.Current()))
4448 continue; // filter duplicates
4452 if (!anIter.Current().IsSame (aSubShape))
4457 Standard_CString aShapeName = NULL;
4458 switch (aSubShape.ShapeType())
4460 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4461 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4462 case TopAbs_SOLID: aShapeName = " Solid"; break;
4463 case TopAbs_SHELL: aShapeName = " Shell"; break;
4464 case TopAbs_FACE: aShapeName = " Face"; break;
4465 case TopAbs_WIRE: aShapeName = " Wire"; break;
4466 case TopAbs_EDGE: aShapeName = " Edge"; break;
4467 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4469 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4472 if (aParentName != aPrevName)
4474 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4475 aPrevName = aParentName;
4477 theDI << " " << aShapeName << " #" << aNumber << "\n";
4483 //==============================================================================
4486 //==============================================================================
4487 static Standard_Integer VState (Draw_Interpretor& theDI,
4488 Standard_Integer theArgNb,
4489 Standard_CString* theArgVec)
4491 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4494 std::cerr << "Error: No opened viewer!\n";
4498 Standard_Boolean toPrintEntities = Standard_False;
4499 Standard_Boolean toCheckSelected = Standard_False;
4501 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4503 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4504 anOption.LowerCase();
4505 if (anOption == "-detectedentities"
4506 || anOption == "-entities")
4508 toPrintEntities = Standard_True;
4510 else if (anOption == "-hasselected")
4512 toCheckSelected = Standard_True;
4516 if (toCheckSelected)
4518 aCtx->InitSelected();
4519 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4520 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4525 if (toPrintEntities)
4527 theDI << "Detected entities:\n";
4528 Standard_DISABLE_DEPRECATION_WARNINGS
4529 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4530 Standard_ENABLE_DEPRECATION_WARNINGS
4531 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4532 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4534 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4535 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4536 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4537 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4538 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4539 aName.LeftJustify (20, ' ');
4540 char anInfoStr[512];
4542 " Depth: %g Distance: %g Point: %g %g %g",
4545 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4546 theDI << " " << aName
4548 << " (" << anEntity->DynamicType()->Name() << ")"
4551 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4552 if (!aBRepOwner.IsNull())
4554 theDI << " Detected Shape: "
4555 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4559 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4560 if (!aWire.IsNull())
4562 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4563 theDI << " Detected Child: "
4564 << aSen->DynamicType()->Name()
4568 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4569 if (!aPrimArr.IsNull())
4571 theDI << " Detected Element: "
4572 << aPrimArr->LastDetectedElement()
4579 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4580 Standard_DISABLE_DEPRECATION_WARNINGS
4581 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4583 aDetected.Add (aCtx->DetectedCurrentObject());
4585 Standard_ENABLE_DEPRECATION_WARNINGS
4587 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4591 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4593 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4594 if (!GetMapOfAIS().IsBound2 (anObjName))
4596 theDI << anObjName << " doesn't exist!\n";
4600 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4601 TCollection_AsciiString aName = anObjName;
4602 aName.LeftJustify (20, ' ');
4603 theDI << " " << aName << " ";
4604 objInfo (aDetected, anObjTrans, theDI);
4610 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4612 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4613 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4615 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4616 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4617 // handle whole object selection
4618 if (anOwner == anObj->GlobalSelOwner())
4620 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4621 aName.LeftJustify (20, ' ');
4622 theDI << aName << " ";
4623 objInfo (aDetected, anObj, theDI);
4628 // process selected sub-shapes
4629 printLocalSelectionInfo (aCtx, theDI);
4634 theDI << "Neutral-point state:\n";
4635 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4636 anObjIter.More(); anObjIter.Next())
4638 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4644 TCollection_AsciiString aName = anObjIter.Key2();
4645 aName.LeftJustify (20, ' ');
4646 theDI << " " << aName << " ";
4647 objInfo (aDetected, anObj, theDI);
4650 printLocalSelectionInfo (aCtx, theDI);
4651 Standard_DISABLE_DEPRECATION_WARNINGS
4652 if (aCtx->HasOpenedContext())
4653 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
4654 Standard_ENABLE_DEPRECATION_WARNINGS
4658 //=======================================================================
4659 //function : PickObjects
4661 //=======================================================================
4662 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4663 const AIS_KindOfInteractive TheType,
4664 const Standard_Integer TheSignature,
4665 const Standard_Integer MaxPick)
4667 Handle(AIS_InteractiveObject) IO;
4668 Standard_DISABLE_DEPRECATION_WARNINGS
4669 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4670 Standard_ENABLE_DEPRECATION_WARNINGS
4672 // step 1: prepare the data
4674 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4675 TheAISContext()->AddFilter(F1);
4678 // step 2 : wait for the selection...
4679 Standard_Integer NbPickGood (0),NbToReach(arr->Length());
4680 Standard_Integer NbPickFail(0);
4681 Standard_Integer argccc = 5;
4682 const char *bufff[] = { "A", "B", "C","D", "E" };
4683 const char **argvvv = (const char **) bufff;
4686 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4687 while(ViewerMainLoop(argccc,argvvv)){}
4688 Standard_Integer NbStored = TheAISContext()->NbSelected();
4689 if(NbStored != NbPickGood)
4690 NbPickGood= NbStored;
4693 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4696 // step3 get result.
4698 if (NbPickFail >= NbToReach)
4699 return Standard_False;
4701 Standard_Integer i(0);
4702 for(TheAISContext()->InitSelected();
4703 TheAISContext()->MoreSelected();
4704 TheAISContext()->NextSelected()){
4706 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4707 arr->SetValue(i,IO2);
4710 Standard_DISABLE_DEPRECATION_WARNINGS
4713 TheAISContext()->CloseLocalContext(curindex);
4715 Standard_ENABLE_DEPRECATION_WARNINGS
4717 return Standard_True;
4721 //=======================================================================
4722 //function : PickObject
4724 //=======================================================================
4725 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4726 const Standard_Integer TheSignature,
4727 const Standard_Integer MaxPick)
4729 Handle(AIS_InteractiveObject) IO;
4730 Standard_DISABLE_DEPRECATION_WARNINGS
4731 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4732 Standard_ENABLE_DEPRECATION_WARNINGS
4734 // step 1: prepare the data
4737 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4738 TheAISContext()->AddFilter(F1);
4741 // step 2 : wait for the selection...
4742 Standard_Boolean IsGood (Standard_False);
4743 Standard_Integer NbPick(0);
4744 Standard_Integer argccc = 5;
4745 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4746 const char **argvvv = (const char **) bufff;
4749 while(!IsGood && NbPick<= MaxPick){
4750 while(ViewerMainLoop(argccc,argvvv)){}
4751 IsGood = (TheAISContext()->NbSelected()>0) ;
4753 cout<<"Nb Pick :"<<NbPick<<endl;
4757 // step3 get result.
4759 TheAISContext()->InitSelected();
4760 IO = TheAISContext()->SelectedInteractive();
4763 Standard_DISABLE_DEPRECATION_WARNINGS
4766 TheAISContext()->CloseLocalContext(curindex);
4768 Standard_ENABLE_DEPRECATION_WARNINGS
4772 //=======================================================================
4773 //function : PickShape
4774 //purpose : First Activate the rightmode + Put Filters to be able to
4775 // pick objets that are of type <TheType>...
4776 //=======================================================================
4778 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4779 const Standard_Integer MaxPick)
4782 // step 1: prepare the data
4783 Standard_DISABLE_DEPRECATION_WARNINGS
4784 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4785 Standard_ENABLE_DEPRECATION_WARNINGS
4786 TopoDS_Shape result;
4788 if(TheType==TopAbs_SHAPE){
4789 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4790 TheAISContext()->AddFilter(F1);
4793 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4794 TheAISContext()->AddFilter(TF);
4795 Standard_DISABLE_DEPRECATION_WARNINGS
4796 TheAISContext()->ActivateStandardMode(TheType);
4797 Standard_ENABLE_DEPRECATION_WARNINGS
4801 // step 2 : wait for the selection...
4802 Standard_Boolean NoShape (Standard_True);
4803 Standard_Integer NbPick(0);
4804 Standard_Integer argccc = 5;
4805 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4806 const char **argvvv = (const char **) bufff;
4809 while(NoShape && NbPick<= MaxPick){
4810 while(ViewerMainLoop(argccc,argvvv)){}
4811 NoShape = (TheAISContext()->NbSelected()==0) ;
4813 cout<<"Nb Pick :"<<NbPick<<endl;
4816 // step3 get result.
4820 TheAISContext()->InitSelected();
4821 if(TheAISContext()->HasSelectedShape())
4822 result = TheAISContext()->SelectedShape();
4824 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4825 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
4829 Standard_DISABLE_DEPRECATION_WARNINGS
4832 TheAISContext()->CloseLocalContext(curindex);
4834 Standard_ENABLE_DEPRECATION_WARNINGS
4840 //=======================================================================
4841 //function : PickShapes
4843 //=======================================================================
4844 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4845 Handle(TopTools_HArray1OfShape)& thearr,
4846 const Standard_Integer MaxPick)
4849 Standard_Integer Taille = thearr->Length();
4851 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4853 // step 1: prepare the data
4854 Standard_DISABLE_DEPRECATION_WARNINGS
4855 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4856 Standard_ENABLE_DEPRECATION_WARNINGS
4857 if(TheType==TopAbs_SHAPE){
4858 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4859 TheAISContext()->AddFilter(F1);
4862 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4863 TheAISContext()->AddFilter(TF);
4864 Standard_DISABLE_DEPRECATION_WARNINGS
4865 TheAISContext()->ActivateStandardMode(TheType);
4866 Standard_ENABLE_DEPRECATION_WARNINGS
4869 // step 2 : wait for the selection...
4870 Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
4871 Standard_Integer NbPickFail(0);
4872 Standard_Integer argccc = 5;
4873 const char *bufff[] = { "A", "B", "C","D", "E" };
4874 const char **argvvv = (const char **) bufff;
4877 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4878 while(ViewerMainLoop(argccc,argvvv)){}
4879 Standard_Integer NbStored = TheAISContext()->NbSelected();
4880 if (NbStored != NbPickGood)
4881 NbPickGood= NbStored;
4884 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4887 // step3 get result.
4889 if (NbPickFail >= NbToReach)
4890 return Standard_False;
4892 Standard_Integer i(0);
4893 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4895 if(TheAISContext()->HasSelectedShape())
4896 thearr->SetValue(i,TheAISContext()->SelectedShape());
4898 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4899 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
4903 Standard_DISABLE_DEPRECATION_WARNINGS
4904 TheAISContext()->CloseLocalContext(curindex);
4905 Standard_ENABLE_DEPRECATION_WARNINGS
4906 return Standard_True;
4910 //=======================================================================
4911 //function : VPickShape
4913 //=======================================================================
4914 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4916 TopoDS_Shape PickSh;
4917 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4920 theType = TopAbs_SHAPE;
4922 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4923 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4924 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4925 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4926 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4927 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4928 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4931 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4932 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4934 TCollection_AsciiString name;
4937 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4939 PickSh = ViewerTest::PickShape(theType);
4948 if(!PickSh.IsNull()){
4949 nbOfSub[Standard_Integer(theType)]++;
4951 name += nameType[Standard_Integer(theType)];
4952 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4957 // si on avait une petite methode pour voir si la shape
4958 // est deja dans la Double map, ca eviterait de creer....
4959 DBRep::Set(name.ToCString(),PickSh);
4961 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4962 GetMapOfAIS().Bind(newsh, name);
4963 TheAISContext()->Display(newsh);
4964 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4967 // Plusieurs objets a picker, vite vite vite....
4970 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4971 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4972 if(ViewerTest::PickShapes(theType,arr)){
4973 for(Standard_Integer i=1;i<=NbToPick;i++){
4974 PickSh = arr->Value(i);
4975 if(!PickSh.IsNull()){
4977 nbOfSub[Standard_Integer(theType)]++;
4980 name += nameType[Standard_Integer(theType)];
4981 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4989 DBRep::Set(name.ToCString(),PickSh);
4990 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4991 GetMapOfAIS().Bind(newsh, name);
4992 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4993 TheAISContext()->Display(newsh);
5001 //=======================================================================
5002 //function : VPickSelected
5004 //=======================================================================
5005 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5007 static Standard_Integer aCount = 0;
5008 TCollection_AsciiString aName = "PickedShape_";
5016 aName = aName + aCount++ + "_";
5019 Standard_Integer anIdx = 0;
5020 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5022 TopoDS_Shape aShape;
5023 if (TheAISContext()->HasSelectedShape())
5025 aShape = TheAISContext()->SelectedShape();
5029 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5030 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5033 TCollection_AsciiString aCurrentName = aName;
5036 aCurrentName += anIdx;
5039 DBRep::Set ((aCurrentName).ToCString(), aShape);
5041 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5042 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5043 TheAISContext()->Display (aNewShape);
5049 //=======================================================================
5050 //function : list of known objects
5052 //=======================================================================
5053 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5055 // 1234567890 12345678901234567 123456789
5056 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5057 TCollection_AsciiString BlankLine(64,'_');
5058 Standard_Integer i ;
5060 di<<"/n"<<BlankLine.ToCString()<<"\n";
5063 Colum[i].Center(20,' ');
5065 di<<"|"<<Colum[i].ToCString();
5068 di<<BlankLine.ToCString()<<"\n";
5070 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5071 const char ** names = GetTypeNames();
5073 TCollection_AsciiString curstring;
5074 TCollection_AsciiString curcolum[3];
5077 // les objets de type Datum..
5078 curcolum[1]+="Datum";
5080 curcolum[0].Clear();
5081 curcolum[0] += names[i];
5083 curcolum[2].Clear();
5084 curcolum[2]+=TCollection_AsciiString(i+1);
5086 for(Standard_Integer j =0;j<=2;j++){
5087 curcolum[j].Center(20,' ');
5088 di<<"|"<<curcolum[j].ToCString();
5092 di<<BlankLine.ToCString()<<"\n";
5094 // les objets de type shape
5095 curcolum[1].Clear();
5096 curcolum[1]+="Shape";
5097 curcolum[1].Center(20,' ');
5100 curcolum[0].Clear();
5101 curcolum[0] += names[7+i];
5102 curcolum[2].Clear();
5103 curcolum[2]+=TCollection_AsciiString(i);
5105 for(Standard_Integer j =0;j<=2;j++){
5106 curcolum[j].Center(20,' ');
5107 di<<"|"<<curcolum[j].ToCString();
5111 di<<BlankLine.ToCString()<<"\n";
5112 // les IO de type objet...
5113 curcolum[1].Clear();
5114 curcolum[1]+="Object";
5115 curcolum[1].Center(20,' ');
5117 curcolum[0].Clear();
5118 curcolum[0] += names[10+i];
5119 curcolum[2].Clear();
5120 curcolum[2]+=TCollection_AsciiString(i);
5122 for(Standard_Integer j =0;j<=2;j++){
5123 curcolum[j].Center(20,' ');
5124 di<<"|"<<curcolum[j].ToCString();
5128 di<<BlankLine.ToCString()<<"\n";
5129 // les contraintes et dimensions.
5130 // pour l'instant on separe juste contraintes et dimensions...
5131 // plus tard, on detaillera toutes les sortes...
5132 curcolum[1].Clear();
5133 curcolum[1]+="Relation";
5134 curcolum[1].Center(20,' ');
5136 curcolum[0].Clear();
5137 curcolum[0] += names[12+i];
5138 curcolum[2].Clear();
5139 curcolum[2]+=TCollection_AsciiString(i);
5141 for(Standard_Integer j =0;j<=2;j++){
5142 curcolum[j].Center(20,' ');
5143 di<<"|"<<curcolum[j].ToCString();
5147 di<<BlankLine.ToCString()<<"\n";
5154 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5156 if(argc!=2) return 1;
5158 AIS_KindOfInteractive TheType;
5159 Standard_Integer TheSign(-1);
5160 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5163 AIS_ListOfInteractive LIO;
5165 // en attendant l'amelioration ais pour les dimensions...
5167 Standard_Integer dimension_status(-1);
5168 if(TheType==AIS_KOI_Relation){
5169 dimension_status = TheSign ==1 ? 1 : 0;
5173 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5174 Handle(AIS_InteractiveObject) curio;
5175 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5178 if(dimension_status == -1)
5179 TheAISContext()->Erase(curio,Standard_False);
5181 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5182 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5183 (dimension_status==1 && KOD != AIS_KOD_NONE))
5184 TheAISContext()->Erase(curio,Standard_False);
5187 TheAISContext()->UpdateCurrentViewer();
5190 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5192 if(argc!=2) return 1;
5194 AIS_KindOfInteractive TheType;
5195 Standard_Integer TheSign(-1);
5196 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5198 // en attendant l'amelioration ais pour les dimensions...
5200 Standard_Integer dimension_status(-1);
5201 if(TheType==AIS_KOI_Relation){
5202 dimension_status = TheSign ==1 ? 1 : 0;
5206 AIS_ListOfInteractive LIO;
5207 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5208 Handle(AIS_InteractiveObject) curio;
5209 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5211 if(dimension_status == -1)
5212 TheAISContext()->Display(curio,Standard_False);
5214 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5215 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5216 (dimension_status==1 && KOD != AIS_KOD_NONE))
5217 TheAISContext()->Display(curio,Standard_False);
5222 TheAISContext()->UpdateCurrentViewer();
5226 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5229 BRep_Builder builder;
5231 BRepTools::Read(shape, s, builder);
5232 DBRep::Set(a[1], shape);
5233 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5234 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5239 //===============================================================================================
5242 //===============================================================================================
5243 static int VBsdf (Draw_Interpretor& theDi,
5244 Standard_Integer theArgsNb,
5245 const char** theArgVec)
5247 Handle(V3d_View) aView = ViewerTest::CurrentView();
5248 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5250 || aViewer.IsNull())
5252 std::cerr << "No active viewer!\n";
5256 ViewerTest_CmdParser aCmd;
5258 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5259 aCmd.AddOption ("print|echo|p", "Print BSDF");
5261 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5262 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5263 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5264 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5265 aCmd.AddOption ("le", "Self-emitted radiance");
5267 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5269 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
5270 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5271 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5273 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5275 aCmd.Parse (theArgsNb, theArgVec);
5277 if (aCmd.HasOption ("help"))
5279 theDi.PrintHelp (theArgVec[0]);
5283 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5286 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5287 if (!aMap.IsBound2 (aName) )
5289 std::cerr << "Use 'vdisplay' before\n";
5293 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5294 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5295 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5297 if (aCmd.HasOption ("print"))
5299 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5302 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5303 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5304 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5305 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5306 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5309 if (aFresnel.x() >= 0.f)
5312 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5314 else if (aFresnel.x() >= -1.5f)
5317 << "|Constant| " << aFresnel.z() << "\n";
5319 else if (aFresnel.x() >= -2.5f)
5322 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5327 << "|Dielectric| " << aFresnel.y() << "\n";
5332 << "Roughness: " << aBSDF.Roughness << "\n"
5333 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
5334 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5335 << aBSDF.AbsorptionColor.g() << ", "
5336 << aBSDF.AbsorptionColor.b() << "\n";
5341 if (aCmd.HasOption ("roughness", 1, Standard_True))
5343 aCmd.Arg ("roughness", 0);
5344 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5347 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5349 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5352 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5354 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5357 if (aCmd.HasOption ("kd", 3))
5359 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5361 else if (aCmd.HasOption ("kd", 1, Standard_True))
5363 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5366 if (aCmd.HasOption ("kr", 3))
5368 aBSDF.Kr = aCmd.ArgVec3f ("kr");
5370 else if (aCmd.HasOption ("kr", 1, Standard_True))
5372 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5375 if (aCmd.HasOption ("kt", 3))
5377 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5379 else if (aCmd.HasOption ("kt", 1, Standard_True))
5381 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5384 if (aCmd.HasOption ("ks", 3))
5386 aBSDF.Ks = aCmd.ArgVec3f ("ks");
5388 else if (aCmd.HasOption ("ks", 1, Standard_True))
5390 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5393 if (aCmd.HasOption ("le", 3))
5395 aBSDF.Le = aCmd.ArgVec3f ("le");
5397 else if (aCmd.HasOption ("le", 1, Standard_True))
5399 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5402 const std::string aFresnelErrorMessage =
5403 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5405 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5407 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5408 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5410 if (aFresnelType == "schlick")
5412 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5413 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5414 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5415 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5419 std::cout << aFresnelErrorMessage;
5422 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5424 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5425 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5427 if (aFresnelType == "conductor")
5429 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5430 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5431 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5435 std::cout << aFresnelErrorMessage;
5438 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5440 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5441 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5443 if (aFresnelType == "dielectric")
5445 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5446 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5448 else if (aFresnelType == "constant")
5450 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5451 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5455 std::cout << aFresnelErrorMessage;
5459 if (aCmd.HasOption ("normalize"))
5464 aMaterial.SetBSDF (aBSDF);
5465 anIObj->SetMaterial (aMaterial);
5472 //==============================================================================
5473 //function : VLoadSelection
5474 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5475 //==============================================================================
5476 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5477 Standard_Integer theArgNb,
5478 const char** theArgVec)
5482 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5486 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5489 ViewerTest::ViewerInit();
5490 aCtx = ViewerTest::GetAISContext();
5493 // Parse input arguments
5494 TColStd_SequenceOfAsciiString aNamesOfIO;
5495 Standard_Boolean isLocal = Standard_False;
5496 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5498 const TCollection_AsciiString aName = theArgVec[anArgIter];
5499 TCollection_AsciiString aNameCase = aName;
5500 aNameCase.LowerCase();
5501 if (aNameCase == "-local")
5503 isLocal = Standard_True;
5507 aNamesOfIO.Append (aName);
5511 if (aNamesOfIO.IsEmpty())
5513 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5518 Standard_DISABLE_DEPRECATION_WARNINGS
5519 if (isLocal && !aCtx->HasOpenedContext())
5521 aCtx->OpenLocalContext (Standard_False);
5523 else if (!isLocal && aCtx->HasOpenedContext())
5525 aCtx->CloseAllContexts (Standard_False);
5527 Standard_ENABLE_DEPRECATION_WARNINGS
5529 // Load selection of interactive objects
5530 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5532 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5534 Handle(AIS_InteractiveObject) aShape;
5535 if (GetMapOfAIS().IsBound2 (aName))
5536 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5538 aShape = GetAISShapeFromName (aName.ToCString());
5540 if (!aShape.IsNull())
5542 if (!GetMapOfAIS().IsBound2 (aName))
5544 GetMapOfAIS().Bind (aShape, aName);
5547 aCtx->Load (aShape, -1, Standard_False);
5548 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5555 //==============================================================================
5556 //function : ViewerTest::Commands
5557 //purpose : Add all the viewer command in the Draw_Interpretor
5558 //==============================================================================
5560 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5562 ViewerTest::ViewerCommands(theCommands);
5563 ViewerTest::RelationCommands(theCommands);
5564 ViewerTest::ObjectCommands(theCommands);
5565 ViewerTest::FilletCommands(theCommands);
5566 ViewerTest::OpenGlCommands(theCommands);
5568 const char *group = "AIS_Display";
5571 theCommands.Add("visos",
5572 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5573 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5574 __FILE__, visos, group);
5576 theCommands.Add("vdisplay",
5577 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5578 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5579 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5580 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5581 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5582 "\n\t\t: [offsetX offsetY]]]"
5583 "\n\t\t: [-dispMode mode] [-highMode mode]"
5584 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5585 "\n\t\t: [-redisplay]"
5586 "\n\t\t: name1 [name2] ... [name n]"
5587 "\n\t\t: Displays named objects."
5588 "\n\t\t: Option -local enables displaying of objects in local"
5589 "\n\t\t: selection context. Local selection context will be opened"
5590 "\n\t\t: if there is not any."
5591 "\n\t\t: -noupdate Suppresses viewer redraw call."
5592 "\n\t\t: -mutable Enables optimizations for mutable objects."
5593 "\n\t\t: -neutral Draws objects in main viewer."
5594 "\n\t\t: -layer Sets z-layer for objects."
5595 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5596 "\n\t\t: options can be used for the default z-layers."
5597 "\n\t\t: -top Draws object on top of main presentations"
5598 "\n\t\t: but below topmost."
5599 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5600 "\n\t\t: with independent Depth."
5601 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5602 "\n\t\t: (On-Screen-Display)"
5603 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5604 "\n\t\t: (On-Screen-Display)"
5605 "\n\t\t: -selectable|-noselect Controls selection of objects."
5606 "\n\t\t: -trsfPers Sets a transform persistence flags."
5607 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5608 "\n\t\t: -2d Displays object in screen coordinates."
5609 "\n\t\t: (DY looks up)"
5610 "\n\t\t: -dispmode Sets display mode for objects."
5611 "\n\t\t: -highmode Sets hilight mode for objects."
5612 "\n\t\t: -redisplay Recomputes presentation of objects.",
5613 __FILE__, VDisplay2, group);
5615 theCommands.Add ("vupdate",
5616 "vupdate name1 [name2] ... [name n]"
5617 "\n\t\t: Updates named objects in interactive context",
5618 __FILE__, VUpdate, group);
5620 theCommands.Add("verase",
5621 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5622 "\n\t\t: Erases selected or named objects."
5623 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5624 "\n\t\t: Option -local enables erasing of selected or named objects without"
5625 "\n\t\t: closing local selection context.",
5626 __FILE__, VErase, group);
5628 theCommands.Add("vremove",
5629 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5630 "or vremove [-context] -all to remove all objects"
5631 "\n\t\t: Removes selected or named objects."
5632 "\n\t\t If -context is in arguments, the objects are not deleted"
5633 "\n\t\t from the map of objects and names."
5634 "\n\t\t: Option -local enables removing of selected or named objects without"
5635 "\n\t\t: closing local selection context. Empty local selection context will be"
5637 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5638 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5639 __FILE__, VRemove, group);
5641 theCommands.Add("vdonly",
5642 "vdonly [-noupdate|-update] [name1] ... [name n]"
5643 "\n\t\t: Displays only selected or named objects",
5644 __FILE__,VDonly2,group);
5646 theCommands.Add("vdisplayall",
5647 "vidsplayall [-local]"
5648 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5649 "\n\t\t: Option -local enables displaying of the objects in local"
5650 "\n\t\t: selection context.",
5651 __FILE__, VDisplayAll, group);
5653 theCommands.Add("veraseall",
5654 "veraseall [-local]"
5655 "\n\t\t: Erases all objects displayed in the viewer."
5656 "\n\t\t: Option -local enables erasing of the objects in local"
5657 "\n\t\t: selection context.",
5658 __FILE__, VErase, group);
5660 theCommands.Add("verasetype",
5662 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5663 __FILE__, VEraseType, group);
5664 theCommands.Add("vbounding",
5665 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5666 "\n\t\t: [-print] [-hide]"
5667 "\n\t\t: Temporarily display bounding box of specified Interactive"
5668 "\n\t\t: Objects, or print it to console if -print is specified."
5669 "\n\t\t: Already displayed box might be hidden by -hide option.",
5670 __FILE__,VBounding,group);
5672 theCommands.Add("vdisplaytype",
5673 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5674 __FILE__,VDisplayType,group);
5676 theCommands.Add("vsetdispmode",
5677 "vsetdispmode [name] mode(1,2,..)"
5678 "\n\t\t: Sets display mode for all, selected or named objects.",
5679 __FILE__,VDispMode,group);
5681 theCommands.Add("vunsetdispmode",
5682 "vunsetdispmode [name]"
5683 "\n\t\t: Unsets custom display mode for selected or named objects.",
5684 __FILE__,VDispMode,group);
5686 theCommands.Add("vdir",
5687 "Lists all objects displayed in 3D viewer",
5688 __FILE__,VDir,group);
5690 #ifdef HAVE_FREEIMAGE
5691 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5693 #define DUMP_FORMATS "{ppm}"
5695 theCommands.Add("vdump",
5696 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5697 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5698 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5699 "\n\t\t: [-tileSize Size=0]"
5700 "\n\t\t: Dumps content of the active view into image file",
5701 __FILE__,VDump,group);
5703 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5704 __FILE__,VSubInt,group);
5706 theCommands.Add("vaspects",
5707 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5708 "\n\t\t: [-setVisibility 0|1]"
5709 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5710 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5711 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5712 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5713 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5714 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5715 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5716 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5717 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5718 "\n\t\t: [-isoontriangulation 0|1]"
5719 "\n\t\t: [-setMaxParamValue {value}]"
5720 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5721 "\n\t\t: Manage presentation properties of all, selected or named objects."
5722 "\n\t\t: When -subshapes is specified than following properties will be"
5723 "\n\t\t: assigned to specified sub-shapes."
5724 "\n\t\t: When -defaults is specified than presentation properties will be"
5725 "\n\t\t: assigned to all objects that have not their own specified properties"
5726 "\n\t\t: and to all objects to be displayed in the future."
5727 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5728 __FILE__,VAspects,group);
5730 theCommands.Add("vsetcolor",
5731 "vsetcolor [-noupdate|-update] [name] ColorName"
5732 "\n\t\t: Sets color for all, selected or named objects."
5733 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5734 __FILE__,VAspects,group);
5736 theCommands.Add("vunsetcolor",
5737 "vunsetcolor [-noupdate|-update] [name]"
5738 "\n\t\t: Resets color for all, selected or named objects."
5739 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5740 __FILE__,VAspects,group);
5742 theCommands.Add("vsettransparency",
5743 "vsettransparency [-noupdate|-update] [name] Coefficient"
5744 "\n\t\t: Sets transparency for all, selected or named objects."
5745 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5746 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5747 __FILE__,VAspects,group);
5749 theCommands.Add("vunsettransparency",
5750 "vunsettransparency [-noupdate|-update] [name]"
5751 "\n\t\t: Resets transparency for all, selected or named objects."
5752 "\n\t\t: Alias for vaspects -unsettransp [name].",
5753 __FILE__,VAspects,group);
5755 theCommands.Add("vsetmaterial",
5756 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5757 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5758 __FILE__,VAspects,group);
5760 theCommands.Add("vunsetmaterial",
5761 "vunsetmaterial [-noupdate|-update] [name]"
5762 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5763 __FILE__,VAspects,group);
5765 theCommands.Add("vsetwidth",
5766 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5767 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5768 __FILE__,VAspects,group);
5770 theCommands.Add("vunsetwidth",
5771 "vunsetwidth [-noupdate|-update] [name]"
5772 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5773 __FILE__,VAspects,group);
5775 theCommands.Add("vsetinteriorstyle",
5776 "vsetinteriorstyle [-noupdate|-update] [name] style"
5777 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5778 __FILE__,VSetInteriorStyle,group);
5780 theCommands.Add("vsensdis",
5781 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5782 "\n\t\t: Standard entity types are those defined in Select3D package:"
5783 "\n\t\t: - sensitive box"
5784 "\n\t\t: - sensitive face"
5785 "\n\t\t: - sensitive curve"
5786 "\n\t\t: - sensitive segment"
5787 "\n\t\t: - sensitive circle"
5788 "\n\t\t: - sensitive point"
5789 "\n\t\t: - sensitive triangulation"
5790 "\n\t\t: - sensitive triangle"
5791 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5792 __FILE__,VDispSensi,group);
5794 theCommands.Add("vsensera",
5795 "vsensera : erase active entities",
5796 __FILE__,VClearSensi,group);
5798 theCommands.Add("vperf",
5799 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
5800 "\n\t\t: Tests the animation of an object along a predefined trajectory.",
5801 __FILE__,VPerf,group);
5803 theCommands.Add("vsetshading",
5804 "vsetshading : vsetshading name Quality(default=0.0008) "
5805 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5806 __FILE__,VShading,group);
5808 theCommands.Add("vunsetshading",
5809 "vunsetshading :vunsetshading name "
5810 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5811 __FILE__,VShading,group);
5813 theCommands.Add ("vtexture",
5814 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5815 " [-scale u v] [-scale off]\n"
5816 " [-origin u v] [-origin off]\n"
5817 " [-repeat u v] [-repeat off]\n"
5818 " [-modulate {on | off}]"
5820 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5821 " specifying one of the predefined textures.\n"
5822 " The options are: \n"
5823 " -scale u v : enable texture scaling and set scale factors\n"
5824 " -scale off : disable texture scaling\n"
5825 " -origin u v : enable texture origin positioning and set the origin\n"
5826 " -origin off : disable texture origin positioning\n"
5827 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5828 " -repeat off : disable texture repeat\n"
5829 " -modulate {on | off} : enable or disable texture modulation\n"
5830 " -default : sets texture mapping default parameters\n"
5831 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5832 "or 'vtexture NameOfShape ?' to list available textures\n",
5833 __FILE__, VTexture, group);
5835 theCommands.Add("vtexscale",
5836 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5837 or 'vtexscale NameOfShape ScaleUV' \n \
5838 or 'vtexscale NameOfShape' to disable scaling\n ",
5839 __FILE__,VTexture,group);
5841 theCommands.Add("vtexorigin",
5842 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5843 or 'vtexorigin NameOfShape UVOrigin' \n \
5844 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5845 __FILE__,VTexture,group);
5847 theCommands.Add("vtexrepeat",
5848 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5849 or 'vtexrepeat NameOfShape UVRepeat \n \
5850 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5853 theCommands.Add("vtexdefault",
5854 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5857 theCommands.Add("vsetam",
5858 "vsetam [shapename] mode"
5859 "\n\t\t: Activates selection mode for all selected or named shapes."
5860 "\n\t\t: Mod can be:"
5861 "\n\t\t: 0 - for shape itself"
5862 "\n\t\t: 1 - vertices"
5866 "\n\t\t: 5 - shells"
5867 "\n\t\t: 6 - solids"
5868 "\n\t\t: 7 - compounds"
5869 __FILE__,VActivatedMode,group);
5871 theCommands.Add("vunsetam",
5872 "vunsetam : Deactivates all selection modes for all shapes.",
5873 __FILE__,VActivatedMode,group);
5875 theCommands.Add("vstate",
5876 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5877 "\n\t\t: Reports show/hidden state for selected or named objects"
5878 "\n\t\t: -entities - print low-level information about detected entities"
5879 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5880 __FILE__,VState,group);
5882 theCommands.Add("vpickshapes",
5883 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5884 __FILE__,VPickShape,group);
5886 theCommands.Add("vtypes",
5887 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5890 theCommands.Add("vr",
5892 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
5893 __FILE__,vr, group);
5895 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5896 __FILE__, VPickSelected, group);
5898 theCommands.Add ("vloadselection",
5899 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5900 "\n\t\t: primitives for the shapes with names given without displaying them."
5901 "\n\t\t: -local - open local context before selection computation",
5902 __FILE__, VLoadSelection, group);
5904 theCommands.Add("vbsdf", "vbsdf [name] [options]"
5905 "\nAdjusts parameters of material BSDF:"
5906 "\n -help : Shows this message"
5907 "\n -print : Print BSDF"
5908 "\n -kd : Weight of the Lambertian BRDF"
5909 "\n -kr : Weight of the reflection BRDF"
5910 "\n -kt : Weight of the transmission BTDF"
5911 "\n -ks : Weight of the glossy Blinn BRDF"
5912 "\n -le : Self-emitted radiance"
5913 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5914 "\n Schlick x y z, Dielectric x, Conductor x y"
5915 "\n -roughness : Roughness of material (Blinn's exponent)"
5916 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
5917 "\n -absorpcolor : Absorption color (only for transparent material)"
5918 "\n -normalize : Normalize BSDF coefficients",
5919 __FILE__, VBsdf, group);
5923 //=====================================================================
5924 //========================= for testing Draft and Rib =================
5925 //=====================================================================
5926 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5927 #include <DBRep.hxx>
5928 #include <TopoDS_Face.hxx>
5929 #include <gp_Pln.hxx>
5930 #include <AIS_KindOfSurface.hxx>
5931 #include <BRepOffsetAPI_DraftAngle.hxx>
5932 #include <Precision.hxx>
5933 #include <BRepAlgo.hxx>
5934 #include <OSD_Environment.hxx>
5935 #include <DrawTrSurf.hxx>
5936 //#include <DbgTools.hxx>
5937 //#include <FeatAlgo_MakeLinearForm.hxx>
5942 //=======================================================================
5943 //function : IsValid
5945 //=======================================================================
5946 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5947 const TopoDS_Shape& theResult,
5948 const Standard_Boolean closedSolid,
5949 const Standard_Boolean GeomCtrl)
5951 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5952 TCollection_AsciiString checkValid = check.Value();
5953 Standard_Boolean ToCheck = Standard_True;
5954 if (!checkValid.IsEmpty()) {
5956 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5958 if ( checkValid=="true" || checkValid=="TRUE" ) {
5959 ToCheck= Standard_False;
5963 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
5966 Standard_Boolean IsValid = Standard_True;
5968 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5973 //===============================================================================
5974 // TDraft : test draft, uses AIS Viewer
5975 // Solid Face Plane Angle Reverse
5976 //===============================================================================
5977 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5979 if (argc < 5) return 1;
5980 // argv[1] - TopoDS_Shape Solid
5981 // argv[2] - TopoDS_Shape Face
5982 // argv[3] - TopoDS_Shape Plane
5983 // argv[4] - Standard_Real Angle
5984 // argv[5] - Standard_Integer Reverse
5986 // Sprintf(prefix, argv[1]);
5987 Standard_Real anAngle = 0;
5988 Standard_Boolean Rev = Standard_False;
5989 Standard_Integer rev = 0;
5990 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5991 TopoDS_Shape face = GetShapeFromName(argv[2]);
5992 TopoDS_Face Face = TopoDS::Face(face);
5993 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5994 if (Plane.IsNull ()) {
5995 di << "TEST : Plane is NULL\n";
5998 anAngle = Draw::Atof(argv[4]);
5999 anAngle = 2*M_PI * anAngle / 360.0;
6001 Handle( Geom_Surface )aSurf;
6002 AIS_KindOfSurface aSurfType;
6003 Standard_Real Offset;
6005 if(argc > 4) { // == 5
6006 rev = Draw::Atoi(argv[5]);
6007 Rev = (rev)? Standard_True : Standard_False;
6010 TopoDS_Face face2 = TopoDS::Face(Plane);
6011 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6013 di << "TEST : Can't find plane\n";
6017 aDir = aPln.Axis().Direction();
6020 if (Plane.Orientation() == TopAbs_REVERSED)
6022 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6024 BRepOffsetAPI_DraftAngle Draft (Solid);
6026 if(Abs(anAngle)< Precision::Angular()) {
6027 di << "TEST : NULL angle\n";
6030 if(Rev) anAngle = - anAngle;
6031 Draft.Add (Face, aDir, anAngle, aPln);
6033 if (!Draft.IsDone()) {
6034 di << "TEST : Draft Not DONE \n";
6037 TopTools_ListOfShape Larg;
6039 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6040 di << "TEST : DesignAlgo returns Not valid\n";
6044 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6045 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6047 if ( !ais.IsNull() ) {
6048 ais->SetColor(DEFAULT_COLOR);
6049 ais->SetMaterial(DEFAULT_MATERIAL);
6050 // Display the AIS_Shape without redraw
6051 Ctx->Display(ais, Standard_False);
6053 const char *Name = "draft1";
6054 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6056 Handle(AIS_InteractiveObject) an_object =
6057 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6058 if (!an_object.IsNull()) {
6059 Ctx->Remove(an_object,
6061 GetMapOfAIS().UnBind2(Name) ;
6064 GetMapOfAIS().Bind(ais, Name);
6065 // DBRep::Set("draft", ais->Shape());
6067 Ctx->Display(ais, Standard_True);
6071 //==============================================================================
6072 //function : splitParameter
6073 //purpose : Split parameter string to parameter name and parameter value
6074 //==============================================================================
6075 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6076 TCollection_AsciiString& theName,
6077 TCollection_AsciiString& theValue)
6079 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6081 if (aParamNameEnd == 0)
6083 return Standard_False;
6086 TCollection_AsciiString aString (theString);
6087 if (aParamNameEnd != 0)
6089 theValue = aString.Split (aParamNameEnd);
6090 aString.Split (aString.Length() - 1);
6094 return Standard_True;
6097 //============================================================================
6099 //============================================================================
6100 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6103 DrawTrSurf::BasicCommands(theCommands);
6104 const char* group = "Check Features Operations commands";
6106 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6108 &TDraft,group); //Draft_Modification
6111 //==============================================================================
6112 // ViewerTest::Factory
6113 //==============================================================================
6114 void ViewerTest::Factory(Draw_Interpretor& theDI)
6116 // definition of Viewer Command
6117 ViewerTest::Commands(theDI);
6120 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6124 // Declare entry point PLUGINFACTORY