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 // avoid warnings on 'extern "C"' functions returning C++ classes
81 #define _CRT_SECURE_NO_DEPRECATE
82 #pragma warning(4:4190)
83 #pragma warning (disable:4996)
86 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
88 #include <Quantity_Color.hxx>
89 #include <Quantity_NameOfColor.hxx>
91 #include <Graphic3d_NameOfMaterial.hxx>
93 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
94 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
95 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
97 //=======================================================================
98 //function : GetColorFromName
99 //purpose : get the Quantity_NameOfColor from a string
100 //=======================================================================
102 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
104 Quantity_NameOfColor aColor = DEFAULT_COLOR;
105 Quantity_Color::ColorFromName (theName, aColor);
109 //=======================================================================
110 //function : ParseColor
112 //=======================================================================
114 Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
115 const char** theArgVec,
116 Quantity_Color& theColor)
118 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
120 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
125 else if (theArgNb >= 3)
127 const TCollection_AsciiString anRgbStr[3] =
133 if (!anRgbStr[0].IsRealValue()
134 || !anRgbStr[1].IsRealValue()
135 || !anRgbStr[2].IsRealValue())
140 Graphic3d_Vec4d anRgb;
141 anRgb.x() = anRgbStr[0].RealValue();
142 anRgb.y() = anRgbStr[1].RealValue();
143 anRgb.z() = anRgbStr[2].RealValue();
144 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
145 || anRgb.y() < 0.0 || anRgb.y() > 1.0
146 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
148 std::cout << "Error: RGB color values should be within range 0..1!\n";
152 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
159 //=======================================================================
160 //function : ParseOnOff
162 //=======================================================================
163 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
164 Standard_Boolean& theIsOn)
166 TCollection_AsciiString aFlag(theArg);
171 theIsOn = Standard_True;
172 return Standard_True;
174 else if (aFlag == "off"
177 theIsOn = Standard_False;
178 return Standard_True;
180 return Standard_False;
183 //=======================================================================
184 //function : GetTypeNames
186 //=======================================================================
187 static const char** GetTypeNames()
189 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
190 "Shape","ConnectedShape","MultiConn.Shape",
191 "ConnectedInter.","MultiConn.",
192 "Constraint","Dimension"};
193 static const char** ThePointer = names;
197 //=======================================================================
198 //function : GetTypeAndSignfromString
200 //=======================================================================
201 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
203 const char ** thefullnames = GetTypeNames();
204 Standard_Integer index(-1);
206 for(Standard_Integer i=0;i<=13 && index==-1;i++)
207 if(!strcasecmp(name,thefullnames[i]))
211 TheType = AIS_KOI_None;
217 TheType = AIS_KOI_Datum;
221 TheType = AIS_KOI_Shape;
225 TheType = AIS_KOI_Object;
229 TheType = AIS_KOI_Relation;
238 #include <Draw_Interpretor.hxx>
240 #include <Draw_Appli.hxx>
244 #include <TCollection_AsciiString.hxx>
245 #include <V3d_Viewer.hxx>
246 #include <V3d_View.hxx>
249 #include <AIS_InteractiveContext.hxx>
250 #include <AIS_Shape.hxx>
251 #include <AIS_TexturedShape.hxx>
252 #include <AIS_DisplayMode.hxx>
253 #include <TColStd_MapOfInteger.hxx>
254 #include <AIS_MapOfInteractive.hxx>
255 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
256 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
257 #include <ViewerTest_EventManager.hxx>
259 #include <TopoDS_Solid.hxx>
260 #include <BRepTools.hxx>
261 #include <BRep_Builder.hxx>
262 #include <TopAbs_ShapeEnum.hxx>
264 #include <TopoDS.hxx>
265 #include <BRep_Tool.hxx>
268 #include <Draw_Window.hxx>
269 #include <AIS_ListIteratorOfListOfInteractive.hxx>
270 #include <AIS_ListOfInteractive.hxx>
271 #include <AIS_DisplayMode.hxx>
272 #include <TopTools_ListOfShape.hxx>
273 #include <BRepOffsetAPI_MakeThickSolid.hxx>
274 #include <BRepOffset.hxx>
276 //==============================================================================
277 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
278 //==============================================================================
279 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
280 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
284 //=======================================================================
287 //=======================================================================
288 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
289 const Handle(AIS_InteractiveObject)& theObject,
290 const Standard_Boolean theToUpdate,
291 const Standard_Boolean theReplaceIfExists)
293 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
294 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
297 std::cout << "Error: AIS context is not available.\n";
298 return Standard_False;
301 if (aMap.IsBound2 (theName))
303 if (!theReplaceIfExists)
305 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
306 << "Please use another name.\n";
307 return Standard_False;
310 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
311 if (!anOldObj.IsNull())
313 aCtx->Remove (anOldObj, Standard_True);
315 aMap.UnBind2 (theName);
318 if (theObject.IsNull())
320 // object with specified name has been already unbound
321 return Standard_True;
324 // unbind AIS object if it was bound with another name
325 aMap.UnBind1 (theObject);
327 // can be registered without rebinding
328 aMap.Bind (theObject, theName);
329 aCtx->Display (theObject, theToUpdate);
330 return Standard_True;
333 //! Alias for ViewerTest::Display(), compatibility with old code.
334 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
335 const Handle(AIS_InteractiveObject)& theObject,
336 Standard_Boolean theReplaceIfExists = Standard_True)
338 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
341 static TColStd_MapOfInteger theactivatedmodes(8);
342 static TColStd_ListOfTransient theEventMgrs;
344 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
345 const Handle(AIS_InteractiveContext)& Ctx)
347 theEventMgrs.Clear();
348 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
351 static Handle(V3d_View)& a3DView()
353 static Handle(V3d_View) Viou;
358 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
359 static Handle(AIS_InteractiveContext) aContext;
363 const Handle(V3d_View)& ViewerTest::CurrentView()
367 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
372 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
374 return TheAISContext();
377 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
379 TheAISContext() = aCtx;
380 ViewerTest::ResetEventManager();
383 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
385 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
388 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
390 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
394 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
395 theEventMgrs.Prepend(EM);
398 void ViewerTest::UnsetEventManager()
400 theEventMgrs.RemoveFirst();
404 void ViewerTest::ResetEventManager()
406 const Handle(V3d_View) aView = ViewerTest::CurrentView();
407 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
410 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
412 Handle(ViewerTest_EventManager) EM;
413 if(theEventMgrs.IsEmpty()) return EM;
414 Handle(Standard_Transient) Tr = theEventMgrs.First();
415 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
419 //=======================================================================
420 //function : Get Context and active view
422 //=======================================================================
423 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
424 Handle(V3d_View)& theView)
426 theCtx = ViewerTest::GetAISContext();
427 theView = ViewerTest::CurrentView();
431 std::cout << "Error: cannot find an active view!\n";
432 return Standard_False;
434 return Standard_True;
437 //==============================================================================
438 //function : GetShapeFromName
439 //purpose : Compute an Shape from a draw variable or a file name
440 //==============================================================================
442 static TopoDS_Shape GetShapeFromName(const char* name)
444 TopoDS_Shape S = DBRep::Get(name);
447 BRep_Builder aBuilder;
448 BRepTools::Read( S, name, aBuilder);
454 //==============================================================================
455 //function : GetAISShapeFromName
456 //purpose : Compute an AIS_Shape from a draw variable or a file name
457 //==============================================================================
458 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
460 Handle(AIS_Shape) retsh;
462 if(GetMapOfAIS().IsBound2(name)){
463 const Handle(AIS_InteractiveObject) IO =
464 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
466 if(IO->Type()==AIS_KOI_Shape) {
467 if(IO->Signature()==0){
468 retsh = Handle(AIS_Shape)::DownCast (IO);
471 cout << "an Object which is not an AIS_Shape "
472 "already has this name!!!"<<endl;
479 TopoDS_Shape S = GetShapeFromName(name);
481 retsh = new AIS_Shape(S);
487 //==============================================================================
489 //purpose : Remove all the object from the viewer
490 //==============================================================================
491 void ViewerTest::Clear()
493 if ( !a3DView().IsNull() ) {
494 if (TheAISContext()->HasOpenedContext())
495 TheAISContext()->CloseLocalContext();
496 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
497 while ( it.More() ) {
498 cout << "Remove " << it.Key2() << endl;
499 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
500 TheAISContext()->Remove(anObj,Standard_False);
503 TheAISContext()->RebuildSelectionStructs();
504 TheAISContext()->UpdateCurrentViewer();
505 GetMapOfAIS().Clear();
509 //==============================================================================
510 //function : StandardModesActivation
511 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
513 //==============================================================================
514 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
516 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
518 if (TheAISContext()->HasOpenedContext())
519 aContext->CloseLocalContext();
522 if(!aContext->HasOpenedContext()) {
523 // To unhilight the preselected object
524 aContext->UnhilightSelected(Standard_False);
525 // Open a local Context in order to be able to select subshape from
526 // the selected shape if any or for all if there is no selection
527 if (!aContext->FirstSelectedObject().IsNull()){
528 aContext->OpenLocalContext(Standard_False);
530 for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
531 aContext->Load( aContext->SelectedInteractive(),-1,Standard_True);
535 aContext->OpenLocalContext();
538 const char *cmode="???";
541 case 0: cmode = "Shape"; break;
542 case 1: cmode = "Vertex"; break;
543 case 2: cmode = "Edge"; break;
544 case 3: cmode = "Wire"; break;
545 case 4: cmode = "Face"; break;
546 case 5: cmode = "Shell"; break;
547 case 6: cmode = "Solid"; break;
548 case 7: cmode = "Compsolid"; break;
549 case 8: cmode = "Compound"; break;
552 if(theactivatedmodes.Contains(mode))
554 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
555 theactivatedmodes.Remove(mode);
556 cout<<"Mode "<< cmode <<" OFF"<<endl;
560 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
561 theactivatedmodes.Add(mode);
562 cout<<"Mode "<< cmode << " ON" << endl;
567 //==============================================================================
568 //function : CopyIsoAspect
569 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
570 //==============================================================================
571 static Handle(Prs3d_IsoAspect) CopyIsoAspect
572 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
573 const Standard_Integer theNbIsos)
575 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
576 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
577 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
579 Handle(Prs3d_IsoAspect) aResult =
580 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
585 //==============================================================================
587 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
588 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
589 //==============================================================================
590 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
592 if (TheAISContext().IsNull()) {
593 di << argv[0] << " Call 'vinit' before!\n";
598 di << "Current number of isos : " <<
599 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
600 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
601 di << "IsoOnPlane mode is " <<
602 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
603 di << "IsoOnTriangulation mode is " <<
604 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
608 Standard_Integer aLastInd = argc - 1;
609 Standard_Boolean isChanged = Standard_False;
610 Standard_Integer aNbUIsos = 0;
611 Standard_Integer aNbVIsos = 0;
614 Standard_Boolean isIsoOnPlane = Standard_False;
616 if (strcmp(argv[aLastInd], "1") == 0) {
617 isIsoOnPlane = Standard_True;
618 isChanged = Standard_True;
619 } else if (strcmp(argv[aLastInd], "0") == 0) {
620 isIsoOnPlane = Standard_False;
621 isChanged = Standard_True;
625 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
626 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
629 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
630 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
632 TheAISContext()->IsoOnPlane(isIsoOnPlane);
635 // If there are no shapes provided set the default numbers.
636 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
637 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
644 for (i = 1; i <= aLastInd; i++) {
645 TCollection_AsciiString name(argv[i]);
646 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
649 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
650 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
651 const Handle(AIS_InteractiveObject) aShape =
652 Handle(AIS_InteractiveObject)::DownCast (anObj);
653 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
654 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
655 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
658 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
659 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
660 TheAISContext()->SetLocalAttributes
661 (aShape, CurDrawer, Standard_False);
662 TheAISContext()->Redisplay(aShape);
664 di << "Number of isos for " << argv[i] << " : "
665 << aUIso->Number() << " " << aVIso->Number() << "\n";
668 di << argv[i] << ": Not an AIS interactive object!\n";
671 di << argv[i] << ": Use 'vdisplay' before\n";
676 TheAISContext()->UpdateCurrentViewer();
682 static Standard_Integer VDispSensi (Draw_Interpretor& ,
683 Standard_Integer theArgNb,
688 std::cout << "Error: wrong syntax!\n";
692 Handle(AIS_InteractiveContext) aCtx;
693 Handle(V3d_View) aView;
694 if (!getCtxAndView (aCtx, aView))
699 aCtx->DisplayActiveSensitive (aView);
704 static Standard_Integer VClearSensi (Draw_Interpretor& ,
705 Standard_Integer theArgNb,
710 std::cout << "Error: wrong syntax!\n";
714 Handle(AIS_InteractiveContext) aCtx;
715 Handle(V3d_View) aView;
716 if (!getCtxAndView (aCtx, aView))
720 aCtx->ClearActiveSensitive (aView);
724 //==============================================================================
726 //purpose : To list the displayed object with their attributes
727 //==============================================================================
728 static int VDir (Draw_Interpretor& theDI,
732 if (!a3DView().IsNull())
737 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
738 anIter.More(); anIter.Next())
740 theDI << "\t" << anIter.Key2().ToCString() << "\n";
745 //==============================================================================
746 //function : VSelPrecision
747 //purpose : To set the selection tolerance value
748 //Draw arg : Selection tolerance value (real value determining the width and
749 // height of selecting frustum bases). Without arguments the function
750 // just prints current tolerance.
751 //==============================================================================
752 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
756 di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
760 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
761 if( aContext.IsNull() )
766 Standard_Real aPixelTolerance = aContext->PixelTolerance();
767 di << "Pixel tolerance : " << aPixelTolerance << "\n";
771 TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
773 if (anArg == "-unset")
775 aContext->SetPixelTolerance (-1);
779 aContext->SetPixelTolerance (anArg.IntegerValue());
786 //! Auxiliary enumeration
787 enum ViewerTest_StereoPair
789 ViewerTest_SP_Single,
790 ViewerTest_SP_SideBySide,
791 ViewerTest_SP_OverUnder
794 //==============================================================================
796 //purpose : To dump the active view snapshot to image file
797 //==============================================================================
798 static Standard_Integer VDump (Draw_Interpretor& theDI,
799 Standard_Integer theArgNb,
800 Standard_CString* theArgVec)
804 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
808 Standard_Integer anArgIter = 1;
809 Standard_CString aFilePath = theArgVec[anArgIter++];
810 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
811 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
812 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
813 Standard_Integer aWidth = 0;
814 Standard_Integer aHeight = 0;
815 for (; anArgIter < theArgNb; ++anArgIter)
817 TCollection_AsciiString anArg (theArgVec[anArgIter]);
819 if (anArg == "-buffer")
821 if (++anArgIter >= theArgNb)
823 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
827 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
829 if (aBufArg == "rgba")
831 aBufferType = Graphic3d_BT_RGBA;
833 else if (aBufArg == "rgb")
835 aBufferType = Graphic3d_BT_RGB;
837 else if (aBufArg == "depth")
839 aBufferType = Graphic3d_BT_Depth;
843 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
847 else if (anArg == "-stereo")
849 if (++anArgIter >= theArgNb)
851 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
855 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
856 aStereoArg.LowerCase();
857 if (aStereoArg == "l"
858 || aStereoArg == "left")
860 aStereoOpts = V3d_SDO_LEFT_EYE;
862 else if (aStereoArg == "r"
863 || aStereoArg == "right")
865 aStereoOpts = V3d_SDO_RIGHT_EYE;
867 else if (aStereoArg == "mono")
869 aStereoOpts = V3d_SDO_MONO;
871 else if (aStereoArg == "blended"
872 || aStereoArg == "blend"
873 || aStereoArg == "stereo")
875 aStereoOpts = V3d_SDO_BLENDED;
877 else if (aStereoArg == "sbs"
878 || aStereoArg == "sidebyside")
880 aStereoPair = ViewerTest_SP_SideBySide;
882 else if (aStereoArg == "ou"
883 || aStereoArg == "overunder")
885 aStereoPair = ViewerTest_SP_OverUnder;
889 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
893 else if (anArg == "-rgba"
896 aBufferType = Graphic3d_BT_RGBA;
898 else if (anArg == "-rgb"
901 aBufferType = Graphic3d_BT_RGB;
903 else if (anArg == "-depth"
906 aBufferType = Graphic3d_BT_Depth;
909 else if (anArg == "-width"
915 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
918 else if (++anArgIter >= theArgNb)
920 std::cout << "Error: integer value is expected right after 'width'\n";
923 aWidth = Draw::Atoi (theArgVec[anArgIter]);
925 else if (anArg == "-height"
927 || anArg == "-sizey")
931 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
934 else if (++anArgIter >= theArgNb)
936 std::cout << "Error: integer value is expected right after 'height'\n";
939 aHeight = Draw::Atoi (theArgVec[anArgIter]);
943 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
947 if ((aWidth <= 0 && aHeight > 0)
948 || (aWidth > 0 && aHeight <= 0))
950 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
954 Handle(V3d_View) aView = ViewerTest::CurrentView();
957 std::cout << "Error: cannot find an active view!\n";
961 if (aWidth <= 0 || aHeight <= 0)
963 aView->Window()->Size (aWidth, aHeight);
966 Image_AlienPixMap aPixMap;
968 bool isBigEndian = Image_PixMap::IsBigEndianHost();
969 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
972 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
973 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
974 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
979 case ViewerTest_SP_Single:
981 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
983 theDI << "Fail: view dump failed!\n";
986 else if (aPixMap.SizeX() != Standard_Size(aWidth)
987 || aPixMap.SizeY() != Standard_Size(aHeight))
989 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
990 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
994 case ViewerTest_SP_SideBySide:
996 if (!aPixMap.InitZero (aFormat, aWidth * 2, aHeight))
998 theDI << "Fail: not enough memory for image allocation!\n";
1002 Image_PixMap aPixMapL, aPixMapR;
1003 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1004 aWidth, aHeight, aPixMap.SizeRowBytes());
1005 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aWidth,
1006 aWidth, aHeight, aPixMap.SizeRowBytes());
1007 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1008 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE)
1011 theDI << "Fail: view dump failed!\n";
1016 case ViewerTest_SP_OverUnder:
1018 if (!aPixMap.InitZero (aFormat, aWidth, aHeight * 2))
1020 theDI << "Fail: not enough memory for image allocation!\n";
1024 Image_PixMap aPixMapL, aPixMapR;
1025 aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
1026 aWidth, aHeight, aPixMap.SizeRowBytes());
1027 aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aHeight,
1028 aWidth, aHeight, aPixMap.SizeRowBytes());
1029 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1030 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE))
1032 theDI << "Fail: view dump failed!\n";
1039 if (!aPixMap.Save (aFilePath))
1041 theDI << "Fail: image can not be saved!\n";
1046 enum TypeOfDispOperation
1048 TypeOfDispOperation_SetDispMode,
1049 TypeOfDispOperation_UnsetDispMode
1052 //! Displays,Erase...
1053 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1054 const Standard_Integer theMode,
1055 const TypeOfDispOperation theType,
1056 const Standard_Boolean theToUpdate)
1058 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1061 case TypeOfDispOperation_SetDispMode:
1063 if (!thePrs.IsNull())
1065 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1069 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1073 case TypeOfDispOperation_UnsetDispMode:
1075 if (!thePrs.IsNull())
1077 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1081 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1088 //=======================================================================
1091 //=======================================================================
1092 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1097 std::cout << "Syntax error: wrong number of arguments\n";
1101 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1102 ? TypeOfDispOperation_UnsetDispMode
1103 : TypeOfDispOperation_SetDispMode;
1104 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1105 if (aType == TypeOfDispOperation_UnsetDispMode)
1109 if (aCtx->NbSelected() == 0)
1111 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1115 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1117 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1120 aCtx->UpdateCurrentViewer();
1124 TCollection_AsciiString aName = argv[1];
1125 if (GetMapOfAIS().IsBound2 (aName))
1127 Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1130 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1137 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1138 if (aCtx->NbSelected() == 0
1139 && aType == TypeOfDispOperation_SetDispMode)
1141 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1143 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1145 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1147 aCtx->UpdateCurrentViewer();
1151 Handle(AIS_InteractiveObject) aPrs;
1152 TCollection_AsciiString aName (argv[1]);
1153 if (GetMapOfAIS().IsBound2 (aName))
1155 aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1159 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1166 //=======================================================================
1169 //=======================================================================
1170 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1172 if(argc==1) return 1;
1173 Standard_Integer On = Draw::Atoi(argv[1]);
1174 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1178 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1179 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1180 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1184 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1188 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1192 Ctx->UpdateCurrentViewer();
1195 Handle(AIS_InteractiveObject) IO;
1196 TCollection_AsciiString name = argv[2];
1197 if(GetMapOfAIS().IsBound2(name)){
1198 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1201 Ctx->SubIntensityOn(IO);
1203 Ctx->SubIntensityOff(IO);
1211 //! Auxiliary class to iterate presentations from different collections.
1212 class ViewTest_PrsIter
1216 //! Create and initialize iterator object.
1217 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1218 : mySource (IterSource_All)
1220 NCollection_Sequence<TCollection_AsciiString> aNames;
1221 if (!theName.IsEmpty())
1222 aNames.Append (theName);
1226 //! Create and initialize iterator object.
1227 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1228 : mySource (IterSource_All)
1233 //! Initialize the iterator.
1234 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1236 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1238 mySelIter.Nullify();
1239 myCurrent.Nullify();
1240 myCurrentTrs.Nullify();
1241 if (!mySeq.IsEmpty())
1243 mySource = IterSource_List;
1244 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1246 else if (aCtx->NbSelected() > 0)
1248 mySource = IterSource_Selected;
1250 mySelIter->InitSelected();
1254 mySource = IterSource_All;
1255 myMapIter.Initialize (GetMapOfAIS());
1260 const TCollection_AsciiString& CurrentName() const
1262 return myCurrentName;
1265 const Handle(AIS_InteractiveObject)& Current() const
1270 const Handle(Standard_Transient)& CurrentTrs() const
1272 return myCurrentTrs;
1275 //! @return true if iterator points to valid object within collection
1276 Standard_Boolean More() const
1280 case IterSource_All: return myMapIter.More();
1281 case IterSource_List: return mySeqIter.More();
1282 case IterSource_Selected: return mySelIter->MoreSelected();
1284 return Standard_False;
1287 //! Go to the next item.
1290 myCurrentName.Clear();
1291 myCurrentTrs.Nullify();
1292 myCurrent.Nullify();
1295 case IterSource_All:
1300 case IterSource_List:
1305 case IterSource_Selected:
1307 mySelIter->NextSelected();
1320 case IterSource_All:
1322 if (myMapIter.More())
1324 myCurrentName = myMapIter.Key2();
1325 myCurrentTrs = myMapIter.Key1();
1326 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1330 case IterSource_List:
1332 if (mySeqIter.More())
1334 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1336 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1339 myCurrentName = mySeqIter.Value();
1340 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1341 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1345 case IterSource_Selected:
1347 if (mySelIter->MoreSelected())
1349 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1350 myCurrent = mySelIter->SelectedInteractive();
1368 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1369 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1370 NCollection_Sequence<TCollection_AsciiString> mySeq;
1371 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1373 TCollection_AsciiString myCurrentName;//!< current item name
1374 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1375 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1377 IterSource mySource; //!< iterated collection
1381 //==============================================================================
1382 //function : VInteriorStyle
1383 //purpose : sets interior style of the a selected or named or displayed shape
1384 //==============================================================================
1385 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1386 Standard_Integer theArgNb,
1387 const char** theArgVec)
1389 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1390 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1393 std::cerr << "Error: no active view!\n";
1397 Standard_Integer anArgIter = 1;
1398 for (; anArgIter < theArgNb; ++anArgIter)
1400 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1405 TCollection_AsciiString aName;
1406 if (theArgNb - anArgIter == 2)
1408 aName = theArgVec[anArgIter++];
1410 else if (theArgNb - anArgIter != 1)
1412 std::cout << "Error: wrong number of arguments! See usage:\n";
1413 theDI.PrintHelp (theArgVec[0]);
1416 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1417 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1418 aStyleArg.LowerCase();
1419 if (aStyleArg == "empty")
1423 else if (aStyleArg == "hollow")
1427 else if (aStyleArg == "hatch")
1431 else if (aStyleArg == "solid")
1435 else if (aStyleArg == "hiddenline")
1441 anInterStyle = aStyleArg.IntegerValue();
1443 if (anInterStyle < Aspect_IS_EMPTY
1444 || anInterStyle > Aspect_IS_HIDDENLINE)
1446 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1447 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1451 if (!aName.IsEmpty()
1452 && !GetMapOfAIS().IsBound2 (aName))
1454 std::cout << "Error: object " << aName << " is not displayed!\n";
1458 if (aCtx->HasOpenedContext())
1460 aCtx->CloseLocalContext();
1462 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1464 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1467 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1468 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1469 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1470 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1471 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1477 //! Auxiliary structure for VAspects
1478 struct ViewerTest_AspectsChangeSet
1480 Standard_Integer ToSetVisibility;
1481 Standard_Integer Visibility;
1483 Standard_Integer ToSetColor;
1484 Quantity_Color Color;
1486 Standard_Integer ToSetLineWidth;
1487 Standard_Real LineWidth;
1489 Standard_Integer ToSetTypeOfLine;
1490 Aspect_TypeOfLine TypeOfLine;
1492 Standard_Integer ToSetTransparency;
1493 Standard_Real Transparency;
1495 Standard_Integer ToSetMaterial;
1496 Graphic3d_NameOfMaterial Material;
1497 TCollection_AsciiString MatName;
1499 NCollection_Sequence<TopoDS_Shape> SubShapes;
1501 Standard_Integer ToSetShowFreeBoundary;
1502 Standard_Integer ToSetFreeBoundaryWidth;
1503 Standard_Real FreeBoundaryWidth;
1504 Standard_Integer ToSetFreeBoundaryColor;
1505 Quantity_Color FreeBoundaryColor;
1507 Standard_Integer ToEnableIsoOnTriangulation;
1509 Standard_Integer ToSetMaxParamValue;
1510 Standard_Real MaxParamValue;
1512 Standard_Integer ToSetSensitivity;
1513 Standard_Integer SelectionMode;
1514 Standard_Integer Sensitivity;
1516 //! Empty constructor
1517 ViewerTest_AspectsChangeSet()
1518 : ToSetVisibility (0),
1521 Color (DEFAULT_COLOR),
1524 ToSetTypeOfLine (0),
1525 TypeOfLine (Aspect_TOL_SOLID),
1526 ToSetTransparency (0),
1529 Material (Graphic3d_NOM_DEFAULT),
1530 ToSetShowFreeBoundary (0),
1531 ToSetFreeBoundaryWidth (0),
1532 FreeBoundaryWidth (1.0),
1533 ToSetFreeBoundaryColor (0),
1534 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1535 ToEnableIsoOnTriangulation (-1),
1536 ToSetMaxParamValue (0),
1537 MaxParamValue (500000),
1538 ToSetSensitivity (0),
1542 //! @return true if no changes have been requested
1543 Standard_Boolean IsEmpty() const
1545 return ToSetVisibility == 0
1546 && ToSetLineWidth == 0
1547 && ToSetTransparency == 0
1549 && ToSetMaterial == 0
1550 && ToSetShowFreeBoundary == 0
1551 && ToSetFreeBoundaryColor == 0
1552 && ToSetFreeBoundaryWidth == 0
1553 && ToSetMaxParamValue == 0
1554 && ToSetSensitivity == 0;
1557 //! @return true if properties are valid
1558 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1560 Standard_Boolean isOk = Standard_True;
1561 if (Visibility != 0 && Visibility != 1)
1563 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1564 isOk = Standard_False;
1566 if (LineWidth <= 0.0
1567 || LineWidth > 10.0)
1569 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1570 isOk = Standard_False;
1572 if (Transparency < 0.0
1573 || Transparency > 1.0)
1575 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1576 isOk = Standard_False;
1579 && ToSetTransparency)
1581 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1582 isOk = Standard_False;
1584 if (ToSetMaterial == 1
1585 && Material == Graphic3d_NOM_DEFAULT)
1587 std::cout << "Error: unknown material " << MatName << ".\n";
1588 isOk = Standard_False;
1590 if (FreeBoundaryWidth <= 0.0
1591 || FreeBoundaryWidth > 10.0)
1593 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1594 isOk = Standard_False;
1596 if (MaxParamValue < 0.0)
1598 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1599 isOk = Standard_False;
1601 if (Sensitivity <= 0 && ToSetSensitivity)
1603 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1604 isOk = Standard_False;
1611 //==============================================================================
1612 //function : VAspects
1614 //==============================================================================
1615 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1616 Standard_Integer theArgNb,
1617 const char** theArgVec)
1619 TCollection_AsciiString aCmdName (theArgVec[0]);
1620 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1621 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1624 std::cerr << "Error: no active view!\n";
1628 Standard_Integer anArgIter = 1;
1629 Standard_Boolean isDefaults = Standard_False;
1630 NCollection_Sequence<TCollection_AsciiString> aNames;
1631 for (; anArgIter < theArgNb; ++anArgIter)
1633 TCollection_AsciiString anArg = theArgVec[anArgIter];
1634 if (anUpdateTool.parseRedrawMode (anArg))
1638 else if (!anArg.IsEmpty()
1639 && anArg.Value (1) != '-')
1641 aNames.Append (anArg);
1645 if (anArg == "-defaults")
1647 isDefaults = Standard_True;
1654 if (!aNames.IsEmpty() && isDefaults)
1656 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1660 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1661 aChanges.Append (ViewerTest_AspectsChangeSet());
1662 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1664 // parse syntax of legacy commands
1665 if (aCmdName == "vsetwidth")
1667 if (aNames.IsEmpty()
1668 || !aNames.Last().IsRealValue())
1670 std::cout << "Error: not enough arguments!\n";
1673 aChangeSet->ToSetLineWidth = 1;
1674 aChangeSet->LineWidth = aNames.Last().RealValue();
1675 aNames.Remove (aNames.Length());
1677 else if (aCmdName == "vunsetwidth")
1679 aChangeSet->ToSetLineWidth = -1;
1681 else if (aCmdName == "vsetcolor")
1683 if (aNames.IsEmpty())
1685 std::cout << "Error: not enough arguments!\n";
1688 aChangeSet->ToSetColor = 1;
1690 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1691 Standard_Boolean isOk = Standard_False;
1692 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1694 aChangeSet->Color = aColor;
1695 aNames.Remove (aNames.Length());
1696 isOk = Standard_True;
1698 else if (aNames.Length() >= 3)
1700 const TCollection_AsciiString anRgbStr[3] =
1702 aNames.Value (aNames.Upper() - 2),
1703 aNames.Value (aNames.Upper() - 1),
1704 aNames.Value (aNames.Upper() - 0)
1706 isOk = anRgbStr[0].IsRealValue()
1707 && anRgbStr[1].IsRealValue()
1708 && anRgbStr[2].IsRealValue();
1711 Graphic3d_Vec4d anRgb;
1712 anRgb.x() = anRgbStr[0].RealValue();
1713 anRgb.y() = anRgbStr[1].RealValue();
1714 anRgb.z() = anRgbStr[2].RealValue();
1715 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1716 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1717 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1719 std::cout << "Error: RGB color values should be within range 0..1!\n";
1722 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1723 aNames.Remove (aNames.Length());
1724 aNames.Remove (aNames.Length());
1725 aNames.Remove (aNames.Length());
1730 std::cout << "Error: not enough arguments!\n";
1734 else if (aCmdName == "vunsetcolor")
1736 aChangeSet->ToSetColor = -1;
1738 else if (aCmdName == "vsettransparency")
1740 if (aNames.IsEmpty()
1741 || !aNames.Last().IsRealValue())
1743 std::cout << "Error: not enough arguments!\n";
1746 aChangeSet->ToSetTransparency = 1;
1747 aChangeSet->Transparency = aNames.Last().RealValue();
1748 aNames.Remove (aNames.Length());
1750 else if (aCmdName == "vunsettransparency")
1752 aChangeSet->ToSetTransparency = -1;
1754 else if (aCmdName == "vsetmaterial")
1756 if (aNames.IsEmpty())
1758 std::cout << "Error: not enough arguments!\n";
1761 aChangeSet->ToSetMaterial = 1;
1762 aChangeSet->MatName = aNames.Last();
1763 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1764 aNames.Remove (aNames.Length());
1766 else if (aCmdName == "vunsetmaterial")
1768 aChangeSet->ToSetMaterial = -1;
1770 else if (anArgIter >= theArgNb)
1772 std::cout << "Error: not enough arguments!\n";
1776 if (!aChangeSet->IsEmpty())
1778 anArgIter = theArgNb;
1780 for (; anArgIter < theArgNb; ++anArgIter)
1782 TCollection_AsciiString anArg = theArgVec[anArgIter];
1784 if (anArg == "-setwidth"
1785 || anArg == "-setlinewidth")
1787 if (++anArgIter >= theArgNb)
1789 std::cout << "Error: wrong syntax at " << anArg << "\n";
1792 aChangeSet->ToSetLineWidth = 1;
1793 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1795 else if (anArg == "-unsetwidth"
1796 || anArg == "-unsetlinewidth")
1798 aChangeSet->ToSetLineWidth = -1;
1799 aChangeSet->LineWidth = 1.0;
1801 else if (anArg == "-settransp"
1802 || anArg == "-settransparency")
1804 if (++anArgIter >= theArgNb)
1806 std::cout << "Error: wrong syntax at " << anArg << "\n";
1809 aChangeSet->ToSetTransparency = 1;
1810 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1811 if (aChangeSet->Transparency >= 0.0
1812 && aChangeSet->Transparency <= Precision::Confusion())
1814 aChangeSet->ToSetTransparency = -1;
1815 aChangeSet->Transparency = 0.0;
1818 else if (anArg == "-setvis"
1819 || anArg == "-setvisibility")
1821 if (++anArgIter >= theArgNb)
1823 std::cout << "Error: wrong syntax at " << anArg << "\n";
1827 aChangeSet->ToSetVisibility = 1;
1828 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1830 else if (anArg == "-setalpha")
1832 if (++anArgIter >= theArgNb)
1834 std::cout << "Error: wrong syntax at " << anArg << "\n";
1837 aChangeSet->ToSetTransparency = 1;
1838 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1839 if (aChangeSet->Transparency < 0.0
1840 || aChangeSet->Transparency > 1.0)
1842 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1845 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1846 if (aChangeSet->Transparency >= 0.0
1847 && aChangeSet->Transparency <= Precision::Confusion())
1849 aChangeSet->ToSetTransparency = -1;
1850 aChangeSet->Transparency = 0.0;
1853 else if (anArg == "-unsettransp"
1854 || anArg == "-unsettransparency"
1855 || anArg == "-unsetalpha"
1856 || anArg == "-opaque")
1858 aChangeSet->ToSetTransparency = -1;
1859 aChangeSet->Transparency = 0.0;
1861 else if (anArg == "-setcolor")
1863 Standard_Integer aNbComps = 0;
1864 Standard_Integer aCompIter = anArgIter + 1;
1865 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1867 if (theArgVec[aCompIter][0] == '-')
1876 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1877 Standard_CString aName = theArgVec[anArgIter + 1];
1878 if (!Quantity_Color::ColorFromName (aName, aColor))
1880 std::cout << "Error: unknown color name '" << aName << "'\n";
1883 aChangeSet->Color = aColor;
1888 Graphic3d_Vec3d anRgb;
1889 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1890 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1891 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1892 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1893 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1894 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1896 std::cout << "Error: RGB color values should be within range 0..1!\n";
1899 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1904 std::cout << "Error: wrong syntax at " << anArg << "\n";
1908 aChangeSet->ToSetColor = 1;
1909 anArgIter += aNbComps;
1911 else if (anArg == "-setlinetype")
1913 if (++anArgIter >= theArgNb)
1915 std::cout << "Error: wrong syntax at " << anArg << "\n";
1919 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1922 if (aValue.IsEqual ("solid"))
1924 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1926 else if (aValue.IsEqual ("dot"))
1928 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1930 else if (aValue.IsEqual ("dash"))
1932 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1934 else if (aValue.IsEqual ("dotdash"))
1936 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1940 std::cout << "Error: wrong syntax at " << anArg << "\n";
1944 aChangeSet->ToSetTypeOfLine = 1;
1946 else if (anArg == "-unsetlinetype")
1948 aChangeSet->ToSetTypeOfLine = -1;
1950 else if (anArg == "-unsetcolor")
1952 aChangeSet->ToSetColor = -1;
1953 aChangeSet->Color = DEFAULT_COLOR;
1955 else if (anArg == "-setmat"
1956 || anArg == "-setmaterial")
1958 if (++anArgIter >= theArgNb)
1960 std::cout << "Error: wrong syntax at " << anArg << "\n";
1963 aChangeSet->ToSetMaterial = 1;
1964 aChangeSet->MatName = theArgVec[anArgIter];
1965 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1967 else if (anArg == "-unsetmat"
1968 || anArg == "-unsetmaterial")
1970 aChangeSet->ToSetMaterial = -1;
1971 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1973 else if (anArg == "-subshape"
1974 || anArg == "-subshapes")
1978 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1982 if (aNames.IsEmpty())
1984 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1988 aChanges.Append (ViewerTest_AspectsChangeSet());
1989 aChangeSet = &aChanges.ChangeLast();
1991 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1993 Standard_CString aSubShapeName = theArgVec[anArgIter];
1994 if (*aSubShapeName == '-')
2000 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2001 if (aSubShape.IsNull())
2003 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2006 aChangeSet->SubShapes.Append (aSubShape);
2009 if (aChangeSet->SubShapes.IsEmpty())
2011 std::cerr << "Error: empty list is specified after -subshapes!\n";
2015 else if (anArg == "-freeboundary"
2018 if (++anArgIter >= theArgNb)
2020 std::cout << "Error: wrong syntax at " << anArg << "\n";
2023 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2028 aChangeSet->ToSetShowFreeBoundary = 1;
2030 else if (aValue == "off"
2033 aChangeSet->ToSetShowFreeBoundary = -1;
2037 std::cout << "Error: wrong syntax at " << anArg << "\n";
2041 else if (anArg == "-setfreeboundarywidth"
2042 || anArg == "-setfbwidth")
2044 if (++anArgIter >= theArgNb)
2046 std::cout << "Error: wrong syntax at " << anArg << "\n";
2049 aChangeSet->ToSetFreeBoundaryWidth = 1;
2050 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2052 else if (anArg == "-unsetfreeboundarywidth"
2053 || anArg == "-unsetfbwidth")
2055 aChangeSet->ToSetFreeBoundaryWidth = -1;
2056 aChangeSet->FreeBoundaryWidth = 1.0;
2058 else if (anArg == "-setfreeboundarycolor"
2059 || anArg == "-setfbcolor")
2061 Standard_Integer aNbComps = 0;
2062 Standard_Integer aCompIter = anArgIter + 1;
2063 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2065 if (theArgVec[aCompIter][0] == '-')
2074 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2075 Standard_CString aName = theArgVec[anArgIter + 1];
2076 if (!Quantity_Color::ColorFromName (aName, aColor))
2078 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2081 aChangeSet->FreeBoundaryColor = aColor;
2086 Graphic3d_Vec3d anRgb;
2087 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2088 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2089 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2090 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2091 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2092 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2094 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2097 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2102 std::cout << "Error: wrong syntax at " << anArg << "\n";
2106 aChangeSet->ToSetFreeBoundaryColor = 1;
2107 anArgIter += aNbComps;
2109 else if (anArg == "-unsetfreeboundarycolor"
2110 || anArg == "-unsetfbcolor")
2112 aChangeSet->ToSetFreeBoundaryColor = -1;
2113 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2115 else if (anArg == "-unset")
2117 aChangeSet->ToSetVisibility = 1;
2118 aChangeSet->Visibility = 1;
2119 aChangeSet->ToSetLineWidth = -1;
2120 aChangeSet->LineWidth = 1.0;
2121 aChangeSet->ToSetTypeOfLine = -1;
2122 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2123 aChangeSet->ToSetTransparency = -1;
2124 aChangeSet->Transparency = 0.0;
2125 aChangeSet->ToSetColor = -1;
2126 aChangeSet->Color = DEFAULT_COLOR;
2127 aChangeSet->ToSetMaterial = -1;
2128 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2129 aChangeSet->ToSetShowFreeBoundary = -1;
2130 aChangeSet->ToSetFreeBoundaryColor = -1;
2131 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2132 aChangeSet->ToSetFreeBoundaryWidth = -1;
2133 aChangeSet->FreeBoundaryWidth = 1.0;
2135 else if (anArg == "-isoontriangulation"
2136 || anArg == "-isoontriang")
2138 if (++anArgIter >= theArgNb)
2140 std::cout << "Error: wrong syntax at " << anArg << "\n";
2143 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2148 aChangeSet->ToEnableIsoOnTriangulation = 1;
2150 else if (aValue == "off"
2153 aChangeSet->ToEnableIsoOnTriangulation = 0;
2157 std::cout << "Error: wrong syntax at " << anArg << "\n";
2161 else if (anArg == "-setmaxparamvalue")
2163 if (++anArgIter >= theArgNb)
2165 std::cout << "Error: wrong syntax at " << anArg << "\n";
2168 aChangeSet->ToSetMaxParamValue = 1;
2169 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2171 else if (anArg == "-setsensitivity")
2175 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2179 if (aNames.IsEmpty())
2181 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2185 if (anArgIter + 2 >= theArgNb)
2187 std::cout << "Error: wrong syntax at " << anArg << "\n";
2190 aChangeSet->ToSetSensitivity = 1;
2191 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2192 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2196 std::cout << "Error: wrong syntax at " << anArg << "\n";
2201 Standard_Boolean isFirst = Standard_True;
2202 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2203 aChangesIter.More(); aChangesIter.Next())
2205 if (!aChangesIter.Value().Validate (!isFirst))
2209 isFirst = Standard_False;
2212 if (aCtx->HasOpenedContext())
2214 aCtx->CloseLocalContext();
2217 // special case for -defaults parameter.
2218 // all changed values will be set to DefaultDrawer.
2221 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2223 if (aChangeSet->ToSetLineWidth != 0)
2225 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2226 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2227 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2228 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2230 if (aChangeSet->ToSetColor != 0)
2232 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2233 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2234 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2235 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2236 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2237 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2239 if (aChangeSet->ToSetTypeOfLine != 0)
2241 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2242 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2243 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2244 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2245 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2247 if (aChangeSet->ToSetTransparency != 0)
2249 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2251 if (aChangeSet->ToSetMaterial != 0)
2253 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2255 if (aChangeSet->ToSetShowFreeBoundary == 1)
2257 aDrawer->SetFreeBoundaryDraw (Standard_True);
2259 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2261 aDrawer->SetFreeBoundaryDraw (Standard_False);
2263 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2265 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2267 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2269 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2271 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2273 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2275 if (aChangeSet->ToSetMaxParamValue != 0)
2277 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2280 // redisplay all objects in context
2281 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2283 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2286 aCtx->Redisplay (aPrs, Standard_False);
2292 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2294 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2295 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2296 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2297 Handle(AIS_ColoredShape) aColoredPrs;
2298 Standard_Boolean toDisplay = Standard_False;
2299 Standard_Boolean toRedisplay = Standard_False;
2300 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2302 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2303 if (aShapePrs.IsNull())
2305 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2308 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2309 if (aColoredPrs.IsNull())
2311 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2312 if (aShapePrs->HasDisplayMode())
2314 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2316 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2317 aCtx->Remove (aShapePrs, Standard_False);
2318 GetMapOfAIS().UnBind2 (aName);
2319 GetMapOfAIS().Bind (aColoredPrs, aName);
2320 toDisplay = Standard_True;
2321 aShapePrs = aColoredPrs;
2328 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2329 aChangeSet = &aChangesIter.ChangeValue();
2330 if (aChangeSet->ToSetVisibility == 1)
2332 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2333 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2335 else if (aChangeSet->ToSetMaterial == 1)
2337 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2339 else if (aChangeSet->ToSetMaterial == -1)
2341 aCtx->UnsetMaterial (aPrs, Standard_False);
2343 if (aChangeSet->ToSetColor == 1)
2345 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2347 else if (aChangeSet->ToSetColor == -1)
2349 aCtx->UnsetColor (aPrs, Standard_False);
2351 if (aChangeSet->ToSetTransparency == 1)
2353 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2355 else if (aChangeSet->ToSetTransparency == -1)
2357 aCtx->UnsetTransparency (aPrs, Standard_False);
2359 if (aChangeSet->ToSetLineWidth == 1)
2361 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2363 else if (aChangeSet->ToSetLineWidth == -1)
2365 aCtx->UnsetWidth (aPrs, Standard_False);
2367 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2369 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2370 toRedisplay = Standard_True;
2372 else if (aChangeSet->ToSetSensitivity != 0)
2374 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2376 if (!aDrawer.IsNull())
2378 if (aChangeSet->ToSetShowFreeBoundary == 1)
2380 aDrawer->SetFreeBoundaryDraw (Standard_True);
2381 toRedisplay = Standard_True;
2383 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2385 aDrawer->SetFreeBoundaryDraw (Standard_False);
2386 toRedisplay = Standard_True;
2388 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2390 Handle(Prs3d_LineAspect) aBoundaryAspect =
2391 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2392 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2393 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2394 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2395 toRedisplay = Standard_True;
2397 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2399 Handle(Prs3d_LineAspect) aBoundaryAspect =
2400 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2401 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2402 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2403 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2404 toRedisplay = Standard_True;
2406 if (aChangeSet->ToSetTypeOfLine != 0)
2408 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2409 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2410 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2411 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2412 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2413 toRedisplay = Standard_True;
2415 if (aChangeSet->ToSetMaxParamValue != 0)
2417 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2421 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2423 aChangeSet = &aChangesIter.ChangeValue();
2424 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2425 aSubShapeIter.More(); aSubShapeIter.Next())
2427 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2428 if (aChangeSet->ToSetVisibility == 1)
2430 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2431 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2433 if (aChangeSet->ToSetColor == 1)
2435 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2437 if (aChangeSet->ToSetLineWidth == 1)
2439 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2441 if (aChangeSet->ToSetColor == -1
2442 || aChangeSet->ToSetLineWidth == -1)
2444 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2446 if (aChangeSet->ToSetMaxParamValue != 0)
2448 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2449 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2451 if (aChangeSet->ToSetSensitivity != 0)
2453 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2459 aCtx->Display (aPrs, Standard_False);
2463 aCtx->Redisplay (aPrs, Standard_False);
2465 else if (!aColoredPrs.IsNull())
2467 aCtx->Redisplay (aColoredPrs, Standard_False);
2474 //==============================================================================
2475 //function : VDonly2
2477 //purpose : Display only a selected or named object
2478 // if there is no selected or named object s, nothing is done
2479 //==============================================================================
2480 static int VDonly2 (Draw_Interpretor& ,
2481 Standard_Integer theArgNb,
2482 const char** theArgVec)
2484 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2485 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2488 std::cerr << "Error: no active view!\n";
2492 if (aCtx->HasOpenedContext())
2494 aCtx->CloseLocalContext();
2497 Standard_Integer anArgIter = 1;
2498 for (; anArgIter < theArgNb; ++anArgIter)
2500 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2506 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2507 if (anArgIter >= theArgNb)
2509 // display only selected objects
2510 if (aCtx->NbSelected() < 1)
2515 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2517 aDispSet.Add (aCtx->SelectedInteractive());
2522 // display only specified objects
2523 for (; anArgIter < theArgNb; ++anArgIter)
2525 TCollection_AsciiString aName = theArgVec[anArgIter];
2526 if (GetMapOfAIS().IsBound2 (aName))
2528 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2529 if (!aShape.IsNull())
2531 aCtx->Display (aShape, Standard_False);
2532 aDispSet.Add (aShape);
2538 // weed out other objects
2539 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2541 if (aDispSet.Contains (anIter.Key1()))
2546 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2547 if (aShape.IsNull())
2549 aCtx->Erase (aShape, Standard_False);
2555 //==============================================================================
2556 //function : VRemove
2557 //purpose : Removes selected or named objects.
2558 // If there is no selected or named objects,
2559 // all objects in the viewer can be removed with argument -all.
2560 // If -context is in arguments, the object is not deleted from the map of
2561 // objects (deleted only from the current context).
2562 //==============================================================================
2563 int VRemove (Draw_Interpretor& theDI,
2564 Standard_Integer theArgNb,
2565 const char** theArgVec)
2567 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2568 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2571 std::cerr << "Error: no active view!\n";
2575 Standard_Boolean isContextOnly = Standard_False;
2576 Standard_Boolean toRemoveAll = Standard_False;
2577 Standard_Boolean toPrintInfo = Standard_True;
2578 Standard_Boolean toRemoveLocal = Standard_False;
2580 Standard_Integer anArgIter = 1;
2581 for (; anArgIter < theArgNb; ++anArgIter)
2583 TCollection_AsciiString anArg = theArgVec[anArgIter];
2585 if (anArg == "-context")
2587 isContextOnly = Standard_True;
2589 else if (anArg == "-all")
2591 toRemoveAll = Standard_True;
2593 else if (anArg == "-noinfo")
2595 toPrintInfo = Standard_False;
2597 else if (anArg == "-local")
2599 toRemoveLocal = Standard_True;
2601 else if (anUpdateTool.parseRedrawMode (anArg))
2611 && anArgIter < theArgNb)
2613 std::cerr << "Error: wrong syntax!\n";
2617 if (toRemoveLocal && !aCtx->HasOpenedContext())
2619 std::cerr << "Error: local selection context is not open.\n";
2622 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2624 aCtx->CloseAllContexts (Standard_False);
2627 NCollection_List<TCollection_AsciiString> anIONameList;
2630 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2631 anIter.More(); anIter.Next())
2633 anIONameList.Append (anIter.Key2());
2636 else if (anArgIter < theArgNb) // removed objects names are in argument list
2638 for (; anArgIter < theArgNb; ++anArgIter)
2640 TCollection_AsciiString aName = theArgVec[anArgIter];
2641 if (!GetMapOfAIS().IsBound2 (aName))
2643 theDI << aName.ToCString() << " was not bound to some object.\n";
2647 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2648 if (anIO->GetContext() != aCtx)
2650 theDI << aName.ToCString() << " was not displayed in current context.\n";
2651 theDI << "Please activate view with this object displayed and try again.\n";
2655 anIONameList.Append (aName);
2659 else if (aCtx->NbSelected() > 0)
2661 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2662 anIter.More(); anIter.Next())
2664 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2665 if (!aCtx->IsSelected (anIO))
2670 anIONameList.Append (anIter.Key2());
2675 // Unbind all removed objects from the map of displayed IO.
2676 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2677 anIter.More(); anIter.Next())
2679 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2680 aCtx->Remove (anIO, Standard_False);
2683 theDI << anIter.Value().ToCString() << " was removed\n";
2687 GetMapOfAIS().UnBind2 (anIter.Value());
2691 // Close local context if it is empty
2692 TColStd_MapOfTransient aLocalIO;
2693 if (aCtx->HasOpenedContext()
2694 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2696 aCtx->CloseAllContexts (Standard_False);
2702 //==============================================================================
2704 //purpose : Erase some selected or named objects
2705 // if there is no selected or named objects, the whole viewer is erased
2706 //==============================================================================
2707 int VErase (Draw_Interpretor& theDI,
2708 Standard_Integer theArgNb,
2709 const char** theArgVec)
2711 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2712 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2713 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2716 std::cerr << "Error: no active view!\n";
2720 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2722 Standard_Integer anArgIter = 1;
2723 Standard_Boolean toEraseLocal = Standard_False;
2724 Standard_Boolean toEraseInView = Standard_False;
2725 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2726 for (; anArgIter < theArgNb; ++anArgIter)
2728 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2729 anArgCase.LowerCase();
2730 if (anUpdateTool.parseRedrawMode (anArgCase))
2734 else if (anArgCase == "-local")
2736 toEraseLocal = Standard_True;
2738 else if (anArgCase == "-view"
2739 || anArgCase == "-inview")
2741 toEraseInView = Standard_True;
2745 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2749 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2751 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2755 if (toEraseLocal && !aCtx->HasOpenedContext())
2757 std::cerr << "Error: local selection context is not open.\n";
2760 else if (!toEraseLocal && aCtx->HasOpenedContext())
2762 aCtx->CloseAllContexts (Standard_False);
2765 if (!aNamesOfEraseIO.IsEmpty())
2767 // Erase named objects
2768 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2770 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2771 if (!GetMapOfAIS().IsBound2 (aName))
2776 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2777 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2778 theDI << aName.ToCString() << " ";
2783 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2787 aCtx->Erase (anIO, Standard_False);
2792 else if (!toEraseAll && aCtx->NbSelected() > 0)
2794 // Erase selected objects
2795 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
2796 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2797 anIter.More(); anIter.Next())
2799 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2801 && aCtx->IsSelected (anIO))
2803 theDI << anIter.Key2().ToCString() << " ";
2806 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2808 else if (aHasOpenedContext)
2810 aCtx->Erase (anIO, Standard_False);
2817 aCtx->EraseSelected (Standard_False);
2822 // Erase all objects
2823 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2824 anIter.More(); anIter.Next())
2826 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2831 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2835 aCtx->Erase (anIO, Standard_False);
2844 //==============================================================================
2845 //function : VDisplayAll
2847 //purpose : Display all the objects of the Map
2848 //==============================================================================
2849 static int VDisplayAll (Draw_Interpretor& ,
2850 Standard_Integer theArgNb,
2851 const char** theArgVec)
2854 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2855 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2858 std::cerr << "Error: no active view!\n";
2862 Standard_Integer anArgIter = 1;
2863 Standard_Boolean toDisplayLocal = Standard_False;
2864 for (; anArgIter < theArgNb; ++anArgIter)
2866 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2867 anArgCase.LowerCase();
2868 if (anArgCase == "-local")
2870 toDisplayLocal = Standard_True;
2872 else if (anUpdateTool.parseRedrawMode (anArgCase))
2881 if (anArgIter < theArgNb)
2883 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2887 if (toDisplayLocal && !aCtx->HasOpenedContext())
2889 std::cerr << "Error: local selection context is not open.\n";
2892 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2894 aCtx->CloseLocalContext (Standard_False);
2897 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2898 anIter.More(); anIter.Next())
2900 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2901 aCtx->Erase (aShape, Standard_False);
2904 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2905 anIter.More(); anIter.Next())
2907 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2908 aCtx->Display (aShape, Standard_False);
2913 //! Auxiliary method to find presentation
2914 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2915 const Handle(AIS_InteractiveObject)& theIO,
2916 const Standard_Integer theMode)
2920 return Handle(PrsMgr_Presentation)();
2925 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2927 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2930 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2932 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2934 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2936 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2938 return Handle(PrsMgr_Presentation)();
2941 enum ViewerTest_BndAction
2948 //! Auxiliary method to print bounding box of presentation
2949 inline void bndPresentation (Draw_Interpretor& theDI,
2950 const Handle(PrsMgr_Presentation)& thePrs,
2951 const TCollection_AsciiString& theName,
2952 const ViewerTest_BndAction theAction)
2956 case BndAction_Hide:
2958 thePrs->Presentation()->GraphicUnHighlight();
2961 case BndAction_Show:
2963 Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
2964 aPrs->CStructure()->HighlightColor = Quantity_NOC_GRAY99;
2965 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
2968 case BndAction_Print:
2970 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2971 gp_Pnt aMin = aBox.CornerMin();
2972 gp_Pnt aMax = aBox.CornerMax();
2973 theDI << theName << "\n"
2974 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2975 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2981 //==============================================================================
2982 //function : VBounding
2984 //==============================================================================
2985 int VBounding (Draw_Interpretor& theDI,
2986 Standard_Integer theArgNb,
2987 const char** theArgVec)
2989 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2990 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2993 std::cout << "Error: no active view!\n";
2997 ViewerTest_BndAction anAction = BndAction_Show;
2998 Standard_Integer aMode = -1;
3000 Standard_Integer anArgIter = 1;
3001 for (; anArgIter < theArgNb; ++anArgIter)
3003 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3005 if (anArg == "-print")
3007 anAction = BndAction_Print;
3009 else if (anArg == "-show")
3011 anAction = BndAction_Show;
3013 else if (anArg == "-hide")
3015 anAction = BndAction_Hide;
3017 else if (anArg == "-mode")
3019 if (++anArgIter >= theArgNb)
3021 std::cout << "Error: wrong syntax at " << anArg << "\n";
3024 aMode = Draw::Atoi (theArgVec[anArgIter]);
3026 else if (!anUpdateTool.parseRedrawMode (anArg))
3032 if (anArgIter < theArgNb)
3034 // has a list of names
3035 for (; anArgIter < theArgNb; ++anArgIter)
3037 TCollection_AsciiString aName = theArgVec[anArgIter];
3038 if (!GetMapOfAIS().IsBound2 (aName))
3040 std::cout << "Error: presentation " << aName << " does not exist\n";
3044 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3045 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3048 std::cout << "Error: presentation " << aName << " does not exist\n";
3051 bndPresentation (theDI, aPrs, aName, anAction);
3054 else if (aCtx->NbSelected() > 0)
3056 // remove all currently selected objects
3057 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3059 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3060 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3063 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
3070 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3071 anIter.More(); anIter.Next())
3073 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3074 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3077 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
3084 //==============================================================================
3085 //function : VTexture
3087 //==============================================================================
3088 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
3090 TCollection_AsciiString aCommandName (theArgv[0]);
3092 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3093 if (aCommandName == "vtexture")
3097 std::cout << theArgv[0] << ": invalid arguments.\n";
3098 std::cout << "Type help for more information.\n";
3102 // look for options of vtexture command
3103 TCollection_AsciiString aParseKey;
3104 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3106 TCollection_AsciiString anArg (theArgv [anArgIt]);
3109 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3112 aParseKey.Remove (1);
3113 aParseKey.UpperCase();
3114 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3118 if (aParseKey.IsEmpty())
3123 aMapOfArgs(aParseKey)->Append (anArg);
3126 else if (aCommandName == "vtexscale"
3127 || aCommandName == "vtexorigin"
3128 || aCommandName == "vtexrepeat")
3130 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3131 // equal to -scale, -origin, -repeat options of vtexture command
3132 if (theArgsNb < 2 || theArgsNb > 4)
3134 std::cout << theArgv[0] << ": invalid arguments.\n";
3135 std::cout << "Type help for more information.\n";
3139 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
3142 anArgs->Append ("OFF");
3144 else if (theArgsNb == 4)
3146 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3147 anArgs->Append (TCollection_AsciiString (theArgv[3]));
3150 TCollection_AsciiString anArgKey;
3151 if (aCommandName == "vtexscale")
3155 else if (aCommandName == "vtexorigin")
3157 anArgKey = "ORIGIN";
3161 anArgKey = "REPEAT";
3164 aMapOfArgs.Bind (anArgKey, anArgs);
3166 else if (aCommandName == "vtexdefault")
3168 // scan for parameters of vtexdefault command
3169 // equal to -default option of vtexture command
3170 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
3173 // Check arguments for validity
3174 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3175 for (; aMapIt.More(); aMapIt.Next())
3177 const TCollection_AsciiString& aKey = aMapIt.Key();
3178 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3180 // -scale, -origin, -repeat: one argument "off", or two real values
3181 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3182 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3183 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3188 // -modulate: single argument "on" / "off"
3189 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3194 // -default: no arguments
3195 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3200 TCollection_AsciiString aLowerKey;
3203 aLowerKey.LowerCase();
3204 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3205 std::cout << "Type help for more information.\n";
3209 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3210 if (anAISContext.IsNull())
3212 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
3216 Standard_Integer aPreviousMode = 0;
3218 TCollection_AsciiString aShapeName (theArgv[1]);
3219 Handle(AIS_InteractiveObject) anIO;
3221 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3222 if (aMapOfIO.IsBound2 (aShapeName))
3224 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3229 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3233 Handle(AIS_TexturedShape) aTexturedIO;
3234 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3236 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3237 aPreviousMode = aTexturedIO->DisplayMode();
3241 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3243 if (anIO->HasTransformation())
3245 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3246 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3249 anAISContext->Remove (anIO, Standard_False);
3250 GetMapOfAIS().UnBind1 (anIO);
3251 GetMapOfAIS().UnBind2 (aShapeName);
3252 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3255 // -------------------------------------------
3256 // Turn texturing on/off - only for vtexture
3257 // -------------------------------------------
3259 if (aCommandName == "vtexture")
3261 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3263 if (aTextureArg.IsEmpty())
3265 std::cout << aCommandName << ": Texture mapping disabled.\n";
3266 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
3268 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3269 if (aPreviousMode == 3)
3271 anAISContext->RecomputePrsOnly (aTexturedIO);
3274 anAISContext->Display (aTexturedIO, Standard_True);
3277 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3279 if (aTextureArg == "?")
3281 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3283 theDi << "\n Files in current directory : \n\n";
3284 theDi.Eval ("glob -nocomplain *");
3286 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3287 aCmnd += aTextureFolder;
3290 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
3291 theDi.Eval (aCmnd.ToCString());
3296 aTexturedIO->SetTextureFileName (aTextureArg);
3301 // ------------------------------------
3302 // Process other options and commands
3303 // ------------------------------------
3305 Handle(TColStd_HSequenceOfAsciiString) aValues;
3306 if (aMapOfArgs.Find ("DEFAULT", aValues))
3308 aTexturedIO->SetTextureRepeat (Standard_False);
3309 aTexturedIO->SetTextureOrigin (Standard_False);
3310 aTexturedIO->SetTextureScale (Standard_False);
3311 aTexturedIO->EnableTextureModulate();
3315 if (aMapOfArgs.Find ("SCALE", aValues))
3317 if (aValues->Value(1) != "OFF")
3319 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3323 aTexturedIO->SetTextureScale (Standard_False);
3327 if (aMapOfArgs.Find ("ORIGIN", aValues))
3329 if (aValues->Value(1) != "OFF")
3331 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3335 aTexturedIO->SetTextureOrigin (Standard_False);
3339 if (aMapOfArgs.Find ("REPEAT", aValues))
3341 if (aValues->Value(1) != "OFF")
3343 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3347 aTexturedIO->SetTextureRepeat (Standard_False);
3351 if (aMapOfArgs.Find ("MODULATE", aValues))
3353 if (aValues->Value(1) == "ON")
3355 aTexturedIO->EnableTextureModulate();
3359 aTexturedIO->DisableTextureModulate();
3364 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3366 anAISContext->RecomputePrsOnly (aTexturedIO);
3370 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3371 anAISContext->Display (aTexturedIO, Standard_True);
3372 anAISContext->Update (aTexturedIO,Standard_True);
3378 //! Auxiliary method to parse transformation persistence flags
3379 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3380 Standard_Integer& theFlags)
3382 if (theFlagString == "pan")
3384 theFlags |= Graphic3d_TMF_PanPers;
3386 else if (theFlagString == "zoom")
3388 theFlags |= Graphic3d_TMF_ZoomPers;
3390 else if (theFlagString == "rotate")
3392 theFlags |= Graphic3d_TMF_RotatePers;
3394 else if (theFlagString == "trihedron")
3396 theFlags = Graphic3d_TMF_TriedronPers;
3398 else if (theFlagString == "full")
3400 theFlags = Graphic3d_TMF_FullPers;
3402 else if (theFlagString == "none")
3404 theFlags = Graphic3d_TMF_None;
3408 return Standard_False;
3411 return Standard_True;
3414 //==============================================================================
3415 //function : VDisplay2
3417 //purpose : Display an object from its name
3418 //==============================================================================
3419 static int VDisplay2 (Draw_Interpretor& theDI,
3420 Standard_Integer theArgNb,
3421 const char** theArgVec)
3425 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3429 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3432 ViewerTest::ViewerInit();
3433 aCtx = ViewerTest::GetAISContext();
3436 // Parse input arguments
3437 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3438 Standard_Integer isMutable = -1;
3439 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3440 Standard_Boolean toDisplayLocal = Standard_False;
3441 Standard_Boolean toReDisplay = Standard_False;
3442 Standard_Integer isSelectable = -1;
3443 Standard_Integer anObjDispMode = -2;
3444 Standard_Integer anObjHighMode = -2;
3445 Standard_Boolean toSetTrsfPers = Standard_False;
3446 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3448 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3449 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3450 Standard_Integer toDisplayInView = Standard_False;
3451 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3453 const TCollection_AsciiString aName = theArgVec[anArgIter];
3454 TCollection_AsciiString aNameCase = aName;
3455 aNameCase.LowerCase();
3456 if (anUpdateTool.parseRedrawMode (aName))
3460 else if (aNameCase == "-mutable")
3464 else if (aNameCase == "-neutral")
3466 aDispStatus = AIS_DS_Displayed;
3468 else if (aNameCase == "-immediate"
3469 || aNameCase == "-top")
3471 aZLayer = Graphic3d_ZLayerId_Top;
3473 else if (aNameCase == "-topmost")
3475 aZLayer = Graphic3d_ZLayerId_Topmost;
3477 else if (aNameCase == "-osd"
3478 || aNameCase == "-toposd"
3479 || aNameCase == "-overlay")
3481 aZLayer = Graphic3d_ZLayerId_TopOSD;
3483 else if (aNameCase == "-botosd"
3484 || aNameCase == "-underlay")
3486 aZLayer = Graphic3d_ZLayerId_BotOSD;
3488 else if (aNameCase == "-select"
3489 || aNameCase == "-selectable")
3493 else if (aNameCase == "-noselect"
3494 || aNameCase == "-noselection")
3498 else if (aNameCase == "-dispmode"
3499 || aNameCase == "-displaymode")
3501 if (++anArgIter >= theArgNb)
3503 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3507 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3509 else if (aNameCase == "-highmode"
3510 || aNameCase == "-highlightmode")
3512 if (++anArgIter >= theArgNb)
3514 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3518 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3520 else if (aNameCase == "-3d")
3522 toSetTrsfPers = Standard_True;
3523 aTrsfPersFlags = Graphic3d_TMF_None;
3525 else if (aNameCase == "-2d")
3527 toSetTrsfPers = Standard_True;
3528 aTrsfPersFlags = Graphic3d_TMF_2d;
3530 else if (aNameCase == "-trsfpers"
3531 || aNameCase == "-pers")
3533 if (++anArgIter >= theArgNb)
3535 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3539 toSetTrsfPers = Standard_True;
3540 aTrsfPersFlags = Graphic3d_TMF_None;
3541 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3542 aPersFlags.LowerCase();
3543 for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
3545 if (aParserPos == -1)
3547 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3549 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3555 TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
3556 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3558 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3561 aPersFlags = anOtherFlags;
3564 else if (aNameCase == "-trsfperspos"
3565 || aNameCase == "-perspos")
3567 if (anArgIter + 2 >= theArgNb)
3569 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3573 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3574 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3575 TCollection_AsciiString aZ = "0";
3576 if (!aX.IsIntegerValue()
3577 || !aY.IsIntegerValue())
3579 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3582 if (anArgIter + 1 < theArgNb)
3584 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3585 if (aTemp.IsIntegerValue())
3591 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
3593 else if (aNameCase == "-layer")
3595 if (++anArgIter >= theArgNb)
3597 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3601 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3602 if (!aValue.IsIntegerValue())
3604 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3608 aZLayer = aValue.IntegerValue();
3610 else if (aNameCase == "-view"
3611 || aNameCase == "-inview")
3613 toDisplayInView = Standard_True;
3615 else if (aNameCase == "-local")
3617 aDispStatus = AIS_DS_Temporary;
3618 toDisplayLocal = Standard_True;
3620 else if (aNameCase == "-redisplay")
3622 toReDisplay = Standard_True;
3626 aNamesOfDisplayIO.Append (aName);
3630 if (aNamesOfDisplayIO.IsEmpty())
3632 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3636 // Prepare context for display
3637 if (toDisplayLocal && !aCtx->HasOpenedContext())
3639 aCtx->OpenLocalContext (Standard_False);
3641 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3643 aCtx->CloseAllContexts (Standard_False);
3646 // Display interactive objects
3647 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3649 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3651 if (!GetMapOfAIS().IsBound2 (aName))
3653 // create the AIS_Shape from a name
3654 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3655 if (!aShape.IsNull())
3657 if (isMutable != -1)
3659 aShape->SetMutable (isMutable == 1);
3661 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3663 aShape->SetZLayer (aZLayer);
3667 aCtx->SetTransformPersistence (aShape, aTrsfPersFlags, aTPPosition);
3669 if (anObjDispMode != -2)
3671 aShape->SetDisplayMode (anObjDispMode);
3673 if (anObjHighMode != -2)
3675 aShape->SetHilightMode (anObjHighMode);
3677 if (!toDisplayLocal)
3678 GetMapOfAIS().Bind (aShape, aName);
3680 Standard_Integer aDispMode = aShape->HasDisplayMode()
3681 ? aShape->DisplayMode()
3682 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3683 ? aCtx->DisplayMode()
3685 Standard_Integer aSelMode = -1;
3686 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3688 aSelMode = aShape->GlobalSelectionMode();
3691 aCtx->Display (aShape, aDispMode, aSelMode,
3692 Standard_False, aShape->AcceptShapeDecomposition(),
3694 if (toDisplayInView)
3696 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3698 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3700 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3705 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3710 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3711 if (isMutable != -1)
3713 aShape->SetMutable (isMutable == 1);
3715 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3717 aShape->SetZLayer (aZLayer);
3721 aCtx->SetTransformPersistence (aShape, aTrsfPersFlags, aTPPosition);
3723 if (anObjDispMode != -2)
3725 aShape->SetDisplayMode (anObjDispMode);
3727 if (anObjHighMode != -2)
3729 aShape->SetHilightMode (anObjHighMode);
3731 Standard_Integer aDispMode = aShape->HasDisplayMode()
3732 ? aShape->DisplayMode()
3733 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3734 ? aCtx->DisplayMode()
3736 Standard_Integer aSelMode = -1;
3737 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3739 aSelMode = aShape->GlobalSelectionMode();
3742 if (aShape->Type() == AIS_KOI_Datum)
3744 aCtx->Display (aShape, Standard_False);
3748 theDI << "Display " << aName.ToCString() << "\n";
3750 // update the Shape in the AIS_Shape
3751 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3752 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3753 if (!aShapePrs.IsNull())
3755 if (!aShapePrs->Shape().IsEqual (aNewShape))
3757 toReDisplay = Standard_True;
3759 aShapePrs->Set (aNewShape);
3763 aCtx->Redisplay (aShape, Standard_False);
3768 aCtx->Erase (aShape);
3770 aCtx->Display (aShape, aDispMode, aSelMode,
3771 Standard_False, aShape->AcceptShapeDecomposition(),
3773 if (toDisplayInView)
3775 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3783 //===============================================================================================
3784 //function : VUpdate
3786 //===============================================================================================
3787 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3789 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3790 if (aContextAIS.IsNull())
3792 std::cout << theArgVec[0] << "AIS context is not available.\n";
3798 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3802 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3804 AIS_ListOfInteractive aListOfIO;
3806 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3808 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3810 Handle(AIS_InteractiveObject) anAISObj;
3811 if (anAISMap.IsBound2 (aName))
3813 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3816 if (anAISObj.IsNull())
3818 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3822 aListOfIO.Append (anAISObj);
3825 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3826 for (; anIOIt.More(); anIOIt.Next())
3828 aContextAIS->Update (anIOIt.Value(), Standard_False);
3831 aContextAIS->UpdateCurrentViewer();
3836 //==============================================================================
3838 //purpose : Test the annimation of an object along a
3839 // predifined trajectory
3840 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3841 //==============================================================================
3843 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3846 if (TheAISContext()->HasOpenedContext())
3847 TheAISContext()->CloseLocalContext();
3849 Standard_Real Step=4*M_PI/180;
3850 Standard_Real Angle=0;
3852 Handle(AIS_InteractiveObject) aIO;
3853 if (GetMapOfAIS().IsBound2(argv[1]))
3854 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3858 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3862 if (Draw::Atoi(argv[3])==1 ) {
3863 di<<" Primitives sensibles OFF\n";
3864 TheAISContext()->Deactivate(aIO);
3867 di<<" Primitives sensibles ON\n";
3869 // Movement par transformation
3870 if(Draw::Atoi(argv[2]) ==1) {
3871 di<<" Calcul par Transformation\n";
3872 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3876 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3877 TheAISContext()->SetLocation(aShape,myTransfo);
3878 TheAISContext() ->UpdateCurrentViewer();
3883 di<<" Calcul par Locations\n";
3884 gp_Trsf myAngleTrsf;
3885 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3886 TopLoc_Location myDeltaAngle (myAngleTrsf);
3887 TopLoc_Location myTrueLoc;
3889 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3892 myTrueLoc=myTrueLoc*myDeltaAngle;
3893 TheAISContext()->SetLocation(aShape,myTrueLoc );
3894 TheAISContext() ->UpdateCurrentViewer();
3897 if (Draw::Atoi(argv[3])==1 ){
3898 // On reactive la selection des primitives sensibles
3899 TheAISContext()->Activate(aIO,0);
3901 a3DView() -> Redraw();
3903 di<<" Temps ecoule \n";
3909 //==================================================================================
3910 // Function : VAnimation
3911 //==================================================================================
3912 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3914 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile\n";
3918 Standard_Real thread = 4;
3919 Standard_Real angleA=0;
3920 Standard_Real angleB;
3922 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3925 TopoDS_Shape CrankArm;
3926 TopoDS_Shape CylinderHead;
3927 TopoDS_Shape Propeller;
3928 TopoDS_Shape EngineBlock;
3930 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3931 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3932 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3933 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3934 BRepTools::Read(CrankArm,argv[1],B);
3935 BRepTools::Read(CylinderHead,argv[2],B);
3936 BRepTools::Read(Propeller,argv[3],B);
3937 BRepTools::Read(EngineBlock,argv[4],B);
3939 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure.\n";}
3945 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3946 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3947 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3948 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3950 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3951 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3952 GetMapOfAIS().Bind(myAisCrankArm,"c");
3953 GetMapOfAIS().Bind(myAisPropeller,"d");
3955 myAisCylinderHead->SetMutable (Standard_True);
3956 myAisEngineBlock ->SetMutable (Standard_True);
3957 myAisCrankArm ->SetMutable (Standard_True);
3958 myAisPropeller ->SetMutable (Standard_True);
3960 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3961 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3962 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3964 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3965 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3966 TheAISContext()->Display (myAisCrankArm, Standard_False);
3967 TheAISContext()->Display (myAisPropeller, Standard_False);
3969 TheAISContext()->Deactivate(myAisCylinderHead);
3970 TheAISContext()->Deactivate(myAisEngineBlock );
3971 TheAISContext()->Deactivate(myAisCrankArm );
3972 TheAISContext()->Deactivate(myAisPropeller );
3974 // Boucle de mouvement
3975 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3977 angleA = thread*myAngle*M_PI/180;
3978 X = Sin(angleA)*3/8;
3979 angleB = atan(X / Sqrt(-X * X + 1));
3980 Standard_Real decal(25*0.6);
3983 //Build a transformation on the display
3984 gp_Trsf aPropellerTrsf;
3985 aPropellerTrsf.SetRotation(Ax1,angleA);
3986 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3988 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));
3989 gp_Trsf aCrankArmTrsf;
3990 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3991 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3993 TheAISContext()->UpdateCurrentViewer();
3996 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3997 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3999 myAisCrankArm ->ResetTransformation();
4000 myAisPropeller->ResetTransformation();
4002 myAisCrankArm -> Set(myNewCrankArm );
4003 myAisPropeller -> Set(myNewPropeller);
4005 TheAISContext()->Activate(myAisCylinderHead,0);
4006 TheAISContext()->Activate(myAisEngineBlock,0 );
4007 TheAISContext()->Activate(myAisCrankArm ,0 );
4008 TheAISContext()->Activate(myAisPropeller ,0 );
4014 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
4015 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
4017 TheAISContext()->UpdateCurrentViewer();
4018 a3DView()->Redraw();
4027 //==============================================================================
4028 //function : VShading
4029 //purpose : Sharpen or roughten the quality of the shading
4030 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4031 //==============================================================================
4032 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4034 Standard_Real myDevCoef;
4035 Handle(AIS_InteractiveObject) TheAisIO;
4038 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4040 if (TheAISContext()->HasOpenedContext())
4041 TheAISContext()->CloseLocalContext();
4046 myDevCoef =Draw::Atof(argv[2]);
4049 TCollection_AsciiString name=argv[1];
4050 if (GetMapOfAIS().IsBound2(name ))
4051 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4052 if (TheAisIO.IsNull())
4053 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4056 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4058 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4060 TheAISContext()->Redisplay(TheAisIO);
4063 //==============================================================================
4064 //function : HaveMode
4065 //use : VActivatedModes
4066 //==============================================================================
4067 #include <TColStd_ListIteratorOfListOfInteger.hxx>
4069 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
4071 TColStd_ListOfInteger List;
4072 TheAISContext()->ActivatedModes (TheAisIO,List);
4073 TColStd_ListIteratorOfListOfInteger it;
4074 Standard_Boolean Found=Standard_False;
4075 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4076 if (it.Value()==mode ) Found=Standard_True;
4083 //==============================================================================
4084 //function : VActivatedMode
4086 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
4087 // (edges,vertex...)qui lui est propre et le mode de selection standard.
4088 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4089 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4090 // qu'un nom et qu'un mode.
4091 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4092 //==============================================================================
4093 #include <AIS_ListIteratorOfListOfInteractive.hxx>
4095 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4098 Standard_Boolean ThereIsName = Standard_False ;
4100 if(!a3DView().IsNull()){
4102 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
4103 // verification des arguments
4105 if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
4106 ThereIsName = (argc == 3);
4110 if (argc>1) {di<<" Syntaxe error\n";return 1;}
4112 di<<" R.A.Z de tous les modes de selecion\n";
4113 di<<" Fermeture du Context local\n";
4114 if (TheAISContext()->HasOpenedContext())
4115 TheAISContext()->CloseLocalContext();
4119 // IL n'y a aps de nom de shape passe en argument
4120 if (HaveToSet && !ThereIsName){
4121 Standard_Integer aMode=Draw::Atoi(argv [1]);
4123 const char *cmode="???";
4125 case 0: cmode = "Shape"; break;
4126 case 1: cmode = "Vertex"; break;
4127 case 2: cmode = "Edge"; break;
4128 case 3: cmode = "Wire"; break;
4129 case 4: cmode = "Face"; break;
4130 case 5: cmode = "Shell"; break;
4131 case 6: cmode = "Solid"; break;
4132 case 7: cmode = "Compound"; break;
4135 if( !TheAISContext()->HasOpenedContext() ) {
4136 // il n'y a pas de Context local d'ouvert
4137 // on en ouvre un et on charge toutes les shapes displayees
4138 // on load tous les objets displayees et on Activate les objets de la liste
4139 AIS_ListOfInteractive ListOfIO;
4140 // on sauve dans une AISListOfInteractive tous les objets currents
4141 if (TheAISContext()->NbSelected()>0 ){
4142 TheAISContext()->UnhilightSelected(Standard_False);
4144 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4145 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
4149 TheAISContext()->OpenLocalContext(Standard_False);
4150 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4153 Handle(AIS_InteractiveObject) aIO =
4154 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4156 TheAISContext()->Load(aIO,0,Standard_False);
4159 // traitement des objets qui etaient currents dans le Contexte global
4160 if (!ListOfIO.IsEmpty() ) {
4161 // il y avait des objets currents
4162 AIS_ListIteratorOfListOfInteractive iter;
4163 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4164 Handle(AIS_InteractiveObject) aIO=iter.Value();
4165 TheAISContext()->Activate(aIO,aMode);
4166 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4170 // On applique le mode a tous les objets displayes
4171 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4172 it2 (GetMapOfAIS());
4174 Handle(AIS_InteractiveObject) aIO =
4175 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4176 if (!aIO.IsNull()) {
4177 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4178 TheAISContext()->Activate(aIO,aMode);
4187 // un Context local est deja ouvert
4188 // Traitement des objets du Context local
4189 if (TheAISContext()->NbSelected()>0 ){
4190 TheAISContext()->UnhilightSelected(Standard_False);
4191 // il y a des objets selected,on les parcourt
4192 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4193 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
4196 if (HaveMode(aIO,aMode) ) {
4197 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4198 TheAISContext()->Deactivate(aIO,aMode);
4201 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4202 TheAISContext()->Activate(aIO,aMode);
4208 // il n'y a pas d'objets selected
4209 // tous les objets diplayes sont traites
4210 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4213 Handle(AIS_InteractiveObject) aIO =
4214 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4215 if (!aIO.IsNull()) {
4216 if (HaveMode(aIO,aMode) ) {
4217 di<<" Mode: "<<cmode<<" OFF pour "
4218 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4219 TheAISContext()->Deactivate(aIO,aMode);
4222 di<<" Mode: "<<cmode<<" ON pour"
4223 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4224 TheAISContext()->Activate(aIO,aMode);
4232 else if (HaveToSet && ThereIsName){
4233 Standard_Integer aMode=Draw::Atoi(argv [2]);
4234 Handle(AIS_InteractiveObject) aIO =
4235 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4237 if (!aIO.IsNull()) {
4238 const char *cmode="???";
4241 case 0: cmode = "Shape"; break;
4242 case 1: cmode = "Vertex"; break;
4243 case 2: cmode = "Edge"; break;
4244 case 3: cmode = "Wire"; break;
4245 case 4: cmode = "Face"; break;
4246 case 5: cmode = "Shell"; break;
4247 case 6: cmode = "Solid"; break;
4248 case 7: cmode = "Compound"; break;
4251 if( !TheAISContext()->HasOpenedContext() ) {
4252 TheAISContext()->OpenLocalContext(Standard_False);
4253 // On charge tous les objets de la map
4254 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4256 Handle(AIS_InteractiveObject) aShape=
4257 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4258 if (!aShape.IsNull())
4259 TheAISContext()->Load(aShape,0,Standard_False);
4262 TheAISContext()->Activate(aIO,aMode);
4263 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4267 // un Context local est deja ouvert
4268 if (HaveMode(aIO,aMode) ) {
4269 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4270 TheAISContext()->Deactivate(aIO,aMode);
4273 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4274 TheAISContext()->Activate(aIO,aMode);
4283 //! Auxiliary method to print Interactive Object information
4284 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4285 const Handle(Standard_Transient)& theObject,
4286 Draw_Interpretor& theDI)
4288 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4291 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4295 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4296 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4297 << (theDetected.Contains (anObj) ? " Detected" : " ")
4299 if (anObj->Type() == AIS_KOI_Datum)
4302 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4303 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4304 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4305 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4306 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4307 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4308 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4311 else if (anObj->Type() == AIS_KOI_Shape
4312 && anObj->Signature() == 0)
4314 theDI << " AIS_Shape";
4316 else if (anObj->Type() == AIS_KOI_Relation)
4318 // AIS_Dimention and AIS_Relation
4319 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4320 switch (aRelation->KindOfDimension())
4322 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4323 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4324 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4325 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4326 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4327 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4328 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4329 default: theDI << " UNKNOWN dimension"; break;
4334 theDI << " UserPrs";
4336 theDI << " (" << theObject->DynamicType()->Name() << ")";
4339 //! Print information about locally selected sub-shapes
4340 template <typename T>
4341 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4343 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4344 TCollection_AsciiString aPrevName;
4345 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4347 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4348 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4349 if (aShapeIO.IsNull() || anOwner.IsNull())
4353 if (anOwner == aShapeIO->GlobalSelOwner())
4356 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4357 if (aSubShape.IsNull()
4358 || aShapeIO.IsNull()
4359 || !GetMapOfAIS().IsBound1 (aShapeIO))
4364 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4365 TopTools_MapOfShape aFilter;
4366 Standard_Integer aNumber = 0;
4367 const TopoDS_Shape aShape = aShapeIO->Shape();
4368 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4369 anIter.More(); anIter.Next())
4371 if (!aFilter.Add (anIter.Current()))
4373 continue; // filter duplicates
4377 if (!anIter.Current().IsSame (aSubShape))
4382 Standard_CString aShapeName = NULL;
4383 switch (aSubShape.ShapeType())
4385 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4386 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4387 case TopAbs_SOLID: aShapeName = " Solid"; break;
4388 case TopAbs_SHELL: aShapeName = " Shell"; break;
4389 case TopAbs_FACE: aShapeName = " Face"; break;
4390 case TopAbs_WIRE: aShapeName = " Wire"; break;
4391 case TopAbs_EDGE: aShapeName = " Edge"; break;
4392 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4394 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4397 if (aParentName != aPrevName)
4399 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4400 aPrevName = aParentName;
4402 theDI << " " << aShapeName << " #" << aNumber << "\n";
4408 //==============================================================================
4411 //==============================================================================
4412 static Standard_Integer VState (Draw_Interpretor& theDI,
4413 Standard_Integer theArgNb,
4414 Standard_CString* theArgVec)
4416 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4419 std::cerr << "Error: No opened viewer!\n";
4423 Standard_Boolean toPrintEntities = Standard_False;
4424 Standard_Boolean toCheckSelected = Standard_False;
4426 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4428 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4429 anOption.LowerCase();
4430 if (anOption == "-detectedentities"
4431 || anOption == "-entities")
4433 toPrintEntities = Standard_True;
4435 else if (anOption == "-hasselected")
4437 toCheckSelected = Standard_True;
4441 if (toCheckSelected)
4443 aCtx->InitSelected();
4444 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4445 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4450 if (toPrintEntities)
4452 theDI << "Detected entities:\n";
4453 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4454 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4455 for (aSelector->InitDetected(); aSelector->MoreDetected(); aSelector->NextDetected())
4457 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->DetectedEntity();
4458 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4459 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4461 if (anObj->TransformPersistence().Flags)
4463 const Graphic3d_Mat4d& aProjection = aMgr.ProjectionMatrix();
4464 const Graphic3d_Mat4d& aWorldView = aMgr.WorldViewMatrix();
4466 Standard_Integer aViewportWidth = 0;
4467 Standard_Integer aViewportHeight = 0;
4468 aMgr.WindowSize (aViewportWidth, aViewportHeight);
4470 Graphic3d_Mat4d aMat = anObj->TransformPersistence().Compute (aMgr.Camera(), aProjection, aWorldView, aViewportWidth, aViewportHeight);
4472 anInvTrsf.SetValue (1, 1, aMat.GetValue (0, 0));
4473 anInvTrsf.SetValue (1, 2, aMat.GetValue (0, 1));
4474 anInvTrsf.SetValue (1, 3, aMat.GetValue (0, 2));
4475 anInvTrsf.SetValue (2, 1, aMat.GetValue (1, 0));
4476 anInvTrsf.SetValue (2, 2, aMat.GetValue (1, 1));
4477 anInvTrsf.SetValue (2, 3, aMat.GetValue (1, 2));
4478 anInvTrsf.SetValue (3, 1, aMat.GetValue (2, 0));
4479 anInvTrsf.SetValue (3, 2, aMat.GetValue (2, 1));
4480 anInvTrsf.SetValue (3, 3, aMat.GetValue (2, 2));
4481 anInvTrsf.SetTranslationPart (gp_XYZ(aMat.GetValue (0, 3), aMat.GetValue (1, 3), aMat.GetValue (2, 3)));
4484 if (anObj->HasTransformation())
4486 anInvTrsf = anObj->InversedTransformation() * anInvTrsf;
4488 if (anEntity->HasInitLocation())
4490 anInvTrsf = anEntity->InvInitLocation() * anInvTrsf;
4492 const Standard_Integer aScale = anEntity->SensitivityFactor() < aSelector->PixelTolerance()
4493 ? anEntity->SensitivityFactor() : 1;
4494 const Standard_Boolean isToScaleAndTransform = anInvTrsf.Form() != gp_Identity || aScale != 1;
4495 SelectMgr_SelectingVolumeManager anEntMgr =
4496 isToScaleAndTransform ? aMgr.ScaleAndTransform (aScale, anInvTrsf)
4498 SelectBasics_PickResult aResult;
4499 anEntity->Matches (anEntMgr, aResult);
4501 gp_Pnt aDetectedPnt = anEntMgr.DetectedPoint (aResult.Depth());
4503 if (anInvTrsf.Form() != gp_Identity)
4505 anInvTrsf.Inverted().Transforms (aDetectedPnt.ChangeCoord());
4508 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4509 aName.LeftJustify (20, ' ');
4510 char anInfoStr[512];
4512 " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
4514 aResult.DistToGeomCenter(),
4515 aDetectedPnt.X(), aDetectedPnt.Y(), aDetectedPnt.Z());
4516 theDI << " " << aName
4518 << " (" << anEntity->DynamicType()->Name() << ")"
4521 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4522 if (!aBRepOwner.IsNull())
4524 theDI << " Detected Shape: "
4525 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4529 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4530 if (!aWire.IsNull())
4532 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4533 theDI << " Detected Child: "
4534 << aSen->DynamicType()->Name()
4538 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4539 if (!aPrimArr.IsNull())
4541 theDI << " Detected Element: "
4542 << aPrimArr->LastDetectedElement()
4549 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4550 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4552 aDetected.Add (aCtx->DetectedCurrentObject());
4555 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4559 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4561 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4562 if (!GetMapOfAIS().IsBound2 (anObjName))
4564 theDI << anObjName << " doesn't exist!\n";
4568 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4569 TCollection_AsciiString aName = anObjName;
4570 aName.LeftJustify (20, ' ');
4571 theDI << " " << aName << " ";
4572 objInfo (aDetected, anObjTrans, theDI);
4578 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4580 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4581 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4583 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4584 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4585 // handle whole object selection
4586 if (anOwner == anObj->GlobalSelOwner())
4588 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4589 aName.LeftJustify (20, ' ');
4590 theDI << aName << " ";
4591 objInfo (aDetected, anObj, theDI);
4596 // process selected sub-shapes
4597 printLocalSelectionInfo (aCtx, theDI);
4602 theDI << "Neutral-point state:\n";
4603 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4604 anObjIter.More(); anObjIter.Next())
4606 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4612 TCollection_AsciiString aName = anObjIter.Key2();
4613 aName.LeftJustify (20, ' ');
4614 theDI << " " << aName << " ";
4615 objInfo (aDetected, anObj, theDI);
4618 printLocalSelectionInfo (aCtx, theDI);
4619 if (aCtx->HasOpenedContext())
4620 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
4624 //=======================================================================
4625 //function : PickObjects
4627 //=======================================================================
4628 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4629 const AIS_KindOfInteractive TheType,
4630 const Standard_Integer TheSignature,
4631 const Standard_Integer MaxPick)
4633 Handle(AIS_InteractiveObject) IO;
4634 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4636 // step 1: prepare the data
4638 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4639 TheAISContext()->AddFilter(F1);
4642 // step 2 : wait for the selection...
4643 Standard_Integer NbPickGood (0),NbToReach(arr->Length());
4644 Standard_Integer NbPickFail(0);
4645 Standard_Integer argccc = 5;
4646 const char *bufff[] = { "A", "B", "C","D", "E" };
4647 const char **argvvv = (const char **) bufff;
4650 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4651 while(ViewerMainLoop(argccc,argvvv)){}
4652 Standard_Integer NbStored = TheAISContext()->NbSelected();
4653 if(NbStored != NbPickGood)
4654 NbPickGood= NbStored;
4657 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4660 // step3 get result.
4662 if (NbPickFail >= NbToReach)
4663 return Standard_False;
4665 Standard_Integer i(0);
4666 for(TheAISContext()->InitSelected();
4667 TheAISContext()->MoreSelected();
4668 TheAISContext()->NextSelected()){
4670 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4671 arr->SetValue(i,IO2);
4676 TheAISContext()->CloseLocalContext(curindex);
4678 return Standard_True;
4682 //=======================================================================
4683 //function : PickObject
4685 //=======================================================================
4686 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4687 const Standard_Integer TheSignature,
4688 const Standard_Integer MaxPick)
4690 Handle(AIS_InteractiveObject) IO;
4691 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4693 // step 1: prepare the data
4696 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4697 TheAISContext()->AddFilter(F1);
4700 // step 2 : wait for the selection...
4701 Standard_Boolean IsGood (Standard_False);
4702 Standard_Integer NbPick(0);
4703 Standard_Integer argccc = 5;
4704 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4705 const char **argvvv = (const char **) bufff;
4708 while(!IsGood && NbPick<= MaxPick){
4709 while(ViewerMainLoop(argccc,argvvv)){}
4710 IsGood = (TheAISContext()->NbSelected()>0) ;
4712 cout<<"Nb Pick :"<<NbPick<<endl;
4716 // step3 get result.
4718 TheAISContext()->InitSelected();
4719 IO = TheAISContext()->SelectedInteractive();
4723 TheAISContext()->CloseLocalContext(curindex);
4727 //=======================================================================
4728 //function : PickShape
4729 //purpose : First Activate the rightmode + Put Filters to be able to
4730 // pick objets that are of type <TheType>...
4731 //=======================================================================
4733 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4734 const Standard_Integer MaxPick)
4737 // step 1: prepare the data
4739 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4740 TopoDS_Shape result;
4742 if(TheType==TopAbs_SHAPE){
4743 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4744 TheAISContext()->AddFilter(F1);
4747 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4748 TheAISContext()->AddFilter(TF);
4749 TheAISContext()->ActivateStandardMode(TheType);
4754 // step 2 : wait for the selection...
4755 Standard_Boolean NoShape (Standard_True);
4756 Standard_Integer NbPick(0);
4757 Standard_Integer argccc = 5;
4758 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4759 const char **argvvv = (const char **) bufff;
4762 while(NoShape && NbPick<= MaxPick){
4763 while(ViewerMainLoop(argccc,argvvv)){}
4764 NoShape = (TheAISContext()->NbSelected()==0) ;
4766 cout<<"Nb Pick :"<<NbPick<<endl;
4769 // step3 get result.
4773 TheAISContext()->InitSelected();
4774 if(TheAISContext()->HasSelectedShape())
4775 result = TheAISContext()->SelectedShape();
4777 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4778 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
4783 TheAISContext()->CloseLocalContext(curindex);
4789 //=======================================================================
4790 //function : PickShapes
4792 //=======================================================================
4793 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4794 Handle(TopTools_HArray1OfShape)& thearr,
4795 const Standard_Integer MaxPick)
4798 Standard_Integer Taille = thearr->Length();
4800 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4802 // step 1: prepare the data
4803 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4804 if(TheType==TopAbs_SHAPE){
4805 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4806 TheAISContext()->AddFilter(F1);
4809 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4810 TheAISContext()->AddFilter(TF);
4811 TheAISContext()->ActivateStandardMode(TheType);
4815 // step 2 : wait for the selection...
4816 Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
4817 Standard_Integer NbPickFail(0);
4818 Standard_Integer argccc = 5;
4819 const char *bufff[] = { "A", "B", "C","D", "E" };
4820 const char **argvvv = (const char **) bufff;
4823 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4824 while(ViewerMainLoop(argccc,argvvv)){}
4825 Standard_Integer NbStored = TheAISContext()->NbSelected();
4826 if (NbStored != NbPickGood)
4827 NbPickGood= NbStored;
4830 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4833 // step3 get result.
4835 if (NbPickFail >= NbToReach)
4836 return Standard_False;
4838 Standard_Integer i(0);
4839 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4841 if(TheAISContext()->HasSelectedShape())
4842 thearr->SetValue(i,TheAISContext()->SelectedShape());
4844 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4845 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
4849 TheAISContext()->CloseLocalContext(curindex);
4850 return Standard_True;
4854 //=======================================================================
4855 //function : VPickShape
4857 //=======================================================================
4858 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4860 TopoDS_Shape PickSh;
4861 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4864 theType = TopAbs_SHAPE;
4866 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4867 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4868 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4869 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4870 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4871 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4872 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4875 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4876 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4878 TCollection_AsciiString name;
4881 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4883 PickSh = ViewerTest::PickShape(theType);
4892 if(!PickSh.IsNull()){
4893 nbOfSub[Standard_Integer(theType)]++;
4895 name += nameType[Standard_Integer(theType)];
4896 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4901 // si on avait une petite methode pour voir si la shape
4902 // est deja dans la Double map, ca eviterait de creer....
4903 DBRep::Set(name.ToCString(),PickSh);
4905 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4906 GetMapOfAIS().Bind(newsh, name);
4907 TheAISContext()->Display(newsh);
4908 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4911 // Plusieurs objets a picker, vite vite vite....
4914 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4915 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4916 if(ViewerTest::PickShapes(theType,arr)){
4917 for(Standard_Integer i=1;i<=NbToPick;i++){
4918 PickSh = arr->Value(i);
4919 if(!PickSh.IsNull()){
4921 nbOfSub[Standard_Integer(theType)]++;
4924 name += nameType[Standard_Integer(theType)];
4925 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4933 DBRep::Set(name.ToCString(),PickSh);
4934 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4935 GetMapOfAIS().Bind(newsh, name);
4936 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4937 TheAISContext()->Display(newsh);
4945 //=======================================================================
4946 //function : VPickSelected
4948 //=======================================================================
4949 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4951 static Standard_Integer aCount = 0;
4952 TCollection_AsciiString aName = "PickedShape_";
4960 aName = aName + aCount++ + "_";
4963 Standard_Integer anIdx = 0;
4964 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4966 TopoDS_Shape aShape;
4967 if (TheAISContext()->HasSelectedShape())
4969 aShape = TheAISContext()->SelectedShape();
4973 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4974 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
4977 TCollection_AsciiString aCurrentName = aName;
4980 aCurrentName += anIdx;
4983 DBRep::Set ((aCurrentName).ToCString(), aShape);
4985 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4986 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4987 TheAISContext()->Display (aNewShape);
4993 //=======================================================================
4994 //function : list of known objects
4996 //=======================================================================
4997 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4999 // 1234567890 12345678901234567 123456789
5000 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5001 TCollection_AsciiString BlankLine(64,'_');
5002 Standard_Integer i ;
5004 di<<"/n"<<BlankLine.ToCString()<<"\n";
5007 Colum[i].Center(20,' ');
5009 di<<"|"<<Colum[i].ToCString();
5012 di<<BlankLine.ToCString()<<"\n";
5014 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5015 const char ** names = GetTypeNames();
5017 TCollection_AsciiString curstring;
5018 TCollection_AsciiString curcolum[3];
5021 // les objets de type Datum..
5022 curcolum[1]+="Datum";
5024 curcolum[0].Clear();
5025 curcolum[0] += names[i];
5027 curcolum[2].Clear();
5028 curcolum[2]+=TCollection_AsciiString(i+1);
5030 for(Standard_Integer j =0;j<=2;j++){
5031 curcolum[j].Center(20,' ');
5032 di<<"|"<<curcolum[j].ToCString();
5036 di<<BlankLine.ToCString()<<"\n";
5038 // les objets de type shape
5039 curcolum[1].Clear();
5040 curcolum[1]+="Shape";
5041 curcolum[1].Center(20,' ');
5044 curcolum[0].Clear();
5045 curcolum[0] += names[7+i];
5046 curcolum[2].Clear();
5047 curcolum[2]+=TCollection_AsciiString(i);
5049 for(Standard_Integer j =0;j<=2;j++){
5050 curcolum[j].Center(20,' ');
5051 di<<"|"<<curcolum[j].ToCString();
5055 di<<BlankLine.ToCString()<<"\n";
5056 // les IO de type objet...
5057 curcolum[1].Clear();
5058 curcolum[1]+="Object";
5059 curcolum[1].Center(20,' ');
5061 curcolum[0].Clear();
5062 curcolum[0] += names[10+i];
5063 curcolum[2].Clear();
5064 curcolum[2]+=TCollection_AsciiString(i);
5066 for(Standard_Integer j =0;j<=2;j++){
5067 curcolum[j].Center(20,' ');
5068 di<<"|"<<curcolum[j].ToCString();
5072 di<<BlankLine.ToCString()<<"\n";
5073 // les contraintes et dimensions.
5074 // pour l'instant on separe juste contraintes et dimensions...
5075 // plus tard, on detaillera toutes les sortes...
5076 curcolum[1].Clear();
5077 curcolum[1]+="Relation";
5078 curcolum[1].Center(20,' ');
5080 curcolum[0].Clear();
5081 curcolum[0] += names[12+i];
5082 curcolum[2].Clear();
5083 curcolum[2]+=TCollection_AsciiString(i);
5085 for(Standard_Integer j =0;j<=2;j++){
5086 curcolum[j].Center(20,' ');
5087 di<<"|"<<curcolum[j].ToCString();
5091 di<<BlankLine.ToCString()<<"\n";
5098 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5100 if(argc!=2) return 1;
5102 AIS_KindOfInteractive TheType;
5103 Standard_Integer TheSign(-1);
5104 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5107 AIS_ListOfInteractive LIO;
5109 // en attendant l'amelioration ais pour les dimensions...
5111 Standard_Integer dimension_status(-1);
5112 if(TheType==AIS_KOI_Relation){
5113 dimension_status = TheSign ==1 ? 1 : 0;
5117 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5118 Handle(AIS_InteractiveObject) curio;
5119 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5122 if(dimension_status == -1)
5123 TheAISContext()->Erase(curio,Standard_False);
5125 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5126 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5127 (dimension_status==1 && KOD != AIS_KOD_NONE))
5128 TheAISContext()->Erase(curio,Standard_False);
5131 TheAISContext()->UpdateCurrentViewer();
5134 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5136 if(argc!=2) return 1;
5138 AIS_KindOfInteractive TheType;
5139 Standard_Integer TheSign(-1);
5140 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5142 // en attendant l'amelioration ais pour les dimensions...
5144 Standard_Integer dimension_status(-1);
5145 if(TheType==AIS_KOI_Relation){
5146 dimension_status = TheSign ==1 ? 1 : 0;
5150 AIS_ListOfInteractive LIO;
5151 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5152 Handle(AIS_InteractiveObject) curio;
5153 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5155 if(dimension_status == -1)
5156 TheAISContext()->Display(curio,Standard_False);
5158 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5159 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5160 (dimension_status==1 && KOD != AIS_KOD_NONE))
5161 TheAISContext()->Display(curio,Standard_False);
5166 TheAISContext()->UpdateCurrentViewer();
5170 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5173 BRep_Builder builder;
5175 BRepTools::Read(shape, s, builder);
5176 DBRep::Set(a[1], shape);
5177 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5178 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5183 //===============================================================================================
5186 //===============================================================================================
5187 static int VBsdf (Draw_Interpretor& theDi,
5188 Standard_Integer theArgsNb,
5189 const char** theArgVec)
5191 Handle(V3d_View) aView = ViewerTest::CurrentView();
5192 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5194 || aViewer.IsNull())
5196 std::cerr << "No active viewer!\n";
5200 ViewerTest_CmdParser aCmd;
5202 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5203 aCmd.AddOption ("print|echo|p", "Print BSDF");
5205 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5206 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5207 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5208 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5209 aCmd.AddOption ("le", "Self-emitted radiance");
5211 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5213 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
5214 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5215 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5217 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5219 aCmd.Parse (theArgsNb, theArgVec);
5221 if (aCmd.HasOption ("help"))
5223 theDi.PrintHelp (theArgVec[0]);
5227 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5230 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5231 if (!aMap.IsBound2 (aName) )
5233 std::cerr << "Use 'vdisplay' before\n";
5237 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5238 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5239 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5241 if (aCmd.HasOption ("print"))
5243 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5246 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5247 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5248 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5249 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5250 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5253 if (aFresnel.x() >= 0.f)
5256 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5258 else if (aFresnel.x() >= -1.5f)
5261 << "|Constant| " << aFresnel.z() << "\n";
5263 else if (aFresnel.x() >= -2.5f)
5266 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5271 << "|Dielectric| " << aFresnel.y() << "\n";
5276 << "Roughness: " << aBSDF.Roughness << "\n"
5277 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
5278 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5279 << aBSDF.AbsorptionColor.g() << ", "
5280 << aBSDF.AbsorptionColor.b() << "\n";
5285 if (aCmd.HasOption ("roughness", 1, Standard_True))
5287 aCmd.Arg ("roughness", 0);
5288 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5291 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5293 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5296 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5298 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5301 if (aCmd.HasOption ("kd", 3))
5303 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5305 else if (aCmd.HasOption ("kd", 1, Standard_True))
5307 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5310 if (aCmd.HasOption ("kr", 3))
5312 aBSDF.Kr = aCmd.ArgVec3f ("kr");
5314 else if (aCmd.HasOption ("kr", 1, Standard_True))
5316 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5319 if (aCmd.HasOption ("kt", 3))
5321 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5323 else if (aCmd.HasOption ("kt", 1, Standard_True))
5325 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5328 if (aCmd.HasOption ("ks", 3))
5330 aBSDF.Ks = aCmd.ArgVec3f ("ks");
5332 else if (aCmd.HasOption ("ks", 1, Standard_True))
5334 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5337 if (aCmd.HasOption ("le", 3))
5339 aBSDF.Le = aCmd.ArgVec3f ("le");
5341 else if (aCmd.HasOption ("le", 1, Standard_True))
5343 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5346 const std::string aFresnelErrorMessage =
5347 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5349 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5351 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5352 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5354 if (aFresnelType == "schlick")
5356 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5357 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5358 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5359 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5363 std::cout << aFresnelErrorMessage;
5366 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5368 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5369 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5371 if (aFresnelType == "conductor")
5373 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5374 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5375 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5379 std::cout << aFresnelErrorMessage;
5382 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5384 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5385 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5387 if (aFresnelType == "dielectric")
5389 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5390 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5392 else if (aFresnelType == "constant")
5394 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5395 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5399 std::cout << aFresnelErrorMessage;
5403 if (aCmd.HasOption ("normalize"))
5408 aMaterial.SetBSDF (aBSDF);
5409 anIObj->SetMaterial (aMaterial);
5416 //==============================================================================
5417 //function : VLoadSelection
5418 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5419 //==============================================================================
5420 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5421 Standard_Integer theArgNb,
5422 const char** theArgVec)
5426 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5430 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5433 ViewerTest::ViewerInit();
5434 aCtx = ViewerTest::GetAISContext();
5437 // Parse input arguments
5438 TColStd_SequenceOfAsciiString aNamesOfIO;
5439 Standard_Boolean isLocal = Standard_False;
5440 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5442 const TCollection_AsciiString aName = theArgVec[anArgIter];
5443 TCollection_AsciiString aNameCase = aName;
5444 aNameCase.LowerCase();
5445 if (aNameCase == "-local")
5447 isLocal = Standard_True;
5451 aNamesOfIO.Append (aName);
5455 if (aNamesOfIO.IsEmpty())
5457 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5462 if (isLocal && !aCtx->HasOpenedContext())
5464 aCtx->OpenLocalContext (Standard_False);
5466 else if (!isLocal && aCtx->HasOpenedContext())
5468 aCtx->CloseAllContexts (Standard_False);
5471 // Load selection of interactive objects
5472 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5474 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5476 Handle(AIS_InteractiveObject) aShape;
5477 if (GetMapOfAIS().IsBound2 (aName))
5478 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5480 aShape = GetAISShapeFromName (aName.ToCString());
5482 if (!aShape.IsNull())
5484 if (!GetMapOfAIS().IsBound2 (aName))
5486 GetMapOfAIS().Bind (aShape, aName);
5489 aCtx->Load (aShape, -1, Standard_False);
5490 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5497 //==============================================================================
5498 //function : VAutoActivateSelection
5499 //purpose : Activates or deactivates auto computation of selection
5500 //==============================================================================
5501 static int VAutoActivateSelection (Draw_Interpretor& theDi,
5502 Standard_Integer theArgNb,
5503 const char** theArgVec)
5508 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5512 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5515 ViewerTest::ViewerInit();
5516 aCtx = ViewerTest::GetAISContext();
5521 TCollection_AsciiString aSelActivationString;
5522 if (aCtx->GetAutoActivateSelection())
5524 aSelActivationString.Copy ("ON");
5528 aSelActivationString.Copy ("OFF");
5531 theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
5535 Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]) != 0;
5536 aCtx->SetAutoActivateSelection (toActivate);
5542 //==============================================================================
5543 //function : ViewerTest::Commands
5544 //purpose : Add all the viewer command in the Draw_Interpretor
5545 //==============================================================================
5547 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5549 ViewerTest::ViewerCommands(theCommands);
5550 ViewerTest::RelationCommands(theCommands);
5551 ViewerTest::ObjectCommands(theCommands);
5552 ViewerTest::FilletCommands(theCommands);
5553 ViewerTest::OpenGlCommands(theCommands);
5555 const char *group = "AIS_Display";
5558 theCommands.Add("visos",
5559 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5560 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5561 __FILE__, visos, group);
5563 theCommands.Add("vdisplay",
5564 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5565 "\n\t\t: [-trsfPers {pan|zoom|rotate|trihedron|full|none}=none] [-trsfPersPos X Y [Z]] [-3d|-2d]"
5566 "\n\t\t: [-dispMode mode] [-highMode mode]"
5567 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5568 "\n\t\t: [-redisplay]"
5569 "\n\t\t: name1 [name2] ... [name n]"
5570 "\n\t\t: Displays named objects."
5571 "\n\t\t: Option -local enables displaying of objects in local"
5572 "\n\t\t: selection context. Local selection context will be opened"
5573 "\n\t\t: if there is not any."
5574 "\n\t\t: -noupdate suppresses viewer redraw call."
5575 "\n\t\t: -mutable enables optimizations for mutable objects."
5576 "\n\t\t: -neutral draws objects in main viewer."
5577 "\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."
5578 "\n\t\t: -top draws objects on top of main presentations but below topmost."
5579 "\n\t\t: -topmost draws in overlay for 3D presentations with independent Depth."
5580 "\n\t\t: -overlay draws objects in overlay for 2D presentations (On-Screen-Display)."
5581 "\n\t\t: -underlay draws objects in underlay for 2D presentations (On-Screen-Display)."
5582 "\n\t\t: -selectable|-noselect controls selection of objects."
5583 "\n\t\t: -trsfPers sets a transform persistence flags. Flag 'full' is pan, zoom and rotate."
5584 "\n\t\t: -trsfPersPos sets an anchor point for transform persistence."
5585 "\n\t\t: -2d displays object in screen coordinates (DY looks up)."
5586 "\n\t\t: -dispmode sets display mode for objects."
5587 "\n\t\t: -highmode sets hilight mode for objects."
5588 "\n\t\t: -redisplay recomputes presentation of objects.",
5589 __FILE__, VDisplay2, group);
5591 theCommands.Add ("vupdate",
5592 "vupdate name1 [name2] ... [name n]"
5593 "\n\t\t: Updates named objects in interactive context",
5594 __FILE__, VUpdate, group);
5596 theCommands.Add("verase",
5597 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5598 "\n\t\t: Erases selected or named objects."
5599 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5600 "\n\t\t: Option -local enables erasing of selected or named objects without"
5601 "\n\t\t: closing local selection context.",
5602 __FILE__, VErase, group);
5604 theCommands.Add("vremove",
5605 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5606 "or vremove [-context] -all to remove all objects"
5607 "\n\t\t: Removes selected or named objects."
5608 "\n\t\t If -context is in arguments, the objects are not deleted"
5609 "\n\t\t from the map of objects and names."
5610 "\n\t\t: Option -local enables removing of selected or named objects without"
5611 "\n\t\t: closing local selection context. Empty local selection context will be"
5613 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5614 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5615 __FILE__, VRemove, group);
5617 theCommands.Add("vdonly",
5618 "vdonly [-noupdate|-update] [name1] ... [name n]"
5619 "\n\t\t: Displays only selected or named objects",
5620 __FILE__,VDonly2,group);
5622 theCommands.Add("vdisplayall",
5623 "vidsplayall [-local]"
5624 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5625 "\n\t\t: Option -local enables displaying of the objects in local"
5626 "\n\t\t: selection context.",
5627 __FILE__, VDisplayAll, group);
5629 theCommands.Add("veraseall",
5630 "veraseall [-local]"
5631 "\n\t\t: Erases all objects displayed in the viewer."
5632 "\n\t\t: Option -local enables erasing of the objects in local"
5633 "\n\t\t: selection context.",
5634 __FILE__, VErase, group);
5636 theCommands.Add("verasetype",
5638 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5639 __FILE__, VEraseType, group);
5640 theCommands.Add("vbounding",
5641 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5642 "\n\t\t: [-print] [-hide]"
5643 "\n\t\t: Temporarily display bounding box of specified Interactive"
5644 "\n\t\t: Objects, or print it to console if -print is specified."
5645 "\n\t\t: Already displayed box might be hidden by -hide option.",
5646 __FILE__,VBounding,group);
5648 theCommands.Add("vdisplaytype",
5649 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5650 __FILE__,VDisplayType,group);
5652 theCommands.Add("vsetdispmode",
5653 "vsetdispmode [name] mode(1,2,..)"
5654 "\n\t\t: Sets display mode for all, selected or named objects.",
5655 __FILE__,VDispMode,group);
5657 theCommands.Add("vunsetdispmode",
5658 "vunsetdispmode [name]"
5659 "\n\t\t: Unsets custom display mode for selected or named objects.",
5660 __FILE__,VDispMode,group);
5662 theCommands.Add("vdir",
5663 "Lists all objects displayed in 3D viewer",
5664 __FILE__,VDir,group);
5666 #ifdef HAVE_FREEIMAGE
5667 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5669 #define DUMP_FORMATS "{ppm}"
5671 theCommands.Add("vdump",
5672 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5673 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5674 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5675 "\n\t\t: Dumps content of the active view into image file",
5676 __FILE__,VDump,group);
5678 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5679 __FILE__,VSubInt,group);
5681 theCommands.Add("vaspects",
5682 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5683 "\n\t\t: [-setVisibility 0|1]"
5684 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5685 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5686 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5687 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5688 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5689 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5690 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5691 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5692 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5693 "\n\t\t: [-isoontriangulation 0|1]"
5694 "\n\t\t: [-setMaxParamValue {value}]"
5695 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5696 "\n\t\t: Manage presentation properties of all, selected or named objects."
5697 "\n\t\t: When -subshapes is specified than following properties will be"
5698 "\n\t\t: assigned to specified sub-shapes."
5699 "\n\t\t: When -defaults is specified than presentation properties will be"
5700 "\n\t\t: assigned to all objects that have not their own specified properties"
5701 "\n\t\t: and to all objects to be displayed in the future."
5702 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5703 __FILE__,VAspects,group);
5705 theCommands.Add("vsetcolor",
5706 "vsetcolor [-noupdate|-update] [name] ColorName"
5707 "\n\t\t: Sets color for all, selected or named objects."
5708 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5709 __FILE__,VAspects,group);
5711 theCommands.Add("vunsetcolor",
5712 "vunsetcolor [-noupdate|-update] [name]"
5713 "\n\t\t: Resets color for all, selected or named objects."
5714 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5715 __FILE__,VAspects,group);
5717 theCommands.Add("vsettransparency",
5718 "vsettransparency [-noupdate|-update] [name] Coefficient"
5719 "\n\t\t: Sets transparency for all, selected or named objects."
5720 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5721 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5722 __FILE__,VAspects,group);
5724 theCommands.Add("vunsettransparency",
5725 "vunsettransparency [-noupdate|-update] [name]"
5726 "\n\t\t: Resets transparency for all, selected or named objects."
5727 "\n\t\t: Alias for vaspects -unsettransp [name].",
5728 __FILE__,VAspects,group);
5730 theCommands.Add("vsetmaterial",
5731 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5732 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5733 __FILE__,VAspects,group);
5735 theCommands.Add("vunsetmaterial",
5736 "vunsetmaterial [-noupdate|-update] [name]"
5737 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5738 __FILE__,VAspects,group);
5740 theCommands.Add("vsetwidth",
5741 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5742 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5743 __FILE__,VAspects,group);
5745 theCommands.Add("vunsetwidth",
5746 "vunsetwidth [-noupdate|-update] [name]"
5747 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5748 __FILE__,VAspects,group);
5750 theCommands.Add("vsetinteriorstyle",
5751 "vsetinteriorstyle [-noupdate|-update] [name] style"
5752 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5753 __FILE__,VSetInteriorStyle,group);
5755 theCommands.Add("vsensdis",
5756 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5757 "\n\t\t: Standard entity types are those defined in Select3D package:"
5758 "\n\t\t: - sensitive box"
5759 "\n\t\t: - sensitive face"
5760 "\n\t\t: - sensitive curve"
5761 "\n\t\t: - sensitive segment"
5762 "\n\t\t: - sensitive circle"
5763 "\n\t\t: - sensitive point"
5764 "\n\t\t: - sensitive triangulation"
5765 "\n\t\t: - sensitive triangle"
5766 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5767 __FILE__,VDispSensi,group);
5769 theCommands.Add("vsensera",
5770 "vsensera : erase active entities",
5771 __FILE__,VClearSensi,group);
5773 theCommands.Add("vselprecision",
5774 "vselprecision [-unset] [tolerance_value]"
5775 "\n\t\t Manages selection precision or prints current value if no parameter is passed."
5776 "\n\t\t -unset - restores default selection tolerance behavior, based on individual entity tolerance",
5777 __FILE__,VSelPrecision,group);
5779 theCommands.Add("vperf",
5780 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
5781 "\n\t\t: Tests the animation of an object along a predefined trajectory.",
5782 __FILE__,VPerf,group);
5784 theCommands.Add("vanimation",
5785 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5786 __FILE__,VAnimation,group);
5788 theCommands.Add("vsetshading",
5789 "vsetshading : vsetshading name Quality(default=0.0008) "
5790 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5791 __FILE__,VShading,group);
5793 theCommands.Add("vunsetshading",
5794 "vunsetshading :vunsetshading name "
5795 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5796 __FILE__,VShading,group);
5798 theCommands.Add ("vtexture",
5799 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5800 " [-scale u v] [-scale off]\n"
5801 " [-origin u v] [-origin off]\n"
5802 " [-repeat u v] [-repeat off]\n"
5803 " [-modulate {on | off}]"
5805 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5806 " specifying one of the predefined textures.\n"
5807 " The options are: \n"
5808 " -scale u v : enable texture scaling and set scale factors\n"
5809 " -scale off : disable texture scaling\n"
5810 " -origin u v : enable texture origin positioning and set the origin\n"
5811 " -origin off : disable texture origin positioning\n"
5812 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5813 " -repeat off : disable texture repeat\n"
5814 " -modulate {on | off} : enable or disable texture modulation\n"
5815 " -default : sets texture mapping default parameters\n"
5816 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5817 "or 'vtexture NameOfShape ?' to list available textures\n",
5818 __FILE__, VTexture, group);
5820 theCommands.Add("vtexscale",
5821 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5822 or 'vtexscale NameOfShape ScaleUV' \n \
5823 or 'vtexscale NameOfShape' to disable scaling\n ",
5824 __FILE__,VTexture,group);
5826 theCommands.Add("vtexorigin",
5827 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5828 or 'vtexorigin NameOfShape UVOrigin' \n \
5829 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5830 __FILE__,VTexture,group);
5832 theCommands.Add("vtexrepeat",
5833 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5834 or 'vtexrepeat NameOfShape UVRepeat \n \
5835 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5838 theCommands.Add("vtexdefault",
5839 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5842 theCommands.Add("vsetam",
5843 "vsetam [shapename] mode"
5844 "\n\t\t: Activates selection mode for all selected or named shapes."
5845 "\n\t\t: Mod can be:"
5846 "\n\t\t: 0 - for shape itself"
5847 "\n\t\t: 1 - vertices"
5851 "\n\t\t: 5 - shells"
5852 "\n\t\t: 6 - solids"
5853 "\n\t\t: 7 - compounds"
5854 __FILE__,VActivatedMode,group);
5856 theCommands.Add("vunsetam",
5857 "vunsetam : Deactivates all selection modes for all shapes.",
5858 __FILE__,VActivatedMode,group);
5860 theCommands.Add("vstate",
5861 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5862 "\n\t\t: Reports show/hidden state for selected or named objects"
5863 "\n\t\t: -entities - print low-level information about detected entities"
5864 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5865 __FILE__,VState,group);
5867 theCommands.Add("vpickshapes",
5868 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5869 __FILE__,VPickShape,group);
5871 theCommands.Add("vtypes",
5872 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5875 theCommands.Add("vr",
5877 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
5878 __FILE__,vr, group);
5880 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5881 __FILE__, VPickSelected, group);
5883 theCommands.Add ("vloadselection",
5884 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5885 "\n\t\t: primitives for the shapes with names given without displaying them."
5886 "\n\t\t: -local - open local context before selection computation",
5887 __FILE__, VLoadSelection, group);
5889 theCommands.Add ("vautoactivatesel",
5890 "vautoactivatesel [0|1] : manage or display the option to automatically"
5891 "\n\t\t: activate selection for newly displayed objects"
5892 "\n\t\t: [0|1] - turn off | on auto activation of selection",
5893 __FILE__, VAutoActivateSelection, group);
5895 theCommands.Add("vbsdf", "vbsdf [name] [options]"
5896 "\nAdjusts parameters of material BSDF:"
5897 "\n -help : Shows this message"
5898 "\n -print : Print BSDF"
5899 "\n -kd : Weight of the Lambertian BRDF"
5900 "\n -kr : Weight of the reflection BRDF"
5901 "\n -kt : Weight of the transmission BTDF"
5902 "\n -ks : Weight of the glossy Blinn BRDF"
5903 "\n -le : Self-emitted radiance"
5904 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5905 "\n Schlick x y z, Dielectric x, Conductor x y"
5906 "\n -roughness : Roughness of material (Blinn's exponent)"
5907 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
5908 "\n -absorpcolor : Absorption color (only for transparent material)"
5909 "\n -normalize : Normalize BSDF coefficients",
5910 __FILE__, VBsdf, group);
5914 //=====================================================================
5915 //========================= for testing Draft and Rib =================
5916 //=====================================================================
5917 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5918 #include <DBRep.hxx>
5919 #include <TopoDS_Face.hxx>
5920 #include <gp_Pln.hxx>
5921 #include <AIS_KindOfSurface.hxx>
5922 #include <BRepOffsetAPI_DraftAngle.hxx>
5923 #include <Precision.hxx>
5924 #include <BRepAlgo.hxx>
5925 #include <OSD_Environment.hxx>
5926 #include <DrawTrSurf.hxx>
5927 //#include <DbgTools.hxx>
5928 //#include <FeatAlgo_MakeLinearForm.hxx>
5933 //=======================================================================
5934 //function : IsValid
5936 //=======================================================================
5937 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5938 const TopoDS_Shape& theResult,
5939 const Standard_Boolean closedSolid,
5940 const Standard_Boolean GeomCtrl)
5942 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5943 TCollection_AsciiString checkValid = check.Value();
5944 Standard_Boolean ToCheck = Standard_True;
5945 if (!checkValid.IsEmpty()) {
5947 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5949 if ( checkValid=="true" || checkValid=="TRUE" ) {
5950 ToCheck= Standard_False;
5954 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
5957 Standard_Boolean IsValid = Standard_True;
5959 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5964 //===============================================================================
5965 // TDraft : test draft, uses AIS Viewer
5966 // Solid Face Plane Angle Reverse
5967 //===============================================================================
5968 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5970 if (argc < 5) return 1;
5971 // argv[1] - TopoDS_Shape Solid
5972 // argv[2] - TopoDS_Shape Face
5973 // argv[3] - TopoDS_Shape Plane
5974 // argv[4] - Standard_Real Angle
5975 // argv[5] - Standard_Integer Reverse
5977 // Sprintf(prefix, argv[1]);
5978 Standard_Real anAngle = 0;
5979 Standard_Boolean Rev = Standard_False;
5980 Standard_Integer rev = 0;
5981 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5982 TopoDS_Shape face = GetShapeFromName(argv[2]);
5983 TopoDS_Face Face = TopoDS::Face(face);
5984 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5985 if (Plane.IsNull ()) {
5986 di << "TEST : Plane is NULL\n";
5989 anAngle = Draw::Atof(argv[4]);
5990 anAngle = 2*M_PI * anAngle / 360.0;
5992 Handle( Geom_Surface )aSurf;
5993 AIS_KindOfSurface aSurfType;
5994 Standard_Real Offset;
5996 if(argc > 4) { // == 5
5997 rev = Draw::Atoi(argv[5]);
5998 Rev = (rev)? Standard_True : Standard_False;
6001 TopoDS_Face face2 = TopoDS::Face(Plane);
6002 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6004 di << "TEST : Can't find plane\n";
6008 aDir = aPln.Axis().Direction();
6011 if (Plane.Orientation() == TopAbs_REVERSED)
6013 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6015 BRepOffsetAPI_DraftAngle Draft (Solid);
6017 if(Abs(anAngle)< Precision::Angular()) {
6018 di << "TEST : NULL angle\n";
6021 if(Rev) anAngle = - anAngle;
6022 Draft.Add (Face, aDir, anAngle, aPln);
6024 if (!Draft.IsDone()) {
6025 di << "TEST : Draft Not DONE \n";
6028 TopTools_ListOfShape Larg;
6030 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6031 di << "TEST : DesignAlgo returns Not valid\n";
6035 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6036 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6038 if ( !ais.IsNull() ) {
6039 ais->SetColor(DEFAULT_COLOR);
6040 ais->SetMaterial(DEFAULT_MATERIAL);
6041 // Display the AIS_Shape without redraw
6042 Ctx->Display(ais, Standard_False);
6044 const char *Name = "draft1";
6045 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6047 Handle(AIS_InteractiveObject) an_object =
6048 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6049 if (!an_object.IsNull()) {
6050 Ctx->Remove(an_object,
6052 GetMapOfAIS().UnBind2(Name) ;
6055 GetMapOfAIS().Bind(ais, Name);
6056 // DBRep::Set("draft", ais->Shape());
6058 Ctx->Display(ais, Standard_True);
6062 //==============================================================================
6063 //function : splitParameter
6064 //purpose : Split parameter string to parameter name and parameter value
6065 //==============================================================================
6066 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6067 TCollection_AsciiString& theName,
6068 TCollection_AsciiString& theValue)
6070 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6072 if (aParamNameEnd == 0)
6074 return Standard_False;
6077 TCollection_AsciiString aString (theString);
6078 if (aParamNameEnd != 0)
6080 theValue = aString.Split (aParamNameEnd);
6081 aString.Split (aString.Length() - 1);
6085 return Standard_True;
6088 //============================================================================
6090 //============================================================================
6091 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6094 DrawTrSurf::BasicCommands(theCommands);
6095 const char* group = "Check Features Operations commands";
6097 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6099 &TDraft,group); //Draft_Modification
6102 //==============================================================================
6103 // ViewerTest::Factory
6104 //==============================================================================
6105 void ViewerTest::Factory(Draw_Interpretor& theDI)
6107 // definition of Viewer Command
6108 ViewerTest::Commands(theDI);
6109 ViewerTest::AviCommands(theDI);
6112 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6116 // Declare entry point PLUGINFACTORY