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)::DownCast (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)::DownCast (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->UnhilightSelected(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->FirstSelectedObject().IsNull()){
503 aContext->OpenLocalContext(Standard_False);
505 for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
506 aContext->Load( aContext->SelectedInteractive(),-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";
580 di << "IsoOnTriangulation mode is " <<
581 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
585 Standard_Integer aLastInd = argc - 1;
586 Standard_Boolean isChanged = Standard_False;
587 Standard_Integer aNbUIsos = 0;
588 Standard_Integer aNbVIsos = 0;
591 Standard_Boolean isIsoOnPlane = Standard_False;
593 if (strcmp(argv[aLastInd], "1") == 0) {
594 isIsoOnPlane = Standard_True;
595 isChanged = Standard_True;
596 } else if (strcmp(argv[aLastInd], "0") == 0) {
597 isIsoOnPlane = Standard_False;
598 isChanged = Standard_True;
602 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
603 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
606 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
607 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
609 TheAISContext()->IsoOnPlane(isIsoOnPlane);
612 // If there are no shapes provided set the default numbers.
613 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
614 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
621 for (i = 1; i <= aLastInd; i++) {
622 TCollection_AsciiString name(argv[i]);
623 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
626 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
627 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
628 const Handle(AIS_InteractiveObject) aShape =
629 Handle(AIS_InteractiveObject)::DownCast (anObj);
630 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
631 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
632 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
635 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
636 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
637 TheAISContext()->SetLocalAttributes
638 (aShape, CurDrawer, Standard_False);
639 TheAISContext()->Redisplay(aShape);
641 di << "Number of isos for " << argv[i] << " : "
642 << aUIso->Number() << " " << aVIso->Number() << "\n";
645 di << argv[i] << ": Not an AIS interactive object!\n";
648 di << argv[i] << ": Use 'vdisplay' before\n";
653 TheAISContext()->UpdateCurrentViewer();
659 static Standard_Integer VDispSensi (Draw_Interpretor& ,
660 Standard_Integer theArgNb,
665 std::cout << "Error: wrong syntax!\n";
669 Handle(AIS_InteractiveContext) aCtx;
670 Handle(V3d_View) aView;
671 if (!getCtxAndView (aCtx, aView))
676 aCtx->DisplayActiveSensitive (aView);
681 static Standard_Integer VClearSensi (Draw_Interpretor& ,
682 Standard_Integer theArgNb,
687 std::cout << "Error: wrong syntax!\n";
691 Handle(AIS_InteractiveContext) aCtx;
692 Handle(V3d_View) aView;
693 if (!getCtxAndView (aCtx, aView))
697 aCtx->ClearActiveSensitive (aView);
701 //==============================================================================
703 //purpose : To list the displayed object with their attributes
704 //==============================================================================
705 static int VDir (Draw_Interpretor& theDI,
709 if (!a3DView().IsNull())
714 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
715 anIter.More(); anIter.Next())
717 theDI << "\t" << anIter.Key2().ToCString() << "\n";
722 //==============================================================================
723 //function : VSelPrecision
724 //purpose : To set the selection tolerance value
725 //Draw arg : Selection tolerance value (real value determining the width and
726 // height of selecting frustum bases). Without arguments the function
727 // just prints current tolerance.
728 //==============================================================================
729 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
733 di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
737 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
738 if( aContext.IsNull() )
743 Standard_Real aPixelTolerance = aContext->PixelTolerance();
744 di << "Pixel tolerance : " << aPixelTolerance << "\n";
748 TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
750 if (anArg == "-unset")
752 aContext->SetPixelTolerance (-1.0);
756 aContext->SetPixelTolerance (anArg.RealValue());
763 //! Auxiliary enumeration
764 enum ViewerTest_StereoPair
766 ViewerTest_SP_Single,
767 ViewerTest_SP_SideBySide,
768 ViewerTest_SP_OverUnder
771 //==============================================================================
773 //purpose : To dump the active view snapshot to image file
774 //==============================================================================
775 static Standard_Integer VDump (Draw_Interpretor& theDI,
776 Standard_Integer theArgNb,
777 Standard_CString* theArgVec)
781 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
785 Standard_Integer anArgIter = 1;
786 Standard_CString aFilePath = theArgVec[anArgIter++];
787 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
788 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
789 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
790 Standard_Integer aWidth = 0;
791 Standard_Integer aHeight = 0;
792 for (; anArgIter < theArgNb; ++anArgIter)
794 TCollection_AsciiString anArg (theArgVec[anArgIter]);
796 if (anArg == "-buffer")
798 if (++anArgIter >= theArgNb)
800 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
804 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
806 if (aBufArg == "rgba")
808 aBufferType = Graphic3d_BT_RGBA;
810 else if (aBufArg == "rgb")
812 aBufferType = Graphic3d_BT_RGB;
814 else if (aBufArg == "depth")
816 aBufferType = Graphic3d_BT_Depth;
820 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
824 else if (anArg == "-stereo")
826 if (++anArgIter >= theArgNb)
828 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
832 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
833 aStereoArg.LowerCase();
834 if (aStereoArg == "l"
835 || aStereoArg == "left")
837 aStereoOpts = V3d_SDO_LEFT_EYE;
839 else if (aStereoArg == "r"
840 || aStereoArg == "right")
842 aStereoOpts = V3d_SDO_RIGHT_EYE;
844 else if (aStereoArg == "mono")
846 aStereoOpts = V3d_SDO_MONO;
848 else if (aStereoArg == "blended"
849 || aStereoArg == "blend"
850 || aStereoArg == "stereo")
852 aStereoOpts = V3d_SDO_BLENDED;
854 else if (aStereoArg == "sbs"
855 || aStereoArg == "sidebyside")
857 aStereoPair = ViewerTest_SP_SideBySide;
859 else if (aStereoArg == "ou"
860 || aStereoArg == "overunder")
862 aStereoPair = ViewerTest_SP_OverUnder;
866 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
870 else if (anArg == "-rgba"
873 aBufferType = Graphic3d_BT_RGBA;
875 else if (anArg == "-rgb"
878 aBufferType = Graphic3d_BT_RGB;
880 else if (anArg == "-depth"
883 aBufferType = Graphic3d_BT_Depth;
886 else if (anArg == "-width"
892 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
895 else if (++anArgIter >= theArgNb)
897 std::cout << "Error: integer value is expected right after 'width'\n";
900 aWidth = Draw::Atoi (theArgVec[anArgIter]);
902 else if (anArg == "-height"
904 || anArg == "-sizey")
908 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
911 else if (++anArgIter >= theArgNb)
913 std::cout << "Error: integer value is expected right after 'height'\n";
916 aHeight = Draw::Atoi (theArgVec[anArgIter]);
920 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
924 if ((aWidth <= 0 && aHeight > 0)
925 || (aWidth > 0 && aHeight <= 0))
927 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
931 Handle(V3d_View) aView = ViewerTest::CurrentView();
934 std::cout << "Error: cannot find an active view!\n";
938 if (aWidth <= 0 || aHeight <= 0)
940 aView->Window()->Size (aWidth, aHeight);
943 Image_AlienPixMap aPixMap;
945 bool isBigEndian = Image_PixMap::IsBigEndianHost();
946 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
949 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
950 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
951 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
956 case ViewerTest_SP_Single:
958 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
960 theDI << "Fail: view dump failed!\n";
963 else if (aPixMap.SizeX() != Standard_Size(aWidth)
964 || aPixMap.SizeY() != Standard_Size(aHeight))
966 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
967 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
971 case ViewerTest_SP_SideBySide:
973 if (!aPixMap.InitZero (aFormat, aWidth * 2, aHeight))
975 theDI << "Fail: not enough memory for image allocation!\n";
979 Image_PixMap aPixMapL, aPixMapR;
980 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
981 aWidth, aHeight, aPixMap.SizeRowBytes());
982 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aWidth,
983 aWidth, aHeight, aPixMap.SizeRowBytes());
984 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
985 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE)
988 theDI << "Fail: view dump failed!\n";
993 case ViewerTest_SP_OverUnder:
995 if (!aPixMap.InitZero (aFormat, aWidth, aHeight * 2))
997 theDI << "Fail: not enough memory for image allocation!\n";
1001 Image_PixMap aPixMapL, aPixMapR;
1002 aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
1003 aWidth, aHeight, aPixMap.SizeRowBytes());
1004 aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aHeight,
1005 aWidth, aHeight, aPixMap.SizeRowBytes());
1006 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1007 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE))
1009 theDI << "Fail: view dump failed!\n";
1016 if (!aPixMap.Save (aFilePath))
1018 theDI << "Fail: image can not be saved!\n";
1023 //==============================================================================
1024 //function : Displays,Erase...
1027 //==============================================================================
1028 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
1029 const Standard_Integer Mode,
1030 const Standard_Integer TypeOfOperation,
1031 const Standard_Boolean Upd)
1033 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1035 switch(TypeOfOperation){
1037 Ctx->Display(IO,Mode,Upd);
1045 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
1047 Ctx->SetDisplayMode(IO,Mode,Upd);
1052 Ctx->SetDisplayMode(0,Upd);
1054 Ctx->UnsetDisplayMode(IO,Upd);
1061 //=======================================================================
1064 //=======================================================================
1065 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1068 TCollection_AsciiString name;
1071 // display others presentations
1072 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
1073 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
1074 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
1075 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1077 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1079 //unset displaymode.. comportement particulier...
1080 if(TypeOfOperation==4){
1082 if(Ctx->NbSelected()==0){
1083 Handle(AIS_InteractiveObject) IO;
1084 VwrTst_DispErase(IO,-1,4,Standard_False);
1087 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1088 VwrTst_DispErase(Ctx->SelectedInteractive(),-1,4,Standard_False);}
1089 Ctx->UpdateCurrentViewer();
1092 Handle(AIS_InteractiveObject) IO;
1094 if(GetMapOfAIS().IsBound2(name)){
1095 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1097 VwrTst_DispErase(IO,-1,4,Standard_True);
1102 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1103 if(Ctx->NbSelected()==0 && TypeOfOperation==3){
1104 Handle(AIS_InteractiveObject) IO;
1105 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1107 if(!Ctx->HasOpenedContext()){
1108 // set/unset display mode sur le Contexte...
1109 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1110 VwrTst_DispErase(Ctx->SelectedInteractive(),Dmode,TypeOfOperation,Standard_False);
1112 Ctx->UpdateCurrentViewer();
1115 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1116 Ctx->Display(Ctx->SelectedInteractive(),Dmode);
1120 Handle(AIS_InteractiveObject) IO;
1122 if(GetMapOfAIS().IsBound2(name))
1123 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1125 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1131 //=======================================================================
1134 //=======================================================================
1135 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1137 if(argc==1) return 1;
1138 Standard_Integer On = Draw::Atoi(argv[1]);
1139 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1143 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1144 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1145 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1149 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1153 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1157 Ctx->UpdateCurrentViewer();
1160 Handle(AIS_InteractiveObject) IO;
1161 TCollection_AsciiString name = argv[2];
1162 if(GetMapOfAIS().IsBound2(name)){
1163 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1166 Ctx->SubIntensityOn(IO);
1168 Ctx->SubIntensityOff(IO);
1176 //! Auxiliary class to iterate presentations from different collections.
1177 class ViewTest_PrsIter
1181 //! Create and initialize iterator object.
1182 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1183 : mySource (IterSource_All)
1185 NCollection_Sequence<TCollection_AsciiString> aNames;
1186 if (!theName.IsEmpty())
1187 aNames.Append (theName);
1191 //! Create and initialize iterator object.
1192 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1193 : mySource (IterSource_All)
1198 //! Initialize the iterator.
1199 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1201 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1203 mySelIter.Nullify();
1204 myCurrent.Nullify();
1205 myCurrentTrs.Nullify();
1206 if (!mySeq.IsEmpty())
1208 mySource = IterSource_List;
1209 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1211 else if (aCtx->NbSelected() > 0)
1213 mySource = IterSource_Selected;
1215 mySelIter->InitSelected();
1219 mySource = IterSource_All;
1220 myMapIter.Initialize (GetMapOfAIS());
1225 const TCollection_AsciiString& CurrentName() const
1227 return myCurrentName;
1230 const Handle(AIS_InteractiveObject)& Current() const
1235 const Handle(Standard_Transient)& CurrentTrs() const
1237 return myCurrentTrs;
1240 //! @return true if iterator points to valid object within collection
1241 Standard_Boolean More() const
1245 case IterSource_All: return myMapIter.More();
1246 case IterSource_List: return mySeqIter.More();
1247 case IterSource_Selected: return mySelIter->MoreSelected();
1249 return Standard_False;
1252 //! Go to the next item.
1255 myCurrentName.Clear();
1256 myCurrentTrs.Nullify();
1257 myCurrent.Nullify();
1260 case IterSource_All:
1265 case IterSource_List:
1270 case IterSource_Selected:
1272 mySelIter->NextSelected();
1285 case IterSource_All:
1287 if (myMapIter.More())
1289 myCurrentName = myMapIter.Key2();
1290 myCurrentTrs = myMapIter.Key1();
1291 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1295 case IterSource_List:
1297 if (mySeqIter.More())
1299 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1301 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1304 myCurrentName = mySeqIter.Value();
1305 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1306 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1310 case IterSource_Selected:
1312 if (mySelIter->MoreSelected())
1314 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1315 myCurrent = mySelIter->SelectedInteractive();
1333 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1334 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1335 NCollection_Sequence<TCollection_AsciiString> mySeq;
1336 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1338 TCollection_AsciiString myCurrentName;//!< current item name
1339 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1340 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1342 IterSource mySource; //!< iterated collection
1346 //==============================================================================
1347 //function : VInteriorStyle
1348 //purpose : sets interior style of the a selected or named or displayed shape
1349 //==============================================================================
1350 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1351 Standard_Integer theArgNb,
1352 const char** theArgVec)
1354 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1355 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1358 std::cerr << "Error: no active view!\n";
1362 Standard_Integer anArgIter = 1;
1363 for (; anArgIter < theArgNb; ++anArgIter)
1365 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1370 TCollection_AsciiString aName;
1371 if (theArgNb - anArgIter == 2)
1373 aName = theArgVec[anArgIter++];
1375 else if (theArgNb - anArgIter != 1)
1377 std::cout << "Error: wrong number of arguments! See usage:\n";
1378 theDI.PrintHelp (theArgVec[0]);
1381 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1382 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1383 aStyleArg.LowerCase();
1384 if (aStyleArg == "empty")
1388 else if (aStyleArg == "hollow")
1392 else if (aStyleArg == "hatch")
1396 else if (aStyleArg == "solid")
1400 else if (aStyleArg == "hiddenline")
1406 anInterStyle = aStyleArg.IntegerValue();
1408 if (anInterStyle < Aspect_IS_EMPTY
1409 || anInterStyle > Aspect_IS_HIDDENLINE)
1411 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1412 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1416 if (!aName.IsEmpty()
1417 && !GetMapOfAIS().IsBound2 (aName))
1419 std::cout << "Error: object " << aName << " is not displayed!\n";
1423 if (aCtx->HasOpenedContext())
1425 aCtx->CloseLocalContext();
1427 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1429 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1432 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1433 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1434 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1435 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1436 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1442 //! Auxiliary structure for VAspects
1443 struct ViewerTest_AspectsChangeSet
1445 Standard_Integer ToSetVisibility;
1446 Standard_Integer Visibility;
1448 Standard_Integer ToSetColor;
1449 Quantity_Color Color;
1451 Standard_Integer ToSetLineWidth;
1452 Standard_Real LineWidth;
1454 Standard_Integer ToSetTypeOfLine;
1455 Aspect_TypeOfLine TypeOfLine;
1457 Standard_Integer ToSetTransparency;
1458 Standard_Real Transparency;
1460 Standard_Integer ToSetMaterial;
1461 Graphic3d_NameOfMaterial Material;
1462 TCollection_AsciiString MatName;
1464 NCollection_Sequence<TopoDS_Shape> SubShapes;
1466 Standard_Integer ToSetShowFreeBoundary;
1467 Standard_Integer ToSetFreeBoundaryWidth;
1468 Standard_Real FreeBoundaryWidth;
1469 Standard_Integer ToSetFreeBoundaryColor;
1470 Quantity_Color FreeBoundaryColor;
1472 Standard_Integer ToEnableIsoOnTriangulation;
1474 Standard_Integer ToSetMaxParamValue;
1475 Standard_Real MaxParamValue;
1477 //! Empty constructor
1478 ViewerTest_AspectsChangeSet()
1479 : ToSetVisibility (0),
1482 Color (DEFAULT_COLOR),
1485 ToSetTypeOfLine (0),
1486 TypeOfLine (Aspect_TOL_SOLID),
1487 ToSetTransparency (0),
1490 Material (Graphic3d_NOM_DEFAULT),
1491 ToSetShowFreeBoundary (0),
1492 ToSetFreeBoundaryWidth (0),
1493 FreeBoundaryWidth (1.0),
1494 ToSetFreeBoundaryColor (0),
1495 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1496 ToEnableIsoOnTriangulation (-1),
1497 ToSetMaxParamValue (0),
1498 MaxParamValue (500000) {}
1500 //! @return true if no changes have been requested
1501 Standard_Boolean IsEmpty() const
1503 return ToSetVisibility == 0
1504 && ToSetLineWidth == 0
1505 && ToSetTransparency == 0
1507 && ToSetMaterial == 0
1508 && ToSetShowFreeBoundary == 0
1509 && ToSetFreeBoundaryColor == 0
1510 && ToSetFreeBoundaryWidth == 0
1511 && ToSetMaxParamValue == 0;
1514 //! @return true if properties are valid
1515 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1517 Standard_Boolean isOk = Standard_True;
1518 if (Visibility != 0 && Visibility != 1)
1520 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1521 isOk = Standard_False;
1523 if (LineWidth <= 0.0
1524 || LineWidth > 10.0)
1526 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1527 isOk = Standard_False;
1529 if (Transparency < 0.0
1530 || Transparency > 1.0)
1532 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1533 isOk = Standard_False;
1536 && ToSetTransparency)
1538 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1539 isOk = Standard_False;
1541 if (ToSetMaterial == 1
1542 && Material == Graphic3d_NOM_DEFAULT)
1544 std::cout << "Error: unknown material " << MatName << ".\n";
1545 isOk = Standard_False;
1547 if (FreeBoundaryWidth <= 0.0
1548 || FreeBoundaryWidth > 10.0)
1550 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1551 isOk = Standard_False;
1553 if (MaxParamValue < 0.0)
1555 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1556 isOk = Standard_False;
1563 //==============================================================================
1564 //function : VAspects
1566 //==============================================================================
1567 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1568 Standard_Integer theArgNb,
1569 const char** theArgVec)
1571 TCollection_AsciiString aCmdName (theArgVec[0]);
1572 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1573 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1576 std::cerr << "Error: no active view!\n";
1580 Standard_Integer anArgIter = 1;
1581 Standard_Boolean isDefaults = Standard_False;
1582 NCollection_Sequence<TCollection_AsciiString> aNames;
1583 for (; anArgIter < theArgNb; ++anArgIter)
1585 TCollection_AsciiString anArg = theArgVec[anArgIter];
1586 if (anUpdateTool.parseRedrawMode (anArg))
1590 else if (!anArg.IsEmpty()
1591 && anArg.Value (1) != '-')
1593 aNames.Append (anArg);
1597 if (anArg == "-defaults")
1599 isDefaults = Standard_True;
1606 if (!aNames.IsEmpty() && isDefaults)
1608 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1612 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1613 aChanges.Append (ViewerTest_AspectsChangeSet());
1614 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1616 // parse syntax of legacy commands
1617 if (aCmdName == "vsetwidth")
1619 if (aNames.IsEmpty()
1620 || !aNames.Last().IsRealValue())
1622 std::cout << "Error: not enough arguments!\n";
1625 aChangeSet->ToSetLineWidth = 1;
1626 aChangeSet->LineWidth = aNames.Last().RealValue();
1627 aNames.Remove (aNames.Length());
1629 else if (aCmdName == "vunsetwidth")
1631 aChangeSet->ToSetLineWidth = -1;
1633 else if (aCmdName == "vsetcolor")
1635 if (aNames.IsEmpty())
1637 std::cout << "Error: not enough arguments!\n";
1640 aChangeSet->ToSetColor = 1;
1642 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1643 Standard_Boolean isOk = Standard_False;
1644 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1646 aChangeSet->Color = aColor;
1647 aNames.Remove (aNames.Length());
1648 isOk = Standard_True;
1650 else if (aNames.Length() >= 3)
1652 const TCollection_AsciiString anRgbStr[3] =
1654 aNames.Value (aNames.Upper() - 2),
1655 aNames.Value (aNames.Upper() - 1),
1656 aNames.Value (aNames.Upper() - 0)
1658 isOk = anRgbStr[0].IsRealValue()
1659 && anRgbStr[1].IsRealValue()
1660 && anRgbStr[2].IsRealValue();
1663 Graphic3d_Vec4d anRgb;
1664 anRgb.x() = anRgbStr[0].RealValue();
1665 anRgb.y() = anRgbStr[1].RealValue();
1666 anRgb.z() = anRgbStr[2].RealValue();
1667 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1668 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1669 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1671 std::cout << "Error: RGB color values should be within range 0..1!\n";
1674 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1675 aNames.Remove (aNames.Length());
1676 aNames.Remove (aNames.Length());
1677 aNames.Remove (aNames.Length());
1682 std::cout << "Error: not enough arguments!\n";
1686 else if (aCmdName == "vunsetcolor")
1688 aChangeSet->ToSetColor = -1;
1690 else if (aCmdName == "vsettransparency")
1692 if (aNames.IsEmpty()
1693 || !aNames.Last().IsRealValue())
1695 std::cout << "Error: not enough arguments!\n";
1698 aChangeSet->ToSetTransparency = 1;
1699 aChangeSet->Transparency = aNames.Last().RealValue();
1700 aNames.Remove (aNames.Length());
1702 else if (aCmdName == "vunsettransparency")
1704 aChangeSet->ToSetTransparency = -1;
1706 else if (aCmdName == "vsetmaterial")
1708 if (aNames.IsEmpty())
1710 std::cout << "Error: not enough arguments!\n";
1713 aChangeSet->ToSetMaterial = 1;
1714 aChangeSet->MatName = aNames.Last();
1715 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1716 aNames.Remove (aNames.Length());
1718 else if (aCmdName == "vunsetmaterial")
1720 aChangeSet->ToSetMaterial = -1;
1722 else if (anArgIter >= theArgNb)
1724 std::cout << "Error: not enough arguments!\n";
1728 if (!aChangeSet->IsEmpty())
1730 anArgIter = theArgNb;
1732 for (; anArgIter < theArgNb; ++anArgIter)
1734 TCollection_AsciiString anArg = theArgVec[anArgIter];
1736 if (anArg == "-setwidth"
1737 || anArg == "-setlinewidth")
1739 if (++anArgIter >= theArgNb)
1741 std::cout << "Error: wrong syntax at " << anArg << "\n";
1744 aChangeSet->ToSetLineWidth = 1;
1745 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1747 else if (anArg == "-unsetwidth"
1748 || anArg == "-unsetlinewidth")
1750 aChangeSet->ToSetLineWidth = -1;
1751 aChangeSet->LineWidth = 1.0;
1753 else if (anArg == "-settransp"
1754 || anArg == "-settransparency")
1756 if (++anArgIter >= theArgNb)
1758 std::cout << "Error: wrong syntax at " << anArg << "\n";
1761 aChangeSet->ToSetTransparency = 1;
1762 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1763 if (aChangeSet->Transparency >= 0.0
1764 && aChangeSet->Transparency <= Precision::Confusion())
1766 aChangeSet->ToSetTransparency = -1;
1767 aChangeSet->Transparency = 0.0;
1770 else if (anArg == "-setvis"
1771 || anArg == "-setvisibility")
1773 if (++anArgIter >= theArgNb)
1775 std::cout << "Error: wrong syntax at " << anArg << "\n";
1779 aChangeSet->ToSetVisibility = 1;
1780 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1782 else if (anArg == "-setalpha")
1784 if (++anArgIter >= theArgNb)
1786 std::cout << "Error: wrong syntax at " << anArg << "\n";
1789 aChangeSet->ToSetTransparency = 1;
1790 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1791 if (aChangeSet->Transparency < 0.0
1792 || aChangeSet->Transparency > 1.0)
1794 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1797 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1798 if (aChangeSet->Transparency >= 0.0
1799 && aChangeSet->Transparency <= Precision::Confusion())
1801 aChangeSet->ToSetTransparency = -1;
1802 aChangeSet->Transparency = 0.0;
1805 else if (anArg == "-unsettransp"
1806 || anArg == "-unsettransparency"
1807 || anArg == "-unsetalpha"
1808 || anArg == "-opaque")
1810 aChangeSet->ToSetTransparency = -1;
1811 aChangeSet->Transparency = 0.0;
1813 else if (anArg == "-setcolor")
1815 Standard_Integer aNbComps = 0;
1816 Standard_Integer aCompIter = anArgIter + 1;
1817 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1819 if (theArgVec[aCompIter][0] == '-')
1828 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1829 Standard_CString aName = theArgVec[anArgIter + 1];
1830 if (!Quantity_Color::ColorFromName (aName, aColor))
1832 std::cout << "Error: unknown color name '" << aName << "'\n";
1835 aChangeSet->Color = aColor;
1840 Graphic3d_Vec3d anRgb;
1841 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1842 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1843 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1844 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1845 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1846 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1848 std::cout << "Error: RGB color values should be within range 0..1!\n";
1851 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1856 std::cout << "Error: wrong syntax at " << anArg << "\n";
1860 aChangeSet->ToSetColor = 1;
1861 anArgIter += aNbComps;
1863 else if (anArg == "-setlinetype")
1865 if (++anArgIter >= theArgNb)
1867 std::cout << "Error: wrong syntax at " << anArg << "\n";
1871 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1874 if (aValue.IsEqual ("solid"))
1876 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1878 else if (aValue.IsEqual ("dot"))
1880 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1882 else if (aValue.IsEqual ("dash"))
1884 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1886 else if (aValue.IsEqual ("dotdash"))
1888 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1892 std::cout << "Error: wrong syntax at " << anArg << "\n";
1896 aChangeSet->ToSetTypeOfLine = 1;
1898 else if (anArg == "-unsetlinetype")
1900 aChangeSet->ToSetTypeOfLine = -1;
1902 else if (anArg == "-unsetcolor")
1904 aChangeSet->ToSetColor = -1;
1905 aChangeSet->Color = DEFAULT_COLOR;
1907 else if (anArg == "-setmat"
1908 || anArg == "-setmaterial")
1910 if (++anArgIter >= theArgNb)
1912 std::cout << "Error: wrong syntax at " << anArg << "\n";
1915 aChangeSet->ToSetMaterial = 1;
1916 aChangeSet->MatName = theArgVec[anArgIter];
1917 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1919 else if (anArg == "-unsetmat"
1920 || anArg == "-unsetmaterial")
1922 aChangeSet->ToSetMaterial = -1;
1923 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1925 else if (anArg == "-subshape"
1926 || anArg == "-subshapes")
1930 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1934 if (aNames.IsEmpty())
1936 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1940 aChanges.Append (ViewerTest_AspectsChangeSet());
1941 aChangeSet = &aChanges.ChangeLast();
1943 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1945 Standard_CString aSubShapeName = theArgVec[anArgIter];
1946 if (*aSubShapeName == '-')
1952 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1953 if (aSubShape.IsNull())
1955 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1958 aChangeSet->SubShapes.Append (aSubShape);
1961 if (aChangeSet->SubShapes.IsEmpty())
1963 std::cerr << "Error: empty list is specified after -subshapes!\n";
1967 else if (anArg == "-freeboundary"
1970 if (++anArgIter >= theArgNb)
1972 std::cout << "Error: wrong syntax at " << anArg << "\n";
1975 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1980 aChangeSet->ToSetShowFreeBoundary = 1;
1982 else if (aValue == "off"
1985 aChangeSet->ToSetShowFreeBoundary = -1;
1989 std::cout << "Error: wrong syntax at " << anArg << "\n";
1993 else if (anArg == "-setfreeboundarywidth"
1994 || anArg == "-setfbwidth")
1996 if (++anArgIter >= theArgNb)
1998 std::cout << "Error: wrong syntax at " << anArg << "\n";
2001 aChangeSet->ToSetFreeBoundaryWidth = 1;
2002 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2004 else if (anArg == "-unsetfreeboundarywidth"
2005 || anArg == "-unsetfbwidth")
2007 aChangeSet->ToSetFreeBoundaryWidth = -1;
2008 aChangeSet->FreeBoundaryWidth = 1.0;
2010 else if (anArg == "-setfreeboundarycolor"
2011 || anArg == "-setfbcolor")
2013 Standard_Integer aNbComps = 0;
2014 Standard_Integer aCompIter = anArgIter + 1;
2015 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2017 if (theArgVec[aCompIter][0] == '-')
2026 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2027 Standard_CString aName = theArgVec[anArgIter + 1];
2028 if (!Quantity_Color::ColorFromName (aName, aColor))
2030 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2033 aChangeSet->FreeBoundaryColor = aColor;
2038 Graphic3d_Vec3d anRgb;
2039 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2040 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2041 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2042 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2043 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2044 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2046 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2049 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2054 std::cout << "Error: wrong syntax at " << anArg << "\n";
2058 aChangeSet->ToSetFreeBoundaryColor = 1;
2059 anArgIter += aNbComps;
2061 else if (anArg == "-unsetfreeboundarycolor"
2062 || anArg == "-unsetfbcolor")
2064 aChangeSet->ToSetFreeBoundaryColor = -1;
2065 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2067 else if (anArg == "-unset")
2069 aChangeSet->ToSetVisibility = 1;
2070 aChangeSet->Visibility = 1;
2071 aChangeSet->ToSetLineWidth = -1;
2072 aChangeSet->LineWidth = 1.0;
2073 aChangeSet->ToSetTypeOfLine = -1;
2074 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2075 aChangeSet->ToSetTransparency = -1;
2076 aChangeSet->Transparency = 0.0;
2077 aChangeSet->ToSetColor = -1;
2078 aChangeSet->Color = DEFAULT_COLOR;
2079 aChangeSet->ToSetMaterial = -1;
2080 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2081 aChangeSet->ToSetShowFreeBoundary = -1;
2082 aChangeSet->ToSetFreeBoundaryColor = -1;
2083 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2084 aChangeSet->ToSetFreeBoundaryWidth = -1;
2085 aChangeSet->FreeBoundaryWidth = 1.0;
2087 else if (anArg == "-isoontriangulation"
2088 || anArg == "-isoontriang")
2090 if (++anArgIter >= theArgNb)
2092 std::cout << "Error: wrong syntax at " << anArg << "\n";
2095 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2100 aChangeSet->ToEnableIsoOnTriangulation = 1;
2102 else if (aValue == "off"
2105 aChangeSet->ToEnableIsoOnTriangulation = 0;
2109 std::cout << "Error: wrong syntax at " << anArg << "\n";
2113 else if (anArg == "-setmaxparamvalue")
2115 if (++anArgIter >= theArgNb)
2117 std::cout << "Error: wrong syntax at " << anArg << "\n";
2120 aChangeSet->ToSetMaxParamValue = 1;
2121 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2125 std::cout << "Error: wrong syntax at " << anArg << "\n";
2130 Standard_Boolean isFirst = Standard_True;
2131 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2132 aChangesIter.More(); aChangesIter.Next())
2134 if (!aChangesIter.Value().Validate (!isFirst))
2138 isFirst = Standard_False;
2141 if (aCtx->HasOpenedContext())
2143 aCtx->CloseLocalContext();
2146 // special case for -defaults parameter.
2147 // all changed values will be set to DefaultDrawer.
2150 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2152 if (aChangeSet->ToSetLineWidth != 0)
2154 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2155 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2156 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2157 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2159 if (aChangeSet->ToSetColor != 0)
2161 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2162 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2163 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2164 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2165 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2166 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2168 if (aChangeSet->ToSetTypeOfLine != 0)
2170 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2171 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2172 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2173 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2174 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2176 if (aChangeSet->ToSetTransparency != 0)
2178 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2180 if (aChangeSet->ToSetMaterial != 0)
2182 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2184 if (aChangeSet->ToSetShowFreeBoundary == 1)
2186 aDrawer->SetFreeBoundaryDraw (Standard_True);
2188 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2190 aDrawer->SetFreeBoundaryDraw (Standard_False);
2192 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2194 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2196 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2198 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2200 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2202 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2204 if (aChangeSet->ToSetMaxParamValue != 0)
2206 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2209 // redisplay all objects in context
2210 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2212 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2215 aCtx->Redisplay (aPrs, Standard_False);
2221 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2223 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2224 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2225 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2226 Handle(AIS_ColoredShape) aColoredPrs;
2227 Standard_Boolean toDisplay = Standard_False;
2228 Standard_Boolean toRedisplay = Standard_False;
2229 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2231 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2232 if (aShapePrs.IsNull())
2234 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2237 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2238 if (aColoredPrs.IsNull())
2240 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2241 aCtx->Remove (aShapePrs, Standard_False);
2242 GetMapOfAIS().UnBind2 (aName);
2243 GetMapOfAIS().Bind (aColoredPrs, aName);
2244 toDisplay = Standard_True;
2245 aShapePrs = aColoredPrs;
2252 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2253 aChangeSet = &aChangesIter.ChangeValue();
2254 if (aChangeSet->ToSetVisibility == 1)
2256 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2257 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2259 else if (aChangeSet->ToSetMaterial == 1)
2261 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2263 else if (aChangeSet->ToSetMaterial == -1)
2265 aCtx->UnsetMaterial (aPrs, Standard_False);
2267 if (aChangeSet->ToSetColor == 1)
2269 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2271 else if (aChangeSet->ToSetColor == -1)
2273 aCtx->UnsetColor (aPrs, Standard_False);
2275 if (aChangeSet->ToSetTransparency == 1)
2277 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2279 else if (aChangeSet->ToSetTransparency == -1)
2281 aCtx->UnsetTransparency (aPrs, Standard_False);
2283 if (aChangeSet->ToSetLineWidth == 1)
2285 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2287 else if (aChangeSet->ToSetLineWidth == -1)
2289 aCtx->UnsetWidth (aPrs, Standard_False);
2291 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2293 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2294 toRedisplay = Standard_True;
2296 if (!aDrawer.IsNull())
2298 if (aChangeSet->ToSetShowFreeBoundary == 1)
2300 aDrawer->SetFreeBoundaryDraw (Standard_True);
2301 toRedisplay = Standard_True;
2303 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2305 aDrawer->SetFreeBoundaryDraw (Standard_False);
2306 toRedisplay = Standard_True;
2308 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2310 Handle(Prs3d_LineAspect) aBoundaryAspect =
2311 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2312 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2313 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2314 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2315 toRedisplay = Standard_True;
2317 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2319 Handle(Prs3d_LineAspect) aBoundaryAspect =
2320 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2321 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2322 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2323 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2324 toRedisplay = Standard_True;
2326 if (aChangeSet->ToSetTypeOfLine != 0)
2328 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2329 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2330 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2331 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2332 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2333 toRedisplay = Standard_True;
2335 if (aChangeSet->ToSetMaxParamValue != 0)
2337 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2341 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2343 aChangeSet = &aChangesIter.ChangeValue();
2344 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2345 aSubShapeIter.More(); aSubShapeIter.Next())
2347 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2348 if (aChangeSet->ToSetVisibility == 1)
2350 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2351 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2353 if (aChangeSet->ToSetColor == 1)
2355 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2357 if (aChangeSet->ToSetLineWidth == 1)
2359 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2361 if (aChangeSet->ToSetColor == -1
2362 || aChangeSet->ToSetLineWidth == -1)
2364 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2366 if (aChangeSet->ToSetMaxParamValue != 0)
2368 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2369 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2375 aCtx->Display (aPrs, Standard_False);
2379 aCtx->Redisplay (aPrs, Standard_False);
2381 else if (!aColoredPrs.IsNull())
2383 aCtx->Redisplay (aColoredPrs, Standard_False);
2390 //==============================================================================
2391 //function : VDonly2
2393 //purpose : Display only a selected or named object
2394 // if there is no selected or named object s, nothing is done
2395 //==============================================================================
2396 static int VDonly2 (Draw_Interpretor& ,
2397 Standard_Integer theArgNb,
2398 const char** theArgVec)
2400 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2401 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2404 std::cerr << "Error: no active view!\n";
2408 if (aCtx->HasOpenedContext())
2410 aCtx->CloseLocalContext();
2413 Standard_Integer anArgIter = 1;
2414 for (; anArgIter < theArgNb; ++anArgIter)
2416 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2422 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2423 if (anArgIter >= theArgNb)
2425 // display only selected objects
2426 if (aCtx->NbSelected() < 1)
2431 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2433 aDispSet.Add (aCtx->SelectedInteractive());
2438 // display only specified objects
2439 for (; anArgIter < theArgNb; ++anArgIter)
2441 TCollection_AsciiString aName = theArgVec[anArgIter];
2442 if (GetMapOfAIS().IsBound2 (aName))
2444 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2445 if (!aShape.IsNull())
2447 aCtx->Display (aShape, Standard_False);
2448 aDispSet.Add (aShape);
2454 // weed out other objects
2455 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2457 if (aDispSet.Contains (anIter.Key1()))
2462 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2463 if (aShape.IsNull())
2465 aCtx->Erase (aShape, Standard_False);
2471 //==============================================================================
2472 //function : VRemove
2473 //purpose : Removes selected or named objects.
2474 // If there is no selected or named objects,
2475 // all objects in the viewer can be removed with argument -all.
2476 // If -context is in arguments, the object is not deleted from the map of
2477 // objects (deleted only from the current context).
2478 //==============================================================================
2479 int VRemove (Draw_Interpretor& theDI,
2480 Standard_Integer theArgNb,
2481 const char** theArgVec)
2483 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2484 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2487 std::cerr << "Error: no active view!\n";
2491 Standard_Boolean isContextOnly = Standard_False;
2492 Standard_Boolean toRemoveAll = Standard_False;
2493 Standard_Boolean toPrintInfo = Standard_True;
2494 Standard_Boolean toRemoveLocal = Standard_False;
2496 Standard_Integer anArgIter = 1;
2497 for (; anArgIter < theArgNb; ++anArgIter)
2499 TCollection_AsciiString anArg = theArgVec[anArgIter];
2501 if (anArg == "-context")
2503 isContextOnly = Standard_True;
2505 else if (anArg == "-all")
2507 toRemoveAll = Standard_True;
2509 else if (anArg == "-noinfo")
2511 toPrintInfo = Standard_False;
2513 else if (anArg == "-local")
2515 toRemoveLocal = Standard_True;
2517 else if (anUpdateTool.parseRedrawMode (anArg))
2527 && anArgIter < theArgNb)
2529 std::cerr << "Error: wrong syntax!\n";
2533 if (toRemoveLocal && !aCtx->HasOpenedContext())
2535 std::cerr << "Error: local selection context is not open.\n";
2538 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2540 aCtx->CloseAllContexts (Standard_False);
2543 NCollection_List<TCollection_AsciiString> anIONameList;
2546 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2547 anIter.More(); anIter.Next())
2549 anIONameList.Append (anIter.Key2());
2552 else if (anArgIter < theArgNb) // removed objects names are in argument list
2554 for (; anArgIter < theArgNb; ++anArgIter)
2556 TCollection_AsciiString aName = theArgVec[anArgIter];
2557 if (!GetMapOfAIS().IsBound2 (aName))
2559 theDI << aName.ToCString() << " was not bound to some object.\n";
2563 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2564 if (anIO->GetContext() != aCtx)
2566 theDI << aName.ToCString() << " was not displayed in current context.\n";
2567 theDI << "Please activate view with this object displayed and try again.\n";
2571 anIONameList.Append (aName);
2575 else if (aCtx->NbSelected() > 0)
2577 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2578 anIter.More(); anIter.Next())
2580 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2581 if (!aCtx->IsSelected (anIO))
2586 anIONameList.Append (anIter.Key2());
2591 // Unbind all removed objects from the map of displayed IO.
2592 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2593 anIter.More(); anIter.Next())
2595 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2596 aCtx->Remove (anIO, Standard_False);
2599 theDI << anIter.Value().ToCString() << " was removed\n";
2603 GetMapOfAIS().UnBind2 (anIter.Value());
2607 // Close local context if it is empty
2608 TColStd_MapOfTransient aLocalIO;
2609 if (aCtx->HasOpenedContext()
2610 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2612 aCtx->CloseAllContexts (Standard_False);
2618 //==============================================================================
2620 //purpose : Erase some selected or named objects
2621 // if there is no selected or named objects, the whole viewer is erased
2622 //==============================================================================
2623 int VErase (Draw_Interpretor& theDI,
2624 Standard_Integer theArgNb,
2625 const char** theArgVec)
2627 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2628 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2629 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2632 std::cerr << "Error: no active view!\n";
2636 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2638 Standard_Integer anArgIter = 1;
2639 Standard_Boolean toEraseLocal = Standard_False;
2640 Standard_Boolean toEraseInView = Standard_False;
2641 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2642 for (; anArgIter < theArgNb; ++anArgIter)
2644 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2645 anArgCase.LowerCase();
2646 if (anUpdateTool.parseRedrawMode (anArgCase))
2650 else if (anArgCase == "-local")
2652 toEraseLocal = Standard_True;
2654 else if (anArgCase == "-view"
2655 || anArgCase == "-inview")
2657 toEraseInView = Standard_True;
2661 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2665 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2667 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2671 if (toEraseLocal && !aCtx->HasOpenedContext())
2673 std::cerr << "Error: local selection context is not open.\n";
2676 else if (!toEraseLocal && aCtx->HasOpenedContext())
2678 aCtx->CloseAllContexts (Standard_False);
2681 if (!aNamesOfEraseIO.IsEmpty())
2683 // Erase named objects
2684 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2686 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2687 if (!GetMapOfAIS().IsBound2 (aName))
2692 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2693 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2694 theDI << aName.ToCString() << " ";
2699 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2703 aCtx->Erase (anIO, Standard_False);
2708 else if (!toEraseAll && aCtx->NbSelected() > 0)
2710 // Erase selected objects
2711 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2712 anIter.More(); anIter.Next())
2714 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2716 && aCtx->IsSelected (anIO))
2718 theDI << anIter.Key2().ToCString() << " ";
2721 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2725 aCtx->Erase (anIO, Standard_False);
2732 // Erase all objects
2733 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2734 anIter.More(); anIter.Next())
2736 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2741 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2745 aCtx->Erase (anIO, Standard_False);
2754 //==============================================================================
2755 //function : VDisplayAll
2757 //purpose : Display all the objects of the Map
2758 //==============================================================================
2759 static int VDisplayAll (Draw_Interpretor& ,
2760 Standard_Integer theArgNb,
2761 const char** theArgVec)
2764 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2765 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2768 std::cerr << "Error: no active view!\n";
2772 Standard_Integer anArgIter = 1;
2773 Standard_Boolean toDisplayLocal = Standard_False;
2774 for (; anArgIter < theArgNb; ++anArgIter)
2776 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2777 anArgCase.LowerCase();
2778 if (anArgCase == "-local")
2780 toDisplayLocal = Standard_True;
2782 else if (anUpdateTool.parseRedrawMode (anArgCase))
2791 if (anArgIter < theArgNb)
2793 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2797 if (toDisplayLocal && !aCtx->HasOpenedContext())
2799 std::cerr << "Error: local selection context is not open.\n";
2802 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2804 aCtx->CloseLocalContext (Standard_False);
2807 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2808 anIter.More(); anIter.Next())
2810 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2811 aCtx->Erase (aShape, Standard_False);
2814 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2815 anIter.More(); anIter.Next())
2817 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2818 aCtx->Display (aShape, Standard_False);
2823 //! Auxiliary method to find presentation
2824 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2825 const Handle(AIS_InteractiveObject)& theIO,
2826 const Standard_Integer theMode)
2830 return Handle(PrsMgr_Presentation)();
2835 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2837 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2840 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2842 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2844 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2846 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2848 return Handle(PrsMgr_Presentation)();
2851 enum ViewerTest_BndAction
2858 //! Auxiliary method to print bounding box of presentation
2859 inline void bndPresentation (Draw_Interpretor& theDI,
2860 const Handle(PrsMgr_Presentation)& thePrs,
2861 const TCollection_AsciiString& theName,
2862 const ViewerTest_BndAction theAction)
2866 case BndAction_Hide:
2868 thePrs->Presentation()->GraphicUnHighlight();
2871 case BndAction_Show:
2873 Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
2874 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2875 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2876 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2877 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
2880 case BndAction_Print:
2882 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2883 gp_Pnt aMin = aBox.CornerMin();
2884 gp_Pnt aMax = aBox.CornerMax();
2885 theDI << theName << "\n"
2886 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2887 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2893 //==============================================================================
2894 //function : VBounding
2896 //==============================================================================
2897 int VBounding (Draw_Interpretor& theDI,
2898 Standard_Integer theArgNb,
2899 const char** theArgVec)
2901 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2902 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2905 std::cout << "Error: no active view!\n";
2909 ViewerTest_BndAction anAction = BndAction_Show;
2910 Standard_Integer aMode = -1;
2912 Standard_Integer anArgIter = 1;
2913 for (; anArgIter < theArgNb; ++anArgIter)
2915 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2917 if (anArg == "-print")
2919 anAction = BndAction_Print;
2921 else if (anArg == "-show")
2923 anAction = BndAction_Show;
2925 else if (anArg == "-hide")
2927 anAction = BndAction_Hide;
2929 else if (anArg == "-mode")
2931 if (++anArgIter >= theArgNb)
2933 std::cout << "Error: wrong syntax at " << anArg << "\n";
2936 aMode = Draw::Atoi (theArgVec[anArgIter]);
2938 else if (!anUpdateTool.parseRedrawMode (anArg))
2944 if (anArgIter < theArgNb)
2946 // has a list of names
2947 for (; anArgIter < theArgNb; ++anArgIter)
2949 TCollection_AsciiString aName = theArgVec[anArgIter];
2950 if (!GetMapOfAIS().IsBound2 (aName))
2952 std::cout << "Error: presentation " << aName << " does not exist\n";
2956 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2957 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2960 std::cout << "Error: presentation " << aName << " does not exist\n";
2963 bndPresentation (theDI, aPrs, aName, anAction);
2966 else if (aCtx->NbSelected() > 0)
2968 // remove all currently selected objects
2969 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2971 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
2972 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2975 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2982 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2983 anIter.More(); anIter.Next())
2985 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2986 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2989 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2996 //==============================================================================
2997 //function : VTexture
2999 //==============================================================================
3000 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
3002 TCollection_AsciiString aCommandName (theArgv[0]);
3004 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3005 if (aCommandName == "vtexture")
3009 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
3010 std::cout << "Type help for more information.\n";
3014 // look for options of vtexture command
3015 TCollection_AsciiString aParseKey;
3016 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3018 TCollection_AsciiString anArg (theArgv [anArgIt]);
3021 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3024 aParseKey.Remove (1);
3025 aParseKey.UpperCase();
3026 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3030 if (aParseKey.IsEmpty())
3035 aMapOfArgs(aParseKey)->Append (anArg);
3038 else if (aCommandName == "vtexscale"
3039 || aCommandName == "vtexorigin"
3040 || aCommandName == "vtexrepeat")
3042 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3043 // equal to -scale, -origin, -repeat options of vtexture command
3044 if (theArgsNb < 2 || theArgsNb > 4)
3046 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
3047 std::cout << "Type help for more information.\n";
3051 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
3054 anArgs->Append ("OFF");
3056 else if (theArgsNb == 4)
3058 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3059 anArgs->Append (TCollection_AsciiString (theArgv[3]));
3062 TCollection_AsciiString anArgKey;
3063 if (aCommandName == "vtexscale")
3067 else if (aCommandName == "vtexorigin")
3069 anArgKey = "ORIGIN";
3073 anArgKey = "REPEAT";
3076 aMapOfArgs.Bind (anArgKey, anArgs);
3078 else if (aCommandName == "vtexdefault")
3080 // scan for parameters of vtexdefault command
3081 // equal to -default option of vtexture command
3082 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
3085 // Check arguments for validity
3086 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3087 for (; aMapIt.More(); aMapIt.Next())
3089 const TCollection_AsciiString& aKey = aMapIt.Key();
3090 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3092 // -scale, -origin, -repeat: one argument "off", or two real values
3093 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3094 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3095 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3100 // -modulate: single argument "on" / "off"
3101 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3106 // -default: no arguments
3107 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3112 TCollection_AsciiString aLowerKey;
3115 aLowerKey.LowerCase();
3116 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3117 std::cout << "Type help for more information.\n";
3121 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3122 if (anAISContext.IsNull())
3124 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
3128 Standard_Integer aPreviousMode = 0;
3130 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
3132 TCollection_AsciiString aShapeName (theArgv[1]);
3133 Handle(AIS_InteractiveObject) anIO;
3135 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3136 if (aMapOfIO.IsBound2 (aShapeName))
3138 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3143 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3147 Handle(AIS_TexturedShape) aTexturedIO;
3148 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3150 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3151 aPreviousMode = aTexturedIO->DisplayMode();
3155 anAISContext->Remove (anIO, Standard_False);
3156 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3157 GetMapOfAIS().UnBind1 (anIO);
3158 GetMapOfAIS().UnBind2 (aShapeName);
3159 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3162 // -------------------------------------------
3163 // Turn texturing on/off - only for vtexture
3164 // -------------------------------------------
3166 if (aCommandName == "vtexture")
3168 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3170 if (aTextureArg.IsEmpty())
3172 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
3173 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
3175 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3176 if (aPreviousMode == 3)
3178 anAISContext->RecomputePrsOnly (aTexturedIO);
3181 anAISContext->Display (aTexturedIO, Standard_True);
3184 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3186 if (aTextureArg == "?")
3188 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3190 theDi << "\n Files in current directory : \n" << "\n";
3191 theDi.Eval ("glob -nocomplain *");
3193 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3194 aCmnd += aTextureFolder;
3197 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
3198 theDi.Eval (aCmnd.ToCString());
3203 aTexturedIO->SetTextureFileName (aTextureArg);
3208 // ------------------------------------
3209 // Process other options and commands
3210 // ------------------------------------
3212 Handle(TColStd_HSequenceOfAsciiString) aValues;
3213 if (aMapOfArgs.Find ("DEFAULT", aValues))
3215 aTexturedIO->SetTextureRepeat (Standard_False);
3216 aTexturedIO->SetTextureOrigin (Standard_False);
3217 aTexturedIO->SetTextureScale (Standard_False);
3218 aTexturedIO->EnableTextureModulate();
3222 if (aMapOfArgs.Find ("SCALE", aValues))
3224 if (aValues->Value(1) != "OFF")
3226 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3230 aTexturedIO->SetTextureScale (Standard_False);
3234 if (aMapOfArgs.Find ("ORIGIN", aValues))
3236 if (aValues->Value(1) != "OFF")
3238 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3242 aTexturedIO->SetTextureOrigin (Standard_False);
3246 if (aMapOfArgs.Find ("REPEAT", aValues))
3248 if (aValues->Value(1) != "OFF")
3250 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3254 aTexturedIO->SetTextureRepeat (Standard_False);
3258 if (aMapOfArgs.Find ("MODULATE", aValues))
3260 if (aValues->Value(1) == "ON")
3262 aTexturedIO->EnableTextureModulate();
3266 aTexturedIO->DisableTextureModulate();
3271 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3273 anAISContext->RecomputePrsOnly (aTexturedIO);
3277 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3278 anAISContext->Display (aTexturedIO, Standard_True);
3279 anAISContext->Update (aTexturedIO,Standard_True);
3285 //! Auxiliary method to parse transformation persistence flags
3286 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3287 Standard_Integer& theFlags)
3289 if (theFlagString == "pan")
3291 theFlags |= Graphic3d_TMF_PanPers;
3293 else if (theFlagString == "zoom")
3295 theFlags |= Graphic3d_TMF_ZoomPers;
3297 else if (theFlagString == "rotate")
3299 theFlags |= Graphic3d_TMF_RotatePers;
3301 else if (theFlagString == "trihedron")
3303 theFlags = Graphic3d_TMF_TriedronPers;
3305 else if (theFlagString == "full")
3307 theFlags = Graphic3d_TMF_FullPers;
3309 else if (theFlagString == "none")
3311 theFlags = Graphic3d_TMF_None;
3315 return Standard_False;
3318 return Standard_True;
3321 //==============================================================================
3322 //function : VDisplay2
3324 //purpose : Display an object from its name
3325 //==============================================================================
3326 static int VDisplay2 (Draw_Interpretor& theDI,
3327 Standard_Integer theArgNb,
3328 const char** theArgVec)
3332 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3336 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3339 ViewerTest::ViewerInit();
3340 aCtx = ViewerTest::GetAISContext();
3343 // Parse input arguments
3344 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3345 Standard_Integer isMutable = -1;
3346 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3347 Standard_Boolean toDisplayLocal = Standard_False;
3348 Standard_Boolean toReDisplay = Standard_False;
3349 Standard_Integer isSelectable = -1;
3350 Standard_Integer anObjDispMode = -2;
3351 Standard_Integer anObjHighMode = -2;
3352 Standard_Boolean toSetTrsfPers = Standard_False;
3353 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3355 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3356 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3357 Standard_Integer toDisplayInView = Standard_False;
3358 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3360 const TCollection_AsciiString aName = theArgVec[anArgIter];
3361 TCollection_AsciiString aNameCase = aName;
3362 aNameCase.LowerCase();
3363 if (anUpdateTool.parseRedrawMode (aName))
3367 else if (aNameCase == "-mutable")
3371 else if (aNameCase == "-neutral")
3373 aDispStatus = AIS_DS_Displayed;
3375 else if (aNameCase == "-immediate"
3376 || aNameCase == "-top")
3378 aZLayer = Graphic3d_ZLayerId_Top;
3380 else if (aNameCase == "-topmost")
3382 aZLayer = Graphic3d_ZLayerId_Topmost;
3384 else if (aNameCase == "-osd"
3385 || aNameCase == "-toposd"
3386 || aNameCase == "-overlay")
3388 aZLayer = Graphic3d_ZLayerId_TopOSD;
3390 else if (aNameCase == "-botosd"
3391 || aNameCase == "-underlay")
3393 aZLayer = Graphic3d_ZLayerId_BotOSD;
3395 else if (aNameCase == "-select"
3396 || aNameCase == "-selectable")
3400 else if (aNameCase == "-noselect"
3401 || aNameCase == "-noselection")
3405 else if (aNameCase == "-dispmode"
3406 || aNameCase == "-displaymode")
3408 if (++anArgIter >= theArgNb)
3410 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3414 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3416 else if (aNameCase == "-highmode"
3417 || aNameCase == "-highlightmode")
3419 if (++anArgIter >= theArgNb)
3421 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3425 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3427 else if (aNameCase == "-3d")
3429 toSetTrsfPers = Standard_True;
3430 aTrsfPersFlags = Graphic3d_TMF_None;
3432 else if (aNameCase == "-2d")
3434 toSetTrsfPers = Standard_True;
3435 aTrsfPersFlags = Graphic3d_TMF_2d;
3437 else if (aNameCase == "-2dtopdown")
3439 toSetTrsfPers = Standard_True;
3440 aTrsfPersFlags = Graphic3d_TMF_2d | Graphic3d_TMF_2d_IsTopDown;
3442 else if (aNameCase == "-trsfpers"
3443 || aNameCase == "-pers")
3445 if (++anArgIter >= theArgNb)
3447 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3451 toSetTrsfPers = Standard_True;
3452 aTrsfPersFlags = Graphic3d_TMF_None;
3453 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3454 aPersFlags.LowerCase();
3455 for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
3457 if (aParserPos == -1)
3459 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3461 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3467 TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
3468 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3470 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3473 aPersFlags = anOtherFlags;
3476 else if (aNameCase == "-trsfperspos"
3477 || aNameCase == "-perspos")
3479 if (anArgIter + 2 >= theArgNb)
3481 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3485 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3486 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3487 TCollection_AsciiString aZ = "0";
3488 if (!aX.IsIntegerValue()
3489 || !aY.IsIntegerValue())
3491 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3494 if (anArgIter + 1 < theArgNb)
3496 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3497 if (aTemp.IsIntegerValue())
3503 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
3505 else if (aNameCase == "-layer")
3507 if (++anArgIter >= theArgNb)
3509 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3513 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3514 if (!aValue.IsIntegerValue())
3516 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3520 aZLayer = aValue.IntegerValue();
3522 else if (aNameCase == "-view"
3523 || aNameCase == "-inview")
3525 toDisplayInView = Standard_True;
3527 else if (aNameCase == "-local")
3529 aDispStatus = AIS_DS_Temporary;
3530 toDisplayLocal = Standard_True;
3532 else if (aNameCase == "-redisplay")
3534 toReDisplay = Standard_True;
3538 aNamesOfDisplayIO.Append (aName);
3542 if (aNamesOfDisplayIO.IsEmpty())
3544 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3548 // Prepare context for display
3549 if (toDisplayLocal && !aCtx->HasOpenedContext())
3551 aCtx->OpenLocalContext (Standard_False);
3553 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3555 aCtx->CloseAllContexts (Standard_False);
3558 // Display interactive objects
3559 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3561 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3563 if (!GetMapOfAIS().IsBound2 (aName))
3565 // create the AIS_Shape from a name
3566 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3567 if (!aShape.IsNull())
3569 if (isMutable != -1)
3571 aShape->SetMutable (isMutable == 1);
3573 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3575 aShape->SetZLayer (aZLayer);
3579 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3581 if (anObjDispMode != -2)
3583 aShape->SetDisplayMode (anObjDispMode);
3585 if (anObjHighMode != -2)
3587 aShape->SetHilightMode (anObjHighMode);
3589 if (!toDisplayLocal)
3590 GetMapOfAIS().Bind (aShape, aName);
3592 Standard_Integer aDispMode = aShape->HasDisplayMode()
3593 ? aShape->DisplayMode()
3594 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3595 ? aCtx->DisplayMode()
3597 Standard_Integer aSelMode = -1;
3598 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3600 aSelMode = aShape->GlobalSelectionMode();
3603 aCtx->Display (aShape, aDispMode, aSelMode,
3604 Standard_False, aShape->AcceptShapeDecomposition(),
3606 if (toDisplayInView)
3608 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3610 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3612 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3617 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3622 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3623 if (isMutable != -1)
3625 aShape->SetMutable (isMutable == 1);
3627 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3629 aShape->SetZLayer (aZLayer);
3633 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3635 if (anObjDispMode != -2)
3637 aShape->SetDisplayMode (anObjDispMode);
3639 if (anObjHighMode != -2)
3641 aShape->SetHilightMode (anObjHighMode);
3643 Standard_Integer aDispMode = aShape->HasDisplayMode()
3644 ? aShape->DisplayMode()
3645 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3646 ? aCtx->DisplayMode()
3648 Standard_Integer aSelMode = -1;
3649 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3651 aSelMode = aShape->GlobalSelectionMode();
3654 if (aShape->Type() == AIS_KOI_Datum)
3656 aCtx->Display (aShape, Standard_False);
3660 theDI << "Display " << aName.ToCString() << "\n";
3662 // update the Shape in the AIS_Shape
3663 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3664 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3665 if (!aShapePrs.IsNull())
3667 if (!aShapePrs->Shape().IsEqual (aNewShape))
3669 toReDisplay = Standard_True;
3671 aShapePrs->Set (aNewShape);
3675 aCtx->Redisplay (aShape, Standard_False);
3680 aCtx->Erase (aShape);
3682 aCtx->Display (aShape, aDispMode, aSelMode,
3683 Standard_False, aShape->AcceptShapeDecomposition(),
3685 if (toDisplayInView)
3687 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3695 //===============================================================================================
3696 //function : VUpdate
3698 //===============================================================================================
3699 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3701 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3702 if (aContextAIS.IsNull())
3704 std::cout << theArgVec[0] << "AIS context is not available.\n";
3710 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3714 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3716 AIS_ListOfInteractive aListOfIO;
3718 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3720 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3722 Handle(AIS_InteractiveObject) anAISObj;
3723 if (anAISMap.IsBound2 (aName))
3725 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3728 if (anAISObj.IsNull())
3730 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3734 aListOfIO.Append (anAISObj);
3737 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3738 for (; anIOIt.More(); anIOIt.Next())
3740 aContextAIS->Update (anIOIt.Value(), Standard_False);
3743 aContextAIS->UpdateCurrentViewer();
3748 //==============================================================================
3750 //purpose : Test the annimation of an object along a
3751 // predifined trajectory
3752 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3753 //==============================================================================
3755 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3758 if (TheAISContext()->HasOpenedContext())
3759 TheAISContext()->CloseLocalContext();
3761 Standard_Real Step=4*M_PI/180;
3762 Standard_Real Angle=0;
3764 Handle(AIS_InteractiveObject) aIO;
3765 if (GetMapOfAIS().IsBound2(argv[1]))
3766 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3770 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3774 if (Draw::Atoi(argv[3])==1 ) {
3775 di<<" Primitives sensibles OFF"<<"\n";
3776 TheAISContext()->Deactivate(aIO);
3779 di<<" Primitives sensibles ON"<<"\n";
3781 // Movement par transformation
3782 if(Draw::Atoi(argv[2]) ==1) {
3783 di<<" Calcul par Transformation"<<"\n";
3784 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3788 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3789 TheAISContext()->SetLocation(aShape,myTransfo);
3790 TheAISContext() ->UpdateCurrentViewer();
3795 di<<" Calcul par Locations"<<"\n";
3796 gp_Trsf myAngleTrsf;
3797 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3798 TopLoc_Location myDeltaAngle (myAngleTrsf);
3799 TopLoc_Location myTrueLoc;
3801 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3804 myTrueLoc=myTrueLoc*myDeltaAngle;
3805 TheAISContext()->SetLocation(aShape,myTrueLoc );
3806 TheAISContext() ->UpdateCurrentViewer();
3809 if (Draw::Atoi(argv[3])==1 ){
3810 // On reactive la selection des primitives sensibles
3811 TheAISContext()->Activate(aIO,0);
3813 a3DView() -> Redraw();
3815 di<<" Temps ecoule "<<"\n";
3821 //==================================================================================
3822 // Function : VAnimation
3823 //==================================================================================
3824 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3826 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
3830 Standard_Real thread = 4;
3831 Standard_Real angleA=0;
3832 Standard_Real angleB;
3834 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3837 TopoDS_Shape CrankArm;
3838 TopoDS_Shape CylinderHead;
3839 TopoDS_Shape Propeller;
3840 TopoDS_Shape EngineBlock;
3842 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3843 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3844 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3845 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3846 BRepTools::Read(CrankArm,argv[1],B);
3847 BRepTools::Read(CylinderHead,argv[2],B);
3848 BRepTools::Read(Propeller,argv[3],B);
3849 BRepTools::Read(EngineBlock,argv[4],B);
3851 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
3857 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3858 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3859 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3860 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3862 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3863 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3864 GetMapOfAIS().Bind(myAisCrankArm,"c");
3865 GetMapOfAIS().Bind(myAisPropeller,"d");
3867 myAisCylinderHead->SetMutable (Standard_True);
3868 myAisEngineBlock ->SetMutable (Standard_True);
3869 myAisCrankArm ->SetMutable (Standard_True);
3870 myAisPropeller ->SetMutable (Standard_True);
3872 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3873 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3874 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3876 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3877 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3878 TheAISContext()->Display (myAisCrankArm, Standard_False);
3879 TheAISContext()->Display (myAisPropeller, Standard_False);
3881 TheAISContext()->Deactivate(myAisCylinderHead);
3882 TheAISContext()->Deactivate(myAisEngineBlock );
3883 TheAISContext()->Deactivate(myAisCrankArm );
3884 TheAISContext()->Deactivate(myAisPropeller );
3886 // Boucle de mouvement
3887 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3889 angleA = thread*myAngle*M_PI/180;
3890 X = Sin(angleA)*3/8;
3891 angleB = atan(X / Sqrt(-X * X + 1));
3892 Standard_Real decal(25*0.6);
3895 //Build a transformation on the display
3896 gp_Trsf aPropellerTrsf;
3897 aPropellerTrsf.SetRotation(Ax1,angleA);
3898 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3900 gp_Ax3 base(gp_Pnt(3*decal*(1-Cos(angleA)),-3*decal*Sin(angleA),0),gp_Vec(0,0,1),gp_Vec(1,0,0));
3901 gp_Trsf aCrankArmTrsf;
3902 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3903 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3905 TheAISContext()->UpdateCurrentViewer();
3908 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3909 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3911 myAisCrankArm ->ResetTransformation();
3912 myAisPropeller->ResetTransformation();
3914 myAisCrankArm -> Set(myNewCrankArm );
3915 myAisPropeller -> Set(myNewPropeller);
3917 TheAISContext()->Activate(myAisCylinderHead,0);
3918 TheAISContext()->Activate(myAisEngineBlock,0 );
3919 TheAISContext()->Activate(myAisCrankArm ,0 );
3920 TheAISContext()->Activate(myAisPropeller ,0 );
3926 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3927 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3929 TheAISContext()->UpdateCurrentViewer();
3930 a3DView()->Redraw();
3939 //==============================================================================
3940 //function : VShading
3941 //purpose : Sharpen or roughten the quality of the shading
3942 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3943 //==============================================================================
3944 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3946 Standard_Real myDevCoef;
3947 Handle(AIS_InteractiveObject) TheAisIO;
3950 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3952 if (TheAISContext()->HasOpenedContext())
3953 TheAISContext()->CloseLocalContext();
3958 myDevCoef =Draw::Atof(argv[2]);
3961 TCollection_AsciiString name=argv[1];
3962 if (GetMapOfAIS().IsBound2(name ))
3963 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3964 if (TheAisIO.IsNull())
3965 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3968 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
3970 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3972 TheAISContext()->Redisplay(TheAisIO);
3975 //==============================================================================
3976 //function : HaveMode
3977 //use : VActivatedModes
3978 //==============================================================================
3979 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3981 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3983 TColStd_ListOfInteger List;
3984 TheAISContext()->ActivatedModes (TheAisIO,List);
3985 TColStd_ListIteratorOfListOfInteger it;
3986 Standard_Boolean Found=Standard_False;
3987 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3988 if (it.Value()==mode ) Found=Standard_True;
3995 //==============================================================================
3996 //function : VActivatedMode
3998 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
3999 // (edges,vertex...)qui lui est propre et le mode de selection standard.
4000 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4001 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4002 // qu'un nom et qu'un mode.
4003 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4004 //==============================================================================
4005 #include <AIS_ListIteratorOfListOfInteractive.hxx>
4007 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4010 Standard_Boolean ThereIsName = Standard_False ;
4012 if(!a3DView().IsNull()){
4014 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
4015 // verification des arguments
4017 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
4018 ThereIsName = (argc == 3);
4022 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
4024 di<<" R.A.Z de tous les modes de selecion"<<"\n";
4025 di<<" Fermeture du Context local"<<"\n";
4026 if (TheAISContext()->HasOpenedContext())
4027 TheAISContext()->CloseLocalContext();
4031 // IL n'y a aps de nom de shape passe en argument
4032 if (HaveToSet && !ThereIsName){
4033 Standard_Integer aMode=Draw::Atoi(argv [1]);
4035 const char *cmode="???";
4037 case 0: cmode = "Shape"; break;
4038 case 1: cmode = "Vertex"; break;
4039 case 2: cmode = "Edge"; break;
4040 case 3: cmode = "Wire"; break;
4041 case 4: cmode = "Face"; break;
4042 case 5: cmode = "Shell"; break;
4043 case 6: cmode = "Solid"; break;
4044 case 7: cmode = "Compound"; break;
4047 if( !TheAISContext()->HasOpenedContext() ) {
4048 // il n'y a pas de Context local d'ouvert
4049 // on en ouvre un et on charge toutes les shapes displayees
4050 // on load tous les objets displayees et on Activate les objets de la liste
4051 AIS_ListOfInteractive ListOfIO;
4052 // on sauve dans une AISListOfInteractive tous les objets currents
4053 if (TheAISContext()->NbSelected()>0 ){
4054 TheAISContext()->UnhilightSelected(Standard_False);
4056 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4057 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
4061 TheAISContext()->OpenLocalContext(Standard_False);
4062 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4065 Handle(AIS_InteractiveObject) aIO =
4066 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4068 TheAISContext()->Load(aIO,0,Standard_False);
4071 // traitement des objets qui etaient currents dans le Contexte global
4072 if (!ListOfIO.IsEmpty() ) {
4073 // il y avait des objets currents
4074 AIS_ListIteratorOfListOfInteractive iter;
4075 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4076 Handle(AIS_InteractiveObject) aIO=iter.Value();
4077 TheAISContext()->Activate(aIO,aMode);
4078 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4082 // On applique le mode a tous les objets displayes
4083 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4084 it2 (GetMapOfAIS());
4086 Handle(AIS_InteractiveObject) aIO =
4087 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4088 if (!aIO.IsNull()) {
4089 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4090 TheAISContext()->Activate(aIO,aMode);
4099 // un Context local est deja ouvert
4100 // Traitement des objets du Context local
4101 if (TheAISContext()->NbSelected()>0 ){
4102 TheAISContext()->UnhilightSelected(Standard_False);
4103 // il y a des objets selected,on les parcourt
4104 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4105 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
4108 if (HaveMode(aIO,aMode) ) {
4109 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4110 TheAISContext()->Deactivate(aIO,aMode);
4113 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4114 TheAISContext()->Activate(aIO,aMode);
4120 // il n'y a pas d'objets selected
4121 // tous les objets diplayes sont traites
4122 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4125 Handle(AIS_InteractiveObject) aIO =
4126 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4127 if (!aIO.IsNull()) {
4128 if (HaveMode(aIO,aMode) ) {
4129 di<<" Mode: "<<cmode<<" OFF pour "
4130 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4131 TheAISContext()->Deactivate(aIO,aMode);
4134 di<<" Mode: "<<cmode<<" ON pour"
4135 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4136 TheAISContext()->Activate(aIO,aMode);
4144 else if (HaveToSet && ThereIsName){
4145 Standard_Integer aMode=Draw::Atoi(argv [2]);
4146 Handle(AIS_InteractiveObject) aIO =
4147 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4149 if (!aIO.IsNull()) {
4150 const char *cmode="???";
4153 case 0: cmode = "Shape"; break;
4154 case 1: cmode = "Vertex"; break;
4155 case 2: cmode = "Edge"; break;
4156 case 3: cmode = "Wire"; break;
4157 case 4: cmode = "Face"; break;
4158 case 5: cmode = "Shell"; break;
4159 case 6: cmode = "Solid"; break;
4160 case 7: cmode = "Compound"; break;
4163 if( !TheAISContext()->HasOpenedContext() ) {
4164 TheAISContext()->OpenLocalContext(Standard_False);
4165 // On charge tous les objets de la map
4166 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4168 Handle(AIS_InteractiveObject) aShape=
4169 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4170 if (!aShape.IsNull())
4171 TheAISContext()->Load(aShape,0,Standard_False);
4174 TheAISContext()->Activate(aIO,aMode);
4175 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4179 // un Context local est deja ouvert
4180 if (HaveMode(aIO,aMode) ) {
4181 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4182 TheAISContext()->Deactivate(aIO,aMode);
4185 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4186 TheAISContext()->Activate(aIO,aMode);
4195 //! Auxiliary method to print Interactive Object information
4196 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4197 const Handle(Standard_Transient)& theObject,
4198 Draw_Interpretor& theDI)
4200 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4203 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4207 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4208 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4209 << (theDetected.Contains (anObj) ? " Detected" : " ")
4211 if (anObj->Type() == AIS_KOI_Datum)
4214 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4215 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4216 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4217 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4218 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4219 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4220 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4223 else if (anObj->Type() == AIS_KOI_Shape
4224 && anObj->Signature() == 0)
4226 theDI << " AIS_Shape";
4228 else if (anObj->Type() == AIS_KOI_Relation)
4230 // AIS_Dimention and AIS_Relation
4231 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4232 switch (aRelation->KindOfDimension())
4234 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4235 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4236 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4237 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4238 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4239 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4240 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4241 default: theDI << " UNKNOWN dimension"; break;
4246 theDI << " UserPrs";
4248 theDI << " (" << theObject->DynamicType()->Name() << ")";
4251 //! Print information about locally selected sub-shapes
4252 static void localCtxInfo (Draw_Interpretor& theDI)
4254 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4255 if (!aCtx->HasOpenedContext())
4260 TCollection_AsciiString aPrevName;
4261 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
4262 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
4264 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
4265 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
4266 if (aSubShape.IsNull()
4267 || aShapeIO.IsNull()
4268 || !GetMapOfAIS().IsBound1 (aShapeIO))
4273 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4274 TopTools_MapOfShape aFilter;
4275 Standard_Integer aNumber = 0;
4276 const TopoDS_Shape aShape = aShapeIO->Shape();
4277 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4278 anIter.More(); anIter.Next())
4280 if (!aFilter.Add (anIter.Current()))
4282 continue; // filter duplicates
4286 if (!anIter.Current().IsSame (aSubShape))
4291 Standard_CString aShapeName = NULL;
4292 switch (aSubShape.ShapeType())
4294 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4295 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4296 case TopAbs_SOLID: aShapeName = " Solid"; break;
4297 case TopAbs_SHELL: aShapeName = " Shell"; break;
4298 case TopAbs_FACE: aShapeName = " Face"; break;
4299 case TopAbs_WIRE: aShapeName = " Wire"; break;
4300 case TopAbs_EDGE: aShapeName = " Edge"; break;
4301 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4303 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4306 if (aParentName != aPrevName)
4308 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4309 aPrevName = aParentName;
4311 theDI << " " << aShapeName << " #" << aNumber << "\n";
4317 //==============================================================================
4320 //==============================================================================
4321 static Standard_Integer VState (Draw_Interpretor& theDI,
4322 Standard_Integer theArgNb,
4323 Standard_CString* theArgVec)
4325 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4328 std::cerr << "Error: No opened viewer!\n";
4332 Standard_Boolean toPrintEntities = Standard_False;
4333 Standard_Boolean toCheckSelected = Standard_False;
4335 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4337 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4338 anOption.LowerCase();
4339 if (anOption == "-detectedentities"
4340 || anOption == "-entities")
4342 toPrintEntities = Standard_True;
4344 else if (anOption == "-hasselected")
4346 toCheckSelected = Standard_True;
4350 if (toCheckSelected)
4352 aCtx->InitSelected();
4353 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4354 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4359 if (toPrintEntities)
4361 theDI << "Detected entities:\n";
4362 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4363 for (aSelector->InitDetected(); aSelector->MoreDetected(); aSelector->NextDetected())
4365 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->DetectedEntity();
4366 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4367 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4368 SelectMgr_SelectingVolumeManager aMgr = anObj->HasTransformation() ? aSelector->GetManager().Transform (anObj->InversedTransformation())
4369 : aSelector->GetManager();
4370 SelectBasics_PickResult aResult;
4371 anEntity->Matches (aMgr, aResult);
4372 NCollection_Vec3<Standard_Real> aDetectedPnt = aMgr.DetectedPoint (aResult.Depth());
4374 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4375 aName.LeftJustify (20, ' ');
4376 char anInfoStr[512];
4378 " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
4380 aResult.DistToGeomCenter(),
4381 aDetectedPnt.x(), aDetectedPnt.y(), aDetectedPnt.z());
4382 theDI << " " << aName
4384 << " (" << anEntity->DynamicType()->Name() << ")"
4387 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4388 if (!aBRepOwner.IsNull())
4390 theDI << " Detected Shape: "
4391 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4395 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4396 if (!aWire.IsNull())
4398 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4399 theDI << " Detected Child: "
4400 << aSen->DynamicType()->Name()
4407 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4408 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4410 aDetected.Add (aCtx->DetectedCurrentObject());
4413 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4417 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4419 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4420 if (!GetMapOfAIS().IsBound2 (anObjName))
4422 theDI << anObjName << " doesn't exist!\n";
4426 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4427 TCollection_AsciiString aName = anObjName;
4428 aName.LeftJustify (20, ' ');
4429 theDI << " " << aName << " ";
4430 objInfo (aDetected, anObjTrans, theDI);
4436 if (aCtx->NbSelected() > 0
4439 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4441 Handle(AIS_InteractiveObject) anObj = aCtx->SelectedInteractive();
4442 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4443 aName.LeftJustify (20, ' ');
4444 theDI << aName << " ";
4445 objInfo (aDetected, anObj, theDI);
4451 theDI << "Neutral-point state:\n";
4452 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4453 anObjIter.More(); anObjIter.Next())
4455 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4461 TCollection_AsciiString aName = anObjIter.Key2();
4462 aName.LeftJustify (20, ' ');
4463 theDI << " " << aName << " ";
4464 objInfo (aDetected, anObj, theDI);
4467 localCtxInfo (theDI);
4471 //=======================================================================
4472 //function : PickObjects
4474 //=======================================================================
4475 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4476 const AIS_KindOfInteractive TheType,
4477 const Standard_Integer TheSignature,
4478 const Standard_Integer MaxPick)
4480 Handle(AIS_InteractiveObject) IO;
4481 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4483 // step 1: prepare the data
4485 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4486 TheAISContext()->AddFilter(F1);
4489 // step 2 : wait for the selection...
4490 // Standard_Boolean IsGood (Standard_False);
4491 // Standard_Integer NbPick(0);
4492 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
4493 Standard_Integer NbPickFail(0);
4494 Standard_Integer argccc = 5;
4495 const char *bufff[] = { "A", "B", "C","D", "E" };
4496 const char **argvvv = (const char **) bufff;
4499 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4500 while(ViewerMainLoop(argccc,argvvv)){}
4501 Standard_Integer NbStored = TheAISContext()->NbSelected();
4502 if((unsigned int ) NbStored != NbPickGood)
4503 NbPickGood= NbStored;
4506 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4509 // step3 get result.
4511 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4513 Standard_Integer i(0);
4514 for(TheAISContext()->InitSelected();
4515 TheAISContext()->MoreSelected();
4516 TheAISContext()->NextSelected()){
4518 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4519 arr->SetValue(i,IO2);
4524 TheAISContext()->CloseLocalContext(curindex);
4526 return Standard_True;
4530 //=======================================================================
4531 //function : PickObject
4533 //=======================================================================
4534 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4535 const Standard_Integer TheSignature,
4536 const Standard_Integer MaxPick)
4538 Handle(AIS_InteractiveObject) IO;
4539 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4541 // step 1: prepare the data
4544 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4545 TheAISContext()->AddFilter(F1);
4548 // step 2 : wait for the selection...
4549 Standard_Boolean IsGood (Standard_False);
4550 Standard_Integer NbPick(0);
4551 Standard_Integer argccc = 5;
4552 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4553 const char **argvvv = (const char **) bufff;
4556 while(!IsGood && NbPick<= MaxPick){
4557 while(ViewerMainLoop(argccc,argvvv)){}
4558 IsGood = (TheAISContext()->NbSelected()>0) ;
4560 cout<<"Nb Pick :"<<NbPick<<endl;
4564 // step3 get result.
4566 TheAISContext()->InitSelected();
4567 IO = TheAISContext()->SelectedInteractive();
4571 TheAISContext()->CloseLocalContext(curindex);
4575 //=======================================================================
4576 //function : PickShape
4577 //purpose : First Activate the rightmode + Put Filters to be able to
4578 // pick objets that are of type <TheType>...
4579 //=======================================================================
4581 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4582 const Standard_Integer MaxPick)
4585 // step 1: prepare the data
4587 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4588 TopoDS_Shape result;
4590 if(TheType==TopAbs_SHAPE){
4591 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4592 TheAISContext()->AddFilter(F1);
4595 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4596 TheAISContext()->AddFilter(TF);
4597 TheAISContext()->ActivateStandardMode(TheType);
4602 // step 2 : wait for the selection...
4603 Standard_Boolean NoShape (Standard_True);
4604 Standard_Integer NbPick(0);
4605 Standard_Integer argccc = 5;
4606 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4607 const char **argvvv = (const char **) bufff;
4610 while(NoShape && NbPick<= MaxPick){
4611 while(ViewerMainLoop(argccc,argvvv)){}
4612 NoShape = (TheAISContext()->NbSelected()==0) ;
4614 cout<<"Nb Pick :"<<NbPick<<endl;
4617 // step3 get result.
4621 TheAISContext()->InitSelected();
4622 if(TheAISContext()->HasSelectedShape())
4623 result = TheAISContext()->SelectedShape();
4625 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4626 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
4631 TheAISContext()->CloseLocalContext(curindex);
4637 //=======================================================================
4638 //function : PickShapes
4640 //=======================================================================
4641 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4642 Handle(TopTools_HArray1OfShape)& thearr,
4643 const Standard_Integer MaxPick)
4646 Standard_Integer Taille = thearr->Length();
4648 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
4650 // step 1: prepare the data
4651 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4652 if(TheType==TopAbs_SHAPE){
4653 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4654 TheAISContext()->AddFilter(F1);
4657 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4658 TheAISContext()->AddFilter(TF);
4659 TheAISContext()->ActivateStandardMode(TheType);
4663 // step 2 : wait for the selection...
4665 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
4666 Standard_Integer NbPickFail(0);
4667 Standard_Integer argccc = 5;
4668 const char *bufff[] = { "A", "B", "C","D", "E" };
4669 const char **argvvv = (const char **) bufff;
4672 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4673 while(ViewerMainLoop(argccc,argvvv)){}
4674 Standard_Integer NbStored = TheAISContext()->NbSelected();
4675 if((unsigned int ) NbStored != NbPickGood)
4676 NbPickGood= NbStored;
4679 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4682 // step3 get result.
4684 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4686 Standard_Integer i(0);
4687 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4689 if(TheAISContext()->HasSelectedShape())
4690 thearr->SetValue(i,TheAISContext()->SelectedShape());
4692 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4693 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
4697 TheAISContext()->CloseLocalContext(curindex);
4698 return Standard_True;
4702 //=======================================================================
4703 //function : VPickShape
4705 //=======================================================================
4706 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4708 TopoDS_Shape PickSh;
4709 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4712 theType = TopAbs_SHAPE;
4714 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4715 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4716 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4717 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4718 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4719 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4720 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4723 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4724 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4726 TCollection_AsciiString name;
4729 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4731 PickSh = ViewerTest::PickShape(theType);
4740 if(!PickSh.IsNull()){
4741 nbOfSub[Standard_Integer(theType)]++;
4743 name += nameType[Standard_Integer(theType)];
4744 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4749 // si on avait une petite methode pour voir si la shape
4750 // est deja dans la Double map, ca eviterait de creer....
4751 DBRep::Set(name.ToCString(),PickSh);
4753 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4754 GetMapOfAIS().Bind(newsh, name);
4755 TheAISContext()->Display(newsh);
4756 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4759 // Plusieurs objets a picker, vite vite vite....
4762 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4763 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4764 if(ViewerTest::PickShapes(theType,arr)){
4765 for(Standard_Integer i=1;i<=NbToPick;i++){
4766 PickSh = arr->Value(i);
4767 if(!PickSh.IsNull()){
4769 nbOfSub[Standard_Integer(theType)]++;
4772 name += nameType[Standard_Integer(theType)];
4773 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4781 DBRep::Set(name.ToCString(),PickSh);
4782 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4783 GetMapOfAIS().Bind(newsh, name);
4784 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4785 TheAISContext()->Display(newsh);
4793 //=======================================================================
4794 //function : VPickSelected
4796 //=======================================================================
4797 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4799 static Standard_Integer aCount = 0;
4800 TCollection_AsciiString aName = "PickedShape_";
4808 aName = aName + aCount++ + "_";
4811 Standard_Integer anIdx = 0;
4812 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4814 TopoDS_Shape aShape;
4815 if (TheAISContext()->HasSelectedShape())
4817 aShape = TheAISContext()->SelectedShape();
4821 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4822 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
4825 TCollection_AsciiString aCurrentName = aName;
4828 aCurrentName += anIdx;
4831 DBRep::Set ((aCurrentName).ToCString(), aShape);
4833 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4834 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4835 TheAISContext()->Display (aNewShape);
4841 //=======================================================================
4842 //function : list of known objects
4844 //=======================================================================
4845 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4847 // 1234567890 12345678901234567 123456789
4848 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4849 TCollection_AsciiString BlankLine(64,'_');
4850 Standard_Integer i ;
4852 di<<"/n"<<BlankLine.ToCString()<<"\n";
4855 Colum[i].Center(20,' ');
4857 di<<"|"<<Colum[i].ToCString();
4860 di<<BlankLine.ToCString()<<"\n";
4862 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4863 const char ** names = GetTypeNames();
4865 TCollection_AsciiString curstring;
4866 TCollection_AsciiString curcolum[3];
4869 // les objets de type Datum..
4870 curcolum[1]+="Datum";
4872 curcolum[0].Clear();
4873 curcolum[0] += names[i];
4875 curcolum[2].Clear();
4876 curcolum[2]+=TCollection_AsciiString(i+1);
4878 for(Standard_Integer j =0;j<=2;j++){
4879 curcolum[j].Center(20,' ');
4880 di<<"|"<<curcolum[j].ToCString();
4884 di<<BlankLine.ToCString()<<"\n";
4886 // les objets de type shape
4887 curcolum[1].Clear();
4888 curcolum[1]+="Shape";
4889 curcolum[1].Center(20,' ');
4892 curcolum[0].Clear();
4893 curcolum[0] += names[7+i];
4894 curcolum[2].Clear();
4895 curcolum[2]+=TCollection_AsciiString(i);
4897 for(Standard_Integer j =0;j<=2;j++){
4898 curcolum[j].Center(20,' ');
4899 di<<"|"<<curcolum[j].ToCString();
4903 di<<BlankLine.ToCString()<<"\n";
4904 // les IO de type objet...
4905 curcolum[1].Clear();
4906 curcolum[1]+="Object";
4907 curcolum[1].Center(20,' ');
4909 curcolum[0].Clear();
4910 curcolum[0] += names[10+i];
4911 curcolum[2].Clear();
4912 curcolum[2]+=TCollection_AsciiString(i);
4914 for(Standard_Integer j =0;j<=2;j++){
4915 curcolum[j].Center(20,' ');
4916 di<<"|"<<curcolum[j].ToCString();
4920 di<<BlankLine.ToCString()<<"\n";
4921 // les contraintes et dimensions.
4922 // pour l'instant on separe juste contraintes et dimensions...
4923 // plus tard, on detaillera toutes les sortes...
4924 curcolum[1].Clear();
4925 curcolum[1]+="Relation";
4926 curcolum[1].Center(20,' ');
4928 curcolum[0].Clear();
4929 curcolum[0] += names[12+i];
4930 curcolum[2].Clear();
4931 curcolum[2]+=TCollection_AsciiString(i);
4933 for(Standard_Integer j =0;j<=2;j++){
4934 curcolum[j].Center(20,' ');
4935 di<<"|"<<curcolum[j].ToCString();
4939 di<<BlankLine.ToCString()<<"\n";
4946 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
4948 if(argc!=2) return 1;
4950 AIS_KindOfInteractive TheType;
4951 Standard_Integer TheSign(-1);
4952 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4955 AIS_ListOfInteractive LIO;
4957 // en attendant l'amelioration ais pour les dimensions...
4959 Standard_Integer dimension_status(-1);
4960 if(TheType==AIS_KOI_Relation){
4961 dimension_status = TheSign ==1 ? 1 : 0;
4965 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
4966 Handle(AIS_InteractiveObject) curio;
4967 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4970 if(dimension_status == -1)
4971 TheAISContext()->Erase(curio,Standard_False);
4973 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
4974 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4975 (dimension_status==1 && KOD != AIS_KOD_NONE))
4976 TheAISContext()->Erase(curio,Standard_False);
4979 TheAISContext()->UpdateCurrentViewer();
4982 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4984 if(argc!=2) return 1;
4986 AIS_KindOfInteractive TheType;
4987 Standard_Integer TheSign(-1);
4988 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4990 // en attendant l'amelioration ais pour les dimensions...
4992 Standard_Integer dimension_status(-1);
4993 if(TheType==AIS_KOI_Relation){
4994 dimension_status = TheSign ==1 ? 1 : 0;
4998 AIS_ListOfInteractive LIO;
4999 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5000 Handle(AIS_InteractiveObject) curio;
5001 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5003 if(dimension_status == -1)
5004 TheAISContext()->Display(curio,Standard_False);
5006 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5007 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5008 (dimension_status==1 && KOD != AIS_KOD_NONE))
5009 TheAISContext()->Display(curio,Standard_False);
5014 TheAISContext()->UpdateCurrentViewer();
5018 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5021 BRep_Builder builder;
5023 BRepTools::Read(shape, s, builder);
5024 DBRep::Set(a[1], shape);
5025 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5026 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5031 //===============================================================================================
5034 //===============================================================================================
5035 static int VBsdf (Draw_Interpretor& theDi,
5036 Standard_Integer theArgsNb,
5037 const char** theArgVec)
5039 Handle(V3d_View) aView = ViewerTest::CurrentView();
5040 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5042 || aViewer.IsNull())
5044 std::cerr << "No active viewer!\n";
5048 ViewerTest_CmdParser aCmd;
5050 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5051 aCmd.AddOption ("print|echo|p", "Print BSDF");
5053 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5054 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5055 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5056 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5057 aCmd.AddOption ("le", "Self-emitted radiance");
5059 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5061 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
5062 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5063 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5065 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5067 aCmd.Parse (theArgsNb, theArgVec);
5069 if (aCmd.HasOption ("help"))
5071 theDi.PrintHelp (theArgVec[0]);
5075 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5078 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5079 if (!aMap.IsBound2 (aName) )
5081 std::cerr << "Use 'vdisplay' before" << "\n";
5085 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5086 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5087 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5089 if (aCmd.HasOption ("print"))
5091 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5094 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5095 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5096 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5097 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5098 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5101 if (aFresnel.x() >= 0.f)
5104 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5106 else if (aFresnel.x() >= -1.5f)
5109 << "|Constant| " << aFresnel.z() << "\n";
5111 else if (aFresnel.x() >= -2.5f)
5114 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5119 << "|Dielectric| " << aFresnel.y() << "\n";
5124 << "Roughness: " << aBSDF.Roughness << "\n"
5125 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
5126 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5127 << aBSDF.AbsorptionColor.g() << ", "
5128 << aBSDF.AbsorptionColor.b() << "\n";
5133 if (aCmd.HasOption ("roughness", 1, Standard_True))
5135 aCmd.Arg ("roughness", 0);
5136 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5139 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5141 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5144 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5146 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5149 if (aCmd.HasOption ("kd", 3))
5151 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5153 else if (aCmd.HasOption ("kd", 1, Standard_True))
5155 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5158 if (aCmd.HasOption ("kr", 3))
5160 aBSDF.Kr = aCmd.ArgVec3f ("kr");
5162 else if (aCmd.HasOption ("kr", 1, Standard_True))
5164 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5167 if (aCmd.HasOption ("kt", 3))
5169 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5171 else if (aCmd.HasOption ("kt", 1, Standard_True))
5173 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5176 if (aCmd.HasOption ("ks", 3))
5178 aBSDF.Ks = aCmd.ArgVec3f ("ks");
5180 else if (aCmd.HasOption ("ks", 1, Standard_True))
5182 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5185 if (aCmd.HasOption ("le", 3))
5187 aBSDF.Le = aCmd.ArgVec3f ("le");
5189 else if (aCmd.HasOption ("le", 1, Standard_True))
5191 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5194 const std::string aFresnelErrorMessage =
5195 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5197 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5199 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5200 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5202 if (aFresnelType == "schlick")
5204 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5205 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5206 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5207 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5211 std::cout << aFresnelErrorMessage;
5214 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5216 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5217 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5219 if (aFresnelType == "conductor")
5221 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5222 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5223 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5227 std::cout << aFresnelErrorMessage;
5230 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5232 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5233 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5235 if (aFresnelType == "dielectric")
5237 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5238 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5240 else if (aFresnelType == "constant")
5242 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5243 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5247 std::cout << aFresnelErrorMessage;
5251 if (aCmd.HasOption ("normalize"))
5256 aMaterial.SetBSDF (aBSDF);
5257 anIObj->SetMaterial (aMaterial);
5264 //==============================================================================
5265 //function : VLoadSelection
5266 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5267 //==============================================================================
5268 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5269 Standard_Integer theArgNb,
5270 const char** theArgVec)
5274 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5278 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5281 ViewerTest::ViewerInit();
5282 aCtx = ViewerTest::GetAISContext();
5285 // Parse input arguments
5286 TColStd_SequenceOfAsciiString aNamesOfIO;
5287 Standard_Boolean isLocal = Standard_False;
5288 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5290 const TCollection_AsciiString aName = theArgVec[anArgIter];
5291 TCollection_AsciiString aNameCase = aName;
5292 aNameCase.LowerCase();
5293 if (aNameCase == "-local")
5295 isLocal = Standard_True;
5299 aNamesOfIO.Append (aName);
5303 if (aNamesOfIO.IsEmpty())
5305 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5310 if (isLocal && !aCtx->HasOpenedContext())
5312 aCtx->OpenLocalContext (Standard_False);
5314 else if (!isLocal && aCtx->HasOpenedContext())
5316 aCtx->CloseAllContexts (Standard_False);
5319 // Load selection of interactive objects
5320 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5322 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5324 Handle(AIS_InteractiveObject) aShape;
5325 if (GetMapOfAIS().IsBound2 (aName))
5326 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5328 aShape = GetAISShapeFromName (aName.ToCString());
5330 if (!aShape.IsNull())
5332 if (!GetMapOfAIS().IsBound2 (aName))
5334 GetMapOfAIS().Bind (aShape, aName);
5337 aCtx->Load (aShape, -1, Standard_False);
5338 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5345 //==============================================================================
5346 //function : VAutoActivateSelection
5347 //purpose : Activates or deactivates auto computation of selection
5348 //==============================================================================
5349 static int VAutoActivateSelection (Draw_Interpretor& theDi,
5350 Standard_Integer theArgNb,
5351 const char** theArgVec)
5356 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5360 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5363 ViewerTest::ViewerInit();
5364 aCtx = ViewerTest::GetAISContext();
5369 TCollection_AsciiString aSelActivationString;
5370 if (aCtx->GetAutoActivateSelection())
5372 aSelActivationString.Copy ("ON");
5376 aSelActivationString.Copy ("OFF");
5379 theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
5383 Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]);
5384 aCtx->SetAutoActivateSelection (toActivate);
5390 //==============================================================================
5391 //function : ViewerTest::Commands
5392 //purpose : Add all the viewer command in the Draw_Interpretor
5393 //==============================================================================
5395 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5397 ViewerTest::ViewerCommands(theCommands);
5398 ViewerTest::RelationCommands(theCommands);
5399 ViewerTest::ObjectCommands(theCommands);
5400 ViewerTest::FilletCommands(theCommands);
5401 ViewerTest::VoxelCommands(theCommands);
5402 ViewerTest::OpenGlCommands(theCommands);
5404 const char *group = "AIS_Display";
5407 theCommands.Add("visos",
5408 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5409 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5410 __FILE__, visos, group);
5412 theCommands.Add("vdisplay",
5413 "vdisplay [-noupdate|-update] [-local] [-mutable] [-overlay|-underlay]"
5414 "\n\t\t: [-trsfPers flags] [-trsfPersPos X Y [Z]] [-3d|-2d|-2dTopDown]"
5415 "\n\t\t: [-dispMode mode] [-highMode mode]"
5416 "\n\t\t: name1 [name2] ... [name n]"
5417 "\n\t\t: Displays named objects."
5418 "\n\t\t: Option -local enables displaying of objects in local"
5419 "\n\t\t: selection context. Local selection context will be opened"
5420 "\n\t\t: if there is not any."
5421 "\n\t\t: -noupdate suppresses viewer redraw call."
5422 "\n\t\t: -mutable enables optimizations for mutable objects."
5423 "\n\t\t: -overlay draws objects in overlay."
5424 "\n\t\t: -underlay draws objects in underlay."
5425 "\n\t\t: -selectable|-noselect controls selection of objects."
5426 "\n\t\t: -trsfPers sets a transform persistence flags."
5427 "\n\t\t: -trsfPersPos sets an anchor point for transform persistence."
5428 "\n\t\t: -2d|-2dTopDown displays object in screen coordinates.",
5429 __FILE__, VDisplay2, group);
5431 theCommands.Add ("vupdate",
5432 "vupdate name1 [name2] ... [name n]"
5433 "\n\t\t: Updates named objects in interactive context",
5434 __FILE__, VUpdate, group);
5436 theCommands.Add("verase",
5437 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5438 "\n\t\t: Erases selected or named objects."
5439 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5440 "\n\t\t: Option -local enables erasing of selected or named objects without"
5441 "\n\t\t: closing local selection context.",
5442 __FILE__, VErase, group);
5444 theCommands.Add("vremove",
5445 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5446 "or vremove [-context] -all to remove all objects"
5447 "\n\t\t: Removes selected or named objects."
5448 "\n\t\t If -context is in arguments, the objects are not deleted"
5449 "\n\t\t from the map of objects and names."
5450 "\n\t\t: Option -local enables removing of selected or named objects without"
5451 "\n\t\t: closing local selection context. Empty local selection context will be"
5453 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5454 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5455 __FILE__, VRemove, group);
5457 theCommands.Add("vdonly",
5458 "vdonly [-noupdate|-update] [name1] ... [name n]"
5459 "\n\t\t: Displays only selected or named objects",
5460 __FILE__,VDonly2,group);
5462 theCommands.Add("vdisplayall",
5463 "vidsplayall [-local]"
5464 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5465 "\n\t\t: Option -local enables displaying of the objects in local"
5466 "\n\t\t: selection context.",
5467 __FILE__, VDisplayAll, group);
5469 theCommands.Add("veraseall",
5470 "veraseall [-local]"
5471 "\n\t\t: Erases all objects displayed in the viewer."
5472 "\n\t\t: Option -local enables erasing of the objects in local"
5473 "\n\t\t: selection context.",
5474 __FILE__, VErase, group);
5476 theCommands.Add("verasetype",
5478 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5479 __FILE__, VEraseType, group);
5480 theCommands.Add("vbounding",
5481 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5482 "\n\t\t: [-print] [-hide]"
5483 "\n\t\t: Temporarily display bounding box of specified Interactive"
5484 "\n\t\t: Objects, or print it to console if -print is specified."
5485 "\n\t\t: Already displayed box might be hidden by -hide option.",
5486 __FILE__,VBounding,group);
5488 theCommands.Add("vdisplaytype",
5489 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5490 __FILE__,VDisplayType,group);
5492 theCommands.Add("vdisplaymode",
5493 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
5494 __FILE__,VDispMode,group);
5496 theCommands.Add("verasemode",
5497 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
5498 __FILE__,VDispMode,group);
5500 theCommands.Add("vsetdispmode",
5501 "vsetdispmode [name] mode(1,2,..)"
5502 "\n\t\t: Sets display mode for all, selected or named objects.",
5503 __FILE__,VDispMode,group);
5505 theCommands.Add("vunsetdispmode",
5506 "vunsetdispmode [name]"
5507 "\n\t\t: Unsets custom display mode for selected or named objects.",
5508 __FILE__,VDispMode,group);
5510 theCommands.Add("vdir",
5511 "Lists all objects displayed in 3D viewer",
5512 __FILE__,VDir,group);
5514 #ifdef HAVE_FREEIMAGE
5515 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5517 #define DUMP_FORMATS "{ppm}"
5519 theCommands.Add("vdump",
5520 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5521 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5522 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5523 "\n\t\t: Dumps content of the active view into image file",
5524 __FILE__,VDump,group);
5526 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5527 __FILE__,VSubInt,group);
5529 theCommands.Add("vaspects",
5530 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5531 "\n\t\t: [-setVisibility 0|1]"
5532 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5533 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5534 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5535 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5536 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5537 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5538 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5539 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5540 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5541 "\n\t\t: [-isoontriangulation 0|1]"
5542 "\n\t\t: [-setMaxParamValue {value}]"
5543 "\n\t\t: Manage presentation properties of all, selected or named objects."
5544 "\n\t\t: When -subshapes is specified than following properties will be"
5545 "\n\t\t: assigned to specified sub-shapes."
5546 "\n\t\t: When -defaults is specified than presentation properties will be"
5547 "\n\t\t: assigned to all objects that have not their own specified properties"
5548 "\n\t\t: and to all objects to be displayed in the future."
5549 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5550 __FILE__,VAspects,group);
5552 theCommands.Add("vsetcolor",
5553 "vsetcolor [-noupdate|-update] [name] ColorName"
5554 "\n\t\t: Sets color for all, selected or named objects."
5555 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5556 __FILE__,VAspects,group);
5558 theCommands.Add("vunsetcolor",
5559 "vunsetcolor [-noupdate|-update] [name]"
5560 "\n\t\t: Resets color for all, selected or named objects."
5561 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5562 __FILE__,VAspects,group);
5564 theCommands.Add("vsettransparency",
5565 "vsettransparency [-noupdate|-update] [name] Coefficient"
5566 "\n\t\t: Sets transparency for all, selected or named objects."
5567 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5568 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5569 __FILE__,VAspects,group);
5571 theCommands.Add("vunsettransparency",
5572 "vunsettransparency [-noupdate|-update] [name]"
5573 "\n\t\t: Resets transparency for all, selected or named objects."
5574 "\n\t\t: Alias for vaspects -unsettransp [name].",
5575 __FILE__,VAspects,group);
5577 theCommands.Add("vsetmaterial",
5578 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5579 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5580 __FILE__,VAspects,group);
5582 theCommands.Add("vunsetmaterial",
5583 "vunsetmaterial [-noupdate|-update] [name]"
5584 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5585 __FILE__,VAspects,group);
5587 theCommands.Add("vsetwidth",
5588 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5589 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5590 __FILE__,VAspects,group);
5592 theCommands.Add("vunsetwidth",
5593 "vunsetwidth [-noupdate|-update] [name]"
5594 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5595 __FILE__,VAspects,group);
5597 theCommands.Add("vsetinteriorstyle",
5598 "vsetinteriorstyle [-noupdate|-update] [name] style"
5599 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5600 __FILE__,VSetInteriorStyle,group);
5602 theCommands.Add("vsensdis",
5603 "vardisp : display active entities",
5604 __FILE__,VDispSensi,group);
5605 theCommands.Add("vsensera",
5606 "vardisp : erase active entities",
5607 __FILE__,VClearSensi,group);
5609 theCommands.Add("vselprecision",
5610 "vselprecision [-unset] [tolerance_value]"
5611 "\n\t\t Manages selection precision or prints current value if no parameter is passed."
5612 "\n\t\t -unset - restores default selection tolerance behavior, based on individual entity tolerance",
5613 __FILE__,VSelPrecision,group);
5615 theCommands.Add("vperf",
5616 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
5617 __FILE__,VPerf,group);
5619 theCommands.Add("vanimation",
5620 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5621 __FILE__,VAnimation,group);
5623 theCommands.Add("vsetshading",
5624 "vsetshading : vsetshading name Quality(default=0.0008) ",
5625 __FILE__,VShading,group);
5627 theCommands.Add("vunsetshading",
5628 "vunsetshading :vunsetshading name ",
5629 __FILE__,VShading,group);
5631 theCommands.Add ("vtexture",
5632 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5633 " [-scale u v] [-scale off]\n"
5634 " [-origin u v] [-origin off]\n"
5635 " [-repeat u v] [-repeat off]\n"
5636 " [-modulate {on | off}]"
5638 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5639 " specifying one of the predefined textures.\n"
5640 " The options are: \n"
5641 " -scale u v : enable texture scaling and set scale factors\n"
5642 " -scale off : disable texture scaling\n"
5643 " -origin u v : enable texture origin positioning and set the origin\n"
5644 " -origin off : disable texture origin positioning\n"
5645 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5646 " -repeat off : disable texture repeat\n"
5647 " -modulate {on | off} : enable or disable texture modulation\n"
5648 " -default : sets texture mapping default parameters\n"
5649 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5650 "or 'vtexture NameOfShape ?' to list available textures\n",
5651 __FILE__, VTexture, group);
5653 theCommands.Add("vtexscale",
5654 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5655 or 'vtexscale NameOfShape ScaleUV' \n \
5656 or 'vtexscale NameOfShape' to disable scaling\n ",
5657 __FILE__,VTexture,group);
5659 theCommands.Add("vtexorigin",
5660 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5661 or 'vtexorigin NameOfShape UVOrigin' \n \
5662 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5663 __FILE__,VTexture,group);
5665 theCommands.Add("vtexrepeat",
5666 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5667 or 'vtexrepeat NameOfShape UVRepeat \n \
5668 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5671 theCommands.Add("vtexdefault",
5672 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5675 theCommands.Add("vsetam",
5676 "vsetActivatedModes: vsetam mode(1->7) ",
5677 __FILE__,VActivatedMode,group);
5679 theCommands.Add("vunsetam",
5680 "vunsetActivatedModes: vunsetam ",
5681 __FILE__,VActivatedMode,group);
5683 theCommands.Add("vstate",
5684 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5685 "\n\t\t: Reports show/hidden state for selected or named objects"
5686 "\n\t\t: -entities - print low-level information about detected entities"
5687 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5688 __FILE__,VState,group);
5690 theCommands.Add("vpickshapes",
5691 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5692 __FILE__,VPickShape,group);
5694 theCommands.Add("vtypes",
5695 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5698 theCommands.Add("vr", "vr : reading of the shape",
5699 __FILE__,vr, group);
5701 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5702 __FILE__, VPickSelected, group);
5704 theCommands.Add ("vloadselection",
5705 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5706 "\n\t\t: primitives for the shapes with names given without displaying them."
5707 "\n\t\t: -local - open local context before selection computation",
5708 __FILE__, VLoadSelection, group);
5710 theCommands.Add ("vautoactivatesel",
5711 "vautoactivatesel [0|1] : manage or display the option to automatically"
5712 "\n\t\t: activate selection for newly displayed objects"
5713 "\n\t\t: [0|1] - turn off | on auto activation of selection",
5714 __FILE__, VAutoActivateSelection, group);
5716 theCommands.Add("vbsdf", "vbsdf [name] [options]"
5717 "\nAdjusts parameters of material BSDF:"
5718 "\n -help : Shows this message"
5719 "\n -print : Print BSDF"
5720 "\n -kd : Weight of the Lambertian BRDF"
5721 "\n -kr : Weight of the reflection BRDF"
5722 "\n -kt : Weight of the transmission BTDF"
5723 "\n -ks : Weight of the glossy Blinn BRDF"
5724 "\n -le : Self-emitted radiance"
5725 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5726 "\n Schlick x y z, Dielectric x, Conductor x y"
5727 "\n -roughness : Roughness of material (Blinn's exponent)"
5728 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
5729 "\n -absorpcolor : Absorption color (only for transparent material)"
5730 "\n -normalize : Normalize BSDF coefficients",
5731 __FILE__, VBsdf, group);
5735 //=====================================================================
5736 //========================= for testing Draft and Rib =================
5737 //=====================================================================
5738 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5739 #include <DBRep.hxx>
5740 #include <TopoDS_Face.hxx>
5741 #include <gp_Pln.hxx>
5742 #include <AIS_KindOfSurface.hxx>
5743 #include <BRepOffsetAPI_DraftAngle.hxx>
5744 #include <Precision.hxx>
5745 #include <BRepAlgo.hxx>
5746 #include <OSD_Environment.hxx>
5747 #include <DrawTrSurf.hxx>
5748 //#include <DbgTools.hxx>
5749 //#include <FeatAlgo_MakeLinearForm.hxx>
5754 //=======================================================================
5755 //function : IsValid
5757 //=======================================================================
5758 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5759 const TopoDS_Shape& theResult,
5760 const Standard_Boolean closedSolid,
5761 const Standard_Boolean GeomCtrl)
5763 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5764 TCollection_AsciiString checkValid = check.Value();
5765 Standard_Boolean ToCheck = Standard_True;
5766 if (!checkValid.IsEmpty()) {
5768 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5770 if ( checkValid=="true" || checkValid=="TRUE" ) {
5771 ToCheck= Standard_False;
5775 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
5778 Standard_Boolean IsValid = Standard_True;
5780 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5785 //===============================================================================
5786 // TDraft : test draft, uses AIS Viewer
5787 // Solid Face Plane Angle Reverse
5788 //===============================================================================
5789 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5791 if (argc < 5) return 1;
5792 // argv[1] - TopoDS_Shape Solid
5793 // argv[2] - TopoDS_Shape Face
5794 // argv[3] - TopoDS_Shape Plane
5795 // argv[4] - Standard_Real Angle
5796 // argv[5] - Standard_Integer Reverse
5798 // Sprintf(prefix, argv[1]);
5799 Standard_Real anAngle = 0;
5800 Standard_Boolean Rev = Standard_False;
5801 Standard_Integer rev = 0;
5802 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5803 TopoDS_Shape face = GetShapeFromName(argv[2]);
5804 TopoDS_Face Face = TopoDS::Face(face);
5805 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5806 if (Plane.IsNull ()) {
5807 di << "TEST : Plane is NULL" << "\n";
5810 anAngle = Draw::Atof(argv[4]);
5811 anAngle = 2*M_PI * anAngle / 360.0;
5813 Handle( Geom_Surface )aSurf;
5814 AIS_KindOfSurface aSurfType;
5815 Standard_Real Offset;
5817 if(argc > 4) { // == 5
5818 rev = Draw::Atoi(argv[5]);
5819 Rev = (rev)? Standard_True : Standard_False;
5822 TopoDS_Face face2 = TopoDS::Face(Plane);
5823 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5825 di << "TEST : Can't find plane" << "\n";
5829 aDir = aPln.Axis().Direction();
5832 if (Plane.Orientation() == TopAbs_REVERSED)
5834 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5836 BRepOffsetAPI_DraftAngle Draft (Solid);
5838 if(Abs(anAngle)< Precision::Angular()) {
5839 di << "TEST : NULL angle" << "\n";
5842 if(Rev) anAngle = - anAngle;
5843 Draft.Add (Face, aDir, anAngle, aPln);
5845 if (!Draft.IsDone()) {
5846 di << "TEST : Draft Not DONE " << "\n";
5849 TopTools_ListOfShape Larg;
5851 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
5852 di << "TEST : DesignAlgo returns Not valid" << "\n";
5856 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5857 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
5859 if ( !ais.IsNull() ) {
5860 ais->SetColor(DEFAULT_COLOR);
5861 ais->SetMaterial(DEFAULT_MATERIAL);
5862 // Display the AIS_Shape without redraw
5863 Ctx->Display(ais, Standard_False);
5865 const char *Name = "draft1";
5866 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
5868 Handle(AIS_InteractiveObject) an_object =
5869 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
5870 if (!an_object.IsNull()) {
5871 Ctx->Remove(an_object,
5873 GetMapOfAIS().UnBind2(Name) ;
5876 GetMapOfAIS().Bind(ais, Name);
5877 // DBRep::Set("draft", ais->Shape());
5879 Ctx->Display(ais, Standard_True);
5883 //==============================================================================
5884 //function : splitParameter
5885 //purpose : Split parameter string to parameter name and parameter value
5886 //==============================================================================
5887 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
5888 TCollection_AsciiString& theName,
5889 TCollection_AsciiString& theValue)
5891 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
5893 if (aParamNameEnd == 0)
5895 return Standard_False;
5898 TCollection_AsciiString aString (theString);
5899 if (aParamNameEnd != 0)
5901 theValue = aString.Split (aParamNameEnd);
5902 aString.Split (aString.Length() - 1);
5906 return Standard_True;
5909 //============================================================================
5911 //============================================================================
5912 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
5915 DrawTrSurf::BasicCommands(theCommands);
5916 const char* group = "Check Features Operations commands";
5918 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
5920 &TDraft,group); //Draft_Modification
5923 //==============================================================================
5924 // ViewerTest::Factory
5925 //==============================================================================
5926 void ViewerTest::Factory(Draw_Interpretor& theDI)
5928 // definition of Viewer Command
5929 ViewerTest::Commands(theDI);
5930 ViewerTest::AviCommands(theDI);
5933 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
5937 // Declare entry point PLUGINFACTORY