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 //==============================================================================
739 //function : VSelPrecision
740 //purpose : To set the selection tolerance value
741 //Draw arg : Selection tolerance value (real value determining the width and
742 // height of selecting frustum bases). Without arguments the function
743 // just prints current tolerance.
744 //==============================================================================
745 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
749 di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
753 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
754 if( aContext.IsNull() )
759 Standard_Real aPixelTolerance = aContext->PixelTolerance();
760 di << "Pixel tolerance : " << aPixelTolerance << "\n";
764 TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
766 if (anArg == "-unset")
768 aContext->SetPixelTolerance (-1);
772 aContext->SetPixelTolerance (anArg.IntegerValue());
779 //! Auxiliary enumeration
780 enum ViewerTest_StereoPair
782 ViewerTest_SP_Single,
783 ViewerTest_SP_SideBySide,
784 ViewerTest_SP_OverUnder
787 //==============================================================================
789 //purpose : To dump the active view snapshot to image file
790 //==============================================================================
791 static Standard_Integer VDump (Draw_Interpretor& theDI,
792 Standard_Integer theArgNb,
793 Standard_CString* theArgVec)
797 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
801 Standard_Integer anArgIter = 1;
802 Standard_CString aFilePath = theArgVec[anArgIter++];
803 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
804 V3d_ImageDumpOptions aParams;
805 aParams.BufferType = Graphic3d_BT_RGB;
806 aParams.StereoOptions = V3d_SDO_MONO;
807 for (; anArgIter < theArgNb; ++anArgIter)
809 TCollection_AsciiString anArg (theArgVec[anArgIter]);
811 if (anArg == "-buffer")
813 if (++anArgIter >= theArgNb)
815 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
819 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
821 if (aBufArg == "rgba")
823 aParams.BufferType = Graphic3d_BT_RGBA;
825 else if (aBufArg == "rgb")
827 aParams.BufferType = Graphic3d_BT_RGB;
829 else if (aBufArg == "depth")
831 aParams.BufferType = Graphic3d_BT_Depth;
835 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
839 else if (anArg == "-stereo")
841 if (++anArgIter >= theArgNb)
843 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
847 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
848 aStereoArg.LowerCase();
849 if (aStereoArg == "l"
850 || aStereoArg == "left")
852 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
854 else if (aStereoArg == "r"
855 || aStereoArg == "right")
857 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
859 else if (aStereoArg == "mono")
861 aParams.StereoOptions = V3d_SDO_MONO;
863 else if (aStereoArg == "blended"
864 || aStereoArg == "blend"
865 || aStereoArg == "stereo")
867 aParams.StereoOptions = V3d_SDO_BLENDED;
869 else if (aStereoArg == "sbs"
870 || aStereoArg == "sidebyside")
872 aStereoPair = ViewerTest_SP_SideBySide;
874 else if (aStereoArg == "ou"
875 || aStereoArg == "overunder")
877 aStereoPair = ViewerTest_SP_OverUnder;
881 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
885 else if (anArg == "-rgba"
888 aParams.BufferType = Graphic3d_BT_RGBA;
890 else if (anArg == "-rgb"
893 aParams.BufferType = Graphic3d_BT_RGB;
895 else if (anArg == "-depth"
898 aParams.BufferType = Graphic3d_BT_Depth;
900 else if (anArg == "-width"
904 if (aParams.Width != 0)
906 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
909 else if (++anArgIter >= theArgNb)
911 std::cout << "Error: integer value is expected right after 'width'\n";
914 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
916 else if (anArg == "-height"
918 || anArg == "-sizey")
920 if (aParams.Height != 0)
922 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
925 else if (++anArgIter >= theArgNb)
927 std::cout << "Error: integer value is expected right after 'height'\n";
930 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
932 else if (anArg == "-tile"
933 || anArg == "-tilesize")
935 if (++anArgIter >= theArgNb)
937 std::cout << "Error: integer value is expected right after 'tileSize'\n";
940 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
944 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
948 if ((aParams.Width <= 0 && aParams.Height > 0)
949 || (aParams.Width > 0 && aParams.Height <= 0))
951 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
955 Handle(V3d_View) aView = ViewerTest::CurrentView();
958 std::cout << "Error: cannot find an active view!\n";
962 if (aParams.Width <= 0 || aParams.Height <= 0)
964 aView->Window()->Size (aParams.Width, aParams.Height);
967 Image_AlienPixMap aPixMap;
969 bool isBigEndian = Image_PixMap::IsBigEndianHost();
970 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
971 switch (aParams.BufferType)
973 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
974 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
975 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
980 case ViewerTest_SP_Single:
982 if (!aView->ToPixMap (aPixMap, aParams))
984 theDI << "Fail: view dump failed!\n";
987 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
988 || aPixMap.SizeY() != Standard_Size(aParams.Height))
990 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
991 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
995 case ViewerTest_SP_SideBySide:
997 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
999 theDI << "Fail: not enough memory for image allocation!\n";
1003 Image_PixMap aPixMapL, aPixMapR;
1004 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1005 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1006 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1007 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1009 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1010 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1011 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1012 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1015 theDI << "Fail: view dump failed!\n";
1020 case ViewerTest_SP_OverUnder:
1022 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1024 theDI << "Fail: not enough memory for image allocation!\n";
1028 Image_PixMap aPixMapL, aPixMapR;
1029 aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
1030 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1031 aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1032 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1034 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1035 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1036 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1037 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1040 theDI << "Fail: view dump failed!\n";
1047 if (!aPixMap.Save (aFilePath))
1049 theDI << "Fail: image can not be saved!\n";
1054 enum TypeOfDispOperation
1056 TypeOfDispOperation_SetDispMode,
1057 TypeOfDispOperation_UnsetDispMode
1060 //! Displays,Erase...
1061 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1062 const Standard_Integer theMode,
1063 const TypeOfDispOperation theType,
1064 const Standard_Boolean theToUpdate)
1066 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1069 case TypeOfDispOperation_SetDispMode:
1071 if (!thePrs.IsNull())
1073 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1077 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1081 case TypeOfDispOperation_UnsetDispMode:
1083 if (!thePrs.IsNull())
1085 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1089 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1096 //=======================================================================
1099 //=======================================================================
1100 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1105 std::cout << "Syntax error: wrong number of arguments\n";
1109 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1110 ? TypeOfDispOperation_UnsetDispMode
1111 : TypeOfDispOperation_SetDispMode;
1112 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1113 if (aType == TypeOfDispOperation_UnsetDispMode)
1117 if (aCtx->NbSelected() == 0)
1119 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1123 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1125 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1128 aCtx->UpdateCurrentViewer();
1132 TCollection_AsciiString aName = argv[1];
1133 if (GetMapOfAIS().IsBound2 (aName))
1135 Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1138 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1145 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1146 if (aCtx->NbSelected() == 0
1147 && aType == TypeOfDispOperation_SetDispMode)
1149 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1151 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1153 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1155 aCtx->UpdateCurrentViewer();
1159 Handle(AIS_InteractiveObject) aPrs;
1160 TCollection_AsciiString aName (argv[1]);
1161 if (GetMapOfAIS().IsBound2 (aName))
1163 aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1167 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1174 //=======================================================================
1177 //=======================================================================
1178 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1180 if(argc==1) return 1;
1181 Standard_Integer On = Draw::Atoi(argv[1]);
1182 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1186 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1187 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1188 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1192 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1196 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1200 Ctx->UpdateCurrentViewer();
1203 Handle(AIS_InteractiveObject) IO;
1204 TCollection_AsciiString name = argv[2];
1205 if(GetMapOfAIS().IsBound2(name)){
1206 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1209 Ctx->SubIntensityOn(IO);
1211 Ctx->SubIntensityOff(IO);
1219 //! Auxiliary class to iterate presentations from different collections.
1220 class ViewTest_PrsIter
1224 //! Create and initialize iterator object.
1225 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1226 : mySource (IterSource_All)
1228 NCollection_Sequence<TCollection_AsciiString> aNames;
1229 if (!theName.IsEmpty())
1230 aNames.Append (theName);
1234 //! Create and initialize iterator object.
1235 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1236 : mySource (IterSource_All)
1241 //! Initialize the iterator.
1242 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1244 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1246 mySelIter.Nullify();
1247 myCurrent.Nullify();
1248 myCurrentTrs.Nullify();
1249 if (!mySeq.IsEmpty())
1251 mySource = IterSource_List;
1252 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1254 else if (aCtx->NbSelected() > 0)
1256 mySource = IterSource_Selected;
1258 mySelIter->InitSelected();
1262 mySource = IterSource_All;
1263 myMapIter.Initialize (GetMapOfAIS());
1268 const TCollection_AsciiString& CurrentName() const
1270 return myCurrentName;
1273 const Handle(AIS_InteractiveObject)& Current() const
1278 const Handle(Standard_Transient)& CurrentTrs() const
1280 return myCurrentTrs;
1283 //! @return true if iterator points to valid object within collection
1284 Standard_Boolean More() const
1288 case IterSource_All: return myMapIter.More();
1289 case IterSource_List: return mySeqIter.More();
1290 case IterSource_Selected: return mySelIter->MoreSelected();
1292 return Standard_False;
1295 //! Go to the next item.
1298 myCurrentName.Clear();
1299 myCurrentTrs.Nullify();
1300 myCurrent.Nullify();
1303 case IterSource_All:
1308 case IterSource_List:
1313 case IterSource_Selected:
1315 mySelIter->NextSelected();
1328 case IterSource_All:
1330 if (myMapIter.More())
1332 myCurrentName = myMapIter.Key2();
1333 myCurrentTrs = myMapIter.Key1();
1334 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1338 case IterSource_List:
1340 if (mySeqIter.More())
1342 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1344 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1347 myCurrentName = mySeqIter.Value();
1348 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1349 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1353 case IterSource_Selected:
1355 if (mySelIter->MoreSelected())
1357 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1358 myCurrent = mySelIter->SelectedInteractive();
1376 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1377 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1378 NCollection_Sequence<TCollection_AsciiString> mySeq;
1379 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1381 TCollection_AsciiString myCurrentName;//!< current item name
1382 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1383 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1385 IterSource mySource; //!< iterated collection
1389 //==============================================================================
1390 //function : VInteriorStyle
1391 //purpose : sets interior style of the a selected or named or displayed shape
1392 //==============================================================================
1393 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1394 Standard_Integer theArgNb,
1395 const char** theArgVec)
1397 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1398 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1401 std::cerr << "Error: no active view!\n";
1405 Standard_Integer anArgIter = 1;
1406 for (; anArgIter < theArgNb; ++anArgIter)
1408 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1413 TCollection_AsciiString aName;
1414 if (theArgNb - anArgIter == 2)
1416 aName = theArgVec[anArgIter++];
1418 else if (theArgNb - anArgIter != 1)
1420 std::cout << "Error: wrong number of arguments! See usage:\n";
1421 theDI.PrintHelp (theArgVec[0]);
1424 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1425 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1426 aStyleArg.LowerCase();
1427 if (aStyleArg == "empty")
1431 else if (aStyleArg == "hollow")
1435 else if (aStyleArg == "hatch")
1439 else if (aStyleArg == "solid")
1443 else if (aStyleArg == "hiddenline")
1449 anInterStyle = aStyleArg.IntegerValue();
1451 if (anInterStyle < Aspect_IS_EMPTY
1452 || anInterStyle > Aspect_IS_HIDDENLINE)
1454 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1455 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1459 if (!aName.IsEmpty()
1460 && !GetMapOfAIS().IsBound2 (aName))
1462 std::cout << "Error: object " << aName << " is not displayed!\n";
1466 if (aCtx->HasOpenedContext())
1468 aCtx->CloseLocalContext();
1470 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1472 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1475 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1476 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1477 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1478 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1479 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1485 //! Auxiliary structure for VAspects
1486 struct ViewerTest_AspectsChangeSet
1488 Standard_Integer ToSetVisibility;
1489 Standard_Integer Visibility;
1491 Standard_Integer ToSetColor;
1492 Quantity_Color Color;
1494 Standard_Integer ToSetLineWidth;
1495 Standard_Real LineWidth;
1497 Standard_Integer ToSetTypeOfLine;
1498 Aspect_TypeOfLine TypeOfLine;
1500 Standard_Integer ToSetTransparency;
1501 Standard_Real Transparency;
1503 Standard_Integer ToSetMaterial;
1504 Graphic3d_NameOfMaterial Material;
1505 TCollection_AsciiString MatName;
1507 NCollection_Sequence<TopoDS_Shape> SubShapes;
1509 Standard_Integer ToSetShowFreeBoundary;
1510 Standard_Integer ToSetFreeBoundaryWidth;
1511 Standard_Real FreeBoundaryWidth;
1512 Standard_Integer ToSetFreeBoundaryColor;
1513 Quantity_Color FreeBoundaryColor;
1515 Standard_Integer ToEnableIsoOnTriangulation;
1517 Standard_Integer ToSetMaxParamValue;
1518 Standard_Real MaxParamValue;
1520 Standard_Integer ToSetSensitivity;
1521 Standard_Integer SelectionMode;
1522 Standard_Integer Sensitivity;
1524 //! Empty constructor
1525 ViewerTest_AspectsChangeSet()
1526 : ToSetVisibility (0),
1529 Color (DEFAULT_COLOR),
1532 ToSetTypeOfLine (0),
1533 TypeOfLine (Aspect_TOL_SOLID),
1534 ToSetTransparency (0),
1537 Material (Graphic3d_NOM_DEFAULT),
1538 ToSetShowFreeBoundary (0),
1539 ToSetFreeBoundaryWidth (0),
1540 FreeBoundaryWidth (1.0),
1541 ToSetFreeBoundaryColor (0),
1542 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1543 ToEnableIsoOnTriangulation (-1),
1544 ToSetMaxParamValue (0),
1545 MaxParamValue (500000),
1546 ToSetSensitivity (0),
1550 //! @return true if no changes have been requested
1551 Standard_Boolean IsEmpty() const
1553 return ToSetVisibility == 0
1554 && ToSetLineWidth == 0
1555 && ToSetTransparency == 0
1557 && ToSetMaterial == 0
1558 && ToSetShowFreeBoundary == 0
1559 && ToSetFreeBoundaryColor == 0
1560 && ToSetFreeBoundaryWidth == 0
1561 && ToSetMaxParamValue == 0
1562 && ToSetSensitivity == 0;
1565 //! @return true if properties are valid
1566 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1568 Standard_Boolean isOk = Standard_True;
1569 if (Visibility != 0 && Visibility != 1)
1571 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1572 isOk = Standard_False;
1574 if (LineWidth <= 0.0
1575 || LineWidth > 10.0)
1577 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1578 isOk = Standard_False;
1580 if (Transparency < 0.0
1581 || Transparency > 1.0)
1583 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1584 isOk = Standard_False;
1587 && ToSetTransparency)
1589 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1590 isOk = Standard_False;
1592 if (ToSetMaterial == 1
1593 && Material == Graphic3d_NOM_DEFAULT)
1595 std::cout << "Error: unknown material " << MatName << ".\n";
1596 isOk = Standard_False;
1598 if (FreeBoundaryWidth <= 0.0
1599 || FreeBoundaryWidth > 10.0)
1601 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1602 isOk = Standard_False;
1604 if (MaxParamValue < 0.0)
1606 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1607 isOk = Standard_False;
1609 if (Sensitivity <= 0 && ToSetSensitivity)
1611 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1612 isOk = Standard_False;
1619 //==============================================================================
1620 //function : VAspects
1622 //==============================================================================
1623 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1624 Standard_Integer theArgNb,
1625 const char** theArgVec)
1627 TCollection_AsciiString aCmdName (theArgVec[0]);
1628 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1629 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1632 std::cerr << "Error: no active view!\n";
1636 Standard_Integer anArgIter = 1;
1637 Standard_Boolean isDefaults = Standard_False;
1638 NCollection_Sequence<TCollection_AsciiString> aNames;
1639 for (; anArgIter < theArgNb; ++anArgIter)
1641 TCollection_AsciiString anArg = theArgVec[anArgIter];
1642 if (anUpdateTool.parseRedrawMode (anArg))
1646 else if (!anArg.IsEmpty()
1647 && anArg.Value (1) != '-')
1649 aNames.Append (anArg);
1653 if (anArg == "-defaults")
1655 isDefaults = Standard_True;
1662 if (!aNames.IsEmpty() && isDefaults)
1664 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1668 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1669 aChanges.Append (ViewerTest_AspectsChangeSet());
1670 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1672 // parse syntax of legacy commands
1673 if (aCmdName == "vsetwidth")
1675 if (aNames.IsEmpty()
1676 || !aNames.Last().IsRealValue())
1678 std::cout << "Error: not enough arguments!\n";
1681 aChangeSet->ToSetLineWidth = 1;
1682 aChangeSet->LineWidth = aNames.Last().RealValue();
1683 aNames.Remove (aNames.Length());
1685 else if (aCmdName == "vunsetwidth")
1687 aChangeSet->ToSetLineWidth = -1;
1689 else if (aCmdName == "vsetcolor")
1691 if (aNames.IsEmpty())
1693 std::cout << "Error: not enough arguments!\n";
1696 aChangeSet->ToSetColor = 1;
1698 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1699 Standard_Boolean isOk = Standard_False;
1700 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1702 aChangeSet->Color = aColor;
1703 aNames.Remove (aNames.Length());
1704 isOk = Standard_True;
1706 else if (aNames.Length() >= 3)
1708 const TCollection_AsciiString anRgbStr[3] =
1710 aNames.Value (aNames.Upper() - 2),
1711 aNames.Value (aNames.Upper() - 1),
1712 aNames.Value (aNames.Upper() - 0)
1714 isOk = anRgbStr[0].IsRealValue()
1715 && anRgbStr[1].IsRealValue()
1716 && anRgbStr[2].IsRealValue();
1719 Graphic3d_Vec4d anRgb;
1720 anRgb.x() = anRgbStr[0].RealValue();
1721 anRgb.y() = anRgbStr[1].RealValue();
1722 anRgb.z() = anRgbStr[2].RealValue();
1723 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1724 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1725 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1727 std::cout << "Error: RGB color values should be within range 0..1!\n";
1730 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1731 aNames.Remove (aNames.Length());
1732 aNames.Remove (aNames.Length());
1733 aNames.Remove (aNames.Length());
1738 std::cout << "Error: not enough arguments!\n";
1742 else if (aCmdName == "vunsetcolor")
1744 aChangeSet->ToSetColor = -1;
1746 else if (aCmdName == "vsettransparency")
1748 if (aNames.IsEmpty()
1749 || !aNames.Last().IsRealValue())
1751 std::cout << "Error: not enough arguments!\n";
1754 aChangeSet->ToSetTransparency = 1;
1755 aChangeSet->Transparency = aNames.Last().RealValue();
1756 aNames.Remove (aNames.Length());
1758 else if (aCmdName == "vunsettransparency")
1760 aChangeSet->ToSetTransparency = -1;
1762 else if (aCmdName == "vsetmaterial")
1764 if (aNames.IsEmpty())
1766 std::cout << "Error: not enough arguments!\n";
1769 aChangeSet->ToSetMaterial = 1;
1770 aChangeSet->MatName = aNames.Last();
1771 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1772 aNames.Remove (aNames.Length());
1774 else if (aCmdName == "vunsetmaterial")
1776 aChangeSet->ToSetMaterial = -1;
1778 else if (anArgIter >= theArgNb)
1780 std::cout << "Error: not enough arguments!\n";
1784 if (!aChangeSet->IsEmpty())
1786 anArgIter = theArgNb;
1788 for (; anArgIter < theArgNb; ++anArgIter)
1790 TCollection_AsciiString anArg = theArgVec[anArgIter];
1792 if (anArg == "-setwidth"
1793 || anArg == "-setlinewidth")
1795 if (++anArgIter >= theArgNb)
1797 std::cout << "Error: wrong syntax at " << anArg << "\n";
1800 aChangeSet->ToSetLineWidth = 1;
1801 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1803 else if (anArg == "-unsetwidth"
1804 || anArg == "-unsetlinewidth")
1806 aChangeSet->ToSetLineWidth = -1;
1807 aChangeSet->LineWidth = 1.0;
1809 else if (anArg == "-settransp"
1810 || anArg == "-settransparency")
1812 if (++anArgIter >= theArgNb)
1814 std::cout << "Error: wrong syntax at " << anArg << "\n";
1817 aChangeSet->ToSetTransparency = 1;
1818 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1819 if (aChangeSet->Transparency >= 0.0
1820 && aChangeSet->Transparency <= Precision::Confusion())
1822 aChangeSet->ToSetTransparency = -1;
1823 aChangeSet->Transparency = 0.0;
1826 else if (anArg == "-setvis"
1827 || anArg == "-setvisibility")
1829 if (++anArgIter >= theArgNb)
1831 std::cout << "Error: wrong syntax at " << anArg << "\n";
1835 aChangeSet->ToSetVisibility = 1;
1836 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1838 else if (anArg == "-setalpha")
1840 if (++anArgIter >= theArgNb)
1842 std::cout << "Error: wrong syntax at " << anArg << "\n";
1845 aChangeSet->ToSetTransparency = 1;
1846 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1847 if (aChangeSet->Transparency < 0.0
1848 || aChangeSet->Transparency > 1.0)
1850 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1853 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1854 if (aChangeSet->Transparency >= 0.0
1855 && aChangeSet->Transparency <= Precision::Confusion())
1857 aChangeSet->ToSetTransparency = -1;
1858 aChangeSet->Transparency = 0.0;
1861 else if (anArg == "-unsettransp"
1862 || anArg == "-unsettransparency"
1863 || anArg == "-unsetalpha"
1864 || anArg == "-opaque")
1866 aChangeSet->ToSetTransparency = -1;
1867 aChangeSet->Transparency = 0.0;
1869 else if (anArg == "-setcolor")
1871 Standard_Integer aNbComps = 0;
1872 Standard_Integer aCompIter = anArgIter + 1;
1873 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1875 if (theArgVec[aCompIter][0] == '-')
1884 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1885 Standard_CString aName = theArgVec[anArgIter + 1];
1886 if (!Quantity_Color::ColorFromName (aName, aColor))
1888 std::cout << "Error: unknown color name '" << aName << "'\n";
1891 aChangeSet->Color = aColor;
1896 Graphic3d_Vec3d anRgb;
1897 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1898 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1899 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1900 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1901 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1902 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1904 std::cout << "Error: RGB color values should be within range 0..1!\n";
1907 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1912 std::cout << "Error: wrong syntax at " << anArg << "\n";
1916 aChangeSet->ToSetColor = 1;
1917 anArgIter += aNbComps;
1919 else if (anArg == "-setlinetype")
1921 if (++anArgIter >= theArgNb)
1923 std::cout << "Error: wrong syntax at " << anArg << "\n";
1927 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1930 if (aValue.IsEqual ("solid"))
1932 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1934 else if (aValue.IsEqual ("dot"))
1936 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1938 else if (aValue.IsEqual ("dash"))
1940 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1942 else if (aValue.IsEqual ("dotdash"))
1944 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1948 std::cout << "Error: wrong syntax at " << anArg << "\n";
1952 aChangeSet->ToSetTypeOfLine = 1;
1954 else if (anArg == "-unsetlinetype")
1956 aChangeSet->ToSetTypeOfLine = -1;
1958 else if (anArg == "-unsetcolor")
1960 aChangeSet->ToSetColor = -1;
1961 aChangeSet->Color = DEFAULT_COLOR;
1963 else if (anArg == "-setmat"
1964 || anArg == "-setmaterial")
1966 if (++anArgIter >= theArgNb)
1968 std::cout << "Error: wrong syntax at " << anArg << "\n";
1971 aChangeSet->ToSetMaterial = 1;
1972 aChangeSet->MatName = theArgVec[anArgIter];
1973 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1975 else if (anArg == "-unsetmat"
1976 || anArg == "-unsetmaterial")
1978 aChangeSet->ToSetMaterial = -1;
1979 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1981 else if (anArg == "-subshape"
1982 || anArg == "-subshapes")
1986 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1990 if (aNames.IsEmpty())
1992 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1996 aChanges.Append (ViewerTest_AspectsChangeSet());
1997 aChangeSet = &aChanges.ChangeLast();
1999 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2001 Standard_CString aSubShapeName = theArgVec[anArgIter];
2002 if (*aSubShapeName == '-')
2008 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2009 if (aSubShape.IsNull())
2011 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2014 aChangeSet->SubShapes.Append (aSubShape);
2017 if (aChangeSet->SubShapes.IsEmpty())
2019 std::cerr << "Error: empty list is specified after -subshapes!\n";
2023 else if (anArg == "-freeboundary"
2026 if (++anArgIter >= theArgNb)
2028 std::cout << "Error: wrong syntax at " << anArg << "\n";
2031 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2036 aChangeSet->ToSetShowFreeBoundary = 1;
2038 else if (aValue == "off"
2041 aChangeSet->ToSetShowFreeBoundary = -1;
2045 std::cout << "Error: wrong syntax at " << anArg << "\n";
2049 else if (anArg == "-setfreeboundarywidth"
2050 || anArg == "-setfbwidth")
2052 if (++anArgIter >= theArgNb)
2054 std::cout << "Error: wrong syntax at " << anArg << "\n";
2057 aChangeSet->ToSetFreeBoundaryWidth = 1;
2058 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2060 else if (anArg == "-unsetfreeboundarywidth"
2061 || anArg == "-unsetfbwidth")
2063 aChangeSet->ToSetFreeBoundaryWidth = -1;
2064 aChangeSet->FreeBoundaryWidth = 1.0;
2066 else if (anArg == "-setfreeboundarycolor"
2067 || anArg == "-setfbcolor")
2069 Standard_Integer aNbComps = 0;
2070 Standard_Integer aCompIter = anArgIter + 1;
2071 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2073 if (theArgVec[aCompIter][0] == '-')
2082 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2083 Standard_CString aName = theArgVec[anArgIter + 1];
2084 if (!Quantity_Color::ColorFromName (aName, aColor))
2086 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2089 aChangeSet->FreeBoundaryColor = aColor;
2094 Graphic3d_Vec3d anRgb;
2095 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2096 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2097 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2098 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2099 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2100 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2102 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2105 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2110 std::cout << "Error: wrong syntax at " << anArg << "\n";
2114 aChangeSet->ToSetFreeBoundaryColor = 1;
2115 anArgIter += aNbComps;
2117 else if (anArg == "-unsetfreeboundarycolor"
2118 || anArg == "-unsetfbcolor")
2120 aChangeSet->ToSetFreeBoundaryColor = -1;
2121 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2123 else if (anArg == "-unset")
2125 aChangeSet->ToSetVisibility = 1;
2126 aChangeSet->Visibility = 1;
2127 aChangeSet->ToSetLineWidth = -1;
2128 aChangeSet->LineWidth = 1.0;
2129 aChangeSet->ToSetTypeOfLine = -1;
2130 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2131 aChangeSet->ToSetTransparency = -1;
2132 aChangeSet->Transparency = 0.0;
2133 aChangeSet->ToSetColor = -1;
2134 aChangeSet->Color = DEFAULT_COLOR;
2135 aChangeSet->ToSetMaterial = -1;
2136 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2137 aChangeSet->ToSetShowFreeBoundary = -1;
2138 aChangeSet->ToSetFreeBoundaryColor = -1;
2139 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2140 aChangeSet->ToSetFreeBoundaryWidth = -1;
2141 aChangeSet->FreeBoundaryWidth = 1.0;
2143 else if (anArg == "-isoontriangulation"
2144 || anArg == "-isoontriang")
2146 if (++anArgIter >= theArgNb)
2148 std::cout << "Error: wrong syntax at " << anArg << "\n";
2151 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2156 aChangeSet->ToEnableIsoOnTriangulation = 1;
2158 else if (aValue == "off"
2161 aChangeSet->ToEnableIsoOnTriangulation = 0;
2165 std::cout << "Error: wrong syntax at " << anArg << "\n";
2169 else if (anArg == "-setmaxparamvalue")
2171 if (++anArgIter >= theArgNb)
2173 std::cout << "Error: wrong syntax at " << anArg << "\n";
2176 aChangeSet->ToSetMaxParamValue = 1;
2177 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2179 else if (anArg == "-setsensitivity")
2183 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2187 if (aNames.IsEmpty())
2189 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2193 if (anArgIter + 2 >= theArgNb)
2195 std::cout << "Error: wrong syntax at " << anArg << "\n";
2198 aChangeSet->ToSetSensitivity = 1;
2199 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2200 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2204 std::cout << "Error: wrong syntax at " << anArg << "\n";
2209 Standard_Boolean isFirst = Standard_True;
2210 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2211 aChangesIter.More(); aChangesIter.Next())
2213 if (!aChangesIter.Value().Validate (!isFirst))
2217 isFirst = Standard_False;
2220 if (aCtx->HasOpenedContext())
2222 aCtx->CloseLocalContext();
2225 // special case for -defaults parameter.
2226 // all changed values will be set to DefaultDrawer.
2229 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2231 if (aChangeSet->ToSetLineWidth != 0)
2233 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2234 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2235 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2236 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2238 if (aChangeSet->ToSetColor != 0)
2240 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2241 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2242 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2243 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2244 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2245 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2247 if (aChangeSet->ToSetTypeOfLine != 0)
2249 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2250 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2251 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2252 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2253 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2255 if (aChangeSet->ToSetTransparency != 0)
2257 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2259 if (aChangeSet->ToSetMaterial != 0)
2261 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2263 if (aChangeSet->ToSetShowFreeBoundary == 1)
2265 aDrawer->SetFreeBoundaryDraw (Standard_True);
2267 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2269 aDrawer->SetFreeBoundaryDraw (Standard_False);
2271 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2273 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2275 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2277 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2279 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2281 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2283 if (aChangeSet->ToSetMaxParamValue != 0)
2285 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2288 // redisplay all objects in context
2289 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2291 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2294 aCtx->Redisplay (aPrs, Standard_False);
2300 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2302 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2303 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2304 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2305 Handle(AIS_ColoredShape) aColoredPrs;
2306 Standard_Boolean toDisplay = Standard_False;
2307 Standard_Boolean toRedisplay = Standard_False;
2308 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2310 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2311 if (aShapePrs.IsNull())
2313 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2316 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2317 if (aColoredPrs.IsNull())
2319 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2320 if (aShapePrs->HasDisplayMode())
2322 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2324 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2325 aCtx->Remove (aShapePrs, Standard_False);
2326 GetMapOfAIS().UnBind2 (aName);
2327 GetMapOfAIS().Bind (aColoredPrs, aName);
2328 toDisplay = Standard_True;
2329 aShapePrs = aColoredPrs;
2336 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2337 aChangeSet = &aChangesIter.ChangeValue();
2338 if (aChangeSet->ToSetVisibility == 1)
2340 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2341 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2343 else if (aChangeSet->ToSetMaterial == 1)
2345 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2347 else if (aChangeSet->ToSetMaterial == -1)
2349 aCtx->UnsetMaterial (aPrs, Standard_False);
2351 if (aChangeSet->ToSetColor == 1)
2353 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2355 else if (aChangeSet->ToSetColor == -1)
2357 aCtx->UnsetColor (aPrs, Standard_False);
2359 if (aChangeSet->ToSetTransparency == 1)
2361 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2363 else if (aChangeSet->ToSetTransparency == -1)
2365 aCtx->UnsetTransparency (aPrs, Standard_False);
2367 if (aChangeSet->ToSetLineWidth == 1)
2369 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2371 else if (aChangeSet->ToSetLineWidth == -1)
2373 aCtx->UnsetWidth (aPrs, Standard_False);
2375 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2377 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2378 toRedisplay = Standard_True;
2380 else if (aChangeSet->ToSetSensitivity != 0)
2382 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2384 if (!aDrawer.IsNull())
2386 if (aChangeSet->ToSetShowFreeBoundary == 1)
2388 aDrawer->SetFreeBoundaryDraw (Standard_True);
2389 toRedisplay = Standard_True;
2391 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2393 aDrawer->SetFreeBoundaryDraw (Standard_False);
2394 toRedisplay = Standard_True;
2396 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2398 Handle(Prs3d_LineAspect) aBoundaryAspect =
2399 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2400 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2401 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2402 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2403 toRedisplay = Standard_True;
2405 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2407 Handle(Prs3d_LineAspect) aBoundaryAspect =
2408 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2409 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2410 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2411 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2412 toRedisplay = Standard_True;
2414 if (aChangeSet->ToSetTypeOfLine != 0)
2416 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2417 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2418 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2419 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2420 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2421 toRedisplay = Standard_True;
2423 if (aChangeSet->ToSetMaxParamValue != 0)
2425 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2429 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2431 aChangeSet = &aChangesIter.ChangeValue();
2432 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2433 aSubShapeIter.More(); aSubShapeIter.Next())
2435 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2436 if (aChangeSet->ToSetVisibility == 1)
2438 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2439 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2441 if (aChangeSet->ToSetColor == 1)
2443 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2445 if (aChangeSet->ToSetLineWidth == 1)
2447 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2449 if (aChangeSet->ToSetColor == -1
2450 || aChangeSet->ToSetLineWidth == -1)
2452 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2454 if (aChangeSet->ToSetMaxParamValue != 0)
2456 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2457 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2459 if (aChangeSet->ToSetSensitivity != 0)
2461 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2467 aCtx->Display (aPrs, Standard_False);
2471 aCtx->Redisplay (aPrs, Standard_False);
2473 else if (!aColoredPrs.IsNull())
2475 aCtx->Redisplay (aColoredPrs, Standard_False);
2482 //==============================================================================
2483 //function : VDonly2
2485 //purpose : Display only a selected or named object
2486 // if there is no selected or named object s, nothing is done
2487 //==============================================================================
2488 static int VDonly2 (Draw_Interpretor& ,
2489 Standard_Integer theArgNb,
2490 const char** theArgVec)
2492 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2493 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2496 std::cerr << "Error: no active view!\n";
2500 if (aCtx->HasOpenedContext())
2502 aCtx->CloseLocalContext();
2505 Standard_Integer anArgIter = 1;
2506 for (; anArgIter < theArgNb; ++anArgIter)
2508 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2514 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2515 if (anArgIter >= theArgNb)
2517 // display only selected objects
2518 if (aCtx->NbSelected() < 1)
2523 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2525 aDispSet.Add (aCtx->SelectedInteractive());
2530 // display only specified objects
2531 for (; anArgIter < theArgNb; ++anArgIter)
2533 TCollection_AsciiString aName = theArgVec[anArgIter];
2534 if (GetMapOfAIS().IsBound2 (aName))
2536 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2537 if (!aShape.IsNull())
2539 aCtx->Display (aShape, Standard_False);
2540 aDispSet.Add (aShape);
2546 // weed out other objects
2547 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2549 if (aDispSet.Contains (anIter.Key1()))
2554 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2555 if (aShape.IsNull())
2557 aCtx->Erase (aShape, Standard_False);
2563 //==============================================================================
2564 //function : VRemove
2565 //purpose : Removes selected or named objects.
2566 // If there is no selected or named objects,
2567 // all objects in the viewer can be removed with argument -all.
2568 // If -context is in arguments, the object is not deleted from the map of
2569 // objects (deleted only from the current context).
2570 //==============================================================================
2571 int VRemove (Draw_Interpretor& theDI,
2572 Standard_Integer theArgNb,
2573 const char** theArgVec)
2575 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2576 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2579 std::cerr << "Error: no active view!\n";
2583 Standard_Boolean isContextOnly = Standard_False;
2584 Standard_Boolean toRemoveAll = Standard_False;
2585 Standard_Boolean toPrintInfo = Standard_True;
2586 Standard_Boolean toRemoveLocal = Standard_False;
2588 Standard_Integer anArgIter = 1;
2589 for (; anArgIter < theArgNb; ++anArgIter)
2591 TCollection_AsciiString anArg = theArgVec[anArgIter];
2593 if (anArg == "-context")
2595 isContextOnly = Standard_True;
2597 else if (anArg == "-all")
2599 toRemoveAll = Standard_True;
2601 else if (anArg == "-noinfo")
2603 toPrintInfo = Standard_False;
2605 else if (anArg == "-local")
2607 toRemoveLocal = Standard_True;
2609 else if (anUpdateTool.parseRedrawMode (anArg))
2619 && anArgIter < theArgNb)
2621 std::cerr << "Error: wrong syntax!\n";
2625 if (toRemoveLocal && !aCtx->HasOpenedContext())
2627 std::cerr << "Error: local selection context is not open.\n";
2630 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2632 aCtx->CloseAllContexts (Standard_False);
2635 NCollection_List<TCollection_AsciiString> anIONameList;
2638 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2639 anIter.More(); anIter.Next())
2641 anIONameList.Append (anIter.Key2());
2644 else if (anArgIter < theArgNb) // removed objects names are in argument list
2646 for (; anArgIter < theArgNb; ++anArgIter)
2648 TCollection_AsciiString aName = theArgVec[anArgIter];
2649 if (!GetMapOfAIS().IsBound2 (aName))
2651 theDI << aName.ToCString() << " was not bound to some object.\n";
2655 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2656 if (anIO->GetContext() != aCtx)
2658 theDI << aName.ToCString() << " was not displayed in current context.\n";
2659 theDI << "Please activate view with this object displayed and try again.\n";
2663 anIONameList.Append (aName);
2667 else if (aCtx->NbSelected() > 0)
2669 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2670 anIter.More(); anIter.Next())
2672 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2673 if (!aCtx->IsSelected (anIO))
2678 anIONameList.Append (anIter.Key2());
2683 // Unbind all removed objects from the map of displayed IO.
2684 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2685 anIter.More(); anIter.Next())
2687 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2688 aCtx->Remove (anIO, Standard_False);
2691 theDI << anIter.Value().ToCString() << " was removed\n";
2695 GetMapOfAIS().UnBind2 (anIter.Value());
2699 // Close local context if it is empty
2700 TColStd_MapOfTransient aLocalIO;
2701 if (aCtx->HasOpenedContext()
2702 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2704 aCtx->CloseAllContexts (Standard_False);
2710 //==============================================================================
2712 //purpose : Erase some selected or named objects
2713 // if there is no selected or named objects, the whole viewer is erased
2714 //==============================================================================
2715 int VErase (Draw_Interpretor& theDI,
2716 Standard_Integer theArgNb,
2717 const char** theArgVec)
2719 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2720 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2721 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2724 std::cerr << "Error: no active view!\n";
2728 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2730 Standard_Integer anArgIter = 1;
2731 Standard_Boolean toEraseLocal = Standard_False;
2732 Standard_Boolean toEraseInView = Standard_False;
2733 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2734 for (; anArgIter < theArgNb; ++anArgIter)
2736 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2737 anArgCase.LowerCase();
2738 if (anUpdateTool.parseRedrawMode (anArgCase))
2742 else if (anArgCase == "-local")
2744 toEraseLocal = Standard_True;
2746 else if (anArgCase == "-view"
2747 || anArgCase == "-inview")
2749 toEraseInView = Standard_True;
2753 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2757 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2759 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2763 if (toEraseLocal && !aCtx->HasOpenedContext())
2765 std::cerr << "Error: local selection context is not open.\n";
2768 else if (!toEraseLocal && aCtx->HasOpenedContext())
2770 aCtx->CloseAllContexts (Standard_False);
2773 if (!aNamesOfEraseIO.IsEmpty())
2775 // Erase named objects
2776 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2778 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2779 if (!GetMapOfAIS().IsBound2 (aName))
2784 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2785 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2786 theDI << aName.ToCString() << " ";
2791 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2795 aCtx->Erase (anIO, Standard_False);
2800 else if (!toEraseAll && aCtx->NbSelected() > 0)
2802 // Erase selected objects
2803 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
2804 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2805 anIter.More(); anIter.Next())
2807 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2809 && aCtx->IsSelected (anIO))
2811 theDI << anIter.Key2().ToCString() << " ";
2814 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2816 else if (aHasOpenedContext)
2818 aCtx->Erase (anIO, Standard_False);
2825 aCtx->EraseSelected (Standard_False);
2830 // Erase all objects
2831 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2832 anIter.More(); anIter.Next())
2834 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2839 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2843 aCtx->Erase (anIO, Standard_False);
2852 //==============================================================================
2853 //function : VDisplayAll
2855 //purpose : Display all the objects of the Map
2856 //==============================================================================
2857 static int VDisplayAll (Draw_Interpretor& ,
2858 Standard_Integer theArgNb,
2859 const char** theArgVec)
2862 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2863 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2866 std::cerr << "Error: no active view!\n";
2870 Standard_Integer anArgIter = 1;
2871 Standard_Boolean toDisplayLocal = Standard_False;
2872 for (; anArgIter < theArgNb; ++anArgIter)
2874 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2875 anArgCase.LowerCase();
2876 if (anArgCase == "-local")
2878 toDisplayLocal = Standard_True;
2880 else if (anUpdateTool.parseRedrawMode (anArgCase))
2889 if (anArgIter < theArgNb)
2891 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2895 if (toDisplayLocal && !aCtx->HasOpenedContext())
2897 std::cerr << "Error: local selection context is not open.\n";
2900 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2902 aCtx->CloseLocalContext (Standard_False);
2905 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2906 anIter.More(); anIter.Next())
2908 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2909 aCtx->Erase (aShape, Standard_False);
2912 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2913 anIter.More(); anIter.Next())
2915 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2916 aCtx->Display (aShape, Standard_False);
2921 //! Auxiliary method to find presentation
2922 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2923 const Handle(AIS_InteractiveObject)& theIO,
2924 const Standard_Integer theMode)
2928 return Handle(PrsMgr_Presentation)();
2933 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2935 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2938 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2940 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2942 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2944 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2946 return Handle(PrsMgr_Presentation)();
2949 enum ViewerTest_BndAction
2956 //! Auxiliary method to print bounding box of presentation
2957 inline void bndPresentation (Draw_Interpretor& theDI,
2958 const Handle(PrsMgr_Presentation)& thePrs,
2959 const TCollection_AsciiString& theName,
2960 const ViewerTest_BndAction theAction)
2964 case BndAction_Hide:
2966 thePrs->Presentation()->GraphicUnHighlight();
2969 case BndAction_Show:
2971 Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
2972 aPrs->CStructure()->HighlightColor = Quantity_NOC_GRAY99;
2973 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
2976 case BndAction_Print:
2978 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2979 gp_Pnt aMin = aBox.CornerMin();
2980 gp_Pnt aMax = aBox.CornerMax();
2981 theDI << theName << "\n"
2982 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2983 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2989 //==============================================================================
2990 //function : VBounding
2992 //==============================================================================
2993 int VBounding (Draw_Interpretor& theDI,
2994 Standard_Integer theArgNb,
2995 const char** theArgVec)
2997 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2998 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3001 std::cout << "Error: no active view!\n";
3005 ViewerTest_BndAction anAction = BndAction_Show;
3006 Standard_Integer aMode = -1;
3008 Standard_Integer anArgIter = 1;
3009 for (; anArgIter < theArgNb; ++anArgIter)
3011 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3013 if (anArg == "-print")
3015 anAction = BndAction_Print;
3017 else if (anArg == "-show")
3019 anAction = BndAction_Show;
3021 else if (anArg == "-hide")
3023 anAction = BndAction_Hide;
3025 else if (anArg == "-mode")
3027 if (++anArgIter >= theArgNb)
3029 std::cout << "Error: wrong syntax at " << anArg << "\n";
3032 aMode = Draw::Atoi (theArgVec[anArgIter]);
3034 else if (!anUpdateTool.parseRedrawMode (anArg))
3040 if (anArgIter < theArgNb)
3042 // has a list of names
3043 for (; anArgIter < theArgNb; ++anArgIter)
3045 TCollection_AsciiString aName = theArgVec[anArgIter];
3046 if (!GetMapOfAIS().IsBound2 (aName))
3048 std::cout << "Error: presentation " << aName << " does not exist\n";
3052 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3053 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3056 std::cout << "Error: presentation " << aName << " does not exist\n";
3059 bndPresentation (theDI, aPrs, aName, anAction);
3062 else if (aCtx->NbSelected() > 0)
3064 // remove all currently selected objects
3065 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3067 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3068 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3071 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
3078 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3079 anIter.More(); anIter.Next())
3081 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3082 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3085 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
3092 //==============================================================================
3093 //function : VTexture
3095 //==============================================================================
3096 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
3098 TCollection_AsciiString aCommandName (theArgv[0]);
3100 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3101 if (aCommandName == "vtexture")
3105 std::cout << theArgv[0] << ": invalid arguments.\n";
3106 std::cout << "Type help for more information.\n";
3110 // look for options of vtexture command
3111 TCollection_AsciiString aParseKey;
3112 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3114 TCollection_AsciiString anArg (theArgv [anArgIt]);
3117 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3120 aParseKey.Remove (1);
3121 aParseKey.UpperCase();
3122 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3126 if (aParseKey.IsEmpty())
3131 aMapOfArgs(aParseKey)->Append (anArg);
3134 else if (aCommandName == "vtexscale"
3135 || aCommandName == "vtexorigin"
3136 || aCommandName == "vtexrepeat")
3138 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3139 // equal to -scale, -origin, -repeat options of vtexture command
3140 if (theArgsNb < 2 || theArgsNb > 4)
3142 std::cout << theArgv[0] << ": invalid arguments.\n";
3143 std::cout << "Type help for more information.\n";
3147 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
3150 anArgs->Append ("OFF");
3152 else if (theArgsNb == 4)
3154 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3155 anArgs->Append (TCollection_AsciiString (theArgv[3]));
3158 TCollection_AsciiString anArgKey;
3159 if (aCommandName == "vtexscale")
3163 else if (aCommandName == "vtexorigin")
3165 anArgKey = "ORIGIN";
3169 anArgKey = "REPEAT";
3172 aMapOfArgs.Bind (anArgKey, anArgs);
3174 else if (aCommandName == "vtexdefault")
3176 // scan for parameters of vtexdefault command
3177 // equal to -default option of vtexture command
3178 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
3181 // Check arguments for validity
3182 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3183 for (; aMapIt.More(); aMapIt.Next())
3185 const TCollection_AsciiString& aKey = aMapIt.Key();
3186 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3188 // -scale, -origin, -repeat: one argument "off", or two real values
3189 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3190 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3191 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3196 // -modulate: single argument "on" / "off"
3197 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3202 // -default: no arguments
3203 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3208 TCollection_AsciiString aLowerKey;
3211 aLowerKey.LowerCase();
3212 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3213 std::cout << "Type help for more information.\n";
3217 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3218 if (anAISContext.IsNull())
3220 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
3224 Standard_Integer aPreviousMode = 0;
3226 TCollection_AsciiString aShapeName (theArgv[1]);
3227 Handle(AIS_InteractiveObject) anIO;
3229 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3230 if (aMapOfIO.IsBound2 (aShapeName))
3232 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3237 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3241 Handle(AIS_TexturedShape) aTexturedIO;
3242 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3244 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3245 aPreviousMode = aTexturedIO->DisplayMode();
3249 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3251 if (anIO->HasTransformation())
3253 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3254 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3257 anAISContext->Remove (anIO, Standard_False);
3258 GetMapOfAIS().UnBind1 (anIO);
3259 GetMapOfAIS().UnBind2 (aShapeName);
3260 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3263 // -------------------------------------------
3264 // Turn texturing on/off - only for vtexture
3265 // -------------------------------------------
3267 if (aCommandName == "vtexture")
3269 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3271 if (aTextureArg.IsEmpty())
3273 std::cout << aCommandName << ": Texture mapping disabled.\n";
3274 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
3276 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3277 if (aPreviousMode == 3)
3279 anAISContext->RecomputePrsOnly (aTexturedIO);
3282 anAISContext->Display (aTexturedIO, Standard_True);
3285 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3287 if (aTextureArg == "?")
3289 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3291 theDi << "\n Files in current directory : \n\n";
3292 theDi.Eval ("glob -nocomplain *");
3294 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3295 aCmnd += aTextureFolder;
3298 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
3299 theDi.Eval (aCmnd.ToCString());
3304 aTexturedIO->SetTextureFileName (aTextureArg);
3309 // ------------------------------------
3310 // Process other options and commands
3311 // ------------------------------------
3313 Handle(TColStd_HSequenceOfAsciiString) aValues;
3314 if (aMapOfArgs.Find ("DEFAULT", aValues))
3316 aTexturedIO->SetTextureRepeat (Standard_False);
3317 aTexturedIO->SetTextureOrigin (Standard_False);
3318 aTexturedIO->SetTextureScale (Standard_False);
3319 aTexturedIO->EnableTextureModulate();
3323 if (aMapOfArgs.Find ("SCALE", aValues))
3325 if (aValues->Value(1) != "OFF")
3327 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3331 aTexturedIO->SetTextureScale (Standard_False);
3335 if (aMapOfArgs.Find ("ORIGIN", aValues))
3337 if (aValues->Value(1) != "OFF")
3339 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3343 aTexturedIO->SetTextureOrigin (Standard_False);
3347 if (aMapOfArgs.Find ("REPEAT", aValues))
3349 if (aValues->Value(1) != "OFF")
3351 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3355 aTexturedIO->SetTextureRepeat (Standard_False);
3359 if (aMapOfArgs.Find ("MODULATE", aValues))
3361 if (aValues->Value(1) == "ON")
3363 aTexturedIO->EnableTextureModulate();
3367 aTexturedIO->DisableTextureModulate();
3372 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3374 anAISContext->RecomputePrsOnly (aTexturedIO);
3378 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3379 anAISContext->Display (aTexturedIO, Standard_True);
3380 anAISContext->Update (aTexturedIO,Standard_True);
3386 //! Auxiliary method to parse transformation persistence flags
3387 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3388 Standard_Integer& theFlags)
3390 if (theFlagString == "pan")
3392 theFlags |= Graphic3d_TMF_PanPers;
3394 else if (theFlagString == "zoom")
3396 theFlags |= Graphic3d_TMF_ZoomPers;
3398 else if (theFlagString == "rotate")
3400 theFlags |= Graphic3d_TMF_RotatePers;
3402 else if (theFlagString == "trihedron")
3404 theFlags = Graphic3d_TMF_TriedronPers;
3406 else if (theFlagString == "full")
3408 theFlags = Graphic3d_TMF_FullPers;
3410 else if (theFlagString == "none")
3412 theFlags = Graphic3d_TMF_None;
3416 return Standard_False;
3419 return Standard_True;
3422 //==============================================================================
3423 //function : VDisplay2
3425 //purpose : Display an object from its name
3426 //==============================================================================
3427 static int VDisplay2 (Draw_Interpretor& theDI,
3428 Standard_Integer theArgNb,
3429 const char** theArgVec)
3433 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3437 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3440 ViewerTest::ViewerInit();
3441 aCtx = ViewerTest::GetAISContext();
3444 // Parse input arguments
3445 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3446 Standard_Integer isMutable = -1;
3447 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3448 Standard_Boolean toDisplayLocal = Standard_False;
3449 Standard_Boolean toReDisplay = Standard_False;
3450 Standard_Integer isSelectable = -1;
3451 Standard_Integer anObjDispMode = -2;
3452 Standard_Integer anObjHighMode = -2;
3453 Standard_Boolean toSetTrsfPers = Standard_False;
3454 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3456 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3457 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3458 Standard_Integer toDisplayInView = Standard_False;
3459 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3461 const TCollection_AsciiString aName = theArgVec[anArgIter];
3462 TCollection_AsciiString aNameCase = aName;
3463 aNameCase.LowerCase();
3464 if (anUpdateTool.parseRedrawMode (aName))
3468 else if (aNameCase == "-mutable")
3472 else if (aNameCase == "-neutral")
3474 aDispStatus = AIS_DS_Displayed;
3476 else if (aNameCase == "-immediate"
3477 || aNameCase == "-top")
3479 aZLayer = Graphic3d_ZLayerId_Top;
3481 else if (aNameCase == "-topmost")
3483 aZLayer = Graphic3d_ZLayerId_Topmost;
3485 else if (aNameCase == "-osd"
3486 || aNameCase == "-toposd"
3487 || aNameCase == "-overlay")
3489 aZLayer = Graphic3d_ZLayerId_TopOSD;
3491 else if (aNameCase == "-botosd"
3492 || aNameCase == "-underlay")
3494 aZLayer = Graphic3d_ZLayerId_BotOSD;
3496 else if (aNameCase == "-select"
3497 || aNameCase == "-selectable")
3501 else if (aNameCase == "-noselect"
3502 || aNameCase == "-noselection")
3506 else if (aNameCase == "-dispmode"
3507 || aNameCase == "-displaymode")
3509 if (++anArgIter >= theArgNb)
3511 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3515 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3517 else if (aNameCase == "-highmode"
3518 || aNameCase == "-highlightmode")
3520 if (++anArgIter >= theArgNb)
3522 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3526 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3528 else if (aNameCase == "-3d")
3530 toSetTrsfPers = Standard_True;
3531 aTrsfPersFlags = Graphic3d_TMF_None;
3533 else if (aNameCase == "-2d")
3535 toSetTrsfPers = Standard_True;
3536 aTrsfPersFlags = Graphic3d_TMF_2d;
3538 else if (aNameCase == "-trsfpers"
3539 || aNameCase == "-pers")
3541 if (++anArgIter >= theArgNb)
3543 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3547 toSetTrsfPers = Standard_True;
3548 aTrsfPersFlags = Graphic3d_TMF_None;
3549 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3550 aPersFlags.LowerCase();
3551 for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
3553 if (aParserPos == -1)
3555 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3557 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3563 TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
3564 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3566 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3569 aPersFlags = anOtherFlags;
3572 else if (aNameCase == "-trsfperspos"
3573 || aNameCase == "-perspos")
3575 if (anArgIter + 2 >= theArgNb)
3577 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3581 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3582 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3583 TCollection_AsciiString aZ = "0";
3584 if (!aX.IsIntegerValue()
3585 || !aY.IsIntegerValue())
3587 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3590 if (anArgIter + 1 < theArgNb)
3592 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3593 if (aTemp.IsIntegerValue())
3599 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
3601 else if (aNameCase == "-layer")
3603 if (++anArgIter >= theArgNb)
3605 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3609 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3610 if (!aValue.IsIntegerValue())
3612 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3616 aZLayer = aValue.IntegerValue();
3618 else if (aNameCase == "-view"
3619 || aNameCase == "-inview")
3621 toDisplayInView = Standard_True;
3623 else if (aNameCase == "-local")
3625 aDispStatus = AIS_DS_Temporary;
3626 toDisplayLocal = Standard_True;
3628 else if (aNameCase == "-redisplay")
3630 toReDisplay = Standard_True;
3634 aNamesOfDisplayIO.Append (aName);
3638 if (aNamesOfDisplayIO.IsEmpty())
3640 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3644 // Prepare context for display
3645 if (toDisplayLocal && !aCtx->HasOpenedContext())
3647 aCtx->OpenLocalContext (Standard_False);
3649 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3651 aCtx->CloseAllContexts (Standard_False);
3654 // Display interactive objects
3655 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3657 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3659 if (!GetMapOfAIS().IsBound2 (aName))
3661 // create the AIS_Shape from a name
3662 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3663 if (!aShape.IsNull())
3665 if (isMutable != -1)
3667 aShape->SetMutable (isMutable == 1);
3669 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3671 aShape->SetZLayer (aZLayer);
3675 aCtx->SetTransformPersistence (aShape, aTrsfPersFlags, aTPPosition);
3677 if (anObjDispMode != -2)
3679 aShape->SetDisplayMode (anObjDispMode);
3681 if (anObjHighMode != -2)
3683 aShape->SetHilightMode (anObjHighMode);
3685 if (!toDisplayLocal)
3686 GetMapOfAIS().Bind (aShape, aName);
3688 Standard_Integer aDispMode = aShape->HasDisplayMode()
3689 ? aShape->DisplayMode()
3690 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3691 ? aCtx->DisplayMode()
3693 Standard_Integer aSelMode = -1;
3694 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3696 aSelMode = aShape->GlobalSelectionMode();
3699 aCtx->Display (aShape, aDispMode, aSelMode,
3700 Standard_False, aShape->AcceptShapeDecomposition(),
3702 if (toDisplayInView)
3704 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3706 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3708 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3713 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3718 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3719 if (isMutable != -1)
3721 aShape->SetMutable (isMutable == 1);
3723 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3725 aShape->SetZLayer (aZLayer);
3729 aCtx->SetTransformPersistence (aShape, aTrsfPersFlags, aTPPosition);
3731 if (anObjDispMode != -2)
3733 aShape->SetDisplayMode (anObjDispMode);
3735 if (anObjHighMode != -2)
3737 aShape->SetHilightMode (anObjHighMode);
3739 Standard_Integer aDispMode = aShape->HasDisplayMode()
3740 ? aShape->DisplayMode()
3741 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3742 ? aCtx->DisplayMode()
3744 Standard_Integer aSelMode = -1;
3745 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3747 aSelMode = aShape->GlobalSelectionMode();
3750 if (aShape->Type() == AIS_KOI_Datum)
3752 aCtx->Display (aShape, Standard_False);
3756 theDI << "Display " << aName.ToCString() << "\n";
3758 // update the Shape in the AIS_Shape
3759 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3760 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3761 if (!aShapePrs.IsNull())
3763 if (!aShapePrs->Shape().IsEqual (aNewShape))
3765 toReDisplay = Standard_True;
3767 aShapePrs->Set (aNewShape);
3771 aCtx->Redisplay (aShape, Standard_False);
3776 aCtx->Erase (aShape);
3778 aCtx->Display (aShape, aDispMode, aSelMode,
3779 Standard_False, aShape->AcceptShapeDecomposition(),
3781 if (toDisplayInView)
3783 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3791 //===============================================================================================
3792 //function : VUpdate
3794 //===============================================================================================
3795 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3797 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3798 if (aContextAIS.IsNull())
3800 std::cout << theArgVec[0] << "AIS context is not available.\n";
3806 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3810 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3812 AIS_ListOfInteractive aListOfIO;
3814 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3816 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3818 Handle(AIS_InteractiveObject) anAISObj;
3819 if (anAISMap.IsBound2 (aName))
3821 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3824 if (anAISObj.IsNull())
3826 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3830 aListOfIO.Append (anAISObj);
3833 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3834 for (; anIOIt.More(); anIOIt.Next())
3836 aContextAIS->Update (anIOIt.Value(), Standard_False);
3839 aContextAIS->UpdateCurrentViewer();
3844 //==============================================================================
3846 //purpose : Test the annimation of an object along a
3847 // predifined trajectory
3848 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3849 //==============================================================================
3851 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3854 if (TheAISContext()->HasOpenedContext())
3855 TheAISContext()->CloseLocalContext();
3857 Standard_Real Step=4*M_PI/180;
3858 Standard_Real Angle=0;
3860 Handle(AIS_InteractiveObject) aIO;
3861 if (GetMapOfAIS().IsBound2(argv[1]))
3862 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3866 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3870 if (Draw::Atoi(argv[3])==1 ) {
3871 di<<" Primitives sensibles OFF\n";
3872 TheAISContext()->Deactivate(aIO);
3875 di<<" Primitives sensibles ON\n";
3877 // Movement par transformation
3878 if(Draw::Atoi(argv[2]) ==1) {
3879 di<<" Calcul par Transformation\n";
3880 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3884 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3885 TheAISContext()->SetLocation(aShape,myTransfo);
3886 TheAISContext() ->UpdateCurrentViewer();
3891 di<<" Calcul par Locations\n";
3892 gp_Trsf myAngleTrsf;
3893 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3894 TopLoc_Location myDeltaAngle (myAngleTrsf);
3895 TopLoc_Location myTrueLoc;
3897 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3900 myTrueLoc=myTrueLoc*myDeltaAngle;
3901 TheAISContext()->SetLocation(aShape,myTrueLoc );
3902 TheAISContext() ->UpdateCurrentViewer();
3905 if (Draw::Atoi(argv[3])==1 ){
3906 // On reactive la selection des primitives sensibles
3907 TheAISContext()->Activate(aIO,0);
3909 a3DView() -> Redraw();
3911 di<<" Temps ecoule \n";
3917 //==================================================================================
3918 // Function : VAnimation
3919 //==================================================================================
3920 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3922 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile\n";
3926 Standard_Real thread = 4;
3927 Standard_Real angleA=0;
3928 Standard_Real angleB;
3930 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3933 TopoDS_Shape CrankArm;
3934 TopoDS_Shape CylinderHead;
3935 TopoDS_Shape Propeller;
3936 TopoDS_Shape EngineBlock;
3938 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3939 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3940 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3941 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3942 BRepTools::Read(CrankArm,argv[1],B);
3943 BRepTools::Read(CylinderHead,argv[2],B);
3944 BRepTools::Read(Propeller,argv[3],B);
3945 BRepTools::Read(EngineBlock,argv[4],B);
3947 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure.\n";}
3953 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3954 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3955 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3956 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3958 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3959 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3960 GetMapOfAIS().Bind(myAisCrankArm,"c");
3961 GetMapOfAIS().Bind(myAisPropeller,"d");
3963 myAisCylinderHead->SetMutable (Standard_True);
3964 myAisEngineBlock ->SetMutable (Standard_True);
3965 myAisCrankArm ->SetMutable (Standard_True);
3966 myAisPropeller ->SetMutable (Standard_True);
3968 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3969 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3970 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3972 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3973 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3974 TheAISContext()->Display (myAisCrankArm, Standard_False);
3975 TheAISContext()->Display (myAisPropeller, Standard_False);
3977 TheAISContext()->Deactivate(myAisCylinderHead);
3978 TheAISContext()->Deactivate(myAisEngineBlock );
3979 TheAISContext()->Deactivate(myAisCrankArm );
3980 TheAISContext()->Deactivate(myAisPropeller );
3982 // Boucle de mouvement
3983 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3985 angleA = thread*myAngle*M_PI/180;
3986 X = Sin(angleA)*3/8;
3987 angleB = atan(X / Sqrt(-X * X + 1));
3988 Standard_Real decal(25*0.6);
3991 //Build a transformation on the display
3992 gp_Trsf aPropellerTrsf;
3993 aPropellerTrsf.SetRotation(Ax1,angleA);
3994 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3996 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));
3997 gp_Trsf aCrankArmTrsf;
3998 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3999 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
4001 TheAISContext()->UpdateCurrentViewer();
4004 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
4005 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
4007 myAisCrankArm ->ResetTransformation();
4008 myAisPropeller->ResetTransformation();
4010 myAisCrankArm -> Set(myNewCrankArm );
4011 myAisPropeller -> Set(myNewPropeller);
4013 TheAISContext()->Activate(myAisCylinderHead,0);
4014 TheAISContext()->Activate(myAisEngineBlock,0 );
4015 TheAISContext()->Activate(myAisCrankArm ,0 );
4016 TheAISContext()->Activate(myAisPropeller ,0 );
4022 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
4023 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
4025 TheAISContext()->UpdateCurrentViewer();
4026 a3DView()->Redraw();
4035 //==============================================================================
4036 //function : VShading
4037 //purpose : Sharpen or roughten the quality of the shading
4038 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4039 //==============================================================================
4040 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4042 Standard_Real myDevCoef;
4043 Handle(AIS_InteractiveObject) TheAisIO;
4046 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4048 if (TheAISContext()->HasOpenedContext())
4049 TheAISContext()->CloseLocalContext();
4054 myDevCoef =Draw::Atof(argv[2]);
4057 TCollection_AsciiString name=argv[1];
4058 if (GetMapOfAIS().IsBound2(name ))
4059 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4060 if (TheAisIO.IsNull())
4061 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4064 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4066 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4068 TheAISContext()->Redisplay(TheAisIO);
4071 //==============================================================================
4072 //function : HaveMode
4073 //use : VActivatedModes
4074 //==============================================================================
4075 #include <TColStd_ListIteratorOfListOfInteger.hxx>
4077 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
4079 TColStd_ListOfInteger List;
4080 TheAISContext()->ActivatedModes (TheAisIO,List);
4081 TColStd_ListIteratorOfListOfInteger it;
4082 Standard_Boolean Found=Standard_False;
4083 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4084 if (it.Value()==mode ) Found=Standard_True;
4091 //==============================================================================
4092 //function : VActivatedMode
4094 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
4095 // (edges,vertex...)qui lui est propre et le mode de selection standard.
4096 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4097 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4098 // qu'un nom et qu'un mode.
4099 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4100 //==============================================================================
4101 #include <AIS_ListIteratorOfListOfInteractive.hxx>
4103 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4106 Standard_Boolean ThereIsName = Standard_False ;
4108 if(!a3DView().IsNull()){
4110 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
4111 // verification des arguments
4113 if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
4114 ThereIsName = (argc == 3);
4118 if (argc>1) {di<<" Syntaxe error\n";return 1;}
4120 di<<" R.A.Z de tous les modes de selecion\n";
4121 di<<" Fermeture du Context local\n";
4122 if (TheAISContext()->HasOpenedContext())
4123 TheAISContext()->CloseLocalContext();
4127 // IL n'y a aps de nom de shape passe en argument
4128 if (HaveToSet && !ThereIsName){
4129 Standard_Integer aMode=Draw::Atoi(argv [1]);
4131 const char *cmode="???";
4133 case 0: cmode = "Shape"; break;
4134 case 1: cmode = "Vertex"; break;
4135 case 2: cmode = "Edge"; break;
4136 case 3: cmode = "Wire"; break;
4137 case 4: cmode = "Face"; break;
4138 case 5: cmode = "Shell"; break;
4139 case 6: cmode = "Solid"; break;
4140 case 7: cmode = "Compound"; break;
4143 if( !TheAISContext()->HasOpenedContext() ) {
4144 // il n'y a pas de Context local d'ouvert
4145 // on en ouvre un et on charge toutes les shapes displayees
4146 // on load tous les objets displayees et on Activate les objets de la liste
4147 AIS_ListOfInteractive ListOfIO;
4148 // on sauve dans une AISListOfInteractive tous les objets currents
4149 if (TheAISContext()->NbSelected()>0 ){
4150 TheAISContext()->UnhilightSelected(Standard_False);
4152 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4153 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
4157 TheAISContext()->OpenLocalContext(Standard_False);
4158 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4161 Handle(AIS_InteractiveObject) aIO =
4162 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4164 TheAISContext()->Load(aIO,0,Standard_False);
4167 // traitement des objets qui etaient currents dans le Contexte global
4168 if (!ListOfIO.IsEmpty() ) {
4169 // il y avait des objets currents
4170 AIS_ListIteratorOfListOfInteractive iter;
4171 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4172 Handle(AIS_InteractiveObject) aIO=iter.Value();
4173 TheAISContext()->Activate(aIO,aMode);
4174 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4178 // On applique le mode a tous les objets displayes
4179 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4180 it2 (GetMapOfAIS());
4182 Handle(AIS_InteractiveObject) aIO =
4183 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4184 if (!aIO.IsNull()) {
4185 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4186 TheAISContext()->Activate(aIO,aMode);
4195 // un Context local est deja ouvert
4196 // Traitement des objets du Context local
4197 if (TheAISContext()->NbSelected()>0 ){
4198 TheAISContext()->UnhilightSelected(Standard_False);
4199 // il y a des objets selected,on les parcourt
4200 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4201 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
4204 if (HaveMode(aIO,aMode) ) {
4205 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4206 TheAISContext()->Deactivate(aIO,aMode);
4209 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4210 TheAISContext()->Activate(aIO,aMode);
4216 // il n'y a pas d'objets selected
4217 // tous les objets diplayes sont traites
4218 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4221 Handle(AIS_InteractiveObject) aIO =
4222 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4223 if (!aIO.IsNull()) {
4224 if (HaveMode(aIO,aMode) ) {
4225 di<<" Mode: "<<cmode<<" OFF pour "
4226 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4227 TheAISContext()->Deactivate(aIO,aMode);
4230 di<<" Mode: "<<cmode<<" ON pour"
4231 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4232 TheAISContext()->Activate(aIO,aMode);
4240 else if (HaveToSet && ThereIsName){
4241 Standard_Integer aMode=Draw::Atoi(argv [2]);
4242 Handle(AIS_InteractiveObject) aIO =
4243 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4245 if (!aIO.IsNull()) {
4246 const char *cmode="???";
4249 case 0: cmode = "Shape"; break;
4250 case 1: cmode = "Vertex"; break;
4251 case 2: cmode = "Edge"; break;
4252 case 3: cmode = "Wire"; break;
4253 case 4: cmode = "Face"; break;
4254 case 5: cmode = "Shell"; break;
4255 case 6: cmode = "Solid"; break;
4256 case 7: cmode = "Compound"; break;
4259 if( !TheAISContext()->HasOpenedContext() ) {
4260 TheAISContext()->OpenLocalContext(Standard_False);
4261 // On charge tous les objets de la map
4262 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4264 Handle(AIS_InteractiveObject) aShape=
4265 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4266 if (!aShape.IsNull())
4267 TheAISContext()->Load(aShape,0,Standard_False);
4270 TheAISContext()->Activate(aIO,aMode);
4271 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4275 // un Context local est deja ouvert
4276 if (HaveMode(aIO,aMode) ) {
4277 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4278 TheAISContext()->Deactivate(aIO,aMode);
4281 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4282 TheAISContext()->Activate(aIO,aMode);
4291 //! Auxiliary method to print Interactive Object information
4292 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4293 const Handle(Standard_Transient)& theObject,
4294 Draw_Interpretor& theDI)
4296 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4299 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4303 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4304 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4305 << (theDetected.Contains (anObj) ? " Detected" : " ")
4307 if (anObj->Type() == AIS_KOI_Datum)
4310 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4311 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4312 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4313 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4314 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4315 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4316 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4319 else if (anObj->Type() == AIS_KOI_Shape
4320 && anObj->Signature() == 0)
4322 theDI << " AIS_Shape";
4324 else if (anObj->Type() == AIS_KOI_Relation)
4326 // AIS_Dimention and AIS_Relation
4327 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4328 switch (aRelation->KindOfDimension())
4330 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4331 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4332 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4333 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4334 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4335 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4336 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4337 default: theDI << " UNKNOWN dimension"; break;
4342 theDI << " UserPrs";
4344 theDI << " (" << theObject->DynamicType()->Name() << ")";
4347 //! Print information about locally selected sub-shapes
4348 template <typename T>
4349 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4351 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4352 TCollection_AsciiString aPrevName;
4353 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4355 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4356 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4357 if (aShapeIO.IsNull() || anOwner.IsNull())
4361 if (anOwner == aShapeIO->GlobalSelOwner())
4364 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4365 if (aSubShape.IsNull()
4366 || aShapeIO.IsNull()
4367 || !GetMapOfAIS().IsBound1 (aShapeIO))
4372 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4373 TopTools_MapOfShape aFilter;
4374 Standard_Integer aNumber = 0;
4375 const TopoDS_Shape aShape = aShapeIO->Shape();
4376 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4377 anIter.More(); anIter.Next())
4379 if (!aFilter.Add (anIter.Current()))
4381 continue; // filter duplicates
4385 if (!anIter.Current().IsSame (aSubShape))
4390 Standard_CString aShapeName = NULL;
4391 switch (aSubShape.ShapeType())
4393 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4394 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4395 case TopAbs_SOLID: aShapeName = " Solid"; break;
4396 case TopAbs_SHELL: aShapeName = " Shell"; break;
4397 case TopAbs_FACE: aShapeName = " Face"; break;
4398 case TopAbs_WIRE: aShapeName = " Wire"; break;
4399 case TopAbs_EDGE: aShapeName = " Edge"; break;
4400 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4402 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4405 if (aParentName != aPrevName)
4407 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4408 aPrevName = aParentName;
4410 theDI << " " << aShapeName << " #" << aNumber << "\n";
4416 //==============================================================================
4419 //==============================================================================
4420 static Standard_Integer VState (Draw_Interpretor& theDI,
4421 Standard_Integer theArgNb,
4422 Standard_CString* theArgVec)
4424 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4427 std::cerr << "Error: No opened viewer!\n";
4431 Standard_Boolean toPrintEntities = Standard_False;
4432 Standard_Boolean toCheckSelected = Standard_False;
4434 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4436 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4437 anOption.LowerCase();
4438 if (anOption == "-detectedentities"
4439 || anOption == "-entities")
4441 toPrintEntities = Standard_True;
4443 else if (anOption == "-hasselected")
4445 toCheckSelected = Standard_True;
4449 if (toCheckSelected)
4451 aCtx->InitSelected();
4452 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4453 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4458 if (toPrintEntities)
4460 theDI << "Detected entities:\n";
4461 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4462 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4463 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4465 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4466 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4467 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4468 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4469 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4470 aName.LeftJustify (20, ' ');
4471 char anInfoStr[512];
4473 " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
4476 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4477 theDI << " " << aName
4479 << " (" << anEntity->DynamicType()->Name() << ")"
4482 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4483 if (!aBRepOwner.IsNull())
4485 theDI << " Detected Shape: "
4486 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4490 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4491 if (!aWire.IsNull())
4493 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4494 theDI << " Detected Child: "
4495 << aSen->DynamicType()->Name()
4499 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4500 if (!aPrimArr.IsNull())
4502 theDI << " Detected Element: "
4503 << aPrimArr->LastDetectedElement()
4510 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4511 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4513 aDetected.Add (aCtx->DetectedCurrentObject());
4516 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4520 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4522 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4523 if (!GetMapOfAIS().IsBound2 (anObjName))
4525 theDI << anObjName << " doesn't exist!\n";
4529 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4530 TCollection_AsciiString aName = anObjName;
4531 aName.LeftJustify (20, ' ');
4532 theDI << " " << aName << " ";
4533 objInfo (aDetected, anObjTrans, theDI);
4539 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4541 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4542 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4544 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4545 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4546 // handle whole object selection
4547 if (anOwner == anObj->GlobalSelOwner())
4549 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4550 aName.LeftJustify (20, ' ');
4551 theDI << aName << " ";
4552 objInfo (aDetected, anObj, theDI);
4557 // process selected sub-shapes
4558 printLocalSelectionInfo (aCtx, theDI);
4563 theDI << "Neutral-point state:\n";
4564 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4565 anObjIter.More(); anObjIter.Next())
4567 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4573 TCollection_AsciiString aName = anObjIter.Key2();
4574 aName.LeftJustify (20, ' ');
4575 theDI << " " << aName << " ";
4576 objInfo (aDetected, anObj, theDI);
4579 printLocalSelectionInfo (aCtx, theDI);
4580 if (aCtx->HasOpenedContext())
4581 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
4585 //=======================================================================
4586 //function : PickObjects
4588 //=======================================================================
4589 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4590 const AIS_KindOfInteractive TheType,
4591 const Standard_Integer TheSignature,
4592 const Standard_Integer MaxPick)
4594 Handle(AIS_InteractiveObject) IO;
4595 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4597 // step 1: prepare the data
4599 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4600 TheAISContext()->AddFilter(F1);
4603 // step 2 : wait for the selection...
4604 Standard_Integer NbPickGood (0),NbToReach(arr->Length());
4605 Standard_Integer NbPickFail(0);
4606 Standard_Integer argccc = 5;
4607 const char *bufff[] = { "A", "B", "C","D", "E" };
4608 const char **argvvv = (const char **) bufff;
4611 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4612 while(ViewerMainLoop(argccc,argvvv)){}
4613 Standard_Integer NbStored = TheAISContext()->NbSelected();
4614 if(NbStored != NbPickGood)
4615 NbPickGood= NbStored;
4618 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4621 // step3 get result.
4623 if (NbPickFail >= NbToReach)
4624 return Standard_False;
4626 Standard_Integer i(0);
4627 for(TheAISContext()->InitSelected();
4628 TheAISContext()->MoreSelected();
4629 TheAISContext()->NextSelected()){
4631 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4632 arr->SetValue(i,IO2);
4637 TheAISContext()->CloseLocalContext(curindex);
4639 return Standard_True;
4643 //=======================================================================
4644 //function : PickObject
4646 //=======================================================================
4647 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4648 const Standard_Integer TheSignature,
4649 const Standard_Integer MaxPick)
4651 Handle(AIS_InteractiveObject) IO;
4652 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4654 // step 1: prepare the data
4657 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4658 TheAISContext()->AddFilter(F1);
4661 // step 2 : wait for the selection...
4662 Standard_Boolean IsGood (Standard_False);
4663 Standard_Integer NbPick(0);
4664 Standard_Integer argccc = 5;
4665 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4666 const char **argvvv = (const char **) bufff;
4669 while(!IsGood && NbPick<= MaxPick){
4670 while(ViewerMainLoop(argccc,argvvv)){}
4671 IsGood = (TheAISContext()->NbSelected()>0) ;
4673 cout<<"Nb Pick :"<<NbPick<<endl;
4677 // step3 get result.
4679 TheAISContext()->InitSelected();
4680 IO = TheAISContext()->SelectedInteractive();
4684 TheAISContext()->CloseLocalContext(curindex);
4688 //=======================================================================
4689 //function : PickShape
4690 //purpose : First Activate the rightmode + Put Filters to be able to
4691 // pick objets that are of type <TheType>...
4692 //=======================================================================
4694 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4695 const Standard_Integer MaxPick)
4698 // step 1: prepare the data
4700 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4701 TopoDS_Shape result;
4703 if(TheType==TopAbs_SHAPE){
4704 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4705 TheAISContext()->AddFilter(F1);
4708 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4709 TheAISContext()->AddFilter(TF);
4710 TheAISContext()->ActivateStandardMode(TheType);
4715 // step 2 : wait for the selection...
4716 Standard_Boolean NoShape (Standard_True);
4717 Standard_Integer NbPick(0);
4718 Standard_Integer argccc = 5;
4719 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4720 const char **argvvv = (const char **) bufff;
4723 while(NoShape && NbPick<= MaxPick){
4724 while(ViewerMainLoop(argccc,argvvv)){}
4725 NoShape = (TheAISContext()->NbSelected()==0) ;
4727 cout<<"Nb Pick :"<<NbPick<<endl;
4730 // step3 get result.
4734 TheAISContext()->InitSelected();
4735 if(TheAISContext()->HasSelectedShape())
4736 result = TheAISContext()->SelectedShape();
4738 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4739 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
4744 TheAISContext()->CloseLocalContext(curindex);
4750 //=======================================================================
4751 //function : PickShapes
4753 //=======================================================================
4754 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4755 Handle(TopTools_HArray1OfShape)& thearr,
4756 const Standard_Integer MaxPick)
4759 Standard_Integer Taille = thearr->Length();
4761 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4763 // step 1: prepare the data
4764 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4765 if(TheType==TopAbs_SHAPE){
4766 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4767 TheAISContext()->AddFilter(F1);
4770 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4771 TheAISContext()->AddFilter(TF);
4772 TheAISContext()->ActivateStandardMode(TheType);
4776 // step 2 : wait for the selection...
4777 Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
4778 Standard_Integer NbPickFail(0);
4779 Standard_Integer argccc = 5;
4780 const char *bufff[] = { "A", "B", "C","D", "E" };
4781 const char **argvvv = (const char **) bufff;
4784 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4785 while(ViewerMainLoop(argccc,argvvv)){}
4786 Standard_Integer NbStored = TheAISContext()->NbSelected();
4787 if (NbStored != NbPickGood)
4788 NbPickGood= NbStored;
4791 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4794 // step3 get result.
4796 if (NbPickFail >= NbToReach)
4797 return Standard_False;
4799 Standard_Integer i(0);
4800 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4802 if(TheAISContext()->HasSelectedShape())
4803 thearr->SetValue(i,TheAISContext()->SelectedShape());
4805 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4806 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
4810 TheAISContext()->CloseLocalContext(curindex);
4811 return Standard_True;
4815 //=======================================================================
4816 //function : VPickShape
4818 //=======================================================================
4819 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4821 TopoDS_Shape PickSh;
4822 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4825 theType = TopAbs_SHAPE;
4827 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4828 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4829 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4830 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4831 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4832 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4833 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4836 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4837 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4839 TCollection_AsciiString name;
4842 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4844 PickSh = ViewerTest::PickShape(theType);
4853 if(!PickSh.IsNull()){
4854 nbOfSub[Standard_Integer(theType)]++;
4856 name += nameType[Standard_Integer(theType)];
4857 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4862 // si on avait une petite methode pour voir si la shape
4863 // est deja dans la Double map, ca eviterait de creer....
4864 DBRep::Set(name.ToCString(),PickSh);
4866 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4867 GetMapOfAIS().Bind(newsh, name);
4868 TheAISContext()->Display(newsh);
4869 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4872 // Plusieurs objets a picker, vite vite vite....
4875 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4876 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4877 if(ViewerTest::PickShapes(theType,arr)){
4878 for(Standard_Integer i=1;i<=NbToPick;i++){
4879 PickSh = arr->Value(i);
4880 if(!PickSh.IsNull()){
4882 nbOfSub[Standard_Integer(theType)]++;
4885 name += nameType[Standard_Integer(theType)];
4886 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4894 DBRep::Set(name.ToCString(),PickSh);
4895 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4896 GetMapOfAIS().Bind(newsh, name);
4897 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4898 TheAISContext()->Display(newsh);
4906 //=======================================================================
4907 //function : VPickSelected
4909 //=======================================================================
4910 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4912 static Standard_Integer aCount = 0;
4913 TCollection_AsciiString aName = "PickedShape_";
4921 aName = aName + aCount++ + "_";
4924 Standard_Integer anIdx = 0;
4925 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4927 TopoDS_Shape aShape;
4928 if (TheAISContext()->HasSelectedShape())
4930 aShape = TheAISContext()->SelectedShape();
4934 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4935 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
4938 TCollection_AsciiString aCurrentName = aName;
4941 aCurrentName += anIdx;
4944 DBRep::Set ((aCurrentName).ToCString(), aShape);
4946 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4947 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4948 TheAISContext()->Display (aNewShape);
4954 //=======================================================================
4955 //function : list of known objects
4957 //=======================================================================
4958 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4960 // 1234567890 12345678901234567 123456789
4961 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4962 TCollection_AsciiString BlankLine(64,'_');
4963 Standard_Integer i ;
4965 di<<"/n"<<BlankLine.ToCString()<<"\n";
4968 Colum[i].Center(20,' ');
4970 di<<"|"<<Colum[i].ToCString();
4973 di<<BlankLine.ToCString()<<"\n";
4975 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4976 const char ** names = GetTypeNames();
4978 TCollection_AsciiString curstring;
4979 TCollection_AsciiString curcolum[3];
4982 // les objets de type Datum..
4983 curcolum[1]+="Datum";
4985 curcolum[0].Clear();
4986 curcolum[0] += names[i];
4988 curcolum[2].Clear();
4989 curcolum[2]+=TCollection_AsciiString(i+1);
4991 for(Standard_Integer j =0;j<=2;j++){
4992 curcolum[j].Center(20,' ');
4993 di<<"|"<<curcolum[j].ToCString();
4997 di<<BlankLine.ToCString()<<"\n";
4999 // les objets de type shape
5000 curcolum[1].Clear();
5001 curcolum[1]+="Shape";
5002 curcolum[1].Center(20,' ');
5005 curcolum[0].Clear();
5006 curcolum[0] += names[7+i];
5007 curcolum[2].Clear();
5008 curcolum[2]+=TCollection_AsciiString(i);
5010 for(Standard_Integer j =0;j<=2;j++){
5011 curcolum[j].Center(20,' ');
5012 di<<"|"<<curcolum[j].ToCString();
5016 di<<BlankLine.ToCString()<<"\n";
5017 // les IO de type objet...
5018 curcolum[1].Clear();
5019 curcolum[1]+="Object";
5020 curcolum[1].Center(20,' ');
5022 curcolum[0].Clear();
5023 curcolum[0] += names[10+i];
5024 curcolum[2].Clear();
5025 curcolum[2]+=TCollection_AsciiString(i);
5027 for(Standard_Integer j =0;j<=2;j++){
5028 curcolum[j].Center(20,' ');
5029 di<<"|"<<curcolum[j].ToCString();
5033 di<<BlankLine.ToCString()<<"\n";
5034 // les contraintes et dimensions.
5035 // pour l'instant on separe juste contraintes et dimensions...
5036 // plus tard, on detaillera toutes les sortes...
5037 curcolum[1].Clear();
5038 curcolum[1]+="Relation";
5039 curcolum[1].Center(20,' ');
5041 curcolum[0].Clear();
5042 curcolum[0] += names[12+i];
5043 curcolum[2].Clear();
5044 curcolum[2]+=TCollection_AsciiString(i);
5046 for(Standard_Integer j =0;j<=2;j++){
5047 curcolum[j].Center(20,' ');
5048 di<<"|"<<curcolum[j].ToCString();
5052 di<<BlankLine.ToCString()<<"\n";
5059 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5061 if(argc!=2) return 1;
5063 AIS_KindOfInteractive TheType;
5064 Standard_Integer TheSign(-1);
5065 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5068 AIS_ListOfInteractive LIO;
5070 // en attendant l'amelioration ais pour les dimensions...
5072 Standard_Integer dimension_status(-1);
5073 if(TheType==AIS_KOI_Relation){
5074 dimension_status = TheSign ==1 ? 1 : 0;
5078 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5079 Handle(AIS_InteractiveObject) curio;
5080 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5083 if(dimension_status == -1)
5084 TheAISContext()->Erase(curio,Standard_False);
5086 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5087 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5088 (dimension_status==1 && KOD != AIS_KOD_NONE))
5089 TheAISContext()->Erase(curio,Standard_False);
5092 TheAISContext()->UpdateCurrentViewer();
5095 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5097 if(argc!=2) return 1;
5099 AIS_KindOfInteractive TheType;
5100 Standard_Integer TheSign(-1);
5101 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5103 // en attendant l'amelioration ais pour les dimensions...
5105 Standard_Integer dimension_status(-1);
5106 if(TheType==AIS_KOI_Relation){
5107 dimension_status = TheSign ==1 ? 1 : 0;
5111 AIS_ListOfInteractive LIO;
5112 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5113 Handle(AIS_InteractiveObject) curio;
5114 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5116 if(dimension_status == -1)
5117 TheAISContext()->Display(curio,Standard_False);
5119 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5120 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5121 (dimension_status==1 && KOD != AIS_KOD_NONE))
5122 TheAISContext()->Display(curio,Standard_False);
5127 TheAISContext()->UpdateCurrentViewer();
5131 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5134 BRep_Builder builder;
5136 BRepTools::Read(shape, s, builder);
5137 DBRep::Set(a[1], shape);
5138 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5139 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5144 //===============================================================================================
5147 //===============================================================================================
5148 static int VBsdf (Draw_Interpretor& theDi,
5149 Standard_Integer theArgsNb,
5150 const char** theArgVec)
5152 Handle(V3d_View) aView = ViewerTest::CurrentView();
5153 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5155 || aViewer.IsNull())
5157 std::cerr << "No active viewer!\n";
5161 ViewerTest_CmdParser aCmd;
5163 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5164 aCmd.AddOption ("print|echo|p", "Print BSDF");
5166 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5167 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5168 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5169 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5170 aCmd.AddOption ("le", "Self-emitted radiance");
5172 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5174 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
5175 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5176 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5178 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5180 aCmd.Parse (theArgsNb, theArgVec);
5182 if (aCmd.HasOption ("help"))
5184 theDi.PrintHelp (theArgVec[0]);
5188 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5191 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5192 if (!aMap.IsBound2 (aName) )
5194 std::cerr << "Use 'vdisplay' before\n";
5198 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5199 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5200 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5202 if (aCmd.HasOption ("print"))
5204 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5207 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5208 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5209 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5210 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5211 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5214 if (aFresnel.x() >= 0.f)
5217 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5219 else if (aFresnel.x() >= -1.5f)
5222 << "|Constant| " << aFresnel.z() << "\n";
5224 else if (aFresnel.x() >= -2.5f)
5227 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5232 << "|Dielectric| " << aFresnel.y() << "\n";
5237 << "Roughness: " << aBSDF.Roughness << "\n"
5238 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
5239 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5240 << aBSDF.AbsorptionColor.g() << ", "
5241 << aBSDF.AbsorptionColor.b() << "\n";
5246 if (aCmd.HasOption ("roughness", 1, Standard_True))
5248 aCmd.Arg ("roughness", 0);
5249 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5252 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5254 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5257 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5259 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5262 if (aCmd.HasOption ("kd", 3))
5264 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5266 else if (aCmd.HasOption ("kd", 1, Standard_True))
5268 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5271 if (aCmd.HasOption ("kr", 3))
5273 aBSDF.Kr = aCmd.ArgVec3f ("kr");
5275 else if (aCmd.HasOption ("kr", 1, Standard_True))
5277 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5280 if (aCmd.HasOption ("kt", 3))
5282 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5284 else if (aCmd.HasOption ("kt", 1, Standard_True))
5286 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5289 if (aCmd.HasOption ("ks", 3))
5291 aBSDF.Ks = aCmd.ArgVec3f ("ks");
5293 else if (aCmd.HasOption ("ks", 1, Standard_True))
5295 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5298 if (aCmd.HasOption ("le", 3))
5300 aBSDF.Le = aCmd.ArgVec3f ("le");
5302 else if (aCmd.HasOption ("le", 1, Standard_True))
5304 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5307 const std::string aFresnelErrorMessage =
5308 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5310 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5312 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5313 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5315 if (aFresnelType == "schlick")
5317 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5318 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5319 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5320 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5324 std::cout << aFresnelErrorMessage;
5327 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5329 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5330 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5332 if (aFresnelType == "conductor")
5334 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5335 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5336 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5340 std::cout << aFresnelErrorMessage;
5343 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5345 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5346 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5348 if (aFresnelType == "dielectric")
5350 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5351 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5353 else if (aFresnelType == "constant")
5355 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5356 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5360 std::cout << aFresnelErrorMessage;
5364 if (aCmd.HasOption ("normalize"))
5369 aMaterial.SetBSDF (aBSDF);
5370 anIObj->SetMaterial (aMaterial);
5377 //==============================================================================
5378 //function : VLoadSelection
5379 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5380 //==============================================================================
5381 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5382 Standard_Integer theArgNb,
5383 const char** theArgVec)
5387 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5391 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5394 ViewerTest::ViewerInit();
5395 aCtx = ViewerTest::GetAISContext();
5398 // Parse input arguments
5399 TColStd_SequenceOfAsciiString aNamesOfIO;
5400 Standard_Boolean isLocal = Standard_False;
5401 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5403 const TCollection_AsciiString aName = theArgVec[anArgIter];
5404 TCollection_AsciiString aNameCase = aName;
5405 aNameCase.LowerCase();
5406 if (aNameCase == "-local")
5408 isLocal = Standard_True;
5412 aNamesOfIO.Append (aName);
5416 if (aNamesOfIO.IsEmpty())
5418 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5423 if (isLocal && !aCtx->HasOpenedContext())
5425 aCtx->OpenLocalContext (Standard_False);
5427 else if (!isLocal && aCtx->HasOpenedContext())
5429 aCtx->CloseAllContexts (Standard_False);
5432 // Load selection of interactive objects
5433 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5435 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5437 Handle(AIS_InteractiveObject) aShape;
5438 if (GetMapOfAIS().IsBound2 (aName))
5439 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5441 aShape = GetAISShapeFromName (aName.ToCString());
5443 if (!aShape.IsNull())
5445 if (!GetMapOfAIS().IsBound2 (aName))
5447 GetMapOfAIS().Bind (aShape, aName);
5450 aCtx->Load (aShape, -1, Standard_False);
5451 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5458 //==============================================================================
5459 //function : VAutoActivateSelection
5460 //purpose : Activates or deactivates auto computation of selection
5461 //==============================================================================
5462 static int VAutoActivateSelection (Draw_Interpretor& theDi,
5463 Standard_Integer theArgNb,
5464 const char** theArgVec)
5469 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5473 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5476 ViewerTest::ViewerInit();
5477 aCtx = ViewerTest::GetAISContext();
5482 TCollection_AsciiString aSelActivationString;
5483 if (aCtx->GetAutoActivateSelection())
5485 aSelActivationString.Copy ("ON");
5489 aSelActivationString.Copy ("OFF");
5492 theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
5496 Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]) != 0;
5497 aCtx->SetAutoActivateSelection (toActivate);
5503 //==============================================================================
5504 //function : ViewerTest::Commands
5505 //purpose : Add all the viewer command in the Draw_Interpretor
5506 //==============================================================================
5508 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5510 ViewerTest::ViewerCommands(theCommands);
5511 ViewerTest::RelationCommands(theCommands);
5512 ViewerTest::ObjectCommands(theCommands);
5513 ViewerTest::FilletCommands(theCommands);
5514 ViewerTest::OpenGlCommands(theCommands);
5516 const char *group = "AIS_Display";
5519 theCommands.Add("visos",
5520 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5521 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5522 __FILE__, visos, group);
5524 theCommands.Add("vdisplay",
5525 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5526 "\n\t\t: [-trsfPers {pan|zoom|rotate|trihedron|full|none}=none] [-trsfPersPos X Y [Z]] [-3d|-2d]"
5527 "\n\t\t: [-dispMode mode] [-highMode mode]"
5528 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5529 "\n\t\t: [-redisplay]"
5530 "\n\t\t: name1 [name2] ... [name n]"
5531 "\n\t\t: Displays named objects."
5532 "\n\t\t: Option -local enables displaying of objects in local"
5533 "\n\t\t: selection context. Local selection context will be opened"
5534 "\n\t\t: if there is not any."
5535 "\n\t\t: -noupdate suppresses viewer redraw call."
5536 "\n\t\t: -mutable enables optimizations for mutable objects."
5537 "\n\t\t: -neutral draws objects in main viewer."
5538 "\n\t\t: -layer sets z-layer for objects. It can use -overlay|-underlay|-top|-topmost instead of -layer index for the default z-layers."
5539 "\n\t\t: -top draws objects on top of main presentations but below topmost."
5540 "\n\t\t: -topmost draws in overlay for 3D presentations with independent Depth."
5541 "\n\t\t: -overlay draws objects in overlay for 2D presentations (On-Screen-Display)."
5542 "\n\t\t: -underlay draws objects in underlay for 2D presentations (On-Screen-Display)."
5543 "\n\t\t: -selectable|-noselect controls selection of objects."
5544 "\n\t\t: -trsfPers sets a transform persistence flags. Flag 'full' is pan, zoom and rotate."
5545 "\n\t\t: -trsfPersPos sets an anchor point for transform persistence."
5546 "\n\t\t: -2d displays object in screen coordinates (DY looks up)."
5547 "\n\t\t: -dispmode sets display mode for objects."
5548 "\n\t\t: -highmode sets hilight mode for objects."
5549 "\n\t\t: -redisplay recomputes presentation of objects.",
5550 __FILE__, VDisplay2, group);
5552 theCommands.Add ("vupdate",
5553 "vupdate name1 [name2] ... [name n]"
5554 "\n\t\t: Updates named objects in interactive context",
5555 __FILE__, VUpdate, group);
5557 theCommands.Add("verase",
5558 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5559 "\n\t\t: Erases selected or named objects."
5560 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5561 "\n\t\t: Option -local enables erasing of selected or named objects without"
5562 "\n\t\t: closing local selection context.",
5563 __FILE__, VErase, group);
5565 theCommands.Add("vremove",
5566 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5567 "or vremove [-context] -all to remove all objects"
5568 "\n\t\t: Removes selected or named objects."
5569 "\n\t\t If -context is in arguments, the objects are not deleted"
5570 "\n\t\t from the map of objects and names."
5571 "\n\t\t: Option -local enables removing of selected or named objects without"
5572 "\n\t\t: closing local selection context. Empty local selection context will be"
5574 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5575 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5576 __FILE__, VRemove, group);
5578 theCommands.Add("vdonly",
5579 "vdonly [-noupdate|-update] [name1] ... [name n]"
5580 "\n\t\t: Displays only selected or named objects",
5581 __FILE__,VDonly2,group);
5583 theCommands.Add("vdisplayall",
5584 "vidsplayall [-local]"
5585 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5586 "\n\t\t: Option -local enables displaying of the objects in local"
5587 "\n\t\t: selection context.",
5588 __FILE__, VDisplayAll, group);
5590 theCommands.Add("veraseall",
5591 "veraseall [-local]"
5592 "\n\t\t: Erases all objects displayed in the viewer."
5593 "\n\t\t: Option -local enables erasing of the objects in local"
5594 "\n\t\t: selection context.",
5595 __FILE__, VErase, group);
5597 theCommands.Add("verasetype",
5599 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5600 __FILE__, VEraseType, group);
5601 theCommands.Add("vbounding",
5602 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5603 "\n\t\t: [-print] [-hide]"
5604 "\n\t\t: Temporarily display bounding box of specified Interactive"
5605 "\n\t\t: Objects, or print it to console if -print is specified."
5606 "\n\t\t: Already displayed box might be hidden by -hide option.",
5607 __FILE__,VBounding,group);
5609 theCommands.Add("vdisplaytype",
5610 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5611 __FILE__,VDisplayType,group);
5613 theCommands.Add("vsetdispmode",
5614 "vsetdispmode [name] mode(1,2,..)"
5615 "\n\t\t: Sets display mode for all, selected or named objects.",
5616 __FILE__,VDispMode,group);
5618 theCommands.Add("vunsetdispmode",
5619 "vunsetdispmode [name]"
5620 "\n\t\t: Unsets custom display mode for selected or named objects.",
5621 __FILE__,VDispMode,group);
5623 theCommands.Add("vdir",
5624 "Lists all objects displayed in 3D viewer",
5625 __FILE__,VDir,group);
5627 #ifdef HAVE_FREEIMAGE
5628 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5630 #define DUMP_FORMATS "{ppm}"
5632 theCommands.Add("vdump",
5633 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5634 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5635 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5636 "\n\t\t: [-tileSize Size=0]"
5637 "\n\t\t: Dumps content of the active view into image file",
5638 __FILE__,VDump,group);
5640 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5641 __FILE__,VSubInt,group);
5643 theCommands.Add("vaspects",
5644 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5645 "\n\t\t: [-setVisibility 0|1]"
5646 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5647 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5648 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5649 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5650 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5651 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5652 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5653 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5654 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5655 "\n\t\t: [-isoontriangulation 0|1]"
5656 "\n\t\t: [-setMaxParamValue {value}]"
5657 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5658 "\n\t\t: Manage presentation properties of all, selected or named objects."
5659 "\n\t\t: When -subshapes is specified than following properties will be"
5660 "\n\t\t: assigned to specified sub-shapes."
5661 "\n\t\t: When -defaults is specified than presentation properties will be"
5662 "\n\t\t: assigned to all objects that have not their own specified properties"
5663 "\n\t\t: and to all objects to be displayed in the future."
5664 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5665 __FILE__,VAspects,group);
5667 theCommands.Add("vsetcolor",
5668 "vsetcolor [-noupdate|-update] [name] ColorName"
5669 "\n\t\t: Sets color for all, selected or named objects."
5670 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5671 __FILE__,VAspects,group);
5673 theCommands.Add("vunsetcolor",
5674 "vunsetcolor [-noupdate|-update] [name]"
5675 "\n\t\t: Resets color for all, selected or named objects."
5676 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5677 __FILE__,VAspects,group);
5679 theCommands.Add("vsettransparency",
5680 "vsettransparency [-noupdate|-update] [name] Coefficient"
5681 "\n\t\t: Sets transparency for all, selected or named objects."
5682 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5683 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5684 __FILE__,VAspects,group);
5686 theCommands.Add("vunsettransparency",
5687 "vunsettransparency [-noupdate|-update] [name]"
5688 "\n\t\t: Resets transparency for all, selected or named objects."
5689 "\n\t\t: Alias for vaspects -unsettransp [name].",
5690 __FILE__,VAspects,group);
5692 theCommands.Add("vsetmaterial",
5693 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5694 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5695 __FILE__,VAspects,group);
5697 theCommands.Add("vunsetmaterial",
5698 "vunsetmaterial [-noupdate|-update] [name]"
5699 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5700 __FILE__,VAspects,group);
5702 theCommands.Add("vsetwidth",
5703 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5704 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5705 __FILE__,VAspects,group);
5707 theCommands.Add("vunsetwidth",
5708 "vunsetwidth [-noupdate|-update] [name]"
5709 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5710 __FILE__,VAspects,group);
5712 theCommands.Add("vsetinteriorstyle",
5713 "vsetinteriorstyle [-noupdate|-update] [name] style"
5714 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5715 __FILE__,VSetInteriorStyle,group);
5717 theCommands.Add("vsensdis",
5718 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5719 "\n\t\t: Standard entity types are those defined in Select3D package:"
5720 "\n\t\t: - sensitive box"
5721 "\n\t\t: - sensitive face"
5722 "\n\t\t: - sensitive curve"
5723 "\n\t\t: - sensitive segment"
5724 "\n\t\t: - sensitive circle"
5725 "\n\t\t: - sensitive point"
5726 "\n\t\t: - sensitive triangulation"
5727 "\n\t\t: - sensitive triangle"
5728 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5729 __FILE__,VDispSensi,group);
5731 theCommands.Add("vsensera",
5732 "vsensera : erase active entities",
5733 __FILE__,VClearSensi,group);
5735 theCommands.Add("vselprecision",
5736 "vselprecision [-unset] [tolerance_value]"
5737 "\n\t\t Manages selection precision or prints current value if no parameter is passed."
5738 "\n\t\t -unset - restores default selection tolerance behavior, based on individual entity tolerance",
5739 __FILE__,VSelPrecision,group);
5741 theCommands.Add("vperf",
5742 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
5743 "\n\t\t: Tests the animation of an object along a predefined trajectory.",
5744 __FILE__,VPerf,group);
5746 theCommands.Add("vanimation",
5747 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5748 __FILE__,VAnimation,group);
5750 theCommands.Add("vsetshading",
5751 "vsetshading : vsetshading name Quality(default=0.0008) "
5752 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5753 __FILE__,VShading,group);
5755 theCommands.Add("vunsetshading",
5756 "vunsetshading :vunsetshading name "
5757 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5758 __FILE__,VShading,group);
5760 theCommands.Add ("vtexture",
5761 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5762 " [-scale u v] [-scale off]\n"
5763 " [-origin u v] [-origin off]\n"
5764 " [-repeat u v] [-repeat off]\n"
5765 " [-modulate {on | off}]"
5767 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5768 " specifying one of the predefined textures.\n"
5769 " The options are: \n"
5770 " -scale u v : enable texture scaling and set scale factors\n"
5771 " -scale off : disable texture scaling\n"
5772 " -origin u v : enable texture origin positioning and set the origin\n"
5773 " -origin off : disable texture origin positioning\n"
5774 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5775 " -repeat off : disable texture repeat\n"
5776 " -modulate {on | off} : enable or disable texture modulation\n"
5777 " -default : sets texture mapping default parameters\n"
5778 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5779 "or 'vtexture NameOfShape ?' to list available textures\n",
5780 __FILE__, VTexture, group);
5782 theCommands.Add("vtexscale",
5783 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5784 or 'vtexscale NameOfShape ScaleUV' \n \
5785 or 'vtexscale NameOfShape' to disable scaling\n ",
5786 __FILE__,VTexture,group);
5788 theCommands.Add("vtexorigin",
5789 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5790 or 'vtexorigin NameOfShape UVOrigin' \n \
5791 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5792 __FILE__,VTexture,group);
5794 theCommands.Add("vtexrepeat",
5795 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5796 or 'vtexrepeat NameOfShape UVRepeat \n \
5797 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5800 theCommands.Add("vtexdefault",
5801 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5804 theCommands.Add("vsetam",
5805 "vsetam [shapename] mode"
5806 "\n\t\t: Activates selection mode for all selected or named shapes."
5807 "\n\t\t: Mod can be:"
5808 "\n\t\t: 0 - for shape itself"
5809 "\n\t\t: 1 - vertices"
5813 "\n\t\t: 5 - shells"
5814 "\n\t\t: 6 - solids"
5815 "\n\t\t: 7 - compounds"
5816 __FILE__,VActivatedMode,group);
5818 theCommands.Add("vunsetam",
5819 "vunsetam : Deactivates all selection modes for all shapes.",
5820 __FILE__,VActivatedMode,group);
5822 theCommands.Add("vstate",
5823 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5824 "\n\t\t: Reports show/hidden state for selected or named objects"
5825 "\n\t\t: -entities - print low-level information about detected entities"
5826 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5827 __FILE__,VState,group);
5829 theCommands.Add("vpickshapes",
5830 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5831 __FILE__,VPickShape,group);
5833 theCommands.Add("vtypes",
5834 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5837 theCommands.Add("vr",
5839 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
5840 __FILE__,vr, group);
5842 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5843 __FILE__, VPickSelected, group);
5845 theCommands.Add ("vloadselection",
5846 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5847 "\n\t\t: primitives for the shapes with names given without displaying them."
5848 "\n\t\t: -local - open local context before selection computation",
5849 __FILE__, VLoadSelection, group);
5851 theCommands.Add ("vautoactivatesel",
5852 "vautoactivatesel [0|1] : manage or display the option to automatically"
5853 "\n\t\t: activate selection for newly displayed objects"
5854 "\n\t\t: [0|1] - turn off | on auto activation of selection",
5855 __FILE__, VAutoActivateSelection, group);
5857 theCommands.Add("vbsdf", "vbsdf [name] [options]"
5858 "\nAdjusts parameters of material BSDF:"
5859 "\n -help : Shows this message"
5860 "\n -print : Print BSDF"
5861 "\n -kd : Weight of the Lambertian BRDF"
5862 "\n -kr : Weight of the reflection BRDF"
5863 "\n -kt : Weight of the transmission BTDF"
5864 "\n -ks : Weight of the glossy Blinn BRDF"
5865 "\n -le : Self-emitted radiance"
5866 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5867 "\n Schlick x y z, Dielectric x, Conductor x y"
5868 "\n -roughness : Roughness of material (Blinn's exponent)"
5869 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
5870 "\n -absorpcolor : Absorption color (only for transparent material)"
5871 "\n -normalize : Normalize BSDF coefficients",
5872 __FILE__, VBsdf, group);
5876 //=====================================================================
5877 //========================= for testing Draft and Rib =================
5878 //=====================================================================
5879 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5880 #include <DBRep.hxx>
5881 #include <TopoDS_Face.hxx>
5882 #include <gp_Pln.hxx>
5883 #include <AIS_KindOfSurface.hxx>
5884 #include <BRepOffsetAPI_DraftAngle.hxx>
5885 #include <Precision.hxx>
5886 #include <BRepAlgo.hxx>
5887 #include <OSD_Environment.hxx>
5888 #include <DrawTrSurf.hxx>
5889 //#include <DbgTools.hxx>
5890 //#include <FeatAlgo_MakeLinearForm.hxx>
5895 //=======================================================================
5896 //function : IsValid
5898 //=======================================================================
5899 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5900 const TopoDS_Shape& theResult,
5901 const Standard_Boolean closedSolid,
5902 const Standard_Boolean GeomCtrl)
5904 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5905 TCollection_AsciiString checkValid = check.Value();
5906 Standard_Boolean ToCheck = Standard_True;
5907 if (!checkValid.IsEmpty()) {
5909 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5911 if ( checkValid=="true" || checkValid=="TRUE" ) {
5912 ToCheck= Standard_False;
5916 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
5919 Standard_Boolean IsValid = Standard_True;
5921 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5926 //===============================================================================
5927 // TDraft : test draft, uses AIS Viewer
5928 // Solid Face Plane Angle Reverse
5929 //===============================================================================
5930 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5932 if (argc < 5) return 1;
5933 // argv[1] - TopoDS_Shape Solid
5934 // argv[2] - TopoDS_Shape Face
5935 // argv[3] - TopoDS_Shape Plane
5936 // argv[4] - Standard_Real Angle
5937 // argv[5] - Standard_Integer Reverse
5939 // Sprintf(prefix, argv[1]);
5940 Standard_Real anAngle = 0;
5941 Standard_Boolean Rev = Standard_False;
5942 Standard_Integer rev = 0;
5943 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5944 TopoDS_Shape face = GetShapeFromName(argv[2]);
5945 TopoDS_Face Face = TopoDS::Face(face);
5946 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5947 if (Plane.IsNull ()) {
5948 di << "TEST : Plane is NULL\n";
5951 anAngle = Draw::Atof(argv[4]);
5952 anAngle = 2*M_PI * anAngle / 360.0;
5954 Handle( Geom_Surface )aSurf;
5955 AIS_KindOfSurface aSurfType;
5956 Standard_Real Offset;
5958 if(argc > 4) { // == 5
5959 rev = Draw::Atoi(argv[5]);
5960 Rev = (rev)? Standard_True : Standard_False;
5963 TopoDS_Face face2 = TopoDS::Face(Plane);
5964 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5966 di << "TEST : Can't find plane\n";
5970 aDir = aPln.Axis().Direction();
5973 if (Plane.Orientation() == TopAbs_REVERSED)
5975 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5977 BRepOffsetAPI_DraftAngle Draft (Solid);
5979 if(Abs(anAngle)< Precision::Angular()) {
5980 di << "TEST : NULL angle\n";
5983 if(Rev) anAngle = - anAngle;
5984 Draft.Add (Face, aDir, anAngle, aPln);
5986 if (!Draft.IsDone()) {
5987 di << "TEST : Draft Not DONE \n";
5990 TopTools_ListOfShape Larg;
5992 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
5993 di << "TEST : DesignAlgo returns Not valid\n";
5997 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5998 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6000 if ( !ais.IsNull() ) {
6001 ais->SetColor(DEFAULT_COLOR);
6002 ais->SetMaterial(DEFAULT_MATERIAL);
6003 // Display the AIS_Shape without redraw
6004 Ctx->Display(ais, Standard_False);
6006 const char *Name = "draft1";
6007 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6009 Handle(AIS_InteractiveObject) an_object =
6010 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6011 if (!an_object.IsNull()) {
6012 Ctx->Remove(an_object,
6014 GetMapOfAIS().UnBind2(Name) ;
6017 GetMapOfAIS().Bind(ais, Name);
6018 // DBRep::Set("draft", ais->Shape());
6020 Ctx->Display(ais, Standard_True);
6024 //==============================================================================
6025 //function : splitParameter
6026 //purpose : Split parameter string to parameter name and parameter value
6027 //==============================================================================
6028 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6029 TCollection_AsciiString& theName,
6030 TCollection_AsciiString& theValue)
6032 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6034 if (aParamNameEnd == 0)
6036 return Standard_False;
6039 TCollection_AsciiString aString (theString);
6040 if (aParamNameEnd != 0)
6042 theValue = aString.Split (aParamNameEnd);
6043 aString.Split (aString.Length() - 1);
6047 return Standard_True;
6050 //============================================================================
6052 //============================================================================
6053 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6056 DrawTrSurf::BasicCommands(theCommands);
6057 const char* group = "Check Features Operations commands";
6059 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6061 &TDraft,group); //Draft_Modification
6064 //==============================================================================
6065 // ViewerTest::Factory
6066 //==============================================================================
6067 void ViewerTest::Factory(Draw_Interpretor& theDI)
6069 // definition of Viewer Command
6070 ViewerTest::Commands(theDI);
6071 ViewerTest::AviCommands(theDI);
6074 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6078 // Declare entry point PLUGINFACTORY