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, Standard_True);
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;
928 bool isBigEndian = Image_PixMap::IsBigEndianHost();
929 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
930 switch (aParams.BufferType)
932 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
933 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
934 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
939 case ViewerTest_SP_Single:
941 if (!aView->ToPixMap (aPixMap, aParams))
943 theDI << "Fail: view dump failed!\n";
946 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
947 || aPixMap.SizeY() != Standard_Size(aParams.Height))
949 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
950 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
954 case ViewerTest_SP_SideBySide:
956 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
958 theDI << "Fail: not enough memory for image allocation!\n";
962 Image_PixMap aPixMapL, aPixMapR;
963 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
964 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
965 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
966 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
968 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
969 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
970 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
971 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
974 theDI << "Fail: view dump failed!\n";
979 case ViewerTest_SP_OverUnder:
981 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
983 theDI << "Fail: not enough memory for image allocation!\n";
987 Image_PixMap aPixMapL, aPixMapR;
988 aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
989 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
990 aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
991 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
993 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
994 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
995 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
996 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
999 theDI << "Fail: view dump failed!\n";
1006 if (!aPixMap.Save (aFilePath))
1008 theDI << "Fail: image can not be saved!\n";
1013 enum TypeOfDispOperation
1015 TypeOfDispOperation_SetDispMode,
1016 TypeOfDispOperation_UnsetDispMode
1019 //! Displays,Erase...
1020 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1021 const Standard_Integer theMode,
1022 const TypeOfDispOperation theType,
1023 const Standard_Boolean theToUpdate)
1025 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1028 case TypeOfDispOperation_SetDispMode:
1030 if (!thePrs.IsNull())
1032 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1036 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1040 case TypeOfDispOperation_UnsetDispMode:
1042 if (!thePrs.IsNull())
1044 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1048 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1055 //=======================================================================
1058 //=======================================================================
1059 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1064 std::cout << "Syntax error: wrong number of arguments\n";
1068 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1069 ? TypeOfDispOperation_UnsetDispMode
1070 : TypeOfDispOperation_SetDispMode;
1071 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1072 if (aType == TypeOfDispOperation_UnsetDispMode)
1076 if (aCtx->NbSelected() == 0)
1078 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1082 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1084 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1087 aCtx->UpdateCurrentViewer();
1091 TCollection_AsciiString aName = argv[1];
1092 if (GetMapOfAIS().IsBound2 (aName))
1094 Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1097 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1104 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1105 if (aCtx->NbSelected() == 0
1106 && aType == TypeOfDispOperation_SetDispMode)
1108 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1110 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1112 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1114 aCtx->UpdateCurrentViewer();
1118 Handle(AIS_InteractiveObject) aPrs;
1119 TCollection_AsciiString aName (argv[1]);
1120 if (GetMapOfAIS().IsBound2 (aName))
1122 aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1126 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1133 //=======================================================================
1136 //=======================================================================
1137 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1139 if(argc==1) return 1;
1140 Standard_Integer On = Draw::Atoi(argv[1]);
1141 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1145 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1146 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1147 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1151 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1155 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1159 Ctx->UpdateCurrentViewer();
1162 Handle(AIS_InteractiveObject) IO;
1163 TCollection_AsciiString name = argv[2];
1164 if(GetMapOfAIS().IsBound2(name)){
1165 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1168 Ctx->SubIntensityOn(IO);
1170 Ctx->SubIntensityOff(IO);
1178 //! Auxiliary class to iterate presentations from different collections.
1179 class ViewTest_PrsIter
1183 //! Create and initialize iterator object.
1184 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1185 : mySource (IterSource_All)
1187 NCollection_Sequence<TCollection_AsciiString> aNames;
1188 if (!theName.IsEmpty())
1189 aNames.Append (theName);
1193 //! Create and initialize iterator object.
1194 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1195 : mySource (IterSource_All)
1200 //! Initialize the iterator.
1201 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1203 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1205 mySelIter.Nullify();
1206 myCurrent.Nullify();
1207 myCurrentTrs.Nullify();
1208 if (!mySeq.IsEmpty())
1210 mySource = IterSource_List;
1211 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1213 else if (aCtx->NbSelected() > 0)
1215 mySource = IterSource_Selected;
1217 mySelIter->InitSelected();
1221 mySource = IterSource_All;
1222 myMapIter.Initialize (GetMapOfAIS());
1227 const TCollection_AsciiString& CurrentName() const
1229 return myCurrentName;
1232 const Handle(AIS_InteractiveObject)& Current() const
1237 const Handle(Standard_Transient)& CurrentTrs() const
1239 return myCurrentTrs;
1242 //! @return true if iterator points to valid object within collection
1243 Standard_Boolean More() const
1247 case IterSource_All: return myMapIter.More();
1248 case IterSource_List: return mySeqIter.More();
1249 case IterSource_Selected: return mySelIter->MoreSelected();
1251 return Standard_False;
1254 //! Go to the next item.
1257 myCurrentName.Clear();
1258 myCurrentTrs.Nullify();
1259 myCurrent.Nullify();
1262 case IterSource_All:
1267 case IterSource_List:
1272 case IterSource_Selected:
1274 mySelIter->NextSelected();
1287 case IterSource_All:
1289 if (myMapIter.More())
1291 myCurrentName = myMapIter.Key2();
1292 myCurrentTrs = myMapIter.Key1();
1293 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1297 case IterSource_List:
1299 if (mySeqIter.More())
1301 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1303 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1306 myCurrentName = mySeqIter.Value();
1307 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1308 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1312 case IterSource_Selected:
1314 if (mySelIter->MoreSelected())
1316 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1317 myCurrent = mySelIter->SelectedInteractive();
1335 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1336 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1337 NCollection_Sequence<TCollection_AsciiString> mySeq;
1338 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1340 TCollection_AsciiString myCurrentName;//!< current item name
1341 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1342 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1344 IterSource mySource; //!< iterated collection
1348 //==============================================================================
1349 //function : VInteriorStyle
1350 //purpose : sets interior style of the a selected or named or displayed shape
1351 //==============================================================================
1352 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1353 Standard_Integer theArgNb,
1354 const char** theArgVec)
1356 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1357 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1360 std::cerr << "Error: no active view!\n";
1364 Standard_Integer anArgIter = 1;
1365 for (; anArgIter < theArgNb; ++anArgIter)
1367 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1372 TCollection_AsciiString aName;
1373 if (theArgNb - anArgIter == 2)
1375 aName = theArgVec[anArgIter++];
1377 else if (theArgNb - anArgIter != 1)
1379 std::cout << "Error: wrong number of arguments! See usage:\n";
1380 theDI.PrintHelp (theArgVec[0]);
1383 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1384 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1385 aStyleArg.LowerCase();
1386 if (aStyleArg == "empty")
1390 else if (aStyleArg == "hollow")
1394 else if (aStyleArg == "hatch")
1398 else if (aStyleArg == "solid")
1402 else if (aStyleArg == "hiddenline")
1408 anInterStyle = aStyleArg.IntegerValue();
1410 if (anInterStyle < Aspect_IS_EMPTY
1411 || anInterStyle > Aspect_IS_HIDDENLINE)
1413 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1414 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1418 if (!aName.IsEmpty()
1419 && !GetMapOfAIS().IsBound2 (aName))
1421 std::cout << "Error: object " << aName << " is not displayed!\n";
1425 if (aCtx->HasOpenedContext())
1427 aCtx->CloseLocalContext();
1429 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1431 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1434 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1435 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1436 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1437 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1438 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1444 //! Auxiliary structure for VAspects
1445 struct ViewerTest_AspectsChangeSet
1447 Standard_Integer ToSetVisibility;
1448 Standard_Integer Visibility;
1450 Standard_Integer ToSetColor;
1451 Quantity_Color Color;
1453 Standard_Integer ToSetLineWidth;
1454 Standard_Real LineWidth;
1456 Standard_Integer ToSetTypeOfLine;
1457 Aspect_TypeOfLine TypeOfLine;
1459 Standard_Integer ToSetTransparency;
1460 Standard_Real Transparency;
1462 Standard_Integer ToSetMaterial;
1463 Graphic3d_NameOfMaterial Material;
1464 TCollection_AsciiString MatName;
1466 NCollection_Sequence<TopoDS_Shape> SubShapes;
1468 Standard_Integer ToSetShowFreeBoundary;
1469 Standard_Integer ToSetFreeBoundaryWidth;
1470 Standard_Real FreeBoundaryWidth;
1471 Standard_Integer ToSetFreeBoundaryColor;
1472 Quantity_Color FreeBoundaryColor;
1474 Standard_Integer ToEnableIsoOnTriangulation;
1476 Standard_Integer ToSetMaxParamValue;
1477 Standard_Real MaxParamValue;
1479 Standard_Integer ToSetSensitivity;
1480 Standard_Integer SelectionMode;
1481 Standard_Integer Sensitivity;
1483 //! Empty constructor
1484 ViewerTest_AspectsChangeSet()
1485 : ToSetVisibility (0),
1488 Color (DEFAULT_COLOR),
1491 ToSetTypeOfLine (0),
1492 TypeOfLine (Aspect_TOL_SOLID),
1493 ToSetTransparency (0),
1496 Material (Graphic3d_NOM_DEFAULT),
1497 ToSetShowFreeBoundary (0),
1498 ToSetFreeBoundaryWidth (0),
1499 FreeBoundaryWidth (1.0),
1500 ToSetFreeBoundaryColor (0),
1501 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1502 ToEnableIsoOnTriangulation (-1),
1503 ToSetMaxParamValue (0),
1504 MaxParamValue (500000),
1505 ToSetSensitivity (0),
1509 //! @return true if no changes have been requested
1510 Standard_Boolean IsEmpty() const
1512 return ToSetVisibility == 0
1513 && ToSetLineWidth == 0
1514 && ToSetTransparency == 0
1516 && ToSetMaterial == 0
1517 && ToSetShowFreeBoundary == 0
1518 && ToSetFreeBoundaryColor == 0
1519 && ToSetFreeBoundaryWidth == 0
1520 && ToSetMaxParamValue == 0
1521 && ToSetSensitivity == 0;
1524 //! @return true if properties are valid
1525 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1527 Standard_Boolean isOk = Standard_True;
1528 if (Visibility != 0 && Visibility != 1)
1530 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1531 isOk = Standard_False;
1533 if (LineWidth <= 0.0
1534 || LineWidth > 10.0)
1536 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1537 isOk = Standard_False;
1539 if (Transparency < 0.0
1540 || Transparency > 1.0)
1542 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1543 isOk = Standard_False;
1546 && ToSetTransparency)
1548 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1549 isOk = Standard_False;
1551 if (ToSetMaterial == 1
1552 && Material == Graphic3d_NOM_DEFAULT)
1554 std::cout << "Error: unknown material " << MatName << ".\n";
1555 isOk = Standard_False;
1557 if (FreeBoundaryWidth <= 0.0
1558 || FreeBoundaryWidth > 10.0)
1560 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1561 isOk = Standard_False;
1563 if (MaxParamValue < 0.0)
1565 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1566 isOk = Standard_False;
1568 if (Sensitivity <= 0 && ToSetSensitivity)
1570 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1571 isOk = Standard_False;
1578 //==============================================================================
1579 //function : VAspects
1581 //==============================================================================
1582 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1583 Standard_Integer theArgNb,
1584 const char** theArgVec)
1586 TCollection_AsciiString aCmdName (theArgVec[0]);
1587 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1588 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1591 std::cerr << "Error: no active view!\n";
1595 Standard_Integer anArgIter = 1;
1596 Standard_Boolean isDefaults = Standard_False;
1597 NCollection_Sequence<TCollection_AsciiString> aNames;
1598 for (; anArgIter < theArgNb; ++anArgIter)
1600 TCollection_AsciiString anArg = theArgVec[anArgIter];
1601 if (anUpdateTool.parseRedrawMode (anArg))
1605 else if (!anArg.IsEmpty()
1606 && anArg.Value (1) != '-')
1608 aNames.Append (anArg);
1612 if (anArg == "-defaults")
1614 isDefaults = Standard_True;
1621 if (!aNames.IsEmpty() && isDefaults)
1623 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1627 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1628 aChanges.Append (ViewerTest_AspectsChangeSet());
1629 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1631 // parse syntax of legacy commands
1632 if (aCmdName == "vsetwidth")
1634 if (aNames.IsEmpty()
1635 || !aNames.Last().IsRealValue())
1637 std::cout << "Error: not enough arguments!\n";
1640 aChangeSet->ToSetLineWidth = 1;
1641 aChangeSet->LineWidth = aNames.Last().RealValue();
1642 aNames.Remove (aNames.Length());
1644 else if (aCmdName == "vunsetwidth")
1646 aChangeSet->ToSetLineWidth = -1;
1648 else if (aCmdName == "vsetcolor")
1650 if (aNames.IsEmpty())
1652 std::cout << "Error: not enough arguments!\n";
1655 aChangeSet->ToSetColor = 1;
1657 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1658 Standard_Boolean isOk = Standard_False;
1659 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1661 aChangeSet->Color = aColor;
1662 aNames.Remove (aNames.Length());
1663 isOk = Standard_True;
1665 else if (aNames.Length() >= 3)
1667 const TCollection_AsciiString anRgbStr[3] =
1669 aNames.Value (aNames.Upper() - 2),
1670 aNames.Value (aNames.Upper() - 1),
1671 aNames.Value (aNames.Upper() - 0)
1673 isOk = anRgbStr[0].IsRealValue()
1674 && anRgbStr[1].IsRealValue()
1675 && anRgbStr[2].IsRealValue();
1678 Graphic3d_Vec4d anRgb;
1679 anRgb.x() = anRgbStr[0].RealValue();
1680 anRgb.y() = anRgbStr[1].RealValue();
1681 anRgb.z() = anRgbStr[2].RealValue();
1682 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1683 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1684 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1686 std::cout << "Error: RGB color values should be within range 0..1!\n";
1689 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1690 aNames.Remove (aNames.Length());
1691 aNames.Remove (aNames.Length());
1692 aNames.Remove (aNames.Length());
1697 std::cout << "Error: not enough arguments!\n";
1701 else if (aCmdName == "vunsetcolor")
1703 aChangeSet->ToSetColor = -1;
1705 else if (aCmdName == "vsettransparency")
1707 if (aNames.IsEmpty()
1708 || !aNames.Last().IsRealValue())
1710 std::cout << "Error: not enough arguments!\n";
1713 aChangeSet->ToSetTransparency = 1;
1714 aChangeSet->Transparency = aNames.Last().RealValue();
1715 aNames.Remove (aNames.Length());
1717 else if (aCmdName == "vunsettransparency")
1719 aChangeSet->ToSetTransparency = -1;
1721 else if (aCmdName == "vsetmaterial")
1723 if (aNames.IsEmpty())
1725 std::cout << "Error: not enough arguments!\n";
1728 aChangeSet->ToSetMaterial = 1;
1729 aChangeSet->MatName = aNames.Last();
1730 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1731 aNames.Remove (aNames.Length());
1733 else if (aCmdName == "vunsetmaterial")
1735 aChangeSet->ToSetMaterial = -1;
1737 else if (anArgIter >= theArgNb)
1739 std::cout << "Error: not enough arguments!\n";
1743 if (!aChangeSet->IsEmpty())
1745 anArgIter = theArgNb;
1747 for (; anArgIter < theArgNb; ++anArgIter)
1749 TCollection_AsciiString anArg = theArgVec[anArgIter];
1751 if (anArg == "-setwidth"
1752 || anArg == "-setlinewidth")
1754 if (++anArgIter >= theArgNb)
1756 std::cout << "Error: wrong syntax at " << anArg << "\n";
1759 aChangeSet->ToSetLineWidth = 1;
1760 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1762 else if (anArg == "-unsetwidth"
1763 || anArg == "-unsetlinewidth")
1765 aChangeSet->ToSetLineWidth = -1;
1766 aChangeSet->LineWidth = 1.0;
1768 else if (anArg == "-settransp"
1769 || anArg == "-settransparency")
1771 if (++anArgIter >= theArgNb)
1773 std::cout << "Error: wrong syntax at " << anArg << "\n";
1776 aChangeSet->ToSetTransparency = 1;
1777 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1778 if (aChangeSet->Transparency >= 0.0
1779 && aChangeSet->Transparency <= Precision::Confusion())
1781 aChangeSet->ToSetTransparency = -1;
1782 aChangeSet->Transparency = 0.0;
1785 else if (anArg == "-setvis"
1786 || anArg == "-setvisibility")
1788 if (++anArgIter >= theArgNb)
1790 std::cout << "Error: wrong syntax at " << anArg << "\n";
1794 aChangeSet->ToSetVisibility = 1;
1795 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1797 else if (anArg == "-setalpha")
1799 if (++anArgIter >= theArgNb)
1801 std::cout << "Error: wrong syntax at " << anArg << "\n";
1804 aChangeSet->ToSetTransparency = 1;
1805 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1806 if (aChangeSet->Transparency < 0.0
1807 || aChangeSet->Transparency > 1.0)
1809 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1812 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1813 if (aChangeSet->Transparency >= 0.0
1814 && aChangeSet->Transparency <= Precision::Confusion())
1816 aChangeSet->ToSetTransparency = -1;
1817 aChangeSet->Transparency = 0.0;
1820 else if (anArg == "-unsettransp"
1821 || anArg == "-unsettransparency"
1822 || anArg == "-unsetalpha"
1823 || anArg == "-opaque")
1825 aChangeSet->ToSetTransparency = -1;
1826 aChangeSet->Transparency = 0.0;
1828 else if (anArg == "-setcolor")
1830 Standard_Integer aNbComps = 0;
1831 Standard_Integer aCompIter = anArgIter + 1;
1832 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1834 if (theArgVec[aCompIter][0] == '-')
1843 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1844 Standard_CString aName = theArgVec[anArgIter + 1];
1845 if (!Quantity_Color::ColorFromName (aName, aColor))
1847 std::cout << "Error: unknown color name '" << aName << "'\n";
1850 aChangeSet->Color = aColor;
1855 Graphic3d_Vec3d anRgb;
1856 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1857 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1858 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1859 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1860 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1861 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1863 std::cout << "Error: RGB color values should be within range 0..1!\n";
1866 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1871 std::cout << "Error: wrong syntax at " << anArg << "\n";
1875 aChangeSet->ToSetColor = 1;
1876 anArgIter += aNbComps;
1878 else if (anArg == "-setlinetype")
1880 if (++anArgIter >= theArgNb)
1882 std::cout << "Error: wrong syntax at " << anArg << "\n";
1886 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1889 if (aValue.IsEqual ("solid"))
1891 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1893 else if (aValue.IsEqual ("dot"))
1895 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1897 else if (aValue.IsEqual ("dash"))
1899 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1901 else if (aValue.IsEqual ("dotdash"))
1903 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1907 std::cout << "Error: wrong syntax at " << anArg << "\n";
1911 aChangeSet->ToSetTypeOfLine = 1;
1913 else if (anArg == "-unsetlinetype")
1915 aChangeSet->ToSetTypeOfLine = -1;
1917 else if (anArg == "-unsetcolor")
1919 aChangeSet->ToSetColor = -1;
1920 aChangeSet->Color = DEFAULT_COLOR;
1922 else if (anArg == "-setmat"
1923 || anArg == "-setmaterial")
1925 if (++anArgIter >= theArgNb)
1927 std::cout << "Error: wrong syntax at " << anArg << "\n";
1930 aChangeSet->ToSetMaterial = 1;
1931 aChangeSet->MatName = theArgVec[anArgIter];
1932 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1934 else if (anArg == "-unsetmat"
1935 || anArg == "-unsetmaterial")
1937 aChangeSet->ToSetMaterial = -1;
1938 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1940 else if (anArg == "-subshape"
1941 || anArg == "-subshapes")
1945 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1949 if (aNames.IsEmpty())
1951 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1955 aChanges.Append (ViewerTest_AspectsChangeSet());
1956 aChangeSet = &aChanges.ChangeLast();
1958 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1960 Standard_CString aSubShapeName = theArgVec[anArgIter];
1961 if (*aSubShapeName == '-')
1967 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1968 if (aSubShape.IsNull())
1970 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1973 aChangeSet->SubShapes.Append (aSubShape);
1976 if (aChangeSet->SubShapes.IsEmpty())
1978 std::cerr << "Error: empty list is specified after -subshapes!\n";
1982 else if (anArg == "-freeboundary"
1985 if (++anArgIter >= theArgNb)
1987 std::cout << "Error: wrong syntax at " << anArg << "\n";
1990 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1995 aChangeSet->ToSetShowFreeBoundary = 1;
1997 else if (aValue == "off"
2000 aChangeSet->ToSetShowFreeBoundary = -1;
2004 std::cout << "Error: wrong syntax at " << anArg << "\n";
2008 else if (anArg == "-setfreeboundarywidth"
2009 || anArg == "-setfbwidth")
2011 if (++anArgIter >= theArgNb)
2013 std::cout << "Error: wrong syntax at " << anArg << "\n";
2016 aChangeSet->ToSetFreeBoundaryWidth = 1;
2017 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2019 else if (anArg == "-unsetfreeboundarywidth"
2020 || anArg == "-unsetfbwidth")
2022 aChangeSet->ToSetFreeBoundaryWidth = -1;
2023 aChangeSet->FreeBoundaryWidth = 1.0;
2025 else if (anArg == "-setfreeboundarycolor"
2026 || anArg == "-setfbcolor")
2028 Standard_Integer aNbComps = 0;
2029 Standard_Integer aCompIter = anArgIter + 1;
2030 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2032 if (theArgVec[aCompIter][0] == '-')
2041 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2042 Standard_CString aName = theArgVec[anArgIter + 1];
2043 if (!Quantity_Color::ColorFromName (aName, aColor))
2045 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2048 aChangeSet->FreeBoundaryColor = aColor;
2053 Graphic3d_Vec3d anRgb;
2054 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2055 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2056 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2057 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2058 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2059 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2061 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2064 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2069 std::cout << "Error: wrong syntax at " << anArg << "\n";
2073 aChangeSet->ToSetFreeBoundaryColor = 1;
2074 anArgIter += aNbComps;
2076 else if (anArg == "-unsetfreeboundarycolor"
2077 || anArg == "-unsetfbcolor")
2079 aChangeSet->ToSetFreeBoundaryColor = -1;
2080 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2082 else if (anArg == "-unset")
2084 aChangeSet->ToSetVisibility = 1;
2085 aChangeSet->Visibility = 1;
2086 aChangeSet->ToSetLineWidth = -1;
2087 aChangeSet->LineWidth = 1.0;
2088 aChangeSet->ToSetTypeOfLine = -1;
2089 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2090 aChangeSet->ToSetTransparency = -1;
2091 aChangeSet->Transparency = 0.0;
2092 aChangeSet->ToSetColor = -1;
2093 aChangeSet->Color = DEFAULT_COLOR;
2094 aChangeSet->ToSetMaterial = -1;
2095 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2096 aChangeSet->ToSetShowFreeBoundary = -1;
2097 aChangeSet->ToSetFreeBoundaryColor = -1;
2098 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2099 aChangeSet->ToSetFreeBoundaryWidth = -1;
2100 aChangeSet->FreeBoundaryWidth = 1.0;
2102 else if (anArg == "-isoontriangulation"
2103 || anArg == "-isoontriang")
2105 if (++anArgIter >= theArgNb)
2107 std::cout << "Error: wrong syntax at " << anArg << "\n";
2110 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2115 aChangeSet->ToEnableIsoOnTriangulation = 1;
2117 else if (aValue == "off"
2120 aChangeSet->ToEnableIsoOnTriangulation = 0;
2124 std::cout << "Error: wrong syntax at " << anArg << "\n";
2128 else if (anArg == "-setmaxparamvalue")
2130 if (++anArgIter >= theArgNb)
2132 std::cout << "Error: wrong syntax at " << anArg << "\n";
2135 aChangeSet->ToSetMaxParamValue = 1;
2136 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2138 else if (anArg == "-setsensitivity")
2142 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2146 if (aNames.IsEmpty())
2148 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2152 if (anArgIter + 2 >= theArgNb)
2154 std::cout << "Error: wrong syntax at " << anArg << "\n";
2157 aChangeSet->ToSetSensitivity = 1;
2158 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2159 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2163 std::cout << "Error: wrong syntax at " << anArg << "\n";
2168 Standard_Boolean isFirst = Standard_True;
2169 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2170 aChangesIter.More(); aChangesIter.Next())
2172 if (!aChangesIter.Value().Validate (!isFirst))
2176 isFirst = Standard_False;
2179 if (aCtx->HasOpenedContext())
2181 aCtx->CloseLocalContext();
2184 // special case for -defaults parameter.
2185 // all changed values will be set to DefaultDrawer.
2188 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2190 if (aChangeSet->ToSetLineWidth != 0)
2192 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2193 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2194 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2195 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2197 if (aChangeSet->ToSetColor != 0)
2199 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2200 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2201 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2202 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2203 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2204 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2206 if (aChangeSet->ToSetTypeOfLine != 0)
2208 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2209 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2210 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2211 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2212 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2214 if (aChangeSet->ToSetTransparency != 0)
2216 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2218 if (aChangeSet->ToSetMaterial != 0)
2220 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2222 if (aChangeSet->ToSetShowFreeBoundary == 1)
2224 aDrawer->SetFreeBoundaryDraw (Standard_True);
2226 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2228 aDrawer->SetFreeBoundaryDraw (Standard_False);
2230 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2232 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2234 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2236 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2238 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2240 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2242 if (aChangeSet->ToSetMaxParamValue != 0)
2244 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2247 // redisplay all objects in context
2248 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2250 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2253 aCtx->Redisplay (aPrs, Standard_False);
2259 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2261 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2262 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2263 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2264 Handle(AIS_ColoredShape) aColoredPrs;
2265 Standard_Boolean toDisplay = Standard_False;
2266 Standard_Boolean toRedisplay = Standard_False;
2267 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2269 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2270 if (aShapePrs.IsNull())
2272 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2275 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2276 if (aColoredPrs.IsNull())
2278 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2279 if (aShapePrs->HasDisplayMode())
2281 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2283 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2284 aCtx->Remove (aShapePrs, Standard_False);
2285 GetMapOfAIS().UnBind2 (aName);
2286 GetMapOfAIS().Bind (aColoredPrs, aName);
2287 toDisplay = Standard_True;
2288 aShapePrs = aColoredPrs;
2295 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2296 aChangeSet = &aChangesIter.ChangeValue();
2297 if (aChangeSet->ToSetVisibility == 1)
2299 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2300 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2302 else if (aChangeSet->ToSetMaterial == 1)
2304 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2306 else if (aChangeSet->ToSetMaterial == -1)
2308 aCtx->UnsetMaterial (aPrs, Standard_False);
2310 if (aChangeSet->ToSetColor == 1)
2312 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2314 else if (aChangeSet->ToSetColor == -1)
2316 aCtx->UnsetColor (aPrs, Standard_False);
2318 if (aChangeSet->ToSetTransparency == 1)
2320 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2322 else if (aChangeSet->ToSetTransparency == -1)
2324 aCtx->UnsetTransparency (aPrs, Standard_False);
2326 if (aChangeSet->ToSetLineWidth == 1)
2328 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2330 else if (aChangeSet->ToSetLineWidth == -1)
2332 aCtx->UnsetWidth (aPrs, Standard_False);
2334 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2336 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2337 toRedisplay = Standard_True;
2339 else if (aChangeSet->ToSetSensitivity != 0)
2341 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2343 if (!aDrawer.IsNull())
2345 if (aChangeSet->ToSetShowFreeBoundary == 1)
2347 aDrawer->SetFreeBoundaryDraw (Standard_True);
2348 toRedisplay = Standard_True;
2350 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2352 aDrawer->SetFreeBoundaryDraw (Standard_False);
2353 toRedisplay = Standard_True;
2355 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2357 Handle(Prs3d_LineAspect) aBoundaryAspect =
2358 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2359 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2360 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2361 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2362 toRedisplay = Standard_True;
2364 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2366 Handle(Prs3d_LineAspect) aBoundaryAspect =
2367 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2368 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2369 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2370 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2371 toRedisplay = Standard_True;
2373 if (aChangeSet->ToSetTypeOfLine != 0)
2375 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2376 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2377 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2378 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2379 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2380 toRedisplay = Standard_True;
2382 if (aChangeSet->ToSetMaxParamValue != 0)
2384 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2388 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2390 aChangeSet = &aChangesIter.ChangeValue();
2391 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2392 aSubShapeIter.More(); aSubShapeIter.Next())
2394 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2395 if (aChangeSet->ToSetVisibility == 1)
2397 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2398 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2400 if (aChangeSet->ToSetColor == 1)
2402 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2404 if (aChangeSet->ToSetLineWidth == 1)
2406 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2408 if (aChangeSet->ToSetColor == -1
2409 || aChangeSet->ToSetLineWidth == -1)
2411 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2413 if (aChangeSet->ToSetMaxParamValue != 0)
2415 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2416 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2418 if (aChangeSet->ToSetSensitivity != 0)
2420 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2426 aCtx->Display (aPrs, Standard_False);
2430 aCtx->Redisplay (aPrs, Standard_False);
2432 else if (!aColoredPrs.IsNull())
2434 aCtx->Redisplay (aColoredPrs, Standard_False);
2441 //==============================================================================
2442 //function : VDonly2
2444 //purpose : Display only a selected or named object
2445 // if there is no selected or named object s, nothing is done
2446 //==============================================================================
2447 static int VDonly2 (Draw_Interpretor& ,
2448 Standard_Integer theArgNb,
2449 const char** theArgVec)
2451 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2452 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2455 std::cerr << "Error: no active view!\n";
2459 if (aCtx->HasOpenedContext())
2461 aCtx->CloseLocalContext();
2464 Standard_Integer anArgIter = 1;
2465 for (; anArgIter < theArgNb; ++anArgIter)
2467 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2473 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2474 if (anArgIter >= theArgNb)
2476 // display only selected objects
2477 if (aCtx->NbSelected() < 1)
2482 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2484 aDispSet.Add (aCtx->SelectedInteractive());
2489 // display only specified objects
2490 for (; anArgIter < theArgNb; ++anArgIter)
2492 TCollection_AsciiString aName = theArgVec[anArgIter];
2493 if (GetMapOfAIS().IsBound2 (aName))
2495 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2496 if (!aShape.IsNull())
2498 aCtx->Display (aShape, Standard_False);
2499 aDispSet.Add (aShape);
2505 // weed out other objects
2506 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2508 if (aDispSet.Contains (anIter.Key1()))
2513 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2514 if (aShape.IsNull())
2516 aCtx->Erase (aShape, Standard_False);
2522 //==============================================================================
2523 //function : VRemove
2524 //purpose : Removes selected or named objects.
2525 // If there is no selected or named objects,
2526 // all objects in the viewer can be removed with argument -all.
2527 // If -context is in arguments, the object is not deleted from the map of
2528 // objects (deleted only from the current context).
2529 //==============================================================================
2530 int VRemove (Draw_Interpretor& theDI,
2531 Standard_Integer theArgNb,
2532 const char** theArgVec)
2534 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2535 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2538 std::cerr << "Error: no active view!\n";
2542 Standard_Boolean isContextOnly = Standard_False;
2543 Standard_Boolean toRemoveAll = Standard_False;
2544 Standard_Boolean toPrintInfo = Standard_True;
2545 Standard_Boolean toRemoveLocal = Standard_False;
2547 Standard_Integer anArgIter = 1;
2548 for (; anArgIter < theArgNb; ++anArgIter)
2550 TCollection_AsciiString anArg = theArgVec[anArgIter];
2552 if (anArg == "-context")
2554 isContextOnly = Standard_True;
2556 else if (anArg == "-all")
2558 toRemoveAll = Standard_True;
2560 else if (anArg == "-noinfo")
2562 toPrintInfo = Standard_False;
2564 else if (anArg == "-local")
2566 toRemoveLocal = Standard_True;
2568 else if (anUpdateTool.parseRedrawMode (anArg))
2578 && anArgIter < theArgNb)
2580 std::cerr << "Error: wrong syntax!\n";
2584 if (toRemoveLocal && !aCtx->HasOpenedContext())
2586 std::cerr << "Error: local selection context is not open.\n";
2589 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2591 aCtx->CloseAllContexts (Standard_False);
2594 NCollection_List<TCollection_AsciiString> anIONameList;
2597 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2598 anIter.More(); anIter.Next())
2600 anIONameList.Append (anIter.Key2());
2603 else if (anArgIter < theArgNb) // removed objects names are in argument list
2605 for (; anArgIter < theArgNb; ++anArgIter)
2607 TCollection_AsciiString aName = theArgVec[anArgIter];
2608 if (!GetMapOfAIS().IsBound2 (aName))
2610 theDI << aName.ToCString() << " was not bound to some object.\n";
2614 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2615 if (anIO->GetContext() != aCtx)
2617 theDI << aName.ToCString() << " was not displayed in current context.\n";
2618 theDI << "Please activate view with this object displayed and try again.\n";
2622 anIONameList.Append (aName);
2626 else if (aCtx->NbSelected() > 0)
2628 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2629 anIter.More(); anIter.Next())
2631 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2632 if (!aCtx->IsSelected (anIO))
2637 anIONameList.Append (anIter.Key2());
2642 // Unbind all removed objects from the map of displayed IO.
2643 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2644 anIter.More(); anIter.Next())
2646 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2647 aCtx->Remove (anIO, Standard_False);
2650 theDI << anIter.Value().ToCString() << " was removed\n";
2654 GetMapOfAIS().UnBind2 (anIter.Value());
2658 // Close local context if it is empty
2659 TColStd_MapOfTransient aLocalIO;
2660 if (aCtx->HasOpenedContext()
2661 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2663 aCtx->CloseAllContexts (Standard_False);
2669 //==============================================================================
2671 //purpose : Erase some selected or named objects
2672 // if there is no selected or named objects, the whole viewer is erased
2673 //==============================================================================
2674 int VErase (Draw_Interpretor& theDI,
2675 Standard_Integer theArgNb,
2676 const char** theArgVec)
2678 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2679 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2680 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2683 std::cerr << "Error: no active view!\n";
2687 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2689 Standard_Integer anArgIter = 1;
2690 Standard_Boolean toEraseLocal = Standard_False;
2691 Standard_Boolean toEraseInView = Standard_False;
2692 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2693 for (; anArgIter < theArgNb; ++anArgIter)
2695 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2696 anArgCase.LowerCase();
2697 if (anUpdateTool.parseRedrawMode (anArgCase))
2701 else if (anArgCase == "-local")
2703 toEraseLocal = Standard_True;
2705 else if (anArgCase == "-view"
2706 || anArgCase == "-inview")
2708 toEraseInView = Standard_True;
2712 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2716 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2718 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2722 if (toEraseLocal && !aCtx->HasOpenedContext())
2724 std::cerr << "Error: local selection context is not open.\n";
2727 else if (!toEraseLocal && aCtx->HasOpenedContext())
2729 aCtx->CloseAllContexts (Standard_False);
2732 if (!aNamesOfEraseIO.IsEmpty())
2734 // Erase named objects
2735 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2737 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2738 if (!GetMapOfAIS().IsBound2 (aName))
2743 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2744 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2745 theDI << aName.ToCString() << " ";
2750 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2754 aCtx->Erase (anIO, Standard_False);
2759 else if (!toEraseAll && aCtx->NbSelected() > 0)
2761 // Erase selected objects
2762 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
2763 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2764 anIter.More(); anIter.Next())
2766 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2768 && aCtx->IsSelected (anIO))
2770 theDI << anIter.Key2().ToCString() << " ";
2773 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2775 else if (aHasOpenedContext)
2777 aCtx->Erase (anIO, Standard_False);
2784 aCtx->EraseSelected (Standard_False);
2789 // Erase all objects
2790 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2791 anIter.More(); anIter.Next())
2793 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2798 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2802 aCtx->Erase (anIO, Standard_False);
2811 //==============================================================================
2812 //function : VDisplayAll
2814 //purpose : Display all the objects of the Map
2815 //==============================================================================
2816 static int VDisplayAll (Draw_Interpretor& ,
2817 Standard_Integer theArgNb,
2818 const char** theArgVec)
2821 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2822 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2825 std::cerr << "Error: no active view!\n";
2829 Standard_Integer anArgIter = 1;
2830 Standard_Boolean toDisplayLocal = Standard_False;
2831 for (; anArgIter < theArgNb; ++anArgIter)
2833 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2834 anArgCase.LowerCase();
2835 if (anArgCase == "-local")
2837 toDisplayLocal = Standard_True;
2839 else if (anUpdateTool.parseRedrawMode (anArgCase))
2848 if (anArgIter < theArgNb)
2850 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2854 if (toDisplayLocal && !aCtx->HasOpenedContext())
2856 std::cerr << "Error: local selection context is not open.\n";
2859 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2861 aCtx->CloseLocalContext (Standard_False);
2864 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2865 anIter.More(); anIter.Next())
2867 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2868 aCtx->Erase (aShape, Standard_False);
2871 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2872 anIter.More(); anIter.Next())
2874 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2875 aCtx->Display (aShape, Standard_False);
2880 //! Auxiliary method to check if presentation exists
2881 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
2882 const Handle(AIS_InteractiveObject)& theIO,
2883 const Standard_Integer theMode)
2885 if (theIO.IsNull() || theCtx.IsNull())
2892 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2897 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2899 return theIO->DisplayMode();
2901 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2903 return theCtx->DisplayMode();
2909 enum ViewerTest_BndAction
2916 //! Auxiliary method to print bounding box of presentation
2917 inline void bndPresentation (Draw_Interpretor& theDI,
2918 const Handle(PrsMgr_PresentationManager)& theMgr,
2919 const Handle(AIS_InteractiveObject)& theObj,
2920 const Standard_Integer theDispMode,
2921 const TCollection_AsciiString& theName,
2922 const ViewerTest_BndAction theAction,
2923 const Handle(Graphic3d_HighlightStyle)& theStyle)
2927 case BndAction_Hide:
2929 theMgr->Unhighlight (theObj, theDispMode);
2932 case BndAction_Show:
2934 theMgr->Color (theObj, theStyle, theDispMode);
2937 case BndAction_Print:
2940 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
2942 if (aPrsIter.Value().Mode() != theDispMode)
2945 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
2947 gp_Pnt aMin = aBox.CornerMin();
2948 gp_Pnt aMax = aBox.CornerMax();
2949 theDI << theName << "\n"
2950 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2951 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2957 //==============================================================================
2958 //function : VBounding
2960 //==============================================================================
2961 int VBounding (Draw_Interpretor& theDI,
2962 Standard_Integer theArgNb,
2963 const char** theArgVec)
2965 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2966 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2969 std::cout << "Error: no active view!\n";
2973 ViewerTest_BndAction anAction = BndAction_Show;
2974 Standard_Integer aMode = -1;
2976 Handle(Graphic3d_HighlightStyle) aStyle;
2978 Standard_Integer anArgIter = 1;
2979 for (; anArgIter < theArgNb; ++anArgIter)
2981 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2983 if (anArg == "-print")
2985 anAction = BndAction_Print;
2987 else if (anArg == "-show")
2989 anAction = BndAction_Show;
2991 else if (anArg == "-hide")
2993 anAction = BndAction_Hide;
2995 else if (anArg == "-mode")
2997 if (++anArgIter >= theArgNb)
2999 std::cout << "Error: wrong syntax at " << anArg << "\n";
3002 aMode = Draw::Atoi (theArgVec[anArgIter]);
3004 else if (!anUpdateTool.parseRedrawMode (anArg))
3010 if (anAction == BndAction_Show)
3011 aStyle = new Graphic3d_HighlightStyle (Aspect_TOHM_BOUNDBOX, Quantity_NOC_GRAY99, 0.0);
3013 Standard_Integer aHighlightedMode = -1;
3014 if (anArgIter < theArgNb)
3016 // has a list of names
3017 for (; anArgIter < theArgNb; ++anArgIter)
3019 TCollection_AsciiString aName = theArgVec[anArgIter];
3020 if (!GetMapOfAIS().IsBound2 (aName))
3022 std::cout << "Error: presentation " << aName << " does not exist\n";
3026 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3027 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3028 if (aHighlightedMode == -1)
3030 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3033 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3036 else if (aCtx->NbSelected() > 0)
3038 // remove all currently selected objects
3039 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3041 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3042 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3043 if (aHighlightedMode != -1)
3045 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3046 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3053 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3054 anIter.More(); anIter.Next())
3056 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3057 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3058 if (aHighlightedMode != -1)
3060 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3067 //==============================================================================
3068 //function : VTexture
3070 //==============================================================================
3071 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
3073 TCollection_AsciiString aCommandName (theArgv[0]);
3075 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3076 if (aCommandName == "vtexture")
3080 std::cout << theArgv[0] << ": invalid arguments.\n";
3081 std::cout << "Type help for more information.\n";
3085 // look for options of vtexture command
3086 TCollection_AsciiString aParseKey;
3087 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3089 TCollection_AsciiString anArg (theArgv [anArgIt]);
3092 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3095 aParseKey.Remove (1);
3096 aParseKey.UpperCase();
3097 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3101 if (aParseKey.IsEmpty())
3106 aMapOfArgs(aParseKey)->Append (anArg);
3109 else if (aCommandName == "vtexscale"
3110 || aCommandName == "vtexorigin"
3111 || aCommandName == "vtexrepeat")
3113 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3114 // equal to -scale, -origin, -repeat options of vtexture command
3115 if (theArgsNb < 2 || theArgsNb > 4)
3117 std::cout << theArgv[0] << ": invalid arguments.\n";
3118 std::cout << "Type help for more information.\n";
3122 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
3125 anArgs->Append ("OFF");
3127 else if (theArgsNb == 4)
3129 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3130 anArgs->Append (TCollection_AsciiString (theArgv[3]));
3133 TCollection_AsciiString anArgKey;
3134 if (aCommandName == "vtexscale")
3138 else if (aCommandName == "vtexorigin")
3140 anArgKey = "ORIGIN";
3144 anArgKey = "REPEAT";
3147 aMapOfArgs.Bind (anArgKey, anArgs);
3149 else if (aCommandName == "vtexdefault")
3151 // scan for parameters of vtexdefault command
3152 // equal to -default option of vtexture command
3153 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
3156 // Check arguments for validity
3157 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3158 for (; aMapIt.More(); aMapIt.Next())
3160 const TCollection_AsciiString& aKey = aMapIt.Key();
3161 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3163 // -scale, -origin, -repeat: one argument "off", or two real values
3164 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3165 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3166 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3171 // -modulate: single argument "on" / "off"
3172 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3177 // -default: no arguments
3178 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3183 TCollection_AsciiString aLowerKey;
3186 aLowerKey.LowerCase();
3187 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3188 std::cout << "Type help for more information.\n";
3192 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3193 if (anAISContext.IsNull())
3195 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
3199 Standard_Integer aPreviousMode = 0;
3201 TCollection_AsciiString aShapeName (theArgv[1]);
3202 Handle(AIS_InteractiveObject) anIO;
3204 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3205 if (aMapOfIO.IsBound2 (aShapeName))
3207 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3212 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3216 Handle(AIS_TexturedShape) aTexturedIO;
3217 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3219 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3220 aPreviousMode = aTexturedIO->DisplayMode();
3224 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3226 if (anIO->HasTransformation())
3228 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3229 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3232 anAISContext->Remove (anIO, Standard_False);
3233 GetMapOfAIS().UnBind1 (anIO);
3234 GetMapOfAIS().UnBind2 (aShapeName);
3235 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3238 // -------------------------------------------
3239 // Turn texturing on/off - only for vtexture
3240 // -------------------------------------------
3242 if (aCommandName == "vtexture")
3244 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3246 if (aTextureArg.IsEmpty())
3248 std::cout << aCommandName << ": Texture mapping disabled.\n";
3249 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
3251 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3252 if (aPreviousMode == 3)
3254 anAISContext->RecomputePrsOnly (aTexturedIO);
3257 anAISContext->Display (aTexturedIO, Standard_True);
3260 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3262 if (aTextureArg == "?")
3264 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3266 theDi << "\n Files in current directory : \n\n";
3267 theDi.Eval ("glob -nocomplain *");
3269 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3270 aCmnd += aTextureFolder;
3273 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
3274 theDi.Eval (aCmnd.ToCString());
3279 aTexturedIO->SetTextureFileName (aTextureArg);
3284 // ------------------------------------
3285 // Process other options and commands
3286 // ------------------------------------
3288 Handle(TColStd_HSequenceOfAsciiString) aValues;
3289 if (aMapOfArgs.Find ("DEFAULT", aValues))
3291 aTexturedIO->SetTextureRepeat (Standard_False);
3292 aTexturedIO->SetTextureOrigin (Standard_False);
3293 aTexturedIO->SetTextureScale (Standard_False);
3294 aTexturedIO->EnableTextureModulate();
3298 if (aMapOfArgs.Find ("SCALE", aValues))
3300 if (aValues->Value(1) != "OFF")
3302 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3306 aTexturedIO->SetTextureScale (Standard_False);
3310 if (aMapOfArgs.Find ("ORIGIN", aValues))
3312 if (aValues->Value(1) != "OFF")
3314 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3318 aTexturedIO->SetTextureOrigin (Standard_False);
3322 if (aMapOfArgs.Find ("REPEAT", aValues))
3324 if (aValues->Value(1) != "OFF")
3326 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3330 aTexturedIO->SetTextureRepeat (Standard_False);
3334 if (aMapOfArgs.Find ("MODULATE", aValues))
3336 if (aValues->Value(1) == "ON")
3338 aTexturedIO->EnableTextureModulate();
3342 aTexturedIO->DisableTextureModulate();
3347 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3349 anAISContext->RecomputePrsOnly (aTexturedIO);
3353 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3354 anAISContext->Display (aTexturedIO, Standard_True);
3355 anAISContext->Update (aTexturedIO,Standard_True);
3361 //! Auxiliary method to parse transformation persistence flags
3362 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3363 Graphic3d_TransModeFlags& theFlags)
3365 if (theFlagString == "zoom")
3367 theFlags = Graphic3d_TMF_ZoomPers;
3369 else if (theFlagString == "rotate")
3371 theFlags = Graphic3d_TMF_RotatePers;
3373 else if (theFlagString == "zoomrotate")
3375 theFlags = Graphic3d_TMF_ZoomRotatePers;
3377 else if (theFlagString == "trihedron"
3378 || theFlagString == "triedron")
3380 theFlags = Graphic3d_TMF_TriedronPers;
3382 else if (theFlagString == "none")
3384 theFlags = Graphic3d_TMF_None;
3388 return Standard_False;
3391 return Standard_True;
3394 //! Auxiliary method to parse transformation persistence flags
3395 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
3396 Aspect_TypeOfTriedronPosition& theCorner)
3398 TCollection_AsciiString aString (theString);
3399 aString.LowerCase();
3400 if (aString == "center")
3402 theCorner = Aspect_TOTP_CENTER;
3404 else if (aString == "top"
3405 || aString == "upper")
3407 theCorner = Aspect_TOTP_TOP;
3409 else if (aString == "bottom"
3410 || aString == "lower")
3412 theCorner = Aspect_TOTP_BOTTOM;
3414 else if (aString == "left")
3416 theCorner = Aspect_TOTP_LEFT;
3418 else if (aString == "right")
3420 theCorner = Aspect_TOTP_RIGHT;
3422 else if (aString == "topleft"
3423 || aString == "leftupper"
3424 || aString == "upperleft")
3426 theCorner = Aspect_TOTP_LEFT_UPPER;
3428 else if (aString == "bottomleft"
3429 || aString == "leftlower"
3430 || aString == "lowerleft")
3432 theCorner = Aspect_TOTP_LEFT_LOWER;
3434 else if (aString == "topright"
3435 || aString == "rightupper"
3436 || aString == "upperright")
3438 theCorner = Aspect_TOTP_RIGHT_UPPER;
3440 else if (aString == "bottomright"
3441 || aString == "lowerright"
3442 || aString == "rightlower")
3444 theCorner = Aspect_TOTP_RIGHT_LOWER;
3448 return Standard_False;
3451 return Standard_True;
3454 //==============================================================================
3455 //function : VDisplay2
3457 //purpose : Display an object from its name
3458 //==============================================================================
3459 static int VDisplay2 (Draw_Interpretor& theDI,
3460 Standard_Integer theArgNb,
3461 const char** theArgVec)
3465 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3469 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3472 ViewerTest::ViewerInit();
3473 aCtx = ViewerTest::GetAISContext();
3476 // Parse input arguments
3477 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3478 Standard_Integer isMutable = -1;
3479 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3480 Standard_Boolean toDisplayLocal = Standard_False;
3481 Standard_Boolean toReDisplay = Standard_False;
3482 Standard_Integer isSelectable = -1;
3483 Standard_Integer anObjDispMode = -2;
3484 Standard_Integer anObjHighMode = -2;
3485 Standard_Boolean toSetTrsfPers = Standard_False;
3486 Handle(Graphic3d_TransformPers) aTrsfPers;
3487 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3488 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3489 Standard_Integer toDisplayInView = Standard_False;
3490 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3492 const TCollection_AsciiString aName = theArgVec[anArgIter];
3493 TCollection_AsciiString aNameCase = aName;
3494 aNameCase.LowerCase();
3495 if (anUpdateTool.parseRedrawMode (aName))
3499 else if (aNameCase == "-mutable")
3503 else if (aNameCase == "-neutral")
3505 aDispStatus = AIS_DS_Displayed;
3507 else if (aNameCase == "-immediate"
3508 || aNameCase == "-top")
3510 aZLayer = Graphic3d_ZLayerId_Top;
3512 else if (aNameCase == "-topmost")
3514 aZLayer = Graphic3d_ZLayerId_Topmost;
3516 else if (aNameCase == "-osd"
3517 || aNameCase == "-toposd"
3518 || aNameCase == "-overlay")
3520 aZLayer = Graphic3d_ZLayerId_TopOSD;
3522 else if (aNameCase == "-botosd"
3523 || aNameCase == "-underlay")
3525 aZLayer = Graphic3d_ZLayerId_BotOSD;
3527 else if (aNameCase == "-select"
3528 || aNameCase == "-selectable")
3532 else if (aNameCase == "-noselect"
3533 || aNameCase == "-noselection")
3537 else if (aNameCase == "-dispmode"
3538 || aNameCase == "-displaymode")
3540 if (++anArgIter >= theArgNb)
3542 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3546 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3548 else if (aNameCase == "-highmode"
3549 || aNameCase == "-highlightmode")
3551 if (++anArgIter >= theArgNb)
3553 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3557 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3559 else if (aNameCase == "-3d")
3561 toSetTrsfPers = Standard_True;
3562 aTrsfPers.Nullify();
3564 else if (aNameCase == "-2d"
3565 || aNameCase == "-trihedron"
3566 || aNameCase == "-triedron")
3568 toSetTrsfPers = Standard_True;
3569 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3571 if (anArgIter + 1 < theArgNb)
3573 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
3574 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
3577 aTrsfPers->SetCorner2d (aCorner);
3579 if (anArgIter + 2 < theArgNb)
3581 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
3582 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
3583 if (anX.IsIntegerValue()
3584 && anY.IsIntegerValue())
3587 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
3593 else if (aNameCase == "-trsfpers"
3594 || aNameCase == "-pers")
3596 if (++anArgIter >= theArgNb
3597 || !aTrsfPers.IsNull())
3599 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3603 toSetTrsfPers = Standard_True;
3604 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3605 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3606 aPersFlags.LowerCase();
3607 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3609 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3613 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
3615 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3617 else if (aTrsfPersFlags != Graphic3d_TMF_None)
3619 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
3622 else if (aNameCase == "-trsfperspos"
3623 || aNameCase == "-perspos")
3625 if (anArgIter + 2 >= theArgNb
3626 || aTrsfPers.IsNull())
3628 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3632 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3633 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3634 TCollection_AsciiString aZ = "0";
3635 if (!aX.IsRealValue()
3636 || !aY.IsRealValue())
3638 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3641 if (anArgIter + 1 < theArgNb)
3643 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3644 if (aTemp.IsRealValue())
3651 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
3652 if (aTrsfPers->IsZoomOrRotate())
3654 aTrsfPers->SetAnchorPoint (aPnt);
3656 else if (aTrsfPers->IsTrihedronOr2d())
3658 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
3661 else if (aNameCase == "-layer")
3663 if (++anArgIter >= theArgNb)
3665 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3669 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3670 if (!aValue.IsIntegerValue())
3672 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3676 aZLayer = aValue.IntegerValue();
3678 else if (aNameCase == "-view"
3679 || aNameCase == "-inview")
3681 toDisplayInView = Standard_True;
3683 else if (aNameCase == "-local")
3685 aDispStatus = AIS_DS_Temporary;
3686 toDisplayLocal = Standard_True;
3688 else if (aNameCase == "-redisplay")
3690 toReDisplay = Standard_True;
3694 aNamesOfDisplayIO.Append (aName);
3698 if (aNamesOfDisplayIO.IsEmpty())
3700 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3704 // Prepare context for display
3705 if (toDisplayLocal && !aCtx->HasOpenedContext())
3707 aCtx->OpenLocalContext (Standard_False);
3709 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3711 aCtx->CloseAllContexts (Standard_False);
3714 // Display interactive objects
3715 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3717 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3719 if (!GetMapOfAIS().IsBound2 (aName))
3721 // create the AIS_Shape from a name
3722 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3723 if (!aShape.IsNull())
3725 if (isMutable != -1)
3727 aShape->SetMutable (isMutable == 1);
3729 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3731 aShape->SetZLayer (aZLayer);
3735 aCtx->SetTransformPersistence (aShape, aTrsfPers);
3737 if (anObjDispMode != -2)
3739 aShape->SetDisplayMode (anObjDispMode);
3741 if (anObjHighMode != -2)
3743 aShape->SetHilightMode (anObjHighMode);
3745 if (!toDisplayLocal)
3746 GetMapOfAIS().Bind (aShape, aName);
3748 Standard_Integer aDispMode = aShape->HasDisplayMode()
3749 ? aShape->DisplayMode()
3750 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3751 ? aCtx->DisplayMode()
3753 Standard_Integer aSelMode = -1;
3754 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3756 aSelMode = aShape->GlobalSelectionMode();
3759 aCtx->Display (aShape, aDispMode, aSelMode,
3760 Standard_False, aShape->AcceptShapeDecomposition(),
3762 if (toDisplayInView)
3764 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
3766 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
3768 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3773 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3778 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3779 if (isMutable != -1)
3781 aShape->SetMutable (isMutable == 1);
3783 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3785 aShape->SetZLayer (aZLayer);
3789 aCtx->SetTransformPersistence (aShape, aTrsfPers);
3791 if (anObjDispMode != -2)
3793 aShape->SetDisplayMode (anObjDispMode);
3795 if (anObjHighMode != -2)
3797 aShape->SetHilightMode (anObjHighMode);
3799 Standard_Integer aDispMode = aShape->HasDisplayMode()
3800 ? aShape->DisplayMode()
3801 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3802 ? aCtx->DisplayMode()
3804 Standard_Integer aSelMode = -1;
3805 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3807 aSelMode = aShape->GlobalSelectionMode();
3810 if (aShape->Type() == AIS_KOI_Datum)
3812 aCtx->Display (aShape, Standard_False);
3816 theDI << "Display " << aName.ToCString() << "\n";
3818 // update the Shape in the AIS_Shape
3819 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3820 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3821 if (!aShapePrs.IsNull())
3823 if (!aShapePrs->Shape().IsEqual (aNewShape))
3825 toReDisplay = Standard_True;
3827 aShapePrs->Set (aNewShape);
3831 aCtx->Redisplay (aShape, Standard_False);
3836 aCtx->Erase (aShape);
3838 aCtx->Display (aShape, aDispMode, aSelMode,
3839 Standard_False, aShape->AcceptShapeDecomposition(),
3841 if (toDisplayInView)
3843 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3851 //===============================================================================================
3852 //function : VUpdate
3854 //===============================================================================================
3855 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3857 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3858 if (aContextAIS.IsNull())
3860 std::cout << theArgVec[0] << "AIS context is not available.\n";
3866 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3870 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3872 AIS_ListOfInteractive aListOfIO;
3874 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3876 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3878 Handle(AIS_InteractiveObject) anAISObj;
3879 if (anAISMap.IsBound2 (aName))
3881 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3884 if (anAISObj.IsNull())
3886 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3890 aListOfIO.Append (anAISObj);
3893 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3894 for (; anIOIt.More(); anIOIt.Next())
3896 aContextAIS->Update (anIOIt.Value(), Standard_False);
3899 aContextAIS->UpdateCurrentViewer();
3904 //==============================================================================
3906 //purpose : Test the annimation of an object along a
3907 // predifined trajectory
3908 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3909 //==============================================================================
3911 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3914 if (TheAISContext()->HasOpenedContext())
3915 TheAISContext()->CloseLocalContext();
3917 Standard_Real Step=4*M_PI/180;
3918 Standard_Real Angle=0;
3920 Handle(AIS_InteractiveObject) aIO;
3921 if (GetMapOfAIS().IsBound2(argv[1]))
3922 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3926 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3930 if (Draw::Atoi(argv[3])==1 ) {
3931 di<<" Primitives sensibles OFF\n";
3932 TheAISContext()->Deactivate(aIO);
3935 di<<" Primitives sensibles ON\n";
3937 // Movement par transformation
3938 if(Draw::Atoi(argv[2]) ==1) {
3939 di<<" Calcul par Transformation\n";
3940 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3944 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3945 TheAISContext()->SetLocation(aShape,myTransfo);
3946 TheAISContext() ->UpdateCurrentViewer();
3951 di<<" Calcul par Locations\n";
3952 gp_Trsf myAngleTrsf;
3953 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3954 TopLoc_Location myDeltaAngle (myAngleTrsf);
3955 TopLoc_Location myTrueLoc;
3957 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3960 myTrueLoc=myTrueLoc*myDeltaAngle;
3961 TheAISContext()->SetLocation(aShape,myTrueLoc );
3962 TheAISContext() ->UpdateCurrentViewer();
3965 if (Draw::Atoi(argv[3])==1 ){
3966 // On reactive la selection des primitives sensibles
3967 TheAISContext()->Activate(aIO,0);
3969 a3DView() -> Redraw();
3971 di<<" Temps ecoule \n";
3977 //==================================================================================
3978 // Function : VAnimation
3979 //==================================================================================
3980 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3982 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile\n";
3986 Standard_Real thread = 4;
3987 Standard_Real angleA=0;
3988 Standard_Real angleB;
3990 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3993 TopoDS_Shape CrankArm;
3994 TopoDS_Shape CylinderHead;
3995 TopoDS_Shape Propeller;
3996 TopoDS_Shape EngineBlock;
3998 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3999 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
4000 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
4001 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
4002 BRepTools::Read(CrankArm,argv[1],B);
4003 BRepTools::Read(CylinderHead,argv[2],B);
4004 BRepTools::Read(Propeller,argv[3],B);
4005 BRepTools::Read(EngineBlock,argv[4],B);
4007 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure.\n";}
4013 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
4014 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
4015 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
4016 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
4018 GetMapOfAIS().Bind(myAisCylinderHead,"a");
4019 GetMapOfAIS().Bind(myAisEngineBlock,"b");
4020 GetMapOfAIS().Bind(myAisCrankArm,"c");
4021 GetMapOfAIS().Bind(myAisPropeller,"d");
4023 myAisCylinderHead->SetMutable (Standard_True);
4024 myAisEngineBlock ->SetMutable (Standard_True);
4025 myAisCrankArm ->SetMutable (Standard_True);
4026 myAisPropeller ->SetMutable (Standard_True);
4028 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
4029 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
4030 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
4032 TheAISContext()->Display (myAisCylinderHead, Standard_False);
4033 TheAISContext()->Display (myAisEngineBlock, Standard_False);
4034 TheAISContext()->Display (myAisCrankArm, Standard_False);
4035 TheAISContext()->Display (myAisPropeller, Standard_False);
4037 TheAISContext()->Deactivate(myAisCylinderHead);
4038 TheAISContext()->Deactivate(myAisEngineBlock );
4039 TheAISContext()->Deactivate(myAisCrankArm );
4040 TheAISContext()->Deactivate(myAisPropeller );
4042 // Boucle de mouvement
4043 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
4045 angleA = thread*myAngle*M_PI/180;
4046 X = Sin(angleA)*3/8;
4047 angleB = atan(X / Sqrt(-X * X + 1));
4048 Standard_Real decal(25*0.6);
4051 //Build a transformation on the display
4052 gp_Trsf aPropellerTrsf;
4053 aPropellerTrsf.SetRotation(Ax1,angleA);
4054 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
4056 gp_Ax3 base(gp_Pnt(3*decal*(1-Cos(angleA)),-3*decal*Sin(angleA),0),gp_Vec(0,0,1),gp_Vec(1,0,0));
4057 gp_Trsf aCrankArmTrsf;
4058 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
4059 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
4061 TheAISContext()->UpdateCurrentViewer();
4064 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
4065 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
4067 myAisCrankArm ->ResetTransformation();
4068 myAisPropeller->ResetTransformation();
4070 myAisCrankArm -> Set(myNewCrankArm );
4071 myAisPropeller -> Set(myNewPropeller);
4073 TheAISContext()->Activate(myAisCylinderHead,0);
4074 TheAISContext()->Activate(myAisEngineBlock,0 );
4075 TheAISContext()->Activate(myAisCrankArm ,0 );
4076 TheAISContext()->Activate(myAisPropeller ,0 );
4082 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
4083 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
4085 TheAISContext()->UpdateCurrentViewer();
4086 a3DView()->Redraw();
4095 //==============================================================================
4096 //function : VShading
4097 //purpose : Sharpen or roughten the quality of the shading
4098 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4099 //==============================================================================
4100 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4102 Standard_Real myDevCoef;
4103 Handle(AIS_InteractiveObject) TheAisIO;
4106 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4108 if (TheAISContext()->HasOpenedContext())
4109 TheAISContext()->CloseLocalContext();
4114 myDevCoef =Draw::Atof(argv[2]);
4117 TCollection_AsciiString name=argv[1];
4118 if (GetMapOfAIS().IsBound2(name ))
4119 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4120 if (TheAisIO.IsNull())
4121 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4124 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4126 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4128 TheAISContext()->Redisplay(TheAisIO);
4131 //==============================================================================
4132 //function : HaveMode
4133 //use : VActivatedModes
4134 //==============================================================================
4135 #include <TColStd_ListIteratorOfListOfInteger.hxx>
4137 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
4139 TColStd_ListOfInteger List;
4140 TheAISContext()->ActivatedModes (TheAisIO,List);
4141 TColStd_ListIteratorOfListOfInteger it;
4142 Standard_Boolean Found=Standard_False;
4143 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4144 if (it.Value()==mode ) Found=Standard_True;
4151 //==============================================================================
4152 //function : VActivatedMode
4154 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
4155 // (edges,vertex...)qui lui est propre et le mode de selection standard.
4156 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4157 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4158 // qu'un nom et qu'un mode.
4159 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4160 //==============================================================================
4161 #include <AIS_ListIteratorOfListOfInteractive.hxx>
4163 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4166 Standard_Boolean ThereIsName = Standard_False ;
4168 if(!a3DView().IsNull()){
4170 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
4171 // verification des arguments
4173 if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
4174 ThereIsName = (argc == 3);
4178 if (argc>1) {di<<" Syntaxe error\n";return 1;}
4180 di<<" R.A.Z de tous les modes de selecion\n";
4181 di<<" Fermeture du Context local\n";
4182 if (TheAISContext()->HasOpenedContext())
4183 TheAISContext()->CloseLocalContext();
4187 // IL n'y a aps de nom de shape passe en argument
4188 if (HaveToSet && !ThereIsName){
4189 Standard_Integer aMode=Draw::Atoi(argv [1]);
4191 const char *cmode="???";
4193 case 0: cmode = "Shape"; break;
4194 case 1: cmode = "Vertex"; break;
4195 case 2: cmode = "Edge"; break;
4196 case 3: cmode = "Wire"; break;
4197 case 4: cmode = "Face"; break;
4198 case 5: cmode = "Shell"; break;
4199 case 6: cmode = "Solid"; break;
4200 case 7: cmode = "Compound"; break;
4203 if( !TheAISContext()->HasOpenedContext() ) {
4204 // il n'y a pas de Context local d'ouvert
4205 // on en ouvre un et on charge toutes les shapes displayees
4206 // on load tous les objets displayees et on Activate les objets de la liste
4207 AIS_ListOfInteractive ListOfIO;
4208 // on sauve dans une AISListOfInteractive tous les objets currents
4209 if (TheAISContext()->NbSelected()>0 ){
4210 TheAISContext()->UnhilightSelected(Standard_False);
4212 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4213 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
4217 TheAISContext()->OpenLocalContext(Standard_False);
4218 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4221 Handle(AIS_InteractiveObject) aIO =
4222 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4224 TheAISContext()->Load(aIO,0,Standard_False);
4227 // traitement des objets qui etaient currents dans le Contexte global
4228 if (!ListOfIO.IsEmpty() ) {
4229 // il y avait des objets currents
4230 AIS_ListIteratorOfListOfInteractive iter;
4231 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4232 Handle(AIS_InteractiveObject) aIO=iter.Value();
4233 TheAISContext()->Activate(aIO,aMode);
4234 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4238 // On applique le mode a tous les objets displayes
4239 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4240 it2 (GetMapOfAIS());
4242 Handle(AIS_InteractiveObject) aIO =
4243 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4244 if (!aIO.IsNull()) {
4245 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4246 TheAISContext()->Activate(aIO,aMode);
4255 // un Context local est deja ouvert
4256 // Traitement des objets du Context local
4257 if (TheAISContext()->NbSelected()>0 ){
4258 TheAISContext()->UnhilightSelected(Standard_False);
4259 // il y a des objets selected,on les parcourt
4260 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4261 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
4264 if (HaveMode(aIO,aMode) ) {
4265 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4266 TheAISContext()->Deactivate(aIO,aMode);
4269 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4270 TheAISContext()->Activate(aIO,aMode);
4276 // il n'y a pas d'objets selected
4277 // tous les objets diplayes sont traites
4278 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4281 Handle(AIS_InteractiveObject) aIO =
4282 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4283 if (!aIO.IsNull()) {
4284 if (HaveMode(aIO,aMode) ) {
4285 di<<" Mode: "<<cmode<<" OFF pour "
4286 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4287 TheAISContext()->Deactivate(aIO,aMode);
4290 di<<" Mode: "<<cmode<<" ON pour"
4291 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4292 TheAISContext()->Activate(aIO,aMode);
4300 else if (HaveToSet && ThereIsName){
4301 Standard_Integer aMode=Draw::Atoi(argv [2]);
4302 Handle(AIS_InteractiveObject) aIO =
4303 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4305 if (!aIO.IsNull()) {
4306 const char *cmode="???";
4309 case 0: cmode = "Shape"; break;
4310 case 1: cmode = "Vertex"; break;
4311 case 2: cmode = "Edge"; break;
4312 case 3: cmode = "Wire"; break;
4313 case 4: cmode = "Face"; break;
4314 case 5: cmode = "Shell"; break;
4315 case 6: cmode = "Solid"; break;
4316 case 7: cmode = "Compound"; break;
4319 if( !TheAISContext()->HasOpenedContext() ) {
4320 TheAISContext()->OpenLocalContext(Standard_False);
4321 // On charge tous les objets de la map
4322 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4324 Handle(AIS_InteractiveObject) aShape=
4325 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4326 if (!aShape.IsNull())
4327 TheAISContext()->Load(aShape,0,Standard_False);
4330 TheAISContext()->Activate(aIO,aMode);
4331 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4335 // un Context local est deja ouvert
4336 if (HaveMode(aIO,aMode) ) {
4337 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4338 TheAISContext()->Deactivate(aIO,aMode);
4341 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4342 TheAISContext()->Activate(aIO,aMode);
4351 //! Auxiliary method to print Interactive Object information
4352 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4353 const Handle(Standard_Transient)& theObject,
4354 Draw_Interpretor& theDI)
4356 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4359 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4363 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4364 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4365 << (theDetected.Contains (anObj) ? " Detected" : " ")
4367 if (anObj->Type() == AIS_KOI_Datum)
4370 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4371 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4372 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4373 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4374 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4375 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4376 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4379 else if (anObj->Type() == AIS_KOI_Shape
4380 && anObj->Signature() == 0)
4382 theDI << " AIS_Shape";
4384 else if (anObj->Type() == AIS_KOI_Relation)
4386 // AIS_Dimention and AIS_Relation
4387 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4388 switch (aRelation->KindOfDimension())
4390 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4391 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4392 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4393 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4394 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4395 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4396 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4397 default: theDI << " UNKNOWN dimension"; break;
4402 theDI << " UserPrs";
4404 theDI << " (" << theObject->DynamicType()->Name() << ")";
4407 //! Print information about locally selected sub-shapes
4408 template <typename T>
4409 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4411 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4412 TCollection_AsciiString aPrevName;
4413 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4415 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4416 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4417 if (aShapeIO.IsNull() || anOwner.IsNull())
4421 if (anOwner == aShapeIO->GlobalSelOwner())
4424 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4425 if (aSubShape.IsNull()
4426 || aShapeIO.IsNull()
4427 || !GetMapOfAIS().IsBound1 (aShapeIO))
4432 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4433 TopTools_MapOfShape aFilter;
4434 Standard_Integer aNumber = 0;
4435 const TopoDS_Shape aShape = aShapeIO->Shape();
4436 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4437 anIter.More(); anIter.Next())
4439 if (!aFilter.Add (anIter.Current()))
4441 continue; // filter duplicates
4445 if (!anIter.Current().IsSame (aSubShape))
4450 Standard_CString aShapeName = NULL;
4451 switch (aSubShape.ShapeType())
4453 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4454 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4455 case TopAbs_SOLID: aShapeName = " Solid"; break;
4456 case TopAbs_SHELL: aShapeName = " Shell"; break;
4457 case TopAbs_FACE: aShapeName = " Face"; break;
4458 case TopAbs_WIRE: aShapeName = " Wire"; break;
4459 case TopAbs_EDGE: aShapeName = " Edge"; break;
4460 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4462 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4465 if (aParentName != aPrevName)
4467 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4468 aPrevName = aParentName;
4470 theDI << " " << aShapeName << " #" << aNumber << "\n";
4476 //==============================================================================
4479 //==============================================================================
4480 static Standard_Integer VState (Draw_Interpretor& theDI,
4481 Standard_Integer theArgNb,
4482 Standard_CString* theArgVec)
4484 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4487 std::cerr << "Error: No opened viewer!\n";
4491 Standard_Boolean toPrintEntities = Standard_False;
4492 Standard_Boolean toCheckSelected = Standard_False;
4494 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4496 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4497 anOption.LowerCase();
4498 if (anOption == "-detectedentities"
4499 || anOption == "-entities")
4501 toPrintEntities = Standard_True;
4503 else if (anOption == "-hasselected")
4505 toCheckSelected = Standard_True;
4509 if (toCheckSelected)
4511 aCtx->InitSelected();
4512 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4513 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4518 if (toPrintEntities)
4520 theDI << "Detected entities:\n";
4521 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4522 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4523 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4525 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4526 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4527 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4528 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4529 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4530 aName.LeftJustify (20, ' ');
4531 char anInfoStr[512];
4533 " Depth: %g Distance: %g Point: %g %g %g",
4536 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4537 theDI << " " << aName
4539 << " (" << anEntity->DynamicType()->Name() << ")"
4542 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4543 if (!aBRepOwner.IsNull())
4545 theDI << " Detected Shape: "
4546 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4550 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4551 if (!aWire.IsNull())
4553 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4554 theDI << " Detected Child: "
4555 << aSen->DynamicType()->Name()
4559 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4560 if (!aPrimArr.IsNull())
4562 theDI << " Detected Element: "
4563 << aPrimArr->LastDetectedElement()
4570 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4571 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4573 aDetected.Add (aCtx->DetectedCurrentObject());
4576 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4580 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4582 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4583 if (!GetMapOfAIS().IsBound2 (anObjName))
4585 theDI << anObjName << " doesn't exist!\n";
4589 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4590 TCollection_AsciiString aName = anObjName;
4591 aName.LeftJustify (20, ' ');
4592 theDI << " " << aName << " ";
4593 objInfo (aDetected, anObjTrans, theDI);
4599 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4601 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4602 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4604 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4605 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4606 // handle whole object selection
4607 if (anOwner == anObj->GlobalSelOwner())
4609 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4610 aName.LeftJustify (20, ' ');
4611 theDI << aName << " ";
4612 objInfo (aDetected, anObj, theDI);
4617 // process selected sub-shapes
4618 printLocalSelectionInfo (aCtx, theDI);
4623 theDI << "Neutral-point state:\n";
4624 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4625 anObjIter.More(); anObjIter.Next())
4627 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4633 TCollection_AsciiString aName = anObjIter.Key2();
4634 aName.LeftJustify (20, ' ');
4635 theDI << " " << aName << " ";
4636 objInfo (aDetected, anObj, theDI);
4639 printLocalSelectionInfo (aCtx, theDI);
4640 if (aCtx->HasOpenedContext())
4641 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
4645 //=======================================================================
4646 //function : PickObjects
4648 //=======================================================================
4649 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4650 const AIS_KindOfInteractive TheType,
4651 const Standard_Integer TheSignature,
4652 const Standard_Integer MaxPick)
4654 Handle(AIS_InteractiveObject) IO;
4655 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4657 // step 1: prepare the data
4659 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4660 TheAISContext()->AddFilter(F1);
4663 // step 2 : wait for the selection...
4664 Standard_Integer NbPickGood (0),NbToReach(arr->Length());
4665 Standard_Integer NbPickFail(0);
4666 Standard_Integer argccc = 5;
4667 const char *bufff[] = { "A", "B", "C","D", "E" };
4668 const char **argvvv = (const char **) bufff;
4671 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4672 while(ViewerMainLoop(argccc,argvvv)){}
4673 Standard_Integer NbStored = TheAISContext()->NbSelected();
4674 if(NbStored != NbPickGood)
4675 NbPickGood= NbStored;
4678 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4681 // step3 get result.
4683 if (NbPickFail >= NbToReach)
4684 return Standard_False;
4686 Standard_Integer i(0);
4687 for(TheAISContext()->InitSelected();
4688 TheAISContext()->MoreSelected();
4689 TheAISContext()->NextSelected()){
4691 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4692 arr->SetValue(i,IO2);
4697 TheAISContext()->CloseLocalContext(curindex);
4699 return Standard_True;
4703 //=======================================================================
4704 //function : PickObject
4706 //=======================================================================
4707 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4708 const Standard_Integer TheSignature,
4709 const Standard_Integer MaxPick)
4711 Handle(AIS_InteractiveObject) IO;
4712 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4714 // step 1: prepare the data
4717 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4718 TheAISContext()->AddFilter(F1);
4721 // step 2 : wait for the selection...
4722 Standard_Boolean IsGood (Standard_False);
4723 Standard_Integer NbPick(0);
4724 Standard_Integer argccc = 5;
4725 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4726 const char **argvvv = (const char **) bufff;
4729 while(!IsGood && NbPick<= MaxPick){
4730 while(ViewerMainLoop(argccc,argvvv)){}
4731 IsGood = (TheAISContext()->NbSelected()>0) ;
4733 cout<<"Nb Pick :"<<NbPick<<endl;
4737 // step3 get result.
4739 TheAISContext()->InitSelected();
4740 IO = TheAISContext()->SelectedInteractive();
4744 TheAISContext()->CloseLocalContext(curindex);
4748 //=======================================================================
4749 //function : PickShape
4750 //purpose : First Activate the rightmode + Put Filters to be able to
4751 // pick objets that are of type <TheType>...
4752 //=======================================================================
4754 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4755 const Standard_Integer MaxPick)
4758 // step 1: prepare the data
4760 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4761 TopoDS_Shape result;
4763 if(TheType==TopAbs_SHAPE){
4764 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4765 TheAISContext()->AddFilter(F1);
4768 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4769 TheAISContext()->AddFilter(TF);
4770 TheAISContext()->ActivateStandardMode(TheType);
4775 // step 2 : wait for the selection...
4776 Standard_Boolean NoShape (Standard_True);
4777 Standard_Integer NbPick(0);
4778 Standard_Integer argccc = 5;
4779 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4780 const char **argvvv = (const char **) bufff;
4783 while(NoShape && NbPick<= MaxPick){
4784 while(ViewerMainLoop(argccc,argvvv)){}
4785 NoShape = (TheAISContext()->NbSelected()==0) ;
4787 cout<<"Nb Pick :"<<NbPick<<endl;
4790 // step3 get result.
4794 TheAISContext()->InitSelected();
4795 if(TheAISContext()->HasSelectedShape())
4796 result = TheAISContext()->SelectedShape();
4798 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4799 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
4804 TheAISContext()->CloseLocalContext(curindex);
4810 //=======================================================================
4811 //function : PickShapes
4813 //=======================================================================
4814 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4815 Handle(TopTools_HArray1OfShape)& thearr,
4816 const Standard_Integer MaxPick)
4819 Standard_Integer Taille = thearr->Length();
4821 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4823 // step 1: prepare the data
4824 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4825 if(TheType==TopAbs_SHAPE){
4826 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4827 TheAISContext()->AddFilter(F1);
4830 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4831 TheAISContext()->AddFilter(TF);
4832 TheAISContext()->ActivateStandardMode(TheType);
4836 // step 2 : wait for the selection...
4837 Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
4838 Standard_Integer NbPickFail(0);
4839 Standard_Integer argccc = 5;
4840 const char *bufff[] = { "A", "B", "C","D", "E" };
4841 const char **argvvv = (const char **) bufff;
4844 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4845 while(ViewerMainLoop(argccc,argvvv)){}
4846 Standard_Integer NbStored = TheAISContext()->NbSelected();
4847 if (NbStored != NbPickGood)
4848 NbPickGood= NbStored;
4851 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4854 // step3 get result.
4856 if (NbPickFail >= NbToReach)
4857 return Standard_False;
4859 Standard_Integer i(0);
4860 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4862 if(TheAISContext()->HasSelectedShape())
4863 thearr->SetValue(i,TheAISContext()->SelectedShape());
4865 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4866 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
4870 TheAISContext()->CloseLocalContext(curindex);
4871 return Standard_True;
4875 //=======================================================================
4876 //function : VPickShape
4878 //=======================================================================
4879 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4881 TopoDS_Shape PickSh;
4882 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4885 theType = TopAbs_SHAPE;
4887 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4888 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4889 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4890 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4891 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4892 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4893 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4896 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4897 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4899 TCollection_AsciiString name;
4902 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4904 PickSh = ViewerTest::PickShape(theType);
4913 if(!PickSh.IsNull()){
4914 nbOfSub[Standard_Integer(theType)]++;
4916 name += nameType[Standard_Integer(theType)];
4917 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4922 // si on avait une petite methode pour voir si la shape
4923 // est deja dans la Double map, ca eviterait de creer....
4924 DBRep::Set(name.ToCString(),PickSh);
4926 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4927 GetMapOfAIS().Bind(newsh, name);
4928 TheAISContext()->Display(newsh);
4929 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4932 // Plusieurs objets a picker, vite vite vite....
4935 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4936 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4937 if(ViewerTest::PickShapes(theType,arr)){
4938 for(Standard_Integer i=1;i<=NbToPick;i++){
4939 PickSh = arr->Value(i);
4940 if(!PickSh.IsNull()){
4942 nbOfSub[Standard_Integer(theType)]++;
4945 name += nameType[Standard_Integer(theType)];
4946 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4954 DBRep::Set(name.ToCString(),PickSh);
4955 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4956 GetMapOfAIS().Bind(newsh, name);
4957 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4958 TheAISContext()->Display(newsh);
4966 //=======================================================================
4967 //function : VPickSelected
4969 //=======================================================================
4970 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4972 static Standard_Integer aCount = 0;
4973 TCollection_AsciiString aName = "PickedShape_";
4981 aName = aName + aCount++ + "_";
4984 Standard_Integer anIdx = 0;
4985 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4987 TopoDS_Shape aShape;
4988 if (TheAISContext()->HasSelectedShape())
4990 aShape = TheAISContext()->SelectedShape();
4994 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4995 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
4998 TCollection_AsciiString aCurrentName = aName;
5001 aCurrentName += anIdx;
5004 DBRep::Set ((aCurrentName).ToCString(), aShape);
5006 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5007 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5008 TheAISContext()->Display (aNewShape);
5014 //=======================================================================
5015 //function : list of known objects
5017 //=======================================================================
5018 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5020 // 1234567890 12345678901234567 123456789
5021 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5022 TCollection_AsciiString BlankLine(64,'_');
5023 Standard_Integer i ;
5025 di<<"/n"<<BlankLine.ToCString()<<"\n";
5028 Colum[i].Center(20,' ');
5030 di<<"|"<<Colum[i].ToCString();
5033 di<<BlankLine.ToCString()<<"\n";
5035 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5036 const char ** names = GetTypeNames();
5038 TCollection_AsciiString curstring;
5039 TCollection_AsciiString curcolum[3];
5042 // les objets de type Datum..
5043 curcolum[1]+="Datum";
5045 curcolum[0].Clear();
5046 curcolum[0] += names[i];
5048 curcolum[2].Clear();
5049 curcolum[2]+=TCollection_AsciiString(i+1);
5051 for(Standard_Integer j =0;j<=2;j++){
5052 curcolum[j].Center(20,' ');
5053 di<<"|"<<curcolum[j].ToCString();
5057 di<<BlankLine.ToCString()<<"\n";
5059 // les objets de type shape
5060 curcolum[1].Clear();
5061 curcolum[1]+="Shape";
5062 curcolum[1].Center(20,' ');
5065 curcolum[0].Clear();
5066 curcolum[0] += names[7+i];
5067 curcolum[2].Clear();
5068 curcolum[2]+=TCollection_AsciiString(i);
5070 for(Standard_Integer j =0;j<=2;j++){
5071 curcolum[j].Center(20,' ');
5072 di<<"|"<<curcolum[j].ToCString();
5076 di<<BlankLine.ToCString()<<"\n";
5077 // les IO de type objet...
5078 curcolum[1].Clear();
5079 curcolum[1]+="Object";
5080 curcolum[1].Center(20,' ');
5082 curcolum[0].Clear();
5083 curcolum[0] += names[10+i];
5084 curcolum[2].Clear();
5085 curcolum[2]+=TCollection_AsciiString(i);
5087 for(Standard_Integer j =0;j<=2;j++){
5088 curcolum[j].Center(20,' ');
5089 di<<"|"<<curcolum[j].ToCString();
5093 di<<BlankLine.ToCString()<<"\n";
5094 // les contraintes et dimensions.
5095 // pour l'instant on separe juste contraintes et dimensions...
5096 // plus tard, on detaillera toutes les sortes...
5097 curcolum[1].Clear();
5098 curcolum[1]+="Relation";
5099 curcolum[1].Center(20,' ');
5101 curcolum[0].Clear();
5102 curcolum[0] += names[12+i];
5103 curcolum[2].Clear();
5104 curcolum[2]+=TCollection_AsciiString(i);
5106 for(Standard_Integer j =0;j<=2;j++){
5107 curcolum[j].Center(20,' ');
5108 di<<"|"<<curcolum[j].ToCString();
5112 di<<BlankLine.ToCString()<<"\n";
5119 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5121 if(argc!=2) return 1;
5123 AIS_KindOfInteractive TheType;
5124 Standard_Integer TheSign(-1);
5125 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5128 AIS_ListOfInteractive LIO;
5130 // en attendant l'amelioration ais pour les dimensions...
5132 Standard_Integer dimension_status(-1);
5133 if(TheType==AIS_KOI_Relation){
5134 dimension_status = TheSign ==1 ? 1 : 0;
5138 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5139 Handle(AIS_InteractiveObject) curio;
5140 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5143 if(dimension_status == -1)
5144 TheAISContext()->Erase(curio,Standard_False);
5146 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5147 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5148 (dimension_status==1 && KOD != AIS_KOD_NONE))
5149 TheAISContext()->Erase(curio,Standard_False);
5152 TheAISContext()->UpdateCurrentViewer();
5155 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5157 if(argc!=2) return 1;
5159 AIS_KindOfInteractive TheType;
5160 Standard_Integer TheSign(-1);
5161 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5163 // en attendant l'amelioration ais pour les dimensions...
5165 Standard_Integer dimension_status(-1);
5166 if(TheType==AIS_KOI_Relation){
5167 dimension_status = TheSign ==1 ? 1 : 0;
5171 AIS_ListOfInteractive LIO;
5172 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5173 Handle(AIS_InteractiveObject) curio;
5174 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5176 if(dimension_status == -1)
5177 TheAISContext()->Display(curio,Standard_False);
5179 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5180 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5181 (dimension_status==1 && KOD != AIS_KOD_NONE))
5182 TheAISContext()->Display(curio,Standard_False);
5187 TheAISContext()->UpdateCurrentViewer();
5191 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5194 BRep_Builder builder;
5196 BRepTools::Read(shape, s, builder);
5197 DBRep::Set(a[1], shape);
5198 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5199 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5204 //===============================================================================================
5207 //===============================================================================================
5208 static int VBsdf (Draw_Interpretor& theDi,
5209 Standard_Integer theArgsNb,
5210 const char** theArgVec)
5212 Handle(V3d_View) aView = ViewerTest::CurrentView();
5213 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5215 || aViewer.IsNull())
5217 std::cerr << "No active viewer!\n";
5221 ViewerTest_CmdParser aCmd;
5223 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5224 aCmd.AddOption ("print|echo|p", "Print BSDF");
5226 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5227 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5228 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5229 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5230 aCmd.AddOption ("le", "Self-emitted radiance");
5232 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5234 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
5235 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5236 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5238 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5240 aCmd.Parse (theArgsNb, theArgVec);
5242 if (aCmd.HasOption ("help"))
5244 theDi.PrintHelp (theArgVec[0]);
5248 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5251 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5252 if (!aMap.IsBound2 (aName) )
5254 std::cerr << "Use 'vdisplay' before\n";
5258 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5259 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5260 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5262 if (aCmd.HasOption ("print"))
5264 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5267 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5268 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5269 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5270 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5271 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5274 if (aFresnel.x() >= 0.f)
5277 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5279 else if (aFresnel.x() >= -1.5f)
5282 << "|Constant| " << aFresnel.z() << "\n";
5284 else if (aFresnel.x() >= -2.5f)
5287 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5292 << "|Dielectric| " << aFresnel.y() << "\n";
5297 << "Roughness: " << aBSDF.Roughness << "\n"
5298 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
5299 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5300 << aBSDF.AbsorptionColor.g() << ", "
5301 << aBSDF.AbsorptionColor.b() << "\n";
5306 if (aCmd.HasOption ("roughness", 1, Standard_True))
5308 aCmd.Arg ("roughness", 0);
5309 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5312 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5314 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5317 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5319 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5322 if (aCmd.HasOption ("kd", 3))
5324 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5326 else if (aCmd.HasOption ("kd", 1, Standard_True))
5328 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5331 if (aCmd.HasOption ("kr", 3))
5333 aBSDF.Kr = aCmd.ArgVec3f ("kr");
5335 else if (aCmd.HasOption ("kr", 1, Standard_True))
5337 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5340 if (aCmd.HasOption ("kt", 3))
5342 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5344 else if (aCmd.HasOption ("kt", 1, Standard_True))
5346 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5349 if (aCmd.HasOption ("ks", 3))
5351 aBSDF.Ks = aCmd.ArgVec3f ("ks");
5353 else if (aCmd.HasOption ("ks", 1, Standard_True))
5355 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5358 if (aCmd.HasOption ("le", 3))
5360 aBSDF.Le = aCmd.ArgVec3f ("le");
5362 else if (aCmd.HasOption ("le", 1, Standard_True))
5364 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5367 const std::string aFresnelErrorMessage =
5368 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5370 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5372 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5373 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5375 if (aFresnelType == "schlick")
5377 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5378 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5379 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5380 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5384 std::cout << aFresnelErrorMessage;
5387 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5389 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5390 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5392 if (aFresnelType == "conductor")
5394 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5395 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5396 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5400 std::cout << aFresnelErrorMessage;
5403 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5405 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5406 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5408 if (aFresnelType == "dielectric")
5410 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5411 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5413 else if (aFresnelType == "constant")
5415 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5416 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5420 std::cout << aFresnelErrorMessage;
5424 if (aCmd.HasOption ("normalize"))
5429 aMaterial.SetBSDF (aBSDF);
5430 anIObj->SetMaterial (aMaterial);
5437 //==============================================================================
5438 //function : VLoadSelection
5439 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5440 //==============================================================================
5441 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5442 Standard_Integer theArgNb,
5443 const char** theArgVec)
5447 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5451 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5454 ViewerTest::ViewerInit();
5455 aCtx = ViewerTest::GetAISContext();
5458 // Parse input arguments
5459 TColStd_SequenceOfAsciiString aNamesOfIO;
5460 Standard_Boolean isLocal = Standard_False;
5461 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5463 const TCollection_AsciiString aName = theArgVec[anArgIter];
5464 TCollection_AsciiString aNameCase = aName;
5465 aNameCase.LowerCase();
5466 if (aNameCase == "-local")
5468 isLocal = Standard_True;
5472 aNamesOfIO.Append (aName);
5476 if (aNamesOfIO.IsEmpty())
5478 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5483 if (isLocal && !aCtx->HasOpenedContext())
5485 aCtx->OpenLocalContext (Standard_False);
5487 else if (!isLocal && aCtx->HasOpenedContext())
5489 aCtx->CloseAllContexts (Standard_False);
5492 // Load selection of interactive objects
5493 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5495 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5497 Handle(AIS_InteractiveObject) aShape;
5498 if (GetMapOfAIS().IsBound2 (aName))
5499 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5501 aShape = GetAISShapeFromName (aName.ToCString());
5503 if (!aShape.IsNull())
5505 if (!GetMapOfAIS().IsBound2 (aName))
5507 GetMapOfAIS().Bind (aShape, aName);
5510 aCtx->Load (aShape, -1, Standard_False);
5511 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5518 //==============================================================================
5519 //function : ViewerTest::Commands
5520 //purpose : Add all the viewer command in the Draw_Interpretor
5521 //==============================================================================
5523 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5525 ViewerTest::ViewerCommands(theCommands);
5526 ViewerTest::RelationCommands(theCommands);
5527 ViewerTest::ObjectCommands(theCommands);
5528 ViewerTest::FilletCommands(theCommands);
5529 ViewerTest::OpenGlCommands(theCommands);
5531 const char *group = "AIS_Display";
5534 theCommands.Add("visos",
5535 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5536 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5537 __FILE__, visos, group);
5539 theCommands.Add("vdisplay",
5540 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5541 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5542 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5543 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5544 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5545 "\n\t\t: [offsetX offsetY]]]"
5546 "\n\t\t: [-dispMode mode] [-highMode mode]"
5547 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5548 "\n\t\t: [-redisplay]"
5549 "\n\t\t: name1 [name2] ... [name n]"
5550 "\n\t\t: Displays named objects."
5551 "\n\t\t: Option -local enables displaying of objects in local"
5552 "\n\t\t: selection context. Local selection context will be opened"
5553 "\n\t\t: if there is not any."
5554 "\n\t\t: -noupdate Suppresses viewer redraw call."
5555 "\n\t\t: -mutable Enables optimizations for mutable objects."
5556 "\n\t\t: -neutral Draws objects in main viewer."
5557 "\n\t\t: -layer Sets z-layer for objects."
5558 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5559 "\n\t\t: options can be used for the default z-layers."
5560 "\n\t\t: -top Draws object on top of main presentations"
5561 "\n\t\t: but below topmost."
5562 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5563 "\n\t\t: with independent Depth."
5564 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5565 "\n\t\t: (On-Screen-Display)"
5566 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5567 "\n\t\t: (On-Screen-Display)"
5568 "\n\t\t: -selectable|-noselect Controls selection of objects."
5569 "\n\t\t: -trsfPers Sets a transform persistence flags."
5570 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5571 "\n\t\t: -2d Displays object in screen coordinates."
5572 "\n\t\t: (DY looks up)"
5573 "\n\t\t: -dispmode Sets display mode for objects."
5574 "\n\t\t: -highmode Sets hilight mode for objects."
5575 "\n\t\t: -redisplay Recomputes presentation of objects.",
5576 __FILE__, VDisplay2, group);
5578 theCommands.Add ("vupdate",
5579 "vupdate name1 [name2] ... [name n]"
5580 "\n\t\t: Updates named objects in interactive context",
5581 __FILE__, VUpdate, group);
5583 theCommands.Add("verase",
5584 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5585 "\n\t\t: Erases selected or named objects."
5586 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5587 "\n\t\t: Option -local enables erasing of selected or named objects without"
5588 "\n\t\t: closing local selection context.",
5589 __FILE__, VErase, group);
5591 theCommands.Add("vremove",
5592 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5593 "or vremove [-context] -all to remove all objects"
5594 "\n\t\t: Removes selected or named objects."
5595 "\n\t\t If -context is in arguments, the objects are not deleted"
5596 "\n\t\t from the map of objects and names."
5597 "\n\t\t: Option -local enables removing of selected or named objects without"
5598 "\n\t\t: closing local selection context. Empty local selection context will be"
5600 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5601 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5602 __FILE__, VRemove, group);
5604 theCommands.Add("vdonly",
5605 "vdonly [-noupdate|-update] [name1] ... [name n]"
5606 "\n\t\t: Displays only selected or named objects",
5607 __FILE__,VDonly2,group);
5609 theCommands.Add("vdisplayall",
5610 "vidsplayall [-local]"
5611 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5612 "\n\t\t: Option -local enables displaying of the objects in local"
5613 "\n\t\t: selection context.",
5614 __FILE__, VDisplayAll, group);
5616 theCommands.Add("veraseall",
5617 "veraseall [-local]"
5618 "\n\t\t: Erases all objects displayed in the viewer."
5619 "\n\t\t: Option -local enables erasing of the objects in local"
5620 "\n\t\t: selection context.",
5621 __FILE__, VErase, group);
5623 theCommands.Add("verasetype",
5625 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5626 __FILE__, VEraseType, group);
5627 theCommands.Add("vbounding",
5628 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5629 "\n\t\t: [-print] [-hide]"
5630 "\n\t\t: Temporarily display bounding box of specified Interactive"
5631 "\n\t\t: Objects, or print it to console if -print is specified."
5632 "\n\t\t: Already displayed box might be hidden by -hide option.",
5633 __FILE__,VBounding,group);
5635 theCommands.Add("vdisplaytype",
5636 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5637 __FILE__,VDisplayType,group);
5639 theCommands.Add("vsetdispmode",
5640 "vsetdispmode [name] mode(1,2,..)"
5641 "\n\t\t: Sets display mode for all, selected or named objects.",
5642 __FILE__,VDispMode,group);
5644 theCommands.Add("vunsetdispmode",
5645 "vunsetdispmode [name]"
5646 "\n\t\t: Unsets custom display mode for selected or named objects.",
5647 __FILE__,VDispMode,group);
5649 theCommands.Add("vdir",
5650 "Lists all objects displayed in 3D viewer",
5651 __FILE__,VDir,group);
5653 #ifdef HAVE_FREEIMAGE
5654 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5656 #define DUMP_FORMATS "{ppm}"
5658 theCommands.Add("vdump",
5659 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5660 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5661 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5662 "\n\t\t: [-tileSize Size=0]"
5663 "\n\t\t: Dumps content of the active view into image file",
5664 __FILE__,VDump,group);
5666 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5667 __FILE__,VSubInt,group);
5669 theCommands.Add("vaspects",
5670 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5671 "\n\t\t: [-setVisibility 0|1]"
5672 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5673 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5674 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5675 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5676 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5677 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5678 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5679 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5680 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5681 "\n\t\t: [-isoontriangulation 0|1]"
5682 "\n\t\t: [-setMaxParamValue {value}]"
5683 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5684 "\n\t\t: Manage presentation properties of all, selected or named objects."
5685 "\n\t\t: When -subshapes is specified than following properties will be"
5686 "\n\t\t: assigned to specified sub-shapes."
5687 "\n\t\t: When -defaults is specified than presentation properties will be"
5688 "\n\t\t: assigned to all objects that have not their own specified properties"
5689 "\n\t\t: and to all objects to be displayed in the future."
5690 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5691 __FILE__,VAspects,group);
5693 theCommands.Add("vsetcolor",
5694 "vsetcolor [-noupdate|-update] [name] ColorName"
5695 "\n\t\t: Sets color for all, selected or named objects."
5696 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5697 __FILE__,VAspects,group);
5699 theCommands.Add("vunsetcolor",
5700 "vunsetcolor [-noupdate|-update] [name]"
5701 "\n\t\t: Resets color for all, selected or named objects."
5702 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5703 __FILE__,VAspects,group);
5705 theCommands.Add("vsettransparency",
5706 "vsettransparency [-noupdate|-update] [name] Coefficient"
5707 "\n\t\t: Sets transparency for all, selected or named objects."
5708 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5709 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5710 __FILE__,VAspects,group);
5712 theCommands.Add("vunsettransparency",
5713 "vunsettransparency [-noupdate|-update] [name]"
5714 "\n\t\t: Resets transparency for all, selected or named objects."
5715 "\n\t\t: Alias for vaspects -unsettransp [name].",
5716 __FILE__,VAspects,group);
5718 theCommands.Add("vsetmaterial",
5719 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5720 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5721 __FILE__,VAspects,group);
5723 theCommands.Add("vunsetmaterial",
5724 "vunsetmaterial [-noupdate|-update] [name]"
5725 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5726 __FILE__,VAspects,group);
5728 theCommands.Add("vsetwidth",
5729 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5730 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5731 __FILE__,VAspects,group);
5733 theCommands.Add("vunsetwidth",
5734 "vunsetwidth [-noupdate|-update] [name]"
5735 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5736 __FILE__,VAspects,group);
5738 theCommands.Add("vsetinteriorstyle",
5739 "vsetinteriorstyle [-noupdate|-update] [name] style"
5740 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5741 __FILE__,VSetInteriorStyle,group);
5743 theCommands.Add("vsensdis",
5744 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5745 "\n\t\t: Standard entity types are those defined in Select3D package:"
5746 "\n\t\t: - sensitive box"
5747 "\n\t\t: - sensitive face"
5748 "\n\t\t: - sensitive curve"
5749 "\n\t\t: - sensitive segment"
5750 "\n\t\t: - sensitive circle"
5751 "\n\t\t: - sensitive point"
5752 "\n\t\t: - sensitive triangulation"
5753 "\n\t\t: - sensitive triangle"
5754 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5755 __FILE__,VDispSensi,group);
5757 theCommands.Add("vsensera",
5758 "vsensera : erase active entities",
5759 __FILE__,VClearSensi,group);
5761 theCommands.Add("vperf",
5762 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
5763 "\n\t\t: Tests the animation of an object along a predefined trajectory.",
5764 __FILE__,VPerf,group);
5766 theCommands.Add("vanimation",
5767 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5768 __FILE__,VAnimation,group);
5770 theCommands.Add("vsetshading",
5771 "vsetshading : vsetshading name Quality(default=0.0008) "
5772 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5773 __FILE__,VShading,group);
5775 theCommands.Add("vunsetshading",
5776 "vunsetshading :vunsetshading name "
5777 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5778 __FILE__,VShading,group);
5780 theCommands.Add ("vtexture",
5781 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5782 " [-scale u v] [-scale off]\n"
5783 " [-origin u v] [-origin off]\n"
5784 " [-repeat u v] [-repeat off]\n"
5785 " [-modulate {on | off}]"
5787 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5788 " specifying one of the predefined textures.\n"
5789 " The options are: \n"
5790 " -scale u v : enable texture scaling and set scale factors\n"
5791 " -scale off : disable texture scaling\n"
5792 " -origin u v : enable texture origin positioning and set the origin\n"
5793 " -origin off : disable texture origin positioning\n"
5794 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5795 " -repeat off : disable texture repeat\n"
5796 " -modulate {on | off} : enable or disable texture modulation\n"
5797 " -default : sets texture mapping default parameters\n"
5798 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5799 "or 'vtexture NameOfShape ?' to list available textures\n",
5800 __FILE__, VTexture, group);
5802 theCommands.Add("vtexscale",
5803 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5804 or 'vtexscale NameOfShape ScaleUV' \n \
5805 or 'vtexscale NameOfShape' to disable scaling\n ",
5806 __FILE__,VTexture,group);
5808 theCommands.Add("vtexorigin",
5809 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5810 or 'vtexorigin NameOfShape UVOrigin' \n \
5811 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5812 __FILE__,VTexture,group);
5814 theCommands.Add("vtexrepeat",
5815 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5816 or 'vtexrepeat NameOfShape UVRepeat \n \
5817 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5820 theCommands.Add("vtexdefault",
5821 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5824 theCommands.Add("vsetam",
5825 "vsetam [shapename] mode"
5826 "\n\t\t: Activates selection mode for all selected or named shapes."
5827 "\n\t\t: Mod can be:"
5828 "\n\t\t: 0 - for shape itself"
5829 "\n\t\t: 1 - vertices"
5833 "\n\t\t: 5 - shells"
5834 "\n\t\t: 6 - solids"
5835 "\n\t\t: 7 - compounds"
5836 __FILE__,VActivatedMode,group);
5838 theCommands.Add("vunsetam",
5839 "vunsetam : Deactivates all selection modes for all shapes.",
5840 __FILE__,VActivatedMode,group);
5842 theCommands.Add("vstate",
5843 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5844 "\n\t\t: Reports show/hidden state for selected or named objects"
5845 "\n\t\t: -entities - print low-level information about detected entities"
5846 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5847 __FILE__,VState,group);
5849 theCommands.Add("vpickshapes",
5850 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5851 __FILE__,VPickShape,group);
5853 theCommands.Add("vtypes",
5854 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5857 theCommands.Add("vr",
5859 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
5860 __FILE__,vr, group);
5862 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5863 __FILE__, VPickSelected, group);
5865 theCommands.Add ("vloadselection",
5866 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5867 "\n\t\t: primitives for the shapes with names given without displaying them."
5868 "\n\t\t: -local - open local context before selection computation",
5869 __FILE__, VLoadSelection, group);
5871 theCommands.Add("vbsdf", "vbsdf [name] [options]"
5872 "\nAdjusts parameters of material BSDF:"
5873 "\n -help : Shows this message"
5874 "\n -print : Print BSDF"
5875 "\n -kd : Weight of the Lambertian BRDF"
5876 "\n -kr : Weight of the reflection BRDF"
5877 "\n -kt : Weight of the transmission BTDF"
5878 "\n -ks : Weight of the glossy Blinn BRDF"
5879 "\n -le : Self-emitted radiance"
5880 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5881 "\n Schlick x y z, Dielectric x, Conductor x y"
5882 "\n -roughness : Roughness of material (Blinn's exponent)"
5883 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
5884 "\n -absorpcolor : Absorption color (only for transparent material)"
5885 "\n -normalize : Normalize BSDF coefficients",
5886 __FILE__, VBsdf, group);
5890 //=====================================================================
5891 //========================= for testing Draft and Rib =================
5892 //=====================================================================
5893 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5894 #include <DBRep.hxx>
5895 #include <TopoDS_Face.hxx>
5896 #include <gp_Pln.hxx>
5897 #include <AIS_KindOfSurface.hxx>
5898 #include <BRepOffsetAPI_DraftAngle.hxx>
5899 #include <Precision.hxx>
5900 #include <BRepAlgo.hxx>
5901 #include <OSD_Environment.hxx>
5902 #include <DrawTrSurf.hxx>
5903 //#include <DbgTools.hxx>
5904 //#include <FeatAlgo_MakeLinearForm.hxx>
5909 //=======================================================================
5910 //function : IsValid
5912 //=======================================================================
5913 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5914 const TopoDS_Shape& theResult,
5915 const Standard_Boolean closedSolid,
5916 const Standard_Boolean GeomCtrl)
5918 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5919 TCollection_AsciiString checkValid = check.Value();
5920 Standard_Boolean ToCheck = Standard_True;
5921 if (!checkValid.IsEmpty()) {
5923 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5925 if ( checkValid=="true" || checkValid=="TRUE" ) {
5926 ToCheck= Standard_False;
5930 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
5933 Standard_Boolean IsValid = Standard_True;
5935 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5940 //===============================================================================
5941 // TDraft : test draft, uses AIS Viewer
5942 // Solid Face Plane Angle Reverse
5943 //===============================================================================
5944 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5946 if (argc < 5) return 1;
5947 // argv[1] - TopoDS_Shape Solid
5948 // argv[2] - TopoDS_Shape Face
5949 // argv[3] - TopoDS_Shape Plane
5950 // argv[4] - Standard_Real Angle
5951 // argv[5] - Standard_Integer Reverse
5953 // Sprintf(prefix, argv[1]);
5954 Standard_Real anAngle = 0;
5955 Standard_Boolean Rev = Standard_False;
5956 Standard_Integer rev = 0;
5957 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5958 TopoDS_Shape face = GetShapeFromName(argv[2]);
5959 TopoDS_Face Face = TopoDS::Face(face);
5960 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5961 if (Plane.IsNull ()) {
5962 di << "TEST : Plane is NULL\n";
5965 anAngle = Draw::Atof(argv[4]);
5966 anAngle = 2*M_PI * anAngle / 360.0;
5968 Handle( Geom_Surface )aSurf;
5969 AIS_KindOfSurface aSurfType;
5970 Standard_Real Offset;
5972 if(argc > 4) { // == 5
5973 rev = Draw::Atoi(argv[5]);
5974 Rev = (rev)? Standard_True : Standard_False;
5977 TopoDS_Face face2 = TopoDS::Face(Plane);
5978 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5980 di << "TEST : Can't find plane\n";
5984 aDir = aPln.Axis().Direction();
5987 if (Plane.Orientation() == TopAbs_REVERSED)
5989 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5991 BRepOffsetAPI_DraftAngle Draft (Solid);
5993 if(Abs(anAngle)< Precision::Angular()) {
5994 di << "TEST : NULL angle\n";
5997 if(Rev) anAngle = - anAngle;
5998 Draft.Add (Face, aDir, anAngle, aPln);
6000 if (!Draft.IsDone()) {
6001 di << "TEST : Draft Not DONE \n";
6004 TopTools_ListOfShape Larg;
6006 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6007 di << "TEST : DesignAlgo returns Not valid\n";
6011 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6012 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6014 if ( !ais.IsNull() ) {
6015 ais->SetColor(DEFAULT_COLOR);
6016 ais->SetMaterial(DEFAULT_MATERIAL);
6017 // Display the AIS_Shape without redraw
6018 Ctx->Display(ais, Standard_False);
6020 const char *Name = "draft1";
6021 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6023 Handle(AIS_InteractiveObject) an_object =
6024 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6025 if (!an_object.IsNull()) {
6026 Ctx->Remove(an_object,
6028 GetMapOfAIS().UnBind2(Name) ;
6031 GetMapOfAIS().Bind(ais, Name);
6032 // DBRep::Set("draft", ais->Shape());
6034 Ctx->Display(ais, Standard_True);
6038 //==============================================================================
6039 //function : splitParameter
6040 //purpose : Split parameter string to parameter name and parameter value
6041 //==============================================================================
6042 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6043 TCollection_AsciiString& theName,
6044 TCollection_AsciiString& theValue)
6046 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6048 if (aParamNameEnd == 0)
6050 return Standard_False;
6053 TCollection_AsciiString aString (theString);
6054 if (aParamNameEnd != 0)
6056 theValue = aString.Split (aParamNameEnd);
6057 aString.Split (aString.Length() - 1);
6061 return Standard_True;
6064 //============================================================================
6066 //============================================================================
6067 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6070 DrawTrSurf::BasicCommands(theCommands);
6071 const char* group = "Check Features Operations commands";
6073 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6075 &TDraft,group); //Draft_Modification
6078 //==============================================================================
6079 // ViewerTest::Factory
6080 //==============================================================================
6081 void ViewerTest::Factory(Draw_Interpretor& theDI)
6083 // definition of Viewer Command
6084 ViewerTest::Commands(theDI);
6087 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6091 // Declare entry point PLUGINFACTORY