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 <Select3D_SensitivePrimitiveArray.hxx>
67 #include <SelectMgr_EntityOwner.hxx>
68 #include <StdSelect_BRepOwner.hxx>
69 #include <StdSelect_ViewerSelector3d.hxx>
70 #include <TopTools_MapOfShape.hxx>
71 #include <ViewerTest_AutoUpdater.hxx>
75 #include <Draw_Interpretor.hxx>
76 #include <TCollection_AsciiString.hxx>
77 #include <Draw_PluginMacro.hxx>
79 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
81 #include <Quantity_Color.hxx>
82 #include <Quantity_NameOfColor.hxx>
84 #include <Graphic3d_NameOfMaterial.hxx>
86 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
87 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
88 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
90 //=======================================================================
91 //function : GetColorFromName
92 //purpose : get the Quantity_NameOfColor from a string
93 //=======================================================================
95 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
97 Quantity_NameOfColor aColor = DEFAULT_COLOR;
98 Quantity_Color::ColorFromName (theName, aColor);
102 //=======================================================================
103 //function : ParseColor
105 //=======================================================================
107 Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
108 const char** theArgVec,
109 Quantity_Color& theColor)
111 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
113 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
118 else if (theArgNb >= 3)
120 const TCollection_AsciiString anRgbStr[3] =
126 if (!anRgbStr[0].IsRealValue()
127 || !anRgbStr[1].IsRealValue()
128 || !anRgbStr[2].IsRealValue())
133 Graphic3d_Vec4d anRgb;
134 anRgb.x() = anRgbStr[0].RealValue();
135 anRgb.y() = anRgbStr[1].RealValue();
136 anRgb.z() = anRgbStr[2].RealValue();
137 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
138 || anRgb.y() < 0.0 || anRgb.y() > 1.0
139 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
141 std::cout << "Error: RGB color values should be within range 0..1!\n";
145 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
152 //=======================================================================
153 //function : ParseOnOff
155 //=======================================================================
156 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
157 Standard_Boolean& theIsOn)
159 TCollection_AsciiString aFlag(theArg);
164 theIsOn = Standard_True;
165 return Standard_True;
167 else if (aFlag == "off"
170 theIsOn = Standard_False;
171 return Standard_True;
173 return Standard_False;
176 //=======================================================================
177 //function : GetTypeNames
179 //=======================================================================
180 static const char** GetTypeNames()
182 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
183 "Shape","ConnectedShape","MultiConn.Shape",
184 "ConnectedInter.","MultiConn.",
185 "Constraint","Dimension"};
186 static const char** ThePointer = names;
190 //=======================================================================
191 //function : GetTypeAndSignfromString
193 //=======================================================================
194 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
196 const char ** thefullnames = GetTypeNames();
197 Standard_Integer index(-1);
199 for(Standard_Integer i=0;i<=13 && index==-1;i++)
200 if(!strcasecmp(name,thefullnames[i]))
204 TheType = AIS_KOI_None;
210 TheType = AIS_KOI_Datum;
214 TheType = AIS_KOI_Shape;
218 TheType = AIS_KOI_Object;
222 TheType = AIS_KOI_Relation;
231 #include <Draw_Interpretor.hxx>
233 #include <Draw_Appli.hxx>
237 #include <TCollection_AsciiString.hxx>
238 #include <V3d_Viewer.hxx>
239 #include <V3d_View.hxx>
242 #include <AIS_InteractiveContext.hxx>
243 #include <AIS_Shape.hxx>
244 #include <AIS_TexturedShape.hxx>
245 #include <AIS_DisplayMode.hxx>
246 #include <TColStd_MapOfInteger.hxx>
247 #include <AIS_MapOfInteractive.hxx>
248 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
249 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
250 #include <ViewerTest_EventManager.hxx>
252 #include <TopoDS_Solid.hxx>
253 #include <BRepTools.hxx>
254 #include <BRep_Builder.hxx>
255 #include <TopAbs_ShapeEnum.hxx>
257 #include <TopoDS.hxx>
258 #include <BRep_Tool.hxx>
261 #include <Draw_Window.hxx>
262 #include <AIS_ListIteratorOfListOfInteractive.hxx>
263 #include <AIS_ListOfInteractive.hxx>
264 #include <AIS_DisplayMode.hxx>
265 #include <TopTools_ListOfShape.hxx>
266 #include <BRepOffsetAPI_MakeThickSolid.hxx>
267 #include <BRepOffset.hxx>
269 //==============================================================================
270 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
271 //==============================================================================
272 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
273 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
277 //=======================================================================
280 //=======================================================================
281 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
282 const Handle(AIS_InteractiveObject)& theObject,
283 const Standard_Boolean theToUpdate,
284 const Standard_Boolean theReplaceIfExists)
286 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
287 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
290 std::cout << "Error: AIS context is not available.\n";
291 return Standard_False;
294 if (aMap.IsBound2 (theName))
296 if (!theReplaceIfExists)
298 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
299 << "Please use another name.\n";
300 return Standard_False;
303 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
304 if (!anOldObj.IsNull())
306 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
308 aMap.UnBind2 (theName);
311 if (theObject.IsNull())
313 // object with specified name has been already unbound
314 return Standard_True;
317 // unbind AIS object if it was bound with another name
318 aMap.UnBind1 (theObject);
320 // can be registered without rebinding
321 aMap.Bind (theObject, theName);
322 aCtx->Display (theObject, theToUpdate);
323 return Standard_True;
326 //! Alias for ViewerTest::Display(), compatibility with old code.
327 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
328 const Handle(AIS_InteractiveObject)& theObject,
329 Standard_Boolean theReplaceIfExists = Standard_True)
331 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
334 static TColStd_MapOfInteger theactivatedmodes(8);
335 static TColStd_ListOfTransient theEventMgrs;
337 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
338 const Handle(AIS_InteractiveContext)& Ctx)
340 theEventMgrs.Clear();
341 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
344 static Handle(V3d_View)& a3DView()
346 static Handle(V3d_View) Viou;
351 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
352 static Handle(AIS_InteractiveContext) aContext;
356 const Handle(V3d_View)& ViewerTest::CurrentView()
360 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
365 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
367 return TheAISContext();
370 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
372 TheAISContext() = aCtx;
373 ViewerTest::ResetEventManager();
376 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
378 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
381 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
383 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
387 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
388 theEventMgrs.Prepend(EM);
391 void ViewerTest::UnsetEventManager()
393 theEventMgrs.RemoveFirst();
397 void ViewerTest::ResetEventManager()
399 const Handle(V3d_View) aView = ViewerTest::CurrentView();
400 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
403 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
405 Handle(ViewerTest_EventManager) EM;
406 if(theEventMgrs.IsEmpty()) return EM;
407 Handle(Standard_Transient) Tr = theEventMgrs.First();
408 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
412 //=======================================================================
413 //function : Get Context and active view
415 //=======================================================================
416 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
417 Handle(V3d_View)& theView)
419 theCtx = ViewerTest::GetAISContext();
420 theView = ViewerTest::CurrentView();
424 std::cout << "Error: cannot find an active view!\n";
425 return Standard_False;
427 return Standard_True;
430 //==============================================================================
431 //function : GetShapeFromName
432 //purpose : Compute an Shape from a draw variable or a file name
433 //==============================================================================
435 static TopoDS_Shape GetShapeFromName(const char* name)
437 TopoDS_Shape S = DBRep::Get(name);
440 BRep_Builder aBuilder;
441 BRepTools::Read( S, name, aBuilder);
447 //==============================================================================
448 //function : GetAISShapeFromName
449 //purpose : Compute an AIS_Shape from a draw variable or a file name
450 //==============================================================================
451 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
453 Handle(AIS_Shape) retsh;
455 if(GetMapOfAIS().IsBound2(name)){
456 const Handle(AIS_InteractiveObject) IO =
457 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
459 if(IO->Type()==AIS_KOI_Shape) {
460 if(IO->Signature()==0){
461 retsh = Handle(AIS_Shape)::DownCast (IO);
464 cout << "an Object which is not an AIS_Shape "
465 "already has this name!!!"<<endl;
472 TopoDS_Shape S = GetShapeFromName(name);
474 retsh = new AIS_Shape(S);
480 //==============================================================================
482 //purpose : Remove all the object from the viewer
483 //==============================================================================
484 void ViewerTest::Clear()
486 if ( !a3DView().IsNull() ) {
487 if (TheAISContext()->HasOpenedContext())
488 TheAISContext()->CloseLocalContext();
489 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
490 while ( it.More() ) {
491 cout << "Remove " << it.Key2() << endl;
492 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
493 TheAISContext()->Remove(anObj,Standard_False);
496 TheAISContext()->RebuildSelectionStructs();
497 TheAISContext()->UpdateCurrentViewer();
498 GetMapOfAIS().Clear();
502 //==============================================================================
503 //function : StandardModesActivation
504 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
506 //==============================================================================
507 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
509 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
511 if (TheAISContext()->HasOpenedContext())
512 aContext->CloseLocalContext();
515 if(!aContext->HasOpenedContext()) {
516 // To unhilight the preselected object
517 aContext->UnhilightSelected(Standard_False);
518 // Open a local Context in order to be able to select subshape from
519 // the selected shape if any or for all if there is no selection
520 if (!aContext->FirstSelectedObject().IsNull()){
521 aContext->OpenLocalContext(Standard_False);
523 for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
524 aContext->Load( aContext->SelectedInteractive(),-1,Standard_True);
528 aContext->OpenLocalContext();
531 const char *cmode="???";
534 case 0: cmode = "Shape"; break;
535 case 1: cmode = "Vertex"; break;
536 case 2: cmode = "Edge"; break;
537 case 3: cmode = "Wire"; break;
538 case 4: cmode = "Face"; break;
539 case 5: cmode = "Shell"; break;
540 case 6: cmode = "Solid"; break;
541 case 7: cmode = "Compsolid"; break;
542 case 8: cmode = "Compound"; break;
545 if(theactivatedmodes.Contains(mode))
547 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
548 theactivatedmodes.Remove(mode);
549 cout<<"Mode "<< cmode <<" OFF"<<endl;
553 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
554 theactivatedmodes.Add(mode);
555 cout<<"Mode "<< cmode << " ON" << endl;
560 //==============================================================================
561 //function : CopyIsoAspect
562 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
563 //==============================================================================
564 static Handle(Prs3d_IsoAspect) CopyIsoAspect
565 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
566 const Standard_Integer theNbIsos)
568 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
569 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
570 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
572 Handle(Prs3d_IsoAspect) aResult =
573 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
578 //==============================================================================
580 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
581 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
582 //==============================================================================
583 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
585 if (TheAISContext().IsNull()) {
586 di << argv[0] << " Call 'vinit' before!\n";
591 di << "Current number of isos : " <<
592 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
593 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
594 di << "IsoOnPlane mode is " <<
595 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
596 di << "IsoOnTriangulation mode is " <<
597 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
601 Standard_Integer aLastInd = argc - 1;
602 Standard_Boolean isChanged = Standard_False;
603 Standard_Integer aNbUIsos = 0;
604 Standard_Integer aNbVIsos = 0;
607 Standard_Boolean isIsoOnPlane = Standard_False;
609 if (strcmp(argv[aLastInd], "1") == 0) {
610 isIsoOnPlane = Standard_True;
611 isChanged = Standard_True;
612 } else if (strcmp(argv[aLastInd], "0") == 0) {
613 isIsoOnPlane = Standard_False;
614 isChanged = Standard_True;
618 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
619 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
622 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
623 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
625 TheAISContext()->IsoOnPlane(isIsoOnPlane);
628 // If there are no shapes provided set the default numbers.
629 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
630 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
637 for (i = 1; i <= aLastInd; i++) {
638 TCollection_AsciiString name(argv[i]);
639 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
642 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
643 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
644 const Handle(AIS_InteractiveObject) aShape =
645 Handle(AIS_InteractiveObject)::DownCast (anObj);
646 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
647 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
648 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
651 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
652 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
653 TheAISContext()->SetLocalAttributes
654 (aShape, CurDrawer, Standard_False);
655 TheAISContext()->Redisplay(aShape);
657 di << "Number of isos for " << argv[i] << " : "
658 << aUIso->Number() << " " << aVIso->Number() << "\n";
661 di << argv[i] << ": Not an AIS interactive object!\n";
664 di << argv[i] << ": Use 'vdisplay' before\n";
669 TheAISContext()->UpdateCurrentViewer();
675 static Standard_Integer VDispSensi (Draw_Interpretor& ,
676 Standard_Integer theArgNb,
681 std::cout << "Error: wrong syntax!\n";
685 Handle(AIS_InteractiveContext) aCtx;
686 Handle(V3d_View) aView;
687 if (!getCtxAndView (aCtx, aView))
692 aCtx->DisplayActiveSensitive (aView);
697 static Standard_Integer VClearSensi (Draw_Interpretor& ,
698 Standard_Integer theArgNb,
703 std::cout << "Error: wrong syntax!\n";
707 Handle(AIS_InteractiveContext) aCtx;
708 Handle(V3d_View) aView;
709 if (!getCtxAndView (aCtx, aView))
713 aCtx->ClearActiveSensitive (aView);
717 //==============================================================================
719 //purpose : To list the displayed object with their attributes
720 //==============================================================================
721 static int VDir (Draw_Interpretor& theDI,
725 if (!a3DView().IsNull())
730 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
731 anIter.More(); anIter.Next())
733 theDI << "\t" << anIter.Key2().ToCString() << "\n";
738 //! Auxiliary enumeration
739 enum ViewerTest_StereoPair
741 ViewerTest_SP_Single,
742 ViewerTest_SP_SideBySide,
743 ViewerTest_SP_OverUnder
746 //==============================================================================
748 //purpose : To dump the active view snapshot to image file
749 //==============================================================================
750 static Standard_Integer VDump (Draw_Interpretor& theDI,
751 Standard_Integer theArgNb,
752 Standard_CString* theArgVec)
756 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
760 Standard_Integer anArgIter = 1;
761 Standard_CString aFilePath = theArgVec[anArgIter++];
762 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
763 V3d_ImageDumpOptions aParams;
764 aParams.BufferType = Graphic3d_BT_RGB;
765 aParams.StereoOptions = V3d_SDO_MONO;
766 for (; anArgIter < theArgNb; ++anArgIter)
768 TCollection_AsciiString anArg (theArgVec[anArgIter]);
770 if (anArg == "-buffer")
772 if (++anArgIter >= theArgNb)
774 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
778 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
780 if (aBufArg == "rgba")
782 aParams.BufferType = Graphic3d_BT_RGBA;
784 else if (aBufArg == "rgb")
786 aParams.BufferType = Graphic3d_BT_RGB;
788 else if (aBufArg == "depth")
790 aParams.BufferType = Graphic3d_BT_Depth;
794 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
798 else if (anArg == "-stereo")
800 if (++anArgIter >= theArgNb)
802 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
806 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
807 aStereoArg.LowerCase();
808 if (aStereoArg == "l"
809 || aStereoArg == "left")
811 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
813 else if (aStereoArg == "r"
814 || aStereoArg == "right")
816 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
818 else if (aStereoArg == "mono")
820 aParams.StereoOptions = V3d_SDO_MONO;
822 else if (aStereoArg == "blended"
823 || aStereoArg == "blend"
824 || aStereoArg == "stereo")
826 aParams.StereoOptions = V3d_SDO_BLENDED;
828 else if (aStereoArg == "sbs"
829 || aStereoArg == "sidebyside")
831 aStereoPair = ViewerTest_SP_SideBySide;
833 else if (aStereoArg == "ou"
834 || aStereoArg == "overunder")
836 aStereoPair = ViewerTest_SP_OverUnder;
840 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
844 else if (anArg == "-rgba"
847 aParams.BufferType = Graphic3d_BT_RGBA;
849 else if (anArg == "-rgb"
852 aParams.BufferType = Graphic3d_BT_RGB;
854 else if (anArg == "-depth"
857 aParams.BufferType = Graphic3d_BT_Depth;
859 else if (anArg == "-width"
863 if (aParams.Width != 0)
865 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
868 else if (++anArgIter >= theArgNb)
870 std::cout << "Error: integer value is expected right after 'width'\n";
873 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
875 else if (anArg == "-height"
877 || anArg == "-sizey")
879 if (aParams.Height != 0)
881 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
884 else if (++anArgIter >= theArgNb)
886 std::cout << "Error: integer value is expected right after 'height'\n";
889 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
891 else if (anArg == "-tile"
892 || anArg == "-tilesize")
894 if (++anArgIter >= theArgNb)
896 std::cout << "Error: integer value is expected right after 'tileSize'\n";
899 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
903 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
907 if ((aParams.Width <= 0 && aParams.Height > 0)
908 || (aParams.Width > 0 && aParams.Height <= 0))
910 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
914 Handle(V3d_View) aView = ViewerTest::CurrentView();
917 std::cout << "Error: cannot find an active view!\n";
921 if (aParams.Width <= 0 || aParams.Height <= 0)
923 aView->Window()->Size (aParams.Width, aParams.Height);
926 Image_AlienPixMap aPixMap;
927 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
928 switch (aParams.BufferType)
930 case Graphic3d_BT_RGB: aFormat = Image_PixMap::ImgRGB; break;
931 case Graphic3d_BT_RGBA: aFormat = Image_PixMap::ImgRGBA; break;
932 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
937 case ViewerTest_SP_Single:
939 if (!aView->ToPixMap (aPixMap, aParams))
941 theDI << "Fail: view dump failed!\n";
944 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
945 || aPixMap.SizeY() != Standard_Size(aParams.Height))
947 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
948 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
952 case ViewerTest_SP_SideBySide:
954 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
956 theDI << "Fail: not enough memory for image allocation!\n";
960 Image_PixMap aPixMapL, aPixMapR;
961 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
962 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
963 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
964 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
966 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
967 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
968 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
969 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
972 theDI << "Fail: view dump failed!\n";
977 case ViewerTest_SP_OverUnder:
979 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
981 theDI << "Fail: not enough memory for image allocation!\n";
985 Image_PixMap aPixMapL, aPixMapR;
986 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
987 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
988 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
989 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
991 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
992 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
993 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
994 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
997 theDI << "Fail: view dump failed!\n";
1004 if (!aPixMap.Save (aFilePath))
1006 theDI << "Fail: image can not be saved!\n";
1011 enum TypeOfDispOperation
1013 TypeOfDispOperation_SetDispMode,
1014 TypeOfDispOperation_UnsetDispMode
1017 //! Displays,Erase...
1018 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1019 const Standard_Integer theMode,
1020 const TypeOfDispOperation theType,
1021 const Standard_Boolean theToUpdate)
1023 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1026 case TypeOfDispOperation_SetDispMode:
1028 if (!thePrs.IsNull())
1030 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1034 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1038 case TypeOfDispOperation_UnsetDispMode:
1040 if (!thePrs.IsNull())
1042 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1046 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1053 //=======================================================================
1056 //=======================================================================
1057 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1062 std::cout << "Syntax error: wrong number of arguments\n";
1066 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1067 ? TypeOfDispOperation_UnsetDispMode
1068 : TypeOfDispOperation_SetDispMode;
1069 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1070 if (aType == TypeOfDispOperation_UnsetDispMode)
1074 if (aCtx->NbSelected() == 0)
1076 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1080 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1082 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1085 aCtx->UpdateCurrentViewer();
1089 TCollection_AsciiString aName = argv[1];
1090 if (GetMapOfAIS().IsBound2 (aName))
1092 Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1095 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1102 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1103 if (aCtx->NbSelected() == 0
1104 && aType == TypeOfDispOperation_SetDispMode)
1106 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1108 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1110 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1112 aCtx->UpdateCurrentViewer();
1116 Handle(AIS_InteractiveObject) aPrs;
1117 TCollection_AsciiString aName (argv[1]);
1118 if (GetMapOfAIS().IsBound2 (aName))
1120 aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1124 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, 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 Standard_Integer ToSetSensitivity;
1478 Standard_Integer SelectionMode;
1479 Standard_Integer Sensitivity;
1481 //! Empty constructor
1482 ViewerTest_AspectsChangeSet()
1483 : ToSetVisibility (0),
1486 Color (DEFAULT_COLOR),
1489 ToSetTypeOfLine (0),
1490 TypeOfLine (Aspect_TOL_SOLID),
1491 ToSetTransparency (0),
1494 Material (Graphic3d_NOM_DEFAULT),
1495 ToSetShowFreeBoundary (0),
1496 ToSetFreeBoundaryWidth (0),
1497 FreeBoundaryWidth (1.0),
1498 ToSetFreeBoundaryColor (0),
1499 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1500 ToEnableIsoOnTriangulation (-1),
1501 ToSetMaxParamValue (0),
1502 MaxParamValue (500000),
1503 ToSetSensitivity (0),
1507 //! @return true if no changes have been requested
1508 Standard_Boolean IsEmpty() const
1510 return ToSetVisibility == 0
1511 && ToSetLineWidth == 0
1512 && ToSetTransparency == 0
1514 && ToSetMaterial == 0
1515 && ToSetShowFreeBoundary == 0
1516 && ToSetFreeBoundaryColor == 0
1517 && ToSetFreeBoundaryWidth == 0
1518 && ToSetMaxParamValue == 0
1519 && ToSetSensitivity == 0;
1522 //! @return true if properties are valid
1523 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1525 Standard_Boolean isOk = Standard_True;
1526 if (Visibility != 0 && Visibility != 1)
1528 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1529 isOk = Standard_False;
1531 if (LineWidth <= 0.0
1532 || LineWidth > 10.0)
1534 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1535 isOk = Standard_False;
1537 if (Transparency < 0.0
1538 || Transparency > 1.0)
1540 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1541 isOk = Standard_False;
1544 && ToSetTransparency)
1546 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1547 isOk = Standard_False;
1549 if (ToSetMaterial == 1
1550 && Material == Graphic3d_NOM_DEFAULT)
1552 std::cout << "Error: unknown material " << MatName << ".\n";
1553 isOk = Standard_False;
1555 if (FreeBoundaryWidth <= 0.0
1556 || FreeBoundaryWidth > 10.0)
1558 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1559 isOk = Standard_False;
1561 if (MaxParamValue < 0.0)
1563 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1564 isOk = Standard_False;
1566 if (Sensitivity <= 0 && ToSetSensitivity)
1568 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1569 isOk = Standard_False;
1576 //==============================================================================
1577 //function : VAspects
1579 //==============================================================================
1580 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1581 Standard_Integer theArgNb,
1582 const char** theArgVec)
1584 TCollection_AsciiString aCmdName (theArgVec[0]);
1585 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1586 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1589 std::cerr << "Error: no active view!\n";
1593 Standard_Integer anArgIter = 1;
1594 Standard_Boolean isDefaults = Standard_False;
1595 NCollection_Sequence<TCollection_AsciiString> aNames;
1596 for (; anArgIter < theArgNb; ++anArgIter)
1598 TCollection_AsciiString anArg = theArgVec[anArgIter];
1599 if (anUpdateTool.parseRedrawMode (anArg))
1603 else if (!anArg.IsEmpty()
1604 && anArg.Value (1) != '-')
1606 aNames.Append (anArg);
1610 if (anArg == "-defaults")
1612 isDefaults = Standard_True;
1619 if (!aNames.IsEmpty() && isDefaults)
1621 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1625 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1626 aChanges.Append (ViewerTest_AspectsChangeSet());
1627 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1629 // parse syntax of legacy commands
1630 if (aCmdName == "vsetwidth")
1632 if (aNames.IsEmpty()
1633 || !aNames.Last().IsRealValue())
1635 std::cout << "Error: not enough arguments!\n";
1638 aChangeSet->ToSetLineWidth = 1;
1639 aChangeSet->LineWidth = aNames.Last().RealValue();
1640 aNames.Remove (aNames.Length());
1642 else if (aCmdName == "vunsetwidth")
1644 aChangeSet->ToSetLineWidth = -1;
1646 else if (aCmdName == "vsetcolor")
1648 if (aNames.IsEmpty())
1650 std::cout << "Error: not enough arguments!\n";
1653 aChangeSet->ToSetColor = 1;
1655 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1656 Standard_Boolean isOk = Standard_False;
1657 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1659 aChangeSet->Color = aColor;
1660 aNames.Remove (aNames.Length());
1661 isOk = Standard_True;
1663 else if (aNames.Length() >= 3)
1665 const TCollection_AsciiString anRgbStr[3] =
1667 aNames.Value (aNames.Upper() - 2),
1668 aNames.Value (aNames.Upper() - 1),
1669 aNames.Value (aNames.Upper() - 0)
1671 isOk = anRgbStr[0].IsRealValue()
1672 && anRgbStr[1].IsRealValue()
1673 && anRgbStr[2].IsRealValue();
1676 Graphic3d_Vec4d anRgb;
1677 anRgb.x() = anRgbStr[0].RealValue();
1678 anRgb.y() = anRgbStr[1].RealValue();
1679 anRgb.z() = anRgbStr[2].RealValue();
1680 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1681 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1682 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1684 std::cout << "Error: RGB color values should be within range 0..1!\n";
1687 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1688 aNames.Remove (aNames.Length());
1689 aNames.Remove (aNames.Length());
1690 aNames.Remove (aNames.Length());
1695 std::cout << "Error: not enough arguments!\n";
1699 else if (aCmdName == "vunsetcolor")
1701 aChangeSet->ToSetColor = -1;
1703 else if (aCmdName == "vsettransparency")
1705 if (aNames.IsEmpty()
1706 || !aNames.Last().IsRealValue())
1708 std::cout << "Error: not enough arguments!\n";
1711 aChangeSet->ToSetTransparency = 1;
1712 aChangeSet->Transparency = aNames.Last().RealValue();
1713 aNames.Remove (aNames.Length());
1715 else if (aCmdName == "vunsettransparency")
1717 aChangeSet->ToSetTransparency = -1;
1719 else if (aCmdName == "vsetmaterial")
1721 if (aNames.IsEmpty())
1723 std::cout << "Error: not enough arguments!\n";
1726 aChangeSet->ToSetMaterial = 1;
1727 aChangeSet->MatName = aNames.Last();
1728 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1729 aNames.Remove (aNames.Length());
1731 else if (aCmdName == "vunsetmaterial")
1733 aChangeSet->ToSetMaterial = -1;
1735 else if (anArgIter >= theArgNb)
1737 std::cout << "Error: not enough arguments!\n";
1741 if (!aChangeSet->IsEmpty())
1743 anArgIter = theArgNb;
1745 for (; anArgIter < theArgNb; ++anArgIter)
1747 TCollection_AsciiString anArg = theArgVec[anArgIter];
1749 if (anArg == "-setwidth"
1750 || anArg == "-setlinewidth")
1752 if (++anArgIter >= theArgNb)
1754 std::cout << "Error: wrong syntax at " << anArg << "\n";
1757 aChangeSet->ToSetLineWidth = 1;
1758 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1760 else if (anArg == "-unsetwidth"
1761 || anArg == "-unsetlinewidth")
1763 aChangeSet->ToSetLineWidth = -1;
1764 aChangeSet->LineWidth = 1.0;
1766 else if (anArg == "-settransp"
1767 || anArg == "-settransparency")
1769 if (++anArgIter >= theArgNb)
1771 std::cout << "Error: wrong syntax at " << anArg << "\n";
1774 aChangeSet->ToSetTransparency = 1;
1775 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1776 if (aChangeSet->Transparency >= 0.0
1777 && aChangeSet->Transparency <= Precision::Confusion())
1779 aChangeSet->ToSetTransparency = -1;
1780 aChangeSet->Transparency = 0.0;
1783 else if (anArg == "-setvis"
1784 || anArg == "-setvisibility")
1786 if (++anArgIter >= theArgNb)
1788 std::cout << "Error: wrong syntax at " << anArg << "\n";
1792 aChangeSet->ToSetVisibility = 1;
1793 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1795 else if (anArg == "-setalpha")
1797 if (++anArgIter >= theArgNb)
1799 std::cout << "Error: wrong syntax at " << anArg << "\n";
1802 aChangeSet->ToSetTransparency = 1;
1803 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1804 if (aChangeSet->Transparency < 0.0
1805 || aChangeSet->Transparency > 1.0)
1807 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1810 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1811 if (aChangeSet->Transparency >= 0.0
1812 && aChangeSet->Transparency <= Precision::Confusion())
1814 aChangeSet->ToSetTransparency = -1;
1815 aChangeSet->Transparency = 0.0;
1818 else if (anArg == "-unsettransp"
1819 || anArg == "-unsettransparency"
1820 || anArg == "-unsetalpha"
1821 || anArg == "-opaque")
1823 aChangeSet->ToSetTransparency = -1;
1824 aChangeSet->Transparency = 0.0;
1826 else if (anArg == "-setcolor")
1828 Standard_Integer aNbComps = 0;
1829 Standard_Integer aCompIter = anArgIter + 1;
1830 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1832 if (theArgVec[aCompIter][0] == '-')
1841 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1842 Standard_CString aName = theArgVec[anArgIter + 1];
1843 if (!Quantity_Color::ColorFromName (aName, aColor))
1845 std::cout << "Error: unknown color name '" << aName << "'\n";
1848 aChangeSet->Color = aColor;
1853 Graphic3d_Vec3d anRgb;
1854 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1855 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1856 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1857 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1858 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1859 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1861 std::cout << "Error: RGB color values should be within range 0..1!\n";
1864 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1869 std::cout << "Error: wrong syntax at " << anArg << "\n";
1873 aChangeSet->ToSetColor = 1;
1874 anArgIter += aNbComps;
1876 else if (anArg == "-setlinetype")
1878 if (++anArgIter >= theArgNb)
1880 std::cout << "Error: wrong syntax at " << anArg << "\n";
1884 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1887 if (aValue.IsEqual ("solid"))
1889 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1891 else if (aValue.IsEqual ("dot"))
1893 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1895 else if (aValue.IsEqual ("dash"))
1897 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1899 else if (aValue.IsEqual ("dotdash"))
1901 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1905 std::cout << "Error: wrong syntax at " << anArg << "\n";
1909 aChangeSet->ToSetTypeOfLine = 1;
1911 else if (anArg == "-unsetlinetype")
1913 aChangeSet->ToSetTypeOfLine = -1;
1915 else if (anArg == "-unsetcolor")
1917 aChangeSet->ToSetColor = -1;
1918 aChangeSet->Color = DEFAULT_COLOR;
1920 else if (anArg == "-setmat"
1921 || anArg == "-setmaterial")
1923 if (++anArgIter >= theArgNb)
1925 std::cout << "Error: wrong syntax at " << anArg << "\n";
1928 aChangeSet->ToSetMaterial = 1;
1929 aChangeSet->MatName = theArgVec[anArgIter];
1930 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1932 else if (anArg == "-unsetmat"
1933 || anArg == "-unsetmaterial")
1935 aChangeSet->ToSetMaterial = -1;
1936 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1938 else if (anArg == "-subshape"
1939 || anArg == "-subshapes")
1943 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1947 if (aNames.IsEmpty())
1949 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1953 aChanges.Append (ViewerTest_AspectsChangeSet());
1954 aChangeSet = &aChanges.ChangeLast();
1956 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1958 Standard_CString aSubShapeName = theArgVec[anArgIter];
1959 if (*aSubShapeName == '-')
1965 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1966 if (aSubShape.IsNull())
1968 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1971 aChangeSet->SubShapes.Append (aSubShape);
1974 if (aChangeSet->SubShapes.IsEmpty())
1976 std::cerr << "Error: empty list is specified after -subshapes!\n";
1980 else if (anArg == "-freeboundary"
1983 if (++anArgIter >= theArgNb)
1985 std::cout << "Error: wrong syntax at " << anArg << "\n";
1988 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1993 aChangeSet->ToSetShowFreeBoundary = 1;
1995 else if (aValue == "off"
1998 aChangeSet->ToSetShowFreeBoundary = -1;
2002 std::cout << "Error: wrong syntax at " << anArg << "\n";
2006 else if (anArg == "-setfreeboundarywidth"
2007 || anArg == "-setfbwidth")
2009 if (++anArgIter >= theArgNb)
2011 std::cout << "Error: wrong syntax at " << anArg << "\n";
2014 aChangeSet->ToSetFreeBoundaryWidth = 1;
2015 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2017 else if (anArg == "-unsetfreeboundarywidth"
2018 || anArg == "-unsetfbwidth")
2020 aChangeSet->ToSetFreeBoundaryWidth = -1;
2021 aChangeSet->FreeBoundaryWidth = 1.0;
2023 else if (anArg == "-setfreeboundarycolor"
2024 || anArg == "-setfbcolor")
2026 Standard_Integer aNbComps = 0;
2027 Standard_Integer aCompIter = anArgIter + 1;
2028 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2030 if (theArgVec[aCompIter][0] == '-')
2039 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2040 Standard_CString aName = theArgVec[anArgIter + 1];
2041 if (!Quantity_Color::ColorFromName (aName, aColor))
2043 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2046 aChangeSet->FreeBoundaryColor = aColor;
2051 Graphic3d_Vec3d anRgb;
2052 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2053 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2054 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2055 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2056 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2057 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2059 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2062 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2067 std::cout << "Error: wrong syntax at " << anArg << "\n";
2071 aChangeSet->ToSetFreeBoundaryColor = 1;
2072 anArgIter += aNbComps;
2074 else if (anArg == "-unsetfreeboundarycolor"
2075 || anArg == "-unsetfbcolor")
2077 aChangeSet->ToSetFreeBoundaryColor = -1;
2078 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2080 else if (anArg == "-unset")
2082 aChangeSet->ToSetVisibility = 1;
2083 aChangeSet->Visibility = 1;
2084 aChangeSet->ToSetLineWidth = -1;
2085 aChangeSet->LineWidth = 1.0;
2086 aChangeSet->ToSetTypeOfLine = -1;
2087 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2088 aChangeSet->ToSetTransparency = -1;
2089 aChangeSet->Transparency = 0.0;
2090 aChangeSet->ToSetColor = -1;
2091 aChangeSet->Color = DEFAULT_COLOR;
2092 aChangeSet->ToSetMaterial = -1;
2093 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2094 aChangeSet->ToSetShowFreeBoundary = -1;
2095 aChangeSet->ToSetFreeBoundaryColor = -1;
2096 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2097 aChangeSet->ToSetFreeBoundaryWidth = -1;
2098 aChangeSet->FreeBoundaryWidth = 1.0;
2100 else if (anArg == "-isoontriangulation"
2101 || anArg == "-isoontriang")
2103 if (++anArgIter >= theArgNb)
2105 std::cout << "Error: wrong syntax at " << anArg << "\n";
2108 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2113 aChangeSet->ToEnableIsoOnTriangulation = 1;
2115 else if (aValue == "off"
2118 aChangeSet->ToEnableIsoOnTriangulation = 0;
2122 std::cout << "Error: wrong syntax at " << anArg << "\n";
2126 else if (anArg == "-setmaxparamvalue")
2128 if (++anArgIter >= theArgNb)
2130 std::cout << "Error: wrong syntax at " << anArg << "\n";
2133 aChangeSet->ToSetMaxParamValue = 1;
2134 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2136 else if (anArg == "-setsensitivity")
2140 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2144 if (aNames.IsEmpty())
2146 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2150 if (anArgIter + 2 >= theArgNb)
2152 std::cout << "Error: wrong syntax at " << anArg << "\n";
2155 aChangeSet->ToSetSensitivity = 1;
2156 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2157 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2161 std::cout << "Error: wrong syntax at " << anArg << "\n";
2166 Standard_Boolean isFirst = Standard_True;
2167 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2168 aChangesIter.More(); aChangesIter.Next())
2170 if (!aChangesIter.Value().Validate (!isFirst))
2174 isFirst = Standard_False;
2177 if (aCtx->HasOpenedContext())
2179 aCtx->CloseLocalContext();
2182 // special case for -defaults parameter.
2183 // all changed values will be set to DefaultDrawer.
2186 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2188 if (aChangeSet->ToSetLineWidth != 0)
2190 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2191 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2192 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2193 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2195 if (aChangeSet->ToSetColor != 0)
2197 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2198 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2199 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2200 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2201 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2202 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2204 if (aChangeSet->ToSetTypeOfLine != 0)
2206 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2207 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2208 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2209 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2210 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2212 if (aChangeSet->ToSetTransparency != 0)
2214 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2216 if (aChangeSet->ToSetMaterial != 0)
2218 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2220 if (aChangeSet->ToSetShowFreeBoundary == 1)
2222 aDrawer->SetFreeBoundaryDraw (Standard_True);
2224 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2226 aDrawer->SetFreeBoundaryDraw (Standard_False);
2228 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2230 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2232 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2234 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2236 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2238 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2240 if (aChangeSet->ToSetMaxParamValue != 0)
2242 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2245 // redisplay all objects in context
2246 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2248 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2251 aCtx->Redisplay (aPrs, Standard_False);
2257 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2259 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2260 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2261 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2262 Handle(AIS_ColoredShape) aColoredPrs;
2263 Standard_Boolean toDisplay = Standard_False;
2264 Standard_Boolean toRedisplay = Standard_False;
2265 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2267 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2268 if (aShapePrs.IsNull())
2270 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2273 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2274 if (aColoredPrs.IsNull())
2276 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2277 if (aShapePrs->HasDisplayMode())
2279 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2281 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2282 aCtx->Remove (aShapePrs, Standard_False);
2283 GetMapOfAIS().UnBind2 (aName);
2284 GetMapOfAIS().Bind (aColoredPrs, aName);
2285 toDisplay = Standard_True;
2286 aShapePrs = aColoredPrs;
2293 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2294 aChangeSet = &aChangesIter.ChangeValue();
2295 if (aChangeSet->ToSetVisibility == 1)
2297 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2298 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2300 else if (aChangeSet->ToSetMaterial == 1)
2302 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2304 else if (aChangeSet->ToSetMaterial == -1)
2306 aCtx->UnsetMaterial (aPrs, Standard_False);
2308 if (aChangeSet->ToSetColor == 1)
2310 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2312 else if (aChangeSet->ToSetColor == -1)
2314 aCtx->UnsetColor (aPrs, Standard_False);
2316 if (aChangeSet->ToSetTransparency == 1)
2318 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2320 else if (aChangeSet->ToSetTransparency == -1)
2322 aCtx->UnsetTransparency (aPrs, Standard_False);
2324 if (aChangeSet->ToSetLineWidth == 1)
2326 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2328 else if (aChangeSet->ToSetLineWidth == -1)
2330 aCtx->UnsetWidth (aPrs, Standard_False);
2332 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2334 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2335 toRedisplay = Standard_True;
2337 else if (aChangeSet->ToSetSensitivity != 0)
2339 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2341 if (!aDrawer.IsNull())
2343 if (aChangeSet->ToSetShowFreeBoundary == 1)
2345 aDrawer->SetFreeBoundaryDraw (Standard_True);
2346 toRedisplay = Standard_True;
2348 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2350 aDrawer->SetFreeBoundaryDraw (Standard_False);
2351 toRedisplay = Standard_True;
2353 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2355 Handle(Prs3d_LineAspect) aBoundaryAspect =
2356 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2357 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2358 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2359 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2360 toRedisplay = Standard_True;
2362 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2364 Handle(Prs3d_LineAspect) aBoundaryAspect =
2365 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2366 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2367 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2368 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2369 toRedisplay = Standard_True;
2371 if (aChangeSet->ToSetTypeOfLine != 0)
2373 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2374 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2375 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2376 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2377 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2378 toRedisplay = Standard_True;
2380 if (aChangeSet->ToSetMaxParamValue != 0)
2382 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2386 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2388 aChangeSet = &aChangesIter.ChangeValue();
2389 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2390 aSubShapeIter.More(); aSubShapeIter.Next())
2392 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2393 if (aChangeSet->ToSetVisibility == 1)
2395 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2396 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2398 if (aChangeSet->ToSetColor == 1)
2400 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2402 if (aChangeSet->ToSetLineWidth == 1)
2404 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2406 if (aChangeSet->ToSetColor == -1
2407 || aChangeSet->ToSetLineWidth == -1)
2409 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2411 if (aChangeSet->ToSetMaxParamValue != 0)
2413 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2414 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2416 if (aChangeSet->ToSetSensitivity != 0)
2418 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2424 aCtx->Display (aPrs, Standard_False);
2428 aCtx->Redisplay (aPrs, Standard_False);
2430 else if (!aColoredPrs.IsNull())
2432 aCtx->Redisplay (aColoredPrs, Standard_False);
2439 //==============================================================================
2440 //function : VDonly2
2442 //purpose : Display only a selected or named object
2443 // if there is no selected or named object s, nothing is done
2444 //==============================================================================
2445 static int VDonly2 (Draw_Interpretor& ,
2446 Standard_Integer theArgNb,
2447 const char** theArgVec)
2449 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2450 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2453 std::cerr << "Error: no active view!\n";
2457 if (aCtx->HasOpenedContext())
2459 aCtx->CloseLocalContext();
2462 Standard_Integer anArgIter = 1;
2463 for (; anArgIter < theArgNb; ++anArgIter)
2465 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2471 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2472 if (anArgIter >= theArgNb)
2474 // display only selected objects
2475 if (aCtx->NbSelected() < 1)
2480 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2482 aDispSet.Add (aCtx->SelectedInteractive());
2487 // display only specified objects
2488 for (; anArgIter < theArgNb; ++anArgIter)
2490 TCollection_AsciiString aName = theArgVec[anArgIter];
2491 if (GetMapOfAIS().IsBound2 (aName))
2493 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2494 if (!aShape.IsNull())
2496 aCtx->Display (aShape, Standard_False);
2497 aDispSet.Add (aShape);
2503 // weed out other objects
2504 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2506 if (aDispSet.Contains (anIter.Key1()))
2511 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2512 if (aShape.IsNull())
2514 aCtx->Erase (aShape, Standard_False);
2520 //==============================================================================
2521 //function : VRemove
2522 //purpose : Removes selected or named objects.
2523 // If there is no selected or named objects,
2524 // all objects in the viewer can be removed with argument -all.
2525 // If -context is in arguments, the object is not deleted from the map of
2526 // objects (deleted only from the current context).
2527 //==============================================================================
2528 int VRemove (Draw_Interpretor& theDI,
2529 Standard_Integer theArgNb,
2530 const char** theArgVec)
2532 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2533 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2536 std::cerr << "Error: no active view!\n";
2540 Standard_Boolean isContextOnly = Standard_False;
2541 Standard_Boolean toRemoveAll = Standard_False;
2542 Standard_Boolean toPrintInfo = Standard_True;
2543 Standard_Boolean toRemoveLocal = Standard_False;
2545 Standard_Integer anArgIter = 1;
2546 for (; anArgIter < theArgNb; ++anArgIter)
2548 TCollection_AsciiString anArg = theArgVec[anArgIter];
2550 if (anArg == "-context")
2552 isContextOnly = Standard_True;
2554 else if (anArg == "-all")
2556 toRemoveAll = Standard_True;
2558 else if (anArg == "-noinfo")
2560 toPrintInfo = Standard_False;
2562 else if (anArg == "-local")
2564 toRemoveLocal = Standard_True;
2566 else if (anUpdateTool.parseRedrawMode (anArg))
2576 && anArgIter < theArgNb)
2578 std::cerr << "Error: wrong syntax!\n";
2582 if (toRemoveLocal && !aCtx->HasOpenedContext())
2584 std::cerr << "Error: local selection context is not open.\n";
2587 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2589 aCtx->CloseAllContexts (Standard_False);
2592 NCollection_List<TCollection_AsciiString> anIONameList;
2595 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2596 anIter.More(); anIter.Next())
2598 anIONameList.Append (anIter.Key2());
2601 else if (anArgIter < theArgNb) // removed objects names are in argument list
2603 for (; anArgIter < theArgNb; ++anArgIter)
2605 TCollection_AsciiString aName = theArgVec[anArgIter];
2606 if (!GetMapOfAIS().IsBound2 (aName))
2608 theDI << aName.ToCString() << " was not bound to some object.\n";
2612 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2613 if (anIO->GetContext() != aCtx)
2615 theDI << aName.ToCString() << " was not displayed in current context.\n";
2616 theDI << "Please activate view with this object displayed and try again.\n";
2620 anIONameList.Append (aName);
2624 else if (aCtx->NbSelected() > 0)
2626 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2627 anIter.More(); anIter.Next())
2629 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2630 if (!aCtx->IsSelected (anIO))
2635 anIONameList.Append (anIter.Key2());
2640 // Unbind all removed objects from the map of displayed IO.
2641 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2642 anIter.More(); anIter.Next())
2644 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2645 aCtx->Remove (anIO, Standard_False);
2648 theDI << anIter.Value().ToCString() << " was removed\n";
2652 GetMapOfAIS().UnBind2 (anIter.Value());
2656 // Close local context if it is empty
2657 TColStd_MapOfTransient aLocalIO;
2658 if (aCtx->HasOpenedContext()
2659 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2661 aCtx->CloseAllContexts (Standard_False);
2667 //==============================================================================
2669 //purpose : Erase some selected or named objects
2670 // if there is no selected or named objects, the whole viewer is erased
2671 //==============================================================================
2672 int VErase (Draw_Interpretor& theDI,
2673 Standard_Integer theArgNb,
2674 const char** theArgVec)
2676 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2677 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2678 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2681 std::cerr << "Error: no active view!\n";
2685 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2687 Standard_Integer anArgIter = 1;
2688 Standard_Boolean toEraseLocal = Standard_False;
2689 Standard_Boolean toEraseInView = Standard_False;
2690 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2691 for (; anArgIter < theArgNb; ++anArgIter)
2693 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2694 anArgCase.LowerCase();
2695 if (anUpdateTool.parseRedrawMode (anArgCase))
2699 else if (anArgCase == "-local")
2701 toEraseLocal = Standard_True;
2703 else if (anArgCase == "-view"
2704 || anArgCase == "-inview")
2706 toEraseInView = Standard_True;
2710 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2714 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2716 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2720 if (toEraseLocal && !aCtx->HasOpenedContext())
2722 std::cerr << "Error: local selection context is not open.\n";
2725 else if (!toEraseLocal && aCtx->HasOpenedContext())
2727 aCtx->CloseAllContexts (Standard_False);
2730 if (!aNamesOfEraseIO.IsEmpty())
2732 // Erase named objects
2733 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2735 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2736 if (!GetMapOfAIS().IsBound2 (aName))
2741 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2742 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2743 theDI << aName.ToCString() << " ";
2748 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2752 aCtx->Erase (anIO, Standard_False);
2757 else if (!toEraseAll && aCtx->NbSelected() > 0)
2759 // Erase selected objects
2760 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
2761 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2762 anIter.More(); anIter.Next())
2764 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2766 && aCtx->IsSelected (anIO))
2768 theDI << anIter.Key2().ToCString() << " ";
2771 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2773 else if (aHasOpenedContext)
2775 aCtx->Erase (anIO, Standard_False);
2782 aCtx->EraseSelected (Standard_False);
2787 // Erase all objects
2788 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2789 anIter.More(); anIter.Next())
2791 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2796 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2800 aCtx->Erase (anIO, Standard_False);
2809 //==============================================================================
2810 //function : VDisplayAll
2812 //purpose : Display all the objects of the Map
2813 //==============================================================================
2814 static int VDisplayAll (Draw_Interpretor& ,
2815 Standard_Integer theArgNb,
2816 const char** theArgVec)
2819 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2820 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2823 std::cerr << "Error: no active view!\n";
2827 Standard_Integer anArgIter = 1;
2828 Standard_Boolean toDisplayLocal = Standard_False;
2829 for (; anArgIter < theArgNb; ++anArgIter)
2831 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2832 anArgCase.LowerCase();
2833 if (anArgCase == "-local")
2835 toDisplayLocal = Standard_True;
2837 else if (anUpdateTool.parseRedrawMode (anArgCase))
2846 if (anArgIter < theArgNb)
2848 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2852 if (toDisplayLocal && !aCtx->HasOpenedContext())
2854 std::cerr << "Error: local selection context is not open.\n";
2857 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2859 aCtx->CloseLocalContext (Standard_False);
2862 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2863 anIter.More(); anIter.Next())
2865 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2866 aCtx->Erase (aShape, Standard_False);
2869 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2870 anIter.More(); anIter.Next())
2872 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2873 aCtx->Display (aShape, Standard_False);
2878 //! Auxiliary method to check if presentation exists
2879 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
2880 const Handle(AIS_InteractiveObject)& theIO,
2881 const Standard_Integer theMode)
2883 if (theIO.IsNull() || theCtx.IsNull())
2890 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2895 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2897 return theIO->DisplayMode();
2899 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2901 return theCtx->DisplayMode();
2907 enum ViewerTest_BndAction
2914 //! Auxiliary method to print bounding box of presentation
2915 inline void bndPresentation (Draw_Interpretor& theDI,
2916 const Handle(PrsMgr_PresentationManager)& theMgr,
2917 const Handle(AIS_InteractiveObject)& theObj,
2918 const Standard_Integer theDispMode,
2919 const TCollection_AsciiString& theName,
2920 const ViewerTest_BndAction theAction,
2921 const Handle(Graphic3d_HighlightStyle)& theStyle)
2925 case BndAction_Hide:
2927 theMgr->Unhighlight (theObj, theDispMode);
2930 case BndAction_Show:
2932 theMgr->Color (theObj, theStyle, theDispMode);
2935 case BndAction_Print:
2938 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
2940 if (aPrsIter.Value().Mode() != theDispMode)
2943 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
2945 gp_Pnt aMin = aBox.CornerMin();
2946 gp_Pnt aMax = aBox.CornerMax();
2947 theDI << theName << "\n"
2948 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2949 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2955 //==============================================================================
2956 //function : VBounding
2958 //==============================================================================
2959 int VBounding (Draw_Interpretor& theDI,
2960 Standard_Integer theArgNb,
2961 const char** theArgVec)
2963 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2964 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2967 std::cout << "Error: no active view!\n";
2971 ViewerTest_BndAction anAction = BndAction_Show;
2972 Standard_Integer aMode = -1;
2974 Handle(Graphic3d_HighlightStyle) aStyle;
2976 Standard_Integer anArgIter = 1;
2977 for (; anArgIter < theArgNb; ++anArgIter)
2979 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2981 if (anArg == "-print")
2983 anAction = BndAction_Print;
2985 else if (anArg == "-show")
2987 anAction = BndAction_Show;
2989 else if (anArg == "-hide")
2991 anAction = BndAction_Hide;
2993 else if (anArg == "-mode")
2995 if (++anArgIter >= theArgNb)
2997 std::cout << "Error: wrong syntax at " << anArg << "\n";
3000 aMode = Draw::Atoi (theArgVec[anArgIter]);
3002 else if (!anUpdateTool.parseRedrawMode (anArg))
3008 if (anAction == BndAction_Show)
3009 aStyle = new Graphic3d_HighlightStyle (Aspect_TOHM_BOUNDBOX, Quantity_NOC_GRAY99, 0.0);
3011 Standard_Integer aHighlightedMode = -1;
3012 if (anArgIter < theArgNb)
3014 // has a list of names
3015 for (; anArgIter < theArgNb; ++anArgIter)
3017 TCollection_AsciiString aName = theArgVec[anArgIter];
3018 if (!GetMapOfAIS().IsBound2 (aName))
3020 std::cout << "Error: presentation " << aName << " does not exist\n";
3024 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3025 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3026 if (aHighlightedMode == -1)
3028 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3031 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3034 else if (aCtx->NbSelected() > 0)
3036 // remove all currently selected objects
3037 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3039 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3040 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3041 if (aHighlightedMode != -1)
3043 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3044 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3051 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3052 anIter.More(); anIter.Next())
3054 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3055 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3056 if (aHighlightedMode != -1)
3058 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3065 //==============================================================================
3066 //function : VTexture
3068 //==============================================================================
3069 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
3071 TCollection_AsciiString aCommandName (theArgv[0]);
3073 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3074 if (aCommandName == "vtexture")
3078 std::cout << theArgv[0] << ": invalid arguments.\n";
3079 std::cout << "Type help for more information.\n";
3083 // look for options of vtexture command
3084 TCollection_AsciiString aParseKey;
3085 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3087 TCollection_AsciiString anArg (theArgv [anArgIt]);
3090 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3093 aParseKey.Remove (1);
3094 aParseKey.UpperCase();
3095 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3099 if (aParseKey.IsEmpty())
3104 aMapOfArgs(aParseKey)->Append (anArg);
3107 else if (aCommandName == "vtexscale"
3108 || aCommandName == "vtexorigin"
3109 || aCommandName == "vtexrepeat")
3111 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3112 // equal to -scale, -origin, -repeat options of vtexture command
3113 if (theArgsNb < 2 || theArgsNb > 4)
3115 std::cout << theArgv[0] << ": invalid arguments.\n";
3116 std::cout << "Type help for more information.\n";
3120 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
3123 anArgs->Append ("OFF");
3125 else if (theArgsNb == 4)
3127 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3128 anArgs->Append (TCollection_AsciiString (theArgv[3]));
3131 TCollection_AsciiString anArgKey;
3132 if (aCommandName == "vtexscale")
3136 else if (aCommandName == "vtexorigin")
3138 anArgKey = "ORIGIN";
3142 anArgKey = "REPEAT";
3145 aMapOfArgs.Bind (anArgKey, anArgs);
3147 else if (aCommandName == "vtexdefault")
3149 // scan for parameters of vtexdefault command
3150 // equal to -default option of vtexture command
3151 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
3154 // Check arguments for validity
3155 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3156 for (; aMapIt.More(); aMapIt.Next())
3158 const TCollection_AsciiString& aKey = aMapIt.Key();
3159 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3161 // -scale, -origin, -repeat: one argument "off", or two real values
3162 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3163 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3164 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3169 // -modulate: single argument "on" / "off"
3170 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3175 // -default: no arguments
3176 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3181 TCollection_AsciiString aLowerKey;
3184 aLowerKey.LowerCase();
3185 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3186 std::cout << "Type help for more information.\n";
3190 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3191 if (anAISContext.IsNull())
3193 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
3197 Standard_Integer aPreviousMode = 0;
3199 TCollection_AsciiString aShapeName (theArgv[1]);
3200 Handle(AIS_InteractiveObject) anIO;
3202 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3203 if (aMapOfIO.IsBound2 (aShapeName))
3205 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3210 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3214 Handle(AIS_TexturedShape) aTexturedIO;
3215 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3217 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3218 aPreviousMode = aTexturedIO->DisplayMode();
3222 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3224 if (anIO->HasTransformation())
3226 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3227 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3230 anAISContext->Remove (anIO, Standard_False);
3231 GetMapOfAIS().UnBind1 (anIO);
3232 GetMapOfAIS().UnBind2 (aShapeName);
3233 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3236 // -------------------------------------------
3237 // Turn texturing on/off - only for vtexture
3238 // -------------------------------------------
3240 if (aCommandName == "vtexture")
3242 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3244 if (aTextureArg.IsEmpty())
3246 std::cout << aCommandName << ": Texture mapping disabled.\n";
3247 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
3249 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3250 if (aPreviousMode == 3)
3252 anAISContext->RecomputePrsOnly (aTexturedIO);
3255 anAISContext->Display (aTexturedIO, Standard_True);
3258 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3260 if (aTextureArg == "?")
3262 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3264 theDi << "\n Files in current directory : \n\n";
3265 theDi.Eval ("glob -nocomplain *");
3267 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3268 aCmnd += aTextureFolder;
3271 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
3272 theDi.Eval (aCmnd.ToCString());
3277 aTexturedIO->SetTextureFileName (aTextureArg);
3282 // ------------------------------------
3283 // Process other options and commands
3284 // ------------------------------------
3286 Handle(TColStd_HSequenceOfAsciiString) aValues;
3287 if (aMapOfArgs.Find ("DEFAULT", aValues))
3289 aTexturedIO->SetTextureRepeat (Standard_False);
3290 aTexturedIO->SetTextureOrigin (Standard_False);
3291 aTexturedIO->SetTextureScale (Standard_False);
3292 aTexturedIO->EnableTextureModulate();
3296 if (aMapOfArgs.Find ("SCALE", aValues))
3298 if (aValues->Value(1) != "OFF")
3300 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3304 aTexturedIO->SetTextureScale (Standard_False);
3308 if (aMapOfArgs.Find ("ORIGIN", aValues))
3310 if (aValues->Value(1) != "OFF")
3312 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3316 aTexturedIO->SetTextureOrigin (Standard_False);
3320 if (aMapOfArgs.Find ("REPEAT", aValues))
3322 if (aValues->Value(1) != "OFF")
3324 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3328 aTexturedIO->SetTextureRepeat (Standard_False);
3332 if (aMapOfArgs.Find ("MODULATE", aValues))
3334 if (aValues->Value(1) == "ON")
3336 aTexturedIO->EnableTextureModulate();
3340 aTexturedIO->DisableTextureModulate();
3345 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3347 anAISContext->RecomputePrsOnly (aTexturedIO);
3351 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3352 anAISContext->Display (aTexturedIO, Standard_True);
3353 anAISContext->Update (aTexturedIO,Standard_True);
3359 //! Auxiliary method to parse transformation persistence flags
3360 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3361 Graphic3d_TransModeFlags& theFlags)
3363 if (theFlagString == "zoom")
3365 theFlags = Graphic3d_TMF_ZoomPers;
3367 else if (theFlagString == "rotate")
3369 theFlags = Graphic3d_TMF_RotatePers;
3371 else if (theFlagString == "zoomrotate")
3373 theFlags = Graphic3d_TMF_ZoomRotatePers;
3375 else if (theFlagString == "trihedron"
3376 || theFlagString == "triedron")
3378 theFlags = Graphic3d_TMF_TriedronPers;
3380 else if (theFlagString == "none")
3382 theFlags = Graphic3d_TMF_None;
3386 return Standard_False;
3389 return Standard_True;
3392 //! Auxiliary method to parse transformation persistence flags
3393 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
3394 Aspect_TypeOfTriedronPosition& theCorner)
3396 TCollection_AsciiString aString (theString);
3397 aString.LowerCase();
3398 if (aString == "center")
3400 theCorner = Aspect_TOTP_CENTER;
3402 else if (aString == "top"
3403 || aString == "upper")
3405 theCorner = Aspect_TOTP_TOP;
3407 else if (aString == "bottom"
3408 || aString == "lower")
3410 theCorner = Aspect_TOTP_BOTTOM;
3412 else if (aString == "left")
3414 theCorner = Aspect_TOTP_LEFT;
3416 else if (aString == "right")
3418 theCorner = Aspect_TOTP_RIGHT;
3420 else if (aString == "topleft"
3421 || aString == "leftupper"
3422 || aString == "upperleft")
3424 theCorner = Aspect_TOTP_LEFT_UPPER;
3426 else if (aString == "bottomleft"
3427 || aString == "leftlower"
3428 || aString == "lowerleft")
3430 theCorner = Aspect_TOTP_LEFT_LOWER;
3432 else if (aString == "topright"
3433 || aString == "rightupper"
3434 || aString == "upperright")
3436 theCorner = Aspect_TOTP_RIGHT_UPPER;
3438 else if (aString == "bottomright"
3439 || aString == "lowerright"
3440 || aString == "rightlower")
3442 theCorner = Aspect_TOTP_RIGHT_LOWER;
3446 return Standard_False;
3449 return Standard_True;
3452 //==============================================================================
3453 //function : VDisplay2
3455 //purpose : Display an object from its name
3456 //==============================================================================
3457 static int VDisplay2 (Draw_Interpretor& theDI,
3458 Standard_Integer theArgNb,
3459 const char** theArgVec)
3463 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3467 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3470 ViewerTest::ViewerInit();
3471 aCtx = ViewerTest::GetAISContext();
3474 // Parse input arguments
3475 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3476 Standard_Integer isMutable = -1;
3477 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3478 Standard_Boolean toDisplayLocal = Standard_False;
3479 Standard_Boolean toReDisplay = Standard_False;
3480 Standard_Integer isSelectable = -1;
3481 Standard_Integer anObjDispMode = -2;
3482 Standard_Integer anObjHighMode = -2;
3483 Standard_Boolean toSetTrsfPers = Standard_False;
3484 Handle(Graphic3d_TransformPers) aTrsfPers;
3485 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3486 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3487 Standard_Integer toDisplayInView = Standard_False;
3488 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3490 const TCollection_AsciiString aName = theArgVec[anArgIter];
3491 TCollection_AsciiString aNameCase = aName;
3492 aNameCase.LowerCase();
3493 if (anUpdateTool.parseRedrawMode (aName))
3497 else if (aNameCase == "-mutable")
3501 else if (aNameCase == "-neutral")
3503 aDispStatus = AIS_DS_Displayed;
3505 else if (aNameCase == "-immediate"
3506 || aNameCase == "-top")
3508 aZLayer = Graphic3d_ZLayerId_Top;
3510 else if (aNameCase == "-topmost")
3512 aZLayer = Graphic3d_ZLayerId_Topmost;
3514 else if (aNameCase == "-osd"
3515 || aNameCase == "-toposd"
3516 || aNameCase == "-overlay")
3518 aZLayer = Graphic3d_ZLayerId_TopOSD;
3520 else if (aNameCase == "-botosd"
3521 || aNameCase == "-underlay")
3523 aZLayer = Graphic3d_ZLayerId_BotOSD;
3525 else if (aNameCase == "-select"
3526 || aNameCase == "-selectable")
3530 else if (aNameCase == "-noselect"
3531 || aNameCase == "-noselection")
3535 else if (aNameCase == "-dispmode"
3536 || aNameCase == "-displaymode")
3538 if (++anArgIter >= theArgNb)
3540 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3544 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3546 else if (aNameCase == "-highmode"
3547 || aNameCase == "-highlightmode")
3549 if (++anArgIter >= theArgNb)
3551 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3555 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3557 else if (aNameCase == "-3d")
3559 toSetTrsfPers = Standard_True;
3560 aTrsfPers.Nullify();
3562 else if (aNameCase == "-2d"
3563 || aNameCase == "-trihedron"
3564 || aNameCase == "-triedron")
3566 toSetTrsfPers = Standard_True;
3567 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3569 if (anArgIter + 1 < theArgNb)
3571 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
3572 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
3575 aTrsfPers->SetCorner2d (aCorner);
3577 if (anArgIter + 2 < theArgNb)
3579 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
3580 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
3581 if (anX.IsIntegerValue()
3582 && anY.IsIntegerValue())
3585 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
3591 else if (aNameCase == "-trsfpers"
3592 || aNameCase == "-pers")
3594 if (++anArgIter >= theArgNb
3595 || !aTrsfPers.IsNull())
3597 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3601 toSetTrsfPers = Standard_True;
3602 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3603 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3604 aPersFlags.LowerCase();
3605 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3607 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3611 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
3613 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3615 else if (aTrsfPersFlags != Graphic3d_TMF_None)
3617 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
3620 else if (aNameCase == "-trsfperspos"
3621 || aNameCase == "-perspos")
3623 if (anArgIter + 2 >= theArgNb
3624 || aTrsfPers.IsNull())
3626 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3630 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3631 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3632 TCollection_AsciiString aZ = "0";
3633 if (!aX.IsRealValue()
3634 || !aY.IsRealValue())
3636 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3639 if (anArgIter + 1 < theArgNb)
3641 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3642 if (aTemp.IsRealValue())
3649 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
3650 if (aTrsfPers->IsZoomOrRotate())
3652 aTrsfPers->SetAnchorPoint (aPnt);
3654 else if (aTrsfPers->IsTrihedronOr2d())
3656 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
3659 else if (aNameCase == "-layer")
3661 if (++anArgIter >= theArgNb)
3663 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3667 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3668 if (!aValue.IsIntegerValue())
3670 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3674 aZLayer = aValue.IntegerValue();
3676 else if (aNameCase == "-view"
3677 || aNameCase == "-inview")
3679 toDisplayInView = Standard_True;
3681 else if (aNameCase == "-local")
3683 aDispStatus = AIS_DS_Temporary;
3684 toDisplayLocal = Standard_True;
3686 else if (aNameCase == "-redisplay")
3688 toReDisplay = Standard_True;
3692 aNamesOfDisplayIO.Append (aName);
3696 if (aNamesOfDisplayIO.IsEmpty())
3698 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3702 // Prepare context for display
3703 if (toDisplayLocal && !aCtx->HasOpenedContext())
3705 aCtx->OpenLocalContext (Standard_False);
3707 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3709 aCtx->CloseAllContexts (Standard_False);
3712 // Display interactive objects
3713 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3715 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3717 if (!GetMapOfAIS().IsBound2 (aName))
3719 // create the AIS_Shape from a name
3720 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3721 if (!aShape.IsNull())
3723 if (isMutable != -1)
3725 aShape->SetMutable (isMutable == 1);
3727 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3729 aShape->SetZLayer (aZLayer);
3733 aCtx->SetTransformPersistence (aShape, aTrsfPers);
3735 if (anObjDispMode != -2)
3737 aShape->SetDisplayMode (anObjDispMode);
3739 if (anObjHighMode != -2)
3741 aShape->SetHilightMode (anObjHighMode);
3743 if (!toDisplayLocal)
3744 GetMapOfAIS().Bind (aShape, aName);
3746 Standard_Integer aDispMode = aShape->HasDisplayMode()
3747 ? aShape->DisplayMode()
3748 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3749 ? aCtx->DisplayMode()
3751 Standard_Integer aSelMode = -1;
3752 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3754 aSelMode = aShape->GlobalSelectionMode();
3757 aCtx->Display (aShape, aDispMode, aSelMode,
3758 Standard_False, aShape->AcceptShapeDecomposition(),
3760 if (toDisplayInView)
3762 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
3764 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
3766 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3771 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3776 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3777 if (isMutable != -1)
3779 aShape->SetMutable (isMutable == 1);
3781 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3783 aShape->SetZLayer (aZLayer);
3787 aCtx->SetTransformPersistence (aShape, aTrsfPers);
3789 if (anObjDispMode != -2)
3791 aShape->SetDisplayMode (anObjDispMode);
3793 if (anObjHighMode != -2)
3795 aShape->SetHilightMode (anObjHighMode);
3797 Standard_Integer aDispMode = aShape->HasDisplayMode()
3798 ? aShape->DisplayMode()
3799 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3800 ? aCtx->DisplayMode()
3802 Standard_Integer aSelMode = -1;
3803 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3805 aSelMode = aShape->GlobalSelectionMode();
3808 if (aShape->Type() == AIS_KOI_Datum)
3810 aCtx->Display (aShape, Standard_False);
3814 theDI << "Display " << aName.ToCString() << "\n";
3816 // update the Shape in the AIS_Shape
3817 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3818 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3819 if (!aShapePrs.IsNull())
3821 if (!aShapePrs->Shape().IsEqual (aNewShape))
3823 toReDisplay = Standard_True;
3825 aShapePrs->Set (aNewShape);
3829 aCtx->Redisplay (aShape, Standard_False);
3834 aCtx->Erase (aShape);
3836 aCtx->Display (aShape, aDispMode, aSelMode,
3837 Standard_False, aShape->AcceptShapeDecomposition(),
3839 if (toDisplayInView)
3841 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3849 //===============================================================================================
3850 //function : VUpdate
3852 //===============================================================================================
3853 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3855 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3856 if (aContextAIS.IsNull())
3858 std::cout << theArgVec[0] << "AIS context is not available.\n";
3864 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3868 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3870 AIS_ListOfInteractive aListOfIO;
3872 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3874 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3876 Handle(AIS_InteractiveObject) anAISObj;
3877 if (anAISMap.IsBound2 (aName))
3879 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3882 if (anAISObj.IsNull())
3884 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3888 aListOfIO.Append (anAISObj);
3891 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3892 for (; anIOIt.More(); anIOIt.Next())
3894 aContextAIS->Update (anIOIt.Value(), Standard_False);
3897 aContextAIS->UpdateCurrentViewer();
3902 //==============================================================================
3904 //purpose : Test the annimation of an object along a
3905 // predifined trajectory
3906 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3907 //==============================================================================
3909 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3912 if (TheAISContext()->HasOpenedContext())
3913 TheAISContext()->CloseLocalContext();
3915 Standard_Real Step=4*M_PI/180;
3916 Standard_Real Angle=0;
3918 Handle(AIS_InteractiveObject) aIO;
3919 if (GetMapOfAIS().IsBound2(argv[1]))
3920 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3924 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3928 if (Draw::Atoi(argv[3])==1 ) {
3929 di<<" Primitives sensibles OFF\n";
3930 TheAISContext()->Deactivate(aIO);
3933 di<<" Primitives sensibles ON\n";
3935 // Movement par transformation
3936 if(Draw::Atoi(argv[2]) ==1) {
3937 di<<" Calcul par Transformation\n";
3938 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3942 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3943 TheAISContext()->SetLocation(aShape,myTransfo);
3944 TheAISContext() ->UpdateCurrentViewer();
3949 di<<" Calcul par Locations\n";
3950 gp_Trsf myAngleTrsf;
3951 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3952 TopLoc_Location myDeltaAngle (myAngleTrsf);
3953 TopLoc_Location myTrueLoc;
3955 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3958 myTrueLoc=myTrueLoc*myDeltaAngle;
3959 TheAISContext()->SetLocation(aShape,myTrueLoc );
3960 TheAISContext() ->UpdateCurrentViewer();
3963 if (Draw::Atoi(argv[3])==1 ){
3964 // On reactive la selection des primitives sensibles
3965 TheAISContext()->Activate(aIO,0);
3967 a3DView() -> Redraw();
3969 di<<" Temps ecoule \n";
3974 //==============================================================================
3975 //function : VShading
3976 //purpose : Sharpen or roughten the quality of the shading
3977 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3978 //==============================================================================
3979 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3981 Standard_Real myDevCoef;
3982 Handle(AIS_InteractiveObject) TheAisIO;
3985 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3987 if (TheAISContext()->HasOpenedContext())
3988 TheAISContext()->CloseLocalContext();
3993 myDevCoef =Draw::Atof(argv[2]);
3996 TCollection_AsciiString name=argv[1];
3997 if (GetMapOfAIS().IsBound2(name ))
3998 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3999 if (TheAisIO.IsNull())
4000 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4003 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4005 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4007 TheAISContext()->Redisplay(TheAisIO);
4010 //==============================================================================
4011 //function : HaveMode
4012 //use : VActivatedModes
4013 //==============================================================================
4014 #include <TColStd_ListIteratorOfListOfInteger.hxx>
4016 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
4018 TColStd_ListOfInteger List;
4019 TheAISContext()->ActivatedModes (TheAisIO,List);
4020 TColStd_ListIteratorOfListOfInteger it;
4021 Standard_Boolean Found=Standard_False;
4022 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4023 if (it.Value()==mode ) Found=Standard_True;
4030 //==============================================================================
4031 //function : VActivatedMode
4033 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
4034 // (edges,vertex...)qui lui est propre et le mode de selection standard.
4035 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4036 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4037 // qu'un nom et qu'un mode.
4038 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4039 //==============================================================================
4040 #include <AIS_ListIteratorOfListOfInteractive.hxx>
4042 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4045 Standard_Boolean ThereIsName = Standard_False ;
4047 if(!a3DView().IsNull()){
4049 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
4050 // verification des arguments
4052 if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
4053 ThereIsName = (argc == 3);
4057 if (argc>1) {di<<" Syntaxe error\n";return 1;}
4059 di<<" R.A.Z de tous les modes de selecion\n";
4060 di<<" Fermeture du Context local\n";
4061 if (TheAISContext()->HasOpenedContext())
4062 TheAISContext()->CloseLocalContext();
4066 // IL n'y a aps de nom de shape passe en argument
4067 if (HaveToSet && !ThereIsName){
4068 Standard_Integer aMode=Draw::Atoi(argv [1]);
4070 const char *cmode="???";
4072 case 0: cmode = "Shape"; break;
4073 case 1: cmode = "Vertex"; break;
4074 case 2: cmode = "Edge"; break;
4075 case 3: cmode = "Wire"; break;
4076 case 4: cmode = "Face"; break;
4077 case 5: cmode = "Shell"; break;
4078 case 6: cmode = "Solid"; break;
4079 case 7: cmode = "Compound"; break;
4082 if( !TheAISContext()->HasOpenedContext() ) {
4083 // il n'y a pas de Context local d'ouvert
4084 // on en ouvre un et on charge toutes les shapes displayees
4085 // on load tous les objets displayees et on Activate les objets de la liste
4086 AIS_ListOfInteractive ListOfIO;
4087 // on sauve dans une AISListOfInteractive tous les objets currents
4088 if (TheAISContext()->NbSelected()>0 ){
4089 TheAISContext()->UnhilightSelected(Standard_False);
4091 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4092 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
4096 TheAISContext()->OpenLocalContext(Standard_False);
4097 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4100 Handle(AIS_InteractiveObject) aIO =
4101 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4103 TheAISContext()->Load(aIO,0,Standard_False);
4106 // traitement des objets qui etaient currents dans le Contexte global
4107 if (!ListOfIO.IsEmpty() ) {
4108 // il y avait des objets currents
4109 AIS_ListIteratorOfListOfInteractive iter;
4110 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4111 Handle(AIS_InteractiveObject) aIO=iter.Value();
4112 TheAISContext()->Activate(aIO,aMode);
4113 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4117 // On applique le mode a tous les objets displayes
4118 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4119 it2 (GetMapOfAIS());
4121 Handle(AIS_InteractiveObject) aIO =
4122 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4123 if (!aIO.IsNull()) {
4124 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4125 TheAISContext()->Activate(aIO,aMode);
4134 // un Context local est deja ouvert
4135 // Traitement des objets du Context local
4136 if (TheAISContext()->NbSelected()>0 ){
4137 TheAISContext()->UnhilightSelected(Standard_False);
4138 // il y a des objets selected,on les parcourt
4139 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4140 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
4143 if (HaveMode(aIO,aMode) ) {
4144 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4145 TheAISContext()->Deactivate(aIO,aMode);
4148 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4149 TheAISContext()->Activate(aIO,aMode);
4155 // il n'y a pas d'objets selected
4156 // tous les objets diplayes sont traites
4157 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4160 Handle(AIS_InteractiveObject) aIO =
4161 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4162 if (!aIO.IsNull()) {
4163 if (HaveMode(aIO,aMode) ) {
4164 di<<" Mode: "<<cmode<<" OFF pour "
4165 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4166 TheAISContext()->Deactivate(aIO,aMode);
4169 di<<" Mode: "<<cmode<<" ON pour"
4170 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4171 TheAISContext()->Activate(aIO,aMode);
4179 else if (HaveToSet && ThereIsName){
4180 Standard_Integer aMode=Draw::Atoi(argv [2]);
4181 Handle(AIS_InteractiveObject) aIO =
4182 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4184 if (!aIO.IsNull()) {
4185 const char *cmode="???";
4188 case 0: cmode = "Shape"; break;
4189 case 1: cmode = "Vertex"; break;
4190 case 2: cmode = "Edge"; break;
4191 case 3: cmode = "Wire"; break;
4192 case 4: cmode = "Face"; break;
4193 case 5: cmode = "Shell"; break;
4194 case 6: cmode = "Solid"; break;
4195 case 7: cmode = "Compound"; break;
4198 if( !TheAISContext()->HasOpenedContext() ) {
4199 TheAISContext()->OpenLocalContext(Standard_False);
4200 // On charge tous les objets de la map
4201 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4203 Handle(AIS_InteractiveObject) aShape=
4204 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4205 if (!aShape.IsNull())
4206 TheAISContext()->Load(aShape,0,Standard_False);
4209 TheAISContext()->Activate(aIO,aMode);
4210 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4214 // un Context local est deja ouvert
4215 if (HaveMode(aIO,aMode) ) {
4216 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4217 TheAISContext()->Deactivate(aIO,aMode);
4220 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4221 TheAISContext()->Activate(aIO,aMode);
4230 //! Auxiliary method to print Interactive Object information
4231 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4232 const Handle(Standard_Transient)& theObject,
4233 Draw_Interpretor& theDI)
4235 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4238 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4242 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4243 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4244 << (theDetected.Contains (anObj) ? " Detected" : " ")
4246 if (anObj->Type() == AIS_KOI_Datum)
4249 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4250 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4251 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4252 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4253 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4254 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4255 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4258 else if (anObj->Type() == AIS_KOI_Shape
4259 && anObj->Signature() == 0)
4261 theDI << " AIS_Shape";
4263 else if (anObj->Type() == AIS_KOI_Relation)
4265 // AIS_Dimention and AIS_Relation
4266 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4267 switch (aRelation->KindOfDimension())
4269 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4270 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4271 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4272 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4273 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4274 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4275 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4276 default: theDI << " UNKNOWN dimension"; break;
4281 theDI << " UserPrs";
4283 theDI << " (" << theObject->DynamicType()->Name() << ")";
4286 //! Print information about locally selected sub-shapes
4287 template <typename T>
4288 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4290 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4291 TCollection_AsciiString aPrevName;
4292 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4294 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4295 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4296 if (aShapeIO.IsNull() || anOwner.IsNull())
4300 if (anOwner == aShapeIO->GlobalSelOwner())
4303 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4304 if (aSubShape.IsNull()
4305 || aShapeIO.IsNull()
4306 || !GetMapOfAIS().IsBound1 (aShapeIO))
4311 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4312 TopTools_MapOfShape aFilter;
4313 Standard_Integer aNumber = 0;
4314 const TopoDS_Shape aShape = aShapeIO->Shape();
4315 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4316 anIter.More(); anIter.Next())
4318 if (!aFilter.Add (anIter.Current()))
4320 continue; // filter duplicates
4324 if (!anIter.Current().IsSame (aSubShape))
4329 Standard_CString aShapeName = NULL;
4330 switch (aSubShape.ShapeType())
4332 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4333 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4334 case TopAbs_SOLID: aShapeName = " Solid"; break;
4335 case TopAbs_SHELL: aShapeName = " Shell"; break;
4336 case TopAbs_FACE: aShapeName = " Face"; break;
4337 case TopAbs_WIRE: aShapeName = " Wire"; break;
4338 case TopAbs_EDGE: aShapeName = " Edge"; break;
4339 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4341 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4344 if (aParentName != aPrevName)
4346 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4347 aPrevName = aParentName;
4349 theDI << " " << aShapeName << " #" << aNumber << "\n";
4355 //==============================================================================
4358 //==============================================================================
4359 static Standard_Integer VState (Draw_Interpretor& theDI,
4360 Standard_Integer theArgNb,
4361 Standard_CString* theArgVec)
4363 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4366 std::cerr << "Error: No opened viewer!\n";
4370 Standard_Boolean toPrintEntities = Standard_False;
4371 Standard_Boolean toCheckSelected = Standard_False;
4373 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4375 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4376 anOption.LowerCase();
4377 if (anOption == "-detectedentities"
4378 || anOption == "-entities")
4380 toPrintEntities = Standard_True;
4382 else if (anOption == "-hasselected")
4384 toCheckSelected = Standard_True;
4388 if (toCheckSelected)
4390 aCtx->InitSelected();
4391 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4392 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4397 if (toPrintEntities)
4399 theDI << "Detected entities:\n";
4400 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4401 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4402 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4404 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4405 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4406 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4407 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4408 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4409 aName.LeftJustify (20, ' ');
4410 char anInfoStr[512];
4412 " Depth: %g Distance: %g Point: %g %g %g",
4415 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4416 theDI << " " << aName
4418 << " (" << anEntity->DynamicType()->Name() << ")"
4421 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4422 if (!aBRepOwner.IsNull())
4424 theDI << " Detected Shape: "
4425 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4429 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4430 if (!aWire.IsNull())
4432 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4433 theDI << " Detected Child: "
4434 << aSen->DynamicType()->Name()
4438 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4439 if (!aPrimArr.IsNull())
4441 theDI << " Detected Element: "
4442 << aPrimArr->LastDetectedElement()
4449 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4450 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4452 aDetected.Add (aCtx->DetectedCurrentObject());
4455 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4459 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4461 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4462 if (!GetMapOfAIS().IsBound2 (anObjName))
4464 theDI << anObjName << " doesn't exist!\n";
4468 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4469 TCollection_AsciiString aName = anObjName;
4470 aName.LeftJustify (20, ' ');
4471 theDI << " " << aName << " ";
4472 objInfo (aDetected, anObjTrans, theDI);
4478 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4480 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4481 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4483 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4484 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4485 // handle whole object selection
4486 if (anOwner == anObj->GlobalSelOwner())
4488 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4489 aName.LeftJustify (20, ' ');
4490 theDI << aName << " ";
4491 objInfo (aDetected, anObj, theDI);
4496 // process selected sub-shapes
4497 printLocalSelectionInfo (aCtx, theDI);
4502 theDI << "Neutral-point state:\n";
4503 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4504 anObjIter.More(); anObjIter.Next())
4506 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4512 TCollection_AsciiString aName = anObjIter.Key2();
4513 aName.LeftJustify (20, ' ');
4514 theDI << " " << aName << " ";
4515 objInfo (aDetected, anObj, theDI);
4518 printLocalSelectionInfo (aCtx, theDI);
4519 if (aCtx->HasOpenedContext())
4520 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
4524 //=======================================================================
4525 //function : PickObjects
4527 //=======================================================================
4528 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4529 const AIS_KindOfInteractive TheType,
4530 const Standard_Integer TheSignature,
4531 const Standard_Integer MaxPick)
4533 Handle(AIS_InteractiveObject) IO;
4534 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4536 // step 1: prepare the data
4538 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4539 TheAISContext()->AddFilter(F1);
4542 // step 2 : wait for the selection...
4543 Standard_Integer NbPickGood (0),NbToReach(arr->Length());
4544 Standard_Integer NbPickFail(0);
4545 Standard_Integer argccc = 5;
4546 const char *bufff[] = { "A", "B", "C","D", "E" };
4547 const char **argvvv = (const char **) bufff;
4550 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4551 while(ViewerMainLoop(argccc,argvvv)){}
4552 Standard_Integer NbStored = TheAISContext()->NbSelected();
4553 if(NbStored != NbPickGood)
4554 NbPickGood= NbStored;
4557 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4560 // step3 get result.
4562 if (NbPickFail >= NbToReach)
4563 return Standard_False;
4565 Standard_Integer i(0);
4566 for(TheAISContext()->InitSelected();
4567 TheAISContext()->MoreSelected();
4568 TheAISContext()->NextSelected()){
4570 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4571 arr->SetValue(i,IO2);
4576 TheAISContext()->CloseLocalContext(curindex);
4578 return Standard_True;
4582 //=======================================================================
4583 //function : PickObject
4585 //=======================================================================
4586 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4587 const Standard_Integer TheSignature,
4588 const Standard_Integer MaxPick)
4590 Handle(AIS_InteractiveObject) IO;
4591 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4593 // step 1: prepare the data
4596 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4597 TheAISContext()->AddFilter(F1);
4600 // step 2 : wait for the selection...
4601 Standard_Boolean IsGood (Standard_False);
4602 Standard_Integer NbPick(0);
4603 Standard_Integer argccc = 5;
4604 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4605 const char **argvvv = (const char **) bufff;
4608 while(!IsGood && NbPick<= MaxPick){
4609 while(ViewerMainLoop(argccc,argvvv)){}
4610 IsGood = (TheAISContext()->NbSelected()>0) ;
4612 cout<<"Nb Pick :"<<NbPick<<endl;
4616 // step3 get result.
4618 TheAISContext()->InitSelected();
4619 IO = TheAISContext()->SelectedInteractive();
4623 TheAISContext()->CloseLocalContext(curindex);
4627 //=======================================================================
4628 //function : PickShape
4629 //purpose : First Activate the rightmode + Put Filters to be able to
4630 // pick objets that are of type <TheType>...
4631 //=======================================================================
4633 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4634 const Standard_Integer MaxPick)
4637 // step 1: prepare the data
4639 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4640 TopoDS_Shape result;
4642 if(TheType==TopAbs_SHAPE){
4643 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4644 TheAISContext()->AddFilter(F1);
4647 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4648 TheAISContext()->AddFilter(TF);
4649 TheAISContext()->ActivateStandardMode(TheType);
4654 // step 2 : wait for the selection...
4655 Standard_Boolean NoShape (Standard_True);
4656 Standard_Integer NbPick(0);
4657 Standard_Integer argccc = 5;
4658 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4659 const char **argvvv = (const char **) bufff;
4662 while(NoShape && NbPick<= MaxPick){
4663 while(ViewerMainLoop(argccc,argvvv)){}
4664 NoShape = (TheAISContext()->NbSelected()==0) ;
4666 cout<<"Nb Pick :"<<NbPick<<endl;
4669 // step3 get result.
4673 TheAISContext()->InitSelected();
4674 if(TheAISContext()->HasSelectedShape())
4675 result = TheAISContext()->SelectedShape();
4677 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4678 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
4683 TheAISContext()->CloseLocalContext(curindex);
4689 //=======================================================================
4690 //function : PickShapes
4692 //=======================================================================
4693 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4694 Handle(TopTools_HArray1OfShape)& thearr,
4695 const Standard_Integer MaxPick)
4698 Standard_Integer Taille = thearr->Length();
4700 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4702 // step 1: prepare the data
4703 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4704 if(TheType==TopAbs_SHAPE){
4705 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4706 TheAISContext()->AddFilter(F1);
4709 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4710 TheAISContext()->AddFilter(TF);
4711 TheAISContext()->ActivateStandardMode(TheType);
4715 // step 2 : wait for the selection...
4716 Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
4717 Standard_Integer NbPickFail(0);
4718 Standard_Integer argccc = 5;
4719 const char *bufff[] = { "A", "B", "C","D", "E" };
4720 const char **argvvv = (const char **) bufff;
4723 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4724 while(ViewerMainLoop(argccc,argvvv)){}
4725 Standard_Integer NbStored = TheAISContext()->NbSelected();
4726 if (NbStored != NbPickGood)
4727 NbPickGood= NbStored;
4730 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4733 // step3 get result.
4735 if (NbPickFail >= NbToReach)
4736 return Standard_False;
4738 Standard_Integer i(0);
4739 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4741 if(TheAISContext()->HasSelectedShape())
4742 thearr->SetValue(i,TheAISContext()->SelectedShape());
4744 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4745 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
4749 TheAISContext()->CloseLocalContext(curindex);
4750 return Standard_True;
4754 //=======================================================================
4755 //function : VPickShape
4757 //=======================================================================
4758 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4760 TopoDS_Shape PickSh;
4761 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4764 theType = TopAbs_SHAPE;
4766 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4767 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4768 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4769 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4770 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4771 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4772 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4775 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4776 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4778 TCollection_AsciiString name;
4781 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4783 PickSh = ViewerTest::PickShape(theType);
4792 if(!PickSh.IsNull()){
4793 nbOfSub[Standard_Integer(theType)]++;
4795 name += nameType[Standard_Integer(theType)];
4796 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4801 // si on avait une petite methode pour voir si la shape
4802 // est deja dans la Double map, ca eviterait de creer....
4803 DBRep::Set(name.ToCString(),PickSh);
4805 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4806 GetMapOfAIS().Bind(newsh, name);
4807 TheAISContext()->Display(newsh);
4808 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4811 // Plusieurs objets a picker, vite vite vite....
4814 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4815 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4816 if(ViewerTest::PickShapes(theType,arr)){
4817 for(Standard_Integer i=1;i<=NbToPick;i++){
4818 PickSh = arr->Value(i);
4819 if(!PickSh.IsNull()){
4821 nbOfSub[Standard_Integer(theType)]++;
4824 name += nameType[Standard_Integer(theType)];
4825 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4833 DBRep::Set(name.ToCString(),PickSh);
4834 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4835 GetMapOfAIS().Bind(newsh, name);
4836 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4837 TheAISContext()->Display(newsh);
4845 //=======================================================================
4846 //function : VPickSelected
4848 //=======================================================================
4849 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4851 static Standard_Integer aCount = 0;
4852 TCollection_AsciiString aName = "PickedShape_";
4860 aName = aName + aCount++ + "_";
4863 Standard_Integer anIdx = 0;
4864 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4866 TopoDS_Shape aShape;
4867 if (TheAISContext()->HasSelectedShape())
4869 aShape = TheAISContext()->SelectedShape();
4873 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4874 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
4877 TCollection_AsciiString aCurrentName = aName;
4880 aCurrentName += anIdx;
4883 DBRep::Set ((aCurrentName).ToCString(), aShape);
4885 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4886 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4887 TheAISContext()->Display (aNewShape);
4893 //=======================================================================
4894 //function : list of known objects
4896 //=======================================================================
4897 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4899 // 1234567890 12345678901234567 123456789
4900 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4901 TCollection_AsciiString BlankLine(64,'_');
4902 Standard_Integer i ;
4904 di<<"/n"<<BlankLine.ToCString()<<"\n";
4907 Colum[i].Center(20,' ');
4909 di<<"|"<<Colum[i].ToCString();
4912 di<<BlankLine.ToCString()<<"\n";
4914 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4915 const char ** names = GetTypeNames();
4917 TCollection_AsciiString curstring;
4918 TCollection_AsciiString curcolum[3];
4921 // les objets de type Datum..
4922 curcolum[1]+="Datum";
4924 curcolum[0].Clear();
4925 curcolum[0] += names[i];
4927 curcolum[2].Clear();
4928 curcolum[2]+=TCollection_AsciiString(i+1);
4930 for(Standard_Integer j =0;j<=2;j++){
4931 curcolum[j].Center(20,' ');
4932 di<<"|"<<curcolum[j].ToCString();
4936 di<<BlankLine.ToCString()<<"\n";
4938 // les objets de type shape
4939 curcolum[1].Clear();
4940 curcolum[1]+="Shape";
4941 curcolum[1].Center(20,' ');
4944 curcolum[0].Clear();
4945 curcolum[0] += names[7+i];
4946 curcolum[2].Clear();
4947 curcolum[2]+=TCollection_AsciiString(i);
4949 for(Standard_Integer j =0;j<=2;j++){
4950 curcolum[j].Center(20,' ');
4951 di<<"|"<<curcolum[j].ToCString();
4955 di<<BlankLine.ToCString()<<"\n";
4956 // les IO de type objet...
4957 curcolum[1].Clear();
4958 curcolum[1]+="Object";
4959 curcolum[1].Center(20,' ');
4961 curcolum[0].Clear();
4962 curcolum[0] += names[10+i];
4963 curcolum[2].Clear();
4964 curcolum[2]+=TCollection_AsciiString(i);
4966 for(Standard_Integer j =0;j<=2;j++){
4967 curcolum[j].Center(20,' ');
4968 di<<"|"<<curcolum[j].ToCString();
4972 di<<BlankLine.ToCString()<<"\n";
4973 // les contraintes et dimensions.
4974 // pour l'instant on separe juste contraintes et dimensions...
4975 // plus tard, on detaillera toutes les sortes...
4976 curcolum[1].Clear();
4977 curcolum[1]+="Relation";
4978 curcolum[1].Center(20,' ');
4980 curcolum[0].Clear();
4981 curcolum[0] += names[12+i];
4982 curcolum[2].Clear();
4983 curcolum[2]+=TCollection_AsciiString(i);
4985 for(Standard_Integer j =0;j<=2;j++){
4986 curcolum[j].Center(20,' ');
4987 di<<"|"<<curcolum[j].ToCString();
4991 di<<BlankLine.ToCString()<<"\n";
4998 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5000 if(argc!=2) return 1;
5002 AIS_KindOfInteractive TheType;
5003 Standard_Integer TheSign(-1);
5004 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5007 AIS_ListOfInteractive LIO;
5009 // en attendant l'amelioration ais pour les dimensions...
5011 Standard_Integer dimension_status(-1);
5012 if(TheType==AIS_KOI_Relation){
5013 dimension_status = TheSign ==1 ? 1 : 0;
5017 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5018 Handle(AIS_InteractiveObject) curio;
5019 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5022 if(dimension_status == -1)
5023 TheAISContext()->Erase(curio,Standard_False);
5025 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5026 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5027 (dimension_status==1 && KOD != AIS_KOD_NONE))
5028 TheAISContext()->Erase(curio,Standard_False);
5031 TheAISContext()->UpdateCurrentViewer();
5034 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5036 if(argc!=2) return 1;
5038 AIS_KindOfInteractive TheType;
5039 Standard_Integer TheSign(-1);
5040 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5042 // en attendant l'amelioration ais pour les dimensions...
5044 Standard_Integer dimension_status(-1);
5045 if(TheType==AIS_KOI_Relation){
5046 dimension_status = TheSign ==1 ? 1 : 0;
5050 AIS_ListOfInteractive LIO;
5051 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5052 Handle(AIS_InteractiveObject) curio;
5053 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5055 if(dimension_status == -1)
5056 TheAISContext()->Display(curio,Standard_False);
5058 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5059 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5060 (dimension_status==1 && KOD != AIS_KOD_NONE))
5061 TheAISContext()->Display(curio,Standard_False);
5066 TheAISContext()->UpdateCurrentViewer();
5070 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5073 BRep_Builder builder;
5075 BRepTools::Read(shape, s, builder);
5076 DBRep::Set(a[1], shape);
5077 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5078 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5083 //===============================================================================================
5086 //===============================================================================================
5087 static int VBsdf (Draw_Interpretor& theDi,
5088 Standard_Integer theArgsNb,
5089 const char** theArgVec)
5091 Handle(V3d_View) aView = ViewerTest::CurrentView();
5092 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5094 || aViewer.IsNull())
5096 std::cerr << "No active viewer!\n";
5100 ViewerTest_CmdParser aCmd;
5102 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5103 aCmd.AddOption ("print|echo|p", "Print BSDF");
5105 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5106 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5107 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5108 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5109 aCmd.AddOption ("le", "Self-emitted radiance");
5111 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5113 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
5114 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5115 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5117 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5119 aCmd.Parse (theArgsNb, theArgVec);
5121 if (aCmd.HasOption ("help"))
5123 theDi.PrintHelp (theArgVec[0]);
5127 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5130 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5131 if (!aMap.IsBound2 (aName) )
5133 std::cerr << "Use 'vdisplay' before\n";
5137 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5138 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5139 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5141 if (aCmd.HasOption ("print"))
5143 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5146 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5147 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5148 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5149 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5150 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5153 if (aFresnel.x() >= 0.f)
5156 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5158 else if (aFresnel.x() >= -1.5f)
5161 << "|Constant| " << aFresnel.z() << "\n";
5163 else if (aFresnel.x() >= -2.5f)
5166 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5171 << "|Dielectric| " << aFresnel.y() << "\n";
5176 << "Roughness: " << aBSDF.Roughness << "\n"
5177 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
5178 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5179 << aBSDF.AbsorptionColor.g() << ", "
5180 << aBSDF.AbsorptionColor.b() << "\n";
5185 if (aCmd.HasOption ("roughness", 1, Standard_True))
5187 aCmd.Arg ("roughness", 0);
5188 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5191 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5193 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5196 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5198 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5201 if (aCmd.HasOption ("kd", 3))
5203 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5205 else if (aCmd.HasOption ("kd", 1, Standard_True))
5207 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5210 if (aCmd.HasOption ("kr", 3))
5212 aBSDF.Kr = aCmd.ArgVec3f ("kr");
5214 else if (aCmd.HasOption ("kr", 1, Standard_True))
5216 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5219 if (aCmd.HasOption ("kt", 3))
5221 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5223 else if (aCmd.HasOption ("kt", 1, Standard_True))
5225 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5228 if (aCmd.HasOption ("ks", 3))
5230 aBSDF.Ks = aCmd.ArgVec3f ("ks");
5232 else if (aCmd.HasOption ("ks", 1, Standard_True))
5234 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5237 if (aCmd.HasOption ("le", 3))
5239 aBSDF.Le = aCmd.ArgVec3f ("le");
5241 else if (aCmd.HasOption ("le", 1, Standard_True))
5243 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5246 const std::string aFresnelErrorMessage =
5247 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5249 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5251 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5252 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5254 if (aFresnelType == "schlick")
5256 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5257 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5258 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5259 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5263 std::cout << aFresnelErrorMessage;
5266 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5268 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5269 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5271 if (aFresnelType == "conductor")
5273 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5274 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5275 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5279 std::cout << aFresnelErrorMessage;
5282 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5284 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5285 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5287 if (aFresnelType == "dielectric")
5289 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5290 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5292 else if (aFresnelType == "constant")
5294 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5295 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5299 std::cout << aFresnelErrorMessage;
5303 if (aCmd.HasOption ("normalize"))
5308 aMaterial.SetBSDF (aBSDF);
5309 anIObj->SetMaterial (aMaterial);
5316 //==============================================================================
5317 //function : VLoadSelection
5318 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5319 //==============================================================================
5320 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5321 Standard_Integer theArgNb,
5322 const char** theArgVec)
5326 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5330 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5333 ViewerTest::ViewerInit();
5334 aCtx = ViewerTest::GetAISContext();
5337 // Parse input arguments
5338 TColStd_SequenceOfAsciiString aNamesOfIO;
5339 Standard_Boolean isLocal = Standard_False;
5340 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5342 const TCollection_AsciiString aName = theArgVec[anArgIter];
5343 TCollection_AsciiString aNameCase = aName;
5344 aNameCase.LowerCase();
5345 if (aNameCase == "-local")
5347 isLocal = Standard_True;
5351 aNamesOfIO.Append (aName);
5355 if (aNamesOfIO.IsEmpty())
5357 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5362 if (isLocal && !aCtx->HasOpenedContext())
5364 aCtx->OpenLocalContext (Standard_False);
5366 else if (!isLocal && aCtx->HasOpenedContext())
5368 aCtx->CloseAllContexts (Standard_False);
5371 // Load selection of interactive objects
5372 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5374 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5376 Handle(AIS_InteractiveObject) aShape;
5377 if (GetMapOfAIS().IsBound2 (aName))
5378 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5380 aShape = GetAISShapeFromName (aName.ToCString());
5382 if (!aShape.IsNull())
5384 if (!GetMapOfAIS().IsBound2 (aName))
5386 GetMapOfAIS().Bind (aShape, aName);
5389 aCtx->Load (aShape, -1, Standard_False);
5390 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5397 //==============================================================================
5398 //function : ViewerTest::Commands
5399 //purpose : Add all the viewer command in the Draw_Interpretor
5400 //==============================================================================
5402 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5404 ViewerTest::ViewerCommands(theCommands);
5405 ViewerTest::RelationCommands(theCommands);
5406 ViewerTest::ObjectCommands(theCommands);
5407 ViewerTest::FilletCommands(theCommands);
5408 ViewerTest::OpenGlCommands(theCommands);
5410 const char *group = "AIS_Display";
5413 theCommands.Add("visos",
5414 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5415 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5416 __FILE__, visos, group);
5418 theCommands.Add("vdisplay",
5419 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5420 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5421 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5422 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5423 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5424 "\n\t\t: [offsetX offsetY]]]"
5425 "\n\t\t: [-dispMode mode] [-highMode mode]"
5426 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5427 "\n\t\t: [-redisplay]"
5428 "\n\t\t: name1 [name2] ... [name n]"
5429 "\n\t\t: Displays named objects."
5430 "\n\t\t: Option -local enables displaying of objects in local"
5431 "\n\t\t: selection context. Local selection context will be opened"
5432 "\n\t\t: if there is not any."
5433 "\n\t\t: -noupdate Suppresses viewer redraw call."
5434 "\n\t\t: -mutable Enables optimizations for mutable objects."
5435 "\n\t\t: -neutral Draws objects in main viewer."
5436 "\n\t\t: -layer Sets z-layer for objects."
5437 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5438 "\n\t\t: options can be used for the default z-layers."
5439 "\n\t\t: -top Draws object on top of main presentations"
5440 "\n\t\t: but below topmost."
5441 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5442 "\n\t\t: with independent Depth."
5443 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5444 "\n\t\t: (On-Screen-Display)"
5445 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5446 "\n\t\t: (On-Screen-Display)"
5447 "\n\t\t: -selectable|-noselect Controls selection of objects."
5448 "\n\t\t: -trsfPers Sets a transform persistence flags."
5449 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5450 "\n\t\t: -2d Displays object in screen coordinates."
5451 "\n\t\t: (DY looks up)"
5452 "\n\t\t: -dispmode Sets display mode for objects."
5453 "\n\t\t: -highmode Sets hilight mode for objects."
5454 "\n\t\t: -redisplay Recomputes presentation of objects.",
5455 __FILE__, VDisplay2, group);
5457 theCommands.Add ("vupdate",
5458 "vupdate name1 [name2] ... [name n]"
5459 "\n\t\t: Updates named objects in interactive context",
5460 __FILE__, VUpdate, group);
5462 theCommands.Add("verase",
5463 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5464 "\n\t\t: Erases selected or named objects."
5465 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5466 "\n\t\t: Option -local enables erasing of selected or named objects without"
5467 "\n\t\t: closing local selection context.",
5468 __FILE__, VErase, group);
5470 theCommands.Add("vremove",
5471 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5472 "or vremove [-context] -all to remove all objects"
5473 "\n\t\t: Removes selected or named objects."
5474 "\n\t\t If -context is in arguments, the objects are not deleted"
5475 "\n\t\t from the map of objects and names."
5476 "\n\t\t: Option -local enables removing of selected or named objects without"
5477 "\n\t\t: closing local selection context. Empty local selection context will be"
5479 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5480 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5481 __FILE__, VRemove, group);
5483 theCommands.Add("vdonly",
5484 "vdonly [-noupdate|-update] [name1] ... [name n]"
5485 "\n\t\t: Displays only selected or named objects",
5486 __FILE__,VDonly2,group);
5488 theCommands.Add("vdisplayall",
5489 "vidsplayall [-local]"
5490 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5491 "\n\t\t: Option -local enables displaying of the objects in local"
5492 "\n\t\t: selection context.",
5493 __FILE__, VDisplayAll, group);
5495 theCommands.Add("veraseall",
5496 "veraseall [-local]"
5497 "\n\t\t: Erases all objects displayed in the viewer."
5498 "\n\t\t: Option -local enables erasing of the objects in local"
5499 "\n\t\t: selection context.",
5500 __FILE__, VErase, group);
5502 theCommands.Add("verasetype",
5504 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5505 __FILE__, VEraseType, group);
5506 theCommands.Add("vbounding",
5507 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5508 "\n\t\t: [-print] [-hide]"
5509 "\n\t\t: Temporarily display bounding box of specified Interactive"
5510 "\n\t\t: Objects, or print it to console if -print is specified."
5511 "\n\t\t: Already displayed box might be hidden by -hide option.",
5512 __FILE__,VBounding,group);
5514 theCommands.Add("vdisplaytype",
5515 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5516 __FILE__,VDisplayType,group);
5518 theCommands.Add("vsetdispmode",
5519 "vsetdispmode [name] mode(1,2,..)"
5520 "\n\t\t: Sets display mode for all, selected or named objects.",
5521 __FILE__,VDispMode,group);
5523 theCommands.Add("vunsetdispmode",
5524 "vunsetdispmode [name]"
5525 "\n\t\t: Unsets custom display mode for selected or named objects.",
5526 __FILE__,VDispMode,group);
5528 theCommands.Add("vdir",
5529 "Lists all objects displayed in 3D viewer",
5530 __FILE__,VDir,group);
5532 #ifdef HAVE_FREEIMAGE
5533 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5535 #define DUMP_FORMATS "{ppm}"
5537 theCommands.Add("vdump",
5538 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5539 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5540 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5541 "\n\t\t: [-tileSize Size=0]"
5542 "\n\t\t: Dumps content of the active view into image file",
5543 __FILE__,VDump,group);
5545 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5546 __FILE__,VSubInt,group);
5548 theCommands.Add("vaspects",
5549 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5550 "\n\t\t: [-setVisibility 0|1]"
5551 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5552 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5553 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5554 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5555 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5556 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5557 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5558 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5559 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5560 "\n\t\t: [-isoontriangulation 0|1]"
5561 "\n\t\t: [-setMaxParamValue {value}]"
5562 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5563 "\n\t\t: Manage presentation properties of all, selected or named objects."
5564 "\n\t\t: When -subshapes is specified than following properties will be"
5565 "\n\t\t: assigned to specified sub-shapes."
5566 "\n\t\t: When -defaults is specified than presentation properties will be"
5567 "\n\t\t: assigned to all objects that have not their own specified properties"
5568 "\n\t\t: and to all objects to be displayed in the future."
5569 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5570 __FILE__,VAspects,group);
5572 theCommands.Add("vsetcolor",
5573 "vsetcolor [-noupdate|-update] [name] ColorName"
5574 "\n\t\t: Sets color for all, selected or named objects."
5575 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5576 __FILE__,VAspects,group);
5578 theCommands.Add("vunsetcolor",
5579 "vunsetcolor [-noupdate|-update] [name]"
5580 "\n\t\t: Resets color for all, selected or named objects."
5581 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5582 __FILE__,VAspects,group);
5584 theCommands.Add("vsettransparency",
5585 "vsettransparency [-noupdate|-update] [name] Coefficient"
5586 "\n\t\t: Sets transparency for all, selected or named objects."
5587 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5588 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5589 __FILE__,VAspects,group);
5591 theCommands.Add("vunsettransparency",
5592 "vunsettransparency [-noupdate|-update] [name]"
5593 "\n\t\t: Resets transparency for all, selected or named objects."
5594 "\n\t\t: Alias for vaspects -unsettransp [name].",
5595 __FILE__,VAspects,group);
5597 theCommands.Add("vsetmaterial",
5598 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5599 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5600 __FILE__,VAspects,group);
5602 theCommands.Add("vunsetmaterial",
5603 "vunsetmaterial [-noupdate|-update] [name]"
5604 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5605 __FILE__,VAspects,group);
5607 theCommands.Add("vsetwidth",
5608 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5609 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5610 __FILE__,VAspects,group);
5612 theCommands.Add("vunsetwidth",
5613 "vunsetwidth [-noupdate|-update] [name]"
5614 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5615 __FILE__,VAspects,group);
5617 theCommands.Add("vsetinteriorstyle",
5618 "vsetinteriorstyle [-noupdate|-update] [name] style"
5619 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5620 __FILE__,VSetInteriorStyle,group);
5622 theCommands.Add("vsensdis",
5623 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5624 "\n\t\t: Standard entity types are those defined in Select3D package:"
5625 "\n\t\t: - sensitive box"
5626 "\n\t\t: - sensitive face"
5627 "\n\t\t: - sensitive curve"
5628 "\n\t\t: - sensitive segment"
5629 "\n\t\t: - sensitive circle"
5630 "\n\t\t: - sensitive point"
5631 "\n\t\t: - sensitive triangulation"
5632 "\n\t\t: - sensitive triangle"
5633 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5634 __FILE__,VDispSensi,group);
5636 theCommands.Add("vsensera",
5637 "vsensera : erase active entities",
5638 __FILE__,VClearSensi,group);
5640 theCommands.Add("vperf",
5641 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
5642 "\n\t\t: Tests the animation of an object along a predefined trajectory.",
5643 __FILE__,VPerf,group);
5645 theCommands.Add("vsetshading",
5646 "vsetshading : vsetshading name Quality(default=0.0008) "
5647 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5648 __FILE__,VShading,group);
5650 theCommands.Add("vunsetshading",
5651 "vunsetshading :vunsetshading name "
5652 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5653 __FILE__,VShading,group);
5655 theCommands.Add ("vtexture",
5656 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5657 " [-scale u v] [-scale off]\n"
5658 " [-origin u v] [-origin off]\n"
5659 " [-repeat u v] [-repeat off]\n"
5660 " [-modulate {on | off}]"
5662 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5663 " specifying one of the predefined textures.\n"
5664 " The options are: \n"
5665 " -scale u v : enable texture scaling and set scale factors\n"
5666 " -scale off : disable texture scaling\n"
5667 " -origin u v : enable texture origin positioning and set the origin\n"
5668 " -origin off : disable texture origin positioning\n"
5669 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5670 " -repeat off : disable texture repeat\n"
5671 " -modulate {on | off} : enable or disable texture modulation\n"
5672 " -default : sets texture mapping default parameters\n"
5673 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5674 "or 'vtexture NameOfShape ?' to list available textures\n",
5675 __FILE__, VTexture, group);
5677 theCommands.Add("vtexscale",
5678 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5679 or 'vtexscale NameOfShape ScaleUV' \n \
5680 or 'vtexscale NameOfShape' to disable scaling\n ",
5681 __FILE__,VTexture,group);
5683 theCommands.Add("vtexorigin",
5684 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5685 or 'vtexorigin NameOfShape UVOrigin' \n \
5686 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5687 __FILE__,VTexture,group);
5689 theCommands.Add("vtexrepeat",
5690 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5691 or 'vtexrepeat NameOfShape UVRepeat \n \
5692 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5695 theCommands.Add("vtexdefault",
5696 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5699 theCommands.Add("vsetam",
5700 "vsetam [shapename] mode"
5701 "\n\t\t: Activates selection mode for all selected or named shapes."
5702 "\n\t\t: Mod can be:"
5703 "\n\t\t: 0 - for shape itself"
5704 "\n\t\t: 1 - vertices"
5708 "\n\t\t: 5 - shells"
5709 "\n\t\t: 6 - solids"
5710 "\n\t\t: 7 - compounds"
5711 __FILE__,VActivatedMode,group);
5713 theCommands.Add("vunsetam",
5714 "vunsetam : Deactivates all selection modes for all shapes.",
5715 __FILE__,VActivatedMode,group);
5717 theCommands.Add("vstate",
5718 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5719 "\n\t\t: Reports show/hidden state for selected or named objects"
5720 "\n\t\t: -entities - print low-level information about detected entities"
5721 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5722 __FILE__,VState,group);
5724 theCommands.Add("vpickshapes",
5725 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5726 __FILE__,VPickShape,group);
5728 theCommands.Add("vtypes",
5729 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5732 theCommands.Add("vr",
5734 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
5735 __FILE__,vr, group);
5737 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5738 __FILE__, VPickSelected, group);
5740 theCommands.Add ("vloadselection",
5741 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5742 "\n\t\t: primitives for the shapes with names given without displaying them."
5743 "\n\t\t: -local - open local context before selection computation",
5744 __FILE__, VLoadSelection, group);
5746 theCommands.Add("vbsdf", "vbsdf [name] [options]"
5747 "\nAdjusts parameters of material BSDF:"
5748 "\n -help : Shows this message"
5749 "\n -print : Print BSDF"
5750 "\n -kd : Weight of the Lambertian BRDF"
5751 "\n -kr : Weight of the reflection BRDF"
5752 "\n -kt : Weight of the transmission BTDF"
5753 "\n -ks : Weight of the glossy Blinn BRDF"
5754 "\n -le : Self-emitted radiance"
5755 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5756 "\n Schlick x y z, Dielectric x, Conductor x y"
5757 "\n -roughness : Roughness of material (Blinn's exponent)"
5758 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
5759 "\n -absorpcolor : Absorption color (only for transparent material)"
5760 "\n -normalize : Normalize BSDF coefficients",
5761 __FILE__, VBsdf, group);
5765 //=====================================================================
5766 //========================= for testing Draft and Rib =================
5767 //=====================================================================
5768 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5769 #include <DBRep.hxx>
5770 #include <TopoDS_Face.hxx>
5771 #include <gp_Pln.hxx>
5772 #include <AIS_KindOfSurface.hxx>
5773 #include <BRepOffsetAPI_DraftAngle.hxx>
5774 #include <Precision.hxx>
5775 #include <BRepAlgo.hxx>
5776 #include <OSD_Environment.hxx>
5777 #include <DrawTrSurf.hxx>
5778 //#include <DbgTools.hxx>
5779 //#include <FeatAlgo_MakeLinearForm.hxx>
5784 //=======================================================================
5785 //function : IsValid
5787 //=======================================================================
5788 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5789 const TopoDS_Shape& theResult,
5790 const Standard_Boolean closedSolid,
5791 const Standard_Boolean GeomCtrl)
5793 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5794 TCollection_AsciiString checkValid = check.Value();
5795 Standard_Boolean ToCheck = Standard_True;
5796 if (!checkValid.IsEmpty()) {
5798 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5800 if ( checkValid=="true" || checkValid=="TRUE" ) {
5801 ToCheck= Standard_False;
5805 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
5808 Standard_Boolean IsValid = Standard_True;
5810 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5815 //===============================================================================
5816 // TDraft : test draft, uses AIS Viewer
5817 // Solid Face Plane Angle Reverse
5818 //===============================================================================
5819 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5821 if (argc < 5) return 1;
5822 // argv[1] - TopoDS_Shape Solid
5823 // argv[2] - TopoDS_Shape Face
5824 // argv[3] - TopoDS_Shape Plane
5825 // argv[4] - Standard_Real Angle
5826 // argv[5] - Standard_Integer Reverse
5828 // Sprintf(prefix, argv[1]);
5829 Standard_Real anAngle = 0;
5830 Standard_Boolean Rev = Standard_False;
5831 Standard_Integer rev = 0;
5832 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5833 TopoDS_Shape face = GetShapeFromName(argv[2]);
5834 TopoDS_Face Face = TopoDS::Face(face);
5835 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5836 if (Plane.IsNull ()) {
5837 di << "TEST : Plane is NULL\n";
5840 anAngle = Draw::Atof(argv[4]);
5841 anAngle = 2*M_PI * anAngle / 360.0;
5843 Handle( Geom_Surface )aSurf;
5844 AIS_KindOfSurface aSurfType;
5845 Standard_Real Offset;
5847 if(argc > 4) { // == 5
5848 rev = Draw::Atoi(argv[5]);
5849 Rev = (rev)? Standard_True : Standard_False;
5852 TopoDS_Face face2 = TopoDS::Face(Plane);
5853 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5855 di << "TEST : Can't find plane\n";
5859 aDir = aPln.Axis().Direction();
5862 if (Plane.Orientation() == TopAbs_REVERSED)
5864 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5866 BRepOffsetAPI_DraftAngle Draft (Solid);
5868 if(Abs(anAngle)< Precision::Angular()) {
5869 di << "TEST : NULL angle\n";
5872 if(Rev) anAngle = - anAngle;
5873 Draft.Add (Face, aDir, anAngle, aPln);
5875 if (!Draft.IsDone()) {
5876 di << "TEST : Draft Not DONE \n";
5879 TopTools_ListOfShape Larg;
5881 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
5882 di << "TEST : DesignAlgo returns Not valid\n";
5886 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5887 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
5889 if ( !ais.IsNull() ) {
5890 ais->SetColor(DEFAULT_COLOR);
5891 ais->SetMaterial(DEFAULT_MATERIAL);
5892 // Display the AIS_Shape without redraw
5893 Ctx->Display(ais, Standard_False);
5895 const char *Name = "draft1";
5896 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
5898 Handle(AIS_InteractiveObject) an_object =
5899 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
5900 if (!an_object.IsNull()) {
5901 Ctx->Remove(an_object,
5903 GetMapOfAIS().UnBind2(Name) ;
5906 GetMapOfAIS().Bind(ais, Name);
5907 // DBRep::Set("draft", ais->Shape());
5909 Ctx->Display(ais, Standard_True);
5913 //==============================================================================
5914 //function : splitParameter
5915 //purpose : Split parameter string to parameter name and parameter value
5916 //==============================================================================
5917 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
5918 TCollection_AsciiString& theName,
5919 TCollection_AsciiString& theValue)
5921 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
5923 if (aParamNameEnd == 0)
5925 return Standard_False;
5928 TCollection_AsciiString aString (theString);
5929 if (aParamNameEnd != 0)
5931 theValue = aString.Split (aParamNameEnd);
5932 aString.Split (aString.Length() - 1);
5936 return Standard_True;
5939 //============================================================================
5941 //============================================================================
5942 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
5945 DrawTrSurf::BasicCommands(theCommands);
5946 const char* group = "Check Features Operations commands";
5948 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
5950 &TDraft,group); //Draft_Modification
5953 //==============================================================================
5954 // ViewerTest::Factory
5955 //==============================================================================
5956 void ViewerTest::Factory(Draw_Interpretor& theDI)
5958 // definition of Viewer Command
5959 ViewerTest::Commands(theDI);
5962 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
5966 // Declare entry point PLUGINFACTORY