1 // File: ViewerTest.cxx
2 // Created: Wed Jul 23 14:14:01 1997
3 // Author: Henri JEANNIN
4 // <bbl@entrax.paris3.matra-dtv.fr>
5 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
7 // Modified by Robert Coublanc [nov 16-17-18 1998]
8 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
9 // ViewerTest_ObjectCommands.cxx
10 // ViewerTest_RelationCommands.cxx
11 // -add Functions and commands for interactive selection of shapes and objects
12 // in AIS Viewers. (PickShape(s), PickObject(s),
14 #include <Standard_Stream.hxx>
16 #include <ViewerTest.hxx>
17 #include <TopLoc_Location.hxx>
18 #include <TopTools_HArray1OfShape.hxx>
19 #include <TColStd_HArray1OfTransient.hxx>
20 #include <OSD_Directory.hxx>
21 #include <OSD_File.hxx>
22 #include <OSD_Path.hxx>
23 #include <OSD_Timer.hxx>
24 #include <Geom_Axis2Placement.hxx>
25 #include <Geom_Axis1Placement.hxx>
26 #include <gp_Trsf.hxx>
27 #include <TopExp_Explorer.hxx>
28 #include <BRepAdaptor_Curve.hxx>
29 #include <StdSelect_ShapeTypeFilter.hxx>
31 #include <AIS_InteractiveObject.hxx>
32 #include <AIS_Trihedron.hxx>
33 #include <AIS_Axis.hxx>
34 #include <AIS_Relation.hxx>
35 #include <AIS_TypeFilter.hxx>
36 #include <AIS_SignatureFilter.hxx>
37 #include <AIS_ListOfInteractive.hxx>
38 #include <AIS_ListIteratorOfListOfInteractive.hxx>
39 #include <Image_PixMap.hxx>
49 #include <Draw_Interpretor.hxx>
50 #include <TCollection_AsciiString.hxx>
51 #include <Draw_PluginMacro.hxx>
52 #include <ViewerTest.hxx>
53 #include <Viewer2dTest.hxx>
55 // avoid warnings on 'extern "C"' functions returning C++ classes
57 #define _CRT_SECURE_NO_DEPRECATE
58 #pragma warning(4:4190)
59 #pragma warning (disable:4996)
62 #include <NIS_InteractiveContext.hxx>
63 #include <NIS_Triangulated.hxx>
64 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
66 //=======================================================================
67 //function : GetColorFromName
68 //purpose : get the Quantity_NameOfColor from a string
69 //=======================================================================
71 #include <Quantity_NameOfColor.hxx>
72 #include <Quantity_Color.hxx>
73 #include <Quantity_NameOfColor.hxx>
75 #include <Graphic3d_NameOfMaterial.hxx>
77 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
78 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
80 static Quantity_NameOfColor GetColorFromName( const char *name )
82 Quantity_NameOfColor ret = DEFAULT_COLOR;
84 Standard_Boolean Found = Standard_False;
85 Standard_CString colstring;
86 for(Standard_Integer i=0;i<=514 && !Found;i++)
88 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
89 if (!strcasecmp(name,colstring)) {
90 ret = (Quantity_NameOfColor)i;
91 Found = Standard_True;
98 //=======================================================================
99 //function : GetMaterialFromName
100 //purpose : get the Graphic3d_NameOfMaterial from a string
101 //=======================================================================
103 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
105 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
107 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
108 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
109 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
110 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
111 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
112 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
113 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
114 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
115 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
116 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
117 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
118 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
119 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
120 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
121 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
122 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
123 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
124 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
125 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
126 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
131 //=======================================================================
132 //function : GetTypeNames
134 //=======================================================================
135 static const char** GetTypeNames()
137 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
138 "Shape","ConnectedShape","MultiConn.Shape",
139 "ConnectedInter.","MultiConn.",
140 "Constraint","Dimension"};
141 static const char** ThePointer = names;
145 //=======================================================================
146 //function : GetTypeAndSignfromString
148 //=======================================================================
149 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
151 const char ** thefullnames = GetTypeNames();
152 Standard_Integer index(-1);
154 for(Standard_Integer i=0;i<=13 && index==-1;i++)
155 if(!strcasecmp(name,thefullnames[i]))
159 TheType = AIS_KOI_None;
165 TheType = AIS_KOI_Datum;
169 TheType = AIS_KOI_Shape;
173 TheType = AIS_KOI_Object;
177 TheType = AIS_KOI_Relation;
186 #include <Draw_Interpretor.hxx>
188 #include <Draw_Appli.hxx>
192 #include <TCollection_AsciiString.hxx>
193 #include <V3d_Viewer.hxx>
194 #include <V3d_View.hxx>
197 #include <AIS_InteractiveContext.hxx>
198 #include <AIS_Shape.hxx>
199 #include <AIS_TexturedShape.hxx>
200 #include <AIS_DisplayMode.hxx>
201 #include <TColStd_MapOfInteger.hxx>
202 #include <AIS_MapOfInteractive.hxx>
203 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
204 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
205 #include <ViewerTest_EventManager.hxx>
207 #include <TopoDS_Solid.hxx>
208 #include <BRepTools.hxx>
209 #include <BRep_Builder.hxx>
210 #include <TopAbs_ShapeEnum.hxx>
212 #include <TopoDS.hxx>
213 #include <BRep_Tool.hxx>
216 #include <Draw_Window.hxx>
217 #include <AIS_ListIteratorOfListOfInteractive.hxx>
218 #include <AIS_ListOfInteractive.hxx>
219 #include <AIS_DisplayMode.hxx>
220 #include <TopTools_ListOfShape.hxx>
221 #include <BRepOffsetAPI_MakeThickSolid.hxx>
222 #include <BRepOffset.hxx>
225 //==============================================================================
226 //function : GetTypeNameFromShape
227 //purpose : get the shape type as a string from a shape
228 //==============================================================================
230 static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
231 { const char *ret = "????";
233 if ( aShape.IsNull() ) ret = "Null Shape";
235 switch ( aShape.ShapeType() ) {
236 case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
237 case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
238 case TopAbs_SOLID : ret = "SOLID" ; break;
239 case TopAbs_SHELL : ret = "SHELL" ; break;
240 case TopAbs_FACE : ret = "FACE" ; break;
241 case TopAbs_WIRE : ret = "WIRE" ; break;
242 case TopAbs_EDGE : ret = "EDGE" ; break;
243 case TopAbs_VERTEX : ret = "VERTEX" ; break;
244 case TopAbs_SHAPE : ret = "SHAPE" ; break;
248 //==============================================================================
249 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
250 //==============================================================================
251 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
252 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
256 static TColStd_MapOfInteger theactivatedmodes(8);
257 static TColStd_ListOfTransient theEventMgrs;
259 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
260 const Handle(AIS_InteractiveContext)& Ctx)
262 theEventMgrs.Clear();
263 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
266 static Handle(V3d_View)& a3DView(){
267 static Handle(V3d_View) Viou;
271 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
272 static Handle(AIS_InteractiveContext) aContext;
276 Handle(V3d_View) ViewerTest::CurrentView()
280 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
285 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
287 static Handle(NIS_InteractiveContext) aContext;
288 if (aContext.IsNull()) {
289 aContext = new NIS_InteractiveContext;
290 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
295 Handle(AIS_InteractiveContext) ViewerTest::GetAISContext()
297 return TheAISContext();
300 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
302 TheAISContext() = aCtx;
303 ViewerTest::ResetEventManager();
306 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
308 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
311 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
313 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
317 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
318 theEventMgrs.Prepend(EM);
321 void ViewerTest::UnsetEventManager()
323 theEventMgrs.RemoveFirst();
327 void ViewerTest::ResetEventManager()
329 const Handle(NIS_View) aView =
330 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
331 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
334 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
336 Handle(ViewerTest_EventManager) EM;
337 if(theEventMgrs.IsEmpty()) return EM;
338 Handle(Standard_Transient) Tr = theEventMgrs.First();
339 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
344 //=======================================================================
345 //function : Get Context and active viou..
347 //=======================================================================
348 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
349 Handle(V3d_View)& Viou)
351 Ctx = ViewerTest::GetAISContext();
354 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
355 Vwr->InitActiveViews();
356 if(Vwr->MoreActiveViews())
357 Viou = Vwr->ActiveView();
362 //==============================================================================
363 //function : GetShapeFromName
364 //purpose : Compute an Shape from a draw variable or a file name
365 //==============================================================================
367 static TopoDS_Shape GetShapeFromName(const char* name)
369 TopoDS_Shape S = DBRep::Get(name);
372 BRep_Builder aBuilder;
373 BRepTools::Read( S, name, aBuilder);
378 //==============================================================================
379 //function : GetShapeFromName
380 //purpose : Compute an Shape from a draw variable or a file name
381 //==============================================================================
384 static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
386 TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
390 //==============================================================================
391 //function : GetAISShapeFromName
392 //purpose : Compute an AIS_Shape from a draw variable or a file name
393 //==============================================================================
394 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
396 Handle(AIS_Shape) retsh;
398 if(GetMapOfAIS().IsBound2(name)){
399 const Handle(AIS_InteractiveObject) IO =
400 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
402 if(IO->Type()==AIS_KOI_Shape)
403 if(IO->Signature()==0){
404 retsh = *((Handle(AIS_Shape)*)&IO);
407 cout << "an Object which is not an AIS_Shape "
408 "already has this name!!!"<<endl;
414 TopoDS_Shape S = GetShapeFromName(name);
416 retsh = new AIS_Shape(S);
422 //==============================================================================
424 //purpose : Remove all the object from the viewer
425 //==============================================================================
426 void ViewerTest::Clear()
428 if ( !a3DView().IsNull() ) {
429 if (TheAISContext()->HasOpenedContext())
430 TheAISContext()->CloseLocalContext();
431 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
432 while ( it.More() ) {
433 cout << "Remove " << it.Key2() << endl;
434 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
435 const Handle(AIS_InteractiveObject) anObj =
436 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
437 TheAISContext()->Remove(anObj,Standard_False);
438 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
439 const Handle(NIS_InteractiveObject) anObj =
440 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
441 TheNISContext()->Remove(anObj,Standard_False);
445 TheAISContext()->UpdateCurrentViewer();
446 TheNISContext()->UpdateViews();
447 GetMapOfAIS().Clear();
451 //==============================================================================
452 //function : StandardModesActivation
453 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
455 //==============================================================================
456 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
458 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
460 if (TheAISContext()->HasOpenedContext())
461 aContext->CloseLocalContext();
464 if(!aContext->HasOpenedContext()) {
465 // To unhilight the preselected object
466 aContext->UnhilightCurrents(Standard_False);
467 // Open a local Context in order to be able to select subshape from
468 // the selected shape if any or for all if there is no selection
469 if (!aContext->FirstCurrentObject().IsNull()){
470 aContext->OpenLocalContext(Standard_False);
472 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
473 aContext->Load( aContext->Current(),-1,Standard_True);
477 aContext->OpenLocalContext();
480 const char *cmode="???";
483 case 0: cmode = "Shape"; break;
484 case 1: cmode = "Vertex"; break;
485 case 2: cmode = "Edge"; break;
486 case 3: cmode = "Wire"; break;
487 case 4: cmode = "Face"; break;
488 case 5: cmode = "Shell"; break;
489 case 6: cmode = "Solid"; break;
490 case 7: cmode = "Compound"; break;
493 if(theactivatedmodes.Contains(mode))
495 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
496 theactivatedmodes.Remove(mode);
497 cout<<"Mode "<< cmode <<" OFF"<<endl;
501 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
502 theactivatedmodes.Add(mode);
503 cout<<"Mode "<< cmode << " ON" << endl;
508 //==============================================================================
509 //function : SelectFromContext
510 //purpose : pick / select an object from the last MoveTo() on a
512 //==============================================================================
514 Handle(AIS_InteractiveObject) Select(Standard_Integer argc,
516 Standard_Boolean shift,
517 Standard_Boolean pick )
519 Handle(AIS_InteractiveObject) ret;
520 Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
527 const Handle(AIS_InteractiveContext) aContext = EM->Context();
529 if ( !aContext->HasOpenedContext() ) {
530 aContext->InitCurrent();
531 while ( aContext->MoreCurrent() ) {
532 Handle(AIS_InteractiveObject) aisPickedShape =
533 Handle(AIS_InteractiveObject)::DownCast(aContext->Current());
536 const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
537 // const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
538 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
540 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape);
541 if(!TheRealSh.IsNull()){
542 cout << "Current is " << name
543 << " (" << GetTypeNameFromShape(TheRealSh->Shape())
546 ret = aisPickedShape;
547 if(!TheRealSh.IsNull()){
548 if ( pick && argc > 4 ) {
549 DBRep::Set(argv[4], TheRealSh->Shape());
552 aContext->NextCurrent();
556 // A LocalContext is opened, the use xxxxSelected()
557 // to select an object and its SubShape
558 aContext->InitSelected();
559 while ( aContext->MoreSelected() ) {
560 if ( !aContext->HasSelectedShape() ) {
563 TopoDS_Shape PickedShape = aContext->SelectedShape();
564 if ( pick && argc > 5 ) {
565 DBRep::Set(argv[5], PickedShape);
569 if ( aContext->Interactive().IsNull() ) {
570 cout << "??? (No InteractiveObject selected)" << endl;
573 Handle(AIS_InteractiveObject) aisPicked =
574 Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive());
576 Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked);
580 const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
581 // const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
582 GetMapOfAIS().Find1(aisPicked).ToCString() :
585 if(!aisPickedShape.IsNull()){
586 if ( pick && argc > 4 ) {
587 // Create a draw variable to store the wohole shape
589 DBRep::Set(argv[4], aisPickedShape->Shape());
592 cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape())
596 // Goto the next selected object
597 aContext->NextSelected();
603 //==============================================================================
604 //function : DetectedFromContext
605 //purpose : hilight dynamicaly an object from the last MoveTo() on a
607 //==============================================================================
608 Handle(AIS_InteractiveObject) DetectedFromContext(
609 Handle(AIS_InteractiveContext) aContext )
611 Handle(AIS_InteractiveObject) ret;
612 if ( aContext->HasDetected() ) {
613 if ( !aContext->HasDetectedShape() ) {
614 //No SubShape selected
617 // Get the detected SubShape
618 TopoDS_Shape PickedShape = aContext->DetectedShape();
620 if ( !aContext->DetectedInteractive().IsNull() ) {
621 Handle(AIS_InteractiveObject) aisPickedShape =
622 Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive());
623 ret = aisPickedShape;
627 ( GetMapOfAIS().IsBound1(aisPickedShape) )?
628 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
636 //==============================================================================
637 //function : VDispAreas,VDispSensitive,...
638 //purpose : Redraw the view
640 //==============================================================================
641 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
644 Handle(AIS_InteractiveContext) Ctx;
645 Handle(V3d_View) Viou;
646 GetCtxAndView(Ctx,Viou);
647 Ctx->DisplayActiveAreas(Viou);
650 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
652 Handle(AIS_InteractiveContext) Ctx;
653 Handle(V3d_View) Viou;
654 GetCtxAndView(Ctx,Viou);
655 Ctx->ClearActiveAreas(Viou);
659 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
661 Handle(AIS_InteractiveContext) Ctx;
662 Handle(V3d_View) Viou;
663 GetCtxAndView(Ctx,Viou);
664 Ctx->DisplayActiveSensitive(Viou);
668 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
670 Handle(AIS_InteractiveContext) Ctx;
671 Handle(V3d_View) Viou;
672 GetCtxAndView(Ctx,Viou);
673 Ctx->ClearActiveSensitive(Viou);
677 //==============================================================================
679 //purpose : To list the displayed object with their attributes
681 //==============================================================================
682 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
683 { if ( !a3DView().IsNull() ) {
684 di << "List of object in the viewer :" << "\n";
686 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
688 while ( it.More() ) {
689 di << "\t" << it.Key2().ToCString() << "\n";
697 //==============================================================================
699 //purpose : To dump the active view snapshot to image file
700 //Draw arg : Picture file name with extension corresponding to desired format
701 //==============================================================================
702 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
706 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
710 Image_TypeOfImage aBufferType = Image_TOI_RGB;
714 TCollection_AsciiString aBuffTypeStr (argv[2]);
715 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
717 aBufferType = Image_TOI_RGB;
719 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
721 aBufferType = Image_TOI_RGBA;
723 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
725 aBufferType = Image_TOI_FLOAT;
729 Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0;
730 Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
732 Handle(AIS_InteractiveContext) IC;
733 Handle(V3d_View) view;
734 GetCtxAndView (IC, view);
737 if (aWidth > 0 && aHeight > 0)
739 return view->ToPixMap (aWidth, aHeight, aBufferType)->Dump (argv[1]) ? 0 : 1;
743 return view->Dump (argv[1], aBufferType) ? 0 : 1;
748 di << "Cannot find an active viewer/view" << "\n";
754 //==============================================================================
755 //function : Displays,Erase...
758 //==============================================================================
759 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
760 const Standard_Integer Mode,
761 const Standard_Integer TypeOfOperation,
762 const Standard_Boolean Upd)
764 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
766 switch(TypeOfOperation){
768 Ctx->Display(IO,Mode,Upd);
771 Ctx->Erase(IO,Mode,Upd);
776 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
778 Ctx->SetDisplayMode(IO,Mode,Upd);
783 Ctx->SetDisplayMode(0,Upd);
785 Ctx->UnsetDisplayMode(IO,Upd);
792 //=======================================================================
795 //=======================================================================
796 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
799 TCollection_AsciiString name;
802 // display others presentations
803 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
804 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
805 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
806 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
808 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
810 //unset displaymode.. comportement particulier...
811 if(TypeOfOperation==4){
813 if(Ctx->NbCurrents()==0 ||
814 Ctx->NbSelected()==0){
815 Handle(AIS_InteractiveObject) IO;
816 VwrTst_DispErase(IO,-1,4,Standard_False);
818 else if(!Ctx->HasOpenedContext()){
819 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
820 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
823 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
824 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
825 Ctx->UpdateCurrentViewer();
828 Handle(AIS_InteractiveObject) IO;
830 if(GetMapOfAIS().IsBound2(name)){
831 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
833 VwrTst_DispErase(IO,-1,4,Standard_True);
838 Standard_Integer Dmode = atoi(argv[1]);
839 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
840 Handle(AIS_InteractiveObject) IO;
841 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
843 if(!Ctx->HasOpenedContext()){
844 // set/unset display mode sur le Contexte...
845 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
846 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
848 Ctx->UpdateCurrentViewer();
851 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
852 Ctx->Display(Ctx->Interactive(),Dmode);
856 Handle(AIS_InteractiveObject) IO;
858 if(GetMapOfAIS().IsBound2(name))
859 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
861 VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
867 //=======================================================================
870 //=======================================================================
871 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
873 if(argc==1) return 1;
874 Standard_Integer On = atoi(argv[1]);
875 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
879 if(!Ctx->HasOpenedContext()){
880 di<<"sub intensite ";
883 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
884 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
886 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
888 di <<"passage dans off"<<"\n";
889 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
894 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
896 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
898 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
901 Ctx->UpdateCurrentViewer();
904 Handle(AIS_InteractiveObject) IO;
905 TCollection_AsciiString name = argv[2];
906 if(GetMapOfAIS().IsBound2(name)){
907 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
910 Ctx->SubIntensityOn(IO);
912 Ctx->SubIntensityOff(IO);
920 //==============================================================================
923 //purpose : change the color of a selected or named or displayed shape
924 //Draw arg : vcolor2 [name] color
925 //==============================================================================
926 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
929 Standard_Boolean ThereIsCurrent;
930 Standard_Boolean ThereIsArgument;
931 Standard_Boolean IsBound = Standard_False ;
932 Standard_Boolean HaveToSet;
934 if (!strcasecmp( argv[0],"vsetcolor")) HaveToSet=Standard_True;
935 else HaveToSet=Standard_False;
937 if ( argc<2 || argc > 3 ) { di << argv[0] << " syntax error: Passez 2 ou 3 arguments" << "\n"; return 1; }
938 if ( argc == 2 ) {ThereIsArgument=Standard_False;}
939 else ThereIsArgument=Standard_True;
943 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
944 if(argc==2) ThereIsArgument=Standard_True;
945 else ThereIsArgument=Standard_False;
948 if ( !a3DView().IsNull() ) {
949 TCollection_AsciiString name;
950 if (ThereIsArgument) {
952 IsBound= GetMapOfAIS().IsBound2(name);
954 if (TheAISContext()->HasOpenedContext())
955 TheAISContext()->CloseLocalContext();
957 // On set le Booleen There is current
958 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
959 else ThereIsCurrent =Standard_False;
961 //=======================================================================
962 // Il y a un argument
963 //=======================================================================
964 if ( ThereIsArgument && IsBound ) {
965 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
966 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
967 Handle(AIS_InteractiveObject) ashape =
968 Handle(AIS_InteractiveObject)::DownCast (anObj);
970 //cout << "HaveToSet "<<HaveToSet <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << endl;
972 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
974 di << "HaveToSet "<< "0" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
978 TheAISContext()->SetColor(ashape,GetColorFromName(argv[2]) );
981 TheAISContext()->UnsetColor(ashape);
982 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
983 Handle(NIS_Triangulated) ashape =
984 Handle(NIS_Triangulated)::DownCast (anObj);
985 if (ashape.IsNull() == Standard_False)
986 ashape->SetColor (GetColorFromName(argv[2]));
991 //=======================================================================
992 // Il n'y a pas d'arguments
993 // Mais un ou plusieurs objets on des current representation
994 //=======================================================================
995 if (ThereIsCurrent && !ThereIsArgument) {
996 for (TheAISContext() -> InitCurrent() ;
997 TheAISContext() -> MoreCurrent() ;
998 TheAISContext() ->NextCurrent() )
1000 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1001 if (ashape.IsNull())
1004 //cout << "HaveToSet "<<HaveToSet <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << endl;
1006 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1008 di << "HaveToSet "<< "0" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1011 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1013 TheAISContext()->UnsetColor(ashape,Standard_False);
1016 TheAISContext()->UpdateCurrentViewer();
1019 //=======================================================================
1020 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1021 // on impose a tous les objets du viewer la couleur passee
1022 //=======================================================================
1023 else if (!ThereIsCurrent && !ThereIsArgument){
1024 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1025 while ( it.More() ) {
1026 const Handle(AIS_InteractiveObject) ashape =
1027 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1028 if (!ashape.IsNull())
1030 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),
1033 TheAISContext()->UnsetColor(ashape,Standard_False);
1036 TheAISContext()->UpdateCurrentViewer();
1042 //==============================================================================
1043 //function : VTransparency
1045 //purpose : change the transparency of a selected or named or displayed shape
1046 //Draw arg : vtransparency [name] TransparencyCoeficient
1047 //==============================================================================
1050 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1053 Standard_Boolean ThereIsCurrent;
1054 Standard_Boolean ThereIsArgument;
1055 Standard_Boolean IsBound = Standard_False ;
1056 Standard_Boolean HaveToSet;
1057 if (!strcasecmp( argv[0],"vsettransparency"))
1058 HaveToSet=Standard_True;
1060 HaveToSet=Standard_False;
1063 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1064 if ( argc == 2 ) {ThereIsArgument=Standard_False;}
1065 else ThereIsArgument=Standard_True;
1068 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1069 if(argc==2) ThereIsArgument=Standard_True;
1070 else ThereIsArgument=Standard_False;
1073 if ( !a3DView().IsNull() ) {
1074 TCollection_AsciiString name;
1075 if (ThereIsArgument) {
1077 IsBound= GetMapOfAIS().IsBound2(name);
1079 if (TheAISContext()->HasOpenedContext())
1080 TheAISContext()->CloseLocalContext();
1082 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1083 else ThereIsCurrent = Standard_False;
1085 //=======================================================================
1086 // Il y a des arguments: un nom et une couleur
1087 //=======================================================================
1088 if ( ThereIsArgument && IsBound ) {
1089 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1090 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1091 const Handle(AIS_InteractiveObject) ashape =
1092 Handle(AIS_InteractiveObject)::DownCast(anObj);
1094 TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1096 TheAISContext()->UnsetTransparency(ashape);
1097 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1098 const Handle(NIS_InteractiveObject) ashape =
1099 Handle(NIS_InteractiveObject)::DownCast(anObj);
1101 ashape->SetTransparency(atof(argv[2]) );
1103 ashape->UnsetTransparency();
1106 //=======================================================================
1107 // Il n'y a pas d'arguments
1108 // Mais un ou plusieurs objets on des current representation
1109 //=======================================================================
1110 if (ThereIsCurrent && !ThereIsArgument) {
1111 for (TheAISContext() -> InitCurrent() ;
1112 TheAISContext() -> MoreCurrent() ;
1113 TheAISContext() ->NextCurrent() )
1115 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1117 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1120 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1123 TheAISContext()->UpdateCurrentViewer();
1125 //=======================================================================
1126 // Il n'y a pas d'arguments ET aucun objet courrant
1127 //=======================================================================
1128 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1129 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1131 while ( it.More() ) {
1132 Handle(AIS_InteractiveObject) ashape =
1133 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1134 if (!ashape.IsNull())
1136 TheAISContext()->SetTransparency(ashape,atof(argv[1]),
1139 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1142 TheAISContext()->UpdateCurrentViewer();
1149 //==============================================================================
1150 //function : VMaterial
1152 //purpose : change the Material of a selected or named or displayed shape
1153 //Draw arg : vmaterial [Name] Material
1154 //==============================================================================
1155 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1158 Standard_Boolean ThereIsCurrent;
1159 Standard_Boolean ThereIsName;
1160 Standard_Boolean IsBound = Standard_False ;
1162 Standard_Boolean HaveToSet;
1163 if (!strcasecmp( argv[0],"vsetmaterial")) HaveToSet=Standard_True;
1164 else HaveToSet=Standard_False;
1166 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1167 if ( argc == 2 ) {ThereIsName=Standard_False;}
1168 else ThereIsName=Standard_True;
1171 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1172 if (argc==2) ThereIsName=Standard_True;
1173 else ThereIsName=Standard_False;
1177 if ( !a3DView().IsNull() ) {
1178 TCollection_AsciiString name;
1181 IsBound= GetMapOfAIS().IsBound2(name);
1183 if (TheAISContext()->HasOpenedContext())
1184 TheAISContext()->CloseLocalContext();
1185 if (TheAISContext() -> NbCurrents() > 0 )
1186 ThereIsCurrent =Standard_True;
1188 ThereIsCurrent =Standard_False;
1190 //=======================================================================
1191 // Ther is a name of shape and a material name
1192 //=======================================================================
1193 if ( ThereIsName && IsBound ) {
1194 Handle(AIS_InteractiveObject) ashape =
1195 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1196 if (!ashape.IsNull())
1198 TheAISContext()->SetMaterial (ashape,
1199 GetMaterialFromName (argv[2]) );
1201 TheAISContext()->UnsetMaterial(ashape);
1203 //=======================================================================
1204 // Il n'y a pas de nom de shape
1205 // Mais un ou plusieurs objets on des current representation
1206 //=======================================================================
1207 if (ThereIsCurrent && !ThereIsName) {
1208 for (TheAISContext() -> InitCurrent() ;
1209 TheAISContext() -> MoreCurrent() ;
1210 TheAISContext() ->NextCurrent() )
1212 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1214 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),
1217 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1219 TheAISContext()->UpdateCurrentViewer();
1222 //=======================================================================
1223 // Il n'y a pas de noms de shape ET aucun objet courrant
1224 // On impose a tous les objets du viewer le material passe en argument
1225 //=======================================================================
1226 else if (!ThereIsCurrent && !ThereIsName){
1227 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1229 while ( it.More() ) {
1230 Handle(AIS_InteractiveObject) ashape =
1231 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1232 if (!ashape.IsNull())
1234 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),
1237 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1240 TheAISContext()->UpdateCurrentViewer();
1248 //==============================================================================
1251 //purpose : change the width of the edges of a selected or named or displayed shape
1252 //Draw arg : vwidth [Name] WidthValue(1->10)
1253 //==============================================================================
1254 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1257 Standard_Boolean ThereIsCurrent;
1258 Standard_Boolean ThereIsArgument;
1259 Standard_Boolean IsBound = Standard_False ;
1261 Standard_Boolean HaveToSet;
1262 if (!strcasecmp( argv[0],"vsetwidth")) HaveToSet=Standard_True;
1263 else HaveToSet=Standard_False;
1265 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1266 if ( argc == 2 ) {ThereIsArgument=Standard_False;}
1267 else ThereIsArgument=Standard_True;
1270 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1271 if (argc==2) ThereIsArgument=Standard_True;
1272 else ThereIsArgument=Standard_False;
1274 if ( !a3DView().IsNull() ) {
1275 TCollection_AsciiString name;
1276 if (ThereIsArgument) {
1278 IsBound= GetMapOfAIS().IsBound2(name);
1280 if (TheAISContext()->HasOpenedContext())
1281 TheAISContext()->CloseLocalContext();
1283 if (TheAISContext() -> NbCurrents() > 0 )
1284 ThereIsCurrent =Standard_True;
1286 ThereIsCurrent =Standard_False;
1288 if ( ThereIsArgument && IsBound ) {
1289 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1290 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1291 const Handle(AIS_InteractiveObject) ashape =
1292 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1294 TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1296 TheAISContext()->UnsetWidth (ashape);
1297 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1298 const Handle(NIS_Triangulated) ashape =
1299 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1300 if (HaveToSet && !ashape.IsNull())
1301 ashape->SetLineWidth ( atof (argv[2]) );
1305 //=======================================================================
1306 // Il n'y a pas d'arguments
1307 // Mais un ou plusieurs objets on des current representation
1308 //=======================================================================
1309 if (ThereIsCurrent && !ThereIsArgument) {
1310 for (TheAISContext() -> InitCurrent() ;
1311 TheAISContext() -> MoreCurrent() ;
1312 TheAISContext() ->NextCurrent() )
1314 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1316 TheAISContext()->SetWidth(ashape,atof (argv[1]),Standard_False);
1318 TheAISContext()->UnsetWidth (ashape,Standard_False);
1321 TheAISContext()->UpdateCurrentViewer();
1323 //=======================================================================
1324 // Il n'y a pas d'arguments ET aucun objet courrant
1325 //=======================================================================
1326 else if (!ThereIsCurrent && !ThereIsArgument){
1327 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1329 while ( it.More() ) {
1330 Handle(AIS_InteractiveObject) ashape =
1331 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1332 if (!ashape.IsNull())
1334 TheAISContext()->SetWidth(ashape,atof (argv[1]),Standard_False );
1336 TheAISContext()->UnsetWidth (ashape,Standard_False);
1339 TheAISContext()->UpdateCurrentViewer();
1344 //==============================================================================
1345 //function : VDonly2
1347 //purpose : Display only a selected or named object
1348 // if there is no selected or named object s, nothing is donne
1349 //Draw arg : vdonly2 [name1] ... [name n]
1350 //==============================================================================
1351 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1354 if ( a3DView().IsNull() )
1357 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1358 Standard_Boolean ThereIsArgument= argc>1;
1360 if (TheAISContext()->HasOpenedContext())
1361 TheAISContext()->CloseLocalContext();
1363 //===============================================================
1364 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1366 //===============================================================
1367 if (!ThereIsArgument && ThereIsCurrent) {
1370 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1373 for(TheAISContext()->InitCurrent();
1374 TheAISContext()->MoreCurrent();
1375 TheAISContext()->NextCurrent()){
1376 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1377 TheAISContext()->Erase(aShape,Standard_False);}
1379 TheAISContext() ->UpdateCurrentViewer();
1380 //===============================================================
1381 // Il y a des arguments
1382 //===============================================================
1383 if (ThereIsArgument) {
1384 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1386 while ( it.More() ) {
1387 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1388 const Handle(AIS_InteractiveObject) aShape =
1389 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1390 TheAISContext()->Erase(aShape,Standard_False);
1391 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1392 const Handle(NIS_InteractiveObject) aShape =
1393 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1394 TheNISContext()->Erase(aShape,Standard_False);
1399 // On display les objets passes par parametre
1400 for (int i=1; i<argc ; i++) {
1401 TCollection_AsciiString name=argv[i];
1402 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1404 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1405 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1406 const Handle(AIS_InteractiveObject) aShape =
1407 Handle(AIS_InteractiveObject)::DownCast (anObj);
1408 TheAISContext()->Display(aShape, Standard_False);
1409 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1410 const Handle(NIS_InteractiveObject) aShape =
1411 Handle(NIS_InteractiveObject)::DownCast (anObj);
1412 TheNISContext()->Display(aShape, 0L, Standard_False);
1416 TheAISContext() ->UpdateCurrentViewer();
1417 TheNISContext() ->UpdateViews();
1422 //==============================================================================
1423 //function : VErase2
1425 //purpose : Erase some selected or named objects
1426 // if there is no selected or named objects, the whole viewer is erased
1427 //Draw arg : verase2 [name1] ... [name n]
1428 //==============================================================================
1429 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1432 if ( a3DView().IsNull() )
1435 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1436 Standard_Boolean ThereIsArgument= argc>1;
1437 if(TheAISContext()->HasOpenedContext())
1438 TheAISContext()->CloseLocalContext();
1440 //===============================================================
1441 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1443 //===============================================================
1444 if (!ThereIsArgument && ThereIsCurrent) {
1445 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1447 while ( it.More() ) {
1448 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1449 const Handle(AIS_InteractiveObject) aShape =
1450 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1451 if (TheAISContext()->IsCurrent(aShape))
1452 TheAISContext()->Erase(aShape,Standard_False);
1457 TheAISContext() ->UpdateCurrentViewer();
1460 //===============================================================
1461 // Il n'y a pas d'arguments et aucuns objets selectionnes
1463 // On erase tout le viewer
1464 //===============================================================
1466 if (!ThereIsArgument && !ThereIsCurrent) {
1467 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1468 while ( it.More() ) {
1469 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1470 const Handle(AIS_InteractiveObject) aShape =
1471 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1472 TheAISContext()->Erase(aShape,Standard_False);
1473 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1474 const Handle(NIS_InteractiveObject) aShape =
1475 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1476 TheNISContext()->Erase(aShape,Standard_False);
1480 TheAISContext() ->UpdateCurrentViewer();
1481 TheNISContext()->UpdateViews();
1484 //===============================================================
1485 // Il y a des arguments
1486 //===============================================================
1487 if (ThereIsArgument) {
1488 for (int i=1; i<argc ; i++) {
1489 TCollection_AsciiString name=argv[i];
1490 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1492 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1493 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1494 const Handle(AIS_InteractiveObject) aShape =
1495 Handle(AIS_InteractiveObject)::DownCast (anObj);
1496 TheAISContext()->Erase(aShape,Standard_False);
1497 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1498 const Handle(NIS_InteractiveObject) aShape =
1499 Handle(NIS_InteractiveObject)::DownCast (anObj);
1500 TheNISContext()->Erase(aShape,Standard_False);
1504 TheAISContext() ->UpdateCurrentViewer();
1505 TheNISContext() ->UpdateViews();
1510 //==============================================================================
1511 //function : VEraseAll
1513 //purpose : Erase all the objects displayed in the viewer
1514 //Draw arg : veraseall
1515 //==============================================================================
1516 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1519 // Verification des arguments
1520 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1521 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1522 TheAISContext()->CloseAllContexts(Standard_False);
1523 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1525 while ( it.More() ) {
1526 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1527 const Handle(AIS_InteractiveObject) aShape =
1528 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1529 TheAISContext()->Erase(aShape,Standard_False);
1530 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1531 const Handle(NIS_InteractiveObject) aShape =
1532 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1533 TheNISContext()->Erase(aShape,Standard_False);
1537 TheAISContext() ->UpdateCurrentViewer();
1538 TheNISContext() ->UpdateViews();
1543 //==============================================================================
1544 //function : VDisplayAll
1546 //purpose : Display all the objects of the Map
1547 //Draw arg : vdisplayall
1548 //==============================================================================
1549 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1552 if (! a3DView().IsNull() ) {
1553 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1554 if (TheAISContext()->HasOpenedContext())
1555 TheAISContext()->CloseLocalContext();
1556 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1558 while ( it.More() ) {
1559 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1560 const Handle(AIS_InteractiveObject) aShape =
1561 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1562 TheAISContext()->Erase(aShape,Standard_False);
1563 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1564 const Handle(NIS_InteractiveObject) aShape =
1565 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1566 TheNISContext()->Erase(aShape,Standard_False);
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()->Display(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()->Display(aShape, 0L, Standard_False);
1583 TheAISContext() ->UpdateCurrentViewer();
1584 TheNISContext() ->UpdateViews();
1590 //#######################################################################################################
1593 static TCollection_AsciiString GetEnvir (Draw_Interpretor& di) {
1595 static Standard_Boolean IsDefined=Standard_False ;
1596 static TCollection_AsciiString VarName;
1598 const char *envir, *casroot ;
1599 envir = getenv("CSF_MDTVTexturesDirectory") ;
1601 Standard_Boolean HasDefinition = Standard_False ;
1603 casroot = getenv("CASROOT");
1605 VarName = TCollection_AsciiString (casroot);
1606 VarName += "/src/Textures" ;
1607 HasDefinition = Standard_True ;
1610 VarName = TCollection_AsciiString (envir);
1611 HasDefinition = Standard_True ;
1613 if ( HasDefinition ) {
1614 OSD_Path aPath ( VarName );
1615 OSD_Directory aDir(aPath);
1616 if ( aDir.Exists () ) {
1617 TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb" ;
1618 OSD_File TextureFile ( aTexture );
1619 if ( !TextureFile.Exists() ) {
1620 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1621 di << " not all files are found in : "<<VarName.ToCString() << "\n";
1622 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1625 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1626 di << " Directory : "<< VarName.ToCString() << " not exist " << "\n";
1627 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1631 di << " CSF_MDTVTexturesDirectory and CASROOT not setted " << "\n";
1632 di << " one of these variable are mandatory to use this fonctionnality" << "\n";
1633 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory and CASROOT not setted " );
1635 IsDefined = Standard_True ;
1641 //#######################################################################################################
1644 //#######################################################################################################
1648 //#######################################################################################################
1650 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1652 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1653 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1654 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1655 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1656 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1658 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1659 if(myAISContext.IsNull())
1661 di << "use 'vinit' command before " << argv[0] << "\n";
1665 Handle(AIS_InteractiveObject) TheAisIO;
1666 Handle(AIS_TexturedShape) myShape;
1667 Standard_Integer myPreviousMode = 0;
1669 if (argc<2 || !argv[1])
1671 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1675 TCollection_AsciiString name = argv[1];
1676 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1678 if (GetMapOfAIS().IsBound2(name))
1679 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1680 (GetMapOfAIS().Find2(name));
1681 if (TheAisIO.IsNull())
1683 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1687 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1689 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1690 myPreviousMode = myShape->DisplayMode() ;
1694 myAISContext->Clear(TheAisIO,Standard_False);
1695 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1696 GetMapOfAIS().UnBind1(TheAisIO);
1697 GetMapOfAIS().UnBind2(name);
1698 GetMapOfAIS().Bind(myShape, name);
1702 case 1: // vtexture : we only map a texture on the shape
1705 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1708 if (argc>2 && argv[2])
1710 if(strcasecmp(argv[2],"?")==0)
1712 TCollection_AsciiString monPath = GetEnvir (di) ;
1714 di<<"\n Files in current directory : \n"<<"\n";
1715 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1716 di.Eval(Cmnd.ToCString());
1718 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1721 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1722 di.Eval(Cmnd.ToCString());
1727 myShape->SetTextureFileName(argv[2]);
1731 di <<"Texture mapping disabled \n \
1732 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1734 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1735 if (myPreviousMode == 3 )
1736 myAISContext->RecomputePrsOnly(myShape);
1737 myAISContext->Display(myShape, Standard_True);
1742 case 2: // vtexscale : we change the scaling factor of the texture
1746 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1750 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1751 ( argv[2] ? atof(argv[2]) : 1.0 ),
1752 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1755 case 3: // vtexorigin : we change the origin of the texture on the shape
1758 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1761 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1762 ( argv[2] ? atof(argv[2]) : 0.0 ),
1763 ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1766 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1769 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1772 if (argc>2 && argv[2])
1774 di <<"Texture repeat enabled"<<"\n";
1775 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1779 di <<"Texture repeat disabled"<<"\n";
1780 myShape->SetTextureRepeat(Standard_False);
1784 case 5: // vtexdefault : default texture mapping
1785 // ScaleU = ScaleV = 100.0
1786 // URepeat = VRepeat = 1.0
1787 // Uorigin = VOrigin = 0.0
1791 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1794 myShape->SetTextureRepeat(Standard_False);
1795 myShape->SetTextureOrigin(Standard_False);
1796 myShape->SetTextureScale (Standard_False);
1800 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1801 myAISContext->RecomputePrsOnly(myShape);
1804 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1805 myAISContext->Display(myShape, Standard_True);
1806 myAISContext->Update(myShape,Standard_True);
1811 //==============================================================================
1812 //function : VDisplay2
1814 //purpose : Display an object from its name
1815 //Draw arg : vdisplay name1 [name2] ... [name n]
1816 //==============================================================================
1817 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1820 // Verification des arguments
1821 if ( a3DView().IsNull() ) {
1823 ViewerTest::ViewerInit();
1824 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1829 di<<argv[0]<<" Syntaxe error"<<"\n";
1834 TCollection_AsciiString name;
1835 if (TheAISContext()->HasOpenedContext())
1836 TheAISContext()->CloseLocalContext();
1838 for ( int i = 1; i < argc; i++ ) {
1840 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1841 Standard_Boolean IsDatum = Standard_False;
1842 Handle(Standard_Transient) anObj;
1844 anObj = GetMapOfAIS().Find2(name);
1845 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1846 Handle(AIS_InteractiveObject) aShape =
1847 Handle(AIS_InteractiveObject)::DownCast(anObj);
1848 if (aShape->Type()==AIS_KOI_Datum) {
1849 IsDatum = Standard_True;
1850 TheAISContext()->Display(aShape, Standard_False);
1853 di << "Display " << name.ToCString() << "\n";
1854 // Get the Shape from a name
1855 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
1857 // Update the Shape in the AIS_Shape
1858 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
1859 if(!TheRealSh.IsNull())
1860 TheRealSh->Set(NewShape);
1861 TheAISContext()->Redisplay(aShape, Standard_False);
1862 TheAISContext()->Display(aShape, Standard_False);
1865 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1866 Handle(NIS_InteractiveObject) aShape =
1867 Handle(NIS_InteractiveObject)::DownCast(anObj);
1868 TheNISContext()->Display(aShape, 0L, Standard_False);
1871 else { // Create the AIS_Shape from a name
1872 const Handle(AIS_InteractiveObject) aShape =
1873 GetAISShapeFromName((const char *)name.ToCString());
1874 if ( !aShape.IsNull() ) {
1875 GetMapOfAIS().Bind(aShape, name);
1876 TheAISContext()->Display(aShape, Standard_False);
1880 // Upadate the screen and redraw the view
1881 TheAISContext()->UpdateCurrentViewer();
1882 TheNISContext()->UpdateViews();
1886 //==============================================================================
1888 //purpose : Test the annimation of an object along a
1889 // predifined trajectory
1890 //Draw arg : vmove ShapeName
1891 //==============================================================================
1894 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
1899 if (TheAISContext()->HasOpenedContext())
1900 TheAISContext()->CloseLocalContext();
1902 Standard_Real Step=2*PI/180;
1903 Standard_Real Angle=0;
1904 // R est le rayon de l'hellicoide
1906 // D est la distance parcourue en translation en 1 tour
1909 Handle(AIS_InteractiveObject) aIO;
1911 if (GetMapOfAIS().IsBound2(argv[1]))
1912 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
1915 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
1918 TheAISContext()->Deactivate(aIO);
1920 // boucle generant le mouvement
1922 di<<" Transformations"<<"\n";
1923 for (Standard_Real myAngle=0;Angle<5*2*PI; myAngle++) {
1926 gp_Ax3 newBase(gp_Pnt(R*cos(Angle), R*sin(Angle), D*Angle/(2*PI) ), gp_Vec(0,0,1), gp_Vec(1,0,0) );
1928 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
1929 TheAISContext()->SetLocation(aIO,myTransfo);
1931 TheAISContext() ->UpdateCurrentViewer();
1936 di<<" Locations"<<"\n";
1937 gp_Trsf myAngleTrsf;
1938 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
1939 TopLoc_Location myDeltaAngle (myAngleTrsf);
1941 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
1942 TopLoc_Location myDeltaDist (myDistTrsf);
1943 TopLoc_Location myTrueLoc;
1945 for (Standard_Real myAngle=0;Angle<5*2*PI; myAngle++) {
1948 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
1949 TheAISContext()->SetLocation(aIO,myTrueLoc );
1950 TheAISContext() ->UpdateCurrentViewer();
1955 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
1957 //TopLoc_Location Tempo=aIO->Location();
1958 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
1959 //ShapeBis.Located(Tempo);
1962 // On reset la location (origine) contenue dans l'AISInteractiveObject
1963 TheAISContext() ->ResetLocation(aIO);
1965 // On force aShape a devenir l'AIS IO propre a ShapeBis
1967 // Pour cela on force aShape(AIS IO) a devenir une AISShape
1968 // ->Set() est une methode de AIS_Shape
1969 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
1971 // On donne a ShapeBis le nom de l'AIS IO
1972 //Rep::Set(argv[1],ShapeBis);
1975 TheAISContext()->Redisplay(aIO,Standard_False);
1977 // On reactive la selection des primitives sensibles
1978 TheAISContext()->Activate(aIO,0);
1980 TheAISContext() ->UpdateCurrentViewer();
1981 a3DView() -> Redraw();
1984 di<<" Temps ecoule "<<"\n";
1992 //==============================================================================
1994 //purpose : Test the annimation of an object along a
1995 // predifined trajectory
1996 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
1997 //==============================================================================
1999 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2002 if (TheAISContext()->HasOpenedContext())
2003 TheAISContext()->CloseLocalContext();
2005 Standard_Real Step=4*PI/180;
2006 Standard_Real Angle=0;
2008 Handle(AIS_InteractiveObject) aIO;
2009 if (GetMapOfAIS().IsBound2(argv[1]))
2010 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2014 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2018 if (atoi(argv[3])==1 ) {
2019 di<<" Primitives sensibles OFF"<<"\n";
2020 TheAISContext()->Deactivate(aIO);
2023 di<<" Primitives sensibles ON"<<"\n";
2025 // Movement par transformation
2026 if(atoi(argv[2]) ==1) {
2027 di<<" Calcul par Transformation"<<"\n";
2028 for (Standard_Real myAngle=0;Angle<10*2*PI; myAngle++) {
2032 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2033 TheAISContext()->SetLocation(aShape,myTransfo);
2034 TheAISContext() ->UpdateCurrentViewer();
2039 di<<" Calcul par Locations"<<"\n";
2040 gp_Trsf myAngleTrsf;
2041 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2042 TopLoc_Location myDeltaAngle (myAngleTrsf);
2043 TopLoc_Location myTrueLoc;
2045 for (Standard_Real myAngle=0;Angle<10*2*PI; myAngle++) {
2048 myTrueLoc=myTrueLoc*myDeltaAngle;
2049 TheAISContext()->SetLocation(aShape,myTrueLoc );
2050 TheAISContext() ->UpdateCurrentViewer();
2053 if (atoi(argv[3])==1 ){
2054 // On reactive la selection des primitives sensibles
2055 TheAISContext()->Activate(aIO,0);
2057 a3DView() -> Redraw();
2059 di<<" Temps ecoule "<<"\n";
2065 //==================================================================================
2066 // Function : VAnimation
2067 //==================================================================================
2068 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2070 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2074 Standard_Real thread = 4;
2075 Standard_Real angleA=0;
2076 Standard_Real angleB;
2078 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2081 TopoDS_Shape CrankArm;
2082 TopoDS_Shape CylinderHead;
2083 TopoDS_Shape Propeller;
2084 TopoDS_Shape EngineBlock;
2086 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2087 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2088 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2089 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2090 BRepTools::Read(CrankArm,argv[1],B);
2091 BRepTools::Read(CylinderHead,argv[2],B);
2092 BRepTools::Read(Propeller,argv[3],B);
2093 BRepTools::Read(EngineBlock,argv[4],B);
2095 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2101 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2102 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2103 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2104 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2106 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2107 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2108 GetMapOfAIS().Bind(myAisCrankArm,"c");
2109 GetMapOfAIS().Bind(myAisPropeller,"d");
2111 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2112 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2113 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2115 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2116 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2117 TheAISContext()->Display(myAisCrankArm,Standard_False );
2118 TheAISContext()->Display(myAisPropeller,Standard_False);
2120 TheAISContext()->Deactivate(myAisCylinderHead);
2121 TheAISContext()->Deactivate(myAisEngineBlock );
2122 TheAISContext()->Deactivate(myAisCrankArm );
2123 TheAISContext()->Deactivate(myAisPropeller );
2125 // Boucle de mouvement
2126 for (Standard_Real myAngle = 0;angleA<2*PI*10.175 ;myAngle++) {
2128 angleA = thread*myAngle*PI/180;
2129 X = Sin(angleA)*3/8;
2130 angleB = atan(X / Sqrt(-X * X + 1));
2131 Standard_Real decal(25*0.6);
2134 //Build a transformation on the display
2135 gp_Trsf aPropellerTrsf;
2136 aPropellerTrsf.SetRotation(Ax1,angleA);
2137 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2139 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));
2140 gp_Trsf aCrankArmTrsf;
2141 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2142 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2144 TheAISContext()->UpdateCurrentViewer();
2147 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2148 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2150 myAisCrankArm ->ResetLocation();
2151 myAisPropeller->ResetLocation();
2153 myAisCrankArm -> Set(myNewCrankArm );
2154 myAisPropeller -> Set(myNewPropeller);
2156 TheAISContext()->Activate(myAisCylinderHead,0);
2157 TheAISContext()->Activate(myAisEngineBlock,0 );
2158 TheAISContext()->Activate(myAisCrankArm ,0 );
2159 TheAISContext()->Activate(myAisPropeller ,0 );
2165 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2166 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2168 TheAISContext()->UpdateCurrentViewer();
2169 a3DView()->Redraw();
2178 //==============================================================================
2179 //function : VShading
2180 //purpose : Sharpen or roughten the quality of the shading
2181 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2182 //==============================================================================
2183 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv) {
2184 Standard_Boolean HaveToSet;
2185 // Standard_Real myDevAngle;
2186 Standard_Real myDevCoef;
2187 Handle(AIS_InteractiveObject) TheAisIO;
2190 if (!strcasecmp(argv[0],"vsetshading") ) HaveToSet=Standard_True;
2191 else HaveToSet=Standard_False;
2192 if (TheAISContext()->HasOpenedContext())
2193 TheAISContext()->CloseLocalContext();
2198 myDevCoef =atof(argv[2]);
2202 TCollection_AsciiString name=argv[1];
2203 if (GetMapOfAIS().IsBound2(name ))
2205 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2206 if (TheAisIO.IsNull())
2207 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2210 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2214 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2218 TheAISContext()->Redisplay(TheAisIO);
2221 //==============================================================================
2222 //function : HaveMode
2223 //use : VActivatedModes
2224 //==============================================================================
2225 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2227 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2229 TColStd_ListOfInteger List;
2230 TheAISContext()->ActivatedModes (TheAisIO,List);
2231 TColStd_ListIteratorOfListOfInteger it;
2232 Standard_Boolean Found=Standard_False;
2233 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2234 if (it.Value()==mode ) Found=Standard_True;
2241 //==============================================================================
2242 //function : VActivatedMode
2244 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2245 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2246 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2247 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2248 // qu'un nom et qu'un mode.
2249 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2250 //==============================================================================
2251 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2253 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2256 Standard_Boolean HaveToSet;
2257 Standard_Boolean ThereIsName = Standard_False ;
2259 if(!a3DView().IsNull()){
2261 if (!strcasecmp(argv[0],"vsetam")) HaveToSet=Standard_True;
2262 else HaveToSet=Standard_False;
2264 // verification des arguments
2266 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2267 if (argc==3) ThereIsName=Standard_True;
2268 else ThereIsName=Standard_False;
2272 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2274 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2275 di<<" Fermeture du Context local"<<"\n";
2276 if (TheAISContext()->HasOpenedContext())
2277 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="???";
2290 case 0: cmode = "Shape"; break;
2291 case 1: cmode = "Vertex"; break;
2292 case 2: cmode = "Edge"; break;
2293 case 3: cmode = "Wire"; break;
2294 case 4: cmode = "Face"; break;
2295 case 5: cmode = "Shell"; break;
2296 case 6: cmode = "Solid"; break;
2297 case 7: cmode = "Compound"; break;
2300 if( !TheAISContext()->HasOpenedContext() ) {
2301 // il n'y a pas de Context local d'ouvert
2302 // on en ouvre un et on charge toutes les shapes displayees
2303 // on load tous les objets displayees et on Activate les objets de la liste
2304 AIS_ListOfInteractive ListOfIO;
2305 // on sauve dans une AISListOfInteractive tous les objets currents
2306 if (TheAISContext()->NbCurrents()>0 ){
2307 TheAISContext()->UnhilightCurrents(Standard_False);
2309 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2310 ListOfIO.Append(TheAISContext()->Current() );
2315 TheAISContext()->OpenLocalContext(Standard_False);
2316 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2319 Handle(AIS_InteractiveObject) aIO =
2320 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2322 TheAISContext()->Load(aIO,0,Standard_False);
2325 // traitement des objets qui etaient currents dans le Contexte global
2326 if (!ListOfIO.IsEmpty() ) {
2327 // il y avait des objets currents
2328 AIS_ListIteratorOfListOfInteractive iter;
2329 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2330 Handle(AIS_InteractiveObject) aIO=iter.Value();
2331 TheAISContext()->Activate(aIO,aMode);
2332 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2336 // On applique le mode a tous les objets displayes
2337 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2338 it2 (GetMapOfAIS());
2340 Handle(AIS_InteractiveObject) aIO =
2341 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2342 if (!aIO.IsNull()) {
2343 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2344 TheAISContext()->Activate(aIO,aMode);
2353 // un Context local est deja ouvert
2354 // Traitement des objets du Context local
2355 if (TheAISContext()->NbSelected()>0 ){
2356 TheAISContext()->UnhilightSelected(Standard_False);
2357 // il y a des objets selected,on les parcourt
2358 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2359 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2362 if (HaveMode(aIO,aMode) ) {
2363 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2364 TheAISContext()->Deactivate(aIO,aMode);
2367 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2368 TheAISContext()->Activate(aIO,aMode);
2374 // il n'y a pas d'objets selected
2375 // tous les objets diplayes sont traites
2376 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2379 Handle(AIS_InteractiveObject) aIO =
2380 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2381 if (!aIO.IsNull()) {
2382 if (HaveMode(aIO,aMode) ) {
2383 di<<" Mode: "<<cmode<<" OFF pour "
2384 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2385 TheAISContext()->Deactivate(aIO,aMode);
2388 di<<" Mode: "<<cmode<<" ON pour"
2389 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2390 TheAISContext()->Activate(aIO,aMode);
2398 else if (HaveToSet && ThereIsName){
2399 Standard_Integer aMode=atoi(argv [2]);
2400 Handle(AIS_InteractiveObject) aIO =
2401 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2403 if (!aIO.IsNull()) {
2404 const char *cmode="???";
2407 case 0: cmode = "Shape"; break;
2408 case 1: cmode = "Vertex"; break;
2409 case 2: cmode = "Edge"; break;
2410 case 3: cmode = "Wire"; break;
2411 case 4: cmode = "Face"; break;
2412 case 5: cmode = "Shell"; break;
2413 case 6: cmode = "Solid"; break;
2414 case 7: cmode = "Compound"; break;
2417 if( !TheAISContext()->HasOpenedContext() ) {
2418 TheAISContext()->OpenLocalContext(Standard_False);
2419 // On charge tous les objets de la map
2420 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2422 Handle(AIS_InteractiveObject) aShape=
2423 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2424 if (!aShape.IsNull())
2425 TheAISContext()->Load(aShape,0,Standard_False);
2428 TheAISContext()->Activate(aIO,aMode);
2429 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2433 // un Context local est deja ouvert
2434 if (HaveMode(aIO,aMode) ) {
2435 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2436 TheAISContext()->Deactivate(aIO,aMode);
2439 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2440 TheAISContext()->Activate(aIO,aMode);
2452 //==============================================================================
2453 // function : WhoAmI
2455 //==============================================================================
2456 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2459 if (theShape->Type()==AIS_KOI_Datum) {
2460 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2461 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2462 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2463 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2464 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2465 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2466 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2469 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2470 // AIS_Dimentions et AIS_Relations
2471 else if (theShape->Type()==AIS_KOI_Relation) {
2472 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2474 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2475 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2476 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2477 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2478 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2479 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2480 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2481 // AIS no repertorie.
2482 else {di<<" Type Unknown.";}
2488 //==============================================================================
2491 //Draw arg : vstate [nameA] ... [nameN]
2492 //==============================================================================
2493 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2495 Standard_Boolean ThereIsCurrent=Standard_False;
2496 Standard_Boolean ThereIsArguments=Standard_False;
2497 TheAISContext()->CloseAllContexts();
2499 ThereIsArguments=Standard_True;
2501 if (TheAISContext()->NbCurrents()>0 ) {
2502 ThereIsCurrent=Standard_True;
2505 // ==================
2506 // Il y a un argument
2507 // ==================
2508 if (ThereIsArguments ) {
2509 for (int cpt=1;cpt<argc;cpt++) {
2510 // Verification que lq piece est bien bindee.
2511 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2512 const Handle(AIS_InteractiveObject) theShape=
2513 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2515 if (!theShape.IsNull()) {
2516 di<<argv[cpt];WhoAmI(theShape, di);
2517 if (TheAISContext()->IsDisplayed(theShape) ) {
2518 di<<" Displayed"<<"\n";
2521 di<<" Not Displayed"<<"\n";
2526 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2530 else if (ThereIsCurrent ) {
2531 for (TheAISContext() -> InitCurrent() ;
2532 TheAISContext() -> MoreCurrent() ;
2533 TheAISContext() ->NextCurrent() )
2535 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2536 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2537 if (TheAISContext()->IsDisplayed(theShape) ) {
2538 di<<" Displayed"<<"\n";
2541 di<<" Not Displayed"<<"\n";
2547 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2549 while ( it.More() ) {
2550 Handle(AIS_InteractiveObject) theShape =
2551 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2552 if (!theShape.IsNull()) {
2553 di<<it.Key2().ToCString();
2554 WhoAmI(theShape, di);
2555 if (TheAISContext()->IsDisplayed(theShape) ) {
2556 di<<" Displayed"<<"\n";
2559 di<<" Not Displayed"<<"\n";
2570 //=======================================================================
2571 //function : PickObjects
2573 //=======================================================================
2574 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2575 const AIS_KindOfInteractive TheType,
2576 const Standard_Integer TheSignature,
2577 const Standard_Integer MaxPick)
2579 Handle(AIS_InteractiveObject) IO;
2580 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2582 // step 1: prepare the data
2584 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2585 TheAISContext()->AddFilter(F1);
2588 // step 2 : wait for the selection...
2589 // Standard_Boolean IsGood (Standard_False);
2590 // Standard_Integer NbPick(0);
2591 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2592 Standard_Integer NbPickFail(0);
2593 Standard_Integer argccc = 5;
2594 const char *bufff[] = { "A", "B", "C","D", "E" };
2595 const char **argvvv = (const char **) bufff;
2598 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2599 while(ViewerMainLoop(argccc,argvvv)){}
2600 Standard_Integer NbStored = TheAISContext()->NbSelected();
2601 if((unsigned int ) NbStored != NbPickGood)
2602 NbPickGood= NbStored;
2605 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2608 // step3 get result.
2610 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2612 Standard_Integer i(0);
2613 for(TheAISContext()->InitSelected();
2614 TheAISContext()->MoreSelected();
2615 TheAISContext()->NextSelected()){
2617 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2618 arr->SetValue(i,IO2);
2623 TheAISContext()->CloseLocalContext(curindex);
2625 return Standard_True;
2629 //=======================================================================
2630 //function : PickObject
2632 //=======================================================================
2633 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2634 const Standard_Integer TheSignature,
2635 const Standard_Integer MaxPick)
2637 Handle(AIS_InteractiveObject) IO;
2638 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2640 // step 1: prepare the data
2643 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2644 TheAISContext()->AddFilter(F1);
2647 // step 2 : wait for the selection...
2648 Standard_Boolean IsGood (Standard_False);
2649 Standard_Integer NbPick(0);
2650 Standard_Integer argccc = 5;
2651 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2652 const char **argvvv = (const char **) bufff;
2655 while(!IsGood && NbPick<= MaxPick){
2656 while(ViewerMainLoop(argccc,argvvv)){}
2657 IsGood = (TheAISContext()->NbSelected()>0) ;
2659 cout<<"Nb Pick :"<<NbPick<<endl;
2663 // step3 get result.
2665 TheAISContext()->InitSelected();
2666 IO = TheAISContext()->SelectedInteractive();
2670 TheAISContext()->CloseLocalContext(curindex);
2674 //=======================================================================
2675 //function : PickShape
2676 //purpose : First Activate the rightmode + Put Filters to be able to
2677 // pick objets that are of type <TheType>...
2678 //=======================================================================
2680 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2681 const Standard_Integer MaxPick)
2684 // step 1: prepare the data
2686 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2687 TopoDS_Shape result;
2689 if(TheType==TopAbs_SHAPE){
2690 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2691 TheAISContext()->AddFilter(F1);
2694 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2695 TheAISContext()->AddFilter(TF);
2696 TheAISContext()->ActivateStandardMode(TheType);
2701 // step 2 : wait for the selection...
2702 Standard_Boolean NoShape (Standard_True);
2703 Standard_Integer NbPick(0);
2704 Standard_Integer argccc = 5;
2705 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2706 const char **argvvv = (const char **) bufff;
2709 while(NoShape && NbPick<= MaxPick){
2710 while(ViewerMainLoop(argccc,argvvv)){}
2711 NoShape = (TheAISContext()->NbSelected()==0) ;
2713 cout<<"Nb Pick :"<<NbPick<<endl;
2716 // step3 get result.
2720 TheAISContext()->InitSelected();
2721 if(TheAISContext()->HasSelectedShape())
2722 result = TheAISContext()->SelectedShape();
2724 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2725 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2730 TheAISContext()->CloseLocalContext(curindex);
2736 //=======================================================================
2737 //function : PickShapes
2739 //=======================================================================
2740 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2741 Handle(TopTools_HArray1OfShape)& thearr,
2742 const Standard_Integer MaxPick)
2745 Standard_Integer Taille = thearr->Length();
2747 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2749 // step 1: prepare the data
2750 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2751 if(TheType==TopAbs_SHAPE){
2752 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2753 TheAISContext()->AddFilter(F1);
2756 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2757 TheAISContext()->AddFilter(TF);
2758 TheAISContext()->ActivateStandardMode(TheType);
2762 // step 2 : wait for the selection...
2764 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2765 Standard_Integer NbPickFail(0);
2766 Standard_Integer argccc = 5;
2767 const char *bufff[] = { "A", "B", "C","D", "E" };
2768 const char **argvvv = (const char **) bufff;
2771 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2772 while(ViewerMainLoop(argccc,argvvv)){}
2773 Standard_Integer NbStored = TheAISContext()->NbSelected();
2774 if((unsigned int ) NbStored != NbPickGood)
2775 NbPickGood= NbStored;
2778 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2781 // step3 get result.
2783 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2785 Standard_Integer i(0);
2786 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2788 if(TheAISContext()->HasSelectedShape())
2789 thearr->SetValue(i,TheAISContext()->SelectedShape());
2791 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2792 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2796 TheAISContext()->CloseLocalContext(curindex);
2797 return Standard_True;
2801 //=======================================================================
2802 //function : VPickShape
2804 //=======================================================================
2805 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2807 TopoDS_Shape PickSh;
2808 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2811 theType = TopAbs_SHAPE;
2813 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2814 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2815 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2816 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2817 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2818 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2819 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2822 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2823 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2825 TCollection_AsciiString name;
2828 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2830 PickSh = ViewerTest::PickShape(theType);
2839 if(!PickSh.IsNull()){
2840 nbOfSub[Standard_Integer(theType)]++;
2842 name += nameType[Standard_Integer(theType)];
2843 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2848 // si on avait une petite methode pour voir si la shape
2849 // est deja dans la Double map, ca eviterait de creer....
2850 DBRep::Set(name.ToCString(),PickSh);
2852 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2853 GetMapOfAIS().Bind(newsh, name);
2854 TheAISContext()->Display(newsh);
2855 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2858 // Plusieurs objets a picker, vite vite vite....
2861 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2862 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2863 if(ViewerTest::PickShapes(theType,arr)){
2864 for(Standard_Integer i=1;i<=NbToPick;i++){
2865 PickSh = arr->Value(i);
2866 if(!PickSh.IsNull()){
2868 nbOfSub[Standard_Integer(theType)]++;
2871 name += nameType[Standard_Integer(theType)];
2872 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2880 DBRep::Set(name.ToCString(),PickSh);
2881 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2882 GetMapOfAIS().Bind(newsh, name);
2883 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2884 TheAISContext()->Display(newsh);
2894 //=======================================================================
2895 //function : VPickObject
2896 //purpose : filters can be set (type of Object to pick....
2898 //=======================================================================
2901 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
2903 // preparation de la nomination automatique
2904 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
2905 // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
2907 /* TCollection_AsciiString name;
2909 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2911 PickSh = ViewerTest::PickObject(theType);
2920 if(!PickSh.IsNull()){
2921 nbOfSub[Standard_Integer(theType)]++;
2923 name += nameType[Standard_Integer(theType)];
2924 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2929 // si on avait une petite methode pour voir si la shape
2930 // est deja dans la Double map, ca eviterait de creer....
2931 DBRep::Set(name.ToCString(),PickSh);
2933 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2934 GetMapOfAIS().Bind(newsh, name);
2935 TheAISContext()->Display(newsh);
2936 cout<<"Nom de la shape pickee : "<<name<<endl;
2939 // Plusieurs objets a picker, vite vite vite....
2942 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2943 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2944 if(ViewerTest::PickShapes(theType,arr)){
2945 for(Standard_Integer i=1;i<=NbToPick;i++){
2946 PickSh = arr->Value(i);
2947 if(!PickSh.IsNull()){
2949 nbOfSub[Standard_Integer(theType)]++;
2952 name += nameType[Standard_Integer(theType)];
2953 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2961 DBRep::Set(name.ToCString(),PickSh);
2962 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2963 GetMapOfAIS().Bind(newsh, name);
2964 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
2965 TheAISContext()->Display(newsh);
2975 //=======================================================================
2976 //function : list of known objects
2978 //=======================================================================
2979 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
2981 // 1234567890 12345678901234567 123456789
2982 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
2983 TCollection_AsciiString BlankLine(64,'_');
2984 Standard_Integer i ;
2986 di<<"/n"<<BlankLine.ToCString()<<"\n";
2989 Colum[i].Center(20,' ');
2991 di<<"|"<<Colum[i].ToCString();
2994 di<<BlankLine.ToCString()<<"\n";
2996 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
2997 const char ** names = GetTypeNames();
2999 TCollection_AsciiString curstring;
3000 TCollection_AsciiString curcolum[3];
3003 // les objets de type Datum..
3004 curcolum[1]+="Datum";
3006 curcolum[0].Clear();
3007 curcolum[0] += names[i];
3009 curcolum[2].Clear();
3010 curcolum[2]+=TCollection_AsciiString(i+1);
3012 for(Standard_Integer j =0;j<=2;j++){
3013 curcolum[j].Center(20,' ');
3014 di<<"|"<<curcolum[j].ToCString();
3018 di<<BlankLine.ToCString()<<"\n";
3020 // les objets de type shape
3021 curcolum[1].Clear();
3022 curcolum[1]+="Shape";
3023 curcolum[1].Center(20,' ');
3026 curcolum[0].Clear();
3027 curcolum[0] += names[7+i];
3028 curcolum[2].Clear();
3029 curcolum[2]+=TCollection_AsciiString(i);
3031 for(Standard_Integer j =0;j<=2;j++){
3032 curcolum[j].Center(20,' ');
3033 di<<"|"<<curcolum[j].ToCString();
3037 di<<BlankLine.ToCString()<<"\n";
3038 // les IO de type objet...
3039 curcolum[1].Clear();
3040 curcolum[1]+="Object";
3041 curcolum[1].Center(20,' ');
3043 curcolum[0].Clear();
3044 curcolum[0] += names[10+i];
3045 curcolum[2].Clear();
3046 curcolum[2]+=TCollection_AsciiString(i);
3048 for(Standard_Integer j =0;j<=2;j++){
3049 curcolum[j].Center(20,' ');
3050 di<<"|"<<curcolum[j].ToCString();
3054 di<<BlankLine.ToCString()<<"\n";
3055 // les contraintes et dimensions.
3056 // pour l'instant on separe juste contraintes et dimensions...
3057 // plus tard, on detaillera toutes les sortes...
3058 curcolum[1].Clear();
3059 curcolum[1]+="Relation";
3060 curcolum[1].Center(20,' ');
3062 curcolum[0].Clear();
3063 curcolum[0] += names[12+i];
3064 curcolum[2].Clear();
3065 curcolum[2]+=TCollection_AsciiString(i);
3067 for(Standard_Integer j =0;j<=2;j++){
3068 curcolum[j].Center(20,' ');
3069 di<<"|"<<curcolum[j].ToCString();
3073 di<<BlankLine.ToCString()<<"\n";
3080 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3082 if(argc!=2) return 1;
3084 AIS_KindOfInteractive TheType;
3085 Standard_Integer TheSign(-1);
3086 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3089 AIS_ListOfInteractive LIO;
3091 // en attendant l'amelioration ais pour les dimensions...
3093 Standard_Integer dimension_status(-1);
3094 if(TheType==AIS_KOI_Relation){
3095 dimension_status = TheSign ==1 ? 1 : 0;
3099 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3100 Handle(AIS_InteractiveObject) curio;
3101 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3104 if(dimension_status == -1)
3105 TheAISContext()->Erase(curio,Standard_False);
3107 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3108 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3109 (dimension_status==1 && KOD != AIS_KOD_NONE))
3110 TheAISContext()->Erase(curio,Standard_False);
3113 TheAISContext()->UpdateCurrentViewer();
3116 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3118 if(argc!=2) return 1;
3120 AIS_KindOfInteractive TheType;
3121 Standard_Integer TheSign(-1);
3122 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3124 // en attendant l'amelioration ais pour les dimensions...
3126 Standard_Integer dimension_status(-1);
3127 if(TheType==AIS_KOI_Relation){
3128 dimension_status = TheSign ==1 ? 1 : 0;
3132 AIS_ListOfInteractive LIO;
3133 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3134 Handle(AIS_InteractiveObject) curio;
3135 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3137 if(dimension_status == -1)
3138 TheAISContext()->Display(curio,Standard_False);
3140 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3141 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3142 (dimension_status==1 && KOD != AIS_KOD_NONE))
3143 TheAISContext()->Display(curio,Standard_False);
3148 TheAISContext()->UpdateCurrentViewer();
3152 //==============================================================================
3153 //function : VSetTransMode
3155 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3156 //==============================================================================
3158 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3159 // Verification des arguments
3160 if ( a3DView().IsNull() ) {
3161 ViewerTest::ViewerInit();
3162 di << "La commande vinit n'a pas ete appele avant" << "\n";
3165 if ( argc < 3 || argc > 8 ) {
3166 di << argv[0] << " Invalid number of arguments" << "\n";
3170 TCollection_AsciiString shapeName;
3171 shapeName = argv[1];
3172 Standard_Integer persFlag1 = atoi(argv[2]);
3173 Standard_Integer persFlag2 = 0;
3174 Standard_Integer persFlag3 = 0;
3175 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3176 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3177 persFlag2 = atoi(argv[3]);
3179 if ( argc == 5 || argc == 8 ) {
3180 persFlag3 = atoi(argv[4]);
3183 origin.SetX( atof(argv[argc - 3]) );
3184 origin.SetY( atof(argv[argc - 2]) );
3185 origin.SetZ( atof(argv[argc - 1]) );
3188 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3189 Standard_Boolean IsDatum = Standard_False;
3190 Handle(Standard_Transient) anObj;
3192 anObj = GetMapOfAIS().Find2(shapeName);
3193 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3194 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3195 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3196 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3197 di << argv[0] << " All persistence modifiers were removed" << "\n";
3200 di << argv[0] << " Wrong object type" << "\n";
3203 } else { // Create the AIS_Shape from a name
3204 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3205 if ( !aShape.IsNull() ) {
3206 GetMapOfAIS().Bind( aShape, shapeName );
3207 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3208 TheAISContext()->Display( aShape, Standard_False );
3210 di << argv[0] << " Object not found" << "\n";
3215 // Upadate the screen and redraw the view
3216 TheAISContext()->UpdateCurrentViewer();
3220 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3223 BRep_Builder builder;
3225 BRepTools::Read(shape, s, builder);
3226 DBRep::Set(a[1], shape);
3227 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3228 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3232 //============================================================================
3233 #include <AIS2D_InteractiveContext.hxx>
3234 #include <HLRAlgo_Projector.hxx>
3235 #include <Prs3d_Projector.hxx>
3236 #include <AIS2D_ProjShape.hxx>
3237 #include <gp_Ax2.hxx>
3239 Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3242 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3243 /////////////////////
3244 TopoDS_Shape aShape = DBRep::Get(a[1]);
3245 aContext2D->EraseAll(Standard_True);
3246 Standard_Integer aPolyAlgo = 0;
3247 Standard_Boolean IsPoly = Standard_False;
3248 gp_Ax2 anAx2 = gp::XOY();
3250 //if(n > 2) aPolyAlgo = atoi(a[2]);
3252 //IsPoly = aPolyAlgo > 0;
3254 TopoDS_Shape aResult = aShape;
3259 Standard_Real x = atof(a[2]);
3260 Standard_Real y = atof(a[3]);
3261 Standard_Real z = atof(a[4]);
3263 Standard_Real dx = atof(a[5]);
3264 Standard_Real dy = atof(a[6]);
3265 Standard_Real dz = atof(a[7]);
3267 Standard_Real dx1 = atof(a[8]);
3268 Standard_Real dy1 = atof(a[9]);
3269 Standard_Real dz1 = atof(a[10]);
3271 gp_Pnt anOrigin (x, y, z);
3272 gp_Dir aNormal (dx, dy, dz);
3273 gp_Dir aDX (dx1, dy1, dz1);
3274 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3278 HLRAlgo_Projector aProjector(anAx2);
3280 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3282 //aProjector = aProjector_t.Projector();
3284 Handle(AIS2D_ProjShape) myDisplayableShape =
3285 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3287 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3288 Standard_False, Standard_True, Standard_False);
3290 myDisplayableShape->Add( aResult );
3293 aContext2D->Display( myDisplayableShape,Standard_True );
3294 aContext2D->UpdateCurrentViewer();
3299 Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3302 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3303 /////////////////////
3304 TopoDS_Shape aShape = DBRep::Get(a[1]);
3305 aContext2D->EraseAll(Standard_True);
3306 Standard_Integer aPolyAlgo = 0;
3307 Standard_Boolean IsPoly = Standard_True;
3308 gp_Ax2 anAx2 = gp::XOY();
3310 //if(n > 2) aPolyAlgo = atoi(a[2]);
3312 //IsPoly = aPolyAlgo > 0;
3314 TopoDS_Shape aResult = aShape;
3319 Standard_Real x = atof(a[2]);
3320 Standard_Real y = atof(a[3]);
3321 Standard_Real z = atof(a[4]);
3323 Standard_Real dx = atof(a[5]);
3324 Standard_Real dy = atof(a[6]);
3325 Standard_Real dz = atof(a[7]);
3327 Standard_Real dx1 = atof(a[8]);
3328 Standard_Real dy1 = atof(a[9]);
3329 Standard_Real dz1 = atof(a[10]);
3331 gp_Pnt anOrigin (x, y, z);
3332 gp_Dir aNormal (dx, dy, dz);
3333 gp_Dir aDX (dx1, dy1, dz1);
3334 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3338 HLRAlgo_Projector aProjector(anAx2);
3340 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3342 //aProjector = aProjector_t.Projector();
3344 Handle(AIS2D_ProjShape) myDisplayableShape =
3345 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3347 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3348 Standard_False, Standard_True, Standard_False);
3350 myDisplayableShape->Add( aResult );
3353 aContext2D->Display( myDisplayableShape,Standard_True );
3354 aContext2D->UpdateCurrentViewer();
3359 //==============================================================================
3360 //function : ViewerTest::Commands
3361 //purpose : Add all the viewer command in the Draw_Interpretor
3362 //==============================================================================
3364 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3366 ViewerTest::ViewerCommands(theCommands);
3367 ViewerTest::RelationCommands(theCommands);
3368 ViewerTest::ObjectCommands(theCommands);
3369 ViewerTest::FilletCommands(theCommands);
3370 ViewerTest::VoxelCommands(theCommands);
3372 const char *group = "AIS_Display";
3376 theCommands.Add("vdisplay",
3377 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3378 __FILE__,VDisplay2,group);
3380 theCommands.Add("verase",
3381 "verase : verase2 [name1] ... [name n] ",
3382 __FILE__,VErase2,group);
3384 theCommands.Add("vdonly",
3385 "vdonly : vdonly2 [name1] ... [name n]",
3386 __FILE__,VDonly2,group);
3388 theCommands.Add("vdisplayall",
3389 "vdisplayall : vdisplayall",
3390 __FILE__,VDisplayAll,group);
3392 theCommands.Add("veraseall",
3393 "veraseall : veraseall ",
3394 __FILE__,VEraseAll,group);
3396 theCommands.Add("verasetype",
3397 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3398 __FILE__,VEraseType,group);
3400 theCommands.Add("vdisplaytype",
3401 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3402 __FILE__,VDisplayType,group);
3404 theCommands.Add("vdisplaymode",
3405 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3406 __FILE__,VDispMode,group);
3408 theCommands.Add("verasemode",
3409 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3410 __FILE__,VDispMode,group);
3412 theCommands.Add("vsetdispmode",
3413 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3414 __FILE__,VDispMode,group);
3416 theCommands.Add("vunsetdispmode",
3417 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3418 __FILE__,VDispMode,group);
3420 theCommands.Add("vdir",
3422 __FILE__,VDebug,group);
3424 theCommands.Add("vdump",
3425 "<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",
3426 __FILE__,VDump,group);
3428 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3429 __FILE__,VSubInt,group);
3431 theCommands.Add("vsetcolor",
3432 "vsetcolor : vsetcolor [name of shape] ColorName",
3433 __FILE__,VColor2,group);
3435 theCommands.Add("vunsetcolor",
3436 "vunsetcolor : vunsetcolor [name of shape] ",
3437 __FILE__,VColor2,group);
3439 theCommands.Add("vsettransparency",
3440 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3441 __FILE__,VTransparency,group);
3443 theCommands.Add("vunsettransparency",
3444 "vunsettransparency : vtransparency [name of shape]",
3445 __FILE__,VTransparency,group);
3447 theCommands.Add("vsetmaterial",
3448 "vmaterial : vmaterial [name of shape] MaterialName",
3449 __FILE__,VMaterial,group);
3451 theCommands.Add("vunsetmaterial",
3452 "vmaterial : vmaterial [name of shape]",
3453 __FILE__,VMaterial,group);
3455 theCommands.Add("vsetwidth",
3456 "vsetwidth : vwidth [name of shape] width(0->10)",
3457 __FILE__,VWidth,group);
3459 theCommands.Add("vunsetwidth",
3460 "vunsetwidth : vwidth [name of shape]",
3461 __FILE__,VWidth,group);
3463 theCommands.Add("vardis",
3464 "vardis : display activeareas",
3465 __FILE__,VDispAreas,group);
3467 theCommands.Add("varera",
3468 "varera : erase activeareas",
3469 __FILE__,VClearAreas,group);
3471 theCommands.Add("vsensdis",
3472 "vardisp : display active entities",
3473 __FILE__,VDispSensi,group);
3474 theCommands.Add("vsensera",
3475 "vardisp : erase active entities",
3476 __FILE__,VClearSensi,group);
3478 theCommands.Add("vperf",
3479 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3480 __FILE__,VPerf,group);
3482 theCommands.Add("vanimation",
3483 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3484 __FILE__,VAnimation,group);
3486 theCommands.Add("vsetshading",
3487 "vsetshading : vsetshading name Quality(default=0.0008) ",
3488 __FILE__,VShading,group);
3490 theCommands.Add("vunsetshading",
3491 "vunsetshading :vunsetshading name ",
3492 __FILE__,VShading,group);
3494 theCommands.Add("vtexture",
3495 "'vtexture NameOfShape TextureFile' \n \
3496 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3497 or 'vtexture NameOfShape ?' to list available textures\n \
3498 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3499 __FILE__,VTexture,group);
3501 theCommands.Add("vtexscale",
3502 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3503 or 'vtexscale NameOfShape ScaleUV' \n \
3504 or 'vtexscale NameOfShape' to disable scaling\n ",
3505 __FILE__,VTexture,group);
3507 theCommands.Add("vtexorigin",
3508 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3509 or 'vtexorigin NameOfShape UVOrigin' \n \
3510 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3511 __FILE__,VTexture,group);
3513 theCommands.Add("vtexrepeat",
3514 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3515 or 'vtexrepeat NameOfShape UVRepeat \n \
3516 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3519 theCommands.Add("vtexdefault",
3520 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3523 theCommands.Add("vsetam",
3524 "vsetActivatedModes: vsetam mode(1->7) ",
3525 __FILE__,VActivatedMode,group);
3527 theCommands.Add("vunsetam",
3528 "vunsetActivatedModes: vunsetam ",
3529 __FILE__,VActivatedMode,group);
3531 theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
3532 __FILE__,VState,group);
3534 theCommands.Add("vpickshapes",
3535 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3536 __FILE__,VPickShape,group);
3538 theCommands.Add("vtypes",
3539 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3542 theCommands.Add("vsettransmode",
3543 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3544 __FILE__,VSetTransMode,group);
3546 theCommands.Add("vr", "vr : reading of the shape",
3547 __FILE__,vr, group);
3549 theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3550 theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3554 //=====================================================================
3555 //========================= for testing Draft and Rib =================
3556 //=====================================================================
3557 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3558 #include <DBRep.hxx>
3559 #include <TopoDS_Face.hxx>
3560 #include <gp_Pln.hxx>
3561 #include <AIS_KindOfSurface.hxx>
3562 #include <BRepOffsetAPI_DraftAngle.hxx>
3563 #include <Precision.hxx>
3564 #include <BRepAlgo.hxx>
3565 #include <OSD_Environment.hxx>
3566 #include <DrawTrSurf.hxx>
3567 //#include <DbgTools.hxx>
3568 //#include <FeatAlgo_MakeLinearForm.hxx>
3573 //=======================================================================
3574 //function : IsValid
3576 //=======================================================================
3577 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3578 const TopoDS_Shape& theResult,
3579 const Standard_Boolean closedSolid,
3580 const Standard_Boolean GeomCtrl)
3582 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3583 TCollection_AsciiString checkValid = check.Value();
3584 Standard_Boolean ToCheck = Standard_True;
3585 if (!checkValid.IsEmpty()) {
3587 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3589 if ( checkValid=="true" || checkValid=="TRUE" ) {
3590 ToCheck= Standard_False;
3594 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3597 Standard_Boolean IsValid = Standard_True;
3599 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3604 //===============================================================================
3605 // TDraft : test draft, uses AIS Viewer
3606 // Solid Face Plane Angle Reverse
3607 //===============================================================================
3608 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3610 if (argc < 5) return 1;
3611 // argv[1] - TopoDS_Shape Solid
3612 // argv[2] - TopoDS_Shape Face
3613 // argv[3] - TopoDS_Shape Plane
3614 // argv[4] - Standard_Real Angle
3615 // argv[5] - Standard_Integer Reverse
3617 // sprintf(prefix, argv[1]);
3618 Standard_Real anAngle = 0;
3619 Standard_Boolean Rev = Standard_False;
3620 Standard_Integer rev = 0;
3621 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3622 TopoDS_Shape face = GetShapeFromName(argv[2]);
3623 TopoDS_Face Face = TopoDS::Face(face);
3624 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3625 if (Plane.IsNull ()) {
3626 di << "TEST : Plane is NULL" << "\n";
3629 anAngle = atof(argv[4]);
3630 anAngle = 2*PI * anAngle / 360.0;
3632 Handle( Geom_Surface )aSurf;
3633 AIS_KindOfSurface aSurfType;
3634 Standard_Real Offset;
3636 if(argc > 4) { // == 5
3637 rev = atoi(argv[5]);
3638 Rev = (rev)? Standard_True : Standard_False;
3641 TopoDS_Face face2 = TopoDS::Face(Plane);
3642 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3644 di << "TEST : Can't find plane" << "\n";
3648 aDir = aPln.Axis().Direction();
3651 if (Plane.Orientation() == TopAbs_REVERSED)
3653 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3655 BRepOffsetAPI_DraftAngle Draft (Solid);
3657 if(Abs(anAngle)< Precision::Angular()) {
3658 di << "TEST : NULL angle" << "\n";
3661 if(Rev) anAngle = - anAngle;
3662 Draft.Add (Face, aDir, anAngle, aPln);
3664 if (!Draft.IsDone()) {
3665 di << "TEST : Draft Not DONE " << "\n";
3668 TopTools_ListOfShape Larg;
3670 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3671 di << "TEST : DesignAlgo returns Not valid" << "\n";
3675 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3676 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3678 if ( !ais.IsNull() ) {
3679 ais->SetColor(DEFAULT_COLOR);
3680 ais->SetMaterial(DEFAULT_MATERIAL);
3681 // Display the AIS_Shape without redraw
3682 Ctx->Display(ais, Standard_False);
3684 const char *Name = "draft1";
3685 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3687 Handle(AIS_InteractiveObject) an_object =
3688 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3689 if (!an_object.IsNull()) {
3690 Ctx->Remove(an_object,
3692 GetMapOfAIS().UnBind2(Name) ;
3695 GetMapOfAIS().Bind(ais, Name);
3696 // DBRep::Set("draft", ais->Shape());
3698 Ctx->Display(ais, Standard_True);
3704 //============================================================================
3706 //============================================================================
3707 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3710 DrawTrSurf::BasicCommands(theCommands);
3711 const char* group = "Check Features Operations commands";
3713 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3715 &TDraft,group); //Draft_Modification
3718 //==============================================================================
3719 // ViewerTest::Factory
3720 //==============================================================================
3721 void ViewerTest::Factory(Draw_Interpretor& theDI)
3723 // definition of Viewer Command
3724 ViewerTest::Commands(theDI);
3725 ViewerTest::AviCommands(theDI);
3726 Viewer2dTest::Commands(theDI);
3728 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3732 // Declare entry point PLUGINFACTORY