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>
30 #include <TopLoc_Location.hxx>
31 #include <TopTools_HArray1OfShape.hxx>
32 #include <TColStd_HArray1OfTransient.hxx>
33 #include <TColStd_SequenceOfAsciiString.hxx>
34 #include <TColStd_HSequenceOfAsciiString.hxx>
35 #include <TColStd_MapOfTransient.hxx>
36 #include <OSD_Timer.hxx>
37 #include <Geom_Axis2Placement.hxx>
38 #include <Geom_Axis1Placement.hxx>
39 #include <gp_Trsf.hxx>
40 #include <TopExp_Explorer.hxx>
41 #include <BRepAdaptor_Curve.hxx>
42 #include <StdSelect_ShapeTypeFilter.hxx>
44 #include <AIS_ColoredShape.hxx>
45 #include <AIS_InteractiveObject.hxx>
46 #include <AIS_Trihedron.hxx>
47 #include <AIS_Axis.hxx>
48 #include <AIS_Relation.hxx>
49 #include <AIS_TypeFilter.hxx>
50 #include <AIS_SignatureFilter.hxx>
51 #include <AIS_LocalContext.hxx>
52 #include <AIS_ListOfInteractive.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <Aspect_InteriorStyle.hxx>
55 #include <Aspect_Window.hxx>
56 #include <Graphic3d_AspectFillArea3d.hxx>
57 #include <Graphic3d_AspectLine3d.hxx>
58 #include <Graphic3d_CStructure.hxx>
59 #include <Graphic3d_TextureRoot.hxx>
60 #include <Image_AlienPixMap.hxx>
61 #include <Prs3d_Drawer.hxx>
62 #include <Prs3d_ShadingAspect.hxx>
63 #include <Prs3d_IsoAspect.hxx>
64 #include <Prs3d_PointAspect.hxx>
65 #include <Select3D_SensitiveWire.hxx>
66 #include <SelectMgr_EntityOwner.hxx>
67 #include <StdSelect_BRepOwner.hxx>
68 #include <StdSelect_ViewerSelector3d.hxx>
69 #include <TopTools_MapOfShape.hxx>
70 #include <ViewerTest_AutoUpdater.hxx>
74 #include <Draw_Interpretor.hxx>
75 #include <TCollection_AsciiString.hxx>
76 #include <Draw_PluginMacro.hxx>
78 // avoid warnings on 'extern "C"' functions returning C++ classes
80 #define _CRT_SECURE_NO_DEPRECATE
81 #pragma warning(4:4190)
82 #pragma warning (disable:4996)
85 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
87 #include <Quantity_Color.hxx>
88 #include <Quantity_NameOfColor.hxx>
90 #include <Graphic3d_NameOfMaterial.hxx>
92 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
93 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
94 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
96 //=======================================================================
97 //function : GetColorFromName
98 //purpose : get the Quantity_NameOfColor from a string
99 //=======================================================================
101 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
103 Quantity_NameOfColor aColor = DEFAULT_COLOR;
104 Quantity_Color::ColorFromName (theName, aColor);
108 //=======================================================================
109 //function : ParseColor
111 //=======================================================================
113 Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
114 const char** theArgVec,
115 Quantity_Color& theColor)
117 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
119 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
124 else if (theArgNb >= 3)
126 const TCollection_AsciiString anRgbStr[3] =
132 if (!anRgbStr[0].IsRealValue()
133 || !anRgbStr[1].IsRealValue()
134 || !anRgbStr[2].IsRealValue())
139 Graphic3d_Vec4d anRgb;
140 anRgb.x() = anRgbStr[0].RealValue();
141 anRgb.y() = anRgbStr[1].RealValue();
142 anRgb.z() = anRgbStr[2].RealValue();
143 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
144 || anRgb.y() < 0.0 || anRgb.y() > 1.0
145 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
147 std::cout << "Error: RGB color values should be within range 0..1!\n";
151 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
158 //=======================================================================
159 //function : GetTypeNames
161 //=======================================================================
162 static const char** GetTypeNames()
164 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
165 "Shape","ConnectedShape","MultiConn.Shape",
166 "ConnectedInter.","MultiConn.",
167 "Constraint","Dimension"};
168 static const char** ThePointer = names;
172 //=======================================================================
173 //function : GetTypeAndSignfromString
175 //=======================================================================
176 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
178 const char ** thefullnames = GetTypeNames();
179 Standard_Integer index(-1);
181 for(Standard_Integer i=0;i<=13 && index==-1;i++)
182 if(!strcasecmp(name,thefullnames[i]))
186 TheType = AIS_KOI_None;
192 TheType = AIS_KOI_Datum;
196 TheType = AIS_KOI_Shape;
200 TheType = AIS_KOI_Object;
204 TheType = AIS_KOI_Relation;
213 #include <Draw_Interpretor.hxx>
215 #include <Draw_Appli.hxx>
219 #include <TCollection_AsciiString.hxx>
220 #include <V3d_Viewer.hxx>
221 #include <V3d_View.hxx>
224 #include <AIS_InteractiveContext.hxx>
225 #include <AIS_Shape.hxx>
226 #include <AIS_TexturedShape.hxx>
227 #include <AIS_DisplayMode.hxx>
228 #include <TColStd_MapOfInteger.hxx>
229 #include <AIS_MapOfInteractive.hxx>
230 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
231 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
232 #include <ViewerTest_EventManager.hxx>
234 #include <TopoDS_Solid.hxx>
235 #include <BRepTools.hxx>
236 #include <BRep_Builder.hxx>
237 #include <TopAbs_ShapeEnum.hxx>
239 #include <TopoDS.hxx>
240 #include <BRep_Tool.hxx>
243 #include <Draw_Window.hxx>
244 #include <AIS_ListIteratorOfListOfInteractive.hxx>
245 #include <AIS_ListOfInteractive.hxx>
246 #include <AIS_DisplayMode.hxx>
247 #include <TopTools_ListOfShape.hxx>
248 #include <BRepOffsetAPI_MakeThickSolid.hxx>
249 #include <BRepOffset.hxx>
251 //==============================================================================
252 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
253 //==============================================================================
254 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
255 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
259 //=======================================================================
262 //=======================================================================
263 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
264 const Handle(AIS_InteractiveObject)& theObject,
265 const Standard_Boolean theToUpdate,
266 const Standard_Boolean theReplaceIfExists)
268 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
269 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
272 std::cout << "Error: AIS context is not available.\n";
273 return Standard_False;
276 if (aMap.IsBound2 (theName))
278 if (!theReplaceIfExists)
280 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
281 << "Please use another name.\n";
282 return Standard_False;
285 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
286 if (!anOldObj.IsNull())
288 aCtx->Remove (anOldObj, Standard_True);
290 aMap.UnBind2 (theName);
293 if (theObject.IsNull())
295 // object with specified name has been already unbound
296 return Standard_True;
299 // unbind AIS object if it was bound with another name
300 aMap.UnBind1 (theObject);
302 // can be registered without rebinding
303 aMap.Bind (theObject, theName);
304 aCtx->Display (theObject, theToUpdate);
305 return Standard_True;
308 //! Alias for ViewerTest::Display(), compatibility with old code.
309 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
310 const Handle(AIS_InteractiveObject)& theObject,
311 Standard_Boolean theReplaceIfExists = Standard_True)
313 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
316 static TColStd_MapOfInteger theactivatedmodes(8);
317 static TColStd_ListOfTransient theEventMgrs;
319 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
320 const Handle(AIS_InteractiveContext)& Ctx)
322 theEventMgrs.Clear();
323 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
326 static Handle(V3d_View)& a3DView()
328 static Handle(V3d_View) Viou;
333 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
334 static Handle(AIS_InteractiveContext) aContext;
338 const Handle(V3d_View)& ViewerTest::CurrentView()
342 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
347 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
349 return TheAISContext();
352 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
354 TheAISContext() = aCtx;
355 ViewerTest::ResetEventManager();
358 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
360 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
363 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
365 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
369 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
370 theEventMgrs.Prepend(EM);
373 void ViewerTest::UnsetEventManager()
375 theEventMgrs.RemoveFirst();
379 void ViewerTest::ResetEventManager()
381 const Handle(V3d_View) aView = ViewerTest::CurrentView();
382 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
385 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
387 Handle(ViewerTest_EventManager) EM;
388 if(theEventMgrs.IsEmpty()) return EM;
389 Handle(Standard_Transient) Tr = theEventMgrs.First();
390 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
394 //=======================================================================
395 //function : Get Context and active view
397 //=======================================================================
398 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
399 Handle(V3d_View)& theView)
401 theCtx = ViewerTest::GetAISContext();
402 theView = ViewerTest::CurrentView();
406 std::cout << "Error: cannot find an active view!\n";
407 return Standard_False;
409 return Standard_True;
412 //==============================================================================
413 //function : GetShapeFromName
414 //purpose : Compute an Shape from a draw variable or a file name
415 //==============================================================================
417 static TopoDS_Shape GetShapeFromName(const char* name)
419 TopoDS_Shape S = DBRep::Get(name);
422 BRep_Builder aBuilder;
423 BRepTools::Read( S, name, aBuilder);
429 //==============================================================================
430 //function : GetAISShapeFromName
431 //purpose : Compute an AIS_Shape from a draw variable or a file name
432 //==============================================================================
433 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
435 Handle(AIS_Shape) retsh;
437 if(GetMapOfAIS().IsBound2(name)){
438 const Handle(AIS_InteractiveObject) IO =
439 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
441 if(IO->Type()==AIS_KOI_Shape) {
442 if(IO->Signature()==0){
443 retsh = *((Handle(AIS_Shape)*)&IO);
446 cout << "an Object which is not an AIS_Shape "
447 "already has this name!!!"<<endl;
454 TopoDS_Shape S = GetShapeFromName(name);
456 retsh = new AIS_Shape(S);
462 //==============================================================================
464 //purpose : Remove all the object from the viewer
465 //==============================================================================
466 void ViewerTest::Clear()
468 if ( !a3DView().IsNull() ) {
469 if (TheAISContext()->HasOpenedContext())
470 TheAISContext()->CloseLocalContext();
471 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
472 while ( it.More() ) {
473 cout << "Remove " << it.Key2() << endl;
474 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
475 TheAISContext()->Remove(anObj,Standard_False);
478 TheAISContext()->RebuildSelectionStructs();
479 TheAISContext()->UpdateCurrentViewer();
480 GetMapOfAIS().Clear();
484 //==============================================================================
485 //function : StandardModesActivation
486 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
488 //==============================================================================
489 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
491 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
493 if (TheAISContext()->HasOpenedContext())
494 aContext->CloseLocalContext();
497 if(!aContext->HasOpenedContext()) {
498 // To unhilight the preselected object
499 aContext->UnhilightCurrents(Standard_False);
500 // Open a local Context in order to be able to select subshape from
501 // the selected shape if any or for all if there is no selection
502 if (!aContext->FirstCurrentObject().IsNull()){
503 aContext->OpenLocalContext(Standard_False);
505 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
506 aContext->Load( aContext->Current(),-1,Standard_True);
510 aContext->OpenLocalContext();
513 const char *cmode="???";
516 case 0: cmode = "Shape"; break;
517 case 1: cmode = "Vertex"; break;
518 case 2: cmode = "Edge"; break;
519 case 3: cmode = "Wire"; break;
520 case 4: cmode = "Face"; break;
521 case 5: cmode = "Shell"; break;
522 case 6: cmode = "Solid"; break;
523 case 7: cmode = "Compsolid"; break;
524 case 8: cmode = "Compound"; break;
527 if(theactivatedmodes.Contains(mode))
529 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
530 theactivatedmodes.Remove(mode);
531 cout<<"Mode "<< cmode <<" OFF"<<endl;
535 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
536 theactivatedmodes.Add(mode);
537 cout<<"Mode "<< cmode << " ON" << endl;
542 //==============================================================================
543 //function : CopyIsoAspect
544 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
545 //==============================================================================
546 static Handle(Prs3d_IsoAspect) CopyIsoAspect
547 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
548 const Standard_Integer theNbIsos)
550 Quantity_Color aColor;
551 Aspect_TypeOfLine aType;
552 Standard_Real aWidth;
554 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
556 Handle(Prs3d_IsoAspect) aResult =
557 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
562 //==============================================================================
564 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
565 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
566 //==============================================================================
567 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
569 if (TheAISContext().IsNull()) {
570 di << argv[0] << " Call 'vinit' before!\n";
575 di << "Current number of isos : " <<
576 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
577 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
578 di << "IsoOnPlane mode is " <<
579 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
584 Standard_Integer aLastInd = argc - 1;
585 Standard_Boolean isChanged = Standard_False;
586 Standard_Integer aNbUIsos = 0;
587 Standard_Integer aNbVIsos = 0;
590 Standard_Boolean isIsoOnPlane = Standard_False;
592 if (strcmp(argv[aLastInd], "1") == 0) {
593 isIsoOnPlane = Standard_True;
594 isChanged = Standard_True;
595 } else if (strcmp(argv[aLastInd], "0") == 0) {
596 isIsoOnPlane = Standard_False;
597 isChanged = Standard_True;
601 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
602 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
605 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
606 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
608 TheAISContext()->IsoOnPlane(isIsoOnPlane);
611 // If there are no shapes provided set the default numbers.
612 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
613 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
620 for (i = 1; i <= aLastInd; i++) {
621 TCollection_AsciiString name(argv[i]);
622 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
625 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
626 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
627 const Handle(AIS_InteractiveObject) aShape =
628 Handle(AIS_InteractiveObject)::DownCast (anObj);
629 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
630 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
631 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
634 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
635 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
636 TheAISContext()->SetLocalAttributes
637 (aShape, CurDrawer, Standard_False);
638 TheAISContext()->Redisplay(aShape);
640 di << "Number of isos for " << argv[i] << " : "
641 << aUIso->Number() << " " << aVIso->Number() << "\n";
644 di << argv[i] << ": Not an AIS interactive object!\n";
647 di << argv[i] << ": Use 'vdisplay' before\n";
652 TheAISContext()->UpdateCurrentViewer();
658 static Standard_Integer VDispSensi (Draw_Interpretor& ,
659 Standard_Integer theArgNb,
664 std::cout << "Error: wrong syntax!\n";
668 Handle(AIS_InteractiveContext) aCtx;
669 Handle(V3d_View) aView;
670 if (!getCtxAndView (aCtx, aView))
675 aCtx->DisplayActiveSensitive (aView);
680 static Standard_Integer VClearSensi (Draw_Interpretor& ,
681 Standard_Integer theArgNb,
686 std::cout << "Error: wrong syntax!\n";
690 Handle(AIS_InteractiveContext) aCtx;
691 Handle(V3d_View) aView;
692 if (!getCtxAndView (aCtx, aView))
696 aCtx->ClearActiveSensitive (aView);
700 //==============================================================================
702 //purpose : To list the displayed object with their attributes
703 //==============================================================================
704 static int VDir (Draw_Interpretor& theDI,
708 if (!a3DView().IsNull())
713 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
714 anIter.More(); anIter.Next())
716 theDI << "\t" << anIter.Key2().ToCString() << "\n";
721 //==============================================================================
722 //function : VSelPrecision
723 //purpose : To set the selection tolerance value
724 //Draw arg : Selection tolerance value (real value determining the width and
725 // height of selecting frustum bases). Without arguments the function
726 // just prints current tolerance.
727 //==============================================================================
728 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
732 di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
736 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
737 if( aContext.IsNull() )
742 Standard_Real aPixelTolerance = aContext->PixelTolerance();
743 di << "Pixel tolerance : " << aPixelTolerance << "\n";
747 TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
749 if (anArg == "-unset")
751 aContext->SetPixelTolerance (-1.0);
755 aContext->SetPixelTolerance (anArg.RealValue());
762 //! Auxiliary enumeration
763 enum ViewerTest_StereoPair
765 ViewerTest_SP_Single,
766 ViewerTest_SP_SideBySide,
767 ViewerTest_SP_OverUnder
770 //==============================================================================
772 //purpose : To dump the active view snapshot to image file
773 //==============================================================================
774 static Standard_Integer VDump (Draw_Interpretor& theDI,
775 Standard_Integer theArgNb,
776 Standard_CString* theArgVec)
780 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
784 Standard_Integer anArgIter = 1;
785 Standard_CString aFilePath = theArgVec[anArgIter++];
786 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
787 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
788 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
789 Standard_Integer aWidth = 0;
790 Standard_Integer aHeight = 0;
791 for (; anArgIter < theArgNb; ++anArgIter)
793 TCollection_AsciiString anArg (theArgVec[anArgIter]);
795 if (anArg == "-buffer")
797 if (++anArgIter >= theArgNb)
799 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
803 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
805 if (aBufArg == "rgba")
807 aBufferType = Graphic3d_BT_RGBA;
809 else if (aBufArg == "rgb")
811 aBufferType = Graphic3d_BT_RGB;
813 else if (aBufArg == "depth")
815 aBufferType = Graphic3d_BT_Depth;
819 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
823 else if (anArg == "-stereo")
825 if (++anArgIter >= theArgNb)
827 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
831 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
832 aStereoArg.LowerCase();
833 if (aStereoArg == "l"
834 || aStereoArg == "left")
836 aStereoOpts = V3d_SDO_LEFT_EYE;
838 else if (aStereoArg == "r"
839 || aStereoArg == "right")
841 aStereoOpts = V3d_SDO_RIGHT_EYE;
843 else if (aStereoArg == "mono")
845 aStereoOpts = V3d_SDO_MONO;
847 else if (aStereoArg == "blended"
848 || aStereoArg == "blend"
849 || aStereoArg == "stereo")
851 aStereoOpts = V3d_SDO_BLENDED;
853 else if (aStereoArg == "sbs"
854 || aStereoArg == "sidebyside")
856 aStereoPair = ViewerTest_SP_SideBySide;
858 else if (aStereoArg == "ou"
859 || aStereoArg == "overunder")
861 aStereoPair = ViewerTest_SP_OverUnder;
865 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
869 else if (anArg == "-rgba"
872 aBufferType = Graphic3d_BT_RGBA;
874 else if (anArg == "-rgb"
877 aBufferType = Graphic3d_BT_RGB;
879 else if (anArg == "-depth"
882 aBufferType = Graphic3d_BT_Depth;
885 else if (anArg == "-width"
891 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
894 else if (++anArgIter >= theArgNb)
896 std::cout << "Error: integer value is expected right after 'width'\n";
899 aWidth = Draw::Atoi (theArgVec[anArgIter]);
901 else if (anArg == "-height"
903 || anArg == "-sizey")
907 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
910 else if (++anArgIter >= theArgNb)
912 std::cout << "Error: integer value is expected right after 'height'\n";
915 aHeight = Draw::Atoi (theArgVec[anArgIter]);
919 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
923 if ((aWidth <= 0 && aHeight > 0)
924 || (aWidth > 0 && aHeight <= 0))
926 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
930 Handle(V3d_View) aView = ViewerTest::CurrentView();
933 std::cout << "Error: cannot find an active view!\n";
937 if (aWidth <= 0 || aHeight <= 0)
939 aView->Window()->Size (aWidth, aHeight);
942 Image_AlienPixMap aPixMap;
944 bool isBigEndian = Image_PixMap::IsBigEndianHost();
945 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
948 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
949 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
950 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
955 case ViewerTest_SP_Single:
957 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
959 theDI << "Fail: view dump failed!\n";
962 else if (aPixMap.SizeX() != Standard_Size(aWidth)
963 || aPixMap.SizeY() != Standard_Size(aHeight))
965 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
966 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
970 case ViewerTest_SP_SideBySide:
972 if (!aPixMap.InitZero (aFormat, aWidth * 2, aHeight))
974 theDI << "Fail: not enough memory for image allocation!\n";
978 Image_PixMap aPixMapL, aPixMapR;
979 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
980 aWidth, aHeight, aPixMap.SizeRowBytes());
981 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aWidth,
982 aWidth, aHeight, aPixMap.SizeRowBytes());
983 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
984 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE)
987 theDI << "Fail: view dump failed!\n";
992 case ViewerTest_SP_OverUnder:
994 if (!aPixMap.InitZero (aFormat, aWidth, aHeight * 2))
996 theDI << "Fail: not enough memory for image allocation!\n";
1000 Image_PixMap aPixMapL, aPixMapR;
1001 aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
1002 aWidth, aHeight, aPixMap.SizeRowBytes());
1003 aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aHeight,
1004 aWidth, aHeight, aPixMap.SizeRowBytes());
1005 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1006 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE))
1008 theDI << "Fail: view dump failed!\n";
1015 if (!aPixMap.Save (aFilePath))
1017 theDI << "Fail: image can not be saved!\n";
1022 //==============================================================================
1023 //function : Displays,Erase...
1026 //==============================================================================
1027 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
1028 const Standard_Integer Mode,
1029 const Standard_Integer TypeOfOperation,
1030 const Standard_Boolean Upd)
1032 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1034 switch(TypeOfOperation){
1036 Ctx->Display(IO,Mode,Upd);
1044 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
1046 Ctx->SetDisplayMode(IO,Mode,Upd);
1051 Ctx->SetDisplayMode(0,Upd);
1053 Ctx->UnsetDisplayMode(IO,Upd);
1060 //=======================================================================
1063 //=======================================================================
1064 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1067 TCollection_AsciiString name;
1070 // display others presentations
1071 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
1072 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
1073 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
1074 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1076 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1078 //unset displaymode.. comportement particulier...
1079 if(TypeOfOperation==4){
1081 if(Ctx->NbCurrents()==0 ||
1082 Ctx->NbSelected()==0){
1083 Handle(AIS_InteractiveObject) IO;
1084 VwrTst_DispErase(IO,-1,4,Standard_False);
1086 else if(!Ctx->HasOpenedContext()){
1087 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1088 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1091 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1092 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1093 Ctx->UpdateCurrentViewer();
1096 Handle(AIS_InteractiveObject) IO;
1098 if(GetMapOfAIS().IsBound2(name)){
1099 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1101 VwrTst_DispErase(IO,-1,4,Standard_True);
1106 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1107 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1108 Handle(AIS_InteractiveObject) IO;
1109 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1111 if(!Ctx->HasOpenedContext()){
1112 // set/unset display mode sur le Contexte...
1113 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1114 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1116 Ctx->UpdateCurrentViewer();
1119 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1120 Ctx->Display(Ctx->Interactive(),Dmode);
1124 Handle(AIS_InteractiveObject) IO;
1126 if(GetMapOfAIS().IsBound2(name))
1127 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1129 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1135 //=======================================================================
1138 //=======================================================================
1139 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1141 if(argc==1) return 1;
1142 Standard_Integer On = Draw::Atoi(argv[1]);
1143 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1147 if(!Ctx->HasOpenedContext()){
1148 di<<"sub intensite ";
1151 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1152 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1154 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1156 di <<"passage dans off"<<"\n";
1157 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1162 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1164 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1166 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1169 Ctx->UpdateCurrentViewer();
1172 Handle(AIS_InteractiveObject) IO;
1173 TCollection_AsciiString name = argv[2];
1174 if(GetMapOfAIS().IsBound2(name)){
1175 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1178 Ctx->SubIntensityOn(IO);
1180 Ctx->SubIntensityOff(IO);
1188 //! Auxiliary class to iterate presentations from different collections.
1189 class ViewTest_PrsIter
1193 //! Create and initialize iterator object.
1194 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1195 : mySource (IterSource_All)
1197 NCollection_Sequence<TCollection_AsciiString> aNames;
1198 if (!theName.IsEmpty())
1199 aNames.Append (theName);
1203 //! Create and initialize iterator object.
1204 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1205 : mySource (IterSource_All)
1210 //! Initialize the iterator.
1211 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1213 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1215 mySelIter.Nullify();
1216 myCurrent.Nullify();
1217 myCurrentTrs.Nullify();
1218 if (!mySeq.IsEmpty())
1220 mySource = IterSource_List;
1221 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1223 else if (aCtx->NbCurrents() > 0)
1225 mySource = IterSource_Selected;
1227 mySelIter->InitCurrent();
1231 mySource = IterSource_All;
1232 myMapIter.Initialize (GetMapOfAIS());
1237 const TCollection_AsciiString& CurrentName() const
1239 return myCurrentName;
1242 const Handle(AIS_InteractiveObject)& Current() const
1247 const Handle(Standard_Transient)& CurrentTrs() const
1249 return myCurrentTrs;
1252 //! @return true if iterator points to valid object within collection
1253 Standard_Boolean More() const
1257 case IterSource_All: return myMapIter.More();
1258 case IterSource_List: return mySeqIter.More();
1259 case IterSource_Selected: return mySelIter->MoreCurrent();
1261 return Standard_False;
1264 //! Go to the next item.
1267 myCurrentName.Clear();
1268 myCurrentTrs.Nullify();
1269 myCurrent.Nullify();
1272 case IterSource_All:
1277 case IterSource_List:
1282 case IterSource_Selected:
1284 mySelIter->NextCurrent();
1297 case IterSource_All:
1299 if (myMapIter.More())
1301 myCurrentName = myMapIter.Key2();
1302 myCurrentTrs = myMapIter.Key1();
1303 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1307 case IterSource_List:
1309 if (mySeqIter.More())
1311 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1313 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1316 myCurrentName = mySeqIter.Value();
1317 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1318 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1322 case IterSource_Selected:
1324 if (mySelIter->MoreCurrent())
1326 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1327 myCurrent = mySelIter->Current();
1345 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1346 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1347 NCollection_Sequence<TCollection_AsciiString> mySeq;
1348 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1350 TCollection_AsciiString myCurrentName;//!< current item name
1351 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1352 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1354 IterSource mySource; //!< iterated collection
1358 //==============================================================================
1359 //function : VInteriorStyle
1360 //purpose : sets interior style of the a selected or named or displayed shape
1361 //==============================================================================
1362 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1363 Standard_Integer theArgNb,
1364 const char** theArgVec)
1366 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1367 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1370 std::cerr << "Error: no active view!\n";
1374 Standard_Integer anArgIter = 1;
1375 for (; anArgIter < theArgNb; ++anArgIter)
1377 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1382 TCollection_AsciiString aName;
1383 if (theArgNb - anArgIter == 2)
1385 aName = theArgVec[anArgIter++];
1387 else if (theArgNb - anArgIter != 1)
1389 std::cout << "Error: wrong number of arguments! See usage:\n";
1390 theDI.PrintHelp (theArgVec[0]);
1393 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1394 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1395 aStyleArg.LowerCase();
1396 if (aStyleArg == "empty")
1400 else if (aStyleArg == "hollow")
1404 else if (aStyleArg == "hatch")
1408 else if (aStyleArg == "solid")
1412 else if (aStyleArg == "hiddenline")
1418 anInterStyle = aStyleArg.IntegerValue();
1420 if (anInterStyle < Aspect_IS_EMPTY
1421 || anInterStyle > Aspect_IS_HIDDENLINE)
1423 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1424 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1428 if (!aName.IsEmpty()
1429 && !GetMapOfAIS().IsBound2 (aName))
1431 std::cout << "Error: object " << aName << " is not displayed!\n";
1435 if (aCtx->HasOpenedContext())
1437 aCtx->CloseLocalContext();
1439 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1441 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1444 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1445 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1446 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1447 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1448 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1454 //! Auxiliary structure for VAspects
1455 struct ViewerTest_AspectsChangeSet
1457 Standard_Integer ToSetVisibility;
1458 Standard_Integer Visibility;
1460 Standard_Integer ToSetColor;
1461 Quantity_Color Color;
1463 Standard_Integer ToSetLineWidth;
1464 Standard_Real LineWidth;
1466 Standard_Integer ToSetTypeOfLine;
1467 Aspect_TypeOfLine TypeOfLine;
1469 Standard_Integer ToSetTransparency;
1470 Standard_Real Transparency;
1472 Standard_Integer ToSetMaterial;
1473 Graphic3d_NameOfMaterial Material;
1474 TCollection_AsciiString MatName;
1476 NCollection_Sequence<TopoDS_Shape> SubShapes;
1478 Standard_Integer ToSetShowFreeBoundary;
1479 Standard_Integer ToSetFreeBoundaryWidth;
1480 Standard_Real FreeBoundaryWidth;
1481 Standard_Integer ToSetFreeBoundaryColor;
1482 Quantity_Color FreeBoundaryColor;
1484 //! Empty constructor
1485 ViewerTest_AspectsChangeSet()
1486 : ToSetVisibility (0),
1489 Color (DEFAULT_COLOR),
1492 ToSetTypeOfLine (0),
1493 TypeOfLine (Aspect_TOL_SOLID),
1494 ToSetTransparency (0),
1497 Material (Graphic3d_NOM_DEFAULT),
1498 ToSetShowFreeBoundary (0),
1499 ToSetFreeBoundaryWidth (0),
1500 FreeBoundaryWidth (1.0),
1501 ToSetFreeBoundaryColor (0),
1502 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR) {}
1504 //! @return true if no changes have been requested
1505 Standard_Boolean IsEmpty() const
1507 return ToSetVisibility == 0
1508 && ToSetLineWidth == 0
1509 && ToSetTransparency == 0
1511 && ToSetMaterial == 0
1512 && ToSetShowFreeBoundary == 0
1513 && ToSetFreeBoundaryColor == 0
1514 && ToSetFreeBoundaryWidth == 0;
1517 //! @return true if properties are valid
1518 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1520 Standard_Boolean isOk = Standard_True;
1521 if (Visibility != 0 && Visibility != 1)
1523 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1524 isOk = Standard_False;
1526 if (LineWidth <= 0.0
1527 || LineWidth > 10.0)
1529 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1530 isOk = Standard_False;
1532 if (Transparency < 0.0
1533 || Transparency > 1.0)
1535 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1536 isOk = Standard_False;
1539 && ToSetTransparency)
1541 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1542 isOk = Standard_False;
1544 if (ToSetMaterial == 1
1545 && Material == Graphic3d_NOM_DEFAULT)
1547 std::cout << "Error: unknown material " << MatName << ".\n";
1548 isOk = Standard_False;
1550 if (FreeBoundaryWidth <= 0.0
1551 || FreeBoundaryWidth > 10.0)
1553 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1554 isOk = Standard_False;
1561 //==============================================================================
1562 //function : VAspects
1564 //==============================================================================
1565 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1566 Standard_Integer theArgNb,
1567 const char** theArgVec)
1569 TCollection_AsciiString aCmdName (theArgVec[0]);
1570 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1571 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1574 std::cerr << "Error: no active view!\n";
1578 Standard_Integer anArgIter = 1;
1579 Standard_Boolean isDefaults = Standard_False;
1580 NCollection_Sequence<TCollection_AsciiString> aNames;
1581 for (; anArgIter < theArgNb; ++anArgIter)
1583 TCollection_AsciiString anArg = theArgVec[anArgIter];
1584 if (anUpdateTool.parseRedrawMode (anArg))
1588 else if (!anArg.IsEmpty()
1589 && anArg.Value (1) != '-')
1591 aNames.Append (anArg);
1595 if (anArg == "-defaults")
1597 isDefaults = Standard_True;
1604 if (!aNames.IsEmpty() && isDefaults)
1606 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1610 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1611 aChanges.Append (ViewerTest_AspectsChangeSet());
1612 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1614 // parse syntax of legacy commands
1615 if (aCmdName == "vsetwidth")
1617 if (aNames.IsEmpty()
1618 || !aNames.Last().IsRealValue())
1620 std::cout << "Error: not enough arguments!\n";
1623 aChangeSet->ToSetLineWidth = 1;
1624 aChangeSet->LineWidth = aNames.Last().RealValue();
1625 aNames.Remove (aNames.Length());
1627 else if (aCmdName == "vunsetwidth")
1629 aChangeSet->ToSetLineWidth = -1;
1631 else if (aCmdName == "vsetcolor")
1633 if (aNames.IsEmpty())
1635 std::cout << "Error: not enough arguments!\n";
1638 aChangeSet->ToSetColor = 1;
1640 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1641 Standard_Boolean isOk = Standard_False;
1642 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1644 aChangeSet->Color = aColor;
1645 aNames.Remove (aNames.Length());
1646 isOk = Standard_True;
1648 else if (aNames.Length() >= 3)
1650 const TCollection_AsciiString anRgbStr[3] =
1652 aNames.Value (aNames.Upper() - 2),
1653 aNames.Value (aNames.Upper() - 1),
1654 aNames.Value (aNames.Upper() - 0)
1656 isOk = anRgbStr[0].IsRealValue()
1657 && anRgbStr[1].IsRealValue()
1658 && anRgbStr[2].IsRealValue();
1661 Graphic3d_Vec4d anRgb;
1662 anRgb.x() = anRgbStr[0].RealValue();
1663 anRgb.y() = anRgbStr[1].RealValue();
1664 anRgb.z() = anRgbStr[2].RealValue();
1665 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1666 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1667 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1669 std::cout << "Error: RGB color values should be within range 0..1!\n";
1672 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1673 aNames.Remove (aNames.Length());
1674 aNames.Remove (aNames.Length());
1675 aNames.Remove (aNames.Length());
1680 std::cout << "Error: not enough arguments!\n";
1684 else if (aCmdName == "vunsetcolor")
1686 aChangeSet->ToSetColor = -1;
1688 else if (aCmdName == "vsettransparency")
1690 if (aNames.IsEmpty()
1691 || !aNames.Last().IsRealValue())
1693 std::cout << "Error: not enough arguments!\n";
1696 aChangeSet->ToSetTransparency = 1;
1697 aChangeSet->Transparency = aNames.Last().RealValue();
1698 aNames.Remove (aNames.Length());
1700 else if (aCmdName == "vunsettransparency")
1702 aChangeSet->ToSetTransparency = -1;
1704 else if (aCmdName == "vsetmaterial")
1706 if (aNames.IsEmpty())
1708 std::cout << "Error: not enough arguments!\n";
1711 aChangeSet->ToSetMaterial = 1;
1712 aChangeSet->MatName = aNames.Last();
1713 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1714 aNames.Remove (aNames.Length());
1716 else if (aCmdName == "vunsetmaterial")
1718 aChangeSet->ToSetMaterial = -1;
1720 else if (anArgIter >= theArgNb)
1722 std::cout << "Error: not enough arguments!\n";
1726 if (!aChangeSet->IsEmpty())
1728 anArgIter = theArgNb;
1730 for (; anArgIter < theArgNb; ++anArgIter)
1732 TCollection_AsciiString anArg = theArgVec[anArgIter];
1734 if (anArg == "-setwidth"
1735 || anArg == "-setlinewidth")
1737 if (++anArgIter >= theArgNb)
1739 std::cout << "Error: wrong syntax at " << anArg << "\n";
1742 aChangeSet->ToSetLineWidth = 1;
1743 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1745 else if (anArg == "-unsetwidth"
1746 || anArg == "-unsetlinewidth")
1748 aChangeSet->ToSetLineWidth = -1;
1749 aChangeSet->LineWidth = 1.0;
1751 else if (anArg == "-settransp"
1752 || anArg == "-settransparency")
1754 if (++anArgIter >= theArgNb)
1756 std::cout << "Error: wrong syntax at " << anArg << "\n";
1759 aChangeSet->ToSetTransparency = 1;
1760 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1761 if (aChangeSet->Transparency >= 0.0
1762 && aChangeSet->Transparency <= Precision::Confusion())
1764 aChangeSet->ToSetTransparency = -1;
1765 aChangeSet->Transparency = 0.0;
1768 else if (anArg == "-setvis"
1769 || anArg == "-setvisibility")
1771 if (++anArgIter >= theArgNb)
1773 std::cout << "Error: wrong syntax at " << anArg << "\n";
1777 aChangeSet->ToSetVisibility = 1;
1778 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1780 else if (anArg == "-setalpha")
1782 if (++anArgIter >= theArgNb)
1784 std::cout << "Error: wrong syntax at " << anArg << "\n";
1787 aChangeSet->ToSetTransparency = 1;
1788 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1789 if (aChangeSet->Transparency < 0.0
1790 || aChangeSet->Transparency > 1.0)
1792 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1795 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1796 if (aChangeSet->Transparency >= 0.0
1797 && aChangeSet->Transparency <= Precision::Confusion())
1799 aChangeSet->ToSetTransparency = -1;
1800 aChangeSet->Transparency = 0.0;
1803 else if (anArg == "-unsettransp"
1804 || anArg == "-unsettransparency"
1805 || anArg == "-unsetalpha"
1806 || anArg == "-opaque")
1808 aChangeSet->ToSetTransparency = -1;
1809 aChangeSet->Transparency = 0.0;
1811 else if (anArg == "-setcolor")
1813 Standard_Integer aNbComps = 0;
1814 Standard_Integer aCompIter = anArgIter + 1;
1815 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1817 if (theArgVec[aCompIter][0] == '-')
1826 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1827 Standard_CString aName = theArgVec[anArgIter + 1];
1828 if (!Quantity_Color::ColorFromName (aName, aColor))
1830 std::cout << "Error: unknown color name '" << aName << "'\n";
1833 aChangeSet->Color = aColor;
1838 Graphic3d_Vec3d anRgb;
1839 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1840 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1841 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1842 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1843 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1844 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1846 std::cout << "Error: RGB color values should be within range 0..1!\n";
1849 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1854 std::cout << "Error: wrong syntax at " << anArg << "\n";
1858 aChangeSet->ToSetColor = 1;
1859 anArgIter += aNbComps;
1861 else if (anArg == "-setlinetype")
1863 if (++anArgIter >= theArgNb)
1865 std::cout << "Error: wrong syntax at " << anArg << "\n";
1869 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1872 if (aValue.IsEqual ("solid"))
1874 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1876 else if (aValue.IsEqual ("dot"))
1878 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1880 else if (aValue.IsEqual ("dash"))
1882 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1884 else if (aValue.IsEqual ("dotdash"))
1886 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1890 std::cout << "Error: wrong syntax at " << anArg << "\n";
1894 aChangeSet->ToSetTypeOfLine = 1;
1896 else if (anArg == "-unsetlinetype")
1898 aChangeSet->ToSetTypeOfLine = -1;
1900 else if (anArg == "-unsetcolor")
1902 aChangeSet->ToSetColor = -1;
1903 aChangeSet->Color = DEFAULT_COLOR;
1905 else if (anArg == "-setmat"
1906 || anArg == "-setmaterial")
1908 if (++anArgIter >= theArgNb)
1910 std::cout << "Error: wrong syntax at " << anArg << "\n";
1913 aChangeSet->ToSetMaterial = 1;
1914 aChangeSet->MatName = theArgVec[anArgIter];
1915 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1917 else if (anArg == "-unsetmat"
1918 || anArg == "-unsetmaterial")
1920 aChangeSet->ToSetMaterial = -1;
1921 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1923 else if (anArg == "-subshape"
1924 || anArg == "-subshapes")
1928 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1932 if (aNames.IsEmpty())
1934 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1938 aChanges.Append (ViewerTest_AspectsChangeSet());
1939 aChangeSet = &aChanges.ChangeLast();
1941 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1943 Standard_CString aSubShapeName = theArgVec[anArgIter];
1944 if (*aSubShapeName == '-')
1950 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1951 if (aSubShape.IsNull())
1953 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1956 aChangeSet->SubShapes.Append (aSubShape);
1959 if (aChangeSet->SubShapes.IsEmpty())
1961 std::cerr << "Error: empty list is specified after -subshapes!\n";
1965 else if (anArg == "-freeboundary"
1968 if (++anArgIter >= theArgNb)
1970 std::cout << "Error: wrong syntax at " << anArg << "\n";
1973 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1978 aChangeSet->ToSetShowFreeBoundary = 1;
1980 else if (aValue == "off"
1983 aChangeSet->ToSetShowFreeBoundary = -1;
1987 std::cout << "Error: wrong syntax at " << anArg << "\n";
1991 else if (anArg == "-setfreeboundarywidth"
1992 || anArg == "-setfbwidth")
1994 if (++anArgIter >= theArgNb)
1996 std::cout << "Error: wrong syntax at " << anArg << "\n";
1999 aChangeSet->ToSetFreeBoundaryWidth = 1;
2000 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2002 else if (anArg == "-unsetfreeboundarywidth"
2003 || anArg == "-unsetfbwidth")
2005 aChangeSet->ToSetFreeBoundaryWidth = -1;
2006 aChangeSet->FreeBoundaryWidth = 1.0;
2008 else if (anArg == "-setfreeboundarycolor"
2009 || anArg == "-setfbcolor")
2011 Standard_Integer aNbComps = 0;
2012 Standard_Integer aCompIter = anArgIter + 1;
2013 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2015 if (theArgVec[aCompIter][0] == '-')
2024 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2025 Standard_CString aName = theArgVec[anArgIter + 1];
2026 if (!Quantity_Color::ColorFromName (aName, aColor))
2028 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2031 aChangeSet->FreeBoundaryColor = aColor;
2036 Graphic3d_Vec3d anRgb;
2037 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2038 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2039 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2040 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2041 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2042 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2044 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2047 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2052 std::cout << "Error: wrong syntax at " << anArg << "\n";
2056 aChangeSet->ToSetFreeBoundaryColor = 1;
2057 anArgIter += aNbComps;
2059 else if (anArg == "-unsetfreeboundarycolor"
2060 || anArg == "-unsetfbcolor")
2062 aChangeSet->ToSetFreeBoundaryColor = -1;
2063 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2065 else if (anArg == "-unset")
2067 aChangeSet->ToSetVisibility = 1;
2068 aChangeSet->Visibility = 1;
2069 aChangeSet->ToSetLineWidth = -1;
2070 aChangeSet->LineWidth = 1.0;
2071 aChangeSet->ToSetTypeOfLine = -1;
2072 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2073 aChangeSet->ToSetTransparency = -1;
2074 aChangeSet->Transparency = 0.0;
2075 aChangeSet->ToSetColor = -1;
2076 aChangeSet->Color = DEFAULT_COLOR;
2077 aChangeSet->ToSetMaterial = -1;
2078 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2079 aChangeSet->ToSetShowFreeBoundary = -1;
2080 aChangeSet->ToSetFreeBoundaryColor = -1;
2081 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2082 aChangeSet->ToSetFreeBoundaryWidth = -1;
2083 aChangeSet->FreeBoundaryWidth = 1.0;
2087 std::cout << "Error: wrong syntax at " << anArg << "\n";
2092 Standard_Boolean isFirst = Standard_True;
2093 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2094 aChangesIter.More(); aChangesIter.Next())
2096 if (!aChangesIter.Value().Validate (!isFirst))
2100 isFirst = Standard_False;
2103 if (aCtx->HasOpenedContext())
2105 aCtx->CloseLocalContext();
2108 // special case for -defaults parameter.
2109 // all changed values will be set to DefaultDrawer.
2112 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2114 if (aChangeSet->ToSetLineWidth != 0)
2116 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2117 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2118 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2119 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2121 if (aChangeSet->ToSetColor != 0)
2123 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2124 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2125 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2126 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2127 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2128 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2130 if (aChangeSet->ToSetTypeOfLine != 0)
2132 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2133 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2134 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2135 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2136 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2138 if (aChangeSet->ToSetTransparency != 0)
2140 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2142 if (aChangeSet->ToSetMaterial != 0)
2144 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2146 if (aChangeSet->ToSetShowFreeBoundary == 1)
2148 aDrawer->SetFreeBoundaryDraw (Standard_True);
2150 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2152 aDrawer->SetFreeBoundaryDraw (Standard_False);
2154 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2156 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2158 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2160 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2163 // redisplay all objects in context
2164 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2166 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2169 aCtx->Redisplay (aPrs, Standard_False);
2175 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2177 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2178 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2179 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2180 Handle(AIS_ColoredShape) aColoredPrs;
2181 Standard_Boolean toDisplay = Standard_False;
2182 Standard_Boolean toRedisplay = Standard_False;
2183 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2185 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2186 if (aShapePrs.IsNull())
2188 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2191 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2192 if (aColoredPrs.IsNull())
2194 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2195 aCtx->Remove (aShapePrs, Standard_False);
2196 GetMapOfAIS().UnBind2 (aName);
2197 GetMapOfAIS().Bind (aColoredPrs, aName);
2198 toDisplay = Standard_True;
2199 aShapePrs = aColoredPrs;
2206 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2207 aChangeSet = &aChangesIter.ChangeValue();
2208 if (aChangeSet->ToSetVisibility == 1)
2210 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2211 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2213 else if (aChangeSet->ToSetMaterial == 1)
2215 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2217 else if (aChangeSet->ToSetMaterial == -1)
2219 aCtx->UnsetMaterial (aPrs, Standard_False);
2221 if (aChangeSet->ToSetColor == 1)
2223 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2225 else if (aChangeSet->ToSetColor == -1)
2227 aCtx->UnsetColor (aPrs, Standard_False);
2229 if (aChangeSet->ToSetTransparency == 1)
2231 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2233 else if (aChangeSet->ToSetTransparency == -1)
2235 aCtx->UnsetTransparency (aPrs, Standard_False);
2237 if (aChangeSet->ToSetLineWidth == 1)
2239 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2241 else if (aChangeSet->ToSetLineWidth == -1)
2243 aCtx->UnsetWidth (aPrs, Standard_False);
2245 if (!aDrawer.IsNull())
2247 if (aChangeSet->ToSetShowFreeBoundary == 1)
2249 aDrawer->SetFreeBoundaryDraw (Standard_True);
2250 toRedisplay = Standard_True;
2252 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2254 aDrawer->SetFreeBoundaryDraw (Standard_False);
2255 toRedisplay = Standard_True;
2257 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2259 Handle(Prs3d_LineAspect) aBoundaryAspect =
2260 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2261 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2262 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2263 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2264 toRedisplay = Standard_True;
2266 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2268 Handle(Prs3d_LineAspect) aBoundaryAspect =
2269 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2270 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2271 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2272 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2273 toRedisplay = Standard_True;
2275 if (aChangeSet->ToSetTypeOfLine != 0)
2277 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2278 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2279 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2280 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2281 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2282 toRedisplay = Standard_True;
2286 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2288 aChangeSet = &aChangesIter.ChangeValue();
2289 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2290 aSubShapeIter.More(); aSubShapeIter.Next())
2292 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2293 if (aChangeSet->ToSetVisibility == 1)
2295 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2296 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2298 if (aChangeSet->ToSetColor == 1)
2300 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2302 if (aChangeSet->ToSetLineWidth == 1)
2304 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2306 if (aChangeSet->ToSetColor == -1
2307 || aChangeSet->ToSetLineWidth == -1)
2309 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2315 aCtx->Display (aPrs, Standard_False);
2319 aCtx->Redisplay (aPrs, Standard_False);
2321 else if (!aColoredPrs.IsNull())
2323 aCtx->Redisplay (aColoredPrs, Standard_False);
2330 //==============================================================================
2331 //function : VDonly2
2333 //purpose : Display only a selected or named object
2334 // if there is no selected or named object s, nothing is done
2335 //==============================================================================
2336 static int VDonly2 (Draw_Interpretor& ,
2337 Standard_Integer theArgNb,
2338 const char** theArgVec)
2340 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2341 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2344 std::cerr << "Error: no active view!\n";
2348 if (aCtx->HasOpenedContext())
2350 aCtx->CloseLocalContext();
2353 Standard_Integer anArgIter = 1;
2354 for (; anArgIter < theArgNb; ++anArgIter)
2356 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2362 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2363 if (anArgIter >= theArgNb)
2365 // display only selected objects
2366 if (aCtx->NbCurrents() < 1)
2371 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2373 aDispSet.Add (aCtx->Current());
2378 // display only specified objects
2379 for (; anArgIter < theArgNb; ++anArgIter)
2381 TCollection_AsciiString aName = theArgVec[anArgIter];
2382 if (GetMapOfAIS().IsBound2 (aName))
2384 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2385 if (!aShape.IsNull())
2387 aCtx->Display (aShape, Standard_False);
2388 aDispSet.Add (aShape);
2394 // weed out other objects
2395 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2397 if (aDispSet.Contains (anIter.Key1()))
2402 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2403 if (aShape.IsNull())
2405 aCtx->Erase (aShape, Standard_False);
2411 //==============================================================================
2412 //function : VRemove
2413 //purpose : Removes selected or named objects.
2414 // If there is no selected or named objects,
2415 // all objects in the viewer can be removed with argument -all.
2416 // If -context is in arguments, the object is not deleted from the map of
2417 // objects (deleted only from the current context).
2418 //==============================================================================
2419 int VRemove (Draw_Interpretor& theDI,
2420 Standard_Integer theArgNb,
2421 const char** theArgVec)
2423 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2424 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2427 std::cerr << "Error: no active view!\n";
2431 Standard_Boolean isContextOnly = Standard_False;
2432 Standard_Boolean toRemoveAll = Standard_False;
2433 Standard_Boolean toPrintInfo = Standard_True;
2434 Standard_Boolean toRemoveLocal = Standard_False;
2436 Standard_Integer anArgIter = 1;
2437 for (; anArgIter < theArgNb; ++anArgIter)
2439 TCollection_AsciiString anArg = theArgVec[anArgIter];
2441 if (anArg == "-context")
2443 isContextOnly = Standard_True;
2445 else if (anArg == "-all")
2447 toRemoveAll = Standard_True;
2449 else if (anArg == "-noinfo")
2451 toPrintInfo = Standard_False;
2453 else if (anArg == "-local")
2455 toRemoveLocal = Standard_True;
2457 else if (anUpdateTool.parseRedrawMode (anArg))
2467 && anArgIter < theArgNb)
2469 std::cerr << "Error: wrong syntax!\n";
2473 if (toRemoveLocal && !aCtx->HasOpenedContext())
2475 std::cerr << "Error: local selection context is not open.\n";
2478 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2480 aCtx->CloseAllContexts (Standard_False);
2483 NCollection_List<TCollection_AsciiString> anIONameList;
2486 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2487 anIter.More(); anIter.Next())
2489 anIONameList.Append (anIter.Key2());
2492 else if (anArgIter < theArgNb) // removed objects names are in argument list
2494 for (; anArgIter < theArgNb; ++anArgIter)
2496 TCollection_AsciiString aName = theArgVec[anArgIter];
2497 if (!GetMapOfAIS().IsBound2 (aName))
2499 theDI << aName.ToCString() << " was not bound to some object.\n";
2503 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2504 if (anIO->GetContext() != aCtx)
2506 theDI << aName.ToCString() << " was not displayed in current context.\n";
2507 theDI << "Please activate view with this object displayed and try again.\n";
2511 anIONameList.Append (aName);
2515 else if (aCtx->NbCurrents() > 0)
2517 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2518 anIter.More(); anIter.Next())
2520 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2521 if (!aCtx->IsCurrent (anIO))
2526 anIONameList.Append (anIter.Key2());
2531 // Unbind all removed objects from the map of displayed IO.
2532 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2533 anIter.More(); anIter.Next())
2535 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2536 aCtx->Remove (anIO, Standard_False);
2539 theDI << anIter.Value().ToCString() << " was removed\n";
2543 GetMapOfAIS().UnBind2 (anIter.Value());
2547 // Close local context if it is empty
2548 TColStd_MapOfTransient aLocalIO;
2549 if (aCtx->HasOpenedContext()
2550 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2552 aCtx->CloseAllContexts (Standard_False);
2558 //==============================================================================
2560 //purpose : Erase some selected or named objects
2561 // if there is no selected or named objects, the whole viewer is erased
2562 //==============================================================================
2563 int VErase (Draw_Interpretor& theDI,
2564 Standard_Integer theArgNb,
2565 const char** theArgVec)
2567 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2568 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2569 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2572 std::cerr << "Error: no active view!\n";
2576 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2578 Standard_Integer anArgIter = 1;
2579 Standard_Boolean toEraseLocal = Standard_False;
2580 Standard_Boolean toEraseInView = Standard_False;
2581 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2582 for (; anArgIter < theArgNb; ++anArgIter)
2584 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2585 anArgCase.LowerCase();
2586 if (anUpdateTool.parseRedrawMode (anArgCase))
2590 else if (anArgCase == "-local")
2592 toEraseLocal = Standard_True;
2594 else if (anArgCase == "-view"
2595 || anArgCase == "-inview")
2597 toEraseInView = Standard_True;
2601 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2605 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2607 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2611 if (toEraseLocal && !aCtx->HasOpenedContext())
2613 std::cerr << "Error: local selection context is not open.\n";
2616 else if (!toEraseLocal && aCtx->HasOpenedContext())
2618 aCtx->CloseAllContexts (Standard_False);
2621 if (!aNamesOfEraseIO.IsEmpty())
2623 // Erase named objects
2624 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2626 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2627 if (!GetMapOfAIS().IsBound2 (aName))
2632 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2633 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2634 theDI << aName.ToCString() << " ";
2639 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2643 aCtx->Erase (anIO, Standard_False);
2648 else if (!toEraseAll && aCtx->NbCurrents() > 0)
2650 // Erase selected objects
2651 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2652 anIter.More(); anIter.Next())
2654 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2656 && aCtx->IsCurrent (anIO))
2658 theDI << anIter.Key2().ToCString() << " ";
2661 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2665 aCtx->Erase (anIO, Standard_False);
2672 // Erase all objects
2673 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2674 anIter.More(); anIter.Next())
2676 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2681 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2685 aCtx->Erase (anIO, Standard_False);
2694 //==============================================================================
2695 //function : VDisplayAll
2697 //purpose : Display all the objects of the Map
2698 //==============================================================================
2699 static int VDisplayAll (Draw_Interpretor& ,
2700 Standard_Integer theArgNb,
2701 const char** theArgVec)
2704 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2705 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2708 std::cerr << "Error: no active view!\n";
2712 Standard_Integer anArgIter = 1;
2713 Standard_Boolean toDisplayLocal = Standard_False;
2714 for (; anArgIter < theArgNb; ++anArgIter)
2716 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2717 anArgCase.LowerCase();
2718 if (anArgCase == "-local")
2720 toDisplayLocal = Standard_True;
2722 else if (anUpdateTool.parseRedrawMode (anArgCase))
2731 if (anArgIter < theArgNb)
2733 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2737 if (toDisplayLocal && !aCtx->HasOpenedContext())
2739 std::cerr << "Error: local selection context is not open.\n";
2742 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2744 aCtx->CloseLocalContext (Standard_False);
2747 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2748 anIter.More(); anIter.Next())
2750 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2751 aCtx->Erase (aShape, Standard_False);
2754 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2755 anIter.More(); anIter.Next())
2757 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2758 aCtx->Display (aShape, Standard_False);
2763 //! Auxiliary method to find presentation
2764 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2765 const Handle(AIS_InteractiveObject)& theIO,
2766 const Standard_Integer theMode)
2770 return Handle(PrsMgr_Presentation)();
2775 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2777 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2780 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2782 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2784 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2786 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2788 return Handle(PrsMgr_Presentation)();
2791 enum ViewerTest_BndAction
2798 //! Auxiliary method to print bounding box of presentation
2799 inline void bndPresentation (Draw_Interpretor& theDI,
2800 const Handle(PrsMgr_Presentation)& thePrs,
2801 const TCollection_AsciiString& theName,
2802 const ViewerTest_BndAction theAction)
2806 case BndAction_Hide:
2808 thePrs->Presentation()->GraphicUnHighlight();
2811 case BndAction_Show:
2813 Handle(Graphic3d_Structure) aPrs = thePrs->Presentation();
2814 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2815 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2816 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2817 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
2820 case BndAction_Print:
2822 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2823 gp_Pnt aMin = aBox.CornerMin();
2824 gp_Pnt aMax = aBox.CornerMax();
2825 theDI << theName << "\n"
2826 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2827 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2833 //==============================================================================
2834 //function : VBounding
2836 //==============================================================================
2837 int VBounding (Draw_Interpretor& theDI,
2838 Standard_Integer theArgNb,
2839 const char** theArgVec)
2841 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2842 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2845 std::cout << "Error: no active view!\n";
2849 ViewerTest_BndAction anAction = BndAction_Show;
2850 Standard_Integer aMode = -1;
2852 Standard_Integer anArgIter = 1;
2853 for (; anArgIter < theArgNb; ++anArgIter)
2855 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2857 if (anArg == "-print")
2859 anAction = BndAction_Print;
2861 else if (anArg == "-show")
2863 anAction = BndAction_Show;
2865 else if (anArg == "-hide")
2867 anAction = BndAction_Hide;
2869 else if (anArg == "-mode")
2871 if (++anArgIter >= theArgNb)
2873 std::cout << "Error: wrong syntax at " << anArg << "\n";
2876 aMode = Draw::Atoi (theArgVec[anArgIter]);
2878 else if (!anUpdateTool.parseRedrawMode (anArg))
2884 if (anArgIter < theArgNb)
2886 // has a list of names
2887 for (; anArgIter < theArgNb; ++anArgIter)
2889 TCollection_AsciiString aName = theArgVec[anArgIter];
2890 if (!GetMapOfAIS().IsBound2 (aName))
2892 std::cout << "Error: presentation " << aName << " does not exist\n";
2896 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2897 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2900 std::cout << "Error: presentation " << aName << " does not exist\n";
2903 bndPresentation (theDI, aPrs, aName, anAction);
2906 else if (aCtx->NbCurrents() > 0)
2908 // remove all currently selected objects
2909 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2911 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2912 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2915 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2922 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2923 anIter.More(); anIter.Next())
2925 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2926 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2929 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2936 //==============================================================================
2937 //function : VTexture
2939 //==============================================================================
2940 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2942 TCollection_AsciiString aCommandName (theArgv[0]);
2944 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
2945 if (aCommandName == "vtexture")
2949 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2950 std::cout << "Type help for more information.\n";
2954 // look for options of vtexture command
2955 TCollection_AsciiString aParseKey;
2956 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2958 TCollection_AsciiString anArg (theArgv [anArgIt]);
2961 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2964 aParseKey.Remove (1);
2965 aParseKey.UpperCase();
2966 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
2970 if (aParseKey.IsEmpty())
2975 aMapOfArgs(aParseKey)->Append (anArg);
2978 else if (aCommandName == "vtexscale"
2979 || aCommandName == "vtexorigin"
2980 || aCommandName == "vtexrepeat")
2982 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2983 // equal to -scale, -origin, -repeat options of vtexture command
2984 if (theArgsNb < 2 || theArgsNb > 4)
2986 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2987 std::cout << "Type help for more information.\n";
2991 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
2994 anArgs->Append ("OFF");
2996 else if (theArgsNb == 4)
2998 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2999 anArgs->Append (TCollection_AsciiString (theArgv[3]));
3002 TCollection_AsciiString anArgKey;
3003 if (aCommandName == "vtexscale")
3007 else if (aCommandName == "vtexorigin")
3009 anArgKey = "ORIGIN";
3013 anArgKey = "REPEAT";
3016 aMapOfArgs.Bind (anArgKey, anArgs);
3018 else if (aCommandName == "vtexdefault")
3020 // scan for parameters of vtexdefault command
3021 // equal to -default option of vtexture command
3022 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
3025 // Check arguments for validity
3026 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3027 for (; aMapIt.More(); aMapIt.Next())
3029 const TCollection_AsciiString& aKey = aMapIt.Key();
3030 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3032 // -scale, -origin, -repeat: one argument "off", or two real values
3033 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3034 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3035 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3040 // -modulate: single argument "on" / "off"
3041 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3046 // -default: no arguments
3047 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3052 TCollection_AsciiString aLowerKey;
3055 aLowerKey.LowerCase();
3056 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3057 std::cout << "Type help for more information.\n";
3061 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3062 if (anAISContext.IsNull())
3064 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
3068 Standard_Integer aPreviousMode = 0;
3070 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
3072 TCollection_AsciiString aShapeName (theArgv[1]);
3073 Handle(AIS_InteractiveObject) anIO;
3075 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3076 if (aMapOfIO.IsBound2 (aShapeName))
3078 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3083 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3087 Handle(AIS_TexturedShape) aTexturedIO;
3088 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3090 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3091 aPreviousMode = aTexturedIO->DisplayMode();
3095 anAISContext->Remove (anIO, Standard_False);
3096 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3097 GetMapOfAIS().UnBind1 (anIO);
3098 GetMapOfAIS().UnBind2 (aShapeName);
3099 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3102 // -------------------------------------------
3103 // Turn texturing on/off - only for vtexture
3104 // -------------------------------------------
3106 if (aCommandName == "vtexture")
3108 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3110 if (aTextureArg.IsEmpty())
3112 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
3113 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
3115 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3116 if (aPreviousMode == 3)
3118 anAISContext->RecomputePrsOnly (aTexturedIO);
3121 anAISContext->Display (aTexturedIO, Standard_True);
3124 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3126 if (aTextureArg == "?")
3128 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3130 theDi << "\n Files in current directory : \n" << "\n";
3131 theDi.Eval ("glob -nocomplain *");
3133 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3134 aCmnd += aTextureFolder;
3137 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
3138 theDi.Eval (aCmnd.ToCString());
3143 aTexturedIO->SetTextureFileName (aTextureArg);
3148 // ------------------------------------
3149 // Process other options and commands
3150 // ------------------------------------
3152 Handle(TColStd_HSequenceOfAsciiString) aValues;
3153 if (aMapOfArgs.Find ("DEFAULT", aValues))
3155 aTexturedIO->SetTextureRepeat (Standard_False);
3156 aTexturedIO->SetTextureOrigin (Standard_False);
3157 aTexturedIO->SetTextureScale (Standard_False);
3158 aTexturedIO->EnableTextureModulate();
3162 if (aMapOfArgs.Find ("SCALE", aValues))
3164 if (aValues->Value(1) != "OFF")
3166 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3170 aTexturedIO->SetTextureScale (Standard_False);
3174 if (aMapOfArgs.Find ("ORIGIN", aValues))
3176 if (aValues->Value(1) != "OFF")
3178 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3182 aTexturedIO->SetTextureOrigin (Standard_False);
3186 if (aMapOfArgs.Find ("REPEAT", aValues))
3188 if (aValues->Value(1) != "OFF")
3190 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3194 aTexturedIO->SetTextureRepeat (Standard_False);
3198 if (aMapOfArgs.Find ("MODULATE", aValues))
3200 if (aValues->Value(1) == "ON")
3202 aTexturedIO->EnableTextureModulate();
3206 aTexturedIO->DisableTextureModulate();
3211 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3213 anAISContext->RecomputePrsOnly (aTexturedIO);
3217 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3218 anAISContext->Display (aTexturedIO, Standard_True);
3219 anAISContext->Update (aTexturedIO,Standard_True);
3225 //! Auxiliary method to parse transformation persistence flags
3226 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3227 Standard_Integer& theFlags)
3229 if (theFlagString == "pan")
3231 theFlags |= Graphic3d_TMF_PanPers;
3233 else if (theFlagString == "zoom")
3235 theFlags |= Graphic3d_TMF_ZoomPers;
3237 else if (theFlagString == "rotate")
3239 theFlags |= Graphic3d_TMF_RotatePers;
3241 else if (theFlagString == "trihedron")
3243 theFlags = Graphic3d_TMF_TriedronPers;
3245 else if (theFlagString == "full")
3247 theFlags = Graphic3d_TMF_FullPers;
3249 else if (theFlagString == "none")
3251 theFlags = Graphic3d_TMF_None;
3255 return Standard_False;
3258 return Standard_True;
3261 //==============================================================================
3262 //function : VDisplay2
3264 //purpose : Display an object from its name
3265 //==============================================================================
3266 static int VDisplay2 (Draw_Interpretor& theDI,
3267 Standard_Integer theArgNb,
3268 const char** theArgVec)
3272 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3276 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3279 ViewerTest::ViewerInit();
3280 aCtx = ViewerTest::GetAISContext();
3283 // Parse input arguments
3284 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3285 Standard_Integer isMutable = -1;
3286 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3287 Standard_Boolean toDisplayLocal = Standard_False;
3288 Standard_Boolean toReDisplay = Standard_False;
3289 Standard_Integer isSelectable = -1;
3290 Standard_Integer anObjDispMode = -2;
3291 Standard_Integer anObjHighMode = -2;
3292 Standard_Boolean toSetTrsfPers = Standard_False;
3293 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3295 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3296 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3297 Standard_Integer toDisplayInView = Standard_False;
3298 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3300 const TCollection_AsciiString aName = theArgVec[anArgIter];
3301 TCollection_AsciiString aNameCase = aName;
3302 aNameCase.LowerCase();
3303 if (anUpdateTool.parseRedrawMode (aName))
3307 else if (aNameCase == "-mutable")
3311 else if (aNameCase == "-neutral")
3313 aDispStatus = AIS_DS_Displayed;
3315 else if (aNameCase == "-immediate"
3316 || aNameCase == "-top")
3318 aZLayer = Graphic3d_ZLayerId_Top;
3320 else if (aNameCase == "-topmost")
3322 aZLayer = Graphic3d_ZLayerId_Topmost;
3324 else if (aNameCase == "-osd"
3325 || aNameCase == "-toposd"
3326 || aNameCase == "-overlay")
3328 aZLayer = Graphic3d_ZLayerId_TopOSD;
3330 else if (aNameCase == "-botosd"
3331 || aNameCase == "-underlay")
3333 aZLayer = Graphic3d_ZLayerId_BotOSD;
3335 else if (aNameCase == "-select"
3336 || aNameCase == "-selectable")
3340 else if (aNameCase == "-noselect"
3341 || aNameCase == "-noselection")
3345 else if (aNameCase == "-dispmode"
3346 || aNameCase == "-displaymode")
3348 if (++anArgIter >= theArgNb)
3350 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3354 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3356 else if (aNameCase == "-highmode"
3357 || aNameCase == "-highlightmode")
3359 if (++anArgIter >= theArgNb)
3361 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3365 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3367 else if (aNameCase == "-3d")
3369 toSetTrsfPers = Standard_True;
3370 aTrsfPersFlags = Graphic3d_TMF_None;
3372 else if (aNameCase == "-2d")
3374 toSetTrsfPers = Standard_True;
3375 aTrsfPersFlags = Graphic3d_TMF_2d;
3377 else if (aNameCase == "-2dtopdown")
3379 toSetTrsfPers = Standard_True;
3380 aTrsfPersFlags = Graphic3d_TMF_2d | Graphic3d_TMF_2d_IsTopDown;
3382 else if (aNameCase == "-trsfpers"
3383 || aNameCase == "-pers")
3385 if (++anArgIter >= theArgNb)
3387 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3391 toSetTrsfPers = Standard_True;
3392 aTrsfPersFlags = Graphic3d_TMF_None;
3393 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3394 aPersFlags.LowerCase();
3395 for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
3397 if (aParserPos == -1)
3399 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3401 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3407 TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
3408 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3410 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3413 aPersFlags = anOtherFlags;
3416 else if (aNameCase == "-trsfperspos"
3417 || aNameCase == "-perspos")
3419 if (anArgIter + 2 >= theArgNb)
3421 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3425 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3426 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3427 TCollection_AsciiString aZ = "0";
3428 if (!aX.IsIntegerValue()
3429 || !aY.IsIntegerValue())
3431 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3434 if (anArgIter + 1 < theArgNb)
3436 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3437 if (aTemp.IsIntegerValue())
3443 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
3445 else if (aNameCase == "-layer")
3447 if (++anArgIter >= theArgNb)
3449 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3453 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3454 if (!aValue.IsIntegerValue())
3456 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3460 aZLayer = aValue.IntegerValue();
3462 else if (aNameCase == "-view"
3463 || aNameCase == "-inview")
3465 toDisplayInView = Standard_True;
3467 else if (aNameCase == "-local")
3469 aDispStatus = AIS_DS_Temporary;
3470 toDisplayLocal = Standard_True;
3472 else if (aNameCase == "-redisplay")
3474 toReDisplay = Standard_True;
3478 aNamesOfDisplayIO.Append (aName);
3482 if (aNamesOfDisplayIO.IsEmpty())
3484 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3488 // Prepare context for display
3489 if (toDisplayLocal && !aCtx->HasOpenedContext())
3491 aCtx->OpenLocalContext (Standard_False);
3493 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3495 aCtx->CloseAllContexts (Standard_False);
3498 // Display interactive objects
3499 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3501 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3503 if (!GetMapOfAIS().IsBound2 (aName))
3505 // create the AIS_Shape from a name
3506 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3507 if (!aShape.IsNull())
3509 if (isMutable != -1)
3511 aShape->SetMutable (isMutable == 1);
3513 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3515 aShape->SetZLayer (aZLayer);
3519 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3521 if (anObjDispMode != -2)
3523 aShape->SetDisplayMode (anObjDispMode);
3525 if (anObjHighMode != -2)
3527 aShape->SetHilightMode (anObjHighMode);
3529 if (!toDisplayLocal)
3530 GetMapOfAIS().Bind (aShape, aName);
3532 Standard_Integer aDispMode = aShape->HasDisplayMode()
3533 ? aShape->DisplayMode()
3534 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3535 ? aCtx->DisplayMode()
3537 Standard_Integer aSelMode = -1;
3538 if ( isSelectable == 1
3539 || (isSelectable == -1
3540 && aCtx->GetAutoActivateSelection()
3541 && aShape->GetTransformPersistenceMode() == 0))
3543 aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
3546 aCtx->Display (aShape, aDispMode, aSelMode,
3547 Standard_False, aShape->AcceptShapeDecomposition(),
3549 if (toDisplayInView)
3551 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3553 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3555 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3560 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3565 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3566 if (isMutable != -1)
3568 aShape->SetMutable (isMutable == 1);
3570 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3572 aShape->SetZLayer (aZLayer);
3576 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3578 if (anObjDispMode != -2)
3580 aShape->SetDisplayMode (anObjDispMode);
3582 if (anObjHighMode != -2)
3584 aShape->SetHilightMode (anObjHighMode);
3586 Standard_Integer aDispMode = aShape->HasDisplayMode()
3587 ? aShape->DisplayMode()
3588 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3589 ? aCtx->DisplayMode()
3591 Standard_Integer aSelMode = -1;
3592 if ( isSelectable == 1
3593 || (isSelectable == -1
3594 && aCtx->GetAutoActivateSelection()
3595 && aShape->GetTransformPersistenceMode() == 0))
3597 aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
3600 if (aShape->Type() == AIS_KOI_Datum)
3602 aCtx->Display (aShape, Standard_False);
3606 theDI << "Display " << aName.ToCString() << "\n";
3608 // update the Shape in the AIS_Shape
3609 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3610 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3611 if (!aShapePrs.IsNull())
3613 if (!aShapePrs->Shape().IsEqual (aNewShape))
3615 toReDisplay = Standard_True;
3617 aShapePrs->Set (aNewShape);
3621 aCtx->Redisplay (aShape, Standard_False);
3626 aCtx->Erase (aShape);
3628 aCtx->Display (aShape, aDispMode, aSelMode,
3629 Standard_False, aShape->AcceptShapeDecomposition(),
3631 if (toDisplayInView)
3633 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3641 //===============================================================================================
3642 //function : VUpdate
3644 //===============================================================================================
3645 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3647 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3648 if (aContextAIS.IsNull())
3650 std::cout << theArgVec[0] << "AIS context is not available.\n";
3656 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3660 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3662 AIS_ListOfInteractive aListOfIO;
3664 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3666 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3668 Handle(AIS_InteractiveObject) anAISObj;
3669 if (anAISMap.IsBound2 (aName))