1 // File: ViewerTest.cxx
2 // Created: Wed Jul 23 14:14:01 1997
3 // Author: Henri JEANNIN
4 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
6 // Modified by Robert Coublanc [nov 16-17-18 1998]
7 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
8 // ViewerTest_ObjectCommands.cxx
9 // ViewerTest_RelationCommands.cxx
10 // -add Functions and commands for interactive selection of shapes and objects
11 // in AIS Viewers. (PickShape(s), PickObject(s),
13 #include <Standard_Stream.hxx>
15 #include <ViewerTest.hxx>
16 #include <TopLoc_Location.hxx>
17 #include <TopTools_HArray1OfShape.hxx>
18 #include <TColStd_HArray1OfTransient.hxx>
19 #include <OSD_Directory.hxx>
20 #include <OSD_File.hxx>
21 #include <OSD_Path.hxx>
22 #include <OSD_Timer.hxx>
23 #include <Geom_Axis2Placement.hxx>
24 #include <Geom_Axis1Placement.hxx>
25 #include <gp_Trsf.hxx>
26 #include <TopExp_Explorer.hxx>
27 #include <BRepAdaptor_Curve.hxx>
28 #include <StdSelect_ShapeTypeFilter.hxx>
30 #include <AIS_InteractiveObject.hxx>
31 #include <AIS_Trihedron.hxx>
32 #include <AIS_Axis.hxx>
33 #include <AIS_Relation.hxx>
34 #include <AIS_TypeFilter.hxx>
35 #include <AIS_SignatureFilter.hxx>
36 #include <AIS_ListOfInteractive.hxx>
37 #include <AIS_ListIteratorOfListOfInteractive.hxx>
38 #include <Image_PixMap.hxx>
48 #include <Draw_Interpretor.hxx>
49 #include <TCollection_AsciiString.hxx>
50 #include <Draw_PluginMacro.hxx>
51 #include <ViewerTest.hxx>
52 #include <Viewer2dTest.hxx>
54 // avoid warnings on 'extern "C"' functions returning C++ classes
56 #define _CRT_SECURE_NO_DEPRECATE
57 #pragma warning(4:4190)
58 #pragma warning (disable:4996)
61 #include <NIS_InteractiveContext.hxx>
62 #include <NIS_Triangulated.hxx>
63 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
65 //=======================================================================
66 //function : GetColorFromName
67 //purpose : get the Quantity_NameOfColor from a string
68 //=======================================================================
70 #include <Quantity_NameOfColor.hxx>
71 #include <Quantity_Color.hxx>
72 #include <Quantity_NameOfColor.hxx>
74 #include <Graphic3d_NameOfMaterial.hxx>
76 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
77 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
79 static Quantity_NameOfColor GetColorFromName( const char *name )
81 Quantity_NameOfColor ret = DEFAULT_COLOR;
83 Standard_Boolean Found = Standard_False;
84 Standard_CString colstring;
85 for(Standard_Integer i=0;i<=514 && !Found;i++)
87 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
88 if (!strcasecmp(name,colstring)) {
89 ret = (Quantity_NameOfColor)i;
90 Found = Standard_True;
97 //=======================================================================
98 //function : GetMaterialFromName
99 //purpose : get the Graphic3d_NameOfMaterial from a string
100 //=======================================================================
102 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
104 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
106 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
107 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
108 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
109 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
110 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
111 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
112 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
113 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
114 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
115 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
116 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
117 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
118 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
119 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
120 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
121 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
122 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
123 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
124 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
125 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
130 //=======================================================================
131 //function : GetTypeNames
133 //=======================================================================
134 static const char** GetTypeNames()
136 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
137 "Shape","ConnectedShape","MultiConn.Shape",
138 "ConnectedInter.","MultiConn.",
139 "Constraint","Dimension"};
140 static const char** ThePointer = names;
144 //=======================================================================
145 //function : GetTypeAndSignfromString
147 //=======================================================================
148 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
150 const char ** thefullnames = GetTypeNames();
151 Standard_Integer index(-1);
153 for(Standard_Integer i=0;i<=13 && index==-1;i++)
154 if(!strcasecmp(name,thefullnames[i]))
158 TheType = AIS_KOI_None;
164 TheType = AIS_KOI_Datum;
168 TheType = AIS_KOI_Shape;
172 TheType = AIS_KOI_Object;
176 TheType = AIS_KOI_Relation;
185 #include <Draw_Interpretor.hxx>
187 #include <Draw_Appli.hxx>
191 #include <TCollection_AsciiString.hxx>
192 #include <V3d_Viewer.hxx>
193 #include <V3d_View.hxx>
196 #include <AIS_InteractiveContext.hxx>
197 #include <AIS_Shape.hxx>
198 #include <AIS_TexturedShape.hxx>
199 #include <AIS_DisplayMode.hxx>
200 #include <TColStd_MapOfInteger.hxx>
201 #include <AIS_MapOfInteractive.hxx>
202 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
203 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
204 #include <ViewerTest_EventManager.hxx>
206 #include <TopoDS_Solid.hxx>
207 #include <BRepTools.hxx>
208 #include <BRep_Builder.hxx>
209 #include <TopAbs_ShapeEnum.hxx>
211 #include <TopoDS.hxx>
212 #include <BRep_Tool.hxx>
215 #include <Draw_Window.hxx>
216 #include <AIS_ListIteratorOfListOfInteractive.hxx>
217 #include <AIS_ListOfInteractive.hxx>
218 #include <AIS_DisplayMode.hxx>
219 #include <TopTools_ListOfShape.hxx>
220 #include <BRepOffsetAPI_MakeThickSolid.hxx>
221 #include <BRepOffset.hxx>
224 //==============================================================================
225 //function : GetTypeNameFromShape
226 //purpose : get the shape type as a string from a shape
227 //==============================================================================
229 static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
230 { const char *ret = "????";
232 if ( aShape.IsNull() ) ret = "Null Shape";
234 switch ( aShape.ShapeType() ) {
235 case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
236 case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
237 case TopAbs_SOLID : ret = "SOLID" ; break;
238 case TopAbs_SHELL : ret = "SHELL" ; break;
239 case TopAbs_FACE : ret = "FACE" ; break;
240 case TopAbs_WIRE : ret = "WIRE" ; break;
241 case TopAbs_EDGE : ret = "EDGE" ; break;
242 case TopAbs_VERTEX : ret = "VERTEX" ; break;
243 case TopAbs_SHAPE : ret = "SHAPE" ; break;
247 //==============================================================================
248 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
249 //==============================================================================
250 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
251 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
256 //==============================================================================
257 //function : VDisplayAISObject
258 //purpose : register interactive object in the map of AIS objects;
259 // if other object with such name already registered, it will be kept
260 // or replaced depending on value of <theReplaceIfExists>,
261 // if "true" - the old object will be cleared from AIS context;
262 // returns Standard_True if <theAISObj> registered in map;
263 //==============================================================================
264 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
265 const Handle(AIS_InteractiveObject)& theAISObj,
266 Standard_Boolean theReplaceIfExists = Standard_True)
268 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
269 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
270 if (aContextAIS.IsNull())
272 std::cout << "AIS context is not available.\n";
273 return Standard_False;
276 if (aMap.IsBound2 (theName))
278 if (!theReplaceIfExists)
280 std::cout << "Other interactive object has been already "
281 << "registered with name: " << theName << ".\n"
282 << "Please use another name.\n";
283 return Standard_False;
286 // stop displaying object
287 Handle(AIS_InteractiveObject) anOldObj =
288 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
290 if (!anOldObj.IsNull())
291 aContextAIS->Clear (anOldObj, Standard_True);
293 // remove name and old object from map
294 aMap.UnBind2 (theName);
297 // unbind AIS object if was bound with another name
298 aMap.UnBind1 (theAISObj);
300 // can be registered without rebinding
301 aMap.Bind (theAISObj, theName);
302 aContextAIS->Display (theAISObj, Standard_True);
303 return Standard_True;
306 static TColStd_MapOfInteger theactivatedmodes(8);
307 static TColStd_ListOfTransient theEventMgrs;
309 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
310 const Handle(AIS_InteractiveContext)& Ctx)
312 theEventMgrs.Clear();
313 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
316 static Handle(V3d_View)& a3DView(){
317 static Handle(V3d_View) Viou;
321 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
322 static Handle(AIS_InteractiveContext) aContext;
326 Handle(V3d_View) ViewerTest::CurrentView()
330 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
335 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
337 static Handle(NIS_InteractiveContext) aContext;
338 if (aContext.IsNull()) {
339 aContext = new NIS_InteractiveContext;
340 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
345 Handle(AIS_InteractiveContext) ViewerTest::GetAISContext()
347 return TheAISContext();
350 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
352 TheAISContext() = aCtx;
353 ViewerTest::ResetEventManager();
356 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
358 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
361 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
363 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
367 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
368 theEventMgrs.Prepend(EM);
371 void ViewerTest::UnsetEventManager()
373 theEventMgrs.RemoveFirst();
377 void ViewerTest::ResetEventManager()
379 const Handle(NIS_View) aView =
380 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
381 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
384 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
386 Handle(ViewerTest_EventManager) EM;
387 if(theEventMgrs.IsEmpty()) return EM;
388 Handle(Standard_Transient) Tr = theEventMgrs.First();
389 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
394 //=======================================================================
395 //function : Get Context and active viou..
397 //=======================================================================
398 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
399 Handle(V3d_View)& Viou)
401 Ctx = ViewerTest::GetAISContext();
404 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
405 Vwr->InitActiveViews();
406 if(Vwr->MoreActiveViews())
407 Viou = Vwr->ActiveView();
412 //==============================================================================
413 //function : GetShapeFromName
414 //purpose : Compute an Shape from a draw variable or a file name
415 //==============================================================================
417 static TopoDS_Shape GetShapeFromName(const char* name)
419 TopoDS_Shape S = DBRep::Get(name);
422 BRep_Builder aBuilder;
423 BRepTools::Read( S, name, aBuilder);
428 //==============================================================================
429 //function : GetShapeFromName
430 //purpose : Compute an Shape from a draw variable or a file name
431 //==============================================================================
434 static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
436 TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
440 //==============================================================================
441 //function : GetAISShapeFromName
442 //purpose : Compute an AIS_Shape from a draw variable or a file name
443 //==============================================================================
444 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
446 Handle(AIS_Shape) retsh;
448 if(GetMapOfAIS().IsBound2(name)){
449 const Handle(AIS_InteractiveObject) IO =
450 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
452 if(IO->Type()==AIS_KOI_Shape)
453 if(IO->Signature()==0){
454 retsh = *((Handle(AIS_Shape)*)&IO);
457 cout << "an Object which is not an AIS_Shape "
458 "already has this name!!!"<<endl;
464 TopoDS_Shape S = GetShapeFromName(name);
466 retsh = new AIS_Shape(S);
472 //==============================================================================
474 //purpose : Remove all the object from the viewer
475 //==============================================================================
476 void ViewerTest::Clear()
478 if ( !a3DView().IsNull() ) {
479 if (TheAISContext()->HasOpenedContext())
480 TheAISContext()->CloseLocalContext();
481 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
482 while ( it.More() ) {
483 cout << "Remove " << it.Key2() << endl;
484 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
485 const Handle(AIS_InteractiveObject) anObj =
486 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
487 TheAISContext()->Remove(anObj,Standard_False);
488 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
489 const Handle(NIS_InteractiveObject) anObj =
490 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
491 TheNISContext()->Remove(anObj);
495 TheAISContext()->UpdateCurrentViewer();
496 // TheNISContext()->UpdateViews();
497 GetMapOfAIS().Clear();
501 //==============================================================================
502 //function : StandardModesActivation
503 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
505 //==============================================================================
506 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
508 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
510 if (TheAISContext()->HasOpenedContext())
511 aContext->CloseLocalContext();
514 if(!aContext->HasOpenedContext()) {
515 // To unhilight the preselected object
516 aContext->UnhilightCurrents(Standard_False);
517 // Open a local Context in order to be able to select subshape from
518 // the selected shape if any or for all if there is no selection
519 if (!aContext->FirstCurrentObject().IsNull()){
520 aContext->OpenLocalContext(Standard_False);
522 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
523 aContext->Load( aContext->Current(),-1,Standard_True);
527 aContext->OpenLocalContext();
530 const char *cmode="???";
533 case 0: cmode = "Shape"; break;
534 case 1: cmode = "Vertex"; break;
535 case 2: cmode = "Edge"; break;
536 case 3: cmode = "Wire"; break;
537 case 4: cmode = "Face"; break;
538 case 5: cmode = "Shell"; break;
539 case 6: cmode = "Solid"; break;
540 case 7: cmode = "Compound"; break;
543 if(theactivatedmodes.Contains(mode))
545 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
546 theactivatedmodes.Remove(mode);
547 cout<<"Mode "<< cmode <<" OFF"<<endl;
551 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
552 theactivatedmodes.Add(mode);
553 cout<<"Mode "<< cmode << " ON" << endl;
558 //==============================================================================
559 //function : SelectFromContext
560 //purpose : pick / select an object from the last MoveTo() on a
562 //==============================================================================
564 Handle(AIS_InteractiveObject) Select(Standard_Integer argc,
566 Standard_Boolean shift,
567 Standard_Boolean pick )
569 Handle(AIS_InteractiveObject) ret;
570 Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
577 const Handle(AIS_InteractiveContext) aContext = EM->Context();
579 if ( !aContext->HasOpenedContext() ) {
580 aContext->InitCurrent();
581 while ( aContext->MoreCurrent() ) {
582 Handle(AIS_InteractiveObject) aisPickedShape =
583 Handle(AIS_InteractiveObject)::DownCast(aContext->Current());
586 const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
587 // const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
588 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
590 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape);
591 if(!TheRealSh.IsNull()){
592 cout << "Current is " << name
593 << " (" << GetTypeNameFromShape(TheRealSh->Shape())
596 ret = aisPickedShape;
597 if(!TheRealSh.IsNull()){
598 if ( pick && argc > 4 ) {
599 DBRep::Set(argv[4], TheRealSh->Shape());
602 aContext->NextCurrent();
606 // A LocalContext is opened, the use xxxxSelected()
607 // to select an object and its SubShape
608 aContext->InitSelected();
609 while ( aContext->MoreSelected() ) {
610 if ( !aContext->HasSelectedShape() ) {
613 TopoDS_Shape PickedShape = aContext->SelectedShape();
614 if ( pick && argc > 5 ) {
615 DBRep::Set(argv[5], PickedShape);
619 if ( aContext->Interactive().IsNull() ) {
620 cout << "??? (No InteractiveObject selected)" << endl;
623 Handle(AIS_InteractiveObject) aisPicked =
624 Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive());
626 Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked);
630 const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
631 // const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
632 GetMapOfAIS().Find1(aisPicked).ToCString() :
635 if(!aisPickedShape.IsNull()){
636 if ( pick && argc > 4 ) {
637 // Create a draw variable to store the wohole shape
639 DBRep::Set(argv[4], aisPickedShape->Shape());
642 cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape())
646 // Goto the next selected object
647 aContext->NextSelected();
653 //==============================================================================
654 //function : DetectedFromContext
655 //purpose : hilight dynamicaly an object from the last MoveTo() on a
657 //==============================================================================
658 Handle(AIS_InteractiveObject) DetectedFromContext(
659 Handle(AIS_InteractiveContext) aContext )
661 Handle(AIS_InteractiveObject) ret;
662 if ( aContext->HasDetected() ) {
663 if ( !aContext->HasDetectedShape() ) {
664 //No SubShape selected
667 // Get the detected SubShape
668 TopoDS_Shape PickedShape = aContext->DetectedShape();
670 if ( !aContext->DetectedInteractive().IsNull() ) {
671 Handle(AIS_InteractiveObject) aisPickedShape =
672 Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive());
673 ret = aisPickedShape;
680 //==============================================================================
681 //function : VDispAreas,VDispSensitive,...
682 //purpose : Redraw the view
684 //==============================================================================
685 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
688 Handle(AIS_InteractiveContext) Ctx;
689 Handle(V3d_View) Viou;
690 GetCtxAndView(Ctx,Viou);
691 Ctx->DisplayActiveAreas(Viou);
694 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
696 Handle(AIS_InteractiveContext) Ctx;
697 Handle(V3d_View) Viou;
698 GetCtxAndView(Ctx,Viou);
699 Ctx->ClearActiveAreas(Viou);
703 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
705 Handle(AIS_InteractiveContext) Ctx;
706 Handle(V3d_View) Viou;
707 GetCtxAndView(Ctx,Viou);
708 Ctx->DisplayActiveSensitive(Viou);
712 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
714 Handle(AIS_InteractiveContext) Ctx;
715 Handle(V3d_View) Viou;
716 GetCtxAndView(Ctx,Viou);
717 Ctx->ClearActiveSensitive(Viou);
721 //==============================================================================
723 //purpose : To list the displayed object with their attributes
725 //==============================================================================
726 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
727 { if ( !a3DView().IsNull() ) {
728 di << "List of object in the viewer :" << "\n";
730 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
732 while ( it.More() ) {
733 di << "\t" << it.Key2().ToCString() << "\n";
741 //==============================================================================
743 //purpose : To dump the active view snapshot to image file
744 //Draw arg : Picture file name with extension corresponding to desired format
745 //==============================================================================
746 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
750 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
754 Image_TypeOfImage aBufferType = Image_TOI_RGB;
758 TCollection_AsciiString aBuffTypeStr (argv[2]);
759 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
761 aBufferType = Image_TOI_RGB;
763 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
765 aBufferType = Image_TOI_RGBA;
767 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
769 aBufferType = Image_TOI_FLOAT;
773 Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0;
774 Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
776 Handle(AIS_InteractiveContext) IC;
777 Handle(V3d_View) view;
778 GetCtxAndView (IC, view);
781 if (aWidth > 0 && aHeight > 0)
783 return view->ToPixMap (aWidth, aHeight, aBufferType)->Dump (argv[1]) ? 0 : 1;
787 return view->Dump (argv[1], aBufferType) ? 0 : 1;
792 di << "Cannot find an active viewer/view" << "\n";
798 //==============================================================================
799 //function : Displays,Erase...
802 //==============================================================================
803 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
804 const Standard_Integer Mode,
805 const Standard_Integer TypeOfOperation,
806 const Standard_Boolean Upd)
808 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
810 switch(TypeOfOperation){
812 Ctx->Display(IO,Mode,Upd);
815 Ctx->Erase(IO,Mode,Upd);
820 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
822 Ctx->SetDisplayMode(IO,Mode,Upd);
827 Ctx->SetDisplayMode(0,Upd);
829 Ctx->UnsetDisplayMode(IO,Upd);
836 //=======================================================================
839 //=======================================================================
840 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
843 TCollection_AsciiString name;
846 // display others presentations
847 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
848 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
849 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
850 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
852 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
854 //unset displaymode.. comportement particulier...
855 if(TypeOfOperation==4){
857 if(Ctx->NbCurrents()==0 ||
858 Ctx->NbSelected()==0){
859 Handle(AIS_InteractiveObject) IO;
860 VwrTst_DispErase(IO,-1,4,Standard_False);
862 else if(!Ctx->HasOpenedContext()){
863 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
864 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
867 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
868 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
869 Ctx->UpdateCurrentViewer();
872 Handle(AIS_InteractiveObject) IO;
874 if(GetMapOfAIS().IsBound2(name)){
875 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
877 VwrTst_DispErase(IO,-1,4,Standard_True);
882 Standard_Integer Dmode = atoi(argv[1]);
883 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
884 Handle(AIS_InteractiveObject) IO;
885 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
887 if(!Ctx->HasOpenedContext()){
888 // set/unset display mode sur le Contexte...
889 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
890 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
892 Ctx->UpdateCurrentViewer();
895 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
896 Ctx->Display(Ctx->Interactive(),Dmode);
900 Handle(AIS_InteractiveObject) IO;
902 if(GetMapOfAIS().IsBound2(name))
903 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
905 VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
911 //=======================================================================
914 //=======================================================================
915 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
917 if(argc==1) return 1;
918 Standard_Integer On = atoi(argv[1]);
919 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
923 if(!Ctx->HasOpenedContext()){
924 di<<"sub intensite ";
927 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
928 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
930 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
932 di <<"passage dans off"<<"\n";
933 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
938 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
940 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
942 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
945 Ctx->UpdateCurrentViewer();
948 Handle(AIS_InteractiveObject) IO;
949 TCollection_AsciiString name = argv[2];
950 if(GetMapOfAIS().IsBound2(name)){
951 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
954 Ctx->SubIntensityOn(IO);
956 Ctx->SubIntensityOff(IO);
964 //==============================================================================
967 //purpose : change the color of a selected or named or displayed shape
968 //Draw arg : vcolor2 [name] color
969 //==============================================================================
970 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
973 Standard_Boolean ThereIsCurrent;
974 Standard_Boolean ThereIsArgument;
975 Standard_Boolean IsBound = Standard_False ;
977 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
979 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
980 ThereIsArgument = (argc != 2);
983 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
984 ThereIsArgument = (argc == 2);
987 if ( !a3DView().IsNull() ) {
988 TCollection_AsciiString name;
989 if (ThereIsArgument) {
991 IsBound= GetMapOfAIS().IsBound2(name);
993 if (TheAISContext()->HasOpenedContext())
994 TheAISContext()->CloseLocalContext();
996 // On set le Booleen There is current
997 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
998 else ThereIsCurrent =Standard_False;
1000 //=======================================================================
1001 // Il y a un argument
1002 //=======================================================================
1003 if ( ThereIsArgument && IsBound ) {
1004 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1005 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1006 Handle(AIS_InteractiveObject) ashape =
1007 Handle(AIS_InteractiveObject)::DownCast (anObj);
1010 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1012 di << "HaveToSet 0\n";
1016 TheAISContext()->SetColor(ashape,GetColorFromName(argv[2]) );
1018 TheAISContext()->UnsetColor(ashape);
1019 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1020 Handle(NIS_Triangulated) ashape =
1021 Handle(NIS_Triangulated)::DownCast (anObj);
1022 if (!ashape.IsNull())
1023 ashape->SetColor (GetColorFromName(argv[2]));
1028 //=======================================================================
1029 // Il n'y a pas d'arguments
1030 // Mais un ou plusieurs objets on des current representation
1031 //=======================================================================
1032 if (ThereIsCurrent && !ThereIsArgument) {
1033 for (TheAISContext() -> InitCurrent() ;
1034 TheAISContext() -> MoreCurrent() ;
1035 TheAISContext() ->NextCurrent() )
1037 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1038 if (ashape.IsNull())
1042 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1044 di << "HaveToSet 0\n";
1047 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1049 TheAISContext()->UnsetColor(ashape,Standard_False);
1052 TheAISContext()->UpdateCurrentViewer();
1055 //=======================================================================
1056 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1057 // on impose a tous les objets du viewer la couleur passee
1058 //=======================================================================
1059 else if (!ThereIsCurrent && !ThereIsArgument){
1060 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1061 while ( it.More() ) {
1062 const Handle(AIS_InteractiveObject) ashape =
1063 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1064 if (!ashape.IsNull())
1066 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1068 TheAISContext()->UnsetColor(ashape,Standard_False);
1071 TheAISContext()->UpdateCurrentViewer();
1077 //==============================================================================
1078 //function : VTransparency
1080 //purpose : change the transparency of a selected or named or displayed shape
1081 //Draw arg : vtransparency [name] TransparencyCoeficient
1082 //==============================================================================
1084 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1087 Standard_Boolean ThereIsCurrent;
1088 Standard_Boolean ThereIsArgument;
1089 Standard_Boolean IsBound = Standard_False ;
1091 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1093 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1094 ThereIsArgument = (argc != 2);
1097 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1098 ThereIsArgument = (argc == 2);
1101 if ( !a3DView().IsNull() ) {
1102 TCollection_AsciiString name;
1103 if (ThereIsArgument) {
1105 IsBound= GetMapOfAIS().IsBound2(name);
1107 if (TheAISContext()->HasOpenedContext())
1108 TheAISContext()->CloseLocalContext();
1110 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1111 else ThereIsCurrent = Standard_False;
1113 //=======================================================================
1114 // Il y a des arguments: un nom et une couleur
1115 //=======================================================================
1116 if ( ThereIsArgument && IsBound ) {
1117 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1118 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1119 const Handle(AIS_InteractiveObject) ashape =
1120 Handle(AIS_InteractiveObject)::DownCast(anObj);
1122 TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1124 TheAISContext()->UnsetTransparency(ashape);
1125 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1126 const Handle(NIS_InteractiveObject) ashape =
1127 Handle(NIS_InteractiveObject)::DownCast(anObj);
1129 ashape->SetTransparency(atof(argv[2]) );
1131 ashape->UnsetTransparency();
1134 //=======================================================================
1135 // Il n'y a pas d'arguments
1136 // Mais un ou plusieurs objets on des current representation
1137 //=======================================================================
1138 if (ThereIsCurrent && !ThereIsArgument) {
1139 for (TheAISContext() -> InitCurrent() ;
1140 TheAISContext() -> MoreCurrent() ;
1141 TheAISContext() ->NextCurrent() )
1143 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1145 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1147 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1150 TheAISContext()->UpdateCurrentViewer();
1152 //=======================================================================
1153 // Il n'y a pas d'arguments ET aucun objet courrant
1154 //=======================================================================
1155 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1156 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1158 while ( it.More() ) {
1159 Handle(AIS_InteractiveObject) ashape =
1160 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1161 if (!ashape.IsNull())
1163 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1165 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1168 TheAISContext()->UpdateCurrentViewer();
1175 //==============================================================================
1176 //function : VMaterial
1178 //purpose : change the Material of a selected or named or displayed shape
1179 //Draw arg : vmaterial [Name] Material
1180 //==============================================================================
1181 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1184 Standard_Boolean ThereIsCurrent;
1185 Standard_Boolean ThereIsName;
1186 Standard_Boolean IsBound = Standard_False ;
1188 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1190 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1191 ThereIsName = (argc != 2);
1194 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1195 ThereIsName = (argc == 2);
1198 if ( !a3DView().IsNull() ) {
1199 TCollection_AsciiString name;
1202 IsBound= GetMapOfAIS().IsBound2(name);
1204 if (TheAISContext()->HasOpenedContext())
1205 TheAISContext()->CloseLocalContext();
1206 if (TheAISContext() -> NbCurrents() > 0 )
1207 ThereIsCurrent =Standard_True;
1209 ThereIsCurrent =Standard_False;
1211 //=======================================================================
1212 // Ther is a name of shape and a material name
1213 //=======================================================================
1214 if ( ThereIsName && IsBound ) {
1215 Handle(AIS_InteractiveObject) ashape =
1216 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1217 if (!ashape.IsNull())
1219 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1221 TheAISContext()->UnsetMaterial(ashape);
1223 //=======================================================================
1224 // Il n'y a pas de nom de shape
1225 // Mais un ou plusieurs objets on des current representation
1226 //=======================================================================
1227 if (ThereIsCurrent && !ThereIsName) {
1228 for (TheAISContext() -> InitCurrent() ;
1229 TheAISContext() -> MoreCurrent() ;
1230 TheAISContext() ->NextCurrent() )
1232 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1234 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1236 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1238 TheAISContext()->UpdateCurrentViewer();
1241 //=======================================================================
1242 // Il n'y a pas de noms de shape ET aucun objet courrant
1243 // On impose a tous les objets du viewer le material passe en argument
1244 //=======================================================================
1245 else if (!ThereIsCurrent && !ThereIsName){
1246 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1248 while ( it.More() ) {
1249 Handle(AIS_InteractiveObject) ashape =
1250 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1251 if (!ashape.IsNull())
1253 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1255 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1258 TheAISContext()->UpdateCurrentViewer();
1266 //==============================================================================
1269 //purpose : change the width of the edges of a selected or named or displayed shape
1270 //Draw arg : vwidth [Name] WidthValue(1->10)
1271 //==============================================================================
1272 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1275 Standard_Boolean ThereIsCurrent;
1276 Standard_Boolean ThereIsArgument;
1277 Standard_Boolean IsBound = Standard_False ;
1279 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1281 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1282 ThereIsArgument = (argc != 2);
1285 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1286 ThereIsArgument = (argc == 2);
1288 if ( !a3DView().IsNull() ) {
1289 TCollection_AsciiString name;
1290 if (ThereIsArgument) {
1292 IsBound= GetMapOfAIS().IsBound2(name);
1294 if (TheAISContext()->HasOpenedContext())
1295 TheAISContext()->CloseLocalContext();
1297 if (TheAISContext() -> NbCurrents() > 0 )
1298 ThereIsCurrent =Standard_True;
1300 ThereIsCurrent =Standard_False;
1302 if ( ThereIsArgument && IsBound ) {
1303 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1304 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1305 const Handle(AIS_InteractiveObject) ashape =
1306 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1308 TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1310 TheAISContext()->UnsetWidth (ashape);
1311 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1312 const Handle(NIS_Triangulated) ashape =
1313 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1314 if (HaveToSet && !ashape.IsNull())
1315 ashape->SetLineWidth ( atof (argv[2]) );
1319 //=======================================================================
1320 // Il n'y a pas d'arguments
1321 // Mais un ou plusieurs objets on des current representation
1322 //=======================================================================
1323 if (ThereIsCurrent && !ThereIsArgument) {
1324 for (TheAISContext() -> InitCurrent() ;
1325 TheAISContext() -> MoreCurrent() ;
1326 TheAISContext() ->NextCurrent() )
1328 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1330 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1332 TheAISContext()->UnsetWidth(ashape,Standard_False);
1334 TheAISContext()->UpdateCurrentViewer();
1336 //=======================================================================
1337 // Il n'y a pas d'arguments ET aucun objet courrant
1338 //=======================================================================
1339 else if (!ThereIsCurrent && !ThereIsArgument){
1340 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1342 while ( it.More() ) {
1343 Handle(AIS_InteractiveObject) ashape =
1344 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1345 if (!ashape.IsNull())
1347 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1349 TheAISContext()->UnsetWidth(ashape,Standard_False);
1352 TheAISContext()->UpdateCurrentViewer();
1357 //==============================================================================
1358 //function : VDonly2
1360 //purpose : Display only a selected or named object
1361 // if there is no selected or named object s, nothing is donne
1362 //Draw arg : vdonly2 [name1] ... [name n]
1363 //==============================================================================
1364 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1367 if ( a3DView().IsNull() )
1370 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1371 Standard_Boolean ThereIsArgument= argc>1;
1373 if (TheAISContext()->HasOpenedContext())
1374 TheAISContext()->CloseLocalContext();
1376 //===============================================================
1377 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1379 //===============================================================
1380 if (!ThereIsArgument && ThereIsCurrent) {
1383 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1386 for(TheAISContext()->InitCurrent();
1387 TheAISContext()->MoreCurrent();
1388 TheAISContext()->NextCurrent()){
1389 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1390 TheAISContext()->Erase(aShape,Standard_False);}
1392 TheAISContext() ->UpdateCurrentViewer();
1393 //===============================================================
1394 // Il y a des arguments
1395 //===============================================================
1396 if (ThereIsArgument) {
1397 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1399 while ( it.More() ) {
1400 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1401 const Handle(AIS_InteractiveObject) aShape =
1402 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1403 TheAISContext()->Erase(aShape,Standard_False);
1404 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1405 const Handle(NIS_InteractiveObject) aShape =
1406 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1407 TheNISContext()->Erase(aShape);
1412 // On display les objets passes par parametre
1413 for (int i=1; i<argc ; i++) {
1414 TCollection_AsciiString name=argv[i];
1415 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1417 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1418 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1419 const Handle(AIS_InteractiveObject) aShape =
1420 Handle(AIS_InteractiveObject)::DownCast (anObj);
1421 TheAISContext()->Display(aShape, Standard_False);
1422 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1423 Handle(NIS_InteractiveObject) aShape =
1424 Handle(NIS_InteractiveObject)::DownCast (anObj);
1425 TheNISContext()->Display(aShape);
1429 TheAISContext() ->UpdateCurrentViewer();
1430 // TheNISContext() ->UpdateViews();
1435 //==============================================================================
1436 //function : VErase2
1438 //purpose : Erase some selected or named objects
1439 // if there is no selected or named objects, the whole viewer is erased
1440 //Draw arg : verase2 [name1] ... [name n]
1441 //==============================================================================
1442 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1445 if ( a3DView().IsNull() )
1448 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1449 Standard_Boolean ThereIsArgument= argc>1;
1450 if(TheAISContext()->HasOpenedContext())
1451 TheAISContext()->CloseLocalContext();
1453 //===============================================================
1454 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1456 //===============================================================
1457 if (!ThereIsArgument && ThereIsCurrent) {
1458 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1460 while ( it.More() ) {
1461 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1462 const Handle(AIS_InteractiveObject) aShape =
1463 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1464 if (TheAISContext()->IsCurrent(aShape))
1465 TheAISContext()->Erase(aShape,Standard_False);
1470 TheAISContext() ->UpdateCurrentViewer();
1473 //===============================================================
1474 // Il n'y a pas d'arguments et aucuns objets selectionnes
1476 // On erase tout le viewer
1477 //===============================================================
1479 if (!ThereIsArgument && !ThereIsCurrent) {
1480 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1481 while ( it.More() ) {
1482 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1483 const Handle(AIS_InteractiveObject) aShape =
1484 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1485 TheAISContext()->Erase(aShape,Standard_False);
1486 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1487 const Handle(NIS_InteractiveObject) aShape =
1488 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1489 TheNISContext()->Erase(aShape);
1493 TheAISContext() ->UpdateCurrentViewer();
1494 // TheNISContext()->UpdateViews();
1497 //===============================================================
1498 // Il y a des arguments
1499 //===============================================================
1500 if (ThereIsArgument) {
1501 for (int i=1; i<argc ; i++) {
1502 TCollection_AsciiString name=argv[i];
1503 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1505 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1506 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1507 const Handle(AIS_InteractiveObject) aShape =
1508 Handle(AIS_InteractiveObject)::DownCast (anObj);
1509 TheAISContext()->Erase(aShape,Standard_False);
1510 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1511 const Handle(NIS_InteractiveObject) aShape =
1512 Handle(NIS_InteractiveObject)::DownCast (anObj);
1513 TheNISContext()->Erase(aShape);
1517 TheAISContext() ->UpdateCurrentViewer();
1518 // TheNISContext() ->UpdateViews();
1523 //==============================================================================
1524 //function : VEraseAll
1526 //purpose : Erase all the objects displayed in the viewer
1527 //Draw arg : veraseall
1528 //==============================================================================
1529 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1532 // Verification des arguments
1533 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1534 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1535 TheAISContext()->CloseAllContexts(Standard_False);
1536 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1538 while ( it.More() ) {
1539 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1540 const Handle(AIS_InteractiveObject) aShape =
1541 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1542 TheAISContext()->Erase(aShape,Standard_False);
1543 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1544 const Handle(NIS_InteractiveObject) aShape =
1545 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1546 TheNISContext()->Erase(aShape);
1550 TheAISContext() ->UpdateCurrentViewer();
1551 // TheNISContext() ->UpdateViews();
1556 //==============================================================================
1557 //function : VDisplayAll
1559 //purpose : Display all the objects of the Map
1560 //Draw arg : vdisplayall
1561 //==============================================================================
1562 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1565 if (! a3DView().IsNull() ) {
1566 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1567 if (TheAISContext()->HasOpenedContext())
1568 TheAISContext()->CloseLocalContext();
1569 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1571 while ( it.More() ) {
1572 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1573 const Handle(AIS_InteractiveObject) aShape =
1574 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1575 TheAISContext()->Erase(aShape,Standard_False);
1576 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1577 const Handle(NIS_InteractiveObject) aShape =
1578 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1579 TheNISContext()->Erase(aShape);
1584 while ( it.More() ) {
1585 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1586 const Handle(AIS_InteractiveObject) aShape =
1587 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1588 TheAISContext()->Display(aShape, Standard_False);
1589 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1590 Handle(NIS_InteractiveObject) aShape =
1591 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1592 TheNISContext()->Display(aShape);
1596 TheAISContext() ->UpdateCurrentViewer();
1597 // TheNISContext() ->UpdateViews();
1603 //#######################################################################################################
1606 static TCollection_AsciiString GetEnvir (Draw_Interpretor& di) {
1608 static Standard_Boolean IsDefined=Standard_False ;
1609 static TCollection_AsciiString VarName;
1611 const char *envir, *casroot ;
1612 envir = getenv("CSF_MDTVTexturesDirectory") ;
1614 Standard_Boolean HasDefinition = Standard_False ;
1616 casroot = getenv("CASROOT");
1618 VarName = TCollection_AsciiString (casroot);
1619 VarName += "/src/Textures" ;
1620 HasDefinition = Standard_True ;
1623 VarName = TCollection_AsciiString (envir);
1624 HasDefinition = Standard_True ;
1626 if ( HasDefinition ) {
1627 OSD_Path aPath ( VarName );
1628 OSD_Directory aDir(aPath);
1629 if ( aDir.Exists () ) {
1630 TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb" ;
1631 OSD_File TextureFile ( aTexture );
1632 if ( !TextureFile.Exists() ) {
1633 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1634 di << " not all files are found in : "<<VarName.ToCString() << "\n";
1635 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1638 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1639 di << " Directory : "<< VarName.ToCString() << " not exist " << "\n";
1640 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1644 di << " CSF_MDTVTexturesDirectory and CASROOT not setted " << "\n";
1645 di << " one of these variable are mandatory to use this fonctionnality" << "\n";
1646 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory and CASROOT not setted " );
1648 IsDefined = Standard_True ;
1654 //#######################################################################################################
1657 //#######################################################################################################
1661 //#######################################################################################################
1663 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1665 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1666 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1667 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1668 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1669 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1671 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1672 if(myAISContext.IsNull())
1674 di << "use 'vinit' command before " << argv[0] << "\n";
1678 Handle(AIS_InteractiveObject) TheAisIO;
1679 Handle(AIS_TexturedShape) myShape;
1680 Standard_Integer myPreviousMode = 0;
1682 if (argc<2 || !argv[1])
1684 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1688 TCollection_AsciiString name = argv[1];
1689 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1691 if (GetMapOfAIS().IsBound2(name))
1692 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1693 (GetMapOfAIS().Find2(name));
1694 if (TheAisIO.IsNull())
1696 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1700 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1702 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1703 myPreviousMode = myShape->DisplayMode() ;
1707 myAISContext->Clear(TheAisIO,Standard_False);
1708 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1709 GetMapOfAIS().UnBind1(TheAisIO);
1710 GetMapOfAIS().UnBind2(name);
1711 GetMapOfAIS().Bind(myShape, name);
1715 case 1: // vtexture : we only map a texture on the shape
1718 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1721 if (argc>2 && argv[2])
1723 if(strcasecmp(argv[2],"?")==0)
1725 TCollection_AsciiString monPath = GetEnvir (di) ;
1727 di<<"\n Files in current directory : \n"<<"\n";
1728 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1729 di.Eval(Cmnd.ToCString());
1731 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1734 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1735 di.Eval(Cmnd.ToCString());
1740 myShape->SetTextureFileName(argv[2]);
1744 di <<"Texture mapping disabled \n \
1745 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1747 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1748 if (myPreviousMode == 3 )
1749 myAISContext->RecomputePrsOnly(myShape);
1750 myAISContext->Display(myShape, Standard_True);
1755 case 2: // vtexscale : we change the scaling factor of the texture
1759 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1763 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1764 ( argv[2] ? atof(argv[2]) : 1.0 ),
1765 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1768 case 3: // vtexorigin : we change the origin of the texture on the shape
1771 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1774 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1775 ( argv[2] ? atof(argv[2]) : 0.0 ),
1776 ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1779 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1782 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1785 if (argc>2 && argv[2])
1787 di <<"Texture repeat enabled"<<"\n";
1788 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1792 di <<"Texture repeat disabled"<<"\n";
1793 myShape->SetTextureRepeat(Standard_False);
1797 case 5: // vtexdefault : default texture mapping
1798 // ScaleU = ScaleV = 100.0
1799 // URepeat = VRepeat = 1.0
1800 // Uorigin = VOrigin = 0.0
1804 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1807 myShape->SetTextureRepeat(Standard_False);
1808 myShape->SetTextureOrigin(Standard_False);
1809 myShape->SetTextureScale (Standard_False);
1813 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1814 myAISContext->RecomputePrsOnly(myShape);
1817 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1818 myAISContext->Display(myShape, Standard_True);
1819 myAISContext->Update(myShape,Standard_True);
1824 //==============================================================================
1825 //function : VDisplay2
1827 //purpose : Display an object from its name
1828 //Draw arg : vdisplay name1 [name2] ... [name n]
1829 //==============================================================================
1830 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1833 // Verification des arguments
1834 if ( a3DView().IsNull() ) {
1836 ViewerTest::ViewerInit();
1837 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1842 di<<argv[0]<<" Syntaxe error"<<"\n";
1847 TCollection_AsciiString name;
1848 if (TheAISContext()->HasOpenedContext())
1849 TheAISContext()->CloseLocalContext();
1851 for ( int i = 1; i < argc; i++ ) {
1853 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1854 Standard_Boolean IsDatum = Standard_False;
1855 Handle(Standard_Transient) anObj;
1857 anObj = GetMapOfAIS().Find2(name);
1858 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1859 Handle(AIS_InteractiveObject) aShape =
1860 Handle(AIS_InteractiveObject)::DownCast(anObj);
1861 if (aShape->Type()==AIS_KOI_Datum) {
1862 IsDatum = Standard_True;
1863 TheAISContext()->Display(aShape, Standard_False);
1866 di << "Display " << name.ToCString() << "\n";
1867 // Get the Shape from a name
1868 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
1870 // Update the Shape in the AIS_Shape
1871 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
1872 if(!TheRealSh.IsNull())
1873 TheRealSh->Set(NewShape);
1874 TheAISContext()->Redisplay(aShape, Standard_False);
1875 TheAISContext()->Display(aShape, Standard_False);
1878 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1879 Handle(NIS_InteractiveObject) aShape =
1880 Handle(NIS_InteractiveObject)::DownCast(anObj);
1881 TheNISContext()->Display(aShape);
1884 else { // Create the AIS_Shape from a name
1885 const Handle(AIS_InteractiveObject) aShape =
1886 GetAISShapeFromName((const char *)name.ToCString());
1887 if ( !aShape.IsNull() ) {
1888 GetMapOfAIS().Bind(aShape, name);
1889 TheAISContext()->Display(aShape, Standard_False);
1893 // Upadate the screen and redraw the view
1894 TheAISContext()->UpdateCurrentViewer();
1895 // TheNISContext()->UpdateViews();
1899 //==============================================================================
1901 //purpose : Test the annimation of an object along a
1902 // predifined trajectory
1903 //Draw arg : vmove ShapeName
1904 //==============================================================================
1907 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
1912 if (TheAISContext()->HasOpenedContext())
1913 TheAISContext()->CloseLocalContext();
1915 Standard_Real Step=2*M_PI/180;
1916 Standard_Real Angle=0;
1917 // R est le rayon de l'hellicoide
1919 // D est la distance parcourue en translation en 1 tour
1922 Handle(AIS_InteractiveObject) aIO;
1924 if (GetMapOfAIS().IsBound2(argv[1]))
1925 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
1928 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
1931 TheAISContext()->Deactivate(aIO);
1933 // boucle generant le mouvement
1935 di<<" Transformations"<<"\n";
1936 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
1939 gp_Ax3 newBase(gp_Pnt(R*cos(Angle), R*sin(Angle), D*Angle/(2*M_PI) ), gp_Vec(0,0,1), gp_Vec(1,0,0) );
1941 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
1942 TheAISContext()->SetLocation(aIO,myTransfo);
1944 TheAISContext() ->UpdateCurrentViewer();
1949 di<<" Locations"<<"\n";
1950 gp_Trsf myAngleTrsf;
1951 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
1952 TopLoc_Location myDeltaAngle (myAngleTrsf);
1954 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
1955 TopLoc_Location myDeltaDist (myDistTrsf);
1956 TopLoc_Location myTrueLoc;
1958 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
1961 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
1962 TheAISContext()->SetLocation(aIO,myTrueLoc );
1963 TheAISContext() ->UpdateCurrentViewer();
1968 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
1970 //TopLoc_Location Tempo=aIO->Location();
1971 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
1972 //ShapeBis.Located(Tempo);
1975 // On reset la location (origine) contenue dans l'AISInteractiveObject
1976 TheAISContext() ->ResetLocation(aIO);
1978 // On force aShape a devenir l'AIS IO propre a ShapeBis
1980 // Pour cela on force aShape(AIS IO) a devenir une AISShape
1981 // ->Set() est une methode de AIS_Shape
1982 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
1984 // On donne a ShapeBis le nom de l'AIS IO
1985 //Rep::Set(argv[1],ShapeBis);
1988 TheAISContext()->Redisplay(aIO,Standard_False);
1990 // On reactive la selection des primitives sensibles
1991 TheAISContext()->Activate(aIO,0);
1993 TheAISContext() ->UpdateCurrentViewer();
1994 a3DView() -> Redraw();
1997 di<<" Temps ecoule "<<"\n";
2005 //==============================================================================
2007 //purpose : Test the annimation of an object along a
2008 // predifined trajectory
2009 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2010 //==============================================================================
2012 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2015 if (TheAISContext()->HasOpenedContext())
2016 TheAISContext()->CloseLocalContext();
2018 Standard_Real Step=4*M_PI/180;
2019 Standard_Real Angle=0;
2021 Handle(AIS_InteractiveObject) aIO;
2022 if (GetMapOfAIS().IsBound2(argv[1]))
2023 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2027 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2031 if (atoi(argv[3])==1 ) {
2032 di<<" Primitives sensibles OFF"<<"\n";
2033 TheAISContext()->Deactivate(aIO);
2036 di<<" Primitives sensibles ON"<<"\n";
2038 // Movement par transformation
2039 if(atoi(argv[2]) ==1) {
2040 di<<" Calcul par Transformation"<<"\n";
2041 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2045 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2046 TheAISContext()->SetLocation(aShape,myTransfo);
2047 TheAISContext() ->UpdateCurrentViewer();
2052 di<<" Calcul par Locations"<<"\n";
2053 gp_Trsf myAngleTrsf;
2054 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2055 TopLoc_Location myDeltaAngle (myAngleTrsf);
2056 TopLoc_Location myTrueLoc;
2058 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2061 myTrueLoc=myTrueLoc*myDeltaAngle;
2062 TheAISContext()->SetLocation(aShape,myTrueLoc );
2063 TheAISContext() ->UpdateCurrentViewer();
2066 if (atoi(argv[3])==1 ){
2067 // On reactive la selection des primitives sensibles
2068 TheAISContext()->Activate(aIO,0);
2070 a3DView() -> Redraw();
2072 di<<" Temps ecoule "<<"\n";
2078 //==================================================================================
2079 // Function : VAnimation
2080 //==================================================================================
2081 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2083 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2087 Standard_Real thread = 4;
2088 Standard_Real angleA=0;
2089 Standard_Real angleB;
2091 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2094 TopoDS_Shape CrankArm;
2095 TopoDS_Shape CylinderHead;
2096 TopoDS_Shape Propeller;
2097 TopoDS_Shape EngineBlock;
2099 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2100 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2101 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2102 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2103 BRepTools::Read(CrankArm,argv[1],B);
2104 BRepTools::Read(CylinderHead,argv[2],B);
2105 BRepTools::Read(Propeller,argv[3],B);
2106 BRepTools::Read(EngineBlock,argv[4],B);
2108 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2114 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2115 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2116 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2117 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2119 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2120 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2121 GetMapOfAIS().Bind(myAisCrankArm,"c");
2122 GetMapOfAIS().Bind(myAisPropeller,"d");
2124 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2125 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2126 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2128 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2129 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2130 TheAISContext()->Display(myAisCrankArm,Standard_False );
2131 TheAISContext()->Display(myAisPropeller,Standard_False);
2133 TheAISContext()->Deactivate(myAisCylinderHead);
2134 TheAISContext()->Deactivate(myAisEngineBlock );
2135 TheAISContext()->Deactivate(myAisCrankArm );
2136 TheAISContext()->Deactivate(myAisPropeller );
2138 // Boucle de mouvement
2139 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2141 angleA = thread*myAngle*M_PI/180;
2142 X = Sin(angleA)*3/8;
2143 angleB = atan(X / Sqrt(-X * X + 1));
2144 Standard_Real decal(25*0.6);
2147 //Build a transformation on the display
2148 gp_Trsf aPropellerTrsf;
2149 aPropellerTrsf.SetRotation(Ax1,angleA);
2150 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2152 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));
2153 gp_Trsf aCrankArmTrsf;
2154 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2155 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2157 TheAISContext()->UpdateCurrentViewer();
2160 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2161 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2163 myAisCrankArm ->ResetLocation();
2164 myAisPropeller->ResetLocation();
2166 myAisCrankArm -> Set(myNewCrankArm );
2167 myAisPropeller -> Set(myNewPropeller);
2169 TheAISContext()->Activate(myAisCylinderHead,0);
2170 TheAISContext()->Activate(myAisEngineBlock,0 );
2171 TheAISContext()->Activate(myAisCrankArm ,0 );
2172 TheAISContext()->Activate(myAisPropeller ,0 );
2178 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2179 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2181 TheAISContext()->UpdateCurrentViewer();
2182 a3DView()->Redraw();
2191 //==============================================================================
2192 //function : VShading
2193 //purpose : Sharpen or roughten the quality of the shading
2194 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2195 //==============================================================================
2196 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2198 Standard_Real myDevCoef;
2199 Handle(AIS_InteractiveObject) TheAisIO;
2202 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2204 if (TheAISContext()->HasOpenedContext())
2205 TheAISContext()->CloseLocalContext();
2210 myDevCoef =atof(argv[2]);
2213 TCollection_AsciiString name=argv[1];
2214 if (GetMapOfAIS().IsBound2(name ))
2215 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2216 if (TheAisIO.IsNull())
2217 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2220 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2222 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2224 TheAISContext()->Redisplay(TheAisIO);
2227 //==============================================================================
2228 //function : HaveMode
2229 //use : VActivatedModes
2230 //==============================================================================
2231 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2233 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2235 TColStd_ListOfInteger List;
2236 TheAISContext()->ActivatedModes (TheAisIO,List);
2237 TColStd_ListIteratorOfListOfInteger it;
2238 Standard_Boolean Found=Standard_False;
2239 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2240 if (it.Value()==mode ) Found=Standard_True;
2247 //==============================================================================
2248 //function : VActivatedMode
2250 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2251 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2252 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2253 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2254 // qu'un nom et qu'un mode.
2255 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2256 //==============================================================================
2257 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2259 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2262 Standard_Boolean ThereIsName = Standard_False ;
2264 if(!a3DView().IsNull()){
2266 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2267 // verification des arguments
2269 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2270 ThereIsName = (argc == 3);
2274 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2276 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2277 di<<" Fermeture du Context local"<<"\n";
2278 if (TheAISContext()->HasOpenedContext())
2279 TheAISContext()->CloseLocalContext();
2283 // IL n'y a aps de nom de shape passe en argument
2284 if (HaveToSet && !ThereIsName){
2285 Standard_Integer aMode=atoi(argv [1]);
2287 const char *cmode="???";
2289 case 0: cmode = "Shape"; break;
2290 case 1: cmode = "Vertex"; break;
2291 case 2: cmode = "Edge"; break;
2292 case 3: cmode = "Wire"; break;
2293 case 4: cmode = "Face"; break;
2294 case 5: cmode = "Shell"; break;
2295 case 6: cmode = "Solid"; break;
2296 case 7: cmode = "Compound"; break;
2299 if( !TheAISContext()->HasOpenedContext() ) {
2300 // il n'y a pas de Context local d'ouvert
2301 // on en ouvre un et on charge toutes les shapes displayees
2302 // on load tous les objets displayees et on Activate les objets de la liste
2303 AIS_ListOfInteractive ListOfIO;
2304 // on sauve dans une AISListOfInteractive tous les objets currents
2305 if (TheAISContext()->NbCurrents()>0 ){
2306 TheAISContext()->UnhilightCurrents(Standard_False);
2308 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2309 ListOfIO.Append(TheAISContext()->Current() );
2313 TheAISContext()->OpenLocalContext(Standard_False);
2314 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2317 Handle(AIS_InteractiveObject) aIO =
2318 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2320 TheAISContext()->Load(aIO,0,Standard_False);
2323 // traitement des objets qui etaient currents dans le Contexte global
2324 if (!ListOfIO.IsEmpty() ) {
2325 // il y avait des objets currents
2326 AIS_ListIteratorOfListOfInteractive iter;
2327 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2328 Handle(AIS_InteractiveObject) aIO=iter.Value();
2329 TheAISContext()->Activate(aIO,aMode);
2330 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2334 // On applique le mode a tous les objets displayes
2335 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2336 it2 (GetMapOfAIS());
2338 Handle(AIS_InteractiveObject) aIO =
2339 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2340 if (!aIO.IsNull()) {
2341 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2342 TheAISContext()->Activate(aIO,aMode);
2351 // un Context local est deja ouvert
2352 // Traitement des objets du Context local
2353 if (TheAISContext()->NbSelected()>0 ){
2354 TheAISContext()->UnhilightSelected(Standard_False);
2355 // il y a des objets selected,on les parcourt
2356 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2357 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2360 if (HaveMode(aIO,aMode) ) {
2361 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2362 TheAISContext()->Deactivate(aIO,aMode);
2365 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2366 TheAISContext()->Activate(aIO,aMode);
2372 // il n'y a pas d'objets selected
2373 // tous les objets diplayes sont traites
2374 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2377 Handle(AIS_InteractiveObject) aIO =
2378 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2379 if (!aIO.IsNull()) {
2380 if (HaveMode(aIO,aMode) ) {
2381 di<<" Mode: "<<cmode<<" OFF pour "
2382 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2383 TheAISContext()->Deactivate(aIO,aMode);
2386 di<<" Mode: "<<cmode<<" ON pour"
2387 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2388 TheAISContext()->Activate(aIO,aMode);
2396 else if (HaveToSet && ThereIsName){
2397 Standard_Integer aMode=atoi(argv [2]);
2398 Handle(AIS_InteractiveObject) aIO =
2399 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2401 if (!aIO.IsNull()) {
2402 const char *cmode="???";
2405 case 0: cmode = "Shape"; break;
2406 case 1: cmode = "Vertex"; break;
2407 case 2: cmode = "Edge"; break;
2408 case 3: cmode = "Wire"; break;
2409 case 4: cmode = "Face"; break;
2410 case 5: cmode = "Shell"; break;
2411 case 6: cmode = "Solid"; break;
2412 case 7: cmode = "Compound"; break;
2415 if( !TheAISContext()->HasOpenedContext() ) {
2416 TheAISContext()->OpenLocalContext(Standard_False);
2417 // On charge tous les objets de la map
2418 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2420 Handle(AIS_InteractiveObject) aShape=
2421 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2422 if (!aShape.IsNull())
2423 TheAISContext()->Load(aShape,0,Standard_False);
2426 TheAISContext()->Activate(aIO,aMode);
2427 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2431 // un Context local est deja ouvert
2432 if (HaveMode(aIO,aMode) ) {
2433 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2434 TheAISContext()->Deactivate(aIO,aMode);
2437 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2438 TheAISContext()->Activate(aIO,aMode);
2450 //==============================================================================
2451 // function : WhoAmI
2453 //==============================================================================
2454 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2457 if (theShape->Type()==AIS_KOI_Datum) {
2458 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2459 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2460 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2461 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2462 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2463 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2464 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2467 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2468 // AIS_Dimentions et AIS_Relations
2469 else if (theShape->Type()==AIS_KOI_Relation) {
2470 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2472 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2473 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2474 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2475 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2476 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2477 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2478 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2479 // AIS no repertorie.
2480 else {di<<" Type Unknown.";}
2486 //==============================================================================
2489 //Draw arg : vstate [nameA] ... [nameN]
2490 //==============================================================================
2491 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2493 TheAISContext()->CloseAllContexts();
2494 const Standard_Boolean ThereIsArguments=(argc>=2);
2495 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2497 // ==================
2498 // Il y a un argument
2499 // ==================
2500 if (ThereIsArguments) {
2501 for (int cpt=1;cpt<argc;cpt++) {
2502 // Verification que lq piece est bien bindee.
2503 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2504 const Handle(AIS_InteractiveObject) theShape=
2505 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2507 if (!theShape.IsNull()) {
2508 di<<argv[cpt];WhoAmI(theShape, di);
2509 if (TheAISContext()->IsDisplayed(theShape) ) {
2510 di<<" Displayed"<<"\n";
2513 di<<" Not Displayed"<<"\n";
2518 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2522 else if (ThereIsCurrent ) {
2523 for (TheAISContext() -> InitCurrent() ;
2524 TheAISContext() -> MoreCurrent() ;
2525 TheAISContext() ->NextCurrent() )
2527 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2528 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2529 if (TheAISContext()->IsDisplayed(theShape) ) {
2530 di<<" Displayed"<<"\n";
2533 di<<" Not Displayed"<<"\n";
2539 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2541 while ( it.More() ) {
2542 Handle(AIS_InteractiveObject) theShape =
2543 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2544 if (!theShape.IsNull()) {
2545 di<<it.Key2().ToCString();
2546 WhoAmI(theShape, di);
2547 if (TheAISContext()->IsDisplayed(theShape) ) {
2548 di<<" Displayed"<<"\n";
2551 di<<" Not Displayed"<<"\n";
2562 //=======================================================================
2563 //function : PickObjects
2565 //=======================================================================
2566 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2567 const AIS_KindOfInteractive TheType,
2568 const Standard_Integer TheSignature,
2569 const Standard_Integer MaxPick)
2571 Handle(AIS_InteractiveObject) IO;
2572 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2574 // step 1: prepare the data
2576 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2577 TheAISContext()->AddFilter(F1);
2580 // step 2 : wait for the selection...
2581 // Standard_Boolean IsGood (Standard_False);
2582 // Standard_Integer NbPick(0);
2583 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2584 Standard_Integer NbPickFail(0);
2585 Standard_Integer argccc = 5;
2586 const char *bufff[] = { "A", "B", "C","D", "E" };
2587 const char **argvvv = (const char **) bufff;
2590 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2591 while(ViewerMainLoop(argccc,argvvv)){}
2592 Standard_Integer NbStored = TheAISContext()->NbSelected();
2593 if((unsigned int ) NbStored != NbPickGood)
2594 NbPickGood= NbStored;
2597 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2600 // step3 get result.
2602 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2604 Standard_Integer i(0);
2605 for(TheAISContext()->InitSelected();
2606 TheAISContext()->MoreSelected();
2607 TheAISContext()->NextSelected()){
2609 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2610 arr->SetValue(i,IO2);
2615 TheAISContext()->CloseLocalContext(curindex);
2617 return Standard_True;
2621 //=======================================================================
2622 //function : PickObject
2624 //=======================================================================
2625 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2626 const Standard_Integer TheSignature,
2627 const Standard_Integer MaxPick)
2629 Handle(AIS_InteractiveObject) IO;
2630 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2632 // 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_Integer argccc = 5;
2643 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2644 const char **argvvv = (const char **) bufff;
2647 while(!IsGood && NbPick<= MaxPick){
2648 while(ViewerMainLoop(argccc,argvvv)){}
2649 IsGood = (TheAISContext()->NbSelected()>0) ;
2651 cout<<"Nb Pick :"<<NbPick<<endl;
2655 // step3 get result.
2657 TheAISContext()->InitSelected();
2658 IO = TheAISContext()->SelectedInteractive();
2662 TheAISContext()->CloseLocalContext(curindex);
2666 //=======================================================================
2667 //function : PickShape
2668 //purpose : First Activate the rightmode + Put Filters to be able to
2669 // pick objets that are of type <TheType>...
2670 //=======================================================================
2672 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2673 const Standard_Integer MaxPick)
2676 // step 1: prepare the data
2678 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2679 TopoDS_Shape result;
2681 if(TheType==TopAbs_SHAPE){
2682 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2683 TheAISContext()->AddFilter(F1);
2686 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2687 TheAISContext()->AddFilter(TF);
2688 TheAISContext()->ActivateStandardMode(TheType);
2693 // step 2 : wait for the selection...
2694 Standard_Boolean NoShape (Standard_True);
2695 Standard_Integer NbPick(0);
2696 Standard_Integer argccc = 5;
2697 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2698 const char **argvvv = (const char **) bufff;
2701 while(NoShape && NbPick<= MaxPick){
2702 while(ViewerMainLoop(argccc,argvvv)){}
2703 NoShape = (TheAISContext()->NbSelected()==0) ;
2705 cout<<"Nb Pick :"<<NbPick<<endl;
2708 // step3 get result.
2712 TheAISContext()->InitSelected();
2713 if(TheAISContext()->HasSelectedShape())
2714 result = TheAISContext()->SelectedShape();
2716 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2717 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2722 TheAISContext()->CloseLocalContext(curindex);
2728 //=======================================================================
2729 //function : PickShapes
2731 //=======================================================================
2732 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2733 Handle(TopTools_HArray1OfShape)& thearr,
2734 const Standard_Integer MaxPick)
2737 Standard_Integer Taille = thearr->Length();
2739 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2741 // step 1: prepare the data
2742 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2743 if(TheType==TopAbs_SHAPE){
2744 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2745 TheAISContext()->AddFilter(F1);
2748 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2749 TheAISContext()->AddFilter(TF);
2750 TheAISContext()->ActivateStandardMode(TheType);
2754 // step 2 : wait for the selection...
2756 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2757 Standard_Integer NbPickFail(0);
2758 Standard_Integer argccc = 5;
2759 const char *bufff[] = { "A", "B", "C","D", "E" };
2760 const char **argvvv = (const char **) bufff;
2763 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2764 while(ViewerMainLoop(argccc,argvvv)){}
2765 Standard_Integer NbStored = TheAISContext()->NbSelected();
2766 if((unsigned int ) NbStored != NbPickGood)
2767 NbPickGood= NbStored;
2770 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2773 // step3 get result.
2775 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2777 Standard_Integer i(0);
2778 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2780 if(TheAISContext()->HasSelectedShape())
2781 thearr->SetValue(i,TheAISContext()->SelectedShape());
2783 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2784 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2788 TheAISContext()->CloseLocalContext(curindex);
2789 return Standard_True;
2793 //=======================================================================
2794 //function : VPickShape
2796 //=======================================================================
2797 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2799 TopoDS_Shape PickSh;
2800 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2803 theType = TopAbs_SHAPE;
2805 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2806 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2807 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2808 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2809 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2810 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2811 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2814 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2815 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2817 TCollection_AsciiString name;
2820 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2822 PickSh = ViewerTest::PickShape(theType);
2831 if(!PickSh.IsNull()){
2832 nbOfSub[Standard_Integer(theType)]++;
2834 name += nameType[Standard_Integer(theType)];
2835 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2840 // si on avait une petite methode pour voir si la shape
2841 // est deja dans la Double map, ca eviterait de creer....
2842 DBRep::Set(name.ToCString(),PickSh);
2844 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2845 GetMapOfAIS().Bind(newsh, name);
2846 TheAISContext()->Display(newsh);
2847 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2850 // Plusieurs objets a picker, vite vite vite....
2853 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2854 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2855 if(ViewerTest::PickShapes(theType,arr)){
2856 for(Standard_Integer i=1;i<=NbToPick;i++){
2857 PickSh = arr->Value(i);
2858 if(!PickSh.IsNull()){
2860 nbOfSub[Standard_Integer(theType)]++;
2863 name += nameType[Standard_Integer(theType)];
2864 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2872 DBRep::Set(name.ToCString(),PickSh);
2873 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2874 GetMapOfAIS().Bind(newsh, name);
2875 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2876 TheAISContext()->Display(newsh);
2886 //=======================================================================
2887 //function : VPickObject
2888 //purpose : filters can be set (type of Object to pick....
2890 //=======================================================================
2893 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
2895 // preparation de la nomination automatique
2896 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
2897 // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
2899 /* TCollection_AsciiString name;
2901 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2903 PickSh = ViewerTest::PickObject(theType);
2912 if(!PickSh.IsNull()){
2913 nbOfSub[Standard_Integer(theType)]++;
2915 name += nameType[Standard_Integer(theType)];
2916 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2921 // si on avait une petite methode pour voir si la shape
2922 // est deja dans la Double map, ca eviterait de creer....
2923 DBRep::Set(name.ToCString(),PickSh);
2925 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2926 GetMapOfAIS().Bind(newsh, name);
2927 TheAISContext()->Display(newsh);
2928 cout<<"Nom de la shape pickee : "<<name<<endl;
2931 // Plusieurs objets a picker, vite vite vite....
2934 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2935 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2936 if(ViewerTest::PickShapes(theType,arr)){
2937 for(Standard_Integer i=1;i<=NbToPick;i++){
2938 PickSh = arr->Value(i);
2939 if(!PickSh.IsNull()){
2941 nbOfSub[Standard_Integer(theType)]++;
2944 name += nameType[Standard_Integer(theType)];
2945 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2953 DBRep::Set(name.ToCString(),PickSh);
2954 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2955 GetMapOfAIS().Bind(newsh, name);
2956 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
2957 TheAISContext()->Display(newsh);
2967 //=======================================================================
2968 //function : list of known objects
2970 //=======================================================================
2971 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
2973 // 1234567890 12345678901234567 123456789
2974 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
2975 TCollection_AsciiString BlankLine(64,'_');
2976 Standard_Integer i ;
2978 di<<"/n"<<BlankLine.ToCString()<<"\n";
2981 Colum[i].Center(20,' ');
2983 di<<"|"<<Colum[i].ToCString();
2986 di<<BlankLine.ToCString()<<"\n";
2988 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
2989 const char ** names = GetTypeNames();
2991 TCollection_AsciiString curstring;
2992 TCollection_AsciiString curcolum[3];
2995 // les objets de type Datum..
2996 curcolum[1]+="Datum";
2998 curcolum[0].Clear();
2999 curcolum[0] += names[i];
3001 curcolum[2].Clear();
3002 curcolum[2]+=TCollection_AsciiString(i+1);
3004 for(Standard_Integer j =0;j<=2;j++){
3005 curcolum[j].Center(20,' ');
3006 di<<"|"<<curcolum[j].ToCString();
3010 di<<BlankLine.ToCString()<<"\n";
3012 // les objets de type shape
3013 curcolum[1].Clear();
3014 curcolum[1]+="Shape";
3015 curcolum[1].Center(20,' ');
3018 curcolum[0].Clear();
3019 curcolum[0] += names[7+i];
3020 curcolum[2].Clear();
3021 curcolum[2]+=TCollection_AsciiString(i);
3023 for(Standard_Integer j =0;j<=2;j++){
3024 curcolum[j].Center(20,' ');
3025 di<<"|"<<curcolum[j].ToCString();
3029 di<<BlankLine.ToCString()<<"\n";
3030 // les IO de type objet...
3031 curcolum[1].Clear();
3032 curcolum[1]+="Object";
3033 curcolum[1].Center(20,' ');
3035 curcolum[0].Clear();
3036 curcolum[0] += names[10+i];
3037 curcolum[2].Clear();
3038 curcolum[2]+=TCollection_AsciiString(i);
3040 for(Standard_Integer j =0;j<=2;j++){
3041 curcolum[j].Center(20,' ');
3042 di<<"|"<<curcolum[j].ToCString();
3046 di<<BlankLine.ToCString()<<"\n";
3047 // les contraintes et dimensions.
3048 // pour l'instant on separe juste contraintes et dimensions...
3049 // plus tard, on detaillera toutes les sortes...
3050 curcolum[1].Clear();
3051 curcolum[1]+="Relation";
3052 curcolum[1].Center(20,' ');
3054 curcolum[0].Clear();
3055 curcolum[0] += names[12+i];
3056 curcolum[2].Clear();
3057 curcolum[2]+=TCollection_AsciiString(i);
3059 for(Standard_Integer j =0;j<=2;j++){
3060 curcolum[j].Center(20,' ');
3061 di<<"|"<<curcolum[j].ToCString();
3065 di<<BlankLine.ToCString()<<"\n";
3072 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3074 if(argc!=2) return 1;
3076 AIS_KindOfInteractive TheType;
3077 Standard_Integer TheSign(-1);
3078 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3081 AIS_ListOfInteractive LIO;
3083 // en attendant l'amelioration ais pour les dimensions...
3085 Standard_Integer dimension_status(-1);
3086 if(TheType==AIS_KOI_Relation){
3087 dimension_status = TheSign ==1 ? 1 : 0;
3091 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3092 Handle(AIS_InteractiveObject) curio;
3093 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3096 if(dimension_status == -1)
3097 TheAISContext()->Erase(curio,Standard_False);
3099 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3100 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3101 (dimension_status==1 && KOD != AIS_KOD_NONE))
3102 TheAISContext()->Erase(curio,Standard_False);
3105 TheAISContext()->UpdateCurrentViewer();
3108 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3110 if(argc!=2) return 1;
3112 AIS_KindOfInteractive TheType;
3113 Standard_Integer TheSign(-1);
3114 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3116 // en attendant l'amelioration ais pour les dimensions...
3118 Standard_Integer dimension_status(-1);
3119 if(TheType==AIS_KOI_Relation){
3120 dimension_status = TheSign ==1 ? 1 : 0;
3124 AIS_ListOfInteractive LIO;
3125 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3126 Handle(AIS_InteractiveObject) curio;
3127 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3129 if(dimension_status == -1)
3130 TheAISContext()->Display(curio,Standard_False);
3132 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3133 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3134 (dimension_status==1 && KOD != AIS_KOD_NONE))
3135 TheAISContext()->Display(curio,Standard_False);
3140 TheAISContext()->UpdateCurrentViewer();
3144 //==============================================================================
3145 //function : VSetTransMode
3147 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3148 //==============================================================================
3150 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3151 // Verification des arguments
3152 if ( a3DView().IsNull() ) {
3153 ViewerTest::ViewerInit();
3154 di << "La commande vinit n'a pas ete appele avant" << "\n";
3157 if ( argc < 3 || argc > 8 ) {
3158 di << argv[0] << " Invalid number of arguments" << "\n";
3162 TCollection_AsciiString shapeName;
3163 shapeName = argv[1];
3164 Standard_Integer persFlag1 = atoi(argv[2]);
3165 Standard_Integer persFlag2 = 0;
3166 Standard_Integer persFlag3 = 0;
3167 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3168 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3169 persFlag2 = atoi(argv[3]);
3171 if ( argc == 5 || argc == 8 ) {
3172 persFlag3 = atoi(argv[4]);
3175 origin.SetX( atof(argv[argc - 3]) );
3176 origin.SetY( atof(argv[argc - 2]) );
3177 origin.SetZ( atof(argv[argc - 1]) );
3180 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3181 Handle(Standard_Transient) anObj;
3183 anObj = GetMapOfAIS().Find2(shapeName);
3184 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3185 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3186 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3187 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3188 di << argv[0] << " All persistence modifiers were removed" << "\n";
3191 di << argv[0] << " Wrong object type" << "\n";
3194 } else { // Create the AIS_Shape from a name
3195 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3196 if ( !aShape.IsNull() ) {
3197 GetMapOfAIS().Bind( aShape, shapeName );
3198 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3199 TheAISContext()->Display( aShape, Standard_False );
3201 di << argv[0] << " Object not found" << "\n";
3206 // Upadate the screen and redraw the view
3207 TheAISContext()->UpdateCurrentViewer();
3211 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3214 BRep_Builder builder;
3216 BRepTools::Read(shape, s, builder);
3217 DBRep::Set(a[1], shape);
3218 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3219 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3223 //============================================================================
3224 #include <AIS2D_InteractiveContext.hxx>
3225 #include <HLRAlgo_Projector.hxx>
3226 #include <Prs3d_Projector.hxx>
3227 #include <AIS2D_ProjShape.hxx>
3228 #include <gp_Ax2.hxx>
3230 Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3233 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3234 /////////////////////
3235 TopoDS_Shape aShape = DBRep::Get(a[1]);
3236 aContext2D->EraseAll(Standard_True);
3237 //Standard_Integer aPolyAlgo = 0;
3238 Standard_Boolean IsPoly = Standard_False;
3239 gp_Ax2 anAx2 = gp::XOY();
3241 //if(n > 2) aPolyAlgo = atoi(a[2]);
3243 //IsPoly = aPolyAlgo > 0;
3245 TopoDS_Shape aResult = aShape;
3250 Standard_Real x = atof(a[2]);
3251 Standard_Real y = atof(a[3]);
3252 Standard_Real z = atof(a[4]);
3254 Standard_Real dx = atof(a[5]);
3255 Standard_Real dy = atof(a[6]);
3256 Standard_Real dz = atof(a[7]);
3258 Standard_Real dx1 = atof(a[8]);
3259 Standard_Real dy1 = atof(a[9]);
3260 Standard_Real dz1 = atof(a[10]);
3262 gp_Pnt anOrigin (x, y, z);
3263 gp_Dir aNormal (dx, dy, dz);
3264 gp_Dir aDX (dx1, dy1, dz1);
3265 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3269 HLRAlgo_Projector aProjector(anAx2);
3271 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3273 //aProjector = aProjector_t.Projector();
3275 Handle(AIS2D_ProjShape) myDisplayableShape =
3276 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3278 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3279 Standard_False, Standard_True, Standard_False);
3281 myDisplayableShape->Add( aResult );
3284 aContext2D->Display( myDisplayableShape,Standard_True );
3285 aContext2D->UpdateCurrentViewer();
3290 Standard_Integer phlrtest(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_True;
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 //==============================================================================
3351 //function : ViewerTest::Commands
3352 //purpose : Add all the viewer command in the Draw_Interpretor
3353 //==============================================================================
3355 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3357 ViewerTest::ViewerCommands(theCommands);
3358 ViewerTest::RelationCommands(theCommands);
3359 ViewerTest::ObjectCommands(theCommands);
3360 ViewerTest::FilletCommands(theCommands);
3361 ViewerTest::VoxelCommands(theCommands);
3363 const char *group = "AIS_Display";
3367 theCommands.Add("vdisplay",
3368 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3369 __FILE__,VDisplay2,group);
3371 theCommands.Add("verase",
3372 "verase : verase2 [name1] ... [name n] ",
3373 __FILE__,VErase2,group);
3375 theCommands.Add("vdonly",
3376 "vdonly : vdonly2 [name1] ... [name n]",
3377 __FILE__,VDonly2,group);
3379 theCommands.Add("vdisplayall",
3380 "vdisplayall : vdisplayall",
3381 __FILE__,VDisplayAll,group);
3383 theCommands.Add("veraseall",
3384 "veraseall : veraseall ",
3385 __FILE__,VEraseAll,group);
3387 theCommands.Add("verasetype",
3388 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3389 __FILE__,VEraseType,group);
3391 theCommands.Add("vdisplaytype",
3392 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3393 __FILE__,VDisplayType,group);
3395 theCommands.Add("vdisplaymode",
3396 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3397 __FILE__,VDispMode,group);
3399 theCommands.Add("verasemode",
3400 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3401 __FILE__,VDispMode,group);
3403 theCommands.Add("vsetdispmode",
3404 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3405 __FILE__,VDispMode,group);
3407 theCommands.Add("vunsetdispmode",
3408 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3409 __FILE__,VDispMode,group);
3411 theCommands.Add("vdir",
3413 __FILE__,VDebug,group);
3415 theCommands.Add("vdump",
3416 "<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",
3417 __FILE__,VDump,group);
3419 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3420 __FILE__,VSubInt,group);
3422 theCommands.Add("vsetcolor",
3423 "vsetcolor : vsetcolor [name of shape] ColorName",
3424 __FILE__,VColor2,group);
3426 theCommands.Add("vunsetcolor",
3427 "vunsetcolor : vunsetcolor [name of shape] ",
3428 __FILE__,VColor2,group);
3430 theCommands.Add("vsettransparency",
3431 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3432 __FILE__,VTransparency,group);
3434 theCommands.Add("vunsettransparency",
3435 "vunsettransparency : vtransparency [name of shape]",
3436 __FILE__,VTransparency,group);
3438 theCommands.Add("vsetmaterial",
3439 "vmaterial : vmaterial [name of shape] MaterialName",
3440 __FILE__,VMaterial,group);
3442 theCommands.Add("vunsetmaterial",
3443 "vmaterial : vmaterial [name of shape]",
3444 __FILE__,VMaterial,group);
3446 theCommands.Add("vsetwidth",
3447 "vsetwidth : vwidth [name of shape] width(0->10)",
3448 __FILE__,VWidth,group);
3450 theCommands.Add("vunsetwidth",
3451 "vunsetwidth : vwidth [name of shape]",
3452 __FILE__,VWidth,group);
3454 theCommands.Add("vardis",
3455 "vardis : display activeareas",
3456 __FILE__,VDispAreas,group);
3458 theCommands.Add("varera",
3459 "varera : erase activeareas",
3460 __FILE__,VClearAreas,group);
3462 theCommands.Add("vsensdis",
3463 "vardisp : display active entities",
3464 __FILE__,VDispSensi,group);
3465 theCommands.Add("vsensera",
3466 "vardisp : erase active entities",
3467 __FILE__,VClearSensi,group);
3469 theCommands.Add("vperf",
3470 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3471 __FILE__,VPerf,group);
3473 theCommands.Add("vanimation",
3474 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3475 __FILE__,VAnimation,group);
3477 theCommands.Add("vsetshading",
3478 "vsetshading : vsetshading name Quality(default=0.0008) ",
3479 __FILE__,VShading,group);
3481 theCommands.Add("vunsetshading",
3482 "vunsetshading :vunsetshading name ",
3483 __FILE__,VShading,group);
3485 theCommands.Add("vtexture",
3486 "'vtexture NameOfShape TextureFile' \n \
3487 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3488 or 'vtexture NameOfShape ?' to list available textures\n \
3489 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3490 __FILE__,VTexture,group);
3492 theCommands.Add("vtexscale",
3493 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3494 or 'vtexscale NameOfShape ScaleUV' \n \
3495 or 'vtexscale NameOfShape' to disable scaling\n ",
3496 __FILE__,VTexture,group);
3498 theCommands.Add("vtexorigin",
3499 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3500 or 'vtexorigin NameOfShape UVOrigin' \n \
3501 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3502 __FILE__,VTexture,group);
3504 theCommands.Add("vtexrepeat",
3505 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3506 or 'vtexrepeat NameOfShape UVRepeat \n \
3507 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3510 theCommands.Add("vtexdefault",
3511 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3514 theCommands.Add("vsetam",
3515 "vsetActivatedModes: vsetam mode(1->7) ",
3516 __FILE__,VActivatedMode,group);
3518 theCommands.Add("vunsetam",
3519 "vunsetActivatedModes: vunsetam ",
3520 __FILE__,VActivatedMode,group);
3522 theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
3523 __FILE__,VState,group);
3525 theCommands.Add("vpickshapes",
3526 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3527 __FILE__,VPickShape,group);
3529 theCommands.Add("vtypes",
3530 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3533 theCommands.Add("vsettransmode",
3534 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3535 __FILE__,VSetTransMode,group);
3537 theCommands.Add("vr", "vr : reading of the shape",
3538 __FILE__,vr, group);
3540 theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3541 theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3545 //=====================================================================
3546 //========================= for testing Draft and Rib =================
3547 //=====================================================================
3548 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3549 #include <DBRep.hxx>
3550 #include <TopoDS_Face.hxx>
3551 #include <gp_Pln.hxx>
3552 #include <AIS_KindOfSurface.hxx>
3553 #include <BRepOffsetAPI_DraftAngle.hxx>
3554 #include <Precision.hxx>
3555 #include <BRepAlgo.hxx>
3556 #include <OSD_Environment.hxx>
3557 #include <DrawTrSurf.hxx>
3558 //#include <DbgTools.hxx>
3559 //#include <FeatAlgo_MakeLinearForm.hxx>
3564 //=======================================================================
3565 //function : IsValid
3567 //=======================================================================
3568 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3569 const TopoDS_Shape& theResult,
3570 const Standard_Boolean closedSolid,
3571 const Standard_Boolean GeomCtrl)
3573 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3574 TCollection_AsciiString checkValid = check.Value();
3575 Standard_Boolean ToCheck = Standard_True;
3576 if (!checkValid.IsEmpty()) {
3578 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3580 if ( checkValid=="true" || checkValid=="TRUE" ) {
3581 ToCheck= Standard_False;
3585 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3588 Standard_Boolean IsValid = Standard_True;
3590 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3595 //===============================================================================
3596 // TDraft : test draft, uses AIS Viewer
3597 // Solid Face Plane Angle Reverse
3598 //===============================================================================
3599 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3601 if (argc < 5) return 1;
3602 // argv[1] - TopoDS_Shape Solid
3603 // argv[2] - TopoDS_Shape Face
3604 // argv[3] - TopoDS_Shape Plane
3605 // argv[4] - Standard_Real Angle
3606 // argv[5] - Standard_Integer Reverse
3608 // sprintf(prefix, argv[1]);
3609 Standard_Real anAngle = 0;
3610 Standard_Boolean Rev = Standard_False;
3611 Standard_Integer rev = 0;
3612 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3613 TopoDS_Shape face = GetShapeFromName(argv[2]);
3614 TopoDS_Face Face = TopoDS::Face(face);
3615 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3616 if (Plane.IsNull ()) {
3617 di << "TEST : Plane is NULL" << "\n";
3620 anAngle = atof(argv[4]);
3621 anAngle = 2*M_PI * anAngle / 360.0;
3623 Handle( Geom_Surface )aSurf;
3624 AIS_KindOfSurface aSurfType;
3625 Standard_Real Offset;
3627 if(argc > 4) { // == 5
3628 rev = atoi(argv[5]);
3629 Rev = (rev)? Standard_True : Standard_False;
3632 TopoDS_Face face2 = TopoDS::Face(Plane);
3633 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3635 di << "TEST : Can't find plane" << "\n";
3639 aDir = aPln.Axis().Direction();
3642 if (Plane.Orientation() == TopAbs_REVERSED)
3644 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3646 BRepOffsetAPI_DraftAngle Draft (Solid);
3648 if(Abs(anAngle)< Precision::Angular()) {
3649 di << "TEST : NULL angle" << "\n";
3652 if(Rev) anAngle = - anAngle;
3653 Draft.Add (Face, aDir, anAngle, aPln);
3655 if (!Draft.IsDone()) {
3656 di << "TEST : Draft Not DONE " << "\n";
3659 TopTools_ListOfShape Larg;
3661 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3662 di << "TEST : DesignAlgo returns Not valid" << "\n";
3666 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3667 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3669 if ( !ais.IsNull() ) {
3670 ais->SetColor(DEFAULT_COLOR);
3671 ais->SetMaterial(DEFAULT_MATERIAL);
3672 // Display the AIS_Shape without redraw
3673 Ctx->Display(ais, Standard_False);
3675 const char *Name = "draft1";
3676 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3678 Handle(AIS_InteractiveObject) an_object =
3679 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3680 if (!an_object.IsNull()) {
3681 Ctx->Remove(an_object,
3683 GetMapOfAIS().UnBind2(Name) ;
3686 GetMapOfAIS().Bind(ais, Name);
3687 // DBRep::Set("draft", ais->Shape());
3689 Ctx->Display(ais, Standard_True);
3695 //============================================================================
3697 //============================================================================
3698 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3701 DrawTrSurf::BasicCommands(theCommands);
3702 const char* group = "Check Features Operations commands";
3704 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3706 &TDraft,group); //Draft_Modification
3709 //==============================================================================
3710 // ViewerTest::Factory
3711 //==============================================================================
3712 void ViewerTest::Factory(Draw_Interpretor& theDI)
3714 // definition of Viewer Command
3715 ViewerTest::Commands(theDI);
3716 ViewerTest::AviCommands(theDI);
3717 Viewer2dTest::Commands(theDI);
3719 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3723 // Declare entry point PLUGINFACTORY