1 // File: ViewerTest.cxx
2 // Created: Wed Jul 23 14:14:01 1997
3 // Author: Henri JEANNIN
4 // <bbl@entrax.paris3.matra-dtv.fr>
5 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
7 // Modified by Robert Coublanc [nov 16-17-18 1998]
8 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
9 // ViewerTest_ObjectCommands.cxx
10 // ViewerTest_RelationCommands.cxx
11 // -add Functions and commands for interactive selection of shapes and objects
12 // in AIS Viewers. (PickShape(s), PickObject(s),
14 #include <Standard_Stream.hxx>
16 #include <ViewerTest.hxx>
17 #include <TopLoc_Location.hxx>
18 #include <TopTools_HArray1OfShape.hxx>
19 #include <TColStd_HArray1OfTransient.hxx>
20 #include <OSD_Directory.hxx>
21 #include <OSD_File.hxx>
22 #include <OSD_Path.hxx>
23 #include <OSD_Timer.hxx>
24 #include <Geom_Axis2Placement.hxx>
25 #include <Geom_Axis1Placement.hxx>
26 #include <gp_Trsf.hxx>
27 #include <TopExp_Explorer.hxx>
28 #include <BRepAdaptor_Curve.hxx>
29 #include <StdSelect_ShapeTypeFilter.hxx>
31 #include <AIS_InteractiveObject.hxx>
32 #include <AIS_Trihedron.hxx>
33 #include <AIS_Axis.hxx>
34 #include <AIS_Relation.hxx>
35 #include <AIS_TypeFilter.hxx>
36 #include <AIS_SignatureFilter.hxx>
37 #include <AIS_ListOfInteractive.hxx>
38 #include <AIS_ListIteratorOfListOfInteractive.hxx>
39 #include <Image_PixMap.hxx>
49 #include <Draw_Interpretor.hxx>
50 #include <TCollection_AsciiString.hxx>
51 #include <Draw_PluginMacro.hxx>
52 #include <ViewerTest.hxx>
53 #include <Viewer2dTest.hxx>
55 // avoid warnings on 'extern "C"' functions returning C++ classes
57 #define _CRT_SECURE_NO_DEPRECATE
58 #pragma warning(4:4190)
59 #pragma warning (disable:4996)
62 #include <NIS_InteractiveContext.hxx>
63 #include <NIS_Triangulated.hxx>
64 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
66 //=======================================================================
67 //function : GetColorFromName
68 //purpose : get the Quantity_NameOfColor from a string
69 //=======================================================================
71 #include <Quantity_NameOfColor.hxx>
72 #include <Quantity_Color.hxx>
73 #include <Quantity_NameOfColor.hxx>
75 #include <Graphic3d_NameOfMaterial.hxx>
77 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
78 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
80 static Quantity_NameOfColor GetColorFromName( const char *name )
82 Quantity_NameOfColor ret = DEFAULT_COLOR;
84 Standard_Boolean Found = Standard_False;
85 Standard_CString colstring;
86 for(Standard_Integer i=0;i<=514 && !Found;i++)
88 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
89 if (!strcasecmp(name,colstring)) {
90 ret = (Quantity_NameOfColor)i;
91 Found = Standard_True;
98 //=======================================================================
99 //function : GetMaterialFromName
100 //purpose : get the Graphic3d_NameOfMaterial from a string
101 //=======================================================================
103 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
105 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
107 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
108 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
109 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
110 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
111 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
112 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
113 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
114 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
115 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
116 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
117 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
118 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
119 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
120 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
121 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
122 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
123 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
124 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
125 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
126 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
131 //=======================================================================
132 //function : GetTypeNames
134 //=======================================================================
135 static const char** GetTypeNames()
137 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
138 "Shape","ConnectedShape","MultiConn.Shape",
139 "ConnectedInter.","MultiConn.",
140 "Constraint","Dimension"};
141 static const char** ThePointer = names;
145 //=======================================================================
146 //function : GetTypeAndSignfromString
148 //=======================================================================
149 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
151 const char ** thefullnames = GetTypeNames();
152 Standard_Integer index(-1);
154 for(Standard_Integer i=0;i<=13 && index==-1;i++)
155 if(!strcasecmp(name,thefullnames[i]))
159 TheType = AIS_KOI_None;
165 TheType = AIS_KOI_Datum;
169 TheType = AIS_KOI_Shape;
173 TheType = AIS_KOI_Object;
177 TheType = AIS_KOI_Relation;
186 #include <Draw_Interpretor.hxx>
188 #include <Draw_Appli.hxx>
192 #include <TCollection_AsciiString.hxx>
193 #include <V3d_Viewer.hxx>
194 #include <V3d_View.hxx>
197 #include <AIS_InteractiveContext.hxx>
198 #include <AIS_Shape.hxx>
199 #include <AIS_TexturedShape.hxx>
200 #include <AIS_DisplayMode.hxx>
201 #include <TColStd_MapOfInteger.hxx>
202 #include <AIS_MapOfInteractive.hxx>
203 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
204 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
205 #include <ViewerTest_EventManager.hxx>
207 #include <TopoDS_Solid.hxx>
208 #include <BRepTools.hxx>
209 #include <BRep_Builder.hxx>
210 #include <TopAbs_ShapeEnum.hxx>
212 #include <TopoDS.hxx>
213 #include <BRep_Tool.hxx>
216 #include <Draw_Window.hxx>
217 #include <AIS_ListIteratorOfListOfInteractive.hxx>
218 #include <AIS_ListOfInteractive.hxx>
219 #include <AIS_DisplayMode.hxx>
220 #include <TopTools_ListOfShape.hxx>
221 #include <BRepOffsetAPI_MakeThickSolid.hxx>
222 #include <BRepOffset.hxx>
225 //==============================================================================
226 //function : GetTypeNameFromShape
227 //purpose : get the shape type as a string from a shape
228 //==============================================================================
230 static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
231 { const char *ret = "????";
233 if ( aShape.IsNull() ) ret = "Null Shape";
235 switch ( aShape.ShapeType() ) {
236 case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
237 case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
238 case TopAbs_SOLID : ret = "SOLID" ; break;
239 case TopAbs_SHELL : ret = "SHELL" ; break;
240 case TopAbs_FACE : ret = "FACE" ; break;
241 case TopAbs_WIRE : ret = "WIRE" ; break;
242 case TopAbs_EDGE : ret = "EDGE" ; break;
243 case TopAbs_VERTEX : ret = "VERTEX" ; break;
244 case TopAbs_SHAPE : ret = "SHAPE" ; break;
248 //==============================================================================
249 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
250 //==============================================================================
251 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
252 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
257 //==============================================================================
258 //function : VDisplayAISObject
259 //purpose : register interactive object in the map of AIS objects;
260 // if other object with such name already registered, it will be kept
261 // or replaced depending on value of <theReplaceIfExists>,
262 // if "true" - the old object will be cleared from AIS context;
263 // returns Standard_True if <theAISObj> registered in map;
264 //==============================================================================
265 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
266 const Handle(AIS_InteractiveObject)& theAISObj,
267 Standard_Boolean theReplaceIfExists = Standard_True)
269 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
270 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
271 if (aContextAIS.IsNull())
273 std::cout << "AIS context is not available.\n";
274 return Standard_False;
277 if (aMap.IsBound2 (theName))
279 if (!theReplaceIfExists)
281 std::cout << "Other interactive object has been already "
282 << "registered with name: " << theName << ".\n"
283 << "Please use another name.\n";
284 return Standard_False;
287 // stop displaying object
288 Handle(AIS_InteractiveObject) anOldObj =
289 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
291 if (!anOldObj.IsNull())
292 aContextAIS->Clear (anOldObj, Standard_True);
294 // remove name and old object from map
295 aMap.UnBind2 (theName);
298 // unbind AIS object if was bound with another name
299 aMap.UnBind1 (theAISObj);
301 // can be registered without rebinding
302 aMap.Bind (theAISObj, theName);
303 aContextAIS->Display (theAISObj, Standard_True);
304 return Standard_True;
307 static TColStd_MapOfInteger theactivatedmodes(8);
308 static TColStd_ListOfTransient theEventMgrs;
310 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
311 const Handle(AIS_InteractiveContext)& Ctx)
313 theEventMgrs.Clear();
314 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
317 static Handle(V3d_View)& a3DView(){
318 static Handle(V3d_View) Viou;
322 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
323 static Handle(AIS_InteractiveContext) aContext;
327 Handle(V3d_View) ViewerTest::CurrentView()
331 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
336 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
338 static Handle(NIS_InteractiveContext) aContext;
339 if (aContext.IsNull()) {
340 aContext = new NIS_InteractiveContext;
341 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
346 Handle(AIS_InteractiveContext) ViewerTest::GetAISContext()
348 return TheAISContext();
351 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
353 TheAISContext() = aCtx;
354 ViewerTest::ResetEventManager();
357 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
359 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
362 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
364 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
368 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
369 theEventMgrs.Prepend(EM);
372 void ViewerTest::UnsetEventManager()
374 theEventMgrs.RemoveFirst();
378 void ViewerTest::ResetEventManager()
380 const Handle(NIS_View) aView =
381 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
382 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
385 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
387 Handle(ViewerTest_EventManager) EM;
388 if(theEventMgrs.IsEmpty()) return EM;
389 Handle(Standard_Transient) Tr = theEventMgrs.First();
390 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
395 //=======================================================================
396 //function : Get Context and active viou..
398 //=======================================================================
399 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
400 Handle(V3d_View)& Viou)
402 Ctx = ViewerTest::GetAISContext();
405 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
406 Vwr->InitActiveViews();
407 if(Vwr->MoreActiveViews())
408 Viou = Vwr->ActiveView();
413 //==============================================================================
414 //function : GetShapeFromName
415 //purpose : Compute an Shape from a draw variable or a file name
416 //==============================================================================
418 static TopoDS_Shape GetShapeFromName(const char* name)
420 TopoDS_Shape S = DBRep::Get(name);
423 BRep_Builder aBuilder;
424 BRepTools::Read( S, name, aBuilder);
429 //==============================================================================
430 //function : GetShapeFromName
431 //purpose : Compute an Shape from a draw variable or a file name
432 //==============================================================================
435 static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
437 TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
441 //==============================================================================
442 //function : GetAISShapeFromName
443 //purpose : Compute an AIS_Shape from a draw variable or a file name
444 //==============================================================================
445 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
447 Handle(AIS_Shape) retsh;
449 if(GetMapOfAIS().IsBound2(name)){
450 const Handle(AIS_InteractiveObject) IO =
451 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
453 if(IO->Type()==AIS_KOI_Shape)
454 if(IO->Signature()==0){
455 retsh = *((Handle(AIS_Shape)*)&IO);
458 cout << "an Object which is not an AIS_Shape "
459 "already has this name!!!"<<endl;
465 TopoDS_Shape S = GetShapeFromName(name);
467 retsh = new AIS_Shape(S);
473 //==============================================================================
475 //purpose : Remove all the object from the viewer
476 //==============================================================================
477 void ViewerTest::Clear()
479 if ( !a3DView().IsNull() ) {
480 if (TheAISContext()->HasOpenedContext())
481 TheAISContext()->CloseLocalContext();
482 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
483 while ( it.More() ) {
484 cout << "Remove " << it.Key2() << endl;
485 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
486 const Handle(AIS_InteractiveObject) anObj =
487 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
488 TheAISContext()->Remove(anObj,Standard_False);
489 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
490 const Handle(NIS_InteractiveObject) anObj =
491 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
492 TheNISContext()->Remove(anObj);
496 TheAISContext()->UpdateCurrentViewer();
497 // TheNISContext()->UpdateViews();
498 GetMapOfAIS().Clear();
502 //==============================================================================
503 //function : StandardModesActivation
504 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
506 //==============================================================================
507 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
509 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
511 if (TheAISContext()->HasOpenedContext())
512 aContext->CloseLocalContext();
515 if(!aContext->HasOpenedContext()) {
516 // To unhilight the preselected object
517 aContext->UnhilightCurrents(Standard_False);
518 // Open a local Context in order to be able to select subshape from
519 // the selected shape if any or for all if there is no selection
520 if (!aContext->FirstCurrentObject().IsNull()){
521 aContext->OpenLocalContext(Standard_False);
523 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
524 aContext->Load( aContext->Current(),-1,Standard_True);
528 aContext->OpenLocalContext();
531 const char *cmode="???";
534 case 0: cmode = "Shape"; break;
535 case 1: cmode = "Vertex"; break;
536 case 2: cmode = "Edge"; break;
537 case 3: cmode = "Wire"; break;
538 case 4: cmode = "Face"; break;
539 case 5: cmode = "Shell"; break;
540 case 6: cmode = "Solid"; break;
541 case 7: cmode = "Compound"; break;
544 if(theactivatedmodes.Contains(mode))
546 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
547 theactivatedmodes.Remove(mode);
548 cout<<"Mode "<< cmode <<" OFF"<<endl;
552 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
553 theactivatedmodes.Add(mode);
554 cout<<"Mode "<< cmode << " ON" << endl;
559 //==============================================================================
560 //function : SelectFromContext
561 //purpose : pick / select an object from the last MoveTo() on a
563 //==============================================================================
565 Handle(AIS_InteractiveObject) Select(Standard_Integer argc,
567 Standard_Boolean shift,
568 Standard_Boolean pick )
570 Handle(AIS_InteractiveObject) ret;
571 Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
578 const Handle(AIS_InteractiveContext) aContext = EM->Context();
580 if ( !aContext->HasOpenedContext() ) {
581 aContext->InitCurrent();
582 while ( aContext->MoreCurrent() ) {
583 Handle(AIS_InteractiveObject) aisPickedShape =
584 Handle(AIS_InteractiveObject)::DownCast(aContext->Current());
587 const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
588 // const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
589 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
591 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape);
592 if(!TheRealSh.IsNull()){
593 cout << "Current is " << name
594 << " (" << GetTypeNameFromShape(TheRealSh->Shape())
597 ret = aisPickedShape;
598 if(!TheRealSh.IsNull()){
599 if ( pick && argc > 4 ) {
600 DBRep::Set(argv[4], TheRealSh->Shape());
603 aContext->NextCurrent();
607 // A LocalContext is opened, the use xxxxSelected()
608 // to select an object and its SubShape
609 aContext->InitSelected();
610 while ( aContext->MoreSelected() ) {
611 if ( !aContext->HasSelectedShape() ) {
614 TopoDS_Shape PickedShape = aContext->SelectedShape();
615 if ( pick && argc > 5 ) {
616 DBRep::Set(argv[5], PickedShape);
620 if ( aContext->Interactive().IsNull() ) {
621 cout << "??? (No InteractiveObject selected)" << endl;
624 Handle(AIS_InteractiveObject) aisPicked =
625 Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive());
627 Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked);
631 const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
632 // const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
633 GetMapOfAIS().Find1(aisPicked).ToCString() :
636 if(!aisPickedShape.IsNull()){
637 if ( pick && argc > 4 ) {
638 // Create a draw variable to store the wohole shape
640 DBRep::Set(argv[4], aisPickedShape->Shape());
643 cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape())
647 // Goto the next selected object
648 aContext->NextSelected();
654 //==============================================================================
655 //function : DetectedFromContext
656 //purpose : hilight dynamicaly an object from the last MoveTo() on a
658 //==============================================================================
659 Handle(AIS_InteractiveObject) DetectedFromContext(
660 Handle(AIS_InteractiveContext) aContext )
662 Handle(AIS_InteractiveObject) ret;
663 if ( aContext->HasDetected() ) {
664 if ( !aContext->HasDetectedShape() ) {
665 //No SubShape selected
668 // Get the detected SubShape
669 TopoDS_Shape PickedShape = aContext->DetectedShape();
671 if ( !aContext->DetectedInteractive().IsNull() ) {
672 Handle(AIS_InteractiveObject) aisPickedShape =
673 Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive());
674 ret = aisPickedShape;
678 ( GetMapOfAIS().IsBound1(aisPickedShape) )?
679 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
687 //==============================================================================
688 //function : VDispAreas,VDispSensitive,...
689 //purpose : Redraw the view
691 //==============================================================================
692 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
695 Handle(AIS_InteractiveContext) Ctx;
696 Handle(V3d_View) Viou;
697 GetCtxAndView(Ctx,Viou);
698 Ctx->DisplayActiveAreas(Viou);
701 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
703 Handle(AIS_InteractiveContext) Ctx;
704 Handle(V3d_View) Viou;
705 GetCtxAndView(Ctx,Viou);
706 Ctx->ClearActiveAreas(Viou);
710 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
712 Handle(AIS_InteractiveContext) Ctx;
713 Handle(V3d_View) Viou;
714 GetCtxAndView(Ctx,Viou);
715 Ctx->DisplayActiveSensitive(Viou);
719 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
721 Handle(AIS_InteractiveContext) Ctx;
722 Handle(V3d_View) Viou;
723 GetCtxAndView(Ctx,Viou);
724 Ctx->ClearActiveSensitive(Viou);
728 //==============================================================================
730 //purpose : To list the displayed object with their attributes
732 //==============================================================================
733 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
734 { if ( !a3DView().IsNull() ) {
735 di << "List of object in the viewer :" << "\n";
737 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
739 while ( it.More() ) {
740 di << "\t" << it.Key2().ToCString() << "\n";
748 //==============================================================================
750 //purpose : To dump the active view snapshot to image file
751 //Draw arg : Picture file name with extension corresponding to desired format
752 //==============================================================================
753 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
757 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
761 Image_TypeOfImage aBufferType = Image_TOI_RGB;
765 TCollection_AsciiString aBuffTypeStr (argv[2]);
766 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
768 aBufferType = Image_TOI_RGB;
770 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
772 aBufferType = Image_TOI_RGBA;
774 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
776 aBufferType = Image_TOI_FLOAT;
780 Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0;
781 Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
783 Handle(AIS_InteractiveContext) IC;
784 Handle(V3d_View) view;
785 GetCtxAndView (IC, view);
788 if (aWidth > 0 && aHeight > 0)
790 return view->ToPixMap (aWidth, aHeight, aBufferType)->Dump (argv[1]) ? 0 : 1;
794 return view->Dump (argv[1], aBufferType) ? 0 : 1;
799 di << "Cannot find an active viewer/view" << "\n";
805 //==============================================================================
806 //function : Displays,Erase...
809 //==============================================================================
810 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
811 const Standard_Integer Mode,
812 const Standard_Integer TypeOfOperation,
813 const Standard_Boolean Upd)
815 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
817 switch(TypeOfOperation){
819 Ctx->Display(IO,Mode,Upd);
822 Ctx->Erase(IO,Mode,Upd);
827 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
829 Ctx->SetDisplayMode(IO,Mode,Upd);
834 Ctx->SetDisplayMode(0,Upd);
836 Ctx->UnsetDisplayMode(IO,Upd);
843 //=======================================================================
846 //=======================================================================
847 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
850 TCollection_AsciiString name;
853 // display others presentations
854 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
855 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
856 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
857 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
859 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
861 //unset displaymode.. comportement particulier...
862 if(TypeOfOperation==4){
864 if(Ctx->NbCurrents()==0 ||
865 Ctx->NbSelected()==0){
866 Handle(AIS_InteractiveObject) IO;
867 VwrTst_DispErase(IO,-1,4,Standard_False);
869 else if(!Ctx->HasOpenedContext()){
870 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
871 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
874 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
875 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
876 Ctx->UpdateCurrentViewer();
879 Handle(AIS_InteractiveObject) IO;
881 if(GetMapOfAIS().IsBound2(name)){
882 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
884 VwrTst_DispErase(IO,-1,4,Standard_True);
889 Standard_Integer Dmode = atoi(argv[1]);
890 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
891 Handle(AIS_InteractiveObject) IO;
892 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
894 if(!Ctx->HasOpenedContext()){
895 // set/unset display mode sur le Contexte...
896 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
897 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
899 Ctx->UpdateCurrentViewer();
902 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
903 Ctx->Display(Ctx->Interactive(),Dmode);
907 Handle(AIS_InteractiveObject) IO;
909 if(GetMapOfAIS().IsBound2(name))
910 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
912 VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
918 //=======================================================================
921 //=======================================================================
922 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
924 if(argc==1) return 1;
925 Standard_Integer On = atoi(argv[1]);
926 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
930 if(!Ctx->HasOpenedContext()){
931 di<<"sub intensite ";
934 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
935 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
937 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
939 di <<"passage dans off"<<"\n";
940 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
945 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
947 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
949 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
952 Ctx->UpdateCurrentViewer();
955 Handle(AIS_InteractiveObject) IO;
956 TCollection_AsciiString name = argv[2];
957 if(GetMapOfAIS().IsBound2(name)){
958 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
961 Ctx->SubIntensityOn(IO);
963 Ctx->SubIntensityOff(IO);
971 //==============================================================================
974 //purpose : change the color of a selected or named or displayed shape
975 //Draw arg : vcolor2 [name] color
976 //==============================================================================
977 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
980 Standard_Boolean ThereIsCurrent;
981 Standard_Boolean ThereIsArgument;
982 Standard_Boolean IsBound = Standard_False ;
983 Standard_Boolean HaveToSet;
985 if (!strcasecmp( argv[0],"vsetcolor")) HaveToSet=Standard_True;
986 else HaveToSet=Standard_False;
988 if ( argc<2 || argc > 3 ) { di << argv[0] << " syntax error: Passez 2 ou 3 arguments" << "\n"; return 1; }
989 if ( argc == 2 ) {ThereIsArgument=Standard_False;}
990 else ThereIsArgument=Standard_True;
994 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
995 if(argc==2) ThereIsArgument=Standard_True;
996 else ThereIsArgument=Standard_False;
999 if ( !a3DView().IsNull() ) {
1000 TCollection_AsciiString name;
1001 if (ThereIsArgument) {
1003 IsBound= GetMapOfAIS().IsBound2(name);
1005 if (TheAISContext()->HasOpenedContext())
1006 TheAISContext()->CloseLocalContext();
1008 // On set le Booleen There is current
1009 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1010 else ThereIsCurrent =Standard_False;
1012 //=======================================================================
1013 // Il y a un argument
1014 //=======================================================================
1015 if ( ThereIsArgument && IsBound ) {
1016 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1017 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1018 Handle(AIS_InteractiveObject) ashape =
1019 Handle(AIS_InteractiveObject)::DownCast (anObj);
1021 //cout << "HaveToSet "<<HaveToSet <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << endl;
1023 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1025 di << "HaveToSet "<< "0" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1029 TheAISContext()->SetColor(ashape,GetColorFromName(argv[2]) );
1032 TheAISContext()->UnsetColor(ashape);
1033 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1034 Handle(NIS_Triangulated) ashape =
1035 Handle(NIS_Triangulated)::DownCast (anObj);
1036 if (ashape.IsNull() == Standard_False)
1037 ashape->SetColor (GetColorFromName(argv[2]));
1042 //=======================================================================
1043 // Il n'y a pas d'arguments
1044 // Mais un ou plusieurs objets on des current representation
1045 //=======================================================================
1046 if (ThereIsCurrent && !ThereIsArgument) {
1047 for (TheAISContext() -> InitCurrent() ;
1048 TheAISContext() -> MoreCurrent() ;
1049 TheAISContext() ->NextCurrent() )
1051 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1052 if (ashape.IsNull())
1055 //cout << "HaveToSet "<<HaveToSet <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << endl;
1057 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1059 di << "HaveToSet "<< "0" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1062 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1064 TheAISContext()->UnsetColor(ashape,Standard_False);
1067 TheAISContext()->UpdateCurrentViewer();
1070 //=======================================================================
1071 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1072 // on impose a tous les objets du viewer la couleur passee
1073 //=======================================================================
1074 else if (!ThereIsCurrent && !ThereIsArgument){
1075 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1076 while ( it.More() ) {
1077 const Handle(AIS_InteractiveObject) ashape =
1078 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1079 if (!ashape.IsNull())
1081 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),
1084 TheAISContext()->UnsetColor(ashape,Standard_False);
1087 TheAISContext()->UpdateCurrentViewer();
1093 //==============================================================================
1094 //function : VTransparency
1096 //purpose : change the transparency of a selected or named or displayed shape
1097 //Draw arg : vtransparency [name] TransparencyCoeficient
1098 //==============================================================================
1101 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1104 Standard_Boolean ThereIsCurrent;
1105 Standard_Boolean ThereIsArgument;
1106 Standard_Boolean IsBound = Standard_False ;
1107 Standard_Boolean HaveToSet;
1108 if (!strcasecmp( argv[0],"vsettransparency"))
1109 HaveToSet=Standard_True;
1111 HaveToSet=Standard_False;
1114 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1115 if ( argc == 2 ) {ThereIsArgument=Standard_False;}
1116 else ThereIsArgument=Standard_True;
1119 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1120 if(argc==2) ThereIsArgument=Standard_True;
1121 else ThereIsArgument=Standard_False;
1124 if ( !a3DView().IsNull() ) {
1125 TCollection_AsciiString name;
1126 if (ThereIsArgument) {
1128 IsBound= GetMapOfAIS().IsBound2(name);
1130 if (TheAISContext()->HasOpenedContext())
1131 TheAISContext()->CloseLocalContext();
1133 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1134 else ThereIsCurrent = Standard_False;
1136 //=======================================================================
1137 // Il y a des arguments: un nom et une couleur
1138 //=======================================================================
1139 if ( ThereIsArgument && IsBound ) {
1140 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1141 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1142 const Handle(AIS_InteractiveObject) ashape =
1143 Handle(AIS_InteractiveObject)::DownCast(anObj);
1145 TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1147 TheAISContext()->UnsetTransparency(ashape);
1148 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1149 const Handle(NIS_InteractiveObject) ashape =
1150 Handle(NIS_InteractiveObject)::DownCast(anObj);
1152 ashape->SetTransparency(atof(argv[2]) );
1154 ashape->UnsetTransparency();
1157 //=======================================================================
1158 // Il n'y a pas d'arguments
1159 // Mais un ou plusieurs objets on des current representation
1160 //=======================================================================
1161 if (ThereIsCurrent && !ThereIsArgument) {
1162 for (TheAISContext() -> InitCurrent() ;
1163 TheAISContext() -> MoreCurrent() ;
1164 TheAISContext() ->NextCurrent() )
1166 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1168 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1171 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1174 TheAISContext()->UpdateCurrentViewer();
1176 //=======================================================================
1177 // Il n'y a pas d'arguments ET aucun objet courrant
1178 //=======================================================================
1179 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1180 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1182 while ( it.More() ) {
1183 Handle(AIS_InteractiveObject) ashape =
1184 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1185 if (!ashape.IsNull())
1187 TheAISContext()->SetTransparency(ashape,atof(argv[1]),
1190 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1193 TheAISContext()->UpdateCurrentViewer();
1200 //==============================================================================
1201 //function : VMaterial
1203 //purpose : change the Material of a selected or named or displayed shape
1204 //Draw arg : vmaterial [Name] Material
1205 //==============================================================================
1206 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1209 Standard_Boolean ThereIsCurrent;
1210 Standard_Boolean ThereIsName;
1211 Standard_Boolean IsBound = Standard_False ;
1213 Standard_Boolean HaveToSet;
1214 if (!strcasecmp( argv[0],"vsetmaterial")) HaveToSet=Standard_True;
1215 else HaveToSet=Standard_False;
1217 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1218 if ( argc == 2 ) {ThereIsName=Standard_False;}
1219 else ThereIsName=Standard_True;
1222 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1223 if (argc==2) ThereIsName=Standard_True;
1224 else ThereIsName=Standard_False;
1228 if ( !a3DView().IsNull() ) {
1229 TCollection_AsciiString name;
1232 IsBound= GetMapOfAIS().IsBound2(name);
1234 if (TheAISContext()->HasOpenedContext())
1235 TheAISContext()->CloseLocalContext();
1236 if (TheAISContext() -> NbCurrents() > 0 )
1237 ThereIsCurrent =Standard_True;
1239 ThereIsCurrent =Standard_False;
1241 //=======================================================================
1242 // Ther is a name of shape and a material name
1243 //=======================================================================
1244 if ( ThereIsName && IsBound ) {
1245 Handle(AIS_InteractiveObject) ashape =
1246 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1247 if (!ashape.IsNull())
1249 TheAISContext()->SetMaterial (ashape,
1250 GetMaterialFromName (argv[2]) );
1252 TheAISContext()->UnsetMaterial(ashape);
1254 //=======================================================================
1255 // Il n'y a pas de nom de shape
1256 // Mais un ou plusieurs objets on des current representation
1257 //=======================================================================
1258 if (ThereIsCurrent && !ThereIsName) {
1259 for (TheAISContext() -> InitCurrent() ;
1260 TheAISContext() -> MoreCurrent() ;
1261 TheAISContext() ->NextCurrent() )
1263 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1265 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),
1268 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1270 TheAISContext()->UpdateCurrentViewer();
1273 //=======================================================================
1274 // Il n'y a pas de noms de shape ET aucun objet courrant
1275 // On impose a tous les objets du viewer le material passe en argument
1276 //=======================================================================
1277 else if (!ThereIsCurrent && !ThereIsName){
1278 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1280 while ( it.More() ) {
1281 Handle(AIS_InteractiveObject) ashape =
1282 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1283 if (!ashape.IsNull())
1285 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),
1288 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1291 TheAISContext()->UpdateCurrentViewer();
1299 //==============================================================================
1302 //purpose : change the width of the edges of a selected or named or displayed shape
1303 //Draw arg : vwidth [Name] WidthValue(1->10)
1304 //==============================================================================
1305 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1308 Standard_Boolean ThereIsCurrent;
1309 Standard_Boolean ThereIsArgument;
1310 Standard_Boolean IsBound = Standard_False ;
1312 Standard_Boolean HaveToSet;
1313 if (!strcasecmp( argv[0],"vsetwidth")) HaveToSet=Standard_True;
1314 else HaveToSet=Standard_False;
1316 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1317 if ( argc == 2 ) {ThereIsArgument=Standard_False;}
1318 else ThereIsArgument=Standard_True;
1321 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1322 if (argc==2) ThereIsArgument=Standard_True;
1323 else ThereIsArgument=Standard_False;
1325 if ( !a3DView().IsNull() ) {
1326 TCollection_AsciiString name;
1327 if (ThereIsArgument) {
1329 IsBound= GetMapOfAIS().IsBound2(name);
1331 if (TheAISContext()->HasOpenedContext())
1332 TheAISContext()->CloseLocalContext();
1334 if (TheAISContext() -> NbCurrents() > 0 )
1335 ThereIsCurrent =Standard_True;
1337 ThereIsCurrent =Standard_False;
1339 if ( ThereIsArgument && IsBound ) {
1340 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1341 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1342 const Handle(AIS_InteractiveObject) ashape =
1343 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1345 TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1347 TheAISContext()->UnsetWidth (ashape);
1348 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1349 const Handle(NIS_Triangulated) ashape =
1350 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1351 if (HaveToSet && !ashape.IsNull())
1352 ashape->SetLineWidth ( atof (argv[2]) );
1356 //=======================================================================
1357 // Il n'y a pas d'arguments
1358 // Mais un ou plusieurs objets on des current representation
1359 //=======================================================================
1360 if (ThereIsCurrent && !ThereIsArgument) {
1361 for (TheAISContext() -> InitCurrent() ;
1362 TheAISContext() -> MoreCurrent() ;
1363 TheAISContext() ->NextCurrent() )
1365 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1367 TheAISContext()->SetWidth(ashape,atof (argv[1]),Standard_False);
1369 TheAISContext()->UnsetWidth (ashape,Standard_False);
1372 TheAISContext()->UpdateCurrentViewer();
1374 //=======================================================================
1375 // Il n'y a pas d'arguments ET aucun objet courrant
1376 //=======================================================================
1377 else if (!ThereIsCurrent && !ThereIsArgument){
1378 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1380 while ( it.More() ) {
1381 Handle(AIS_InteractiveObject) ashape =
1382 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1383 if (!ashape.IsNull())
1385 TheAISContext()->SetWidth(ashape,atof (argv[1]),Standard_False );
1387 TheAISContext()->UnsetWidth (ashape,Standard_False);
1390 TheAISContext()->UpdateCurrentViewer();
1395 //==============================================================================
1396 //function : VDonly2
1398 //purpose : Display only a selected or named object
1399 // if there is no selected or named object s, nothing is donne
1400 //Draw arg : vdonly2 [name1] ... [name n]
1401 //==============================================================================
1402 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1405 if ( a3DView().IsNull() )
1408 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1409 Standard_Boolean ThereIsArgument= argc>1;
1411 if (TheAISContext()->HasOpenedContext())
1412 TheAISContext()->CloseLocalContext();
1414 //===============================================================
1415 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1417 //===============================================================
1418 if (!ThereIsArgument && ThereIsCurrent) {
1421 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1424 for(TheAISContext()->InitCurrent();
1425 TheAISContext()->MoreCurrent();
1426 TheAISContext()->NextCurrent()){
1427 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1428 TheAISContext()->Erase(aShape,Standard_False);}
1430 TheAISContext() ->UpdateCurrentViewer();
1431 //===============================================================
1432 // Il y a des arguments
1433 //===============================================================
1434 if (ThereIsArgument) {
1435 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1437 while ( it.More() ) {
1438 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1439 const Handle(AIS_InteractiveObject) aShape =
1440 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1441 TheAISContext()->Erase(aShape,Standard_False);
1442 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1443 const Handle(NIS_InteractiveObject) aShape =
1444 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1445 TheNISContext()->Erase(aShape);
1450 // On display les objets passes par parametre
1451 for (int i=1; i<argc ; i++) {
1452 TCollection_AsciiString name=argv[i];
1453 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1455 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1456 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1457 const Handle(AIS_InteractiveObject) aShape =
1458 Handle(AIS_InteractiveObject)::DownCast (anObj);
1459 TheAISContext()->Display(aShape, Standard_False);
1460 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1461 Handle(NIS_InteractiveObject) aShape =
1462 Handle(NIS_InteractiveObject)::DownCast (anObj);
1463 TheNISContext()->Display(aShape);
1467 TheAISContext() ->UpdateCurrentViewer();
1468 // TheNISContext() ->UpdateViews();
1473 //==============================================================================
1474 //function : VErase2
1476 //purpose : Erase some selected or named objects
1477 // if there is no selected or named objects, the whole viewer is erased
1478 //Draw arg : verase2 [name1] ... [name n]
1479 //==============================================================================
1480 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1483 if ( a3DView().IsNull() )
1486 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1487 Standard_Boolean ThereIsArgument= argc>1;
1488 if(TheAISContext()->HasOpenedContext())
1489 TheAISContext()->CloseLocalContext();
1491 //===============================================================
1492 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1494 //===============================================================
1495 if (!ThereIsArgument && ThereIsCurrent) {
1496 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1498 while ( it.More() ) {
1499 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1500 const Handle(AIS_InteractiveObject) aShape =
1501 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1502 if (TheAISContext()->IsCurrent(aShape))
1503 TheAISContext()->Erase(aShape,Standard_False);
1508 TheAISContext() ->UpdateCurrentViewer();
1511 //===============================================================
1512 // Il n'y a pas d'arguments et aucuns objets selectionnes
1514 // On erase tout le viewer
1515 //===============================================================
1517 if (!ThereIsArgument && !ThereIsCurrent) {
1518 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1519 while ( it.More() ) {
1520 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1521 const Handle(AIS_InteractiveObject) aShape =
1522 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1523 TheAISContext()->Erase(aShape,Standard_False);
1524 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1525 const Handle(NIS_InteractiveObject) aShape =
1526 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1527 TheNISContext()->Erase(aShape);
1531 TheAISContext() ->UpdateCurrentViewer();
1532 // TheNISContext()->UpdateViews();
1535 //===============================================================
1536 // Il y a des arguments
1537 //===============================================================
1538 if (ThereIsArgument) {
1539 for (int i=1; i<argc ; i++) {
1540 TCollection_AsciiString name=argv[i];
1541 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1543 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1544 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1545 const Handle(AIS_InteractiveObject) aShape =
1546 Handle(AIS_InteractiveObject)::DownCast (anObj);
1547 TheAISContext()->Erase(aShape,Standard_False);
1548 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1549 const Handle(NIS_InteractiveObject) aShape =
1550 Handle(NIS_InteractiveObject)::DownCast (anObj);
1551 TheNISContext()->Erase(aShape);
1555 TheAISContext() ->UpdateCurrentViewer();
1556 // TheNISContext() ->UpdateViews();
1561 //==============================================================================
1562 //function : VEraseAll
1564 //purpose : Erase all the objects displayed in the viewer
1565 //Draw arg : veraseall
1566 //==============================================================================
1567 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1570 // Verification des arguments
1571 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1572 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1573 TheAISContext()->CloseAllContexts(Standard_False);
1574 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1576 while ( it.More() ) {
1577 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1578 const Handle(AIS_InteractiveObject) aShape =
1579 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1580 TheAISContext()->Erase(aShape,Standard_False);
1581 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1582 const Handle(NIS_InteractiveObject) aShape =
1583 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1584 TheNISContext()->Erase(aShape);
1588 TheAISContext() ->UpdateCurrentViewer();
1589 // TheNISContext() ->UpdateViews();
1594 //==============================================================================
1595 //function : VDisplayAll
1597 //purpose : Display all the objects of the Map
1598 //Draw arg : vdisplayall
1599 //==============================================================================
1600 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1603 if (! a3DView().IsNull() ) {
1604 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1605 if (TheAISContext()->HasOpenedContext())
1606 TheAISContext()->CloseLocalContext();
1607 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1609 while ( it.More() ) {
1610 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1611 const Handle(AIS_InteractiveObject) aShape =
1612 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1613 TheAISContext()->Erase(aShape,Standard_False);
1614 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1615 const Handle(NIS_InteractiveObject) aShape =
1616 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1617 TheNISContext()->Erase(aShape);
1622 while ( it.More() ) {
1623 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1624 const Handle(AIS_InteractiveObject) aShape =
1625 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1626 TheAISContext()->Display(aShape, Standard_False);
1627 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1628 Handle(NIS_InteractiveObject) aShape =
1629 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1630 TheNISContext()->Display(aShape);
1634 TheAISContext() ->UpdateCurrentViewer();
1635 // TheNISContext() ->UpdateViews();
1641 //#######################################################################################################
1644 static TCollection_AsciiString GetEnvir (Draw_Interpretor& di) {
1646 static Standard_Boolean IsDefined=Standard_False ;
1647 static TCollection_AsciiString VarName;
1649 const char *envir, *casroot ;
1650 envir = getenv("CSF_MDTVTexturesDirectory") ;
1652 Standard_Boolean HasDefinition = Standard_False ;
1654 casroot = getenv("CASROOT");
1656 VarName = TCollection_AsciiString (casroot);
1657 VarName += "/src/Textures" ;
1658 HasDefinition = Standard_True ;
1661 VarName = TCollection_AsciiString (envir);
1662 HasDefinition = Standard_True ;
1664 if ( HasDefinition ) {
1665 OSD_Path aPath ( VarName );
1666 OSD_Directory aDir(aPath);
1667 if ( aDir.Exists () ) {
1668 TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb" ;
1669 OSD_File TextureFile ( aTexture );
1670 if ( !TextureFile.Exists() ) {
1671 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1672 di << " not all files are found in : "<<VarName.ToCString() << "\n";
1673 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1676 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1677 di << " Directory : "<< VarName.ToCString() << " not exist " << "\n";
1678 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1682 di << " CSF_MDTVTexturesDirectory and CASROOT not setted " << "\n";
1683 di << " one of these variable are mandatory to use this fonctionnality" << "\n";
1684 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory and CASROOT not setted " );
1686 IsDefined = Standard_True ;
1692 //#######################################################################################################
1695 //#######################################################################################################
1699 //#######################################################################################################
1701 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1703 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1704 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1705 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1706 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1707 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1709 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1710 if(myAISContext.IsNull())
1712 di << "use 'vinit' command before " << argv[0] << "\n";
1716 Handle(AIS_InteractiveObject) TheAisIO;
1717 Handle(AIS_TexturedShape) myShape;
1718 Standard_Integer myPreviousMode = 0;
1720 if (argc<2 || !argv[1])
1722 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1726 TCollection_AsciiString name = argv[1];
1727 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1729 if (GetMapOfAIS().IsBound2(name))
1730 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1731 (GetMapOfAIS().Find2(name));
1732 if (TheAisIO.IsNull())
1734 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1738 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1740 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1741 myPreviousMode = myShape->DisplayMode() ;
1745 myAISContext->Clear(TheAisIO,Standard_False);
1746 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1747 GetMapOfAIS().UnBind1(TheAisIO);
1748 GetMapOfAIS().UnBind2(name);
1749 GetMapOfAIS().Bind(myShape, name);
1753 case 1: // vtexture : we only map a texture on the shape
1756 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1759 if (argc>2 && argv[2])
1761 if(strcasecmp(argv[2],"?")==0)
1763 TCollection_AsciiString monPath = GetEnvir (di) ;
1765 di<<"\n Files in current directory : \n"<<"\n";
1766 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1767 di.Eval(Cmnd.ToCString());
1769 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1772 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1773 di.Eval(Cmnd.ToCString());
1778 myShape->SetTextureFileName(argv[2]);
1782 di <<"Texture mapping disabled \n \
1783 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1785 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1786 if (myPreviousMode == 3 )
1787 myAISContext->RecomputePrsOnly(myShape);
1788 myAISContext->Display(myShape, Standard_True);
1793 case 2: // vtexscale : we change the scaling factor of the texture
1797 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1801 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1802 ( argv[2] ? atof(argv[2]) : 1.0 ),
1803 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1806 case 3: // vtexorigin : we change the origin of the texture on the shape
1809 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1812 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1813 ( argv[2] ? atof(argv[2]) : 0.0 ),
1814 ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1817 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1820 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1823 if (argc>2 && argv[2])
1825 di <<"Texture repeat enabled"<<"\n";
1826 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1830 di <<"Texture repeat disabled"<<"\n";
1831 myShape->SetTextureRepeat(Standard_False);
1835 case 5: // vtexdefault : default texture mapping
1836 // ScaleU = ScaleV = 100.0
1837 // URepeat = VRepeat = 1.0
1838 // Uorigin = VOrigin = 0.0
1842 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1845 myShape->SetTextureRepeat(Standard_False);
1846 myShape->SetTextureOrigin(Standard_False);
1847 myShape->SetTextureScale (Standard_False);
1851 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1852 myAISContext->RecomputePrsOnly(myShape);
1855 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1856 myAISContext->Display(myShape, Standard_True);
1857 myAISContext->Update(myShape,Standard_True);
1862 //==============================================================================
1863 //function : VDisplay2
1865 //purpose : Display an object from its name
1866 //Draw arg : vdisplay name1 [name2] ... [name n]
1867 //==============================================================================
1868 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1871 // Verification des arguments
1872 if ( a3DView().IsNull() ) {
1874 ViewerTest::ViewerInit();
1875 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1880 di<<argv[0]<<" Syntaxe error"<<"\n";
1885 TCollection_AsciiString name;
1886 if (TheAISContext()->HasOpenedContext())
1887 TheAISContext()->CloseLocalContext();
1889 for ( int i = 1; i < argc; i++ ) {
1891 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1892 Standard_Boolean IsDatum = Standard_False;
1893 Handle(Standard_Transient) anObj;
1895 anObj = GetMapOfAIS().Find2(name);
1896 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1897 Handle(AIS_InteractiveObject) aShape =
1898 Handle(AIS_InteractiveObject)::DownCast(anObj);
1899 if (aShape->Type()==AIS_KOI_Datum) {
1900 IsDatum = Standard_True;
1901 TheAISContext()->Display(aShape, Standard_False);
1904 di << "Display " << name.ToCString() << "\n";
1905 // Get the Shape from a name
1906 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
1908 // Update the Shape in the AIS_Shape
1909 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
1910 if(!TheRealSh.IsNull())
1911 TheRealSh->Set(NewShape);
1912 TheAISContext()->Redisplay(aShape, Standard_False);
1913 TheAISContext()->Display(aShape, Standard_False);
1916 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1917 Handle(NIS_InteractiveObject) aShape =
1918 Handle(NIS_InteractiveObject)::DownCast(anObj);
1919 TheNISContext()->Display(aShape);
1922 else { // Create the AIS_Shape from a name
1923 const Handle(AIS_InteractiveObject) aShape =
1924 GetAISShapeFromName((const char *)name.ToCString());
1925 if ( !aShape.IsNull() ) {
1926 GetMapOfAIS().Bind(aShape, name);
1927 TheAISContext()->Display(aShape, Standard_False);
1931 // Upadate the screen and redraw the view
1932 TheAISContext()->UpdateCurrentViewer();
1933 // TheNISContext()->UpdateViews();
1937 //==============================================================================
1939 //purpose : Test the annimation of an object along a
1940 // predifined trajectory
1941 //Draw arg : vmove ShapeName
1942 //==============================================================================
1945 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
1950 if (TheAISContext()->HasOpenedContext())
1951 TheAISContext()->CloseLocalContext();
1953 Standard_Real Step=2*PI/180;
1954 Standard_Real Angle=0;
1955 // R est le rayon de l'hellicoide
1957 // D est la distance parcourue en translation en 1 tour
1960 Handle(AIS_InteractiveObject) aIO;
1962 if (GetMapOfAIS().IsBound2(argv[1]))
1963 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
1966 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
1969 TheAISContext()->Deactivate(aIO);
1971 // boucle generant le mouvement
1973 di<<" Transformations"<<"\n";
1974 for (Standard_Real myAngle=0;Angle<5*2*PI; myAngle++) {
1977 gp_Ax3 newBase(gp_Pnt(R*cos(Angle), R*sin(Angle), D*Angle/(2*PI) ), gp_Vec(0,0,1), gp_Vec(1,0,0) );
1979 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
1980 TheAISContext()->SetLocation(aIO,myTransfo);
1982 TheAISContext() ->UpdateCurrentViewer();
1987 di<<" Locations"<<"\n";
1988 gp_Trsf myAngleTrsf;
1989 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
1990 TopLoc_Location myDeltaAngle (myAngleTrsf);
1992 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
1993 TopLoc_Location myDeltaDist (myDistTrsf);
1994 TopLoc_Location myTrueLoc;
1996 for (Standard_Real myAngle=0;Angle<5*2*PI; myAngle++) {
1999 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
2000 TheAISContext()->SetLocation(aIO,myTrueLoc );
2001 TheAISContext() ->UpdateCurrentViewer();
2006 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
2008 //TopLoc_Location Tempo=aIO->Location();
2009 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
2010 //ShapeBis.Located(Tempo);
2013 // On reset la location (origine) contenue dans l'AISInteractiveObject
2014 TheAISContext() ->ResetLocation(aIO);
2016 // On force aShape a devenir l'AIS IO propre a ShapeBis
2018 // Pour cela on force aShape(AIS IO) a devenir une AISShape
2019 // ->Set() est une methode de AIS_Shape
2020 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
2022 // On donne a ShapeBis le nom de l'AIS IO
2023 //Rep::Set(argv[1],ShapeBis);
2026 TheAISContext()->Redisplay(aIO,Standard_False);
2028 // On reactive la selection des primitives sensibles
2029 TheAISContext()->Activate(aIO,0);
2031 TheAISContext() ->UpdateCurrentViewer();
2032 a3DView() -> Redraw();
2035 di<<" Temps ecoule "<<"\n";
2043 //==============================================================================
2045 //purpose : Test the annimation of an object along a
2046 // predifined trajectory
2047 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2048 //==============================================================================
2050 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2053 if (TheAISContext()->HasOpenedContext())
2054 TheAISContext()->CloseLocalContext();
2056 Standard_Real Step=4*PI/180;
2057 Standard_Real Angle=0;
2059 Handle(AIS_InteractiveObject) aIO;
2060 if (GetMapOfAIS().IsBound2(argv[1]))
2061 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2065 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2069 if (atoi(argv[3])==1 ) {
2070 di<<" Primitives sensibles OFF"<<"\n";
2071 TheAISContext()->Deactivate(aIO);
2074 di<<" Primitives sensibles ON"<<"\n";
2076 // Movement par transformation
2077 if(atoi(argv[2]) ==1) {
2078 di<<" Calcul par Transformation"<<"\n";
2079 for (Standard_Real myAngle=0;Angle<10*2*PI; myAngle++) {
2083 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2084 TheAISContext()->SetLocation(aShape,myTransfo);
2085 TheAISContext() ->UpdateCurrentViewer();
2090 di<<" Calcul par Locations"<<"\n";
2091 gp_Trsf myAngleTrsf;
2092 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2093 TopLoc_Location myDeltaAngle (myAngleTrsf);
2094 TopLoc_Location myTrueLoc;
2096 for (Standard_Real myAngle=0;Angle<10*2*PI; myAngle++) {
2099 myTrueLoc=myTrueLoc*myDeltaAngle;
2100 TheAISContext()->SetLocation(aShape,myTrueLoc );
2101 TheAISContext() ->UpdateCurrentViewer();
2104 if (atoi(argv[3])==1 ){
2105 // On reactive la selection des primitives sensibles
2106 TheAISContext()->Activate(aIO,0);
2108 a3DView() -> Redraw();
2110 di<<" Temps ecoule "<<"\n";
2116 //==================================================================================
2117 // Function : VAnimation
2118 //==================================================================================
2119 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2121 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2125 Standard_Real thread = 4;
2126 Standard_Real angleA=0;
2127 Standard_Real angleB;
2129 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2132 TopoDS_Shape CrankArm;
2133 TopoDS_Shape CylinderHead;
2134 TopoDS_Shape Propeller;
2135 TopoDS_Shape EngineBlock;
2137 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2138 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2139 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2140 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2141 BRepTools::Read(CrankArm,argv[1],B);
2142 BRepTools::Read(CylinderHead,argv[2],B);
2143 BRepTools::Read(Propeller,argv[3],B);
2144 BRepTools::Read(EngineBlock,argv[4],B);
2146 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2152 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2153 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2154 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2155 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2157 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2158 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2159 GetMapOfAIS().Bind(myAisCrankArm,"c");
2160 GetMapOfAIS().Bind(myAisPropeller,"d");
2162 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2163 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2164 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2166 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2167 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2168 TheAISContext()->Display(myAisCrankArm,Standard_False );
2169 TheAISContext()->Display(myAisPropeller,Standard_False);
2171 TheAISContext()->Deactivate(myAisCylinderHead);
2172 TheAISContext()->Deactivate(myAisEngineBlock );
2173 TheAISContext()->Deactivate(myAisCrankArm );
2174 TheAISContext()->Deactivate(myAisPropeller );
2176 // Boucle de mouvement
2177 for (Standard_Real myAngle = 0;angleA<2*PI*10.175 ;myAngle++) {
2179 angleA = thread*myAngle*PI/180;
2180 X = Sin(angleA)*3/8;
2181 angleB = atan(X / Sqrt(-X * X + 1));
2182 Standard_Real decal(25*0.6);
2185 //Build a transformation on the display
2186 gp_Trsf aPropellerTrsf;
2187 aPropellerTrsf.SetRotation(Ax1,angleA);
2188 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2190 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));
2191 gp_Trsf aCrankArmTrsf;
2192 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2193 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2195 TheAISContext()->UpdateCurrentViewer();
2198 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2199 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2201 myAisCrankArm ->ResetLocation();
2202 myAisPropeller->ResetLocation();
2204 myAisCrankArm -> Set(myNewCrankArm );
2205 myAisPropeller -> Set(myNewPropeller);
2207 TheAISContext()->Activate(myAisCylinderHead,0);
2208 TheAISContext()->Activate(myAisEngineBlock,0 );
2209 TheAISContext()->Activate(myAisCrankArm ,0 );
2210 TheAISContext()->Activate(myAisPropeller ,0 );
2216 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2217 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2219 TheAISContext()->UpdateCurrentViewer();
2220 a3DView()->Redraw();
2229 //==============================================================================
2230 //function : VShading
2231 //purpose : Sharpen or roughten the quality of the shading
2232 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2233 //==============================================================================
2234 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv) {
2235 Standard_Boolean HaveToSet;
2236 // Standard_Real myDevAngle;
2237 Standard_Real myDevCoef;
2238 Handle(AIS_InteractiveObject) TheAisIO;
2241 if (!strcasecmp(argv[0],"vsetshading") ) HaveToSet=Standard_True;
2242 else HaveToSet=Standard_False;
2243 if (TheAISContext()->HasOpenedContext())
2244 TheAISContext()->CloseLocalContext();
2249 myDevCoef =atof(argv[2]);
2253 TCollection_AsciiString name=argv[1];
2254 if (GetMapOfAIS().IsBound2(name ))
2256 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2257 if (TheAisIO.IsNull())
2258 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2261 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2265 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2269 TheAISContext()->Redisplay(TheAisIO);
2272 //==============================================================================
2273 //function : HaveMode
2274 //use : VActivatedModes
2275 //==============================================================================
2276 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2278 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2280 TColStd_ListOfInteger List;
2281 TheAISContext()->ActivatedModes (TheAisIO,List);
2282 TColStd_ListIteratorOfListOfInteger it;
2283 Standard_Boolean Found=Standard_False;
2284 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2285 if (it.Value()==mode ) Found=Standard_True;
2292 //==============================================================================
2293 //function : VActivatedMode
2295 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2296 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2297 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2298 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2299 // qu'un nom et qu'un mode.
2300 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2301 //==============================================================================
2302 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2304 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2307 Standard_Boolean HaveToSet;
2308 Standard_Boolean ThereIsName = Standard_False ;
2310 if(!a3DView().IsNull()){
2312 if (!strcasecmp(argv[0],"vsetam")) HaveToSet=Standard_True;
2313 else HaveToSet=Standard_False;
2315 // verification des arguments
2317 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2318 if (argc==3) ThereIsName=Standard_True;
2319 else ThereIsName=Standard_False;
2323 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2325 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2326 di<<" Fermeture du Context local"<<"\n";
2327 if (TheAISContext()->HasOpenedContext())
2328 TheAISContext()->CloseLocalContext();
2334 // IL n'y a aps de nom de shape passe en argument
2335 if (HaveToSet && !ThereIsName){
2336 Standard_Integer aMode=atoi(argv [1]);
2338 const char *cmode="???";
2341 case 0: cmode = "Shape"; break;
2342 case 1: cmode = "Vertex"; break;
2343 case 2: cmode = "Edge"; break;
2344 case 3: cmode = "Wire"; break;
2345 case 4: cmode = "Face"; break;
2346 case 5: cmode = "Shell"; break;
2347 case 6: cmode = "Solid"; break;
2348 case 7: cmode = "Compound"; break;
2351 if( !TheAISContext()->HasOpenedContext() ) {
2352 // il n'y a pas de Context local d'ouvert
2353 // on en ouvre un et on charge toutes les shapes displayees
2354 // on load tous les objets displayees et on Activate les objets de la liste
2355 AIS_ListOfInteractive ListOfIO;
2356 // on sauve dans une AISListOfInteractive tous les objets currents
2357 if (TheAISContext()->NbCurrents()>0 ){
2358 TheAISContext()->UnhilightCurrents(Standard_False);
2360 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2361 ListOfIO.Append(TheAISContext()->Current() );
2366 TheAISContext()->OpenLocalContext(Standard_False);
2367 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2370 Handle(AIS_InteractiveObject) aIO =
2371 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2373 TheAISContext()->Load(aIO,0,Standard_False);
2376 // traitement des objets qui etaient currents dans le Contexte global
2377 if (!ListOfIO.IsEmpty() ) {
2378 // il y avait des objets currents
2379 AIS_ListIteratorOfListOfInteractive iter;
2380 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2381 Handle(AIS_InteractiveObject) aIO=iter.Value();
2382 TheAISContext()->Activate(aIO,aMode);
2383 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2387 // On applique le mode a tous les objets displayes
2388 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2389 it2 (GetMapOfAIS());
2391 Handle(AIS_InteractiveObject) aIO =
2392 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2393 if (!aIO.IsNull()) {
2394 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2395 TheAISContext()->Activate(aIO,aMode);
2404 // un Context local est deja ouvert
2405 // Traitement des objets du Context local
2406 if (TheAISContext()->NbSelected()>0 ){
2407 TheAISContext()->UnhilightSelected(Standard_False);
2408 // il y a des objets selected,on les parcourt
2409 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2410 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2413 if (HaveMode(aIO,aMode) ) {
2414 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2415 TheAISContext()->Deactivate(aIO,aMode);
2418 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2419 TheAISContext()->Activate(aIO,aMode);
2425 // il n'y a pas d'objets selected
2426 // tous les objets diplayes sont traites
2427 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2430 Handle(AIS_InteractiveObject) aIO =
2431 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2432 if (!aIO.IsNull()) {
2433 if (HaveMode(aIO,aMode) ) {
2434 di<<" Mode: "<<cmode<<" OFF pour "
2435 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2436 TheAISContext()->Deactivate(aIO,aMode);
2439 di<<" Mode: "<<cmode<<" ON pour"
2440 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2441 TheAISContext()->Activate(aIO,aMode);
2449 else if (HaveToSet && ThereIsName){
2450 Standard_Integer aMode=atoi(argv [2]);
2451 Handle(AIS_InteractiveObject) aIO =
2452 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2454 if (!aIO.IsNull()) {
2455 const char *cmode="???";
2458 case 0: cmode = "Shape"; break;
2459 case 1: cmode = "Vertex"; break;
2460 case 2: cmode = "Edge"; break;
2461 case 3: cmode = "Wire"; break;
2462 case 4: cmode = "Face"; break;
2463 case 5: cmode = "Shell"; break;
2464 case 6: cmode = "Solid"; break;
2465 case 7: cmode = "Compound"; break;
2468 if( !TheAISContext()->HasOpenedContext() ) {
2469 TheAISContext()->OpenLocalContext(Standard_False);
2470 // On charge tous les objets de la map
2471 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2473 Handle(AIS_InteractiveObject) aShape=
2474 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2475 if (!aShape.IsNull())
2476 TheAISContext()->Load(aShape,0,Standard_False);
2479 TheAISContext()->Activate(aIO,aMode);
2480 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2484 // un Context local est deja ouvert
2485 if (HaveMode(aIO,aMode) ) {
2486 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2487 TheAISContext()->Deactivate(aIO,aMode);
2490 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2491 TheAISContext()->Activate(aIO,aMode);
2503 //==============================================================================
2504 // function : WhoAmI
2506 //==============================================================================
2507 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2510 if (theShape->Type()==AIS_KOI_Datum) {
2511 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2512 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2513 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2514 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2515 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2516 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2517 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2520 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2521 // AIS_Dimentions et AIS_Relations
2522 else if (theShape->Type()==AIS_KOI_Relation) {
2523 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2525 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2526 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2527 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2528 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2529 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2530 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2531 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2532 // AIS no repertorie.
2533 else {di<<" Type Unknown.";}
2539 //==============================================================================
2542 //Draw arg : vstate [nameA] ... [nameN]
2543 //==============================================================================
2544 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2546 Standard_Boolean ThereIsCurrent=Standard_False;
2547 Standard_Boolean ThereIsArguments=Standard_False;
2548 TheAISContext()->CloseAllContexts();
2550 ThereIsArguments=Standard_True;
2552 if (TheAISContext()->NbCurrents()>0 ) {
2553 ThereIsCurrent=Standard_True;
2556 // ==================
2557 // Il y a un argument
2558 // ==================
2559 if (ThereIsArguments ) {
2560 for (int cpt=1;cpt<argc;cpt++) {
2561 // Verification que lq piece est bien bindee.
2562 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2563 const Handle(AIS_InteractiveObject) theShape=
2564 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2566 if (!theShape.IsNull()) {
2567 di<<argv[cpt];WhoAmI(theShape, di);
2568 if (TheAISContext()->IsDisplayed(theShape) ) {
2569 di<<" Displayed"<<"\n";
2572 di<<" Not Displayed"<<"\n";
2577 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2581 else if (ThereIsCurrent ) {
2582 for (TheAISContext() -> InitCurrent() ;
2583 TheAISContext() -> MoreCurrent() ;
2584 TheAISContext() ->NextCurrent() )
2586 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2587 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2588 if (TheAISContext()->IsDisplayed(theShape) ) {
2589 di<<" Displayed"<<"\n";
2592 di<<" Not Displayed"<<"\n";
2598 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2600 while ( it.More() ) {
2601 Handle(AIS_InteractiveObject) theShape =
2602 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2603 if (!theShape.IsNull()) {
2604 di<<it.Key2().ToCString();
2605 WhoAmI(theShape, di);
2606 if (TheAISContext()->IsDisplayed(theShape) ) {
2607 di<<" Displayed"<<"\n";
2610 di<<" Not Displayed"<<"\n";
2621 //=======================================================================
2622 //function : PickObjects
2624 //=======================================================================
2625 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2626 const AIS_KindOfInteractive TheType,
2627 const Standard_Integer TheSignature,
2628 const Standard_Integer MaxPick)
2630 Handle(AIS_InteractiveObject) IO;
2631 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2633 // step 1: prepare the data
2635 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2636 TheAISContext()->AddFilter(F1);
2639 // step 2 : wait for the selection...
2640 // Standard_Boolean IsGood (Standard_False);
2641 // Standard_Integer NbPick(0);
2642 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2643 Standard_Integer NbPickFail(0);
2644 Standard_Integer argccc = 5;
2645 const char *bufff[] = { "A", "B", "C","D", "E" };
2646 const char **argvvv = (const char **) bufff;
2649 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2650 while(ViewerMainLoop(argccc,argvvv)){}
2651 Standard_Integer NbStored = TheAISContext()->NbSelected();
2652 if((unsigned int ) NbStored != NbPickGood)
2653 NbPickGood= NbStored;
2656 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2659 // step3 get result.
2661 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2663 Standard_Integer i(0);
2664 for(TheAISContext()->InitSelected();
2665 TheAISContext()->MoreSelected();
2666 TheAISContext()->NextSelected()){
2668 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2669 arr->SetValue(i,IO2);
2674 TheAISContext()->CloseLocalContext(curindex);
2676 return Standard_True;
2680 //=======================================================================
2681 //function : PickObject
2683 //=======================================================================
2684 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2685 const Standard_Integer TheSignature,
2686 const Standard_Integer MaxPick)
2688 Handle(AIS_InteractiveObject) IO;
2689 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2691 // step 1: prepare the data
2694 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2695 TheAISContext()->AddFilter(F1);
2698 // step 2 : wait for the selection...
2699 Standard_Boolean IsGood (Standard_False);
2700 Standard_Integer NbPick(0);
2701 Standard_Integer argccc = 5;
2702 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2703 const char **argvvv = (const char **) bufff;
2706 while(!IsGood && NbPick<= MaxPick){
2707 while(ViewerMainLoop(argccc,argvvv)){}
2708 IsGood = (TheAISContext()->NbSelected()>0) ;
2710 cout<<"Nb Pick :"<<NbPick<<endl;
2714 // step3 get result.
2716 TheAISContext()->InitSelected();
2717 IO = TheAISContext()->SelectedInteractive();
2721 TheAISContext()->CloseLocalContext(curindex);
2725 //=======================================================================
2726 //function : PickShape
2727 //purpose : First Activate the rightmode + Put Filters to be able to
2728 // pick objets that are of type <TheType>...
2729 //=======================================================================
2731 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2732 const Standard_Integer MaxPick)
2735 // step 1: prepare the data
2737 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2738 TopoDS_Shape result;
2740 if(TheType==TopAbs_SHAPE){
2741 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2742 TheAISContext()->AddFilter(F1);
2745 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2746 TheAISContext()->AddFilter(TF);
2747 TheAISContext()->ActivateStandardMode(TheType);
2752 // step 2 : wait for the selection...
2753 Standard_Boolean NoShape (Standard_True);
2754 Standard_Integer NbPick(0);
2755 Standard_Integer argccc = 5;
2756 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2757 const char **argvvv = (const char **) bufff;
2760 while(NoShape && NbPick<= MaxPick){
2761 while(ViewerMainLoop(argccc,argvvv)){}
2762 NoShape = (TheAISContext()->NbSelected()==0) ;
2764 cout<<"Nb Pick :"<<NbPick<<endl;
2767 // step3 get result.
2771 TheAISContext()->InitSelected();
2772 if(TheAISContext()->HasSelectedShape())
2773 result = TheAISContext()->SelectedShape();
2775 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2776 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2781 TheAISContext()->CloseLocalContext(curindex);
2787 //=======================================================================
2788 //function : PickShapes
2790 //=======================================================================
2791 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2792 Handle(TopTools_HArray1OfShape)& thearr,
2793 const Standard_Integer MaxPick)
2796 Standard_Integer Taille = thearr->Length();
2798 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2800 // step 1: prepare the data
2801 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2802 if(TheType==TopAbs_SHAPE){
2803 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2804 TheAISContext()->AddFilter(F1);
2807 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2808 TheAISContext()->AddFilter(TF);
2809 TheAISContext()->ActivateStandardMode(TheType);
2813 // step 2 : wait for the selection...
2815 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2816 Standard_Integer NbPickFail(0);
2817 Standard_Integer argccc = 5;
2818 const char *bufff[] = { "A", "B", "C","D", "E" };
2819 const char **argvvv = (const char **) bufff;
2822 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2823 while(ViewerMainLoop(argccc,argvvv)){}
2824 Standard_Integer NbStored = TheAISContext()->NbSelected();
2825 if((unsigned int ) NbStored != NbPickGood)
2826 NbPickGood= NbStored;
2829 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2832 // step3 get result.
2834 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2836 Standard_Integer i(0);
2837 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2839 if(TheAISContext()->HasSelectedShape())
2840 thearr->SetValue(i,TheAISContext()->SelectedShape());
2842 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2843 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2847 TheAISContext()->CloseLocalContext(curindex);
2848 return Standard_True;
2852 //=======================================================================
2853 //function : VPickShape
2855 //=======================================================================
2856 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2858 TopoDS_Shape PickSh;
2859 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2862 theType = TopAbs_SHAPE;
2864 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2865 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2866 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2867 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2868 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2869 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2870 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2873 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2874 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2876 TCollection_AsciiString name;
2879 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2881 PickSh = ViewerTest::PickShape(theType);
2890 if(!PickSh.IsNull()){
2891 nbOfSub[Standard_Integer(theType)]++;
2893 name += nameType[Standard_Integer(theType)];
2894 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2899 // si on avait une petite methode pour voir si la shape
2900 // est deja dans la Double map, ca eviterait de creer....
2901 DBRep::Set(name.ToCString(),PickSh);
2903 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2904 GetMapOfAIS().Bind(newsh, name);
2905 TheAISContext()->Display(newsh);
2906 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2909 // Plusieurs objets a picker, vite vite vite....
2912 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2913 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2914 if(ViewerTest::PickShapes(theType,arr)){
2915 for(Standard_Integer i=1;i<=NbToPick;i++){
2916 PickSh = arr->Value(i);
2917 if(!PickSh.IsNull()){
2919 nbOfSub[Standard_Integer(theType)]++;
2922 name += nameType[Standard_Integer(theType)];
2923 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2931 DBRep::Set(name.ToCString(),PickSh);
2932 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2933 GetMapOfAIS().Bind(newsh, name);
2934 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2935 TheAISContext()->Display(newsh);
2945 //=======================================================================
2946 //function : VPickObject
2947 //purpose : filters can be set (type of Object to pick....
2949 //=======================================================================
2952 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
2954 // preparation de la nomination automatique
2955 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
2956 // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
2958 /* TCollection_AsciiString name;
2960 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2962 PickSh = ViewerTest::PickObject(theType);
2971 if(!PickSh.IsNull()){
2972 nbOfSub[Standard_Integer(theType)]++;
2974 name += nameType[Standard_Integer(theType)];
2975 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2980 // si on avait une petite methode pour voir si la shape
2981 // est deja dans la Double map, ca eviterait de creer....
2982 DBRep::Set(name.ToCString(),PickSh);
2984 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2985 GetMapOfAIS().Bind(newsh, name);
2986 TheAISContext()->Display(newsh);
2987 cout<<"Nom de la shape pickee : "<<name<<endl;
2990 // Plusieurs objets a picker, vite vite vite....
2993 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2994 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2995 if(ViewerTest::PickShapes(theType,arr)){
2996 for(Standard_Integer i=1;i<=NbToPick;i++){
2997 PickSh = arr->Value(i);
2998 if(!PickSh.IsNull()){
3000 nbOfSub[Standard_Integer(theType)]++;
3003 name += nameType[Standard_Integer(theType)];
3004 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3012 DBRep::Set(name.ToCString(),PickSh);
3013 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3014 GetMapOfAIS().Bind(newsh, name);
3015 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
3016 TheAISContext()->Display(newsh);
3026 //=======================================================================
3027 //function : list of known objects
3029 //=======================================================================
3030 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3032 // 1234567890 12345678901234567 123456789
3033 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3034 TCollection_AsciiString BlankLine(64,'_');
3035 Standard_Integer i ;
3037 di<<"/n"<<BlankLine.ToCString()<<"\n";
3040 Colum[i].Center(20,' ');
3042 di<<"|"<<Colum[i].ToCString();
3045 di<<BlankLine.ToCString()<<"\n";
3047 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3048 const char ** names = GetTypeNames();
3050 TCollection_AsciiString curstring;
3051 TCollection_AsciiString curcolum[3];
3054 // les objets de type Datum..
3055 curcolum[1]+="Datum";
3057 curcolum[0].Clear();
3058 curcolum[0] += names[i];
3060 curcolum[2].Clear();
3061 curcolum[2]+=TCollection_AsciiString(i+1);
3063 for(Standard_Integer j =0;j<=2;j++){
3064 curcolum[j].Center(20,' ');
3065 di<<"|"<<curcolum[j].ToCString();
3069 di<<BlankLine.ToCString()<<"\n";
3071 // les objets de type shape
3072 curcolum[1].Clear();
3073 curcolum[1]+="Shape";
3074 curcolum[1].Center(20,' ');
3077 curcolum[0].Clear();
3078 curcolum[0] += names[7+i];
3079 curcolum[2].Clear();
3080 curcolum[2]+=TCollection_AsciiString(i);
3082 for(Standard_Integer j =0;j<=2;j++){
3083 curcolum[j].Center(20,' ');
3084 di<<"|"<<curcolum[j].ToCString();
3088 di<<BlankLine.ToCString()<<"\n";
3089 // les IO de type objet...
3090 curcolum[1].Clear();
3091 curcolum[1]+="Object";
3092 curcolum[1].Center(20,' ');
3094 curcolum[0].Clear();
3095 curcolum[0] += names[10+i];
3096 curcolum[2].Clear();
3097 curcolum[2]+=TCollection_AsciiString(i);
3099 for(Standard_Integer j =0;j<=2;j++){
3100 curcolum[j].Center(20,' ');
3101 di<<"|"<<curcolum[j].ToCString();
3105 di<<BlankLine.ToCString()<<"\n";
3106 // les contraintes et dimensions.
3107 // pour l'instant on separe juste contraintes et dimensions...
3108 // plus tard, on detaillera toutes les sortes...
3109 curcolum[1].Clear();
3110 curcolum[1]+="Relation";
3111 curcolum[1].Center(20,' ');
3113 curcolum[0].Clear();
3114 curcolum[0] += names[12+i];
3115 curcolum[2].Clear();
3116 curcolum[2]+=TCollection_AsciiString(i);
3118 for(Standard_Integer j =0;j<=2;j++){
3119 curcolum[j].Center(20,' ');
3120 di<<"|"<<curcolum[j].ToCString();
3124 di<<BlankLine.ToCString()<<"\n";
3131 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3133 if(argc!=2) return 1;
3135 AIS_KindOfInteractive TheType;
3136 Standard_Integer TheSign(-1);
3137 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3140 AIS_ListOfInteractive LIO;
3142 // en attendant l'amelioration ais pour les dimensions...
3144 Standard_Integer dimension_status(-1);
3145 if(TheType==AIS_KOI_Relation){
3146 dimension_status = TheSign ==1 ? 1 : 0;
3150 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3151 Handle(AIS_InteractiveObject) curio;
3152 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3155 if(dimension_status == -1)
3156 TheAISContext()->Erase(curio,Standard_False);
3158 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3159 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3160 (dimension_status==1 && KOD != AIS_KOD_NONE))
3161 TheAISContext()->Erase(curio,Standard_False);
3164 TheAISContext()->UpdateCurrentViewer();
3167 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3169 if(argc!=2) return 1;
3171 AIS_KindOfInteractive TheType;
3172 Standard_Integer TheSign(-1);
3173 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3175 // en attendant l'amelioration ais pour les dimensions...
3177 Standard_Integer dimension_status(-1);
3178 if(TheType==AIS_KOI_Relation){
3179 dimension_status = TheSign ==1 ? 1 : 0;
3183 AIS_ListOfInteractive LIO;
3184 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3185 Handle(AIS_InteractiveObject) curio;
3186 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3188 if(dimension_status == -1)
3189 TheAISContext()->Display(curio,Standard_False);
3191 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3192 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3193 (dimension_status==1 && KOD != AIS_KOD_NONE))
3194 TheAISContext()->Display(curio,Standard_False);
3199 TheAISContext()->UpdateCurrentViewer();
3203 //==============================================================================
3204 //function : VSetTransMode
3206 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3207 //==============================================================================
3209 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3210 // Verification des arguments
3211 if ( a3DView().IsNull() ) {
3212 ViewerTest::ViewerInit();
3213 di << "La commande vinit n'a pas ete appele avant" << "\n";
3216 if ( argc < 3 || argc > 8 ) {
3217 di << argv[0] << " Invalid number of arguments" << "\n";
3221 TCollection_AsciiString shapeName;
3222 shapeName = argv[1];
3223 Standard_Integer persFlag1 = atoi(argv[2]);
3224 Standard_Integer persFlag2 = 0;
3225 Standard_Integer persFlag3 = 0;
3226 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3227 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3228 persFlag2 = atoi(argv[3]);
3230 if ( argc == 5 || argc == 8 ) {
3231 persFlag3 = atoi(argv[4]);
3234 origin.SetX( atof(argv[argc - 3]) );
3235 origin.SetY( atof(argv[argc - 2]) );
3236 origin.SetZ( atof(argv[argc - 1]) );
3239 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3240 Standard_Boolean IsDatum = Standard_False;
3241 Handle(Standard_Transient) anObj;
3243 anObj = GetMapOfAIS().Find2(shapeName);
3244 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3245 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3246 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3247 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3248 di << argv[0] << " All persistence modifiers were removed" << "\n";
3251 di << argv[0] << " Wrong object type" << "\n";
3254 } else { // Create the AIS_Shape from a name
3255 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3256 if ( !aShape.IsNull() ) {
3257 GetMapOfAIS().Bind( aShape, shapeName );
3258 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3259 TheAISContext()->Display( aShape, Standard_False );
3261 di << argv[0] << " Object not found" << "\n";
3266 // Upadate the screen and redraw the view
3267 TheAISContext()->UpdateCurrentViewer();
3271 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3274 BRep_Builder builder;
3276 BRepTools::Read(shape, s, builder);
3277 DBRep::Set(a[1], shape);
3278 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3279 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3283 //============================================================================
3284 #include <AIS2D_InteractiveContext.hxx>
3285 #include <HLRAlgo_Projector.hxx>
3286 #include <Prs3d_Projector.hxx>
3287 #include <AIS2D_ProjShape.hxx>
3288 #include <gp_Ax2.hxx>
3290 Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3293 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3294 /////////////////////
3295 TopoDS_Shape aShape = DBRep::Get(a[1]);
3296 aContext2D->EraseAll(Standard_True);
3297 Standard_Integer aPolyAlgo = 0;
3298 Standard_Boolean IsPoly = Standard_False;
3299 gp_Ax2 anAx2 = gp::XOY();
3301 //if(n > 2) aPolyAlgo = atoi(a[2]);
3303 //IsPoly = aPolyAlgo > 0;
3305 TopoDS_Shape aResult = aShape;
3310 Standard_Real x = atof(a[2]);
3311 Standard_Real y = atof(a[3]);
3312 Standard_Real z = atof(a[4]);
3314 Standard_Real dx = atof(a[5]);
3315 Standard_Real dy = atof(a[6]);
3316 Standard_Real dz = atof(a[7]);
3318 Standard_Real dx1 = atof(a[8]);
3319 Standard_Real dy1 = atof(a[9]);
3320 Standard_Real dz1 = atof(a[10]);
3322 gp_Pnt anOrigin (x, y, z);
3323 gp_Dir aNormal (dx, dy, dz);
3324 gp_Dir aDX (dx1, dy1, dz1);
3325 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3329 HLRAlgo_Projector aProjector(anAx2);
3331 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3333 //aProjector = aProjector_t.Projector();
3335 Handle(AIS2D_ProjShape) myDisplayableShape =
3336 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3338 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3339 Standard_False, Standard_True, Standard_False);
3341 myDisplayableShape->Add( aResult );
3344 aContext2D->Display( myDisplayableShape,Standard_True );
3345 aContext2D->UpdateCurrentViewer();
3350 Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3353 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3354 /////////////////////
3355 TopoDS_Shape aShape = DBRep::Get(a[1]);
3356 aContext2D->EraseAll(Standard_True);
3357 Standard_Integer aPolyAlgo = 0;
3358 Standard_Boolean IsPoly = Standard_True;
3359 gp_Ax2 anAx2 = gp::XOY();
3361 //if(n > 2) aPolyAlgo = atoi(a[2]);
3363 //IsPoly = aPolyAlgo > 0;
3365 TopoDS_Shape aResult = aShape;
3370 Standard_Real x = atof(a[2]);
3371 Standard_Real y = atof(a[3]);
3372 Standard_Real z = atof(a[4]);
3374 Standard_Real dx = atof(a[5]);
3375 Standard_Real dy = atof(a[6]);
3376 Standard_Real dz = atof(a[7]);
3378 Standard_Real dx1 = atof(a[8]);
3379 Standard_Real dy1 = atof(a[9]);
3380 Standard_Real dz1 = atof(a[10]);
3382 gp_Pnt anOrigin (x, y, z);
3383 gp_Dir aNormal (dx, dy, dz);
3384 gp_Dir aDX (dx1, dy1, dz1);
3385 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3389 HLRAlgo_Projector aProjector(anAx2);
3391 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3393 //aProjector = aProjector_t.Projector();
3395 Handle(AIS2D_ProjShape) myDisplayableShape =
3396 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3398 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3399 Standard_False, Standard_True, Standard_False);
3401 myDisplayableShape->Add( aResult );
3404 aContext2D->Display( myDisplayableShape,Standard_True );
3405 aContext2D->UpdateCurrentViewer();
3410 //==============================================================================
3411 //function : ViewerTest::Commands
3412 //purpose : Add all the viewer command in the Draw_Interpretor
3413 //==============================================================================
3415 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3417 ViewerTest::ViewerCommands(theCommands);
3418 ViewerTest::RelationCommands(theCommands);
3419 ViewerTest::ObjectCommands(theCommands);
3420 ViewerTest::FilletCommands(theCommands);
3421 ViewerTest::VoxelCommands(theCommands);
3423 const char *group = "AIS_Display";
3427 theCommands.Add("vdisplay",
3428 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3429 __FILE__,VDisplay2,group);
3431 theCommands.Add("verase",
3432 "verase : verase2 [name1] ... [name n] ",
3433 __FILE__,VErase2,group);
3435 theCommands.Add("vdonly",
3436 "vdonly : vdonly2 [name1] ... [name n]",
3437 __FILE__,VDonly2,group);
3439 theCommands.Add("vdisplayall",
3440 "vdisplayall : vdisplayall",
3441 __FILE__,VDisplayAll,group);
3443 theCommands.Add("veraseall",
3444 "veraseall : veraseall ",
3445 __FILE__,VEraseAll,group);
3447 theCommands.Add("verasetype",
3448 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3449 __FILE__,VEraseType,group);
3451 theCommands.Add("vdisplaytype",
3452 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3453 __FILE__,VDisplayType,group);
3455 theCommands.Add("vdisplaymode",
3456 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3457 __FILE__,VDispMode,group);
3459 theCommands.Add("verasemode",
3460 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3461 __FILE__,VDispMode,group);
3463 theCommands.Add("vsetdispmode",
3464 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3465 __FILE__,VDispMode,group);
3467 theCommands.Add("vunsetdispmode",
3468 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3469 __FILE__,VDispMode,group);
3471 theCommands.Add("vdir",
3473 __FILE__,VDebug,group);
3475 theCommands.Add("vdump",
3476 "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n\t\t: Dump contents of viewer window to PNG, BMP, JPEG or GIF file",
3477 __FILE__,VDump,group);
3479 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3480 __FILE__,VSubInt,group);
3482 theCommands.Add("vsetcolor",
3483 "vsetcolor : vsetcolor [name of shape] ColorName",
3484 __FILE__,VColor2,group);
3486 theCommands.Add("vunsetcolor",
3487 "vunsetcolor : vunsetcolor [name of shape] ",
3488 __FILE__,VColor2,group);
3490 theCommands.Add("vsettransparency",
3491 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3492 __FILE__,VTransparency,group);
3494 theCommands.Add("vunsettransparency",
3495 "vunsettransparency : vtransparency [name of shape]",
3496 __FILE__,VTransparency,group);
3498 theCommands.Add("vsetmaterial",
3499 "vmaterial : vmaterial [name of shape] MaterialName",
3500 __FILE__,VMaterial,group);
3502 theCommands.Add("vunsetmaterial",
3503 "vmaterial : vmaterial [name of shape]",
3504 __FILE__,VMaterial,group);
3506 theCommands.Add("vsetwidth",
3507 "vsetwidth : vwidth [name of shape] width(0->10)",
3508 __FILE__,VWidth,group);
3510 theCommands.Add("vunsetwidth",
3511 "vunsetwidth : vwidth [name of shape]",
3512 __FILE__,VWidth,group);
3514 theCommands.Add("vardis",
3515 "vardis : display activeareas",
3516 __FILE__,VDispAreas,group);
3518 theCommands.Add("varera",
3519 "varera : erase activeareas",
3520 __FILE__,VClearAreas,group);
3522 theCommands.Add("vsensdis",
3523 "vardisp : display active entities",
3524 __FILE__,VDispSensi,group);
3525 theCommands.Add("vsensera",
3526 "vardisp : erase active entities",
3527 __FILE__,VClearSensi,group);
3529 theCommands.Add("vperf",
3530 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3531 __FILE__,VPerf,group);
3533 theCommands.Add("vanimation",
3534 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3535 __FILE__,VAnimation,group);
3537 theCommands.Add("vsetshading",
3538 "vsetshading : vsetshading name Quality(default=0.0008) ",
3539 __FILE__,VShading,group);
3541 theCommands.Add("vunsetshading",
3542 "vunsetshading :vunsetshading name ",
3543 __FILE__,VShading,group);
3545 theCommands.Add("vtexture",
3546 "'vtexture NameOfShape TextureFile' \n \
3547 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3548 or 'vtexture NameOfShape ?' to list available textures\n \
3549 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3550 __FILE__,VTexture,group);
3552 theCommands.Add("vtexscale",
3553 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3554 or 'vtexscale NameOfShape ScaleUV' \n \
3555 or 'vtexscale NameOfShape' to disable scaling\n ",
3556 __FILE__,VTexture,group);
3558 theCommands.Add("vtexorigin",
3559 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3560 or 'vtexorigin NameOfShape UVOrigin' \n \
3561 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3562 __FILE__,VTexture,group);
3564 theCommands.Add("vtexrepeat",
3565 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3566 or 'vtexrepeat NameOfShape UVRepeat \n \
3567 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3570 theCommands.Add("vtexdefault",
3571 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3574 theCommands.Add("vsetam",
3575 "vsetActivatedModes: vsetam mode(1->7) ",
3576 __FILE__,VActivatedMode,group);
3578 theCommands.Add("vunsetam",
3579 "vunsetActivatedModes: vunsetam ",
3580 __FILE__,VActivatedMode,group);
3582 theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
3583 __FILE__,VState,group);
3585 theCommands.Add("vpickshapes",
3586 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3587 __FILE__,VPickShape,group);
3589 theCommands.Add("vtypes",
3590 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3593 theCommands.Add("vsettransmode",
3594 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3595 __FILE__,VSetTransMode,group);
3597 theCommands.Add("vr", "vr : reading of the shape",
3598 __FILE__,vr, group);
3600 theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3601 theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3605 //=====================================================================
3606 //========================= for testing Draft and Rib =================
3607 //=====================================================================
3608 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3609 #include <DBRep.hxx>
3610 #include <TopoDS_Face.hxx>
3611 #include <gp_Pln.hxx>
3612 #include <AIS_KindOfSurface.hxx>
3613 #include <BRepOffsetAPI_DraftAngle.hxx>
3614 #include <Precision.hxx>
3615 #include <BRepAlgo.hxx>
3616 #include <OSD_Environment.hxx>
3617 #include <DrawTrSurf.hxx>
3618 //#include <DbgTools.hxx>
3619 //#include <FeatAlgo_MakeLinearForm.hxx>
3624 //=======================================================================
3625 //function : IsValid
3627 //=======================================================================
3628 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3629 const TopoDS_Shape& theResult,
3630 const Standard_Boolean closedSolid,
3631 const Standard_Boolean GeomCtrl)
3633 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3634 TCollection_AsciiString checkValid = check.Value();
3635 Standard_Boolean ToCheck = Standard_True;
3636 if (!checkValid.IsEmpty()) {
3638 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3640 if ( checkValid=="true" || checkValid=="TRUE" ) {
3641 ToCheck= Standard_False;
3645 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3648 Standard_Boolean IsValid = Standard_True;
3650 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3655 //===============================================================================
3656 // TDraft : test draft, uses AIS Viewer
3657 // Solid Face Plane Angle Reverse
3658 //===============================================================================
3659 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3661 if (argc < 5) return 1;
3662 // argv[1] - TopoDS_Shape Solid
3663 // argv[2] - TopoDS_Shape Face
3664 // argv[3] - TopoDS_Shape Plane
3665 // argv[4] - Standard_Real Angle
3666 // argv[5] - Standard_Integer Reverse
3668 // sprintf(prefix, argv[1]);
3669 Standard_Real anAngle = 0;
3670 Standard_Boolean Rev = Standard_False;
3671 Standard_Integer rev = 0;
3672 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3673 TopoDS_Shape face = GetShapeFromName(argv[2]);
3674 TopoDS_Face Face = TopoDS::Face(face);
3675 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3676 if (Plane.IsNull ()) {
3677 di << "TEST : Plane is NULL" << "\n";
3680 anAngle = atof(argv[4]);
3681 anAngle = 2*PI * anAngle / 360.0;
3683 Handle( Geom_Surface )aSurf;
3684 AIS_KindOfSurface aSurfType;
3685 Standard_Real Offset;
3687 if(argc > 4) { // == 5
3688 rev = atoi(argv[5]);
3689 Rev = (rev)? Standard_True : Standard_False;
3692 TopoDS_Face face2 = TopoDS::Face(Plane);
3693 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3695 di << "TEST : Can't find plane" << "\n";
3699 aDir = aPln.Axis().Direction();
3702 if (Plane.Orientation() == TopAbs_REVERSED)
3704 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3706 BRepOffsetAPI_DraftAngle Draft (Solid);
3708 if(Abs(anAngle)< Precision::Angular()) {
3709 di << "TEST : NULL angle" << "\n";
3712 if(Rev) anAngle = - anAngle;
3713 Draft.Add (Face, aDir, anAngle, aPln);
3715 if (!Draft.IsDone()) {
3716 di << "TEST : Draft Not DONE " << "\n";
3719 TopTools_ListOfShape Larg;
3721 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3722 di << "TEST : DesignAlgo returns Not valid" << "\n";
3726 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3727 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3729 if ( !ais.IsNull() ) {
3730 ais->SetColor(DEFAULT_COLOR);
3731 ais->SetMaterial(DEFAULT_MATERIAL);
3732 // Display the AIS_Shape without redraw
3733 Ctx->Display(ais, Standard_False);
3735 const char *Name = "draft1";
3736 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3738 Handle(AIS_InteractiveObject) an_object =
3739 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3740 if (!an_object.IsNull()) {
3741 Ctx->Remove(an_object,
3743 GetMapOfAIS().UnBind2(Name) ;
3746 GetMapOfAIS().Bind(ais, Name);
3747 // DBRep::Set("draft", ais->Shape());
3749 Ctx->Display(ais, Standard_True);
3755 //============================================================================
3757 //============================================================================
3758 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3761 DrawTrSurf::BasicCommands(theCommands);
3762 const char* group = "Check Features Operations commands";
3764 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3766 &TDraft,group); //Draft_Modification
3769 //==============================================================================
3770 // ViewerTest::Factory
3771 //==============================================================================
3772 void ViewerTest::Factory(Draw_Interpretor& theDI)
3774 // definition of Viewer Command
3775 ViewerTest::Commands(theDI);
3776 ViewerTest::AviCommands(theDI);
3777 Viewer2dTest::Commands(theDI);
3779 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3783 // Declare entry point PLUGINFACTORY