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;
576 Aspect_TypeOfLine aType;
577 Standard_Real aWidth;
579 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
581 Handle(Prs3d_IsoAspect) aResult =
582 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
587 //==============================================================================
589 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
590 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
591 //==============================================================================
592 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
594 if (TheAISContext().IsNull()) {
595 di << argv[0] << " Call 'vinit' before!\n";
600 di << "Current number of isos : " <<
601 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
602 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
603 di << "IsoOnPlane mode is " <<
604 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
605 di << "IsoOnTriangulation mode is " <<
606 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
610 Standard_Integer aLastInd = argc - 1;
611 Standard_Boolean isChanged = Standard_False;
612 Standard_Integer aNbUIsos = 0;
613 Standard_Integer aNbVIsos = 0;
616 Standard_Boolean isIsoOnPlane = Standard_False;
618 if (strcmp(argv[aLastInd], "1") == 0) {
619 isIsoOnPlane = Standard_True;
620 isChanged = Standard_True;
621 } else if (strcmp(argv[aLastInd], "0") == 0) {
622 isIsoOnPlane = Standard_False;
623 isChanged = Standard_True;
627 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
628 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
631 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
632 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
634 TheAISContext()->IsoOnPlane(isIsoOnPlane);
637 // If there are no shapes provided set the default numbers.
638 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
639 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
646 for (i = 1; i <= aLastInd; i++) {
647 TCollection_AsciiString name(argv[i]);
648 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
651 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
652 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
653 const Handle(AIS_InteractiveObject) aShape =
654 Handle(AIS_InteractiveObject)::DownCast (anObj);
655 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
656 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
657 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
660 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
661 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
662 TheAISContext()->SetLocalAttributes
663 (aShape, CurDrawer, Standard_False);
664 TheAISContext()->Redisplay(aShape);
666 di << "Number of isos for " << argv[i] << " : "
667 << aUIso->Number() << " " << aVIso->Number() << "\n";
670 di << argv[i] << ": Not an AIS interactive object!\n";
673 di << argv[i] << ": Use 'vdisplay' before\n";
678 TheAISContext()->UpdateCurrentViewer();
684 static Standard_Integer VDispSensi (Draw_Interpretor& ,
685 Standard_Integer theArgNb,
690 std::cout << "Error: wrong syntax!\n";
694 Handle(AIS_InteractiveContext) aCtx;
695 Handle(V3d_View) aView;
696 if (!getCtxAndView (aCtx, aView))
701 aCtx->DisplayActiveSensitive (aView);
706 static Standard_Integer VClearSensi (Draw_Interpretor& ,
707 Standard_Integer theArgNb,
712 std::cout << "Error: wrong syntax!\n";
716 Handle(AIS_InteractiveContext) aCtx;
717 Handle(V3d_View) aView;
718 if (!getCtxAndView (aCtx, aView))
722 aCtx->ClearActiveSensitive (aView);
726 //==============================================================================
728 //purpose : To list the displayed object with their attributes
729 //==============================================================================
730 static int VDir (Draw_Interpretor& theDI,
734 if (!a3DView().IsNull())
739 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
740 anIter.More(); anIter.Next())
742 theDI << "\t" << anIter.Key2().ToCString() << "\n";
747 //==============================================================================
748 //function : VSelPrecision
749 //purpose : To set the selection tolerance value
750 //Draw arg : Selection tolerance value (real value determining the width and
751 // height of selecting frustum bases). Without arguments the function
752 // just prints current tolerance.
753 //==============================================================================
754 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
758 di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
762 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
763 if( aContext.IsNull() )
768 Standard_Real aPixelTolerance = aContext->PixelTolerance();
769 di << "Pixel tolerance : " << aPixelTolerance << "\n";
773 TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
775 if (anArg == "-unset")
777 aContext->SetPixelTolerance (-1);
781 aContext->SetPixelTolerance (anArg.IntegerValue());
788 //! Auxiliary enumeration
789 enum ViewerTest_StereoPair
791 ViewerTest_SP_Single,
792 ViewerTest_SP_SideBySide,
793 ViewerTest_SP_OverUnder
796 //==============================================================================
798 //purpose : To dump the active view snapshot to image file
799 //==============================================================================
800 static Standard_Integer VDump (Draw_Interpretor& theDI,
801 Standard_Integer theArgNb,
802 Standard_CString* theArgVec)
806 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
810 Standard_Integer anArgIter = 1;
811 Standard_CString aFilePath = theArgVec[anArgIter++];
812 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
813 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
814 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
815 Standard_Integer aWidth = 0;
816 Standard_Integer aHeight = 0;
817 for (; anArgIter < theArgNb; ++anArgIter)
819 TCollection_AsciiString anArg (theArgVec[anArgIter]);
821 if (anArg == "-buffer")
823 if (++anArgIter >= theArgNb)
825 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
829 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
831 if (aBufArg == "rgba")
833 aBufferType = Graphic3d_BT_RGBA;
835 else if (aBufArg == "rgb")
837 aBufferType = Graphic3d_BT_RGB;
839 else if (aBufArg == "depth")
841 aBufferType = Graphic3d_BT_Depth;
845 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
849 else if (anArg == "-stereo")
851 if (++anArgIter >= theArgNb)
853 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
857 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
858 aStereoArg.LowerCase();
859 if (aStereoArg == "l"
860 || aStereoArg == "left")
862 aStereoOpts = V3d_SDO_LEFT_EYE;
864 else if (aStereoArg == "r"
865 || aStereoArg == "right")
867 aStereoOpts = V3d_SDO_RIGHT_EYE;
869 else if (aStereoArg == "mono")
871 aStereoOpts = V3d_SDO_MONO;
873 else if (aStereoArg == "blended"
874 || aStereoArg == "blend"
875 || aStereoArg == "stereo")
877 aStereoOpts = V3d_SDO_BLENDED;
879 else if (aStereoArg == "sbs"
880 || aStereoArg == "sidebyside")
882 aStereoPair = ViewerTest_SP_SideBySide;
884 else if (aStereoArg == "ou"
885 || aStereoArg == "overunder")
887 aStereoPair = ViewerTest_SP_OverUnder;
891 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
895 else if (anArg == "-rgba"
898 aBufferType = Graphic3d_BT_RGBA;
900 else if (anArg == "-rgb"
903 aBufferType = Graphic3d_BT_RGB;
905 else if (anArg == "-depth"
908 aBufferType = Graphic3d_BT_Depth;
911 else if (anArg == "-width"
917 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
920 else if (++anArgIter >= theArgNb)
922 std::cout << "Error: integer value is expected right after 'width'\n";
925 aWidth = Draw::Atoi (theArgVec[anArgIter]);
927 else if (anArg == "-height"
929 || anArg == "-sizey")
933 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
936 else if (++anArgIter >= theArgNb)
938 std::cout << "Error: integer value is expected right after 'height'\n";
941 aHeight = Draw::Atoi (theArgVec[anArgIter]);
945 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
949 if ((aWidth <= 0 && aHeight > 0)
950 || (aWidth > 0 && aHeight <= 0))
952 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
956 Handle(V3d_View) aView = ViewerTest::CurrentView();
959 std::cout << "Error: cannot find an active view!\n";
963 if (aWidth <= 0 || aHeight <= 0)
965 aView->Window()->Size (aWidth, aHeight);
968 Image_AlienPixMap aPixMap;
970 bool isBigEndian = Image_PixMap::IsBigEndianHost();
971 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
974 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
975 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
976 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
981 case ViewerTest_SP_Single:
983 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
985 theDI << "Fail: view dump failed!\n";
988 else if (aPixMap.SizeX() != Standard_Size(aWidth)
989 || aPixMap.SizeY() != Standard_Size(aHeight))
991 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
992 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
996 case ViewerTest_SP_SideBySide:
998 if (!aPixMap.InitZero (aFormat, aWidth * 2, aHeight))
1000 theDI << "Fail: not enough memory for image allocation!\n";
1004 Image_PixMap aPixMapL, aPixMapR;
1005 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1006 aWidth, aHeight, aPixMap.SizeRowBytes());
1007 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aWidth,
1008 aWidth, aHeight, aPixMap.SizeRowBytes());
1009 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1010 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE)
1013 theDI << "Fail: view dump failed!\n";
1018 case ViewerTest_SP_OverUnder:
1020 if (!aPixMap.InitZero (aFormat, aWidth, aHeight * 2))
1022 theDI << "Fail: not enough memory for image allocation!\n";
1026 Image_PixMap aPixMapL, aPixMapR;
1027 aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
1028 aWidth, aHeight, aPixMap.SizeRowBytes());
1029 aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aHeight,
1030 aWidth, aHeight, aPixMap.SizeRowBytes());
1031 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1032 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE))
1034 theDI << "Fail: view dump failed!\n";
1041 if (!aPixMap.Save (aFilePath))
1043 theDI << "Fail: image can not be saved!\n";
1048 //==============================================================================
1049 //function : Displays,Erase...
1052 //==============================================================================
1053 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
1054 const Standard_Integer Mode,
1055 const Standard_Integer TypeOfOperation,
1056 const Standard_Boolean Upd)
1058 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1060 switch(TypeOfOperation){
1062 Ctx->Display(IO,Mode,Upd);
1070 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
1072 Ctx->SetDisplayMode(IO,Mode,Upd);
1077 Ctx->SetDisplayMode(0,Upd);
1079 Ctx->UnsetDisplayMode(IO,Upd);
1086 //=======================================================================
1089 //=======================================================================
1090 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1093 TCollection_AsciiString name;
1096 // display others presentations
1097 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
1098 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
1099 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
1100 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1102 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1104 //unset displaymode.. comportement particulier...
1105 if(TypeOfOperation==4){
1107 if(Ctx->NbSelected()==0){
1108 Handle(AIS_InteractiveObject) IO;
1109 VwrTst_DispErase(IO,-1,4,Standard_False);
1112 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1113 VwrTst_DispErase(Ctx->SelectedInteractive(),-1,4,Standard_False);}
1114 Ctx->UpdateCurrentViewer();
1117 Handle(AIS_InteractiveObject) IO;
1119 if(GetMapOfAIS().IsBound2(name)){
1120 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1122 VwrTst_DispErase(IO,-1,4,Standard_True);
1127 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1128 if(Ctx->NbSelected()==0 && TypeOfOperation==3){
1129 Handle(AIS_InteractiveObject) IO;
1130 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1132 if(!Ctx->HasOpenedContext()){
1133 // set/unset display mode sur le Contexte...
1134 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1135 VwrTst_DispErase(Ctx->SelectedInteractive(),Dmode,TypeOfOperation,Standard_False);
1137 Ctx->UpdateCurrentViewer();
1140 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1141 Ctx->Display(Ctx->SelectedInteractive(),Dmode);
1145 Handle(AIS_InteractiveObject) IO;
1147 if(GetMapOfAIS().IsBound2(name))
1148 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1150 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1156 //=======================================================================
1159 //=======================================================================
1160 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1162 if(argc==1) return 1;
1163 Standard_Integer On = Draw::Atoi(argv[1]);
1164 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1168 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1169 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1170 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1174 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1178 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1182 Ctx->UpdateCurrentViewer();
1185 Handle(AIS_InteractiveObject) IO;
1186 TCollection_AsciiString name = argv[2];
1187 if(GetMapOfAIS().IsBound2(name)){
1188 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1191 Ctx->SubIntensityOn(IO);
1193 Ctx->SubIntensityOff(IO);
1201 //! Auxiliary class to iterate presentations from different collections.
1202 class ViewTest_PrsIter
1206 //! Create and initialize iterator object.
1207 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1208 : mySource (IterSource_All)
1210 NCollection_Sequence<TCollection_AsciiString> aNames;
1211 if (!theName.IsEmpty())
1212 aNames.Append (theName);
1216 //! Create and initialize iterator object.
1217 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1218 : mySource (IterSource_All)
1223 //! Initialize the iterator.
1224 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1226 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1228 mySelIter.Nullify();
1229 myCurrent.Nullify();
1230 myCurrentTrs.Nullify();
1231 if (!mySeq.IsEmpty())
1233 mySource = IterSource_List;
1234 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1236 else if (aCtx->NbSelected() > 0)
1238 mySource = IterSource_Selected;
1240 mySelIter->InitSelected();
1244 mySource = IterSource_All;
1245 myMapIter.Initialize (GetMapOfAIS());
1250 const TCollection_AsciiString& CurrentName() const
1252 return myCurrentName;
1255 const Handle(AIS_InteractiveObject)& Current() const
1260 const Handle(Standard_Transient)& CurrentTrs() const
1262 return myCurrentTrs;
1265 //! @return true if iterator points to valid object within collection
1266 Standard_Boolean More() const
1270 case IterSource_All: return myMapIter.More();
1271 case IterSource_List: return mySeqIter.More();
1272 case IterSource_Selected: return mySelIter->MoreSelected();
1274 return Standard_False;
1277 //! Go to the next item.
1280 myCurrentName.Clear();
1281 myCurrentTrs.Nullify();
1282 myCurrent.Nullify();
1285 case IterSource_All:
1290 case IterSource_List:
1295 case IterSource_Selected:
1297 mySelIter->NextSelected();
1310 case IterSource_All:
1312 if (myMapIter.More())
1314 myCurrentName = myMapIter.Key2();
1315 myCurrentTrs = myMapIter.Key1();
1316 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1320 case IterSource_List:
1322 if (mySeqIter.More())
1324 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1326 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1329 myCurrentName = mySeqIter.Value();
1330 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1331 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1335 case IterSource_Selected:
1337 if (mySelIter->MoreSelected())
1339 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1340 myCurrent = mySelIter->SelectedInteractive();
1358 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1359 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1360 NCollection_Sequence<TCollection_AsciiString> mySeq;
1361 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1363 TCollection_AsciiString myCurrentName;//!< current item name
1364 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1365 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1367 IterSource mySource; //!< iterated collection
1371 //==============================================================================
1372 //function : VInteriorStyle
1373 //purpose : sets interior style of the a selected or named or displayed shape
1374 //==============================================================================
1375 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1376 Standard_Integer theArgNb,
1377 const char** theArgVec)
1379 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1380 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1383 std::cerr << "Error: no active view!\n";
1387 Standard_Integer anArgIter = 1;
1388 for (; anArgIter < theArgNb; ++anArgIter)
1390 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1395 TCollection_AsciiString aName;
1396 if (theArgNb - anArgIter == 2)
1398 aName = theArgVec[anArgIter++];
1400 else if (theArgNb - anArgIter != 1)
1402 std::cout << "Error: wrong number of arguments! See usage:\n";
1403 theDI.PrintHelp (theArgVec[0]);
1406 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1407 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1408 aStyleArg.LowerCase();
1409 if (aStyleArg == "empty")
1413 else if (aStyleArg == "hollow")
1417 else if (aStyleArg == "hatch")
1421 else if (aStyleArg == "solid")
1425 else if (aStyleArg == "hiddenline")
1431 anInterStyle = aStyleArg.IntegerValue();
1433 if (anInterStyle < Aspect_IS_EMPTY
1434 || anInterStyle > Aspect_IS_HIDDENLINE)
1436 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1437 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1441 if (!aName.IsEmpty()
1442 && !GetMapOfAIS().IsBound2 (aName))
1444 std::cout << "Error: object " << aName << " is not displayed!\n";
1448 if (aCtx->HasOpenedContext())
1450 aCtx->CloseLocalContext();
1452 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1454 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1457 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1458 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1459 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1460 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1461 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1467 //! Auxiliary structure for VAspects
1468 struct ViewerTest_AspectsChangeSet
1470 Standard_Integer ToSetVisibility;
1471 Standard_Integer Visibility;
1473 Standard_Integer ToSetColor;
1474 Quantity_Color Color;
1476 Standard_Integer ToSetLineWidth;
1477 Standard_Real LineWidth;
1479 Standard_Integer ToSetTypeOfLine;
1480 Aspect_TypeOfLine TypeOfLine;
1482 Standard_Integer ToSetTransparency;
1483 Standard_Real Transparency;
1485 Standard_Integer ToSetMaterial;
1486 Graphic3d_NameOfMaterial Material;
1487 TCollection_AsciiString MatName;
1489 NCollection_Sequence<TopoDS_Shape> SubShapes;
1491 Standard_Integer ToSetShowFreeBoundary;
1492 Standard_Integer ToSetFreeBoundaryWidth;
1493 Standard_Real FreeBoundaryWidth;
1494 Standard_Integer ToSetFreeBoundaryColor;
1495 Quantity_Color FreeBoundaryColor;
1497 Standard_Integer ToEnableIsoOnTriangulation;
1499 Standard_Integer ToSetMaxParamValue;
1500 Standard_Real MaxParamValue;
1502 Standard_Integer ToSetSensitivity;
1503 Standard_Integer SelectionMode;
1504 Standard_Integer Sensitivity;
1506 //! Empty constructor
1507 ViewerTest_AspectsChangeSet()
1508 : ToSetVisibility (0),
1511 Color (DEFAULT_COLOR),
1514 ToSetTypeOfLine (0),
1515 TypeOfLine (Aspect_TOL_SOLID),
1516 ToSetTransparency (0),
1519 Material (Graphic3d_NOM_DEFAULT),
1520 ToSetShowFreeBoundary (0),
1521 ToSetFreeBoundaryWidth (0),
1522 FreeBoundaryWidth (1.0),
1523 ToSetFreeBoundaryColor (0),
1524 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1525 ToEnableIsoOnTriangulation (-1),
1526 ToSetMaxParamValue (0),
1527 MaxParamValue (500000),
1528 ToSetSensitivity (0),
1532 //! @return true if no changes have been requested
1533 Standard_Boolean IsEmpty() const
1535 return ToSetVisibility == 0
1536 && ToSetLineWidth == 0
1537 && ToSetTransparency == 0
1539 && ToSetMaterial == 0
1540 && ToSetShowFreeBoundary == 0
1541 && ToSetFreeBoundaryColor == 0
1542 && ToSetFreeBoundaryWidth == 0
1543 && ToSetMaxParamValue == 0
1544 && ToSetSensitivity == 0;
1547 //! @return true if properties are valid
1548 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1550 Standard_Boolean isOk = Standard_True;
1551 if (Visibility != 0 && Visibility != 1)
1553 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1554 isOk = Standard_False;
1556 if (LineWidth <= 0.0
1557 || LineWidth > 10.0)
1559 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1560 isOk = Standard_False;
1562 if (Transparency < 0.0
1563 || Transparency > 1.0)
1565 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1566 isOk = Standard_False;
1569 && ToSetTransparency)
1571 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1572 isOk = Standard_False;
1574 if (ToSetMaterial == 1
1575 && Material == Graphic3d_NOM_DEFAULT)
1577 std::cout << "Error: unknown material " << MatName << ".\n";
1578 isOk = Standard_False;
1580 if (FreeBoundaryWidth <= 0.0
1581 || FreeBoundaryWidth > 10.0)
1583 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1584 isOk = Standard_False;
1586 if (MaxParamValue < 0.0)
1588 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1589 isOk = Standard_False;
1591 if (Sensitivity <= 0 && ToSetSensitivity)
1593 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1594 isOk = Standard_False;
1601 //==============================================================================
1602 //function : VAspects
1604 //==============================================================================
1605 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1606 Standard_Integer theArgNb,
1607 const char** theArgVec)
1609 TCollection_AsciiString aCmdName (theArgVec[0]);
1610 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1611 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1614 std::cerr << "Error: no active view!\n";
1618 Standard_Integer anArgIter = 1;
1619 Standard_Boolean isDefaults = Standard_False;
1620 NCollection_Sequence<TCollection_AsciiString> aNames;
1621 for (; anArgIter < theArgNb; ++anArgIter)
1623 TCollection_AsciiString anArg = theArgVec[anArgIter];
1624 if (anUpdateTool.parseRedrawMode (anArg))
1628 else if (!anArg.IsEmpty()
1629 && anArg.Value (1) != '-')
1631 aNames.Append (anArg);
1635 if (anArg == "-defaults")
1637 isDefaults = Standard_True;
1644 if (!aNames.IsEmpty() && isDefaults)
1646 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1650 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1651 aChanges.Append (ViewerTest_AspectsChangeSet());
1652 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1654 // parse syntax of legacy commands
1655 if (aCmdName == "vsetwidth")
1657 if (aNames.IsEmpty()
1658 || !aNames.Last().IsRealValue())
1660 std::cout << "Error: not enough arguments!\n";
1663 aChangeSet->ToSetLineWidth = 1;
1664 aChangeSet->LineWidth = aNames.Last().RealValue();
1665 aNames.Remove (aNames.Length());
1667 else if (aCmdName == "vunsetwidth")
1669 aChangeSet->ToSetLineWidth = -1;
1671 else if (aCmdName == "vsetcolor")
1673 if (aNames.IsEmpty())
1675 std::cout << "Error: not enough arguments!\n";
1678 aChangeSet->ToSetColor = 1;
1680 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1681 Standard_Boolean isOk = Standard_False;
1682 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1684 aChangeSet->Color = aColor;
1685 aNames.Remove (aNames.Length());
1686 isOk = Standard_True;
1688 else if (aNames.Length() >= 3)
1690 const TCollection_AsciiString anRgbStr[3] =
1692 aNames.Value (aNames.Upper() - 2),
1693 aNames.Value (aNames.Upper() - 1),
1694 aNames.Value (aNames.Upper() - 0)
1696 isOk = anRgbStr[0].IsRealValue()
1697 && anRgbStr[1].IsRealValue()
1698 && anRgbStr[2].IsRealValue();
1701 Graphic3d_Vec4d anRgb;
1702 anRgb.x() = anRgbStr[0].RealValue();
1703 anRgb.y() = anRgbStr[1].RealValue();
1704 anRgb.z() = anRgbStr[2].RealValue();
1705 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1706 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1707 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1709 std::cout << "Error: RGB color values should be within range 0..1!\n";
1712 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1713 aNames.Remove (aNames.Length());
1714 aNames.Remove (aNames.Length());
1715 aNames.Remove (aNames.Length());
1720 std::cout << "Error: not enough arguments!\n";
1724 else if (aCmdName == "vunsetcolor")
1726 aChangeSet->ToSetColor = -1;
1728 else if (aCmdName == "vsettransparency")
1730 if (aNames.IsEmpty()
1731 || !aNames.Last().IsRealValue())
1733 std::cout << "Error: not enough arguments!\n";
1736 aChangeSet->ToSetTransparency = 1;
1737 aChangeSet->Transparency = aNames.Last().RealValue();
1738 aNames.Remove (aNames.Length());
1740 else if (aCmdName == "vunsettransparency")
1742 aChangeSet->ToSetTransparency = -1;
1744 else if (aCmdName == "vsetmaterial")
1746 if (aNames.IsEmpty())
1748 std::cout << "Error: not enough arguments!\n";
1751 aChangeSet->ToSetMaterial = 1;
1752 aChangeSet->MatName = aNames.Last();
1753 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1754 aNames.Remove (aNames.Length());
1756 else if (aCmdName == "vunsetmaterial")
1758 aChangeSet->ToSetMaterial = -1;
1760 else if (anArgIter >= theArgNb)
1762 std::cout << "Error: not enough arguments!\n";
1766 if (!aChangeSet->IsEmpty())
1768 anArgIter = theArgNb;
1770 for (; anArgIter < theArgNb; ++anArgIter)
1772 TCollection_AsciiString anArg = theArgVec[anArgIter];
1774 if (anArg == "-setwidth"
1775 || anArg == "-setlinewidth")
1777 if (++anArgIter >= theArgNb)
1779 std::cout << "Error: wrong syntax at " << anArg << "\n";
1782 aChangeSet->ToSetLineWidth = 1;
1783 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1785 else if (anArg == "-unsetwidth"
1786 || anArg == "-unsetlinewidth")
1788 aChangeSet->ToSetLineWidth = -1;
1789 aChangeSet->LineWidth = 1.0;
1791 else if (anArg == "-settransp"
1792 || anArg == "-settransparency")
1794 if (++anArgIter >= theArgNb)
1796 std::cout << "Error: wrong syntax at " << anArg << "\n";
1799 aChangeSet->ToSetTransparency = 1;
1800 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1801 if (aChangeSet->Transparency >= 0.0
1802 && aChangeSet->Transparency <= Precision::Confusion())
1804 aChangeSet->ToSetTransparency = -1;
1805 aChangeSet->Transparency = 0.0;
1808 else if (anArg == "-setvis"
1809 || anArg == "-setvisibility")
1811 if (++anArgIter >= theArgNb)
1813 std::cout << "Error: wrong syntax at " << anArg << "\n";
1817 aChangeSet->ToSetVisibility = 1;
1818 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1820 else if (anArg == "-setalpha")
1822 if (++anArgIter >= theArgNb)
1824 std::cout << "Error: wrong syntax at " << anArg << "\n";
1827 aChangeSet->ToSetTransparency = 1;
1828 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1829 if (aChangeSet->Transparency < 0.0
1830 || aChangeSet->Transparency > 1.0)
1832 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1835 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1836 if (aChangeSet->Transparency >= 0.0
1837 && aChangeSet->Transparency <= Precision::Confusion())
1839 aChangeSet->ToSetTransparency = -1;
1840 aChangeSet->Transparency = 0.0;
1843 else if (anArg == "-unsettransp"
1844 || anArg == "-unsettransparency"
1845 || anArg == "-unsetalpha"
1846 || anArg == "-opaque")
1848 aChangeSet->ToSetTransparency = -1;
1849 aChangeSet->Transparency = 0.0;
1851 else if (anArg == "-setcolor")
1853 Standard_Integer aNbComps = 0;
1854 Standard_Integer aCompIter = anArgIter + 1;
1855 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1857 if (theArgVec[aCompIter][0] == '-')
1866 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1867 Standard_CString aName = theArgVec[anArgIter + 1];
1868 if (!Quantity_Color::ColorFromName (aName, aColor))
1870 std::cout << "Error: unknown color name '" << aName << "'\n";
1873 aChangeSet->Color = aColor;
1878 Graphic3d_Vec3d anRgb;
1879 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1880 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1881 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1882 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1883 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1884 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1886 std::cout << "Error: RGB color values should be within range 0..1!\n";
1889 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1894 std::cout << "Error: wrong syntax at " << anArg << "\n";
1898 aChangeSet->ToSetColor = 1;
1899 anArgIter += aNbComps;
1901 else if (anArg == "-setlinetype")
1903 if (++anArgIter >= theArgNb)
1905 std::cout << "Error: wrong syntax at " << anArg << "\n";
1909 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1912 if (aValue.IsEqual ("solid"))
1914 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1916 else if (aValue.IsEqual ("dot"))
1918 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1920 else if (aValue.IsEqual ("dash"))
1922 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1924 else if (aValue.IsEqual ("dotdash"))
1926 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1930 std::cout << "Error: wrong syntax at " << anArg << "\n";
1934 aChangeSet->ToSetTypeOfLine = 1;
1936 else if (anArg == "-unsetlinetype")
1938 aChangeSet->ToSetTypeOfLine = -1;
1940 else if (anArg == "-unsetcolor")
1942 aChangeSet->ToSetColor = -1;
1943 aChangeSet->Color = DEFAULT_COLOR;
1945 else if (anArg == "-setmat"
1946 || anArg == "-setmaterial")
1948 if (++anArgIter >= theArgNb)
1950 std::cout << "Error: wrong syntax at " << anArg << "\n";
1953 aChangeSet->ToSetMaterial = 1;
1954 aChangeSet->MatName = theArgVec[anArgIter];
1955 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1957 else if (anArg == "-unsetmat"
1958 || anArg == "-unsetmaterial")
1960 aChangeSet->ToSetMaterial = -1;
1961 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1963 else if (anArg == "-subshape"
1964 || anArg == "-subshapes")
1968 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1972 if (aNames.IsEmpty())
1974 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1978 aChanges.Append (ViewerTest_AspectsChangeSet());
1979 aChangeSet = &aChanges.ChangeLast();
1981 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1983 Standard_CString aSubShapeName = theArgVec[anArgIter];
1984 if (*aSubShapeName == '-')
1990 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1991 if (aSubShape.IsNull())
1993 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1996 aChangeSet->SubShapes.Append (aSubShape);
1999 if (aChangeSet->SubShapes.IsEmpty())
2001 std::cerr << "Error: empty list is specified after -subshapes!\n";
2005 else if (anArg == "-freeboundary"
2008 if (++anArgIter >= theArgNb)
2010 std::cout << "Error: wrong syntax at " << anArg << "\n";
2013 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2018 aChangeSet->ToSetShowFreeBoundary = 1;
2020 else if (aValue == "off"
2023 aChangeSet->ToSetShowFreeBoundary = -1;
2027 std::cout << "Error: wrong syntax at " << anArg << "\n";
2031 else if (anArg == "-setfreeboundarywidth"
2032 || anArg == "-setfbwidth")
2034 if (++anArgIter >= theArgNb)
2036 std::cout << "Error: wrong syntax at " << anArg << "\n";
2039 aChangeSet->ToSetFreeBoundaryWidth = 1;
2040 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2042 else if (anArg == "-unsetfreeboundarywidth"
2043 || anArg == "-unsetfbwidth")
2045 aChangeSet->ToSetFreeBoundaryWidth = -1;
2046 aChangeSet->FreeBoundaryWidth = 1.0;
2048 else if (anArg == "-setfreeboundarycolor"
2049 || anArg == "-setfbcolor")
2051 Standard_Integer aNbComps = 0;
2052 Standard_Integer aCompIter = anArgIter + 1;
2053 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2055 if (theArgVec[aCompIter][0] == '-')
2064 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2065 Standard_CString aName = theArgVec[anArgIter + 1];
2066 if (!Quantity_Color::ColorFromName (aName, aColor))
2068 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2071 aChangeSet->FreeBoundaryColor = aColor;
2076 Graphic3d_Vec3d anRgb;
2077 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2078 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2079 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2080 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2081 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2082 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2084 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2087 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2092 std::cout << "Error: wrong syntax at " << anArg << "\n";
2096 aChangeSet->ToSetFreeBoundaryColor = 1;
2097 anArgIter += aNbComps;
2099 else if (anArg == "-unsetfreeboundarycolor"
2100 || anArg == "-unsetfbcolor")
2102 aChangeSet->ToSetFreeBoundaryColor = -1;
2103 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2105 else if (anArg == "-unset")
2107 aChangeSet->ToSetVisibility = 1;
2108 aChangeSet->Visibility = 1;
2109 aChangeSet->ToSetLineWidth = -1;
2110 aChangeSet->LineWidth = 1.0;
2111 aChangeSet->ToSetTypeOfLine = -1;
2112 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2113 aChangeSet->ToSetTransparency = -1;
2114 aChangeSet->Transparency = 0.0;
2115 aChangeSet->ToSetColor = -1;
2116 aChangeSet->Color = DEFAULT_COLOR;
2117 aChangeSet->ToSetMaterial = -1;
2118 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2119 aChangeSet->ToSetShowFreeBoundary = -1;
2120 aChangeSet->ToSetFreeBoundaryColor = -1;
2121 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2122 aChangeSet->ToSetFreeBoundaryWidth = -1;
2123 aChangeSet->FreeBoundaryWidth = 1.0;
2125 else if (anArg == "-isoontriangulation"
2126 || anArg == "-isoontriang")
2128 if (++anArgIter >= theArgNb)
2130 std::cout << "Error: wrong syntax at " << anArg << "\n";
2133 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2138 aChangeSet->ToEnableIsoOnTriangulation = 1;
2140 else if (aValue == "off"
2143 aChangeSet->ToEnableIsoOnTriangulation = 0;
2147 std::cout << "Error: wrong syntax at " << anArg << "\n";
2151 else if (anArg == "-setmaxparamvalue")
2153 if (++anArgIter >= theArgNb)
2155 std::cout << "Error: wrong syntax at " << anArg << "\n";
2158 aChangeSet->ToSetMaxParamValue = 1;
2159 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2161 else if (anArg == "-setsensitivity")
2165 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2169 if (aNames.IsEmpty())
2171 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2175 if (anArgIter + 2 >= theArgNb)
2177 std::cout << "Error: wrong syntax at " << anArg << "\n";
2180 aChangeSet->ToSetSensitivity = 1;
2181 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2182 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2186 std::cout << "Error: wrong syntax at " << anArg << "\n";
2191 Standard_Boolean isFirst = Standard_True;
2192 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2193 aChangesIter.More(); aChangesIter.Next())
2195 if (!aChangesIter.Value().Validate (!isFirst))
2199 isFirst = Standard_False;
2202 if (aCtx->HasOpenedContext())
2204 aCtx->CloseLocalContext();
2207 // special case for -defaults parameter.
2208 // all changed values will be set to DefaultDrawer.
2211 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2213 if (aChangeSet->ToSetLineWidth != 0)
2215 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2216 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2217 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2218 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2220 if (aChangeSet->ToSetColor != 0)
2222 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2223 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2224 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2225 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2226 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2227 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2229 if (aChangeSet->ToSetTypeOfLine != 0)
2231 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2232 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2233 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2234 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2235 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2237 if (aChangeSet->ToSetTransparency != 0)
2239 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2241 if (aChangeSet->ToSetMaterial != 0)
2243 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2245 if (aChangeSet->ToSetShowFreeBoundary == 1)
2247 aDrawer->SetFreeBoundaryDraw (Standard_True);
2249 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2251 aDrawer->SetFreeBoundaryDraw (Standard_False);
2253 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2255 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2257 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2259 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2261 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2263 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2265 if (aChangeSet->ToSetMaxParamValue != 0)
2267 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2270 // redisplay all objects in context
2271 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2273 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2276 aCtx->Redisplay (aPrs, Standard_False);
2282 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2284 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2285 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2286 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2287 Handle(AIS_ColoredShape) aColoredPrs;
2288 Standard_Boolean toDisplay = Standard_False;
2289 Standard_Boolean toRedisplay = Standard_False;
2290 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2292 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2293 if (aShapePrs.IsNull())
2295 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2298 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2299 if (aColoredPrs.IsNull())
2301 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2302 aCtx->Remove (aShapePrs, Standard_False);
2303 GetMapOfAIS().UnBind2 (aName);
2304 GetMapOfAIS().Bind (aColoredPrs, aName);
2305 toDisplay = Standard_True;
2306 aShapePrs = aColoredPrs;
2313 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2314 aChangeSet = &aChangesIter.ChangeValue();
2315 if (aChangeSet->ToSetVisibility == 1)
2317 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2318 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2320 else if (aChangeSet->ToSetMaterial == 1)
2322 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2324 else if (aChangeSet->ToSetMaterial == -1)
2326 aCtx->UnsetMaterial (aPrs, Standard_False);
2328 if (aChangeSet->ToSetColor == 1)
2330 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2332 else if (aChangeSet->ToSetColor == -1)
2334 aCtx->UnsetColor (aPrs, Standard_False);
2336 if (aChangeSet->ToSetTransparency == 1)
2338 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2340 else if (aChangeSet->ToSetTransparency == -1)
2342 aCtx->UnsetTransparency (aPrs, Standard_False);
2344 if (aChangeSet->ToSetLineWidth == 1)
2346 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2348 else if (aChangeSet->ToSetLineWidth == -1)
2350 aCtx->UnsetWidth (aPrs, Standard_False);
2352 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2354 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2355 toRedisplay = Standard_True;
2357 else if (aChangeSet->ToSetSensitivity != 0)
2359 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2361 if (!aDrawer.IsNull())
2363 if (aChangeSet->ToSetShowFreeBoundary == 1)
2365 aDrawer->SetFreeBoundaryDraw (Standard_True);
2366 toRedisplay = Standard_True;
2368 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2370 aDrawer->SetFreeBoundaryDraw (Standard_False);
2371 toRedisplay = Standard_True;
2373 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2375 Handle(Prs3d_LineAspect) aBoundaryAspect =
2376 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2377 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2378 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2379 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2380 toRedisplay = Standard_True;
2382 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2384 Handle(Prs3d_LineAspect) aBoundaryAspect =
2385 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2386 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2387 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2388 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2389 toRedisplay = Standard_True;
2391 if (aChangeSet->ToSetTypeOfLine != 0)
2393 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2394 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2395 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2396 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2397 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2398 toRedisplay = Standard_True;
2400 if (aChangeSet->ToSetMaxParamValue != 0)
2402 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2406 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2408 aChangeSet = &aChangesIter.ChangeValue();
2409 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2410 aSubShapeIter.More(); aSubShapeIter.Next())
2412 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2413 if (aChangeSet->ToSetVisibility == 1)
2415 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2416 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2418 if (aChangeSet->ToSetColor == 1)
2420 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2422 if (aChangeSet->ToSetLineWidth == 1)
2424 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2426 if (aChangeSet->ToSetColor == -1
2427 || aChangeSet->ToSetLineWidth == -1)
2429 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2431 if (aChangeSet->ToSetMaxParamValue != 0)
2433 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2434 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2436 if (aChangeSet->ToSetSensitivity != 0)
2438 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2444 aCtx->Display (aPrs, Standard_False);
2448 aCtx->Redisplay (aPrs, Standard_False);
2450 else if (!aColoredPrs.IsNull())
2452 aCtx->Redisplay (aColoredPrs, Standard_False);
2459 //==============================================================================
2460 //function : VDonly2
2462 //purpose : Display only a selected or named object
2463 // if there is no selected or named object s, nothing is done
2464 //==============================================================================
2465 static int VDonly2 (Draw_Interpretor& ,
2466 Standard_Integer theArgNb,
2467 const char** theArgVec)
2469 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2470 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2473 std::cerr << "Error: no active view!\n";
2477 if (aCtx->HasOpenedContext())
2479 aCtx->CloseLocalContext();
2482 Standard_Integer anArgIter = 1;
2483 for (; anArgIter < theArgNb; ++anArgIter)
2485 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2491 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2492 if (anArgIter >= theArgNb)
2494 // display only selected objects
2495 if (aCtx->NbSelected() < 1)
2500 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2502 aDispSet.Add (aCtx->SelectedInteractive());
2507 // display only specified objects
2508 for (; anArgIter < theArgNb; ++anArgIter)
2510 TCollection_AsciiString aName = theArgVec[anArgIter];
2511 if (GetMapOfAIS().IsBound2 (aName))
2513 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2514 if (!aShape.IsNull())
2516 aCtx->Display (aShape, Standard_False);
2517 aDispSet.Add (aShape);
2523 // weed out other objects
2524 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2526 if (aDispSet.Contains (anIter.Key1()))
2531 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2532 if (aShape.IsNull())
2534 aCtx->Erase (aShape, Standard_False);
2540 //==============================================================================
2541 //function : VRemove
2542 //purpose : Removes selected or named objects.
2543 // If there is no selected or named objects,
2544 // all objects in the viewer can be removed with argument -all.
2545 // If -context is in arguments, the object is not deleted from the map of
2546 // objects (deleted only from the current context).
2547 //==============================================================================
2548 int VRemove (Draw_Interpretor& theDI,
2549 Standard_Integer theArgNb,
2550 const char** theArgVec)
2552 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2553 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2556 std::cerr << "Error: no active view!\n";
2560 Standard_Boolean isContextOnly = Standard_False;
2561 Standard_Boolean toRemoveAll = Standard_False;
2562 Standard_Boolean toPrintInfo = Standard_True;
2563 Standard_Boolean toRemoveLocal = Standard_False;
2565 Standard_Integer anArgIter = 1;
2566 for (; anArgIter < theArgNb; ++anArgIter)
2568 TCollection_AsciiString anArg = theArgVec[anArgIter];
2570 if (anArg == "-context")
2572 isContextOnly = Standard_True;
2574 else if (anArg == "-all")
2576 toRemoveAll = Standard_True;
2578 else if (anArg == "-noinfo")
2580 toPrintInfo = Standard_False;
2582 else if (anArg == "-local")
2584 toRemoveLocal = Standard_True;
2586 else if (anUpdateTool.parseRedrawMode (anArg))
2596 && anArgIter < theArgNb)
2598 std::cerr << "Error: wrong syntax!\n";
2602 if (toRemoveLocal && !aCtx->HasOpenedContext())
2604 std::cerr << "Error: local selection context is not open.\n";
2607 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2609 aCtx->CloseAllContexts (Standard_False);
2612 NCollection_List<TCollection_AsciiString> anIONameList;
2615 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2616 anIter.More(); anIter.Next())
2618 anIONameList.Append (anIter.Key2());
2621 else if (anArgIter < theArgNb) // removed objects names are in argument list
2623 for (; anArgIter < theArgNb; ++anArgIter)
2625 TCollection_AsciiString aName = theArgVec[anArgIter];
2626 if (!GetMapOfAIS().IsBound2 (aName))
2628 theDI << aName.ToCString() << " was not bound to some object.\n";
2632 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2633 if (anIO->GetContext() != aCtx)
2635 theDI << aName.ToCString() << " was not displayed in current context.\n";
2636 theDI << "Please activate view with this object displayed and try again.\n";
2640 anIONameList.Append (aName);
2644 else if (aCtx->NbSelected() > 0)
2646 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2647 anIter.More(); anIter.Next())
2649 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2650 if (!aCtx->IsSelected (anIO))
2655 anIONameList.Append (anIter.Key2());
2660 // Unbind all removed objects from the map of displayed IO.
2661 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2662 anIter.More(); anIter.Next())
2664 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2665 aCtx->Remove (anIO, Standard_False);
2668 theDI << anIter.Value().ToCString() << " was removed\n";
2672 GetMapOfAIS().UnBind2 (anIter.Value());
2676 // Close local context if it is empty
2677 TColStd_MapOfTransient aLocalIO;
2678 if (aCtx->HasOpenedContext()
2679 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2681 aCtx->CloseAllContexts (Standard_False);
2687 //==============================================================================
2689 //purpose : Erase some selected or named objects
2690 // if there is no selected or named objects, the whole viewer is erased
2691 //==============================================================================
2692 int VErase (Draw_Interpretor& theDI,
2693 Standard_Integer theArgNb,
2694 const char** theArgVec)
2696 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2697 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2698 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2701 std::cerr << "Error: no active view!\n";
2705 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2707 Standard_Integer anArgIter = 1;
2708 Standard_Boolean toEraseLocal = Standard_False;
2709 Standard_Boolean toEraseInView = Standard_False;
2710 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2711 for (; anArgIter < theArgNb; ++anArgIter)
2713 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2714 anArgCase.LowerCase();
2715 if (anUpdateTool.parseRedrawMode (anArgCase))
2719 else if (anArgCase == "-local")
2721 toEraseLocal = Standard_True;
2723 else if (anArgCase == "-view"
2724 || anArgCase == "-inview")
2726 toEraseInView = Standard_True;
2730 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2734 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2736 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2740 if (toEraseLocal && !aCtx->HasOpenedContext())
2742 std::cerr << "Error: local selection context is not open.\n";
2745 else if (!toEraseLocal && aCtx->HasOpenedContext())
2747 aCtx->CloseAllContexts (Standard_False);
2750 if (!aNamesOfEraseIO.IsEmpty())
2752 // Erase named objects
2753 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2755 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2756 if (!GetMapOfAIS().IsBound2 (aName))
2761 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2762 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2763 theDI << aName.ToCString() << " ";
2768 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2772 aCtx->Erase (anIO, Standard_False);
2777 else if (!toEraseAll && aCtx->NbSelected() > 0)
2779 // Erase selected objects
2780 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
2781 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2782 anIter.More(); anIter.Next())
2784 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2786 && aCtx->IsSelected (anIO))
2788 theDI << anIter.Key2().ToCString() << " ";
2791 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2793 else if (aHasOpenedContext)
2795 aCtx->Erase (anIO, Standard_False);
2802 aCtx->EraseSelected (Standard_False);
2807 // Erase all objects
2808 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2809 anIter.More(); anIter.Next())
2811 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2816 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2820 aCtx->Erase (anIO, Standard_False);
2829 //==============================================================================
2830 //function : VDisplayAll
2832 //purpose : Display all the objects of the Map
2833 //==============================================================================
2834 static int VDisplayAll (Draw_Interpretor& ,
2835 Standard_Integer theArgNb,
2836 const char** theArgVec)
2839 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2840 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2843 std::cerr << "Error: no active view!\n";
2847 Standard_Integer anArgIter = 1;
2848 Standard_Boolean toDisplayLocal = Standard_False;
2849 for (; anArgIter < theArgNb; ++anArgIter)
2851 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2852 anArgCase.LowerCase();
2853 if (anArgCase == "-local")
2855 toDisplayLocal = Standard_True;
2857 else if (anUpdateTool.parseRedrawMode (anArgCase))
2866 if (anArgIter < theArgNb)
2868 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2872 if (toDisplayLocal && !aCtx->HasOpenedContext())
2874 std::cerr << "Error: local selection context is not open.\n";
2877 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2879 aCtx->CloseLocalContext (Standard_False);
2882 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2883 anIter.More(); anIter.Next())
2885 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2886 aCtx->Erase (aShape, Standard_False);
2889 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2890 anIter.More(); anIter.Next())
2892 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2893 aCtx->Display (aShape, Standard_False);
2898 //! Auxiliary method to find presentation
2899 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2900 const Handle(AIS_InteractiveObject)& theIO,
2901 const Standard_Integer theMode)
2905 return Handle(PrsMgr_Presentation)();
2910 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2912 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2915 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2917 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2919 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2921 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2923 return Handle(PrsMgr_Presentation)();
2926 enum ViewerTest_BndAction
2933 //! Auxiliary method to print bounding box of presentation
2934 inline void bndPresentation (Draw_Interpretor& theDI,
2935 const Handle(PrsMgr_Presentation)& thePrs,
2936 const TCollection_AsciiString& theName,
2937 const ViewerTest_BndAction theAction)
2941 case BndAction_Hide:
2943 thePrs->Presentation()->GraphicUnHighlight();
2946 case BndAction_Show:
2948 Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
2949 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2950 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2951 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2952 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
2955 case BndAction_Print:
2957 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2958 gp_Pnt aMin = aBox.CornerMin();
2959 gp_Pnt aMax = aBox.CornerMax();
2960 theDI << theName << "\n"
2961 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2962 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2968 //==============================================================================
2969 //function : VBounding
2971 //==============================================================================
2972 int VBounding (Draw_Interpretor& theDI,
2973 Standard_Integer theArgNb,
2974 const char** theArgVec)
2976 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2977 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2980 std::cout << "Error: no active view!\n";
2984 ViewerTest_BndAction anAction = BndAction_Show;
2985 Standard_Integer aMode = -1;
2987 Standard_Integer anArgIter = 1;
2988 for (; anArgIter < theArgNb; ++anArgIter)
2990 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2992 if (anArg == "-print")
2994 anAction = BndAction_Print;
2996 else if (anArg == "-show")
2998 anAction = BndAction_Show;
3000 else if (anArg == "-hide")
3002 anAction = BndAction_Hide;
3004 else if (anArg == "-mode")
3006 if (++anArgIter >= theArgNb)
3008 std::cout << "Error: wrong syntax at " << anArg << "\n";
3011 aMode = Draw::Atoi (theArgVec[anArgIter]);
3013 else if (!anUpdateTool.parseRedrawMode (anArg))
3019 if (anArgIter < theArgNb)
3021 // has a list of names
3022 for (; anArgIter < theArgNb; ++anArgIter)
3024 TCollection_AsciiString aName = theArgVec[anArgIter];
3025 if (!GetMapOfAIS().IsBound2 (aName))
3027 std::cout << "Error: presentation " << aName << " does not exist\n";
3031 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3032 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3035 std::cout << "Error: presentation " << aName << " does not exist\n";
3038 bndPresentation (theDI, aPrs, aName, anAction);
3041 else if (aCtx->NbSelected() > 0)
3043 // remove all currently selected objects
3044 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3046 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3047 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3050 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
3057 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3058 anIter.More(); anIter.Next())
3060 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3061 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3064 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
3071 //==============================================================================
3072 //function : VTexture
3074 //==============================================================================
3075 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
3077 TCollection_AsciiString aCommandName (theArgv[0]);
3079 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3080 if (aCommandName == "vtexture")
3084 std::cout << theArgv[0] << ": invalid arguments.\n";
3085 std::cout << "Type help for more information.\n";
3089 // look for options of vtexture command
3090 TCollection_AsciiString aParseKey;
3091 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3093 TCollection_AsciiString anArg (theArgv [anArgIt]);
3096 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3099 aParseKey.Remove (1);
3100 aParseKey.UpperCase();
3101 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3105 if (aParseKey.IsEmpty())
3110 aMapOfArgs(aParseKey)->Append (anArg);
3113 else if (aCommandName == "vtexscale"
3114 || aCommandName == "vtexorigin"
3115 || aCommandName == "vtexrepeat")
3117 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3118 // equal to -scale, -origin, -repeat options of vtexture command
3119 if (theArgsNb < 2 || theArgsNb > 4)
3121 std::cout << theArgv[0] << ": invalid arguments.\n";
3122 std::cout << "Type help for more information.\n";
3126 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
3129 anArgs->Append ("OFF");
3131 else if (theArgsNb == 4)
3133 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3134 anArgs->Append (TCollection_AsciiString (theArgv[3]));
3137 TCollection_AsciiString anArgKey;
3138 if (aCommandName == "vtexscale")
3142 else if (aCommandName == "vtexorigin")
3144 anArgKey = "ORIGIN";
3148 anArgKey = "REPEAT";
3151 aMapOfArgs.Bind (anArgKey, anArgs);
3153 else if (aCommandName == "vtexdefault")
3155 // scan for parameters of vtexdefault command
3156 // equal to -default option of vtexture command
3157 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
3160 // Check arguments for validity
3161 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3162 for (; aMapIt.More(); aMapIt.Next())
3164 const TCollection_AsciiString& aKey = aMapIt.Key();
3165 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3167 // -scale, -origin, -repeat: one argument "off", or two real values
3168 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3169 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3170 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3175 // -modulate: single argument "on" / "off"
3176 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3181 // -default: no arguments
3182 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3187 TCollection_AsciiString aLowerKey;
3190 aLowerKey.LowerCase();
3191 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3192 std::cout << "Type help for more information.\n";
3196 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3197 if (anAISContext.IsNull())
3199 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
3203 Standard_Integer aPreviousMode = 0;
3205 TCollection_AsciiString aShapeName (theArgv[1]);
3206 Handle(AIS_InteractiveObject) anIO;
3208 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3209 if (aMapOfIO.IsBound2 (aShapeName))
3211 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3216 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3220 Handle(AIS_TexturedShape) aTexturedIO;
3221 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3223 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3224 aPreviousMode = aTexturedIO->DisplayMode();
3228 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3230 if (anIO->HasTransformation())
3232 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3233 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3236 anAISContext->Remove (anIO, Standard_False);
3237 GetMapOfAIS().UnBind1 (anIO);
3238 GetMapOfAIS().UnBind2 (aShapeName);
3239 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3242 // -------------------------------------------
3243 // Turn texturing on/off - only for vtexture
3244 // -------------------------------------------
3246 if (aCommandName == "vtexture")
3248 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3250 if (aTextureArg.IsEmpty())
3252 std::cout << aCommandName << ": Texture mapping disabled.\n";
3253 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
3255 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3256 if (aPreviousMode == 3)
3258 anAISContext->RecomputePrsOnly (aTexturedIO);
3261 anAISContext->Display (aTexturedIO, Standard_True);
3264 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3266 if (aTextureArg == "?")
3268 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3270 theDi << "\n Files in current directory : \n\n";
3271 theDi.Eval ("glob -nocomplain *");
3273 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3274 aCmnd += aTextureFolder;
3277 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
3278 theDi.Eval (aCmnd.ToCString());
3283 aTexturedIO->SetTextureFileName (aTextureArg);
3288 // ------------------------------------
3289 // Process other options and commands
3290 // ------------------------------------
3292 Handle(TColStd_HSequenceOfAsciiString) aValues;
3293 if (aMapOfArgs.Find ("DEFAULT", aValues))
3295 aTexturedIO->SetTextureRepeat (Standard_False);
3296 aTexturedIO->SetTextureOrigin (Standard_False);
3297 aTexturedIO->SetTextureScale (Standard_False);
3298 aTexturedIO->EnableTextureModulate();
3302 if (aMapOfArgs.Find ("SCALE", aValues))
3304 if (aValues->Value(1) != "OFF")
3306 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3310 aTexturedIO->SetTextureScale (Standard_False);
3314 if (aMapOfArgs.Find ("ORIGIN", aValues))
3316 if (aValues->Value(1) != "OFF")
3318 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3322 aTexturedIO->SetTextureOrigin (Standard_False);
3326 if (aMapOfArgs.Find ("REPEAT", aValues))
3328 if (aValues->Value(1) != "OFF")
3330 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3334 aTexturedIO->SetTextureRepeat (Standard_False);
3338 if (aMapOfArgs.Find ("MODULATE", aValues))
3340 if (aValues->Value(1) == "ON")
3342 aTexturedIO->EnableTextureModulate();
3346 aTexturedIO->DisableTextureModulate();
3351 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3353 anAISContext->RecomputePrsOnly (aTexturedIO);
3357 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3358 anAISContext->Display (aTexturedIO, Standard_True);
3359 anAISContext->Update (aTexturedIO,Standard_True);
3365 //! Auxiliary method to parse transformation persistence flags
3366 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3367 Standard_Integer& theFlags)
3369 if (theFlagString == "pan")
3371 theFlags |= Graphic3d_TMF_PanPers;
3373 else if (theFlagString == "zoom")
3375 theFlags |= Graphic3d_TMF_ZoomPers;
3377 else if (theFlagString == "rotate")
3379 theFlags |= Graphic3d_TMF_RotatePers;
3381 else if (theFlagString == "trihedron")
3383 theFlags = Graphic3d_TMF_TriedronPers;
3385 else if (theFlagString == "full")
3387 theFlags = Graphic3d_TMF_FullPers;
3389 else if (theFlagString == "none")
3391 theFlags = Graphic3d_TMF_None;
3395 return Standard_False;
3398 return Standard_True;
3401 //==============================================================================
3402 //function : VDisplay2
3404 //purpose : Display an object from its name
3405 //==============================================================================
3406 static int VDisplay2 (Draw_Interpretor& theDI,
3407 Standard_Integer theArgNb,
3408 const char** theArgVec)
3412 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3416 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3419 ViewerTest::ViewerInit();
3420 aCtx = ViewerTest::GetAISContext();
3423 // Parse input arguments
3424 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3425 Standard_Integer isMutable = -1;
3426 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3427 Standard_Boolean toDisplayLocal = Standard_False;
3428 Standard_Boolean toReDisplay = Standard_False;
3429 Standard_Integer isSelectable = -1;
3430 Standard_Integer anObjDispMode = -2;
3431 Standard_Integer anObjHighMode = -2;
3432 Standard_Boolean toSetTrsfPers = Standard_False;
3433 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3435 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3436 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3437 Standard_Integer toDisplayInView = Standard_False;
3438 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3440 const TCollection_AsciiString aName = theArgVec[anArgIter];
3441 TCollection_AsciiString aNameCase = aName;
3442 aNameCase.LowerCase();
3443 if (anUpdateTool.parseRedrawMode (aName))
3447 else if (aNameCase == "-mutable")
3451 else if (aNameCase == "-neutral")
3453 aDispStatus = AIS_DS_Displayed;
3455 else if (aNameCase == "-immediate"
3456 || aNameCase == "-top")
3458 aZLayer = Graphic3d_ZLayerId_Top;
3460 else if (aNameCase == "-topmost")
3462 aZLayer = Graphic3d_ZLayerId_Topmost;
3464 else if (aNameCase == "-osd"
3465 || aNameCase == "-toposd"
3466 || aNameCase == "-overlay")
3468 aZLayer = Graphic3d_ZLayerId_TopOSD;
3470 else if (aNameCase == "-botosd"
3471 || aNameCase == "-underlay")
3473 aZLayer = Graphic3d_ZLayerId_BotOSD;
3475 else if (aNameCase == "-select"
3476 || aNameCase == "-selectable")
3480 else if (aNameCase == "-noselect"
3481 || aNameCase == "-noselection")
3485 else if (aNameCase == "-dispmode"
3486 || aNameCase == "-displaymode")
3488 if (++anArgIter >= theArgNb)
3490 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3494 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3496 else if (aNameCase == "-highmode"
3497 || aNameCase == "-highlightmode")
3499 if (++anArgIter >= theArgNb)
3501 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3505 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3507 else if (aNameCase == "-3d")
3509 toSetTrsfPers = Standard_True;
3510 aTrsfPersFlags = Graphic3d_TMF_None;
3512 else if (aNameCase == "-2d")
3514 toSetTrsfPers = Standard_True;
3515 aTrsfPersFlags = Graphic3d_TMF_2d;
3517 else if (aNameCase == "-2dtopdown")
3519 toSetTrsfPers = Standard_True;
3520 aTrsfPersFlags = Graphic3d_TMF_2d | Graphic3d_TMF_2d_IsTopDown;
3522 else if (aNameCase == "-trsfpers"
3523 || aNameCase == "-pers")
3525 if (++anArgIter >= theArgNb)
3527 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3531 toSetTrsfPers = Standard_True;
3532 aTrsfPersFlags = Graphic3d_TMF_None;
3533 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3534 aPersFlags.LowerCase();
3535 for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
3537 if (aParserPos == -1)
3539 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3541 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3547 TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
3548 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3550 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3553 aPersFlags = anOtherFlags;
3556 else if (aNameCase == "-trsfperspos"
3557 || aNameCase == "-perspos")
3559 if (anArgIter + 2 >= theArgNb)
3561 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3565 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3566 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3567 TCollection_AsciiString aZ = "0";
3568 if (!aX.IsIntegerValue()
3569 || !aY.IsIntegerValue())
3571 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3574 if (anArgIter + 1 < theArgNb)
3576 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3577 if (aTemp.IsIntegerValue())
3583 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
3585 else if (aNameCase == "-layer")
3587 if (++anArgIter >= theArgNb)
3589 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3593 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3594 if (!aValue.IsIntegerValue())
3596 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3600 aZLayer = aValue.IntegerValue();
3602 else if (aNameCase == "-view"
3603 || aNameCase == "-inview")
3605 toDisplayInView = Standard_True;
3607 else if (aNameCase == "-local")
3609 aDispStatus = AIS_DS_Temporary;
3610 toDisplayLocal = Standard_True;
3612 else if (aNameCase == "-redisplay")
3614 toReDisplay = Standard_True;
3618 aNamesOfDisplayIO.Append (aName);
3622 if (aNamesOfDisplayIO.IsEmpty())
3624 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3628 // Prepare context for display
3629 if (toDisplayLocal && !aCtx->HasOpenedContext())
3631 aCtx->OpenLocalContext (Standard_False);
3633 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3635 aCtx->CloseAllContexts (Standard_False);
3638 // Display interactive objects
3639 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3641 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3643 if (!GetMapOfAIS().IsBound2 (aName))
3645 // create the AIS_Shape from a name
3646 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3647 if (!aShape.IsNull())
3649 if (isMutable != -1)
3651 aShape->SetMutable (isMutable == 1);
3653 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3655 aShape->SetZLayer (aZLayer);
3659 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3661 if (anObjDispMode != -2)
3663 aShape->SetDisplayMode (anObjDispMode);
3665 if (anObjHighMode != -2)
3667 aShape->SetHilightMode (anObjHighMode);
3669 if (!toDisplayLocal)
3670 GetMapOfAIS().Bind (aShape, aName);
3672 Standard_Integer aDispMode = aShape->HasDisplayMode()
3673 ? aShape->DisplayMode()
3674 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3675 ? aCtx->DisplayMode()
3677 Standard_Integer aSelMode = -1;
3678 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3680 aSelMode = aShape->GlobalSelectionMode();
3683 aCtx->Display (aShape, aDispMode, aSelMode,
3684 Standard_False, aShape->AcceptShapeDecomposition(),
3686 if (toDisplayInView)
3688 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3690 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3692 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3697 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3702 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3703 if (isMutable != -1)
3705 aShape->SetMutable (isMutable == 1);
3707 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3709 aShape->SetZLayer (aZLayer);
3713 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3715 if (anObjDispMode != -2)
3717 aShape->SetDisplayMode (anObjDispMode);
3719 if (anObjHighMode != -2)
3721 aShape->SetHilightMode (anObjHighMode);
3723 Standard_Integer aDispMode = aShape->HasDisplayMode()
3724 ? aShape->DisplayMode()
3725 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3726 ? aCtx->DisplayMode()
3728 Standard_Integer aSelMode = -1;
3729 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3731 aSelMode = aShape->GlobalSelectionMode();
3734 if (aShape->Type() == AIS_KOI_Datum)
3736 aCtx->Display (aShape, Standard_False);
3740 theDI << "Display " << aName.ToCString() << "\n";
3742 // update the Shape in the AIS_Shape
3743 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3744 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3745 if (!aShapePrs.IsNull())
3747 if (!aShapePrs->Shape().IsEqual (aNewShape))
3749 toReDisplay = Standard_True;
3751 aShapePrs->Set (aNewShape);
3755 aCtx->Redisplay (aShape, Standard_False);
3760 aCtx->Erase (aShape);
3762 aCtx->Display (aShape, aDispMode, aSelMode,
3763 Standard_False, aShape->AcceptShapeDecomposition(),
3765 if (toDisplayInView)
3767 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3775 //===============================================================================================
3776 //function : VUpdate
3778 //===============================================================================================
3779 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3781 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3782 if (aContextAIS.IsNull())
3784 std::cout << theArgVec[0] << "AIS context is not available.\n";
3790 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3794 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3796 AIS_ListOfInteractive aListOfIO;
3798 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3800 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3802 Handle(AIS_InteractiveObject) anAISObj;
3803 if (anAISMap.IsBound2 (aName))
3805 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3808 if (anAISObj.IsNull())
3810 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3814 aListOfIO.Append (anAISObj);
3817 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3818 for (; anIOIt.More(); anIOIt.Next())
3820 aContextAIS->Update (anIOIt.Value(), Standard_False);
3823 aContextAIS->UpdateCurrentViewer();
3828 //==============================================================================
3830 //purpose : Test the annimation of an object along a
3831 // predifined trajectory
3832 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3833 //==============================================================================
3835 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3838 if (TheAISContext()->HasOpenedContext())
3839 TheAISContext()->CloseLocalContext();
3841 Standard_Real Step=4*M_PI/180;
3842 Standard_Real Angle=0;
3844 Handle(AIS_InteractiveObject) aIO;
3845 if (GetMapOfAIS().IsBound2(argv[1]))
3846 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3850 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3854 if (Draw::Atoi(argv[3])==1 ) {
3855 di<<" Primitives sensibles OFF\n";
3856 TheAISContext()->Deactivate(aIO);
3859 di<<" Primitives sensibles ON\n";
3861 // Movement par transformation
3862 if(Draw::Atoi(argv[2]) ==1) {
3863 di<<" Calcul par Transformation\n";
3864 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3868 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3869 TheAISContext()->SetLocation(aShape,myTransfo);
3870 TheAISContext() ->UpdateCurrentViewer();
3875 di<<" Calcul par Locations\n";
3876 gp_Trsf myAngleTrsf;
3877 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3878 TopLoc_Location myDeltaAngle (myAngleTrsf);
3879 TopLoc_Location myTrueLoc;
3881 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3884 myTrueLoc=myTrueLoc*myDeltaAngle;
3885 TheAISContext()->SetLocation(aShape,myTrueLoc );
3886 TheAISContext() ->UpdateCurrentViewer();
3889 if (Draw::Atoi(argv[3])==1 ){
3890 // On reactive la selection des primitives sensibles
3891 TheAISContext()->Activate(aIO,0);
3893 a3DView() -> Redraw();
3895 di<<" Temps ecoule \n";
3901 //==================================================================================
3902 // Function : VAnimation
3903 //==================================================================================
3904 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3906 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile\n";
3910 Standard_Real thread = 4;
3911 Standard_Real angleA=0;
3912 Standard_Real angleB;
3914 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3917 TopoDS_Shape CrankArm;
3918 TopoDS_Shape CylinderHead;
3919 TopoDS_Shape Propeller;
3920 TopoDS_Shape EngineBlock;
3922 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3923 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3924 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3925 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3926 BRepTools::Read(CrankArm,argv[1],B);
3927 BRepTools::Read(CylinderHead,argv[2],B);
3928 BRepTools::Read(Propeller,argv[3],B);
3929 BRepTools::Read(EngineBlock,argv[4],B);
3931 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure.\n";}
3937 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3938 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3939 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3940 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3942 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3943 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3944 GetMapOfAIS().Bind(myAisCrankArm,"c");
3945 GetMapOfAIS().Bind(myAisPropeller,"d");
3947 myAisCylinderHead->SetMutable (Standard_True);
3948 myAisEngineBlock ->SetMutable (Standard_True);
3949 myAisCrankArm ->SetMutable (Standard_True);
3950 myAisPropeller ->SetMutable (Standard_True);
3952 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3953 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3954 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3956 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3957 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3958 TheAISContext()->Display (myAisCrankArm, Standard_False);
3959 TheAISContext()->Display (myAisPropeller, Standard_False);
3961 TheAISContext()->Deactivate(myAisCylinderHead);
3962 TheAISContext()->Deactivate(myAisEngineBlock );
3963 TheAISContext()->Deactivate(myAisCrankArm );
3964 TheAISContext()->Deactivate(myAisPropeller );
3966 // Boucle de mouvement
3967 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3969 angleA = thread*myAngle*M_PI/180;
3970 X = Sin(angleA)*3/8;
3971 angleB = atan(X / Sqrt(-X * X + 1));
3972 Standard_Real decal(25*0.6);
3975 //Build a transformation on the display
3976 gp_Trsf aPropellerTrsf;
3977 aPropellerTrsf.SetRotation(Ax1,angleA);
3978 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3980 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));
3981 gp_Trsf aCrankArmTrsf;
3982 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3983 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3985 TheAISContext()->UpdateCurrentViewer();
3988 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3989 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3991 myAisCrankArm ->ResetTransformation();
3992 myAisPropeller->ResetTransformation();
3994 myAisCrankArm -> Set(myNewCrankArm );
3995 myAisPropeller -> Set(myNewPropeller);
3997 TheAISContext()->Activate(myAisCylinderHead,0);
3998 TheAISContext()->Activate(myAisEngineBlock,0 );
3999 TheAISContext()->Activate(myAisCrankArm ,0 );
4000 TheAISContext()->Activate(myAisPropeller ,0 );
4006 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
4007 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
4009 TheAISContext()->UpdateCurrentViewer();
4010 a3DView()->Redraw();
4019 //==============================================================================
4020 //function : VShading
4021 //purpose : Sharpen or roughten the quality of the shading
4022 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4023 //==============================================================================
4024 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4026 Standard_Real myDevCoef;
4027 Handle(AIS_InteractiveObject) TheAisIO;
4030 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4032 if (TheAISContext()->HasOpenedContext())
4033 TheAISContext()->CloseLocalContext();
4038 myDevCoef =Draw::Atof(argv[2]);
4041 TCollection_AsciiString name=argv[1];
4042 if (GetMapOfAIS().IsBound2(name ))
4043 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4044 if (TheAisIO.IsNull())
4045 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4048 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4050 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4052 TheAISContext()->Redisplay(TheAisIO);
4055 //==============================================================================
4056 //function : HaveMode
4057 //use : VActivatedModes
4058 //==============================================================================
4059 #include <TColStd_ListIteratorOfListOfInteger.hxx>
4061 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
4063 TColStd_ListOfInteger List;
4064 TheAISContext()->ActivatedModes (TheAisIO,List);
4065 TColStd_ListIteratorOfListOfInteger it;
4066 Standard_Boolean Found=Standard_False;
4067 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4068 if (it.Value()==mode ) Found=Standard_True;
4075 //==============================================================================
4076 //function : VActivatedMode
4078 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
4079 // (edges,vertex...)qui lui est propre et le mode de selection standard.
4080 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4081 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4082 // qu'un nom et qu'un mode.
4083 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4084 //==============================================================================
4085 #include <AIS_ListIteratorOfListOfInteractive.hxx>
4087 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4090 Standard_Boolean ThereIsName = Standard_False ;
4092 if(!a3DView().IsNull()){
4094 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
4095 // verification des arguments
4097 if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
4098 ThereIsName = (argc == 3);
4102 if (argc>1) {di<<" Syntaxe error\n";return 1;}
4104 di<<" R.A.Z de tous les modes de selecion\n";
4105 di<<" Fermeture du Context local\n";
4106 if (TheAISContext()->HasOpenedContext())
4107 TheAISContext()->CloseLocalContext();
4111 // IL n'y a aps de nom de shape passe en argument
4112 if (HaveToSet && !ThereIsName){
4113 Standard_Integer aMode=Draw::Atoi(argv [1]);
4115 const char *cmode="???";
4117 case 0: cmode = "Shape"; break;
4118 case 1: cmode = "Vertex"; break;
4119 case 2: cmode = "Edge"; break;
4120 case 3: cmode = "Wire"; break;
4121 case 4: cmode = "Face"; break;
4122 case 5: cmode = "Shell"; break;
4123 case 6: cmode = "Solid"; break;
4124 case 7: cmode = "Compound"; break;
4127 if( !TheAISContext()->HasOpenedContext() ) {
4128 // il n'y a pas de Context local d'ouvert
4129 // on en ouvre un et on charge toutes les shapes displayees
4130 // on load tous les objets displayees et on Activate les objets de la liste
4131 AIS_ListOfInteractive ListOfIO;
4132 // on sauve dans une AISListOfInteractive tous les objets currents
4133 if (TheAISContext()->NbSelected()>0 ){
4134 TheAISContext()->UnhilightSelected(Standard_False);
4136 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4137 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
4141 TheAISContext()->OpenLocalContext(Standard_False);
4142 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4145 Handle(AIS_InteractiveObject) aIO =
4146 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4148 TheAISContext()->Load(aIO,0,Standard_False);
4151 // traitement des objets qui etaient currents dans le Contexte global
4152 if (!ListOfIO.IsEmpty() ) {
4153 // il y avait des objets currents
4154 AIS_ListIteratorOfListOfInteractive iter;
4155 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4156 Handle(AIS_InteractiveObject) aIO=iter.Value();
4157 TheAISContext()->Activate(aIO,aMode);
4158 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4162 // On applique le mode a tous les objets displayes
4163 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4164 it2 (GetMapOfAIS());
4166 Handle(AIS_InteractiveObject) aIO =
4167 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4168 if (!aIO.IsNull()) {
4169 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4170 TheAISContext()->Activate(aIO,aMode);
4179 // un Context local est deja ouvert
4180 // Traitement des objets du Context local
4181 if (TheAISContext()->NbSelected()>0 ){
4182 TheAISContext()->UnhilightSelected(Standard_False);
4183 // il y a des objets selected,on les parcourt
4184 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4185 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
4188 if (HaveMode(aIO,aMode) ) {
4189 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4190 TheAISContext()->Deactivate(aIO,aMode);
4193 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4194 TheAISContext()->Activate(aIO,aMode);
4200 // il n'y a pas d'objets selected
4201 // tous les objets diplayes sont traites
4202 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4205 Handle(AIS_InteractiveObject) aIO =
4206 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4207 if (!aIO.IsNull()) {
4208 if (HaveMode(aIO,aMode) ) {
4209 di<<" Mode: "<<cmode<<" OFF pour "
4210 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4211 TheAISContext()->Deactivate(aIO,aMode);
4214 di<<" Mode: "<<cmode<<" ON pour"
4215 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4216 TheAISContext()->Activate(aIO,aMode);
4224 else if (HaveToSet && ThereIsName){
4225 Standard_Integer aMode=Draw::Atoi(argv [2]);
4226 Handle(AIS_InteractiveObject) aIO =
4227 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4229 if (!aIO.IsNull()) {
4230 const char *cmode="???";
4233 case 0: cmode = "Shape"; break;
4234 case 1: cmode = "Vertex"; break;
4235 case 2: cmode = "Edge"; break;
4236 case 3: cmode = "Wire"; break;
4237 case 4: cmode = "Face"; break;
4238 case 5: cmode = "Shell"; break;
4239 case 6: cmode = "Solid"; break;
4240 case 7: cmode = "Compound"; break;
4243 if( !TheAISContext()->HasOpenedContext() ) {
4244 TheAISContext()->OpenLocalContext(Standard_False);
4245 // On charge tous les objets de la map
4246 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4248 Handle(AIS_InteractiveObject) aShape=
4249 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4250 if (!aShape.IsNull())
4251 TheAISContext()->Load(aShape,0,Standard_False);
4254 TheAISContext()->Activate(aIO,aMode);
4255 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4259 // un Context local est deja ouvert
4260 if (HaveMode(aIO,aMode) ) {
4261 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4262 TheAISContext()->Deactivate(aIO,aMode);
4265 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4266 TheAISContext()->Activate(aIO,aMode);
4275 //! Auxiliary method to print Interactive Object information
4276 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4277 const Handle(Standard_Transient)& theObject,
4278 Draw_Interpretor& theDI)
4280 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4283 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4287 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4288 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4289 << (theDetected.Contains (anObj) ? " Detected" : " ")
4291 if (anObj->Type() == AIS_KOI_Datum)
4294 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4295 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4296 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4297 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4298 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4299 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4300 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4303 else if (anObj->Type() == AIS_KOI_Shape
4304 && anObj->Signature() == 0)
4306 theDI << " AIS_Shape";
4308 else if (anObj->Type() == AIS_KOI_Relation)
4310 // AIS_Dimention and AIS_Relation
4311 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4312 switch (aRelation->KindOfDimension())
4314 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4315 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4316 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4317 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4318 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4319 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4320 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4321 default: theDI << " UNKNOWN dimension"; break;
4326 theDI << " UserPrs";
4328 theDI << " (" << theObject->DynamicType()->Name() << ")";
4331 //! Print information about locally selected sub-shapes
4332 template <typename T>
4333 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4335 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4336 TCollection_AsciiString aPrevName;
4337 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4339 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4340 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4341 if (aShapeIO.IsNull() || anOwner.IsNull())
4345 if (anOwner == aShapeIO->GlobalSelOwner())
4348 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4349 if (aSubShape.IsNull()
4350 || aShapeIO.IsNull()
4351 || !GetMapOfAIS().IsBound1 (aShapeIO))
4356 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4357 TopTools_MapOfShape aFilter;
4358 Standard_Integer aNumber = 0;
4359 const TopoDS_Shape aShape = aShapeIO->Shape();
4360 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4361 anIter.More(); anIter.Next())
4363 if (!aFilter.Add (anIter.Current()))
4365 continue; // filter duplicates
4369 if (!anIter.Current().IsSame (aSubShape))
4374 Standard_CString aShapeName = NULL;
4375 switch (aSubShape.ShapeType())
4377 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4378 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4379 case TopAbs_SOLID: aShapeName = " Solid"; break;
4380 case TopAbs_SHELL: aShapeName = " Shell"; break;
4381 case TopAbs_FACE: aShapeName = " Face"; break;
4382 case TopAbs_WIRE: aShapeName = " Wire"; break;
4383 case TopAbs_EDGE: aShapeName = " Edge"; break;
4384 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4386 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4389 if (aParentName != aPrevName)
4391 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4392 aPrevName = aParentName;
4394 theDI << " " << aShapeName << " #" << aNumber << "\n";
4400 //==============================================================================
4403 //==============================================================================
4404 static Standard_Integer VState (Draw_Interpretor& theDI,
4405 Standard_Integer theArgNb,
4406 Standard_CString* theArgVec)
4408 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4411 std::cerr << "Error: No opened viewer!\n";
4415 Standard_Boolean toPrintEntities = Standard_False;
4416 Standard_Boolean toCheckSelected = Standard_False;
4418 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4420 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4421 anOption.LowerCase();
4422 if (anOption == "-detectedentities"
4423 || anOption == "-entities")
4425 toPrintEntities = Standard_True;
4427 else if (anOption == "-hasselected")
4429 toCheckSelected = Standard_True;
4433 if (toCheckSelected)
4435 aCtx->InitSelected();
4436 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4437 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4442 if (toPrintEntities)
4444 theDI << "Detected entities:\n";
4445 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4446 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4447 for (aSelector->InitDetected(); aSelector->MoreDetected(); aSelector->NextDetected())
4449 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->DetectedEntity();
4450 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4451 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4453 if (anObj->TransformPersistence().Flags)
4455 const Graphic3d_Mat4d& aProjection = aMgr.ProjectionMatrix();
4456 const Graphic3d_Mat4d& aWorldView = aMgr.WorldViewMatrix();
4458 Graphic3d_Mat4d aMat = anObj->TransformPersistence().Compute (aProjection, aWorldView, 0, 0);
4459 anInvTrsf.SetValues (aMat.GetValue (0, 0), aMat.GetValue (0, 1), aMat.GetValue (0, 2), aMat.GetValue (0, 3),
4460 aMat.GetValue (1, 0), aMat.GetValue (1, 1), aMat.GetValue (1, 2), aMat.GetValue (1, 3),
4461 aMat.GetValue (2, 0), aMat.GetValue (2, 1), aMat.GetValue (2, 2), aMat.GetValue (2, 3));
4464 if (anObj->HasTransformation())
4466 anInvTrsf = anObj->InversedTransformation() * anInvTrsf;
4468 if (anEntity->HasInitLocation())
4470 anInvTrsf = anEntity->InvInitLocation() * anInvTrsf;
4472 const Standard_Integer aScale = anEntity->SensitivityFactor() < aSelector->PixelTolerance()
4473 ? anEntity->SensitivityFactor() : 1;
4474 const Standard_Boolean isToScaleAndTransform = anInvTrsf.Form() != gp_Identity || aScale != 1;
4475 SelectMgr_SelectingVolumeManager anEntMgr =
4476 isToScaleAndTransform ? aMgr.ScaleAndTransform (aScale, anInvTrsf)
4478 SelectBasics_PickResult aResult;
4479 anEntity->Matches (anEntMgr, aResult);
4480 gp_Pnt aDetectedPnt = anInvTrsf.Form() == gp_Identity ?
4481 anEntMgr.DetectedPoint (aResult.Depth()) : anEntMgr.DetectedPoint (aResult.Depth()).Transformed (anInvTrsf.Inverted());
4483 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4484 aName.LeftJustify (20, ' ');
4485 char anInfoStr[512];
4487 " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
4489 aResult.DistToGeomCenter(),
4490 aDetectedPnt.X(), aDetectedPnt.Y(), aDetectedPnt.Z());
4491 theDI << " " << aName
4493 << " (" << anEntity->DynamicType()->Name() << ")"
4496 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4497 if (!aBRepOwner.IsNull())
4499 theDI << " Detected Shape: "
4500 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4504 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4505 if (!aWire.IsNull())
4507 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4508 theDI << " Detected Child: "
4509 << aSen->DynamicType()->Name()
4513 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4514 if (!aPrimArr.IsNull())
4516 theDI << " Detected Element: "
4517 << aPrimArr->LastDetectedElement()
4524 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4525 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4527 aDetected.Add (aCtx->DetectedCurrentObject());
4530 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4534 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4536 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4537 if (!GetMapOfAIS().IsBound2 (anObjName))
4539 theDI << anObjName << " doesn't exist!\n";
4543 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4544 TCollection_AsciiString aName = anObjName;
4545 aName.LeftJustify (20, ' ');
4546 theDI << " " << aName << " ";
4547 objInfo (aDetected, anObjTrans, theDI);
4553 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4555 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4556 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4558 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4559 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4560 // handle whole object selection
4561 if (anOwner == anObj->GlobalSelOwner())
4563 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4564 aName.LeftJustify (20, ' ');
4565 theDI << aName << " ";
4566 objInfo (aDetected, anObj, theDI);
4571 // process selected sub-shapes
4572 printLocalSelectionInfo (aCtx, theDI);
4577 theDI << "Neutral-point state:\n";
4578 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4579 anObjIter.More(); anObjIter.Next())
4581 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4587 TCollection_AsciiString aName = anObjIter.Key2();
4588 aName.LeftJustify (20, ' ');
4589 theDI << " " << aName << " ";
4590 objInfo (aDetected, anObj, theDI);
4593 printLocalSelectionInfo (aCtx, theDI);
4594 if (aCtx->HasOpenedContext())
4595 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
4599 //=======================================================================
4600 //function : PickObjects
4602 //=======================================================================
4603 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4604 const AIS_KindOfInteractive TheType,
4605 const Standard_Integer TheSignature,
4606 const Standard_Integer MaxPick)
4608 Handle(AIS_InteractiveObject) IO;
4609 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4611 // step 1: prepare the data
4613 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4614 TheAISContext()->AddFilter(F1);
4617 // step 2 : wait for the selection...
4618 Standard_Integer NbPickGood (0),NbToReach(arr->Length());
4619 Standard_Integer NbPickFail(0);
4620 Standard_Integer argccc = 5;
4621 const char *bufff[] = { "A", "B", "C","D", "E" };
4622 const char **argvvv = (const char **) bufff;
4625 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4626 while(ViewerMainLoop(argccc,argvvv)){}
4627 Standard_Integer NbStored = TheAISContext()->NbSelected();
4628 if(NbStored != NbPickGood)
4629 NbPickGood= NbStored;
4632 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4635 // step3 get result.
4637 if (NbPickFail >= NbToReach)
4638 return Standard_False;
4640 Standard_Integer i(0);
4641 for(TheAISContext()->InitSelected();
4642 TheAISContext()->MoreSelected();
4643 TheAISContext()->NextSelected()){
4645 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4646 arr->SetValue(i,IO2);
4651 TheAISContext()->CloseLocalContext(curindex);
4653 return Standard_True;
4657 //=======================================================================
4658 //function : PickObject
4660 //=======================================================================
4661 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4662 const Standard_Integer TheSignature,
4663 const Standard_Integer MaxPick)
4665 Handle(AIS_InteractiveObject) IO;
4666 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4668 // step 1: prepare the data
4671 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4672 TheAISContext()->AddFilter(F1);
4675 // step 2 : wait for the selection...
4676 Standard_Boolean IsGood (Standard_False);
4677 Standard_Integer NbPick(0);
4678 Standard_Integer argccc = 5;
4679 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4680 const char **argvvv = (const char **) bufff;
4683 while(!IsGood && NbPick<= MaxPick){
4684 while(ViewerMainLoop(argccc,argvvv)){}
4685 IsGood = (TheAISContext()->NbSelected()>0) ;
4687 cout<<"Nb Pick :"<<NbPick<<endl;
4691 // step3 get result.
4693 TheAISContext()->InitSelected();
4694 IO = TheAISContext()->SelectedInteractive();
4698 TheAISContext()->CloseLocalContext(curindex);
4702 //=======================================================================
4703 //function : PickShape
4704 //purpose : First Activate the rightmode + Put Filters to be able to
4705 // pick objets that are of type <TheType>...
4706 //=======================================================================
4708 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4709 const Standard_Integer MaxPick)
4712 // step 1: prepare the data
4714 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4715 TopoDS_Shape result;
4717 if(TheType==TopAbs_SHAPE){
4718 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4719 TheAISContext()->AddFilter(F1);
4722 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4723 TheAISContext()->AddFilter(TF);
4724 TheAISContext()->ActivateStandardMode(TheType);
4729 // step 2 : wait for the selection...
4730 Standard_Boolean NoShape (Standard_True);
4731 Standard_Integer NbPick(0);
4732 Standard_Integer argccc = 5;
4733 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4734 const char **argvvv = (const char **) bufff;
4737 while(NoShape && NbPick<= MaxPick){
4738 while(ViewerMainLoop(argccc,argvvv)){}
4739 NoShape = (TheAISContext()->NbSelected()==0) ;
4741 cout<<"Nb Pick :"<<NbPick<<endl;
4744 // step3 get result.
4748 TheAISContext()->InitSelected();
4749 if(TheAISContext()->HasSelectedShape())
4750 result = TheAISContext()->SelectedShape();
4752 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4753 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
4758 TheAISContext()->CloseLocalContext(curindex);
4764 //=======================================================================
4765 //function : PickShapes
4767 //=======================================================================
4768 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4769 Handle(TopTools_HArray1OfShape)& thearr,
4770 const Standard_Integer MaxPick)
4773 Standard_Integer Taille = thearr->Length();
4775 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4777 // step 1: prepare the data
4778 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4779 if(TheType==TopAbs_SHAPE){
4780 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4781 TheAISContext()->AddFilter(F1);
4784 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4785 TheAISContext()->AddFilter(TF);
4786 TheAISContext()->ActivateStandardMode(TheType);
4790 // step 2 : wait for the selection...
4791 Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
4792 Standard_Integer NbPickFail(0);
4793 Standard_Integer argccc = 5;
4794 const char *bufff[] = { "A", "B", "C","D", "E" };
4795 const char **argvvv = (const char **) bufff;
4798 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4799 while(ViewerMainLoop(argccc,argvvv)){}
4800 Standard_Integer NbStored = TheAISContext()->NbSelected();
4801 if (NbStored != NbPickGood)
4802 NbPickGood= NbStored;
4805 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4808 // step3 get result.
4810 if (NbPickFail >= NbToReach)
4811 return Standard_False;
4813 Standard_Integer i(0);
4814 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4816 if(TheAISContext()->HasSelectedShape())
4817 thearr->SetValue(i,TheAISContext()->SelectedShape());
4819 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4820 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
4824 TheAISContext()->CloseLocalContext(curindex);
4825 return Standard_True;
4829 //=======================================================================
4830 //function : VPickShape
4832 //=======================================================================
4833 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4835 TopoDS_Shape PickSh;
4836 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4839 theType = TopAbs_SHAPE;
4841 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4842 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4843 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4844 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4845 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4846 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4847 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4850 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4851 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4853 TCollection_AsciiString name;
4856 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4858 PickSh = ViewerTest::PickShape(theType);
4867 if(!PickSh.IsNull()){
4868 nbOfSub[Standard_Integer(theType)]++;
4870 name += nameType[Standard_Integer(theType)];
4871 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4876 // si on avait une petite methode pour voir si la shape
4877 // est deja dans la Double map, ca eviterait de creer....
4878 DBRep::Set(name.ToCString(),PickSh);
4880 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4881 GetMapOfAIS().Bind(newsh, name);
4882 TheAISContext()->Display(newsh);
4883 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4886 // Plusieurs objets a picker, vite vite vite....
4889 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4890 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4891 if(ViewerTest::PickShapes(theType,arr)){
4892 for(Standard_Integer i=1;i<=NbToPick;i++){
4893 PickSh = arr->Value(i);
4894 if(!PickSh.IsNull()){
4896 nbOfSub[Standard_Integer(theType)]++;
4899 name += nameType[Standard_Integer(theType)];
4900 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4908 DBRep::Set(name.ToCString(),PickSh);
4909 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4910 GetMapOfAIS().Bind(newsh, name);
4911 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4912 TheAISContext()->Display(newsh);
4920 //=======================================================================
4921 //function : VPickSelected
4923 //=======================================================================
4924 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4926 static Standard_Integer aCount = 0;
4927 TCollection_AsciiString aName = "PickedShape_";
4935 aName = aName + aCount++ + "_";
4938 Standard_Integer anIdx = 0;
4939 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4941 TopoDS_Shape aShape;
4942 if (TheAISContext()->HasSelectedShape())
4944 aShape = TheAISContext()->SelectedShape();
4948 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4949 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
4952 TCollection_AsciiString aCurrentName = aName;
4955 aCurrentName += anIdx;
4958 DBRep::Set ((aCurrentName).ToCString(), aShape);
4960 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4961 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4962 TheAISContext()->Display (aNewShape);
4968 //=======================================================================
4969 //function : list of known objects
4971 //=======================================================================
4972 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4974 // 1234567890 12345678901234567 123456789
4975 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4976 TCollection_AsciiString BlankLine(64,'_');
4977 Standard_Integer i ;
4979 di<<"/n"<<BlankLine.ToCString()<<"\n";
4982 Colum[i].Center(20,' ');
4984 di<<"|"<<Colum[i].ToCString();
4987 di<<BlankLine.ToCString()<<"\n";
4989 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4990 const char ** names = GetTypeNames();
4992 TCollection_AsciiString curstring;
4993 TCollection_AsciiString curcolum[3];
4996 // les objets de type Datum..
4997 curcolum[1]+="Datum";
4999 curcolum[0].Clear();
5000 curcolum[0] += names[i];
5002 curcolum[2].Clear();
5003 curcolum[2]+=TCollection_AsciiString(i+1);
5005 for(Standard_Integer j =0;j<=2;j++){
5006 curcolum[j].Center(20,' ');
5007 di<<"|"<<curcolum[j].ToCString();
5011 di<<BlankLine.ToCString()<<"\n";
5013 // les objets de type shape
5014 curcolum[1].Clear();
5015 curcolum[1]+="Shape";
5016 curcolum[1].Center(20,' ');
5019 curcolum[0].Clear();
5020 curcolum[0] += names[7+i];
5021 curcolum[2].Clear();
5022 curcolum[2]+=TCollection_AsciiString(i);
5024 for(Standard_Integer j =0;j<=2;j++){
5025 curcolum[j].Center(20,' ');
5026 di<<"|"<<curcolum[j].ToCString();
5030 di<<BlankLine.ToCString()<<"\n";
5031 // les IO de type objet...
5032 curcolum[1].Clear();
5033 curcolum[1]+="Object";
5034 curcolum[1].Center(20,' ');
5036 curcolum[0].Clear();
5037 curcolum[0] += names[10+i];
5038 curcolum[2].Clear();
5039 curcolum[2]+=TCollection_AsciiString(i);
5041 for(Standard_Integer j =0;j<=2;j++){
5042 curcolum[j].Center(20,' ');
5043 di<<"|"<<curcolum[j].ToCString();
5047 di<<BlankLine.ToCString()<<"\n";
5048 // les contraintes et dimensions.
5049 // pour l'instant on separe juste contraintes et dimensions...
5050 // plus tard, on detaillera toutes les sortes...
5051 curcolum[1].Clear();
5052 curcolum[1]+="Relation";
5053 curcolum[1].Center(20,' ');
5055 curcolum[0].Clear();
5056 curcolum[0] += names[12+i];
5057 curcolum[2].Clear();
5058 curcolum[2]+=TCollection_AsciiString(i);
5060 for(Standard_Integer j =0;j<=2;j++){
5061 curcolum[j].Center(20,' ');
5062 di<<"|"<<curcolum[j].ToCString();
5066 di<<BlankLine.ToCString()<<"\n";
5073 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5075 if(argc!=2) return 1;
5077 AIS_KindOfInteractive TheType;
5078 Standard_Integer TheSign(-1);
5079 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5082 AIS_ListOfInteractive LIO;
5084 // en attendant l'amelioration ais pour les dimensions...
5086 Standard_Integer dimension_status(-1);
5087 if(TheType==AIS_KOI_Relation){
5088 dimension_status = TheSign ==1 ? 1 : 0;
5092 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5093 Handle(AIS_InteractiveObject) curio;
5094 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5097 if(dimension_status == -1)
5098 TheAISContext()->Erase(curio,Standard_False);
5100 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5101 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5102 (dimension_status==1 && KOD != AIS_KOD_NONE))
5103 TheAISContext()->Erase(curio,Standard_False);
5106 TheAISContext()->UpdateCurrentViewer();
5109 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5111 if(argc!=2) return 1;
5113 AIS_KindOfInteractive TheType;
5114 Standard_Integer TheSign(-1);
5115 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5117 // en attendant l'amelioration ais pour les dimensions...
5119 Standard_Integer dimension_status(-1);
5120 if(TheType==AIS_KOI_Relation){
5121 dimension_status = TheSign ==1 ? 1 : 0;
5125 AIS_ListOfInteractive LIO;
5126 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5127 Handle(AIS_InteractiveObject) curio;
5128 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5130 if(dimension_status == -1)
5131 TheAISContext()->Display(curio,Standard_False);
5133 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5134 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5135 (dimension_status==1 && KOD != AIS_KOD_NONE))
5136 TheAISContext()->Display(curio,Standard_False);
5141 TheAISContext()->UpdateCurrentViewer();
5145 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5148 BRep_Builder builder;
5150 BRepTools::Read(shape, s, builder);
5151 DBRep::Set(a[1], shape);
5152 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5153 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5158 //===============================================================================================
5161 //===============================================================================================
5162 static int VBsdf (Draw_Interpretor& theDi,
5163 Standard_Integer theArgsNb,
5164 const char** theArgVec)
5166 Handle(V3d_View) aView = ViewerTest::CurrentView();
5167 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5169 || aViewer.IsNull())
5171 std::cerr << "No active viewer!\n";
5175 ViewerTest_CmdParser aCmd;
5177 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5178 aCmd.AddOption ("print|echo|p", "Print BSDF");
5180 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5181 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5182 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5183 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5184 aCmd.AddOption ("le", "Self-emitted radiance");
5186 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5188 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
5189 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5190 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5192 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5194 aCmd.Parse (theArgsNb, theArgVec);
5196 if (aCmd.HasOption ("help"))
5198 theDi.PrintHelp (theArgVec[0]);
5202 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5205 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5206 if (!aMap.IsBound2 (aName) )
5208 std::cerr << "Use 'vdisplay' before\n";
5212 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5213 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5214 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5216 if (aCmd.HasOption ("print"))
5218 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5221 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5222 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5223 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5224 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5225 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5228 if (aFresnel.x() >= 0.f)
5231 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5233 else if (aFresnel.x() >= -1.5f)
5236 << "|Constant| " << aFresnel.z() << "\n";
5238 else if (aFresnel.x() >= -2.5f)
5241 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5246 << "|Dielectric| " << aFresnel.y() << "\n";
5251 << "Roughness: " << aBSDF.Roughness << "\n"
5252 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
5253 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5254 << aBSDF.AbsorptionColor.g() << ", "
5255 << aBSDF.AbsorptionColor.b() << "\n";
5260 if (aCmd.HasOption ("roughness", 1, Standard_True))
5262 aCmd.Arg ("roughness", 0);
5263 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5266 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5268 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5271 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5273 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5276 if (aCmd.HasOption ("kd", 3))
5278 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5280 else if (aCmd.HasOption ("kd", 1, Standard_True))
5282 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5285 if (aCmd.HasOption ("kr", 3))
5287 aBSDF.Kr = aCmd.ArgVec3f ("kr");
5289 else if (aCmd.HasOption ("kr", 1, Standard_True))
5291 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5294 if (aCmd.HasOption ("kt", 3))
5296 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5298 else if (aCmd.HasOption ("kt", 1, Standard_True))
5300 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5303 if (aCmd.HasOption ("ks", 3))
5305 aBSDF.Ks = aCmd.ArgVec3f ("ks");
5307 else if (aCmd.HasOption ("ks", 1, Standard_True))
5309 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5312 if (aCmd.HasOption ("le", 3))
5314 aBSDF.Le = aCmd.ArgVec3f ("le");
5316 else if (aCmd.HasOption ("le", 1, Standard_True))
5318 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5321 const std::string aFresnelErrorMessage =
5322 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5324 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5326 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5327 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5329 if (aFresnelType == "schlick")
5331 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5332 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5333 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5334 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5338 std::cout << aFresnelErrorMessage;
5341 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5343 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5344 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5346 if (aFresnelType == "conductor")
5348 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5349 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5350 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5354 std::cout << aFresnelErrorMessage;
5357 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5359 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5360 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5362 if (aFresnelType == "dielectric")
5364 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5365 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5367 else if (aFresnelType == "constant")
5369 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5370 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5374 std::cout << aFresnelErrorMessage;
5378 if (aCmd.HasOption ("normalize"))
5383 aMaterial.SetBSDF (aBSDF);
5384 anIObj->SetMaterial (aMaterial);
5391 //==============================================================================
5392 //function : VLoadSelection
5393 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5394 //==============================================================================
5395 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5396 Standard_Integer theArgNb,
5397 const char** theArgVec)
5401 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5405 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5408 ViewerTest::ViewerInit();
5409 aCtx = ViewerTest::GetAISContext();
5412 // Parse input arguments
5413 TColStd_SequenceOfAsciiString aNamesOfIO;
5414 Standard_Boolean isLocal = Standard_False;
5415 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5417 const TCollection_AsciiString aName = theArgVec[anArgIter];
5418 TCollection_AsciiString aNameCase = aName;
5419 aNameCase.LowerCase();
5420 if (aNameCase == "-local")
5422 isLocal = Standard_True;
5426 aNamesOfIO.Append (aName);
5430 if (aNamesOfIO.IsEmpty())
5432 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5437 if (isLocal && !aCtx->HasOpenedContext())
5439 aCtx->OpenLocalContext (Standard_False);
5441 else if (!isLocal && aCtx->HasOpenedContext())
5443 aCtx->CloseAllContexts (Standard_False);
5446 // Load selection of interactive objects
5447 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5449 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5451 Handle(AIS_InteractiveObject) aShape;
5452 if (GetMapOfAIS().IsBound2 (aName))
5453 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5455 aShape = GetAISShapeFromName (aName.ToCString());
5457 if (!aShape.IsNull())
5459 if (!GetMapOfAIS().IsBound2 (aName))
5461 GetMapOfAIS().Bind (aShape, aName);
5464 aCtx->Load (aShape, -1, Standard_False);
5465 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5472 //==============================================================================
5473 //function : VAutoActivateSelection
5474 //purpose : Activates or deactivates auto computation of selection
5475 //==============================================================================
5476 static int VAutoActivateSelection (Draw_Interpretor& theDi,
5477 Standard_Integer theArgNb,
5478 const char** theArgVec)
5483 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5487 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5490 ViewerTest::ViewerInit();
5491 aCtx = ViewerTest::GetAISContext();
5496 TCollection_AsciiString aSelActivationString;
5497 if (aCtx->GetAutoActivateSelection())
5499 aSelActivationString.Copy ("ON");
5503 aSelActivationString.Copy ("OFF");
5506 theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
5510 Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]);
5511 aCtx->SetAutoActivateSelection (toActivate);
5517 //==============================================================================
5518 //function : ViewerTest::Commands
5519 //purpose : Add all the viewer command in the Draw_Interpretor
5520 //==============================================================================
5522 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5524 ViewerTest::ViewerCommands(theCommands);
5525 ViewerTest::RelationCommands(theCommands);
5526 ViewerTest::ObjectCommands(theCommands);
5527 ViewerTest::FilletCommands(theCommands);
5528 ViewerTest::OpenGlCommands(theCommands);
5530 const char *group = "AIS_Display";
5533 theCommands.Add("visos",
5534 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5535 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5536 __FILE__, visos, group);
5538 theCommands.Add("vdisplay",
5539 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5540 "\n\t\t: [-trsfPers {pan|zoom|rotate|trihedron|full|none}=none] [-trsfPersPos X Y [Z]] [-3d|-2d|-2dTopDown]"
5541 "\n\t\t: [-dispMode mode] [-highMode mode]"
5542 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5543 "\n\t\t: [-redisplay]"
5544 "\n\t\t: name1 [name2] ... [name n]"
5545 "\n\t\t: Displays named objects."
5546 "\n\t\t: Option -local enables displaying of objects in local"
5547 "\n\t\t: selection context. Local selection context will be opened"
5548 "\n\t\t: if there is not any."
5549 "\n\t\t: -noupdate suppresses viewer redraw call."
5550 "\n\t\t: -mutable enables optimizations for mutable objects."
5551 "\n\t\t: -neutral draws objects in main viewer."
5552 "\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."
5553 "\n\t\t: -top draws objects on top of main presentations but below topmost."
5554 "\n\t\t: -topmost draws in overlay for 3D presentations with independent Depth."
5555 "\n\t\t: -overlay draws objects in overlay for 2D presentations (On-Screen-Display)."
5556 "\n\t\t: -underlay draws objects in underlay for 2D presentations (On-Screen-Display)."
5557 "\n\t\t: -selectable|-noselect controls selection of objects."
5558 "\n\t\t: -trsfPers sets a transform persistence flags. Flag 'full' is pan, zoom and rotate."
5559 "\n\t\t: -trsfPersPos sets an anchor point for transform persistence."
5560 "\n\t\t: -2d|-2dTopDown displays object in screen coordinates."
5561 "\n\t\t: -dispmode sets display mode for objects."
5562 "\n\t\t: -highmode sets hilight mode for objects."
5563 "\n\t\t: -redisplay recomputes presentation of objects.",
5564 __FILE__, VDisplay2, group);
5566 theCommands.Add ("vupdate",
5567 "vupdate name1 [name2] ... [name n]"
5568 "\n\t\t: Updates named objects in interactive context",
5569 __FILE__, VUpdate, group);
5571 theCommands.Add("verase",
5572 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5573 "\n\t\t: Erases selected or named objects."
5574 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5575 "\n\t\t: Option -local enables erasing of selected or named objects without"
5576 "\n\t\t: closing local selection context.",
5577 __FILE__, VErase, group);
5579 theCommands.Add("vremove",
5580 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5581 "or vremove [-context] -all to remove all objects"
5582 "\n\t\t: Removes selected or named objects."
5583 "\n\t\t If -context is in arguments, the objects are not deleted"
5584 "\n\t\t from the map of objects and names."
5585 "\n\t\t: Option -local enables removing of selected or named objects without"
5586 "\n\t\t: closing local selection context. Empty local selection context will be"
5588 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5589 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5590 __FILE__, VRemove, group);
5592 theCommands.Add("vdonly",
5593 "vdonly [-noupdate|-update] [name1] ... [name n]"
5594 "\n\t\t: Displays only selected or named objects",
5595 __FILE__,VDonly2,group);
5597 theCommands.Add("vdisplayall",
5598 "vidsplayall [-local]"
5599 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5600 "\n\t\t: Option -local enables displaying of the objects in local"
5601 "\n\t\t: selection context.",
5602 __FILE__, VDisplayAll, group);
5604 theCommands.Add("veraseall",
5605 "veraseall [-local]"
5606 "\n\t\t: Erases all objects displayed in the viewer."
5607 "\n\t\t: Option -local enables erasing of the objects in local"
5608 "\n\t\t: selection context.",
5609 __FILE__, VErase, group);
5611 theCommands.Add("verasetype",
5613 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5614 __FILE__, VEraseType, group);
5615 theCommands.Add("vbounding",
5616 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5617 "\n\t\t: [-print] [-hide]"
5618 "\n\t\t: Temporarily display bounding box of specified Interactive"
5619 "\n\t\t: Objects, or print it to console if -print is specified."
5620 "\n\t\t: Already displayed box might be hidden by -hide option.",
5621 __FILE__,VBounding,group);
5623 theCommands.Add("vdisplaytype",
5624 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5625 __FILE__,VDisplayType,group);
5627 theCommands.Add("vdisplaymode",
5628 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
5629 __FILE__,VDispMode,group);
5631 theCommands.Add("verasemode",
5632 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
5633 __FILE__,VDispMode,group);
5635 theCommands.Add("vsetdispmode",
5636 "vsetdispmode [name] mode(1,2,..)"
5637 "\n\t\t: Sets display mode for all, selected or named objects.",
5638 __FILE__,VDispMode,group);
5640 theCommands.Add("vunsetdispmode",
5641 "vunsetdispmode [name]"
5642 "\n\t\t: Unsets custom display mode for selected or named objects.",
5643 __FILE__,VDispMode,group);
5645 theCommands.Add("vdir",
5646 "Lists all objects displayed in 3D viewer",
5647 __FILE__,VDir,group);
5649 #ifdef HAVE_FREEIMAGE
5650 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5652 #define DUMP_FORMATS "{ppm}"
5654 theCommands.Add("vdump",
5655 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5656 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5657 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5658 "\n\t\t: Dumps content of the active view into image file",
5659 __FILE__,VDump,group);
5661 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5662 __FILE__,VSubInt,group);
5664 theCommands.Add("vaspects",
5665 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5666 "\n\t\t: [-setVisibility 0|1]"
5667 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5668 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5669 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5670 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5671 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5672 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5673 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5674 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5675 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5676 "\n\t\t: [-isoontriangulation 0|1]"
5677 "\n\t\t: [-setMaxParamValue {value}]"
5678 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
5679 "\n\t\t: Manage presentation properties of all, selected or named objects."
5680 "\n\t\t: When -subshapes is specified than following properties will be"
5681 "\n\t\t: assigned to specified sub-shapes."
5682 "\n\t\t: When -defaults is specified than presentation properties will be"
5683 "\n\t\t: assigned to all objects that have not their own specified properties"
5684 "\n\t\t: and to all objects to be displayed in the future."
5685 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5686 __FILE__,VAspects,group);
5688 theCommands.Add("vsetcolor",
5689 "vsetcolor [-noupdate|-update] [name] ColorName"
5690 "\n\t\t: Sets color for all, selected or named objects."
5691 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5692 __FILE__,VAspects,group);
5694 theCommands.Add("vunsetcolor",
5695 "vunsetcolor [-noupdate|-update] [name]"
5696 "\n\t\t: Resets color for all, selected or named objects."
5697 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5698 __FILE__,VAspects,group);
5700 theCommands.Add("vsettransparency",
5701 "vsettransparency [-noupdate|-update] [name] Coefficient"
5702 "\n\t\t: Sets transparency for all, selected or named objects."
5703 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5704 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5705 __FILE__,VAspects,group);
5707 theCommands.Add("vunsettransparency",
5708 "vunsettransparency [-noupdate|-update] [name]"
5709 "\n\t\t: Resets transparency for all, selected or named objects."
5710 "\n\t\t: Alias for vaspects -unsettransp [name].",
5711 __FILE__,VAspects,group);
5713 theCommands.Add("vsetmaterial",
5714 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5715 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5716 __FILE__,VAspects,group);
5718 theCommands.Add("vunsetmaterial",
5719 "vunsetmaterial [-noupdate|-update] [name]"
5720 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5721 __FILE__,VAspects,group);
5723 theCommands.Add("vsetwidth",
5724 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5725 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5726 __FILE__,VAspects,group);
5728 theCommands.Add("vunsetwidth",
5729 "vunsetwidth [-noupdate|-update] [name]"
5730 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5731 __FILE__,VAspects,group);
5733 theCommands.Add("vsetinteriorstyle",
5734 "vsetinteriorstyle [-noupdate|-update] [name] style"
5735 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5736 __FILE__,VSetInteriorStyle,group);
5738 theCommands.Add("vsensdis",
5739 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5740 "\n\t\t: Standard entity types are those defined in Select3D package:"
5741 "\n\t\t: - sensitive box"
5742 "\n\t\t: - sensitive face"
5743 "\n\t\t: - sensitive curve"
5744 "\n\t\t: - sensitive segment"
5745 "\n\t\t: - sensitive circle"
5746 "\n\t\t: - sensitive point"
5747 "\n\t\t: - sensitive triangulation"
5748 "\n\t\t: - sensitive triangle"
5749 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5750 __FILE__,VDispSensi,group);
5752 theCommands.Add("vsensera",
5753 "vsensera : erase active entities",
5754 __FILE__,VClearSensi,group);
5756 theCommands.Add("vselprecision",
5757 "vselprecision [-unset] [tolerance_value]"
5758 "\n\t\t Manages selection precision or prints current value if no parameter is passed."
5759 "\n\t\t -unset - restores default selection tolerance behavior, based on individual entity tolerance",
5760 __FILE__,VSelPrecision,group);
5762 theCommands.Add("vperf",
5763 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
5764 "\n\t\t: Tests the animation of an object along a predefined trajectory.",
5765 __FILE__,VPerf,group);
5767 theCommands.Add("vanimation",
5768 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5769 __FILE__,VAnimation,group);
5771 theCommands.Add("vsetshading",
5772 "vsetshading : vsetshading name Quality(default=0.0008) "
5773 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5774 __FILE__,VShading,group);
5776 theCommands.Add("vunsetshading",
5777 "vunsetshading :vunsetshading name "
5778 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5779 __FILE__,VShading,group);
5781 theCommands.Add ("vtexture",
5782 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5783 " [-scale u v] [-scale off]\n"
5784 " [-origin u v] [-origin off]\n"
5785 " [-repeat u v] [-repeat off]\n"
5786 " [-modulate {on | off}]"
5788 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5789 " specifying one of the predefined textures.\n"
5790 " The options are: \n"
5791 " -scale u v : enable texture scaling and set scale factors\n"
5792 " -scale off : disable texture scaling\n"
5793 " -origin u v : enable texture origin positioning and set the origin\n"
5794 " -origin off : disable texture origin positioning\n"
5795 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5796 " -repeat off : disable texture repeat\n"
5797 " -modulate {on | off} : enable or disable texture modulation\n"
5798 " -default : sets texture mapping default parameters\n"
5799 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5800 "or 'vtexture NameOfShape ?' to list available textures\n",
5801 __FILE__, VTexture, group);
5803 theCommands.Add("vtexscale",
5804 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5805 or 'vtexscale NameOfShape ScaleUV' \n \
5806 or 'vtexscale NameOfShape' to disable scaling\n ",
5807 __FILE__,VTexture,group);
5809 theCommands.Add("vtexorigin",
5810 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5811 or 'vtexorigin NameOfShape UVOrigin' \n \
5812 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5813 __FILE__,VTexture,group);
5815 theCommands.Add("vtexrepeat",
5816 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5817 or 'vtexrepeat NameOfShape UVRepeat \n \
5818 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5821 theCommands.Add("vtexdefault",
5822 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5825 theCommands.Add("vsetam",
5826 "vsetam [shapename] mode"
5827 "\n\t\t: Activates selection mode for all selected or named shapes."
5828 "\n\t\t: Mod can be:"
5829 "\n\t\t: 0 - for shape itself"
5830 "\n\t\t: 1 - vertices"
5834 "\n\t\t: 5 - shells"
5835 "\n\t\t: 6 - solids"
5836 "\n\t\t: 7 - compounds"
5837 __FILE__,VActivatedMode,group);
5839 theCommands.Add("vunsetam",
5840 "vunsetam : Deactivates all selection modes for all shapes.",
5841 __FILE__,VActivatedMode,group);
5843 theCommands.Add("vstate",
5844 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5845 "\n\t\t: Reports show/hidden state for selected or named objects"
5846 "\n\t\t: -entities - print low-level information about detected entities"
5847 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5848 __FILE__,VState,group);
5850 theCommands.Add("vpickshapes",
5851 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5852 __FILE__,VPickShape,group);
5854 theCommands.Add("vtypes",
5855 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5858 theCommands.Add("vr",
5860 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
5861 __FILE__,vr, group);
5863 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5864 __FILE__, VPickSelected, group);
5866 theCommands.Add ("vloadselection",
5867 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5868 "\n\t\t: primitives for the shapes with names given without displaying them."
5869 "\n\t\t: -local - open local context before selection computation",
5870 __FILE__, VLoadSelection, group);
5872 theCommands.Add ("vautoactivatesel",
5873 "vautoactivatesel [0|1] : manage or display the option to automatically"
5874 "\n\t\t: activate selection for newly displayed objects"
5875 "\n\t\t: [0|1] - turn off | on auto activation of selection",
5876 __FILE__, VAutoActivateSelection, group);
5878 theCommands.Add("vbsdf", "vbsdf [name] [options]"
5879 "\nAdjusts parameters of material BSDF:"
5880 "\n -help : Shows this message"
5881 "\n -print : Print BSDF"
5882 "\n -kd : Weight of the Lambertian BRDF"
5883 "\n -kr : Weight of the reflection BRDF"
5884 "\n -kt : Weight of the transmission BTDF"
5885 "\n -ks : Weight of the glossy Blinn BRDF"
5886 "\n -le : Self-emitted radiance"
5887 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5888 "\n Schlick x y z, Dielectric x, Conductor x y"
5889 "\n -roughness : Roughness of material (Blinn's exponent)"
5890 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
5891 "\n -absorpcolor : Absorption color (only for transparent material)"
5892 "\n -normalize : Normalize BSDF coefficients",
5893 __FILE__, VBsdf, group);
5897 //=====================================================================
5898 //========================= for testing Draft and Rib =================
5899 //=====================================================================
5900 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5901 #include <DBRep.hxx>
5902 #include <TopoDS_Face.hxx>
5903 #include <gp_Pln.hxx>
5904 #include <AIS_KindOfSurface.hxx>
5905 #include <BRepOffsetAPI_DraftAngle.hxx>
5906 #include <Precision.hxx>
5907 #include <BRepAlgo.hxx>
5908 #include <OSD_Environment.hxx>
5909 #include <DrawTrSurf.hxx>
5910 //#include <DbgTools.hxx>
5911 //#include <FeatAlgo_MakeLinearForm.hxx>
5916 //=======================================================================
5917 //function : IsValid
5919 //=======================================================================
5920 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5921 const TopoDS_Shape& theResult,
5922 const Standard_Boolean closedSolid,
5923 const Standard_Boolean GeomCtrl)
5925 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5926 TCollection_AsciiString checkValid = check.Value();
5927 Standard_Boolean ToCheck = Standard_True;
5928 if (!checkValid.IsEmpty()) {
5930 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5932 if ( checkValid=="true" || checkValid=="TRUE" ) {
5933 ToCheck= Standard_False;
5937 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
5940 Standard_Boolean IsValid = Standard_True;
5942 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5947 //===============================================================================
5948 // TDraft : test draft, uses AIS Viewer
5949 // Solid Face Plane Angle Reverse
5950 //===============================================================================
5951 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5953 if (argc < 5) return 1;
5954 // argv[1] - TopoDS_Shape Solid
5955 // argv[2] - TopoDS_Shape Face
5956 // argv[3] - TopoDS_Shape Plane
5957 // argv[4] - Standard_Real Angle
5958 // argv[5] - Standard_Integer Reverse
5960 // Sprintf(prefix, argv[1]);
5961 Standard_Real anAngle = 0;
5962 Standard_Boolean Rev = Standard_False;
5963 Standard_Integer rev = 0;
5964 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5965 TopoDS_Shape face = GetShapeFromName(argv[2]);
5966 TopoDS_Face Face = TopoDS::Face(face);
5967 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5968 if (Plane.IsNull ()) {
5969 di << "TEST : Plane is NULL\n";
5972 anAngle = Draw::Atof(argv[4]);
5973 anAngle = 2*M_PI * anAngle / 360.0;
5975 Handle( Geom_Surface )aSurf;
5976 AIS_KindOfSurface aSurfType;
5977 Standard_Real Offset;
5979 if(argc > 4) { // == 5
5980 rev = Draw::Atoi(argv[5]);
5981 Rev = (rev)? Standard_True : Standard_False;
5984 TopoDS_Face face2 = TopoDS::Face(Plane);
5985 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5987 di << "TEST : Can't find plane\n";
5991 aDir = aPln.Axis().Direction();
5994 if (Plane.Orientation() == TopAbs_REVERSED)
5996 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5998 BRepOffsetAPI_DraftAngle Draft (Solid);
6000 if(Abs(anAngle)< Precision::Angular()) {
6001 di << "TEST : NULL angle\n";
6004 if(Rev) anAngle = - anAngle;
6005 Draft.Add (Face, aDir, anAngle, aPln);
6007 if (!Draft.IsDone()) {
6008 di << "TEST : Draft Not DONE \n";
6011 TopTools_ListOfShape Larg;
6013 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6014 di << "TEST : DesignAlgo returns Not valid\n";
6018 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6019 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6021 if ( !ais.IsNull() ) {
6022 ais->SetColor(DEFAULT_COLOR);
6023 ais->SetMaterial(DEFAULT_MATERIAL);
6024 // Display the AIS_Shape without redraw
6025 Ctx->Display(ais, Standard_False);
6027 const char *Name = "draft1";
6028 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6030 Handle(AIS_InteractiveObject) an_object =
6031 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6032 if (!an_object.IsNull()) {
6033 Ctx->Remove(an_object,
6035 GetMapOfAIS().UnBind2(Name) ;
6038 GetMapOfAIS().Bind(ais, Name);
6039 // DBRep::Set("draft", ais->Shape());
6041 Ctx->Display(ais, Standard_True);
6045 //==============================================================================
6046 //function : splitParameter
6047 //purpose : Split parameter string to parameter name and parameter value
6048 //==============================================================================
6049 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6050 TCollection_AsciiString& theName,
6051 TCollection_AsciiString& theValue)
6053 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6055 if (aParamNameEnd == 0)
6057 return Standard_False;
6060 TCollection_AsciiString aString (theString);
6061 if (aParamNameEnd != 0)
6063 theValue = aString.Split (aParamNameEnd);
6064 aString.Split (aString.Length() - 1);
6068 return Standard_True;
6071 //============================================================================
6073 //============================================================================
6074 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6077 DrawTrSurf::BasicCommands(theCommands);
6078 const char* group = "Check Features Operations commands";
6080 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6082 &TDraft,group); //Draft_Modification
6085 //==============================================================================
6086 // ViewerTest::Factory
6087 //==============================================================================
6088 void ViewerTest::Factory(Draw_Interpretor& theDI)
6090 // definition of Viewer Command
6091 ViewerTest::Commands(theDI);
6092 ViewerTest::AviCommands(theDI);
6095 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6099 // Declare entry point PLUGINFACTORY