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 <TopLoc_Location.hxx>
29 #include <TopTools_HArray1OfShape.hxx>
30 #include <TColStd_HArray1OfTransient.hxx>
31 #include <TColStd_HSequenceOfAsciiString.hxx>
32 #include <OSD_Timer.hxx>
33 #include <Geom_Axis2Placement.hxx>
34 #include <Geom_Axis1Placement.hxx>
35 #include <gp_Trsf.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <BRepAdaptor_Curve.hxx>
38 #include <StdSelect_ShapeTypeFilter.hxx>
40 #include <AIS_Drawer.hxx>
41 #include <AIS_ColoredShape.hxx>
42 #include <AIS_InteractiveObject.hxx>
43 #include <AIS_Trihedron.hxx>
44 #include <AIS_Axis.hxx>
45 #include <AIS_Relation.hxx>
46 #include <AIS_TypeFilter.hxx>
47 #include <AIS_SignatureFilter.hxx>
48 #include <AIS_LocalContext.hxx>
49 #include <AIS_ListOfInteractive.hxx>
50 #include <AIS_ListIteratorOfListOfInteractive.hxx>
51 #include <Aspect_InteriorStyle.hxx>
52 #include <Aspect_Window.hxx>
53 #include <Graphic3d_AspectFillArea3d.hxx>
54 #include <Graphic3d_AspectLine3d.hxx>
55 #include <Graphic3d_TextureRoot.hxx>
56 #include <Image_AlienPixMap.hxx>
57 #include <Prs3d_ShadingAspect.hxx>
58 #include <Prs3d_IsoAspect.hxx>
59 #include <TopTools_MapOfShape.hxx>
63 #include <Draw_Interpretor.hxx>
64 #include <TCollection_AsciiString.hxx>
65 #include <Draw_PluginMacro.hxx>
66 #include <ViewerTest.hxx>
68 // avoid warnings on 'extern "C"' functions returning C++ classes
70 #define _CRT_SECURE_NO_DEPRECATE
71 #pragma warning(4:4190)
72 #pragma warning (disable:4996)
75 #include <NIS_InteractiveContext.hxx>
76 #include <NIS_Triangulated.hxx>
77 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
79 #include <Quantity_Color.hxx>
80 #include <Quantity_NameOfColor.hxx>
82 #include <Graphic3d_NameOfMaterial.hxx>
84 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
85 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
87 enum ViewerTest_RedrawMode
89 ViewerTest_RM_Auto = -1,
90 ViewerTest_RM_RedrawForce,
91 ViewerTest_RM_RedrawSuppress
94 //! Auxiliary method to parse redraw mode argument
95 static Standard_Boolean parseRedrawMode (const TCollection_AsciiString& theArg,
96 ViewerTest_RedrawMode& theMode)
98 TCollection_AsciiString anArgCase (theArg);
99 anArgCase.LowerCase();
100 if (anArgCase == "-update"
101 || anArgCase == "-redraw")
103 theMode = ViewerTest_RM_RedrawForce;
104 return Standard_True;
106 else if (anArgCase == "-noupdate"
107 || anArgCase == "-noredraw")
109 theMode = ViewerTest_RM_RedrawSuppress;
110 return Standard_True;
112 return Standard_False;
115 //=======================================================================
116 //function : GetColorFromName
117 //purpose : get the Quantity_NameOfColor from a string
118 //=======================================================================
120 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
122 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
124 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
125 if (strcasecmp (theName, aColorName) == 0)
127 return Quantity_NameOfColor (anIter);
131 return DEFAULT_COLOR;
134 //=======================================================================
135 //function : GetTypeNames
137 //=======================================================================
138 static const char** GetTypeNames()
140 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
141 "Shape","ConnectedShape","MultiConn.Shape",
142 "ConnectedInter.","MultiConn.",
143 "Constraint","Dimension"};
144 static const char** ThePointer = names;
148 //=======================================================================
149 //function : GetTypeAndSignfromString
151 //=======================================================================
152 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
154 const char ** thefullnames = GetTypeNames();
155 Standard_Integer index(-1);
157 for(Standard_Integer i=0;i<=13 && index==-1;i++)
158 if(!strcasecmp(name,thefullnames[i]))
162 TheType = AIS_KOI_None;
168 TheType = AIS_KOI_Datum;
172 TheType = AIS_KOI_Shape;
176 TheType = AIS_KOI_Object;
180 TheType = AIS_KOI_Relation;
189 #include <Draw_Interpretor.hxx>
191 #include <Draw_Appli.hxx>
195 #include <TCollection_AsciiString.hxx>
196 #include <V3d_Viewer.hxx>
197 #include <V3d_View.hxx>
200 #include <AIS_InteractiveContext.hxx>
201 #include <AIS_Shape.hxx>
202 #include <AIS_TexturedShape.hxx>
203 #include <AIS_DisplayMode.hxx>
204 #include <TColStd_MapOfInteger.hxx>
205 #include <AIS_MapOfInteractive.hxx>
206 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
207 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
208 #include <ViewerTest_EventManager.hxx>
210 #include <TopoDS_Solid.hxx>
211 #include <BRepTools.hxx>
212 #include <BRep_Builder.hxx>
213 #include <TopAbs_ShapeEnum.hxx>
215 #include <TopoDS.hxx>
216 #include <BRep_Tool.hxx>
219 #include <Draw_Window.hxx>
220 #include <AIS_ListIteratorOfListOfInteractive.hxx>
221 #include <AIS_ListOfInteractive.hxx>
222 #include <AIS_DisplayMode.hxx>
223 #include <TopTools_ListOfShape.hxx>
224 #include <BRepOffsetAPI_MakeThickSolid.hxx>
225 #include <BRepOffset.hxx>
227 //==============================================================================
228 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
229 //==============================================================================
230 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
231 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
236 //==============================================================================
237 //function : VDisplayAISObject
238 //purpose : register interactive object in the map of AIS objects;
239 // if other object with such name already registered, it will be kept
240 // or replaced depending on value of <theReplaceIfExists>,
241 // if "true" - the old object will be cleared from AIS context;
242 // returns Standard_True if <theAISObj> registered in map;
243 //==============================================================================
244 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
245 const Handle(AIS_InteractiveObject)& theAISObj,
246 Standard_Boolean theReplaceIfExists = Standard_True)
248 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
249 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
250 if (aContextAIS.IsNull())
252 std::cout << "AIS context is not available.\n";
253 return Standard_False;
256 if (aMap.IsBound2 (theName))
258 if (!theReplaceIfExists)
260 std::cout << "Other interactive object has been already "
261 << "registered with name: " << theName << ".\n"
262 << "Please use another name.\n";
263 return Standard_False;
266 // stop displaying object
267 Handle(AIS_InteractiveObject) anOldObj =
268 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
270 if (!anOldObj.IsNull())
271 aContextAIS->Clear (anOldObj, Standard_True);
273 // remove name and old object from map
274 aMap.UnBind2 (theName);
277 if (theAISObj.IsNull())
279 // object with specified name already unbound
280 return Standard_True;
283 // unbind AIS object if was bound with another name
284 aMap.UnBind1 (theAISObj);
286 // can be registered without rebinding
287 aMap.Bind (theAISObj, theName);
288 aContextAIS->Display (theAISObj, Standard_True);
289 return Standard_True;
292 static TColStd_MapOfInteger theactivatedmodes(8);
293 static TColStd_ListOfTransient theEventMgrs;
295 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
296 const Handle(AIS_InteractiveContext)& Ctx)
298 theEventMgrs.Clear();
299 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
302 static Handle(V3d_View)& a3DView()
304 static Handle(V3d_View) Viou;
309 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
310 static Handle(AIS_InteractiveContext) aContext;
314 const Handle(V3d_View)& ViewerTest::CurrentView()
318 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
323 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
325 static Handle(NIS_InteractiveContext) aContext;
326 if (aContext.IsNull()) {
327 aContext = new NIS_InteractiveContext;
328 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
333 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
335 return TheAISContext();
338 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
340 TheAISContext() = aCtx;
341 ViewerTest::ResetEventManager();
344 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
346 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
349 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
351 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
355 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
356 theEventMgrs.Prepend(EM);
359 void ViewerTest::UnsetEventManager()
361 theEventMgrs.RemoveFirst();
365 void ViewerTest::ResetEventManager()
367 const Handle(NIS_View) aView =
368 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
369 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
372 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
374 Handle(ViewerTest_EventManager) EM;
375 if(theEventMgrs.IsEmpty()) return EM;
376 Handle(Standard_Transient) Tr = theEventMgrs.First();
377 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
381 //=======================================================================
382 //function : Get Context and active view
384 //=======================================================================
385 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
386 Handle(V3d_View)& theView)
388 theCtx = ViewerTest::GetAISContext();
389 theView = ViewerTest::CurrentView();
393 std::cout << "Error: cannot find an active view!\n";
394 return Standard_False;
396 return Standard_True;
399 //==============================================================================
400 //function : GetShapeFromName
401 //purpose : Compute an Shape from a draw variable or a file name
402 //==============================================================================
404 static TopoDS_Shape GetShapeFromName(const char* name)
406 TopoDS_Shape S = DBRep::Get(name);
409 BRep_Builder aBuilder;
410 BRepTools::Read( S, name, aBuilder);
416 //==============================================================================
417 //function : GetAISShapeFromName
418 //purpose : Compute an AIS_Shape from a draw variable or a file name
419 //==============================================================================
420 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
422 Handle(AIS_Shape) retsh;
424 if(GetMapOfAIS().IsBound2(name)){
425 const Handle(AIS_InteractiveObject) IO =
426 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
428 if(IO->Type()==AIS_KOI_Shape) {
429 if(IO->Signature()==0){
430 retsh = *((Handle(AIS_Shape)*)&IO);
433 cout << "an Object which is not an AIS_Shape "
434 "already has this name!!!"<<endl;
441 TopoDS_Shape S = GetShapeFromName(name);
443 retsh = new AIS_Shape(S);
449 //==============================================================================
451 //purpose : Remove all the object from the viewer
452 //==============================================================================
453 void ViewerTest::Clear()
455 if ( !a3DView().IsNull() ) {
456 if (TheAISContext()->HasOpenedContext())
457 TheAISContext()->CloseLocalContext();
458 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
459 while ( it.More() ) {
460 cout << "Remove " << it.Key2() << endl;
461 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
462 const Handle(AIS_InteractiveObject) anObj =
463 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
464 TheAISContext()->Remove(anObj,Standard_False);
465 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
466 const Handle(NIS_InteractiveObject) anObj =
467 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
468 TheNISContext()->Remove(anObj);
472 TheAISContext()->UpdateCurrentViewer();
473 // TheNISContext()->UpdateViews();
474 GetMapOfAIS().Clear();
478 //==============================================================================
479 //function : StandardModesActivation
480 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
482 //==============================================================================
483 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
485 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
487 if (TheAISContext()->HasOpenedContext())
488 aContext->CloseLocalContext();
491 if(!aContext->HasOpenedContext()) {
492 // To unhilight the preselected object
493 aContext->UnhilightCurrents(Standard_False);
494 // Open a local Context in order to be able to select subshape from
495 // the selected shape if any or for all if there is no selection
496 if (!aContext->FirstCurrentObject().IsNull()){
497 aContext->OpenLocalContext(Standard_False);
499 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
500 aContext->Load( aContext->Current(),-1,Standard_True);
504 aContext->OpenLocalContext();
507 const char *cmode="???";
510 case 0: cmode = "Shape"; break;
511 case 1: cmode = "Vertex"; break;
512 case 2: cmode = "Edge"; break;
513 case 3: cmode = "Wire"; break;
514 case 4: cmode = "Face"; break;
515 case 5: cmode = "Shell"; break;
516 case 6: cmode = "Solid"; break;
517 case 7: cmode = "Compsolid"; break;
518 case 8: cmode = "Compound"; break;
521 if(theactivatedmodes.Contains(mode))
523 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
524 theactivatedmodes.Remove(mode);
525 cout<<"Mode "<< cmode <<" OFF"<<endl;
529 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
530 theactivatedmodes.Add(mode);
531 cout<<"Mode "<< cmode << " ON" << endl;
536 //==============================================================================
537 //function : CopyIsoAspect
538 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
539 //==============================================================================
540 static Handle(Prs3d_IsoAspect) CopyIsoAspect
541 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
542 const Standard_Integer theNbIsos)
544 Quantity_Color aColor;
545 Aspect_TypeOfLine aType;
546 Standard_Real aWidth;
548 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
550 Handle(Prs3d_IsoAspect) aResult =
551 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
556 //==============================================================================
558 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
559 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
560 //==============================================================================
561 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
563 if (TheAISContext().IsNull()) {
564 di << argv[0] << " Call 'vinit' before!\n";
569 di << "Current number of isos : " <<
570 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
571 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
572 di << "IsoOnPlane mode is " <<
573 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
578 Standard_Integer aLastInd = argc - 1;
579 Standard_Boolean isChanged = Standard_False;
580 Standard_Integer aNbUIsos = 0;
581 Standard_Integer aNbVIsos = 0;
584 Standard_Boolean isIsoOnPlane = Standard_False;
586 if (strcmp(argv[aLastInd], "1") == 0) {
587 isIsoOnPlane = Standard_True;
588 isChanged = Standard_True;
589 } else if (strcmp(argv[aLastInd], "0") == 0) {
590 isIsoOnPlane = Standard_False;
591 isChanged = Standard_True;
595 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
596 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
599 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
600 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
602 TheAISContext()->IsoOnPlane(isIsoOnPlane);
605 // If there are no shapes provided set the default numbers.
606 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
607 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
614 for (i = 1; i <= aLastInd; i++) {
615 TCollection_AsciiString name(argv[i]);
616 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
619 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
620 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
621 const Handle(AIS_InteractiveObject) aShape =
622 Handle(AIS_InteractiveObject)::DownCast (anObj);
623 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
624 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
625 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
628 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
629 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
630 TheAISContext()->SetLocalAttributes
631 (aShape, CurDrawer, Standard_False);
632 TheAISContext()->Redisplay(aShape);
634 di << "Number of isos for " << argv[i] << " : "
635 << aUIso->Number() << " " << aVIso->Number() << "\n";
638 di << argv[i] << ": Not an AIS interactive object!\n";
641 di << argv[i] << ": Use 'vdisplay' before\n";
646 TheAISContext()->UpdateCurrentViewer();
652 //==============================================================================
653 //function : VDispAreas,VDispSensitive,...
655 //==============================================================================
656 static Standard_Integer VDispAreas (Draw_Interpretor& ,
657 Standard_Integer theArgNb,
662 std::cout << "Error: wrong syntax!\n";
666 Handle(AIS_InteractiveContext) aCtx;
667 Handle(V3d_View) aView;
668 if (!getCtxAndView (aCtx, aView))
673 aCtx->DisplayActiveAreas (aView);
676 static Standard_Integer VClearAreas (Draw_Interpretor& ,
677 Standard_Integer theArgNb,
682 std::cout << "Error: wrong syntax!\n";
686 Handle(AIS_InteractiveContext) aCtx;
687 Handle(V3d_View) aView;
688 if (!getCtxAndView (aCtx, aView))
693 aCtx->ClearActiveAreas (aView);
697 static Standard_Integer VDispSensi (Draw_Interpretor& ,
698 Standard_Integer theArgNb,
703 std::cout << "Error: wrong syntax!\n";
707 Handle(AIS_InteractiveContext) aCtx;
708 Handle(V3d_View) aView;
709 if (!getCtxAndView (aCtx, aView))
714 aCtx->DisplayActiveSensitive (aView);
719 static Standard_Integer VClearSensi (Draw_Interpretor& ,
720 Standard_Integer theArgNb,
725 std::cout << "Error: wrong syntax!\n";
729 Handle(AIS_InteractiveContext) aCtx;
730 Handle(V3d_View) aView;
731 if (!getCtxAndView (aCtx, aView))
735 aCtx->ClearActiveSensitive (aView);
739 //==============================================================================
741 //purpose : To list the displayed object with their attributes
742 //==============================================================================
743 static int VDir (Draw_Interpretor& theDI,
747 if (!a3DView().IsNull())
752 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
753 anIter.More(); anIter.Next())
755 theDI << "\t" << anIter.Key2().ToCString() << "\n";
760 //==============================================================================
761 //function : VSelPrecision
762 //purpose : To set the selection precision mode and tolerance value
763 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
764 // value (integer number of pixel for window mode, double value of
765 // sensitivity for view mode). Without arguments the function just
766 // prints the current precision mode and the corresponding tolerance.
767 //==============================================================================
768 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
772 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
776 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
777 if( aContext.IsNull() )
782 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
783 if( aMode == StdSelect_SM_WINDOW )
785 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
786 di << "Precision mode : 0 (window)\n";
787 di << "Pixel tolerance : " << aPixelTolerance << "\n";
789 else if( aMode == StdSelect_SM_VIEW )
791 Standard_Real aSensitivity = aContext->Sensitivity();
792 di << "Precision mode : 1 (view)\n";
793 di << "Sensitivity : " << aSensitivity << "\n";
798 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
799 aContext->SetSensitivityMode( aMode );
802 if( aMode == StdSelect_SM_WINDOW )
804 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
805 aContext->SetPixelTolerance( aPixelTolerance );
807 else if( aMode == StdSelect_SM_VIEW )
809 Standard_Real aSensitivity = Draw::Atof( argv[2] );
810 aContext->SetSensitivity( aSensitivity );
817 //==============================================================================
819 //purpose : To dump the active view snapshot to image file
820 //==============================================================================
821 static Standard_Integer VDump (Draw_Interpretor& theDI,
822 Standard_Integer theArgNb,
823 Standard_CString* theArgVec)
827 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
831 Standard_Integer anArgIter = 1;
832 Standard_CString aFilePath = theArgVec[anArgIter++];
833 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
834 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
835 Standard_Integer aWidth = 0;
836 Standard_Integer aHeight = 0;
837 for (; anArgIter < theArgNb; ++anArgIter)
839 TCollection_AsciiString anArg (theArgVec[anArgIter]);
843 aBufferType = Graphic3d_BT_RGBA;
845 else if (anArg == "rgb")
847 aBufferType = Graphic3d_BT_RGB;
849 else if (anArg == "depth")
851 aBufferType = Graphic3d_BT_Depth;
853 else if (anArg == "l"
856 aStereoOpts = V3d_SDO_LEFT_EYE;
858 else if (anArg == "r"
861 aStereoOpts = V3d_SDO_RIGHT_EYE;
863 else if (anArg == "mono")
865 aStereoOpts = V3d_SDO_MONO;
867 else if (anArg == "w"
872 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
875 else if (++anArgIter >= theArgNb)
877 std::cout << "Error: integer value is expected right after 'width'\n";
880 aWidth = Draw::Atoi (theArgVec[anArgIter]);
882 else if (anArg == "h"
883 || anArg == "height")
887 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
890 if (++anArgIter >= theArgNb)
892 std::cout << "Error: integer value is expected right after 'height'\n";
895 aHeight = Draw::Atoi (theArgVec[anArgIter]);
897 else if (anArg.IsIntegerValue())
899 // compatibility with old syntax
903 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
906 else if (++anArgIter >= theArgNb)
908 std::cout << "Error: height value is expected right after width\n";
911 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
912 aHeight = Draw::Atoi (theArgVec[anArgIter]);
916 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
920 if ((aWidth <= 0 && aHeight > 0)
921 || (aWidth > 0 && aHeight <= 0))
923 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
927 Handle(V3d_View) aView = ViewerTest::CurrentView();
930 std::cout << "Error: cannot find an active view!\n";
934 if (aWidth <= 0 || aHeight <= 0)
936 if (aStereoOpts != V3d_SDO_MONO)
938 aView->Window()->Size (aWidth, aHeight);
942 if (!aView->Dump (aFilePath, aBufferType))
944 theDI << "Fail: view dump failed!\n";
950 Image_AlienPixMap aPixMap;
951 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
953 theDI << "Fail: view dump failed!\n";
957 if (aPixMap.SizeX() != Standard_Size(aWidth)
958 || aPixMap.SizeY() != Standard_Size(aHeight))
960 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
961 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
963 if (!aPixMap.Save (aFilePath))
965 theDI << "Fail: image can not be saved!\n";
971 //==============================================================================
972 //function : Displays,Erase...
975 //==============================================================================
976 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
977 const Standard_Integer Mode,
978 const Standard_Integer TypeOfOperation,
979 const Standard_Boolean Upd)
981 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
983 switch(TypeOfOperation){
985 Ctx->Display(IO,Mode,Upd);
993 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
995 Ctx->SetDisplayMode(IO,Mode,Upd);
1000 Ctx->SetDisplayMode(0,Upd);
1002 Ctx->UnsetDisplayMode(IO,Upd);
1009 //=======================================================================
1012 //=======================================================================
1013 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1016 TCollection_AsciiString name;
1019 // display others presentations
1020 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
1021 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
1022 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
1023 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1025 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1027 //unset displaymode.. comportement particulier...
1028 if(TypeOfOperation==4){
1030 if(Ctx->NbCurrents()==0 ||
1031 Ctx->NbSelected()==0){
1032 Handle(AIS_InteractiveObject) IO;
1033 VwrTst_DispErase(IO,-1,4,Standard_False);
1035 else if(!Ctx->HasOpenedContext()){
1036 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1037 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1040 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1041 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1042 Ctx->UpdateCurrentViewer();
1045 Handle(AIS_InteractiveObject) IO;
1047 if(GetMapOfAIS().IsBound2(name)){
1048 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1050 VwrTst_DispErase(IO,-1,4,Standard_True);
1055 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1056 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1057 Handle(AIS_InteractiveObject) IO;
1058 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1060 if(!Ctx->HasOpenedContext()){
1061 // set/unset display mode sur le Contexte...
1062 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1063 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1065 Ctx->UpdateCurrentViewer();
1068 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1069 Ctx->Display(Ctx->Interactive(),Dmode);
1073 Handle(AIS_InteractiveObject) IO;
1075 if(GetMapOfAIS().IsBound2(name))
1076 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1078 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1084 //=======================================================================
1087 //=======================================================================
1088 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1090 if(argc==1) return 1;
1091 Standard_Integer On = Draw::Atoi(argv[1]);
1092 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1096 if(!Ctx->HasOpenedContext()){
1097 di<<"sub intensite ";
1100 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1101 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1103 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1105 di <<"passage dans off"<<"\n";
1106 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1111 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1113 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1115 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1118 Ctx->UpdateCurrentViewer();
1121 Handle(AIS_InteractiveObject) IO;
1122 TCollection_AsciiString name = argv[2];
1123 if(GetMapOfAIS().IsBound2(name)){
1124 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1127 Ctx->SubIntensityOn(IO);
1129 Ctx->SubIntensityOff(IO);
1137 //! Auxiliary class to iterate presentations from different collections.
1138 class ViewTest_PrsIter
1142 //! Create and initialize iterator object.
1143 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1144 : mySource (IterSource_All)
1146 NCollection_Sequence<TCollection_AsciiString> aNames;
1147 if (!theName.IsEmpty())
1148 aNames.Append (theName);
1152 //! Create and initialize iterator object.
1153 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1154 : mySource (IterSource_All)
1159 //! Initialize the iterator.
1160 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1162 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1164 mySelIter.Nullify();
1165 myCurrent.Nullify();
1166 myCurrentTrs.Nullify();
1167 if (!mySeq.IsEmpty())
1169 mySource = IterSource_List;
1170 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1172 else if (aCtx->NbCurrents() > 0)
1174 mySource = IterSource_Selected;
1176 mySelIter->InitCurrent();
1180 mySource = IterSource_All;
1181 myMapIter.Initialize (GetMapOfAIS());
1186 const TCollection_AsciiString& CurrentName() const
1188 return myCurrentName;
1191 const Handle(AIS_InteractiveObject)& Current() const
1196 const Handle(Standard_Transient)& CurrentTrs() const
1198 return myCurrentTrs;
1201 //! @return true if iterator points to valid object within collection
1202 Standard_Boolean More() const
1206 case IterSource_All: return myMapIter.More();
1207 case IterSource_List: return mySeqIter.More();
1208 case IterSource_Selected: return mySelIter->MoreCurrent();
1210 return Standard_False;
1213 //! Go to the next item.
1216 myCurrentName.Clear();
1217 myCurrentTrs.Nullify();
1218 myCurrent.Nullify();
1221 case IterSource_All:
1226 case IterSource_List:
1231 case IterSource_Selected:
1233 mySelIter->NextCurrent();
1246 case IterSource_All:
1248 if (myMapIter.More())
1250 myCurrentName = myMapIter.Key2();
1251 myCurrentTrs = myMapIter.Key1();
1252 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1256 case IterSource_List:
1258 if (mySeqIter.More())
1260 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1262 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1265 myCurrentName = mySeqIter.Value();
1266 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1267 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1271 case IterSource_Selected:
1273 if (mySelIter->MoreCurrent())
1275 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1276 myCurrent = mySelIter->Current();
1294 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1295 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1296 NCollection_Sequence<TCollection_AsciiString> mySeq;
1297 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1299 TCollection_AsciiString myCurrentName;//!< current item name
1300 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1301 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1303 IterSource mySource; //!< iterated collection
1307 //==============================================================================
1308 //function : VInteriorStyle
1309 //purpose : sets interior style of the a selected or named or displayed shape
1310 //==============================================================================
1311 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1312 Standard_Integer theArgNb,
1313 const char** theArgVec)
1315 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1318 std::cerr << "Error: no active view!\n";
1322 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
1323 Standard_Integer anArgIter = 1;
1324 for (; anArgIter < theArgNb; ++anArgIter)
1326 if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
1331 TCollection_AsciiString aName;
1332 if (theArgNb - anArgIter == 2)
1334 aName = theArgVec[anArgIter++];
1336 else if (theArgNb - anArgIter != 1)
1338 std::cout << "Error: wrong number of arguments! See usage:\n";
1339 theDI.PrintHelp (theArgVec[0]);
1342 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1343 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1344 aStyleArg.LowerCase();
1345 if (aStyleArg == "empty")
1349 else if (aStyleArg == "hollow")
1353 else if (aStyleArg == "hatch")
1357 else if (aStyleArg == "solid")
1361 else if (aStyleArg == "hiddenline")
1367 anInterStyle = aStyleArg.IntegerValue();
1369 if (anInterStyle < Aspect_IS_EMPTY
1370 || anInterStyle > Aspect_IS_HIDDENLINE)
1372 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1373 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1377 if (!aName.IsEmpty()
1378 && !GetMapOfAIS().IsBound2 (aName))
1380 std::cout << "Error: object " << aName << " is not displayed!\n";
1384 if (aCtx->HasOpenedContext())
1386 aCtx->CloseLocalContext();
1388 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1390 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1393 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1394 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1395 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1396 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1397 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1401 // update the screen and redraw the view
1402 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
1403 a3DView()->SetImmediateUpdate (isAutoUpdate);
1404 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
1405 || aToUpdate == ViewerTest_RM_RedrawForce)
1407 TheAISContext()->UpdateCurrentViewer();
1412 //! Auxiliary structure for VAspects
1413 struct ViewerTest_AspectsChangeSet
1415 Standard_Integer ToSetColor;
1416 Quantity_Color Color;
1418 Standard_Integer ToSetLineWidth;
1419 Standard_Real LineWidth;
1421 Standard_Integer ToSetTransparency;
1422 Standard_Real Transparency;
1424 Standard_Integer ToSetMaterial;
1425 Graphic3d_NameOfMaterial Material;
1426 TCollection_AsciiString MatName;
1428 NCollection_Sequence<TopoDS_Shape> SubShapes;
1430 //! Empty constructor
1431 ViewerTest_AspectsChangeSet()
1433 Color (DEFAULT_COLOR),
1436 ToSetTransparency (0),
1439 Material (Graphic3d_NOM_DEFAULT) {}
1441 //! @return true if no changes have been requested
1442 Standard_Boolean IsEmpty() const
1444 return ToSetLineWidth == 0
1445 && ToSetTransparency == 0
1447 && ToSetMaterial == 0;
1450 //! @return true if properties are valid
1451 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1453 Standard_Boolean isOk = Standard_True;
1454 if (LineWidth <= 0.0
1455 || LineWidth > 10.0)
1457 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1458 isOk = Standard_False;
1460 if (Transparency < 0.0
1461 || Transparency > 1.0)
1463 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1464 isOk = Standard_False;
1467 && ToSetTransparency)
1469 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1470 isOk = Standard_False;
1472 if (ToSetMaterial == 1
1473 && Material == Graphic3d_NOM_DEFAULT)
1475 std::cout << "Error: unknown material " << MatName << ".\n";
1476 isOk = Standard_False;
1483 //==============================================================================
1484 //function : VAspects
1486 //==============================================================================
1487 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1488 Standard_Integer theArgNb,
1489 const char** theArgVec)
1491 TCollection_AsciiString aCmdName (theArgVec[0]);
1492 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1495 std::cerr << "Error: no active view!\n";
1499 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
1500 Standard_Integer anArgIter = 1;
1501 NCollection_Sequence<TCollection_AsciiString> aNames;
1502 for (; anArgIter < theArgNb; ++anArgIter)
1504 TCollection_AsciiString anArg = theArgVec[anArgIter];
1505 if (parseRedrawMode (anArg, aToUpdate))
1509 else if (!anArg.IsEmpty()
1510 && anArg.Value (1) != '-')
1512 aNames.Append (anArg);
1520 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1521 aChanges.Append (ViewerTest_AspectsChangeSet());
1522 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1524 // parse syntax of legacy commands
1525 if (aCmdName == "vsetwidth")
1527 if (aNames.IsEmpty()
1528 || !aNames.Last().IsRealValue())
1530 std::cout << "Error: not enough arguments!\n";
1533 aChangeSet->ToSetLineWidth = 1;
1534 aChangeSet->LineWidth = aNames.Last().RealValue();
1535 aNames.Remove (aNames.Length());
1537 else if (aCmdName == "vunsetwidth")
1539 aChangeSet->ToSetLineWidth = -1;
1541 else if (aCmdName == "vsetcolor")
1543 if (aNames.IsEmpty())
1545 std::cout << "Error: not enough arguments!\n";
1548 aChangeSet->ToSetColor = 1;
1549 aChangeSet->Color = ViewerTest::GetColorFromName (aNames.Last().ToCString());
1550 aNames.Remove (aNames.Length());
1552 else if (aCmdName == "vunsetcolor")
1554 aChangeSet->ToSetColor = -1;
1556 else if (aCmdName == "vsettransparency")
1558 if (aNames.IsEmpty()
1559 || !aNames.Last().IsRealValue())
1561 std::cout << "Error: not enough arguments!\n";
1564 aChangeSet->ToSetTransparency = 1;
1565 aChangeSet->Transparency = aNames.Last().RealValue();
1566 aNames.Remove (aNames.Length());
1568 else if (aCmdName == "vunsettransparency")
1570 aChangeSet->ToSetTransparency = -1;
1572 else if (aCmdName == "vsetmaterial")
1574 if (aNames.IsEmpty())
1576 std::cout << "Error: not enough arguments!\n";
1579 aChangeSet->ToSetMaterial = 1;
1580 aChangeSet->MatName = aNames.Last();
1581 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1582 aNames.Remove (aNames.Length());
1584 else if (aCmdName == "vunsetmaterial")
1586 aChangeSet->ToSetMaterial = -1;
1588 else if (anArgIter >= theArgNb)
1590 std::cout << "Error: not enough arguments!\n";
1594 if (!aChangeSet->IsEmpty())
1596 anArgIter = theArgNb;
1598 for (; anArgIter < theArgNb; ++anArgIter)
1600 TCollection_AsciiString anArg = theArgVec[anArgIter];
1602 if (anArg == "-setwidth"
1603 || anArg == "-setlinewidth")
1605 if (++anArgIter >= theArgNb)
1607 std::cout << "Error: wrong syntax at " << anArg << "\n";
1610 aChangeSet->ToSetLineWidth = 1;
1611 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1613 else if (anArg == "-unsetwidth"
1614 || anArg == "-unsetlinewidth")
1616 aChangeSet->ToSetLineWidth = -1;
1617 aChangeSet->LineWidth = 1.0;
1619 else if (anArg == "-settransp"
1620 || anArg == "-settransparency")
1622 if (++anArgIter >= theArgNb)
1624 std::cout << "Error: wrong syntax at " << anArg << "\n";
1627 aChangeSet->ToSetTransparency = 1;
1628 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1629 if (aChangeSet->Transparency >= 0.0
1630 && aChangeSet->Transparency <= Precision::Confusion())
1632 aChangeSet->ToSetTransparency = -1;
1633 aChangeSet->Transparency = 0.0;
1636 else if (anArg == "-setalpha")
1638 if (++anArgIter >= theArgNb)
1640 std::cout << "Error: wrong syntax at " << anArg << "\n";
1643 aChangeSet->ToSetTransparency = 1;
1644 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1645 if (aChangeSet->Transparency < 0.0
1646 || aChangeSet->Transparency > 1.0)
1648 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1651 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1652 if (aChangeSet->Transparency >= 0.0
1653 && aChangeSet->Transparency <= Precision::Confusion())
1655 aChangeSet->ToSetTransparency = -1;
1656 aChangeSet->Transparency = 0.0;
1659 else if (anArg == "-unsettransp"
1660 || anArg == "-unsettransparency"
1661 || anArg == "-unsetalpha"
1662 || anArg == "-opaque")
1664 aChangeSet->ToSetTransparency = -1;
1665 aChangeSet->Transparency = 0.0;
1667 else if (anArg == "-setcolor")
1669 if (++anArgIter >= theArgNb)
1671 std::cout << "Error: wrong syntax at " << anArg << "\n";
1674 aChangeSet->ToSetColor = 1;
1675 aChangeSet->Color = ViewerTest::GetColorFromName (theArgVec[anArgIter]);
1677 else if (anArg == "-unsetcolor")
1679 aChangeSet->ToSetColor = -1;
1680 aChangeSet->Color = DEFAULT_COLOR;
1682 else if (anArg == "-setmat"
1683 || anArg == "-setmaterial")
1685 if (++anArgIter >= theArgNb)
1687 std::cout << "Error: wrong syntax at " << anArg << "\n";
1690 aChangeSet->ToSetMaterial = 1;
1691 aChangeSet->MatName = theArgVec[anArgIter];
1692 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1694 else if (anArg == "-unsetmat"
1695 || anArg == "-unsetmaterial")
1697 aChangeSet->ToSetMaterial = -1;
1698 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1700 else if (anArg == "-subshape"
1701 || anArg == "-subshapes")
1703 if (aNames.IsEmpty())
1705 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1709 aChanges.Append (ViewerTest_AspectsChangeSet());
1710 aChangeSet = &aChanges.ChangeLast();
1712 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1714 Standard_CString aSubShapeName = theArgVec[anArgIter];
1715 if (*aSubShapeName == '-')
1721 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1722 if (aSubShape.IsNull())
1724 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1727 aChangeSet->SubShapes.Append (aSubShape);
1730 if (aChangeSet->SubShapes.IsEmpty())
1732 std::cerr << "Error: empty list is specified after -subshapes!\n";
1736 else if (anArg == "-unset")
1738 aChangeSet->ToSetLineWidth = -1;
1739 aChangeSet->LineWidth = 1.0;
1740 aChangeSet->ToSetTransparency = -1;
1741 aChangeSet->Transparency = 0.0;
1742 aChangeSet->ToSetColor = -1;
1743 aChangeSet->Color = DEFAULT_COLOR;
1744 aChangeSet->ToSetMaterial = -1;
1745 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1749 std::cout << "Error: wrong syntax at " << anArg << "\n";
1754 Standard_Boolean isFirst = Standard_True;
1755 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1756 aChangesIter.More(); aChangesIter.Next())
1758 if (!aChangesIter.Value().Validate (!isFirst))
1762 isFirst = Standard_False;
1765 if (aCtx->HasOpenedContext())
1767 aCtx->CloseLocalContext();
1769 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
1771 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
1772 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
1773 Handle(AIS_ColoredShape) aColoredPrs;
1774 Standard_Boolean toDisplay = Standard_False;
1775 if (aChanges.Length() > 1)
1777 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
1778 if (aShapePrs.IsNull())
1780 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
1783 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
1784 if (aColoredPrs.IsNull())
1786 aColoredPrs = new AIS_ColoredShape (aShapePrs);
1787 aCtx->Remove (aShapePrs, Standard_False);
1788 GetMapOfAIS().UnBind2 (aName);
1789 GetMapOfAIS().Bind (aColoredPrs, aName);
1790 toDisplay = Standard_True;
1791 aShapePrs = aColoredPrs;
1798 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1799 aChangeSet = &aChangesIter.ChangeValue();
1800 if (aChangeSet->ToSetMaterial == 1)
1802 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
1804 else if (aChangeSet->ToSetMaterial == -1)
1806 aCtx->UnsetMaterial (aPrs, Standard_False);
1808 if (aChangeSet->ToSetColor == 1)
1810 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
1812 else if (aChangeSet->ToSetColor == -1)
1814 aCtx->UnsetColor (aPrs, Standard_False);
1816 if (aChangeSet->ToSetTransparency == 1)
1818 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
1820 else if (aChangeSet->ToSetTransparency == -1)
1822 aCtx->UnsetTransparency (aPrs, Standard_False);
1824 if (aChangeSet->ToSetLineWidth == 1)
1826 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
1828 else if (aChangeSet->ToSetLineWidth == -1)
1830 aCtx->UnsetWidth (aPrs, Standard_False);
1833 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
1835 aChangeSet = &aChangesIter.ChangeValue();
1836 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
1837 aSubShapeIter.More(); aSubShapeIter.Next())
1839 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
1840 if (aChangeSet->ToSetColor == 1)
1842 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
1844 if (aChangeSet->ToSetLineWidth == 1)
1846 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
1848 if (aChangeSet->ToSetColor == -1
1849 || aChangeSet->ToSetLineWidth == -1)
1851 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
1857 aCtx->Display (aPrs, Standard_False);
1859 else if (!aColoredPrs.IsNull())
1861 aColoredPrs->Redisplay();
1866 Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
1867 Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
1868 if (!aNisObj.IsNull())
1870 if (aChangeSet->ToSetTransparency != 0)
1872 aNisObj->SetTransparency (aChangeSet->Transparency);
1875 if (!aNisTri.IsNull())
1877 if (aChangeSet->ToSetColor != 0)
1879 aNisTri->SetColor (aChangeSet->Color);
1881 if (aChangeSet->ToSetLineWidth != 0)
1883 aNisTri->SetLineWidth (aChangeSet->LineWidth);
1889 // update the screen and redraw the view
1890 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
1891 a3DView()->SetImmediateUpdate (isAutoUpdate);
1892 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
1893 || aToUpdate == ViewerTest_RM_RedrawForce)
1895 TheAISContext()->UpdateCurrentViewer();
1900 //==============================================================================
1901 //function : VDonly2
1903 //purpose : Display only a selected or named object
1904 // if there is no selected or named object s, nothing is done
1905 //==============================================================================
1906 static int VDonly2 (Draw_Interpretor& ,
1907 Standard_Integer theArgNb,
1908 const char** theArgVec)
1910 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1913 std::cerr << "Error: no active view!\n";
1917 if (aCtx->HasOpenedContext())
1919 aCtx->CloseLocalContext();
1921 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
1923 Standard_Integer anArgIter = 1;
1924 for (; anArgIter < theArgNb; ++anArgIter)
1926 if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
1932 NCollection_Map<Handle(Standard_Transient)> aDispSet;
1933 if (anArgIter >= theArgNb)
1935 // display only selected objects
1936 if (aCtx->NbCurrents() < 1)
1941 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
1943 aDispSet.Add (aCtx->Current());
1948 // display only specified objects
1949 for (; anArgIter < theArgNb; ++anArgIter)
1951 TCollection_AsciiString aName = theArgVec[anArgIter];
1952 if (GetMapOfAIS().IsBound2 (aName))
1954 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1955 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1957 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
1958 aCtx->Display (aShape, Standard_False);
1960 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1962 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
1963 TheNISContext()->Display (aShape);
1965 aDispSet.Add (anObj);
1970 // weed out other objects
1971 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
1973 if (aDispSet.Contains (anIter.Key1()))
1978 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1980 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1981 aCtx->Erase (aShape, Standard_False);
1983 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1985 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1986 TheNISContext()->Erase (aShape);
1990 // update the screen and redraw the view
1991 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
1992 a3DView()->SetImmediateUpdate (isAutoUpdate);
1993 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
1994 || aToUpdate == ViewerTest_RM_RedrawForce)
1996 TheAISContext()->UpdateCurrentViewer();
2002 //==============================================================================
2003 //function : VRemove
2004 //purpose : Removes selected or named objects.
2005 // If there is no selected or named objects,
2006 // all objects in the viewer can be removed with argument -all.
2007 // If -context is in arguments, the object is not deleted from the map of
2008 // objects (deleted only from the current context).
2009 //==============================================================================
2010 int VRemove (Draw_Interpretor& theDI,
2011 Standard_Integer theArgNb,
2012 const char** theArgVec)
2014 if (a3DView().IsNull())
2016 std::cout << "Error: wrong syntax!\n";
2020 TheAISContext()->CloseAllContexts (Standard_False);
2022 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
2023 Standard_Boolean isContextOnly = Standard_False;
2024 Standard_Boolean toRemoveAll = Standard_False;
2025 Standard_Boolean toPrintInfo = Standard_True;
2027 Standard_Integer anArgIter = 1;
2028 for (; anArgIter < theArgNb; ++anArgIter)
2030 TCollection_AsciiString anArg = theArgVec[anArgIter];
2032 if (anArg == "-context")
2034 isContextOnly = Standard_True;
2036 else if (anArg == "-all")
2038 toRemoveAll = Standard_True;
2040 else if (anArg == "-noinfo")
2042 toPrintInfo = Standard_False;
2044 else if (!parseRedrawMode (anArg, aToUpdate))
2050 && anArgIter < theArgNb)
2052 std::cout << "Error: wrong syntax!\n";
2056 NCollection_List<TCollection_AsciiString> anIONameList;
2059 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2060 anIter.More(); anIter.Next())
2062 anIONameList.Append (anIter.Key2());
2065 else if (anArgIter < theArgNb) // removed objects names are in argument list
2067 for (; anArgIter < theArgNb; ++anArgIter)
2069 TCollection_AsciiString aName = theArgVec[anArgIter];
2070 if (!GetMapOfAIS().IsBound2 (aName))
2072 theDI << aName.ToCString() << " was not bound to some object.\n";
2076 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2078 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2081 if (anIO->GetContext() != TheAISContext())
2083 theDI << aName.ToCString() << " was not displayed in current context.\n";
2084 theDI << "Please activate view with this object displayed and try again.\n";
2088 anIONameList.Append (aName);
2092 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2093 if (!aNisIO.IsNull())
2095 anIONameList.Append (aName);
2099 else if (TheAISContext()->NbCurrents() > 0
2100 || TheNISContext()->GetSelected().Extent() > 0)
2102 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2103 anIter.More(); anIter.Next())
2105 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2108 if (!TheAISContext()->IsCurrent (anIO))
2113 anIONameList.Append (anIter.Key2());
2117 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2118 if (!aNisIO.IsNull())
2120 if (!TheNISContext()->IsSelected (aNisIO))
2125 anIONameList.Append (anIter.Key2());
2130 // Unbind all removed objects from the map of displayed IO.
2131 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2132 anIter.More(); anIter.Next())
2134 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2137 TheAISContext()->Remove (anIO, Standard_False);
2140 theDI << anIter.Value().ToCString() << " was removed\n";
2145 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2146 if (!aNisIO.IsNull())
2148 TheNISContext()->Remove (aNisIO);
2151 theDI << anIter.Value().ToCString() << " was removed\n";
2157 GetMapOfAIS().UnBind2 (anIter.Value());
2161 // update the screen and redraw the view
2162 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
2163 a3DView()->SetImmediateUpdate (isAutoUpdate);
2164 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
2165 || aToUpdate == ViewerTest_RM_RedrawForce)
2167 TheAISContext()->UpdateCurrentViewer();
2173 //==============================================================================
2175 //purpose : Erase some selected or named objects
2176 // if there is no selected or named objects, the whole viewer is erased
2177 //==============================================================================
2178 int VErase (Draw_Interpretor& theDI,
2179 Standard_Integer theArgNb,
2180 const char** theArgVec)
2182 if (a3DView().IsNull())
2184 std::cout << "Error: no active view!\n";
2187 TheAISContext()->CloseAllContexts (Standard_False);
2189 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
2190 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2192 Standard_Integer anArgIter = 1;
2193 for (; anArgIter < theArgNb; ++anArgIter)
2195 if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
2201 if (anArgIter < theArgNb)
2205 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2209 // has a list of names
2210 for (; anArgIter < theArgNb; ++anArgIter)
2212 TCollection_AsciiString aName = theArgVec[anArgIter];
2213 if (!GetMapOfAIS().IsBound2 (aName))
2218 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2219 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2220 theDI << aName.ToCString() << " ";
2223 TheAISContext()->Erase (anIO, Standard_False);
2227 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2228 if (!aNisIO.IsNull())
2230 TheNISContext()->Erase (aNisIO);
2235 else if (!toEraseAll
2236 && TheAISContext()->NbCurrents() > 0)
2238 // remove all currently selected objects
2239 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2240 anIter.More(); anIter.Next())
2242 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2244 && TheAISContext()->IsCurrent (anIO))
2246 theDI << anIter.Key2().ToCString() << " ";
2247 TheAISContext()->Erase (anIO, Standard_False);
2253 // erase entire viewer
2254 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2255 anIter.More(); anIter.Next())
2257 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2260 TheAISContext()->Erase (anIO, Standard_False);
2264 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2265 if (!aNisIO.IsNull())
2267 TheNISContext()->Erase (aNisIO);
2273 // update the screen and redraw the view
2274 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
2275 a3DView()->SetImmediateUpdate (isAutoUpdate);
2276 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
2277 || aToUpdate == ViewerTest_RM_RedrawForce)
2279 TheAISContext()->UpdateCurrentViewer();
2285 //==============================================================================
2286 //function : VDisplayAll
2288 //purpose : Display all the objects of the Map
2289 //==============================================================================
2290 static int VDisplayAll (Draw_Interpretor& ,
2291 Standard_Integer theArgNb,
2292 const char** theArgVec)
2295 if (a3DView().IsNull())
2297 std::cout << "Error: no active view!\n";
2301 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
2303 Standard_Integer anArgIter = 1;
2304 for (; anArgIter < theArgNb; ++anArgIter)
2306 if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
2311 if (anArgIter < theArgNb)
2313 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2317 if (TheAISContext()->HasOpenedContext())
2319 TheAISContext()->CloseLocalContext();
2322 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2323 anIter.More(); anIter.Next())
2325 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2327 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2328 TheAISContext()->Erase (aShape, Standard_False);
2330 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2332 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2333 TheNISContext()->Erase (aShape);
2337 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2338 anIter.More(); anIter.Next())
2340 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2342 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2343 TheAISContext()->Display (aShape, Standard_False);
2345 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2347 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2348 TheNISContext()->Display (aShape);
2352 // update the screen and redraw the view
2353 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
2354 a3DView()->SetImmediateUpdate (isAutoUpdate);
2355 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
2356 || aToUpdate == ViewerTest_RM_RedrawForce)
2358 TheAISContext()->UpdateCurrentViewer();
2364 //! Auxiliary method to find presentation
2365 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2366 const Handle(AIS_InteractiveObject)& theIO,
2367 const Standard_Integer theMode)
2371 return Handle(PrsMgr_Presentation)();
2376 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2378 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2381 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2383 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2385 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2387 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2389 return Handle(PrsMgr_Presentation)();
2392 enum ViewerTest_BndAction
2399 //! Auxiliary method to print bounding box of presentation
2400 inline void bndPresentation (Draw_Interpretor& theDI,
2401 const Handle(PrsMgr_Presentation)& thePrs,
2402 const TCollection_AsciiString& theName,
2403 const ViewerTest_BndAction theAction)
2407 case BndAction_Hide:
2409 thePrs->Presentation()->GraphicUnHighlight();
2412 case BndAction_Show:
2414 thePrs->Presentation()->BoundBox();
2417 case BndAction_Print:
2419 Graphic3d_Vec3d aMin, aMax;
2420 thePrs->Presentation()->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
2421 aMax.x(), aMax.y(), aMax.z());
2422 theDI << theName << "\n"
2423 << aMin.x() << " " << aMin.y() << " " << aMin.z() << " "
2424 << aMax.x() << " " << aMax.y() << " " << aMax.z() << "\n";
2430 //==============================================================================
2431 //function : VBounding
2433 //==============================================================================
2434 int VBounding (Draw_Interpretor& theDI,
2435 Standard_Integer theArgNb,
2436 const char** theArgVec)
2438 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2441 std::cout << "Error: no active view!\n";
2445 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
2446 ViewerTest_BndAction anAction = BndAction_Show;
2447 Standard_Integer aMode = -1;
2449 Standard_Integer anArgIter = 1;
2450 for (; anArgIter < theArgNb; ++anArgIter)
2452 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2454 if (anArg == "-print")
2456 anAction = BndAction_Print;
2458 else if (anArg == "-show")
2460 anAction = BndAction_Show;
2462 else if (anArg == "-hide")
2464 anAction = BndAction_Hide;
2466 else if (anArg == "-mode")
2468 if (++anArgIter >= theArgNb)
2470 std::cout << "Error: wrong syntax at " << anArg << "\n";
2473 aMode = Draw::Atoi (theArgVec[anArgIter]);
2475 else if (!parseRedrawMode (anArg, aToUpdate))
2481 if (anArgIter < theArgNb)
2483 // has a list of names
2484 for (; anArgIter < theArgNb; ++anArgIter)
2486 TCollection_AsciiString aName = theArgVec[anArgIter];
2487 if (!GetMapOfAIS().IsBound2 (aName))
2489 std::cout << "Error: presentation " << aName << " does not exist\n";
2493 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2494 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2497 std::cout << "Error: presentation " << aName << " does not exist\n";
2500 bndPresentation (theDI, aPrs, aName, anAction);
2503 else if (TheAISContext()->NbCurrents() > 0)
2505 // remove all currently selected objects
2506 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2508 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2509 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2512 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2519 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2520 anIter.More(); anIter.Next())
2522 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2523 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2526 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2531 // update the screen and redraw the view
2532 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
2533 a3DView()->SetImmediateUpdate (isAutoUpdate);
2534 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
2535 || aToUpdate == ViewerTest_RM_RedrawForce)
2537 TheAISContext()->UpdateCurrentViewer();
2543 //==============================================================================
2544 //function : VTexture
2546 //==============================================================================
2547 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2549 TCollection_AsciiString aCommandName (theArgv[0]);
2551 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
2552 if (aCommandName == "vtexture")
2556 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2557 std::cout << "Type help for more information.\n";
2561 // look for options of vtexture command
2562 TCollection_AsciiString aParseKey;
2563 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2565 TCollection_AsciiString anArg (theArgv [anArgIt]);
2568 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2571 aParseKey.Remove (1);
2572 aParseKey.UpperCase();
2573 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
2577 if (aParseKey.IsEmpty())
2582 aMapOfArgs(aParseKey)->Append (anArg);
2585 else if (aCommandName == "vtexscale"
2586 || aCommandName == "vtexorigin"
2587 || aCommandName == "vtexrepeat")
2589 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2590 // equal to -scale, -origin, -repeat options of vtexture command
2591 if (theArgsNb < 2 || theArgsNb > 4)
2593 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2594 std::cout << "Type help for more information.\n";
2598 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
2601 anArgs->Append ("OFF");
2603 else if (theArgsNb == 4)
2605 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2606 anArgs->Append (TCollection_AsciiString (theArgv[3]));
2609 TCollection_AsciiString anArgKey;
2610 if (aCommandName == "vtexscale")
2614 else if (aCommandName == "vtexorigin")
2616 anArgKey = "ORIGIN";
2620 anArgKey = "REPEAT";
2623 aMapOfArgs.Bind (anArgKey, anArgs);
2625 else if (aCommandName == "vtexdefault")
2627 // scan for parameters of vtexdefault command
2628 // equal to -default option of vtexture command
2629 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
2632 // Check arguments for validity
2633 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
2634 for (; aMapIt.More(); aMapIt.Next())
2636 const TCollection_AsciiString& aKey = aMapIt.Key();
2637 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
2639 // -scale, -origin, -repeat: one argument "off", or two real values
2640 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
2641 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2642 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
2647 // -modulate: single argument "on" / "off"
2648 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
2653 // -default: no arguments
2654 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
2659 TCollection_AsciiString aLowerKey;
2662 aLowerKey.LowerCase();
2663 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
2664 std::cout << "Type help for more information.\n";
2668 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
2669 if (anAISContext.IsNull())
2671 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
2675 Standard_Integer aPreviousMode = 0;
2677 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
2679 TCollection_AsciiString aShapeName (theArgv[1]);
2680 Handle(AIS_InteractiveObject) anIO;
2682 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
2683 if (aMapOfIO.IsBound2 (aShapeName))
2685 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
2690 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
2694 Handle(AIS_TexturedShape) aTexturedIO;
2695 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
2697 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
2698 aPreviousMode = aTexturedIO->DisplayMode();
2702 anAISContext->Clear (anIO, Standard_False);
2703 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
2704 GetMapOfAIS().UnBind1 (anIO);
2705 GetMapOfAIS().UnBind2 (aShapeName);
2706 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
2709 // -------------------------------------------
2710 // Turn texturing on/off - only for vtexture
2711 // -------------------------------------------
2713 if (aCommandName == "vtexture")
2715 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
2717 if (aTextureArg.IsEmpty())
2719 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
2720 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
2722 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
2723 if (aPreviousMode == 3)
2725 anAISContext->RecomputePrsOnly (aTexturedIO);
2728 anAISContext->Display (aTexturedIO, Standard_True);
2731 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
2733 if (aTextureArg == "?")
2735 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
2737 theDi << "\n Files in current directory : \n" << "\n";
2738 theDi.Eval ("glob -nocomplain *");
2740 TCollection_AsciiString aCmnd ("glob -nocomplain ");
2741 aCmnd += aTextureFolder;
2744 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
2745 theDi.Eval (aCmnd.ToCString());
2750 aTexturedIO->SetTextureFileName (aTextureArg);
2755 // ------------------------------------
2756 // Process other options and commands
2757 // ------------------------------------
2759 Handle(TColStd_HSequenceOfAsciiString) aValues;
2760 if (aMapOfArgs.Find ("DEFAULT", aValues))
2762 aTexturedIO->SetTextureRepeat (Standard_False);
2763 aTexturedIO->SetTextureOrigin (Standard_False);
2764 aTexturedIO->SetTextureScale (Standard_False);
2765 aTexturedIO->EnableTextureModulate();
2769 if (aMapOfArgs.Find ("SCALE", aValues))
2771 if (aValues->Value(1) != "OFF")
2773 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2777 aTexturedIO->SetTextureScale (Standard_False);
2781 if (aMapOfArgs.Find ("ORIGIN", aValues))
2783 if (aValues->Value(1) != "OFF")
2785 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2789 aTexturedIO->SetTextureOrigin (Standard_False);
2793 if (aMapOfArgs.Find ("REPEAT", aValues))
2795 if (aValues->Value(1) != "OFF")
2797 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2801 aTexturedIO->SetTextureRepeat (Standard_False);
2805 if (aMapOfArgs.Find ("MODULATE", aValues))
2807 if (aValues->Value(1) == "ON")
2809 aTexturedIO->EnableTextureModulate();
2813 aTexturedIO->DisableTextureModulate();
2818 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
2820 anAISContext->RecomputePrsOnly (aTexturedIO);
2824 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
2825 anAISContext->Display (aTexturedIO, Standard_True);
2826 anAISContext->Update (aTexturedIO,Standard_True);
2832 //==============================================================================
2833 //function : VDisplay2
2835 //purpose : Display an object from its name
2836 //==============================================================================
2837 static int VDisplay2 (Draw_Interpretor& theDI,
2838 Standard_Integer theArgNb,
2839 const char** theArgVec)
2843 std::cout << theArgVec[0] << "Error: wrong syntax!\n";
2846 else if (a3DView().IsNull())
2848 ViewerTest::ViewerInit();
2849 std::cout << "Command vinit should be called before!\n";
2853 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2854 if (aCtx->HasOpenedContext())
2856 aCtx->CloseLocalContext();
2859 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
2860 Standard_Integer isMutable = -1;
2861 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2863 const TCollection_AsciiString aName = theArgVec[anArgIter];
2864 TCollection_AsciiString aNameCase = aName;
2865 aNameCase.LowerCase();
2866 if (parseRedrawMode (aName, aToUpdate))
2870 else if (aNameCase == "-mutable")
2875 else if (!GetMapOfAIS().IsBound2 (aName))
2877 // create the AIS_Shape from a name
2878 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
2879 if (!aShape.IsNull())
2881 if (isMutable != -1)
2883 aShape->SetMutable (isMutable == 1);
2885 GetMapOfAIS().Bind (aShape, aName);
2886 aCtx->Display (aShape, Standard_False);
2891 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2892 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
2894 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2895 if (isMutable != -1)
2897 aShape->SetMutable (isMutable == 1);
2900 if (aShape->Type() == AIS_KOI_Datum)
2902 aCtx->Display (aShape, Standard_False);
2906 theDI << "Display " << aName.ToCString() << "\n";
2907 // get the Shape from a name
2908 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
2910 // update the Shape in the AIS_Shape
2911 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
2912 if (!aShapePrs.IsNull())
2914 aShapePrs->Set (aNewShape);
2916 aCtx->Redisplay (aShape, Standard_False);
2917 aCtx->Display (aShape, Standard_False);
2920 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
2922 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2923 TheNISContext()->Display (aShape);
2927 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
2928 a3DView()->SetImmediateUpdate (isAutoUpdate);
2929 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
2930 || aToUpdate == ViewerTest_RM_RedrawForce)
2932 // update the screen and redraw the view
2933 aCtx->UpdateCurrentViewer();
2938 //===============================================================================================
2939 //function : VUpdate
2941 //===============================================================================================
2942 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2944 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2945 if (aContextAIS.IsNull())
2947 std::cout << theArgVec[0] << "AIS context is not available.\n";
2953 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
2957 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
2959 AIS_ListOfInteractive aListOfIO;
2961 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2963 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
2965 Handle(AIS_InteractiveObject) anAISObj;
2966 if (anAISMap.IsBound2 (aName))
2968 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
2971 if (anAISObj.IsNull())
2973 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
2977 aListOfIO.Append (anAISObj);
2980 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
2981 for (; anIOIt.More(); anIOIt.Next())
2983 aContextAIS->Update (anIOIt.Value(), Standard_False);
2986 aContextAIS->UpdateCurrentViewer();
2991 //==============================================================================
2993 //purpose : Test the annimation of an object along a
2994 // predifined trajectory
2995 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2996 //==============================================================================
2998 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3001 if (TheAISContext()->HasOpenedContext())
3002 TheAISContext()->CloseLocalContext();
3004 Standard_Real Step=4*M_PI/180;
3005 Standard_Real Angle=0;
3007 Handle(AIS_InteractiveObject) aIO;
3008 if (GetMapOfAIS().IsBound2(argv[1]))
3009 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3013 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3017 if (Draw::Atoi(argv[3])==1 ) {
3018 di<<" Primitives sensibles OFF"<<"\n";
3019 TheAISContext()->Deactivate(aIO);
3022 di<<" Primitives sensibles ON"<<"\n";
3024 // Movement par transformation
3025 if(Draw::Atoi(argv[2]) ==1) {
3026 di<<" Calcul par Transformation"<<"\n";
3027 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3031 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3032 TheAISContext()->SetLocation(aShape,myTransfo);
3033 TheAISContext() ->UpdateCurrentViewer();
3038 di<<" Calcul par Locations"<<"\n";
3039 gp_Trsf myAngleTrsf;
3040 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3041 TopLoc_Location myDeltaAngle (myAngleTrsf);
3042 TopLoc_Location myTrueLoc;
3044 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3047 myTrueLoc=myTrueLoc*myDeltaAngle;
3048 TheAISContext()->SetLocation(aShape,myTrueLoc );
3049 TheAISContext() ->UpdateCurrentViewer();
3052 if (Draw::Atoi(argv[3])==1 ){
3053 // On reactive la selection des primitives sensibles
3054 TheAISContext()->Activate(aIO,0);
3056 a3DView() -> Redraw();
3058 di<<" Temps ecoule "<<"\n";
3064 //==================================================================================
3065 // Function : VAnimation
3066 //==================================================================================
3067 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3069 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
3073 Standard_Real thread = 4;
3074 Standard_Real angleA=0;
3075 Standard_Real angleB;
3077 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3080 TopoDS_Shape CrankArm;
3081 TopoDS_Shape CylinderHead;
3082 TopoDS_Shape Propeller;
3083 TopoDS_Shape EngineBlock;
3085 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3086 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3087 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3088 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3089 BRepTools::Read(CrankArm,argv[1],B);
3090 BRepTools::Read(CylinderHead,argv[2],B);
3091 BRepTools::Read(Propeller,argv[3],B);
3092 BRepTools::Read(EngineBlock,argv[4],B);
3094 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
3100 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3101 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3102 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3103 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3105 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3106 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3107 GetMapOfAIS().Bind(myAisCrankArm,"c");
3108 GetMapOfAIS().Bind(myAisPropeller,"d");
3110 myAisCylinderHead->SetMutable (Standard_True);
3111 myAisEngineBlock ->SetMutable (Standard_True);
3112 myAisCrankArm ->SetMutable (Standard_True);
3113 myAisPropeller ->SetMutable (Standard_True);
3115 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3116 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3117 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3119 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3120 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3121 TheAISContext()->Display (myAisCrankArm, Standard_False);
3122 TheAISContext()->Display (myAisPropeller, Standard_False);
3124 TheAISContext()->Deactivate(myAisCylinderHead);
3125 TheAISContext()->Deactivate(myAisEngineBlock );
3126 TheAISContext()->Deactivate(myAisCrankArm );
3127 TheAISContext()->Deactivate(myAisPropeller );
3129 // Boucle de mouvement
3130 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3132 angleA = thread*myAngle*M_PI/180;
3133 X = Sin(angleA)*3/8;
3134 angleB = atan(X / Sqrt(-X * X + 1));
3135 Standard_Real decal(25*0.6);
3138 //Build a transformation on the display
3139 gp_Trsf aPropellerTrsf;
3140 aPropellerTrsf.SetRotation(Ax1,angleA);
3141 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3143 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));
3144 gp_Trsf aCrankArmTrsf;
3145 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3146 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3148 TheAISContext()->UpdateCurrentViewer();
3151 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3152 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3154 myAisCrankArm ->ResetTransformation();
3155 myAisPropeller->ResetTransformation();
3157 myAisCrankArm -> Set(myNewCrankArm );
3158 myAisPropeller -> Set(myNewPropeller);
3160 TheAISContext()->Activate(myAisCylinderHead,0);
3161 TheAISContext()->Activate(myAisEngineBlock,0 );
3162 TheAISContext()->Activate(myAisCrankArm ,0 );
3163 TheAISContext()->Activate(myAisPropeller ,0 );
3169 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3170 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3172 TheAISContext()->UpdateCurrentViewer();
3173 a3DView()->Redraw();
3182 //==============================================================================
3183 //function : VShading
3184 //purpose : Sharpen or roughten the quality of the shading
3185 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3186 //==============================================================================
3187 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3189 Standard_Real myDevCoef;
3190 Handle(AIS_InteractiveObject) TheAisIO;
3193 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3195 if (TheAISContext()->HasOpenedContext())
3196 TheAISContext()->CloseLocalContext();
3201 myDevCoef =Draw::Atof(argv[2]);
3204 TCollection_AsciiString name=argv[1];
3205 if (GetMapOfAIS().IsBound2(name ))
3206 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3207 if (TheAisIO.IsNull())
3208 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3211 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
3213 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3215 TheAISContext()->Redisplay(TheAisIO);
3218 //==============================================================================
3219 //function : HaveMode
3220 //use : VActivatedModes
3221 //==============================================================================
3222 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3224 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3226 TColStd_ListOfInteger List;
3227 TheAISContext()->ActivatedModes (TheAisIO,List);
3228 TColStd_ListIteratorOfListOfInteger it;
3229 Standard_Boolean Found=Standard_False;
3230 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3231 if (it.Value()==mode ) Found=Standard_True;
3238 //==============================================================================
3239 //function : VActivatedMode
3241 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
3242 // (edges,vertex...)qui lui est propre et le mode de selection standard.
3243 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3244 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3245 // qu'un nom et qu'un mode.
3246 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
3247 //==============================================================================
3248 #include <AIS_ListIteratorOfListOfInteractive.hxx>
3250 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3253 Standard_Boolean ThereIsName = Standard_False ;
3255 if(!a3DView().IsNull()){
3257 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
3258 // verification des arguments
3260 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
3261 ThereIsName = (argc == 3);
3265 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3267 di<<" R.A.Z de tous les modes de selecion"<<"\n";
3268 di<<" Fermeture du Context local"<<"\n";
3269 if (TheAISContext()->HasOpenedContext())
3270 TheAISContext()->CloseLocalContext();
3274 // IL n'y a aps de nom de shape passe en argument
3275 if (HaveToSet && !ThereIsName){
3276 Standard_Integer aMode=Draw::Atoi(argv [1]);
3278 const char *cmode="???";
3280 case 0: cmode = "Shape"; break;
3281 case 1: cmode = "Vertex"; break;
3282 case 2: cmode = "Edge"; break;
3283 case 3: cmode = "Wire"; break;
3284 case 4: cmode = "Face"; break;
3285 case 5: cmode = "Shell"; break;
3286 case 6: cmode = "Solid"; break;
3287 case 7: cmode = "Compound"; break;
3290 if( !TheAISContext()->HasOpenedContext() ) {
3291 // il n'y a pas de Context local d'ouvert
3292 // on en ouvre un et on charge toutes les shapes displayees
3293 // on load tous les objets displayees et on Activate les objets de la liste
3294 AIS_ListOfInteractive ListOfIO;
3295 // on sauve dans une AISListOfInteractive tous les objets currents
3296 if (TheAISContext()->NbCurrents()>0 ){
3297 TheAISContext()->UnhilightCurrents(Standard_False);
3299 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3300 ListOfIO.Append(TheAISContext()->Current() );
3304 TheAISContext()->OpenLocalContext(Standard_False);
3305 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3308 Handle(AIS_InteractiveObject) aIO =
3309 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3311 TheAISContext()->Load(aIO,0,Standard_False);
3314 // traitement des objets qui etaient currents dans le Contexte global
3315 if (!ListOfIO.IsEmpty() ) {
3316 // il y avait des objets currents
3317 AIS_ListIteratorOfListOfInteractive iter;
3318 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3319 Handle(AIS_InteractiveObject) aIO=iter.Value();
3320 TheAISContext()->Activate(aIO,aMode);
3321 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3325 // On applique le mode a tous les objets displayes
3326 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3327 it2 (GetMapOfAIS());
3329 Handle(AIS_InteractiveObject) aIO =
3330 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
3331 if (!aIO.IsNull()) {
3332 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
3333 TheAISContext()->Activate(aIO,aMode);
3342 // un Context local est deja ouvert
3343 // Traitement des objets du Context local
3344 if (TheAISContext()->NbSelected()>0 ){
3345 TheAISContext()->UnhilightSelected(Standard_False);
3346 // il y a des objets selected,on les parcourt
3347 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
3348 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
3351 if (HaveMode(aIO,aMode) ) {
3352 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3353 TheAISContext()->Deactivate(aIO,aMode);
3356 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3357 TheAISContext()->Activate(aIO,aMode);
3363 // il n'y a pas d'objets selected
3364 // tous les objets diplayes sont traites
3365 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3368 Handle(AIS_InteractiveObject) aIO =
3369 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3370 if (!aIO.IsNull()) {
3371 if (HaveMode(aIO,aMode) ) {
3372 di<<" Mode: "<<cmode<<" OFF pour "
3373 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3374 TheAISContext()->Deactivate(aIO,aMode);
3377 di<<" Mode: "<<cmode<<" ON pour"
3378 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3379 TheAISContext()->Activate(aIO,aMode);
3387 else if (HaveToSet && ThereIsName){
3388 Standard_Integer aMode=Draw::Atoi(argv [2]);
3389 Handle(AIS_InteractiveObject) aIO =
3390 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3392 if (!aIO.IsNull()) {
3393 const char *cmode="???";
3396 case 0: cmode = "Shape"; break;
3397 case 1: cmode = "Vertex"; break;
3398 case 2: cmode = "Edge"; break;
3399 case 3: cmode = "Wire"; break;
3400 case 4: cmode = "Face"; break;
3401 case 5: cmode = "Shell"; break;
3402 case 6: cmode = "Solid"; break;
3403 case 7: cmode = "Compound"; break;
3406 if( !TheAISContext()->HasOpenedContext() ) {
3407 TheAISContext()->OpenLocalContext(Standard_False);
3408 // On charge tous les objets de la map
3409 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
3411 Handle(AIS_InteractiveObject) aShape=
3412 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3413 if (!aShape.IsNull())
3414 TheAISContext()->Load(aShape,0,Standard_False);
3417 TheAISContext()->Activate(aIO,aMode);
3418 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3422 // un Context local est deja ouvert
3423 if (HaveMode(aIO,aMode) ) {
3424 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
3425 TheAISContext()->Deactivate(aIO,aMode);
3428 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3429 TheAISContext()->Activate(aIO,aMode);
3438 //! Auxiliary method to print Interactive Object information
3439 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
3440 const Handle(Standard_Transient)& theObject,
3441 Draw_Interpretor& theDI)
3443 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
3446 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
3450 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
3451 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
3452 << (theDetected.Contains (anObj) ? " Detected" : " ")
3454 if (anObj->Type() == AIS_KOI_Datum)
3457 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
3458 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
3459 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
3460 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
3461 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
3462 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
3463 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
3466 else if (anObj->Type() == AIS_KOI_Shape
3467 && anObj->Signature() == 0)
3469 theDI << " AIS_Shape";
3471 else if (anObj->Type() == AIS_KOI_Relation)
3473 // AIS_Dimention and AIS_Relation
3474 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
3475 switch (aRelation->KindOfDimension())
3477 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
3478 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
3479 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
3480 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
3481 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
3482 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
3483 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
3484 default: theDI << " UNKNOWN dimension"; break;
3489 theDI << " UserPrs";
3491 theDI << " (" << theObject->DynamicType()->Name() << ")";
3494 //! Print information about locally selected sub-shapes
3495 static void localCtxInfo (Draw_Interpretor& theDI)
3497 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3498 if (!aCtx->HasOpenedContext())
3503 TCollection_AsciiString aPrevName;
3504 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
3505 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
3507 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
3508 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
3509 if (aSubShape.IsNull()
3510 || aShapeIO.IsNull()
3511 || !GetMapOfAIS().IsBound1 (aShapeIO))
3516 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
3517 TopTools_MapOfShape aFilter;
3518 Standard_Integer aNumber = 0;
3519 const TopoDS_Shape aShape = aShapeIO->Shape();
3520 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
3521 anIter.More(); anIter.Next())
3523 if (!aFilter.Add (anIter.Current()))
3525 continue; // filter duplicates
3529 if (!anIter.Current().IsSame (aSubShape))
3534 Standard_CString aShapeName = NULL;
3535 switch (aSubShape.ShapeType())
3537 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
3538 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
3539 case TopAbs_SOLID: aShapeName = " Solid"; break;
3540 case TopAbs_SHELL: aShapeName = " Shell"; break;
3541 case TopAbs_FACE: aShapeName = " Face"; break;
3542 case TopAbs_WIRE: aShapeName = " Wire"; break;
3543 case TopAbs_EDGE: aShapeName = " Edge"; break;
3544 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
3546 case TopAbs_SHAPE: aShapeName = " Shape"; break;
3549 if (aParentName != aPrevName)
3551 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
3552 aPrevName = aParentName;
3554 theDI << " " << aShapeName << " #" << aNumber << "\n";
3560 //==============================================================================
3563 //Draw arg : vstate [nameA] ... [nameN]
3564 //==============================================================================
3565 static Standard_Integer VState (Draw_Interpretor& theDI,
3566 Standard_Integer theArgNb,
3567 Standard_CString* theArgVec)
3569 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3572 std::cerr << "Error: No opened viewer!\n";
3576 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
3577 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
3579 aDetected.Add (aCtx->DetectedCurrentObject());
3582 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
3586 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3588 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
3589 if (!GetMapOfAIS().IsBound2 (anObjName))
3591 theDI << anObjName << " doesn't exist!\n";
3595 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
3596 TCollection_AsciiString aName = anObjName;
3597 aName.LeftJustify (20, ' ');
3598 theDI << " " << aName << " ";
3599 objInfo (aDetected, anObjTrans, theDI);
3605 if (aCtx->NbCurrents() > 0
3608 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
3610 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
3611 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
3612 aName.LeftJustify (20, ' ');
3613 theDI << aName << " ";
3614 objInfo (aDetected, anObj, theDI);
3620 theDI << "Neutral-point state:\n";
3621 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
3622 anObjIter.More(); anObjIter.Next())
3624 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
3630 TCollection_AsciiString aName = anObjIter.Key2();
3631 aName.LeftJustify (20, ' ');
3632 theDI << " " << aName << " ";
3633 objInfo (aDetected, anObj, theDI);
3636 localCtxInfo (theDI);
3640 //=======================================================================
3641 //function : PickObjects
3643 //=======================================================================
3644 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
3645 const AIS_KindOfInteractive TheType,
3646 const Standard_Integer TheSignature,
3647 const Standard_Integer MaxPick)
3649 Handle(AIS_InteractiveObject) IO;
3650 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3652 // step 1: prepare the data
3654 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3655 TheAISContext()->AddFilter(F1);
3658 // step 2 : wait for the selection...
3659 // Standard_Boolean IsGood (Standard_False);
3660 // Standard_Integer NbPick(0);
3661 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
3662 Standard_Integer NbPickFail(0);
3663 Standard_Integer argccc = 5;
3664 const char *bufff[] = { "A", "B", "C","D", "E" };
3665 const char **argvvv = (const char **) bufff;
3668 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3669 while(ViewerMainLoop(argccc,argvvv)){}
3670 Standard_Integer NbStored = TheAISContext()->NbSelected();
3671 if((unsigned int ) NbStored != NbPickGood)
3672 NbPickGood= NbStored;
3675 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
3678 // step3 get result.
3680 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3682 Standard_Integer i(0);
3683 for(TheAISContext()->InitSelected();
3684 TheAISContext()->MoreSelected();
3685 TheAISContext()->NextSelected()){
3687 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
3688 arr->SetValue(i,IO2);
3693 TheAISContext()->CloseLocalContext(curindex);
3695 return Standard_True;
3699 //=======================================================================
3700 //function : PickObject
3702 //=======================================================================
3703 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
3704 const Standard_Integer TheSignature,
3705 const Standard_Integer MaxPick)
3707 Handle(AIS_InteractiveObject) IO;
3708 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3710 // step 1: prepare the data
3713 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3714 TheAISContext()->AddFilter(F1);
3717 // step 2 : wait for the selection...
3718 Standard_Boolean IsGood (Standard_False);
3719 Standard_Integer NbPick(0);
3720 Standard_Integer argccc = 5;
3721 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3722 const char **argvvv = (const char **) bufff;
3725 while(!IsGood && NbPick<= MaxPick){
3726 while(ViewerMainLoop(argccc,argvvv)){}
3727 IsGood = (TheAISContext()->NbSelected()>0) ;
3729 cout<<"Nb Pick :"<<NbPick<<endl;
3733 // step3 get result.
3735 TheAISContext()->InitSelected();
3736 IO = TheAISContext()->SelectedInteractive();
3740 TheAISContext()->CloseLocalContext(curindex);
3744 //=======================================================================
3745 //function : PickShape
3746 //purpose : First Activate the rightmode + Put Filters to be able to
3747 // pick objets that are of type <TheType>...
3748 //=======================================================================
3750 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
3751 const Standard_Integer MaxPick)
3754 // step 1: prepare the data
3756 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3757 TopoDS_Shape result;
3759 if(TheType==TopAbs_SHAPE){
3760 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3761 TheAISContext()->AddFilter(F1);
3764 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3765 TheAISContext()->AddFilter(TF);
3766 TheAISContext()->ActivateStandardMode(TheType);
3771 // step 2 : wait for the selection...
3772 Standard_Boolean NoShape (Standard_True);
3773 Standard_Integer NbPick(0);
3774 Standard_Integer argccc = 5;
3775 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3776 const char **argvvv = (const char **) bufff;
3779 while(NoShape && NbPick<= MaxPick){
3780 while(ViewerMainLoop(argccc,argvvv)){}
3781 NoShape = (TheAISContext()->NbSelected()==0) ;
3783 cout<<"Nb Pick :"<<NbPick<<endl;
3786 // step3 get result.
3790 TheAISContext()->InitSelected();
3791 if(TheAISContext()->HasSelectedShape())
3792 result = TheAISContext()->SelectedShape();
3794 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3795 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
3800 TheAISContext()->CloseLocalContext(curindex);
3806 //=======================================================================
3807 //function : PickShapes
3809 //=======================================================================
3810 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
3811 Handle(TopTools_HArray1OfShape)& thearr,
3812 const Standard_Integer MaxPick)
3815 Standard_Integer Taille = thearr->Length();
3817 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
3819 // step 1: prepare the data
3820 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3821 if(TheType==TopAbs_SHAPE){
3822 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3823 TheAISContext()->AddFilter(F1);
3826 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3827 TheAISContext()->AddFilter(TF);
3828 TheAISContext()->ActivateStandardMode(TheType);
3832 // step 2 : wait for the selection...
3834 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
3835 Standard_Integer NbPickFail(0);
3836 Standard_Integer argccc = 5;
3837 const char *bufff[] = { "A", "B", "C","D", "E" };
3838 const char **argvvv = (const char **) bufff;
3841 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3842 while(ViewerMainLoop(argccc,argvvv)){}
3843 Standard_Integer NbStored = TheAISContext()->NbSelected();
3844 if((unsigned int ) NbStored != NbPickGood)
3845 NbPickGood= NbStored;
3848 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
3851 // step3 get result.
3853 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3855 Standard_Integer i(0);
3856 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
3858 if(TheAISContext()->HasSelectedShape())
3859 thearr->SetValue(i,TheAISContext()->SelectedShape());
3861 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3862 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
3866 TheAISContext()->CloseLocalContext(curindex);
3867 return Standard_True;
3871 //=======================================================================
3872 //function : VPickShape
3874 //=======================================================================
3875 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3877 TopoDS_Shape PickSh;
3878 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
3881 theType = TopAbs_SHAPE;
3883 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
3884 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
3885 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
3886 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
3887 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
3888 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
3889 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
3892 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
3893 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
3895 TCollection_AsciiString name;
3898 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3900 PickSh = ViewerTest::PickShape(theType);
3909 if(!PickSh.IsNull()){
3910 nbOfSub[Standard_Integer(theType)]++;
3912 name += nameType[Standard_Integer(theType)];
3913 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3918 // si on avait une petite methode pour voir si la shape
3919 // est deja dans la Double map, ca eviterait de creer....
3920 DBRep::Set(name.ToCString(),PickSh);
3922 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3923 GetMapOfAIS().Bind(newsh, name);
3924 TheAISContext()->Display(newsh);
3925 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
3928 // Plusieurs objets a picker, vite vite vite....
3931 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3932 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3933 if(ViewerTest::PickShapes(theType,arr)){
3934 for(Standard_Integer i=1;i<=NbToPick;i++){
3935 PickSh = arr->Value(i);
3936 if(!PickSh.IsNull()){
3938 nbOfSub[Standard_Integer(theType)]++;
3941 name += nameType[Standard_Integer(theType)];
3942 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3950 DBRep::Set(name.ToCString(),PickSh);
3951 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3952 GetMapOfAIS().Bind(newsh, name);
3953 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3954 TheAISContext()->Display(newsh);
3962 //=======================================================================
3963 //function : list of known objects
3965 //=======================================================================
3966 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3968 // 1234567890 12345678901234567 123456789
3969 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3970 TCollection_AsciiString BlankLine(64,'_');
3971 Standard_Integer i ;
3973 di<<"/n"<<BlankLine.ToCString()<<"\n";
3976 Colum[i].Center(20,' ');
3978 di<<"|"<<Colum[i].ToCString();
3981 di<<BlankLine.ToCString()<<"\n";
3983 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3984 const char ** names = GetTypeNames();
3986 TCollection_AsciiString curstring;
3987 TCollection_AsciiString curcolum[3];
3990 // les objets de type Datum..
3991 curcolum[1]+="Datum";
3993 curcolum[0].Clear();
3994 curcolum[0] += names[i];
3996 curcolum[2].Clear();
3997 curcolum[2]+=TCollection_AsciiString(i+1);
3999 for(Standard_Integer j =0;j<=2;j++){
4000 curcolum[j].Center(20,' ');
4001 di<<"|"<<curcolum[j].ToCString();
4005 di<<BlankLine.ToCString()<<"\n";
4007 // les objets de type shape
4008 curcolum[1].Clear();
4009 curcolum[1]+="Shape";
4010 curcolum[1].Center(20,' ');
4013 curcolum[0].Clear();
4014 curcolum[0] += names[7+i];
4015 curcolum[2].Clear();
4016 curcolum[2]+=TCollection_AsciiString(i);
4018 for(Standard_Integer j =0;j<=2;j++){
4019 curcolum[j].Center(20,' ');
4020 di<<"|"<<curcolum[j].ToCString();
4024 di<<BlankLine.ToCString()<<"\n";
4025 // les IO de type objet...
4026 curcolum[1].Clear();
4027 curcolum[1]+="Object";
4028 curcolum[1].Center(20,' ');
4030 curcolum[0].Clear();
4031 curcolum[0] += names[10+i];
4032 curcolum[2].Clear();
4033 curcolum[2]+=TCollection_AsciiString(i);
4035 for(Standard_Integer j =0;j<=2;j++){
4036 curcolum[j].Center(20,' ');
4037 di<<"|"<<curcolum[j].ToCString();
4041 di<<BlankLine.ToCString()<<"\n";
4042 // les contraintes et dimensions.
4043 // pour l'instant on separe juste contraintes et dimensions...
4044 // plus tard, on detaillera toutes les sortes...
4045 curcolum[1].Clear();
4046 curcolum[1]+="Relation";
4047 curcolum[1].Center(20,' ');
4049 curcolum[0].Clear();
4050 curcolum[0] += names[12+i];
4051 curcolum[2].Clear();
4052 curcolum[2]+=TCollection_AsciiString(i);
4054 for(Standard_Integer j =0;j<=2;j++){
4055 curcolum[j].Center(20,' ');
4056 di<<"|"<<curcolum[j].ToCString();
4060 di<<BlankLine.ToCString()<<"\n";
4067 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
4069 if(argc!=2) return 1;
4071 AIS_KindOfInteractive TheType;
4072 Standard_Integer TheSign(-1);
4073 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4076 AIS_ListOfInteractive LIO;
4078 // en attendant l'amelioration ais pour les dimensions...
4080 Standard_Integer dimension_status(-1);
4081 if(TheType==AIS_KOI_Relation){
4082 dimension_status = TheSign ==1 ? 1 : 0;
4086 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
4087 Handle(AIS_InteractiveObject) curio;
4088 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4091 if(dimension_status == -1)
4092 TheAISContext()->Erase(curio,Standard_False);
4094 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4095 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4096 (dimension_status==1 && KOD != AIS_KOD_NONE))
4097 TheAISContext()->Erase(curio,Standard_False);
4100 TheAISContext()->UpdateCurrentViewer();
4103 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4105 if(argc!=2) return 1;
4107 AIS_KindOfInteractive TheType;
4108 Standard_Integer TheSign(-1);
4109 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4111 // en attendant l'amelioration ais pour les dimensions...
4113 Standard_Integer dimension_status(-1);
4114 if(TheType==AIS_KOI_Relation){
4115 dimension_status = TheSign ==1 ? 1 : 0;
4119 AIS_ListOfInteractive LIO;
4120 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
4121 Handle(AIS_InteractiveObject) curio;
4122 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4124 if(dimension_status == -1)
4125 TheAISContext()->Display(curio,Standard_False);
4127 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4128 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4129 (dimension_status==1 && KOD != AIS_KOD_NONE))
4130 TheAISContext()->Display(curio,Standard_False);
4135 TheAISContext()->UpdateCurrentViewer();
4139 //==============================================================================
4140 //function : VSetTransMode
4142 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
4143 //==============================================================================
4145 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4146 // Verification des arguments
4147 if ( a3DView().IsNull() ) {
4148 ViewerTest::ViewerInit();
4149 di << "La commande vinit n'a pas ete appele avant" << "\n";
4152 if ( argc < 3 || argc > 8 ) {
4153 di << argv[0] << " Invalid number of arguments" << "\n";
4157 TCollection_AsciiString shapeName;
4158 shapeName = argv[1];
4159 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
4160 Standard_Integer persFlag2 = 0;
4161 Standard_Integer persFlag3 = 0;
4162 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
4163 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
4164 persFlag2 = Draw::Atoi(argv[3]);
4166 if ( argc == 5 || argc == 8 ) {
4167 persFlag3 = Draw::Atoi(argv[4]);
4170 origin.SetX( Draw::Atof(argv[argc - 3]) );
4171 origin.SetY( Draw::Atof(argv[argc - 2]) );
4172 origin.SetZ( Draw::Atof(argv[argc - 1]) );
4175 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
4176 Handle(Standard_Transient) anObj;
4178 anObj = GetMapOfAIS().Find2(shapeName);
4179 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
4180 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
4181 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4182 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
4183 di << argv[0] << " All persistence modifiers were removed" << "\n";
4186 di << argv[0] << " Wrong object type" << "\n";
4189 } else { // Create the AIS_Shape from a name
4190 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
4191 if ( !aShape.IsNull() ) {
4192 GetMapOfAIS().Bind( aShape, shapeName );
4193 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4194 TheAISContext()->Display( aShape, Standard_False );
4196 di << argv[0] << " Object not found" << "\n";
4201 // Upadate the screen and redraw the view
4202 TheAISContext()->UpdateCurrentViewer();
4206 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
4209 BRep_Builder builder;
4211 BRepTools::Read(shape, s, builder);
4212 DBRep::Set(a[1], shape);
4213 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4214 Handle(AIS_Shape) ais = new AIS_Shape(shape);
4219 //==============================================================================
4220 //function : ViewerTest::Commands
4221 //purpose : Add all the viewer command in the Draw_Interpretor
4222 //==============================================================================
4224 void ViewerTest::Commands(Draw_Interpretor& theCommands)
4226 ViewerTest::ViewerCommands(theCommands);
4227 ViewerTest::RelationCommands(theCommands);
4228 ViewerTest::ObjectCommands(theCommands);
4229 ViewerTest::FilletCommands(theCommands);
4230 ViewerTest::VoxelCommands(theCommands);
4231 ViewerTest::OpenGlCommands(theCommands);
4233 const char *group = "AIS_Display";
4236 theCommands.Add("visos",
4237 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
4238 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
4239 __FILE__, visos, group);
4241 theCommands.Add("vdisplay",
4242 "vdisplay [-noupdate|-update] [-mutable] name1 [name2] ... [name n]"
4243 "\n\t\t: Displays named objects."
4244 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4245 "\n\t\t: Option -mutable enables optimizations for mutable objects."
4246 __FILE__,VDisplay2,group);
4248 theCommands.Add ("vupdate",
4249 "vupdate name1 [name2] ... [name n]"
4250 "\n\t\t: Updates named objects in interactive context",
4251 __FILE__, VUpdate, group);
4253 theCommands.Add("verase",
4254 "verase [-noupdate|-update] [name1] ... [name n]"
4255 "\n\t\t: Erases selected or named objects."
4256 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
4257 __FILE__, VErase, group);
4259 theCommands.Add("vremove",
4260 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
4261 "or vremove [-context] -all to remove all objects"
4262 "\n\t\t: Removes selected or named objects."
4263 "\n\t\t If -context is in arguments, the objects are not deleted"
4264 "\n\t\t from the map of objects and names."
4265 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4266 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
4267 __FILE__, VRemove, group);
4269 theCommands.Add("vdonly",
4270 "vdonly [-noupdate|-update] [name1] ... [name n]"
4271 "\n\t\t: Displays only selected or named objects",
4272 __FILE__,VDonly2,group);
4274 theCommands.Add("vdisplayall",
4275 "Displays all erased interactive objects (see vdir and vstate)",
4276 __FILE__,VDisplayAll,group);
4278 theCommands.Add("veraseall",
4279 "Erases all objects displayed in the viewer",
4280 __FILE__, VErase, group);
4282 theCommands.Add("verasetype",
4284 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
4285 __FILE__,VEraseType,group);
4287 theCommands.Add("vbounding",
4288 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
4289 "\n\t\t: [-print] [-hide]"
4290 "\n\t\t: Temporarily display bounding box of specified Interactive"
4291 "\n\t\t: Objects, or print it to console if -print is specified."
4292 "\n\t\t: Already displayed box might be hidden by -hide option.",
4293 __FILE__,VBounding,group);
4295 theCommands.Add("vdisplaytype",
4296 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
4297 __FILE__,VDisplayType,group);
4299 theCommands.Add("vdisplaymode",
4300 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
4301 __FILE__,VDispMode,group);
4303 theCommands.Add("verasemode",
4304 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
4305 __FILE__,VDispMode,group);
4307 theCommands.Add("vsetdispmode",
4308 "vsetdispmode [name] mode(1,2,..)"
4309 "\n\t\t: Sets display mode for all, selected or named objects.",
4310 __FILE__,VDispMode,group);
4312 theCommands.Add("vunsetdispmode",
4313 "vunsetdispmode [name]"
4314 "\n\t\t: Unsets custom display mode for selected or named objects.",
4315 __FILE__,VDispMode,group);
4317 theCommands.Add("vdir",
4318 "Lists all objects displayed in 3D viewer",
4319 __FILE__,VDir,group);
4321 theCommands.Add("vdump",
4322 #ifdef HAVE_FREEIMAGE
4323 "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4324 "\n\t\t: [width Width=0 height Height=0]"
4325 "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
4327 "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4328 "\n\t\t: [width Width=0 height Height=0]"
4329 "\n\t\t: Dumps content of the active view into PPM image file",
4331 __FILE__,VDump,group);
4333 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
4334 __FILE__,VSubInt,group);
4336 theCommands.Add("vaspects",
4337 "vaspects [-noupdate|-update] [name1 [name2 [...]]]"
4338 "\n\t\t: [-setcolor ColorName] [-unsetcolor]"
4339 "\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
4340 "\n\t\t: [-settransparency Transp] [-unsettransparency]"
4341 "\n\t\t: [-setwidth LineWidth] [-unsetwidth]"
4342 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
4343 "\n\t\t: Manage presentation properties of all, selected or named objects."
4344 "\n\t\t: When -subshapes is specified than following properties will be"
4345 "\n\t\t: assigned to specified sub-shapes.",
4346 __FILE__,VAspects,group);
4348 theCommands.Add("vsetcolor",
4349 "vsetcolor [-noupdate|-update] [name] ColorName"
4350 "\n\t\t: Sets color for all, selected or named objects."
4351 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
4352 __FILE__,VAspects,group);
4354 theCommands.Add("vunsetcolor",
4355 "vunsetcolor [-noupdate|-update] [name]"
4356 "\n\t\t: Resets color for all, selected or named objects."
4357 "\n\t\t: Alias for vaspects -unsetcolor [name].",
4358 __FILE__,VAspects,group);
4360 theCommands.Add("vsettransparency",
4361 "vsettransparency [-noupdate|-update] [name] Coefficient"
4362 "\n\t\t: Sets transparency for all, selected or named objects."
4363 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
4364 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
4365 __FILE__,VAspects,group);
4367 theCommands.Add("vunsettransparency",
4368 "vunsettransparency [-noupdate|-update] [name]"
4369 "\n\t\t: Resets transparency for all, selected or named objects."
4370 "\n\t\t: Alias for vaspects -unsettransp [name].",
4371 __FILE__,VAspects,group);
4373 theCommands.Add("vsetmaterial",
4374 "vsetmaterial [-noupdate|-update] [name] MaterialName"
4375 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
4376 __FILE__,VAspects,group);
4378 theCommands.Add("vunsetmaterial",
4379 "vunsetmaterial [-noupdate|-update] [name]"
4380 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
4381 __FILE__,VAspects,group);
4383 theCommands.Add("vsetwidth",
4384 "vsetwidth [-noupdate|-update] [name] width(0->10)"
4385 "\n\t\t: Alias for vaspects -setwidth [name] width.",
4386 __FILE__,VAspects,group);
4388 theCommands.Add("vunsetwidth",
4389 "vunsetwidth [-noupdate|-update] [name]"
4390 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
4391 __FILE__,VAspects,group);
4393 theCommands.Add("vsetinteriorstyle",
4394 "vsetinteriorstyle [-noupdate|-update] [name] style"
4395 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
4396 __FILE__,VSetInteriorStyle,group);
4398 theCommands.Add("vardis",
4399 "vardis : display activeareas",
4400 __FILE__,VDispAreas,group);
4402 theCommands.Add("varera",
4403 "varera : erase activeareas",
4404 __FILE__,VClearAreas,group);
4406 theCommands.Add("vsensdis",
4407 "vardisp : display active entities",
4408 __FILE__,VDispSensi,group);
4409 theCommands.Add("vsensera",
4410 "vardisp : erase active entities",
4411 __FILE__,VClearSensi,group);
4413 theCommands.Add("vselprecision",
4414 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
4415 __FILE__,VSelPrecision,group);
4417 theCommands.Add("vperf",
4418 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
4419 __FILE__,VPerf,group);
4421 theCommands.Add("vanimation",
4422 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
4423 __FILE__,VAnimation,group);
4425 theCommands.Add("vsetshading",
4426 "vsetshading : vsetshading name Quality(default=0.0008) ",
4427 __FILE__,VShading,group);
4429 theCommands.Add("vunsetshading",
4430 "vunsetshading :vunsetshading name ",
4431 __FILE__,VShading,group);
4433 theCommands.Add ("vtexture",
4434 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
4435 " [-scale u v] [-scale off]\n"
4436 " [-origin u v] [-origin off]\n"
4437 " [-repeat u v] [-repeat off]\n"
4438 " [-modulate {on | off}]"
4440 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
4441 " specifying one of the predefined textures.\n"
4442 " The options are: \n"
4443 " -scale u v : enable texture scaling and set scale factors\n"
4444 " -scale off : disable texture scaling\n"
4445 " -origin u v : enable texture origin positioning and set the origin\n"
4446 " -origin off : disable texture origin positioning\n"
4447 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
4448 " -repeat off : disable texture repeat\n"
4449 " -modulate {on | off} : enable or disable texture modulation\n"
4450 " -default : sets texture mapping default parameters\n"
4451 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
4452 "or 'vtexture NameOfShape ?' to list available textures\n",
4453 __FILE__, VTexture, group);
4455 theCommands.Add("vtexscale",
4456 "'vtexscale NameOfShape ScaleU ScaleV' \n \
4457 or 'vtexscale NameOfShape ScaleUV' \n \
4458 or 'vtexscale NameOfShape' to disable scaling\n ",
4459 __FILE__,VTexture,group);
4461 theCommands.Add("vtexorigin",
4462 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
4463 or 'vtexorigin NameOfShape UVOrigin' \n \
4464 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
4465 __FILE__,VTexture,group);
4467 theCommands.Add("vtexrepeat",
4468 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
4469 or 'vtexrepeat NameOfShape UVRepeat \n \
4470 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
4473 theCommands.Add("vtexdefault",
4474 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
4477 theCommands.Add("vsetam",
4478 "vsetActivatedModes: vsetam mode(1->7) ",
4479 __FILE__,VActivatedMode,group);
4481 theCommands.Add("vunsetam",
4482 "vunsetActivatedModes: vunsetam ",
4483 __FILE__,VActivatedMode,group);
4485 theCommands.Add("vstate",
4486 "vstate [name1] ... [nameN]"
4487 "\n\t\t: Reports show/hidden state for selected or named objects",
4488 __FILE__,VState,group);
4490 theCommands.Add("vpickshapes",
4491 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
4492 __FILE__,VPickShape,group);
4494 theCommands.Add("vtypes",
4495 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
4498 theCommands.Add("vsettransmode",
4499 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
4500 __FILE__,VSetTransMode,group);
4502 theCommands.Add("vr", "vr : reading of the shape",
4503 __FILE__,vr, group);
4507 //=====================================================================
4508 //========================= for testing Draft and Rib =================
4509 //=====================================================================
4510 #include <BRepOffsetAPI_MakeThickSolid.hxx>
4511 #include <DBRep.hxx>
4512 #include <TopoDS_Face.hxx>
4513 #include <gp_Pln.hxx>
4514 #include <AIS_KindOfSurface.hxx>
4515 #include <BRepOffsetAPI_DraftAngle.hxx>
4516 #include <Precision.hxx>
4517 #include <BRepAlgo.hxx>
4518 #include <OSD_Environment.hxx>
4519 #include <DrawTrSurf.hxx>
4520 //#include <DbgTools.hxx>
4521 //#include <FeatAlgo_MakeLinearForm.hxx>
4526 //=======================================================================
4527 //function : IsValid
4529 //=======================================================================
4530 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
4531 const TopoDS_Shape& theResult,
4532 const Standard_Boolean closedSolid,
4533 const Standard_Boolean GeomCtrl)
4535 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
4536 TCollection_AsciiString checkValid = check.Value();
4537 Standard_Boolean ToCheck = Standard_True;
4538 if (!checkValid.IsEmpty()) {
4540 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
4542 if ( checkValid=="true" || checkValid=="TRUE" ) {
4543 ToCheck= Standard_False;
4547 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
4550 Standard_Boolean IsValid = Standard_True;
4552 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
4557 //===============================================================================
4558 // TDraft : test draft, uses AIS Viewer
4559 // Solid Face Plane Angle Reverse
4560 //===============================================================================
4561 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4563 if (argc < 5) return 1;
4564 // argv[1] - TopoDS_Shape Solid
4565 // argv[2] - TopoDS_Shape Face
4566 // argv[3] - TopoDS_Shape Plane
4567 // argv[4] - Standard_Real Angle
4568 // argv[5] - Standard_Integer Reverse
4570 // Sprintf(prefix, argv[1]);
4571 Standard_Real anAngle = 0;
4572 Standard_Boolean Rev = Standard_False;
4573 Standard_Integer rev = 0;
4574 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
4575 TopoDS_Shape face = GetShapeFromName(argv[2]);
4576 TopoDS_Face Face = TopoDS::Face(face);
4577 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
4578 if (Plane.IsNull ()) {
4579 di << "TEST : Plane is NULL" << "\n";
4582 anAngle = Draw::Atof(argv[4]);
4583 anAngle = 2*M_PI * anAngle / 360.0;
4585 Handle( Geom_Surface )aSurf;
4586 AIS_KindOfSurface aSurfType;
4587 Standard_Real Offset;
4589 if(argc > 4) { // == 5
4590 rev = Draw::Atoi(argv[5]);
4591 Rev = (rev)? Standard_True : Standard_False;
4594 TopoDS_Face face2 = TopoDS::Face(Plane);
4595 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
4597 di << "TEST : Can't find plane" << "\n";
4601 aDir = aPln.Axis().Direction();
4604 if (Plane.Orientation() == TopAbs_REVERSED)
4606 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
4608 BRepOffsetAPI_DraftAngle Draft (Solid);
4610 if(Abs(anAngle)< Precision::Angular()) {
4611 di << "TEST : NULL angle" << "\n";
4614 if(Rev) anAngle = - anAngle;
4615 Draft.Add (Face, aDir, anAngle, aPln);
4617 if (!Draft.IsDone()) {
4618 di << "TEST : Draft Not DONE " << "\n";
4621 TopTools_ListOfShape Larg;
4623 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
4624 di << "TEST : DesignAlgo returns Not valid" << "\n";
4628 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4629 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
4631 if ( !ais.IsNull() ) {
4632 ais->SetColor(DEFAULT_COLOR);
4633 ais->SetMaterial(DEFAULT_MATERIAL);
4634 // Display the AIS_Shape without redraw
4635 Ctx->Display(ais, Standard_False);
4637 const char *Name = "draft1";
4638 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
4640 Handle(AIS_InteractiveObject) an_object =
4641 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
4642 if (!an_object.IsNull()) {
4643 Ctx->Remove(an_object,
4645 GetMapOfAIS().UnBind2(Name) ;
4648 GetMapOfAIS().Bind(ais, Name);
4649 // DBRep::Set("draft", ais->Shape());
4651 Ctx->Display(ais, Standard_True);
4655 //==============================================================================
4656 //function : splitParameter
4657 //purpose : Split parameter string to parameter name and parameter value
4658 //==============================================================================
4659 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
4660 TCollection_AsciiString& theName,
4661 TCollection_AsciiString& theValue)
4663 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
4665 if (aParamNameEnd == 0)
4667 return Standard_False;
4670 TCollection_AsciiString aString (theString);
4671 if (aParamNameEnd != 0)
4673 theValue = aString.Split (aParamNameEnd);
4674 aString.Split (aString.Length() - 1);
4678 return Standard_True;
4681 //============================================================================
4683 //============================================================================
4684 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
4687 DrawTrSurf::BasicCommands(theCommands);
4688 const char* group = "Check Features Operations commands";
4690 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
4692 &TDraft,group); //Draft_Modification
4695 //==============================================================================
4696 // ViewerTest::Factory
4697 //==============================================================================
4698 void ViewerTest::Factory(Draw_Interpretor& theDI)
4700 // definition of Viewer Command
4701 ViewerTest::Commands(theDI);
4702 ViewerTest::AviCommands(theDI);
4705 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
4709 // Declare entry point PLUGINFACTORY