0023510: Integration of test grid "vis" into the new testing system
[occt.git] / src / ViewerTest / ViewerTest.cxx
1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21 // Modified by  Eric Gouthiere [sep-oct 98] -> add commands for display...
22 // Modified by  Robert Coublanc [nov 16-17-18 1998]
23 //             -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
24 //                                                  ViewerTest_ObjectCommands.cxx
25 //                                                  ViewerTest_RelationCommands.cxx
26 //             -add Functions and commands for interactive selection of shapes and objects
27 //              in AIS Viewers. (PickShape(s), PickObject(s),
28
29 #include <Standard_Stream.hxx>
30
31 #include <ViewerTest.hxx>
32 #include <TopLoc_Location.hxx>
33 #include <TopTools_HArray1OfShape.hxx>
34 #include <TColStd_HArray1OfTransient.hxx>
35 #include <OSD_Directory.hxx>
36 #include <OSD_File.hxx>
37 #include <OSD_Path.hxx>
38 #include <OSD_Timer.hxx>
39 #include <Geom_Axis2Placement.hxx>
40 #include <Geom_Axis1Placement.hxx>
41 #include <gp_Trsf.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <StdSelect_ShapeTypeFilter.hxx>
45 #include <AIS.hxx>
46 #include <AIS_Drawer.hxx>
47 #include <AIS_InteractiveObject.hxx>
48 #include <AIS_Trihedron.hxx>
49 #include <AIS_Axis.hxx>
50 #include <AIS_Relation.hxx>
51 #include <AIS_TypeFilter.hxx>
52 #include <AIS_SignatureFilter.hxx>
53 #include <AIS_ListOfInteractive.hxx>
54 #include <AIS_ListIteratorOfListOfInteractive.hxx>
55 #include <Aspect_InteriorStyle.hxx>
56 #include <Graphic3d_AspectFillArea3d.hxx>
57 #include <Graphic3d_TextureRoot.hxx>
58 #include <Image_AlienPixMap.hxx>
59 #include <Prs3d_ShadingAspect.hxx>
60
61 #ifdef HAVE_CONFIG_H
62 # include <config.h>
63 #endif
64 #include <stdio.h>
65 #ifdef HAVE_STRINGS_H
66 # include <strings.h>
67 #endif
68
69 #include <Draw_Interpretor.hxx>
70 #include <TCollection_AsciiString.hxx>
71 #include <Draw_PluginMacro.hxx>
72 #include <ViewerTest.hxx>
73 #include <Viewer2dTest.hxx>
74
75 // avoid warnings on 'extern "C"' functions returning C++ classes
76 #ifdef WNT
77 #define _CRT_SECURE_NO_DEPRECATE
78 #pragma warning(4:4190)
79 #pragma warning (disable:4996)
80 #endif
81
82 #include <NIS_InteractiveContext.hxx>
83 #include <NIS_Triangulated.hxx>
84 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
85
86 #include <Quantity_Color.hxx>
87 #include <Quantity_NameOfColor.hxx>
88
89 #include <Graphic3d_NameOfMaterial.hxx>
90
91 #define DEFAULT_COLOR    Quantity_NOC_GOLDENROD
92 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
93
94 //=======================================================================
95 //function : GetColorFromName
96 //purpose  : get the Quantity_NameOfColor from a string
97 //=======================================================================
98
99 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
100 {
101   for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
102   {
103     Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
104     if (strcasecmp (theName, aColorName) == 0)
105     {
106       return Quantity_NameOfColor (anIter);
107     }
108   }
109
110   return DEFAULT_COLOR;
111 }
112
113 //=======================================================================
114 //function : GetMaterialFromName
115 //purpose  : get the Graphic3d_NameOfMaterial from a string
116 //=======================================================================
117
118 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
119 {
120   Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
121
122   if      ( !strcasecmp(name,"BRASS" ) )         mat = Graphic3d_NOM_BRASS;
123   else if ( !strcasecmp(name,"BRONZE" ) )        mat = Graphic3d_NOM_BRONZE;
124   else if ( !strcasecmp(name,"COPPER" ) )        mat = Graphic3d_NOM_COPPER;
125   else if ( !strcasecmp(name,"GOLD" ) )          mat = Graphic3d_NOM_GOLD;
126   else if ( !strcasecmp(name,"PEWTER" ) )        mat = Graphic3d_NOM_PEWTER;
127   else if ( !strcasecmp(name,"SILVER" ) )        mat = Graphic3d_NOM_SILVER;
128   else if ( !strcasecmp(name,"STEEL" ) )         mat = Graphic3d_NOM_STEEL;
129   else if ( !strcasecmp(name,"METALIZED" ) )     mat = Graphic3d_NOM_METALIZED;
130   else if ( !strcasecmp(name,"STONE" ) )         mat = Graphic3d_NOM_STONE;
131   else if ( !strcasecmp(name,"CHROME" ) )        mat = Graphic3d_NOM_CHROME;
132   else if ( !strcasecmp(name,"ALUMINIUM" ) )     mat = Graphic3d_NOM_ALUMINIUM;
133   else if ( !strcasecmp(name,"NEON_PHC" ) )      mat = Graphic3d_NOM_NEON_PHC;
134   else if ( !strcasecmp(name,"NEON_GNC" ) )      mat = Graphic3d_NOM_NEON_GNC;
135   else if ( !strcasecmp(name,"PLASTER" ) )       mat = Graphic3d_NOM_PLASTER;
136   else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
137   else if ( !strcasecmp(name,"SATIN" ) )         mat = Graphic3d_NOM_SATIN;
138   else if ( !strcasecmp(name,"PLASTIC" ) )       mat = Graphic3d_NOM_PLASTIC;
139   else if ( !strcasecmp(name,"OBSIDIAN" ) )      mat = Graphic3d_NOM_OBSIDIAN;
140   else if ( !strcasecmp(name,"JADE" ) )          mat = Graphic3d_NOM_JADE;
141
142   return mat;
143 }
144
145 //=======================================================================
146 //function : GetTypeNames
147 //purpose  :
148 //=======================================================================
149 static const char** GetTypeNames()
150 {
151   static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
152                           "Shape","ConnectedShape","MultiConn.Shape",
153                           "ConnectedInter.","MultiConn.",
154                           "Constraint","Dimension"};
155   static const char** ThePointer = names;
156   return ThePointer;
157 }
158
159 //=======================================================================
160 //function : GetTypeAndSignfromString
161 //purpose  :
162 //=======================================================================
163 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
164 {
165   const char ** thefullnames = GetTypeNames();
166   Standard_Integer index(-1);
167
168   for(Standard_Integer i=0;i<=13 && index==-1;i++)
169     if(!strcasecmp(name,thefullnames[i]))
170       index = i;
171
172   if(index ==-1){
173     TheType = AIS_KOI_None;
174     TheSign = -1;
175     return;
176   }
177
178   if(index<=6){
179     TheType = AIS_KOI_Datum;
180     TheSign = index+1;
181   }
182   else if (index <=9){
183     TheType = AIS_KOI_Shape;
184     TheSign = index-7;
185   }
186   else if(index<=11){
187     TheType = AIS_KOI_Object;
188     TheSign = index-10;
189   }
190   else{
191     TheType = AIS_KOI_Relation;
192     TheSign = index-12;
193   }
194
195 }
196
197
198
199 #include <string.h>
200 #include <Draw_Interpretor.hxx>
201 #include <Draw.hxx>
202 #include <Draw_Appli.hxx>
203 #include <DBRep.hxx>
204
205
206 #include <TCollection_AsciiString.hxx>
207 #include <V3d_Viewer.hxx>
208 #include <V3d_View.hxx>
209 #include <V3d.hxx>
210
211 #include <AIS_InteractiveContext.hxx>
212 #include <AIS_Shape.hxx>
213 #include <AIS_TexturedShape.hxx>
214 #include <AIS_DisplayMode.hxx>
215 #include <TColStd_MapOfInteger.hxx>
216 #include <AIS_MapOfInteractive.hxx>
217 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
218 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
219 #include <ViewerTest_EventManager.hxx>
220
221 #include <TopoDS_Solid.hxx>
222 #include <BRepTools.hxx>
223 #include <BRep_Builder.hxx>
224 #include <TopAbs_ShapeEnum.hxx>
225
226 #include <TopoDS.hxx>
227 #include <BRep_Tool.hxx>
228
229
230 #include <Draw_Window.hxx>
231 #include <AIS_ListIteratorOfListOfInteractive.hxx>
232 #include <AIS_ListOfInteractive.hxx>
233 #include <AIS_DisplayMode.hxx>
234 #include <TopTools_ListOfShape.hxx>
235 #include <BRepOffsetAPI_MakeThickSolid.hxx>
236 #include <BRepOffset.hxx>
237
238
239 //==============================================================================
240 //function : GetTypeNameFromShape
241 //purpose  : get the shape type as a string from a shape
242 //==============================================================================
243
244 static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
245 { const char *ret = "????";
246
247   if ( aShape.IsNull() ) ret = "Null Shape";
248
249             switch ( aShape.ShapeType() ) {
250               case TopAbs_COMPOUND  : ret = "COMPOUND" ; break;
251               case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
252               case TopAbs_SOLID     : ret = "SOLID" ; break;
253               case TopAbs_SHELL     : ret = "SHELL" ; break;
254               case TopAbs_FACE      : ret = "FACE" ; break;
255               case TopAbs_WIRE      : ret = "WIRE" ; break;
256               case TopAbs_EDGE      : ret = "EDGE" ; break;
257               case TopAbs_VERTEX    : ret = "VERTEX" ; break;
258               case TopAbs_SHAPE     : ret = "SHAPE" ; break;
259             }
260   return ret;
261 }
262 //==============================================================================
263 //  VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
264 //==============================================================================
265 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
266   static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
267   return TheMap;
268 }
269
270
271 //==============================================================================
272 //function : VDisplayAISObject
273 //purpose  : register interactive object in the map of AIS objects;
274 //           if other object with such name already registered, it will be kept
275 //           or replaced depending on value of <theReplaceIfExists>,
276 //           if "true" - the old object will be cleared from AIS context;
277 //           returns Standard_True if <theAISObj> registered in map;
278 //==============================================================================
279 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
280                                                     const Handle(AIS_InteractiveObject)& theAISObj,
281                                                     Standard_Boolean theReplaceIfExists = Standard_True)
282 {
283   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
284   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
285   if (aContextAIS.IsNull())
286   {
287     std::cout << "AIS context is not available.\n";
288     return Standard_False;
289   }
290
291   if (aMap.IsBound2 (theName))
292   {
293     if (!theReplaceIfExists)
294     {
295       std::cout << "Other interactive object has been already "
296                 << "registered with name: " << theName << ".\n"
297                 << "Please use another name.\n";
298       return Standard_False;
299     }
300
301     // stop displaying object
302     Handle(AIS_InteractiveObject) anOldObj =
303        Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
304
305     if (!anOldObj.IsNull())
306       aContextAIS->Clear (anOldObj, Standard_True);
307
308     // remove name and old object from map
309     aMap.UnBind2 (theName);
310   }
311
312   if (theAISObj.IsNull())
313   {
314     // object with specified name already unbound
315     return Standard_True;
316   }
317
318   // unbind AIS object if was bound with another name
319   aMap.UnBind1 (theAISObj);
320
321   // can be registered without rebinding
322   aMap.Bind (theAISObj, theName);
323   aContextAIS->Display (theAISObj, Standard_True);
324   return Standard_True;
325 }
326
327 static TColStd_MapOfInteger theactivatedmodes(8);
328 static TColStd_ListOfTransient theEventMgrs;
329
330 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
331                                 const Handle(AIS_InteractiveContext)& Ctx)
332 {
333   theEventMgrs.Clear();
334   theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
335 }
336
337 static Handle(V3d_View)&  a3DView()
338 {
339   static Handle(V3d_View) Viou;
340   return Viou;
341 }
342
343
344 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
345   static Handle(AIS_InteractiveContext) aContext;
346   return aContext;
347 }
348
349 const Handle(V3d_View)& ViewerTest::CurrentView()
350 {
351   return a3DView();
352 }
353 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
354 {
355   a3DView() = V;
356 }
357
358 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
359 {
360   static Handle(NIS_InteractiveContext) aContext;
361   if (aContext.IsNull()) {
362     aContext = new NIS_InteractiveContext;
363     aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
364   }
365   return aContext;
366 }
367
368 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
369 {
370   return TheAISContext();
371 }
372
373 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
374 {
375   TheAISContext() = aCtx;
376   ViewerTest::ResetEventManager();
377 }
378
379 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
380 {
381   return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
382 }
383
384 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
385 {
386   return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
387 }
388
389
390 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
391   theEventMgrs.Prepend(EM);
392 }
393
394 void ViewerTest::UnsetEventManager()
395 {
396   theEventMgrs.RemoveFirst();
397 }
398
399
400 void ViewerTest::ResetEventManager()
401 {
402   const Handle(NIS_View) aView =
403     Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
404   VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
405 }
406
407 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
408 {
409   Handle(ViewerTest_EventManager) EM;
410   if(theEventMgrs.IsEmpty()) return EM;
411   Handle(Standard_Transient) Tr =  theEventMgrs.First();
412   EM = *((Handle(ViewerTest_EventManager)*)&Tr);
413   return EM;
414 }
415
416
417 //=======================================================================
418 //function : Get Context and active viou..
419 //purpose  :
420 //=======================================================================
421 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
422                    Handle(V3d_View)& Viou)
423 {
424   Ctx = ViewerTest::GetAISContext();
425   if (!Ctx.IsNull())
426   {
427     const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
428     Vwr->InitActiveViews();
429     if(Vwr->MoreActiveViews())
430       Viou = Vwr->ActiveView();
431   }
432 }
433
434
435 //==============================================================================
436 //function : GetShapeFromName
437 //purpose  : Compute an Shape from a draw variable or a file name
438 //==============================================================================
439
440 static TopoDS_Shape GetShapeFromName(const char* name)
441 {
442   TopoDS_Shape S = DBRep::Get(name);
443
444   if ( S.IsNull() ) {
445         BRep_Builder aBuilder;
446         BRepTools::Read( S, name, aBuilder);
447   }
448
449   return S;
450 }
451 //==============================================================================
452 //function : GetShapeFromName
453 //purpose  : Compute an Shape from a draw variable or a file name
454 //==============================================================================
455 // Unused :
456 #ifdef DEB
457 static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
458 {
459   TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
460   return TheShape;
461 }
462 #endif
463 //==============================================================================
464 //function : GetAISShapeFromName
465 //purpose  : Compute an AIS_Shape from a draw variable or a file name
466 //==============================================================================
467 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
468 {
469   Handle(AIS_Shape) retsh;
470
471   if(GetMapOfAIS().IsBound2(name)){
472     const Handle(AIS_InteractiveObject) IO =
473       Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
474     if (!IO.IsNull()) {
475       if(IO->Type()==AIS_KOI_Shape)
476         if(IO->Signature()==0){
477           retsh = *((Handle(AIS_Shape)*)&IO);
478         }
479         else
480           cout << "an Object which is not an AIS_Shape "
481             "already has this name!!!"<<endl;
482     }
483     return retsh;
484   }
485
486
487   TopoDS_Shape S = GetShapeFromName(name);
488   if ( !S.IsNull() ) {
489     retsh = new AIS_Shape(S);
490   }
491   return retsh;
492 }
493
494
495 //==============================================================================
496 //function : Clear
497 //purpose  : Remove all the object from the viewer
498 //==============================================================================
499 void ViewerTest::Clear()
500 {
501   if ( !a3DView().IsNull() ) {
502     if (TheAISContext()->HasOpenedContext())
503       TheAISContext()->CloseLocalContext();
504     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
505     while ( it.More() ) {
506       cout << "Remove " << it.Key2() << endl;
507       if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
508         const Handle(AIS_InteractiveObject) anObj =
509           Handle(AIS_InteractiveObject)::DownCast (it.Key1());
510         TheAISContext()->Remove(anObj,Standard_False);
511       } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
512         const Handle(NIS_InteractiveObject) anObj =
513           Handle(NIS_InteractiveObject)::DownCast (it.Key1());
514         TheNISContext()->Remove(anObj);
515       }
516       it.Next();
517     }
518     TheAISContext()->UpdateCurrentViewer();
519 //    TheNISContext()->UpdateViews();
520     GetMapOfAIS().Clear();
521   }
522 }
523
524 //==============================================================================
525 //function : StandardModesActivation
526 //purpose  : Activate a selection mode, vertex, edge, wire ..., in a local
527 //           Context
528 //==============================================================================
529 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
530 {
531   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
532   if(mode==0) {
533     if (TheAISContext()->HasOpenedContext())
534       aContext->CloseLocalContext();
535   } else {
536
537     if(!aContext->HasOpenedContext()) {
538       // To unhilight the preselected object
539       aContext->UnhilightCurrents(Standard_False);
540       // Open a local Context in order to be able to select subshape from
541       // the selected shape if any or for all if there is no selection
542       if (!aContext->FirstCurrentObject().IsNull()){
543         aContext->OpenLocalContext(Standard_False);
544
545         for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
546           aContext->Load(       aContext->Current(),-1,Standard_True);
547         }
548       }
549       else
550         aContext->OpenLocalContext();
551     }
552
553     const char *cmode="???";
554
555     switch (mode) {
556     case 0: cmode = "Shape"; break;
557     case 1: cmode = "Vertex"; break;
558     case 2: cmode = "Edge"; break;
559     case 3: cmode = "Wire"; break;
560     case 4: cmode = "Face"; break;
561     case 5: cmode = "Shell"; break;
562     case 6: cmode = "Solid"; break;
563     case 7: cmode = "Compsolid"; break;
564     case 8: cmode = "Compound"; break;
565     }
566
567     if(theactivatedmodes.Contains(mode))
568       { // Desactivate
569         aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
570         theactivatedmodes.Remove(mode);
571         cout<<"Mode "<< cmode <<" OFF"<<endl;
572       }
573     else
574       { // Activate
575         aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
576         theactivatedmodes.Add(mode);
577         cout<<"Mode "<< cmode << " ON" << endl;
578       }
579   }
580 }
581
582 //==============================================================================
583 //function : VDispAreas,VDispSensitive,...
584 //purpose  : Redraw the view
585 //Draw arg : No args
586 //==============================================================================
587 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
588 {
589
590   Handle(AIS_InteractiveContext) Ctx;
591   Handle(V3d_View) Viou;
592   GetCtxAndView(Ctx,Viou);
593   Ctx->DisplayActiveAreas(Viou);
594   return 0;
595 }
596 static  int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
597 {
598   Handle(AIS_InteractiveContext) Ctx;
599   Handle(V3d_View) Viou;
600   GetCtxAndView(Ctx,Viou);
601   Ctx->ClearActiveAreas(Viou);
602   return 0;
603
604 }
605 static  int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
606 {
607   Handle(AIS_InteractiveContext) Ctx;
608   Handle(V3d_View) Viou;
609   GetCtxAndView(Ctx,Viou);
610   Ctx->DisplayActiveSensitive(Viou);
611   return 0;
612
613 }
614 static  int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
615 {
616   Handle(AIS_InteractiveContext) Ctx;
617   Handle(V3d_View) Viou;
618   GetCtxAndView(Ctx,Viou);
619   Ctx->ClearActiveSensitive(Viou);
620   return 0;
621 }
622
623 //==============================================================================
624 //function : VDebug
625 //purpose  : To list the displayed object with their attributes
626 //Draw arg : No args
627 //==============================================================================
628 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
629 { if ( !a3DView().IsNull() ) {
630      di << "List of object in the viewer :" << "\n";
631
632     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
633
634     while ( it.More() ) {
635         di << "\t" << it.Key2().ToCString() << "\n";
636         it.Next();
637     }
638   }
639
640   return 0;
641 }
642
643 //==============================================================================
644 //function : VSelPrecision
645 //purpose  : To set the selection precision mode and tolerance value
646 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
647 //           value (integer number of pixel for window mode, double value of
648 //           sensitivity for view mode). Without arguments the function just
649 //           prints the current precision mode and the corresponding tolerance.
650 //==============================================================================
651 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
652 {
653   if( argc > 3 )
654   {
655     di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
656     return 1;
657   }
658
659   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
660   if( aContext.IsNull() )
661     return 1;
662
663   if( argc == 1 )
664   {
665     StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
666     if( aMode == StdSelect_SM_WINDOW )
667     {
668       Standard_Integer aPixelTolerance = aContext->PixelTolerance();
669       di << "Precision mode  : 0 (window)\n";
670       di << "Pixel tolerance : " << aPixelTolerance << "\n";
671     }
672     else if( aMode == StdSelect_SM_VIEW )
673     {
674       Standard_Real aSensitivity = aContext->Sensitivity();
675       di << "Precision mode : 1 (view)\n";
676       di << "Sensitivity    : " << aSensitivity << "\n";
677     }
678   }
679   else if( argc > 1 )
680   {
681     StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )atoi( argv[1] );
682     aContext->SetSensitivityMode( aMode );
683     if( argc > 2 )
684     {
685       if( aMode == StdSelect_SM_WINDOW )
686       {
687         Standard_Integer aPixelTolerance = atoi( argv[2] );
688         aContext->SetPixelTolerance( aPixelTolerance );
689       }
690       else if( aMode == StdSelect_SM_VIEW )
691       {
692         Standard_Real aSensitivity = atof( argv[2] );
693         aContext->SetSensitivity( aSensitivity );
694       }
695     }
696   }
697   return 0;
698 }
699
700 //==============================================================================
701 //function : VDump
702 //purpose  : To dump the active view snapshot to image file
703 //Draw arg : Picture file name with extension corresponding to desired format
704 //==============================================================================
705 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
706 {
707   if (argc < 2)
708   {
709     di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
710     return 1;
711   }
712
713   Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
714   if (argc > 2)
715   {
716     TCollection_AsciiString aBuffTypeStr (argv[2]);
717     if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
718     {
719       aBufferType = Graphic3d_BT_RGB;
720     }
721     else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
722     {
723       aBufferType = Graphic3d_BT_RGBA;
724     }
725     else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
726     {
727       aBufferType = Graphic3d_BT_Depth;
728     }
729   }
730
731   Standard_Integer aWidth  = (argc > 3) ? atoi (argv[3]) : 0;
732   Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
733
734   Handle(AIS_InteractiveContext) IC;
735   Handle(V3d_View) view;
736   GetCtxAndView (IC, view);
737   if (view.IsNull())
738   {
739     di << "Cannot find an active viewer/view\n";
740     return 1;
741   }
742
743   if (aWidth <= 0 || aHeight <= 0)
744   {
745     if (!view->Dump (argv[1], aBufferType))
746     {
747       di << "Dumping failed!\n";
748       return 1;
749     }
750     return 0;
751   }
752
753   Image_AlienPixMap aPixMap;
754   if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
755   {
756     di << "Dumping failed!\n";
757     return 1;
758   }
759
760   if (aPixMap.SizeX() != Standard_Size(aWidth)
761    || aPixMap.SizeY() != Standard_Size(aHeight))
762   {
763     std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
764               << " are lesser than requested " << aWidth          << "x" << aHeight << "\n";
765   }
766   if (!aPixMap.Save (argv[1]))
767   {
768     di << "Saving image failed!\n";
769     return 1;
770   }
771   return 0;
772 }
773
774
775 //==============================================================================
776 //function : Displays,Erase...
777 //purpose  :
778 //Draw arg :
779 //==============================================================================
780 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
781                             const Standard_Integer Mode,
782                             const Standard_Integer TypeOfOperation,
783                             const Standard_Boolean Upd)
784 {
785   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
786
787   switch(TypeOfOperation){
788   case 1:
789     Ctx->Display(IO,Mode,Upd);
790     break;
791   case 2:{
792     Ctx->Erase(IO,Mode,Upd);
793     break;
794   }
795   case 3:{
796     if(IO.IsNull())
797       Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
798     else
799       Ctx->SetDisplayMode(IO,Mode,Upd);
800     break;
801   }
802   case 4:{
803     if(IO.IsNull())
804       Ctx->SetDisplayMode(0,Upd);
805     else
806       Ctx->UnsetDisplayMode(IO,Upd);
807     break;
808   }
809   }
810   return 0;
811 }
812
813 //=======================================================================
814 //function :
815 //purpose  :
816 //=======================================================================
817 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
818 {
819
820   TCollection_AsciiString name;
821   if(argc>3)
822     return 1;
823   // display others presentations
824   Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
825     (strcasecmp(argv[0],"verasemode")==0) ? 2 :
826       (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
827         (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
828
829   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
830
831   //unset displaymode.. comportement particulier...
832   if(TypeOfOperation==4){
833     if(argc==1){
834       if(Ctx->NbCurrents()==0 ||
835          Ctx->NbSelected()==0){
836         Handle(AIS_InteractiveObject) IO;
837         VwrTst_DispErase(IO,-1,4,Standard_False);
838       }
839       else if(!Ctx->HasOpenedContext()){
840         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
841           VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
842       }
843       else{
844         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
845           VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
846       Ctx->UpdateCurrentViewer();
847     }
848     else{
849       Handle(AIS_InteractiveObject) IO;
850       name = argv[1];
851       if(GetMapOfAIS().IsBound2(name)){
852         IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
853         if (!IO.IsNull())
854           VwrTst_DispErase(IO,-1,4,Standard_True);
855       }
856     }
857   }
858   else if(argc==2){
859     Standard_Integer Dmode = atoi(argv[1]);
860     if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
861       Handle(AIS_InteractiveObject) IO;
862       VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
863     }
864     if(!Ctx->HasOpenedContext()){
865       // set/unset display mode sur le Contexte...
866       for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
867         VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
868       }
869       Ctx->UpdateCurrentViewer();
870     }
871     else{
872       for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
873         Ctx->Display(Ctx->Interactive(),Dmode);
874     }
875   }
876   else{
877     Handle(AIS_InteractiveObject) IO;
878     name = argv[1];
879     if(GetMapOfAIS().IsBound2(name))
880       IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
881     if (!IO.IsNull())
882       VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
883   }
884   return 0;
885 }
886
887
888 //=======================================================================
889 //function :
890 //purpose  :
891 //=======================================================================
892 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
893 {
894   if(argc==1) return 1;
895   Standard_Integer On = atoi(argv[1]);
896   const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
897
898   if(argc==2){
899
900     if(!Ctx->HasOpenedContext()){
901       di<<"sub intensite ";
902       if(On==1) di<<"On";
903       else di<<"Off";
904       di<<" pour "<<Ctx->NbCurrents()<<"  objets"<<"\n";
905       for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
906         if(On==1){
907           Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
908         else{
909           di <<"passage dans off"<<"\n";
910           Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
911         }
912       }
913     }
914     else{
915       for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
916         if(On==1){
917           Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
918         else{
919           Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
920       }
921     }
922     Ctx->UpdateCurrentViewer();
923   }
924   else {
925     Handle(AIS_InteractiveObject) IO;
926     TCollection_AsciiString name = argv[2];
927     if(GetMapOfAIS().IsBound2(name)){
928       IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
929       if (!IO.IsNull())
930         if(On==1)
931           Ctx->SubIntensityOn(IO);
932         else
933           Ctx->SubIntensityOff(IO);
934
935     }
936     else return 1;
937   }
938   return 0;
939
940 }
941 //==============================================================================
942 //function : VColor2
943 //Author   : ege
944 //purpose  : change the color of a selected or named or displayed shape
945 //Draw arg : vcolor2 [name] color
946 //==============================================================================
947 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
948 {
949
950   Standard_Boolean    ThereIsCurrent;
951   Standard_Boolean    ThereIsArgument;
952   Standard_Boolean    IsBound = Standard_False ;
953
954   const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
955   if (HaveToSet) {
956     if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
957     ThereIsArgument = (argc != 2);
958   }
959   else {
960     if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
961     ThereIsArgument = (argc == 2);
962   }
963
964   if ( !a3DView().IsNull() ) {
965     TCollection_AsciiString name;
966     if (ThereIsArgument) {
967       name = argv[1];
968       IsBound= GetMapOfAIS().IsBound2(name);
969     }
970     if (TheAISContext()->HasOpenedContext())
971       TheAISContext()->CloseLocalContext();
972
973     //  On set le Booleen There is current
974     if (TheAISContext() -> NbCurrents() > 0  ) {ThereIsCurrent =Standard_True; }
975     else ThereIsCurrent =Standard_False;
976
977     //=======================================================================
978     // Il y a un  argument
979     //=======================================================================
980     if ( ThereIsArgument && IsBound ) {
981       const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
982       if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
983         Handle(AIS_InteractiveObject) ashape =
984           Handle(AIS_InteractiveObject)::DownCast (anObj);
985 #ifdef DEB
986           if (HaveToSet)
987             di  << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
988           else
989             di  << "HaveToSet 0\n";
990 #endif
991
992         if(HaveToSet)
993           TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
994         else
995           TheAISContext()->UnsetColor(ashape);
996       } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
997         Handle(NIS_Triangulated) ashape =
998           Handle(NIS_Triangulated)::DownCast (anObj);
999         if (!ashape.IsNull())
1000           ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1001       }
1002     }
1003
1004
1005     //=======================================================================
1006     // Il n'y a pas d'arguments
1007     // Mais un ou plusieurs objets on des current representation
1008     //=======================================================================
1009     if (ThereIsCurrent && !ThereIsArgument) {
1010       for (TheAISContext() -> InitCurrent() ;
1011            TheAISContext() -> MoreCurrent() ;
1012            TheAISContext() ->NextCurrent() )
1013       {
1014         const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1015         if (ashape.IsNull())
1016           continue;
1017 #ifdef DEB
1018         if (HaveToSet)
1019           di  << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1020         else
1021           di  << "HaveToSet 0\n";
1022 #endif
1023         if(HaveToSet)
1024           TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1025         else
1026           TheAISContext()->UnsetColor(ashape,Standard_False);
1027       }
1028
1029       TheAISContext()->UpdateCurrentViewer();
1030     }
1031
1032     //=======================================================================
1033     // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1034     // on impose a tous les objets du viewer la couleur passee
1035     //=======================================================================
1036     else if (!ThereIsCurrent && !ThereIsArgument){
1037       ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1038       while ( it.More() ) {
1039         const Handle(AIS_InteractiveObject) ashape =
1040           Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1041         if (!ashape.IsNull())
1042           if(HaveToSet)
1043             TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1044           else
1045             TheAISContext()->UnsetColor(ashape,Standard_False);
1046         it.Next();
1047       }
1048       TheAISContext()->UpdateCurrentViewer();
1049     }
1050   }
1051   return 0;
1052 }
1053
1054 //==============================================================================
1055 //function : VTransparency
1056 //Author   : ege
1057 //purpose  : change the transparency of a selected or named or displayed shape
1058 //Draw arg : vtransparency [name] TransparencyCoeficient
1059 //==============================================================================
1060
1061 static int VTransparency  (Draw_Interpretor& di, Standard_Integer argc,
1062                            const char** argv)
1063 {
1064   Standard_Boolean    ThereIsCurrent;
1065   Standard_Boolean    ThereIsArgument;
1066   Standard_Boolean    IsBound = Standard_False ;
1067
1068   const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1069   if (HaveToSet) {
1070     if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1071     ThereIsArgument = (argc != 2);
1072   }
1073   else{
1074     if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1075     ThereIsArgument = (argc == 2);
1076   }
1077
1078   if ( !a3DView().IsNull() ) {
1079     TCollection_AsciiString name;
1080     if (ThereIsArgument) {
1081       name = argv[1];
1082       IsBound= GetMapOfAIS().IsBound2(name);
1083     }
1084     if (TheAISContext()->HasOpenedContext())
1085       TheAISContext()->CloseLocalContext();
1086
1087     if (TheAISContext() -> NbCurrents() > 0  ) {ThereIsCurrent =Standard_True; }
1088     else ThereIsCurrent = Standard_False;
1089
1090     //=======================================================================
1091     // Il y a des arguments: un nom et une couleur
1092     //=======================================================================
1093     if ( ThereIsArgument && IsBound ) {
1094       const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1095       if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1096         const Handle(AIS_InteractiveObject) ashape =
1097           Handle(AIS_InteractiveObject)::DownCast(anObj);
1098         if(HaveToSet)
1099           TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1100         else
1101           TheAISContext()->UnsetTransparency(ashape);
1102       } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1103         const Handle(NIS_InteractiveObject) ashape =
1104           Handle(NIS_InteractiveObject)::DownCast(anObj);
1105         if(HaveToSet)
1106           ashape->SetTransparency(atof(argv[2]) );
1107         else
1108           ashape->UnsetTransparency();
1109       }
1110     }
1111     //=======================================================================
1112     // Il n'y a pas d'arguments
1113     // Mais un ou plusieurs objets on des current representation
1114     //=======================================================================
1115     if (ThereIsCurrent && !ThereIsArgument) {
1116       for (TheAISContext() -> InitCurrent() ;
1117            TheAISContext() -> MoreCurrent() ;
1118            TheAISContext() ->NextCurrent() )
1119       {
1120         Handle(AIS_InteractiveObject) ashape =  TheAISContext() -> Current();
1121         if(HaveToSet)
1122           TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1123         else
1124           TheAISContext()->UnsetTransparency(ashape,Standard_False);
1125       }
1126
1127       TheAISContext()->UpdateCurrentViewer();
1128     }
1129     //=======================================================================
1130     // Il n'y a pas d'arguments ET aucun objet courrant
1131     //=======================================================================
1132     else if ( !ThereIsCurrent && !ThereIsArgument ) {
1133       ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1134         it(GetMapOfAIS());
1135       while ( it.More() ) {
1136         Handle(AIS_InteractiveObject) ashape =
1137           Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1138         if (!ashape.IsNull())
1139           if(HaveToSet)
1140             TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1141           else
1142             TheAISContext()->UnsetTransparency(ashape,Standard_False);
1143         it.Next();
1144       }
1145       TheAISContext()->UpdateCurrentViewer();
1146     }
1147   }
1148   return 0;
1149 }
1150
1151
1152 //==============================================================================
1153 //function : VMaterial
1154 //Author   : ege
1155 //purpose  : change the Material of a selected or named or displayed shape
1156 //Draw arg : vmaterial  [Name] Material
1157 //==============================================================================
1158 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1159 {
1160
1161   Standard_Boolean    ThereIsCurrent;
1162   Standard_Boolean    ThereIsName;
1163   Standard_Boolean    IsBound = Standard_False ;
1164
1165   const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1166   if (HaveToSet) {
1167     if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1168     ThereIsName = (argc != 2);
1169   }
1170   else {
1171     if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1172     ThereIsName = (argc == 2);
1173   }
1174
1175   if ( !a3DView().IsNull() ) {
1176     TCollection_AsciiString name;
1177     if (ThereIsName) {
1178       name = argv[1];
1179       IsBound= GetMapOfAIS().IsBound2(name);
1180     }
1181     if (TheAISContext()->HasOpenedContext())
1182       TheAISContext()->CloseLocalContext();
1183     if (TheAISContext() -> NbCurrents() > 0  )
1184       ThereIsCurrent =Standard_True;
1185     else
1186       ThereIsCurrent =Standard_False;
1187
1188     //=======================================================================
1189     // Ther is a name of shape and a material name
1190     //=======================================================================
1191     if ( ThereIsName && IsBound ) {
1192       Handle(AIS_InteractiveObject) ashape =
1193         Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1194       if (!ashape.IsNull())
1195         if (HaveToSet)
1196           TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1197         else
1198           TheAISContext()->UnsetMaterial(ashape);
1199     }
1200     //=======================================================================
1201     // Il n'y a pas de nom de shape
1202     // Mais un ou plusieurs objets on des current representation
1203     //=======================================================================
1204     if (ThereIsCurrent && !ThereIsName) {
1205       for (TheAISContext() -> InitCurrent() ;
1206            TheAISContext() -> MoreCurrent() ;
1207            TheAISContext() ->NextCurrent() )
1208       {
1209         Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1210         if (HaveToSet)
1211           TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1212         else
1213           TheAISContext()->UnsetMaterial(ashape,Standard_False);
1214       }
1215       TheAISContext()->UpdateCurrentViewer();
1216     }
1217
1218     //=======================================================================
1219     // Il n'y a pas de noms de shape ET aucun objet courrant
1220     // On impose a tous les objets du viewer le material passe en argument
1221     //=======================================================================
1222     else if (!ThereIsCurrent && !ThereIsName){
1223       ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1224         it(GetMapOfAIS());
1225       while ( it.More() ) {
1226         Handle(AIS_InteractiveObject) ashape =
1227           Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1228         if (!ashape.IsNull())
1229           if (HaveToSet)
1230             TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1231           else
1232             TheAISContext()->UnsetMaterial(ashape,Standard_False);
1233         it.Next();
1234       }
1235       TheAISContext()->UpdateCurrentViewer();
1236     }
1237   }
1238   return 0;
1239 }
1240
1241
1242
1243 //==============================================================================
1244 //function : VWidth
1245 //Author   : ege
1246 //purpose  : change the width of the edges of a selected or named or displayed shape
1247 //Draw arg : vwidth  [Name] WidthValue(1->10)
1248 //==============================================================================
1249 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1250 {
1251
1252   Standard_Boolean    ThereIsCurrent;
1253   Standard_Boolean    ThereIsArgument;
1254   Standard_Boolean    IsBound = Standard_False ;
1255
1256   const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1257   if (HaveToSet) {
1258     if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1259     ThereIsArgument = (argc != 2);
1260   }
1261   else {
1262     if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1  argument" << "\n"; return 1; }
1263     ThereIsArgument = (argc == 2);
1264   }
1265   if ( !a3DView().IsNull() ) {
1266     TCollection_AsciiString name;
1267     if (ThereIsArgument) {
1268       name = argv[1];
1269       IsBound= GetMapOfAIS().IsBound2(name);
1270     }
1271     if (TheAISContext()->HasOpenedContext())
1272       TheAISContext()->CloseLocalContext();
1273
1274     if (TheAISContext() -> NbCurrents() > 0  )
1275       ThereIsCurrent =Standard_True;
1276     else
1277       ThereIsCurrent =Standard_False;
1278
1279     if ( ThereIsArgument && IsBound ) {
1280       const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1281       if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1282         const Handle(AIS_InteractiveObject) ashape =
1283           Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1284         if (HaveToSet)
1285           TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1286         else
1287           TheAISContext()->UnsetWidth (ashape);
1288       } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1289         const Handle(NIS_Triangulated) ashape =
1290           Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1291         if (HaveToSet && !ashape.IsNull())
1292           ashape->SetLineWidth ( atof (argv[2]) );
1293       }
1294     }
1295
1296     //=======================================================================
1297     // Il n'y a pas d'arguments
1298     // Mais un ou plusieurs objets on des current representation
1299     //=======================================================================
1300     if (ThereIsCurrent && !ThereIsArgument) {
1301       for (TheAISContext() -> InitCurrent() ;
1302            TheAISContext() -> MoreCurrent() ;
1303            TheAISContext() ->NextCurrent() )
1304       {
1305         Handle(AIS_InteractiveObject) ashape =  TheAISContext() -> Current();
1306         if (HaveToSet)
1307           TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1308         else
1309           TheAISContext()->UnsetWidth(ashape,Standard_False);
1310       }
1311       TheAISContext()->UpdateCurrentViewer();
1312     }
1313     //=======================================================================
1314     // Il n'y a pas d'arguments ET aucun objet courrant
1315     //=======================================================================
1316     else if (!ThereIsCurrent && !ThereIsArgument){
1317      ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1318        it(GetMapOfAIS());
1319      while ( it.More() ) {
1320        Handle(AIS_InteractiveObject) ashape =
1321          Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1322        if (!ashape.IsNull())
1323          if (HaveToSet)
1324            TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1325          else
1326            TheAISContext()->UnsetWidth(ashape,Standard_False);
1327        it.Next();
1328      }
1329      TheAISContext()->UpdateCurrentViewer();
1330    }
1331   }
1332   return 0;
1333 }
1334
1335 //==============================================================================
1336 //function : VInteriorStyle
1337 //purpose  : sets interior style of the a selected or named or displayed shape
1338 //Draw arg : vsetinteriorstyle [shape] style
1339 //==============================================================================
1340 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1341                               const Standard_Integer theStyle,
1342                               Draw_Interpretor& di)
1343 {
1344   if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1345     di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1346       " (Aspect_IS_HIDDENLINE)]\n";
1347     return;
1348   }
1349   const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1350   Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1351   Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1352   Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1353   aFillAspect->SetInteriorStyle (aStyle);
1354   TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1355 }
1356
1357 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1358 {
1359   if (argc < 2 || argc > 3) {
1360     di << argv[0] << " requires 2 or 3 arguments\n";
1361     di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1362     di << "Style must match Aspect_InteriorStyle and be one of:\n";
1363     di << "         0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1364     return 1;
1365   }
1366
1367   Standard_Boolean    ThereIsCurrent;
1368   Standard_Boolean    ThereIsArgument;
1369   Standard_Boolean    IsBound = Standard_False ;
1370
1371   ThereIsArgument = (argc > 2);
1372   if ( !a3DView().IsNull() ) {
1373     TCollection_AsciiString name;
1374     if (ThereIsArgument) {
1375       name = argv[1];
1376       IsBound= GetMapOfAIS().IsBound2(name);
1377     }
1378     if (TheAISContext()->HasOpenedContext())
1379       TheAISContext()->CloseLocalContext();
1380
1381     if (TheAISContext() -> NbCurrents() > 0  )
1382       ThereIsCurrent =Standard_True;
1383     else
1384       ThereIsCurrent =Standard_False;
1385
1386     if ( ThereIsArgument && IsBound ) {
1387       const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1388       if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1389         const Handle(AIS_InteractiveObject) ashape =
1390           Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1391         SetInteriorStyle (ashape, atoi (argv[2]), di);
1392       }
1393     }
1394     //=======================================================================
1395     // No arguments specified
1396     // But there are one or more selected objects
1397     //=======================================================================
1398     if (ThereIsCurrent && !ThereIsArgument) {
1399       for (TheAISContext() -> InitCurrent() ;
1400            TheAISContext() -> MoreCurrent() ;
1401            TheAISContext() ->NextCurrent() )
1402       {
1403         Handle(AIS_InteractiveObject) ashape =  TheAISContext() -> Current();
1404         SetInteriorStyle (ashape, atoi (argv[1]), di);
1405       }
1406     }
1407     //=======================================================================
1408     // No arguments specified and there are no selected objects
1409     //=======================================================================
1410     else if (!ThereIsCurrent && !ThereIsArgument){
1411       ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1412        it(GetMapOfAIS());
1413       while ( it.More() ) {
1414         Handle(AIS_InteractiveObject) ashape =
1415           Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1416         if (!ashape.IsNull())
1417           SetInteriorStyle (ashape, atoi (argv[1]), di);
1418         it.Next();
1419       }
1420     }
1421     TheAISContext()->UpdateCurrentViewer();
1422   }
1423   return 0;
1424 }
1425
1426 //==============================================================================
1427 //function : VDonly2
1428 //author   : ege
1429 //purpose  : Display only a selected or named  object
1430 //           if there is no selected or named object s, nothing is donne
1431 //Draw arg : vdonly2 [name1] ... [name n]
1432 //==============================================================================
1433 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1434
1435 {
1436   if ( a3DView().IsNull() )
1437     return 1;
1438
1439   Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1440   Standard_Boolean ThereIsArgument= argc>1;
1441
1442   if (TheAISContext()->HasOpenedContext())
1443     TheAISContext()->CloseLocalContext();
1444
1445   //===============================================================
1446   // Il n'y a pas d'arguments mais des objets selectionnes(current)
1447   // dans le viewer
1448   //===============================================================
1449   if (!ThereIsArgument && ThereIsCurrent) {
1450
1451 #ifdef DEB
1452     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1453       it (GetMapOfAIS());
1454 #endif
1455     for(TheAISContext()->InitCurrent();
1456         TheAISContext()->MoreCurrent();
1457         TheAISContext()->NextCurrent()){
1458       Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1459       TheAISContext()->Erase(aShape,Standard_False);}
1460   }
1461   TheAISContext() ->UpdateCurrentViewer();
1462   //===============================================================
1463   // Il y a des arguments
1464   //===============================================================
1465   if (ThereIsArgument) {
1466     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1467       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);
1477       }
1478       it.Next();
1479     }
1480
1481     // On display les objets passes par parametre
1482     for (int i=1; i<argc ; i++) {
1483       TCollection_AsciiString name=argv[i];
1484       Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1485       if (IsBound) {
1486         const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1487         if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1488           const Handle(AIS_InteractiveObject) aShape =
1489             Handle(AIS_InteractiveObject)::DownCast (anObj);
1490           TheAISContext()->Display(aShape, Standard_False);
1491         } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1492           Handle(NIS_InteractiveObject) aShape =
1493             Handle(NIS_InteractiveObject)::DownCast (anObj);
1494           TheNISContext()->Display(aShape);
1495         }
1496       }
1497     }
1498     TheAISContext() ->UpdateCurrentViewer();
1499 //    TheNISContext() ->UpdateViews();
1500   }
1501   return 0;
1502 }
1503
1504 //==============================================================================
1505 //function : VErase2
1506 //author   : ege
1507 //purpose  : Erase some  selected or named  objects
1508 //           if there is no selected or named objects, the whole viewer is erased
1509 //Draw arg : verase2 [name1] ... [name n]
1510 //==============================================================================
1511 static int VErase2(Draw_Interpretor& ,  Standard_Integer argc,  const char** argv)
1512
1513 {
1514   if ( a3DView().IsNull() )
1515     return 1;
1516
1517   Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1518   Standard_Boolean ThereIsArgument= argc>1;
1519   if(TheAISContext()->HasOpenedContext())
1520     TheAISContext()->CloseLocalContext();
1521
1522   //===============================================================
1523   // Il n'y a pas d'arguments mais des objets selectionnes(current)
1524   // dans le viewer
1525   //===============================================================
1526   if (!ThereIsArgument && ThereIsCurrent) {
1527     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1528       it (GetMapOfAIS());
1529     while ( it.More() ) {
1530       if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1531         const Handle(AIS_InteractiveObject) aShape =
1532           Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1533         if (TheAISContext()->IsCurrent(aShape))
1534           TheAISContext()->Erase(aShape,Standard_False);
1535       }
1536       it.Next();
1537     }
1538
1539     TheAISContext() ->UpdateCurrentViewer();
1540   }
1541
1542   //===============================================================
1543   // Il n'y a pas d'arguments et aucuns objets selectionnes
1544   // dans le viewer:
1545   // On erase tout le viewer
1546   //===============================================================
1547
1548   if (!ThereIsArgument && !ThereIsCurrent) {
1549     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1550     while ( it.More() ) {
1551       if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1552         const Handle(AIS_InteractiveObject) aShape =
1553           Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1554         TheAISContext()->Erase(aShape,Standard_False);
1555       } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1556         const Handle(NIS_InteractiveObject) aShape =
1557           Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1558         TheNISContext()->Erase(aShape);
1559       }
1560       it.Next();
1561     }
1562     TheAISContext() ->UpdateCurrentViewer();
1563 //    TheNISContext()->UpdateViews();
1564   }
1565
1566   //===============================================================
1567   // Il y a des arguments
1568   //===============================================================
1569   if (ThereIsArgument) {
1570     for (int i=1; i<argc ; i++) {
1571       TCollection_AsciiString name=argv[i];
1572       Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1573       if (IsBound) {
1574         const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1575         if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1576           const Handle(AIS_InteractiveObject) aShape =
1577             Handle(AIS_InteractiveObject)::DownCast (anObj);
1578           TheAISContext()->Erase(aShape,Standard_False);
1579         } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1580           const Handle(NIS_InteractiveObject) aShape =
1581             Handle(NIS_InteractiveObject)::DownCast (anObj);
1582           TheNISContext()->Erase(aShape);
1583         }
1584       }
1585     }
1586     TheAISContext() ->UpdateCurrentViewer();
1587 //    TheNISContext() ->UpdateViews();
1588   }
1589   return 0;
1590 }
1591
1592 //==============================================================================
1593 //function : VEraseAll
1594 //author   : ege
1595 //purpose  : Erase all the objects displayed in the viewer
1596 //Draw arg : veraseall
1597 //==============================================================================
1598 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1599
1600 {
1601   // Verification des arguments
1602   if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1603   if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1604   TheAISContext()->CloseAllContexts(Standard_False);
1605   ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1606     it(GetMapOfAIS());
1607   while ( it.More() ) {
1608     if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1609       const Handle(AIS_InteractiveObject) aShape =
1610         Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1611       TheAISContext()->Erase(aShape,Standard_False);
1612     } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1613       const Handle(NIS_InteractiveObject) aShape =
1614         Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1615       TheNISContext()->Erase(aShape);
1616     }
1617     it.Next();
1618   }
1619   TheAISContext() ->UpdateCurrentViewer();
1620 //  TheNISContext() ->UpdateViews();
1621   return 0;
1622 }
1623
1624
1625 //==============================================================================
1626 //function : VDisplayAll
1627 //author   : ege
1628 //purpose  : Display all the objects of the Map
1629 //Draw arg : vdisplayall
1630 //==============================================================================
1631 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1632
1633 {
1634   if (! a3DView().IsNull() ) {
1635     if (argc >  1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1636     if (TheAISContext()->HasOpenedContext())
1637       TheAISContext()->CloseLocalContext();
1638     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1639       it (GetMapOfAIS());
1640     while ( it.More() ) {
1641       if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1642         const Handle(AIS_InteractiveObject) aShape =
1643           Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1644         TheAISContext()->Erase(aShape,Standard_False);
1645       } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1646         const Handle(NIS_InteractiveObject) aShape =
1647           Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1648         TheNISContext()->Erase(aShape);
1649       }
1650       it.Next();
1651     }
1652     it.Reset();
1653     while ( it.More() ) {
1654       if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1655         const Handle(AIS_InteractiveObject) aShape =
1656           Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1657         TheAISContext()->Display(aShape, Standard_False);
1658       } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1659         Handle(NIS_InteractiveObject) aShape =
1660           Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1661         TheNISContext()->Display(aShape);
1662       }
1663       it.Next();
1664     }
1665     TheAISContext() ->UpdateCurrentViewer();
1666 //    TheNISContext() ->UpdateViews();
1667   }
1668   return 0;
1669 }
1670
1671 //#######################################################################################################
1672
1673 //##     VTexture
1674
1675 //#######################################################################################################
1676
1677 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1678 {
1679   Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1680     (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1681       (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1682         (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1683           (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1684
1685   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1686   if(myAISContext.IsNull())
1687     {
1688       di << "use 'vinit' command before " << argv[0] << "\n";
1689       return 1;
1690     }
1691
1692   Handle(AIS_InteractiveObject) TheAisIO;
1693   Handle(AIS_TexturedShape) myShape;
1694   Standard_Integer myPreviousMode = 0;
1695
1696   if (argc<2 || !argv[1])
1697     {
1698       di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1699       return 1;
1700     }
1701
1702   TCollection_AsciiString name = argv[1];
1703   ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1704
1705   if (GetMapOfAIS().IsBound2(name))
1706     TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1707       (GetMapOfAIS().Find2(name));
1708   if (TheAisIO.IsNull())
1709   {
1710     di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1711     return 1;
1712   }
1713
1714   if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1715     {
1716       myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1717       myPreviousMode = myShape->DisplayMode() ;
1718     }
1719   else
1720     {
1721       myAISContext->Clear(TheAisIO,Standard_False);
1722       myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1723       GetMapOfAIS().UnBind1(TheAisIO);
1724       GetMapOfAIS().UnBind2(name);
1725       GetMapOfAIS().Bind(myShape, name);
1726     }
1727   switch (command)
1728     {
1729     case 1: // vtexture : we only map a texture on the shape
1730       if(argc<=1)
1731         {
1732           di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1733           return 1;
1734         }
1735       if (argc>2 && argv[2])
1736         {
1737           if(strcasecmp(argv[2],"?")==0)
1738             {
1739               TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
1740               di<<"\n Files in current directory : \n"<<"\n";
1741               TCollection_AsciiString Cmnd ("glob -nocomplain *");
1742               di.Eval(Cmnd.ToCString());
1743
1744               Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1745               Cmnd += monPath ;
1746               Cmnd += "/* " ;
1747               di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1748               di.Eval(Cmnd.ToCString());
1749
1750               return 0;
1751             }
1752           else
1753             myShape->SetTextureFileName(argv[2]);
1754         }
1755       else
1756         {
1757           di <<"Texture mapping disabled \n \
1758                   To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1759
1760           myAISContext->SetDisplayMode(myShape,1,Standard_False);
1761           if (myPreviousMode == 3 )
1762             myAISContext->RecomputePrsOnly(myShape);
1763           myAISContext->Display(myShape, Standard_True);
1764           return 0;
1765         }
1766       break;
1767
1768     case 2: // vtexscale : we change the scaling factor of the texture
1769
1770       if(argc<2)
1771         {
1772           di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1773           return 1;
1774         }
1775
1776       myShape->SetTextureScale (( argv[2] ? Standard_True    : Standard_False ),
1777                                 ( argv[2] ? atof(argv[2])    : 1.0 ),
1778                                 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1779       break;
1780
1781     case 3: // vtexorigin : we change the origin of the texture on the shape
1782       if(argc<2)
1783         {
1784           di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1785           return 1;
1786         }
1787       myShape->SetTextureOrigin (( argv[2] ? Standard_True    : Standard_False ),
1788                                  ( argv[2] ? atof(argv[2])    : 0.0 ),
1789                                  ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1790       break;
1791
1792     case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1793       if(argc<2)
1794         {
1795           di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1796           return 1;
1797         }
1798       if (argc>2 && argv[2])
1799         {
1800           di <<"Texture repeat enabled"<<"\n";
1801           myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1802         }
1803       else
1804         {
1805           di <<"Texture repeat disabled"<<"\n";
1806           myShape->SetTextureRepeat(Standard_False);
1807         }
1808       break;
1809
1810     case 5: // vtexdefault : default texture mapping
1811       // ScaleU = ScaleV = 100.0
1812       // URepeat = VRepeat = 1.0
1813       // Uorigin = VOrigin = 0.0
1814
1815       if(argc<2)
1816         {
1817           di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1818           return 1;
1819         }
1820       myShape->SetTextureRepeat(Standard_False);
1821       myShape->SetTextureOrigin(Standard_False);
1822       myShape->SetTextureScale (Standard_False);
1823       break;
1824     }
1825
1826   if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1827     myAISContext->RecomputePrsOnly(myShape);
1828   else
1829     {
1830       myAISContext->SetDisplayMode(myShape,3,Standard_False);
1831       myAISContext->Display(myShape, Standard_True);
1832       myAISContext->Update(myShape,Standard_True);
1833     }
1834   return 0;
1835 }
1836
1837 //==============================================================================
1838 //function : VDisplay2
1839 //author   : ege
1840 //purpose  : Display an object from its name
1841 //Draw arg : vdisplay name1 [name2] ... [name n]
1842 //==============================================================================
1843 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1844
1845 {
1846   // Verification des arguments
1847   if ( a3DView().IsNull() ) {
1848
1849     ViewerTest::ViewerInit();
1850     di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1851     //    return 1;
1852   }
1853
1854   if ( argc<2) {
1855     di<<argv[0]<<" Syntaxe error"<<"\n";
1856     return 1;
1857   }
1858
1859
1860   TCollection_AsciiString name;
1861   if (TheAISContext()->HasOpenedContext())
1862     TheAISContext()->CloseLocalContext();
1863
1864   for ( int i = 1; i < argc; i++ ) {
1865     name = argv[i];
1866     Standard_Boolean IsBound      = GetMapOfAIS().IsBound2(name);
1867     Standard_Boolean IsDatum = Standard_False;
1868     Handle(Standard_Transient) anObj;
1869     if ( IsBound ) {
1870       anObj = GetMapOfAIS().Find2(name);
1871       if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1872         Handle(AIS_InteractiveObject) aShape =
1873           Handle(AIS_InteractiveObject)::DownCast(anObj);
1874         if (aShape->Type()==AIS_KOI_Datum) {
1875           IsDatum  = Standard_True;
1876           TheAISContext()->Display(aShape, Standard_False);
1877         }
1878         if (!IsDatum) {
1879           di << "Display " << name.ToCString() << "\n";
1880           // Get the Shape from a name
1881           TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
1882
1883           // Update the Shape in the AIS_Shape
1884           Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
1885           if(!TheRealSh.IsNull())
1886             TheRealSh->Set(NewShape);
1887           TheAISContext()->Redisplay(aShape, Standard_False);
1888           TheAISContext()->Display(aShape, Standard_False);
1889         }
1890         aShape.Nullify();
1891       } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1892         Handle(NIS_InteractiveObject) aShape =
1893           Handle(NIS_InteractiveObject)::DownCast(anObj);
1894         TheNISContext()->Display(aShape);
1895       }
1896     }
1897     else { // Create the AIS_Shape from a name
1898       const Handle(AIS_InteractiveObject) aShape =
1899         GetAISShapeFromName((const char *)name.ToCString());
1900       if ( !aShape.IsNull() ) {
1901         GetMapOfAIS().Bind(aShape, name);
1902         TheAISContext()->Display(aShape, Standard_False);
1903       }
1904     }
1905   }
1906   // Upadate the screen and redraw the view
1907   TheAISContext()->UpdateCurrentViewer();
1908 //  TheNISContext()->UpdateViews();
1909   return 0;
1910 }
1911
1912 //==============================================================================
1913 //function : VMoveA
1914 //purpose  : Test the annimation of an object along a
1915 //           predifined trajectory
1916 //Draw arg : vmove ShapeName
1917 //==============================================================================
1918
1919 #ifdef DEB
1920 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
1921
1922   OSD_Timer myTimer;
1923   myTimer.Start();
1924
1925   if (TheAISContext()->HasOpenedContext())
1926     TheAISContext()->CloseLocalContext();
1927
1928   Standard_Real Step=2*M_PI/180;
1929   Standard_Real Angle=0;
1930   // R est le rayon de l'hellicoide
1931   Standard_Real R=50;
1932   // D est la distance parcourue en translation en 1 tour
1933   Standard_Real D=50;
1934
1935   Handle(AIS_InteractiveObject) aIO;
1936
1937   if (GetMapOfAIS().IsBound2(argv[1]))
1938     aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
1939
1940   if (aIO.IsNull()) {
1941     di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
1942     return 1;
1943   }
1944   TheAISContext()->Deactivate(aIO);
1945
1946   // boucle generant le mouvement
1947   if(argc==3) {
1948     di<<" Transformations"<<"\n";
1949     for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
1950
1951       Angle=Step*myAngle;
1952       gp_Ax3 newBase(gp_Pnt(R*cos(Angle), R*sin(Angle), D*Angle/(2*M_PI) ), gp_Vec(0,0,1), gp_Vec(1,0,0)  );
1953       gp_Trsf myTransfo;
1954       myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1)  ),Angle ) );
1955       TheAISContext()->SetLocation(aIO,myTransfo);
1956
1957       TheAISContext() ->UpdateCurrentViewer();
1958
1959     }
1960   }
1961   else {
1962     di<<" Locations"<<"\n";
1963     gp_Trsf myAngleTrsf;
1964     myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step  );
1965     TopLoc_Location myDeltaAngle (myAngleTrsf);
1966     gp_Trsf myDistTrsf;
1967     myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
1968     TopLoc_Location myDeltaDist (myDistTrsf);
1969     TopLoc_Location myTrueLoc;
1970
1971     for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
1972
1973       Angle=Step*myAngle;
1974       myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
1975       TheAISContext()->SetLocation(aIO,myTrueLoc );
1976       TheAISContext() ->UpdateCurrentViewer();
1977     }
1978   }
1979
1980
1981   TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
1982
1983   //TopLoc_Location Tempo=aIO->Location();
1984   //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
1985   //ShapeBis.Located(Tempo);
1986
1987
1988   // On reset la location (origine) contenue dans l'AISInteractiveObject
1989   TheAISContext() ->ResetLocation(aIO);
1990
1991   // On force aShape a devenir l'AIS IO propre a ShapeBis
1992
1993   // Pour cela on force aShape(AIS IO) a devenir une AISShape
1994   // ->Set() est une methode de AIS_Shape
1995   (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
1996
1997   // On donne a ShapeBis le nom de l'AIS IO
1998   //Rep::Set(argv[1],ShapeBis);
1999
2000
2001   TheAISContext()->Redisplay(aIO,Standard_False);
2002
2003   // On reactive la selection des primitives sensibles
2004   TheAISContext()->Activate(aIO,0);
2005
2006   TheAISContext() ->UpdateCurrentViewer();
2007   a3DView() -> Redraw();
2008
2009   myTimer.Stop();
2010   di<<" Temps ecoule "<<"\n";
2011   myTimer.Show();
2012
2013   return 0;
2014 }
2015 #endif
2016
2017
2018 //==============================================================================
2019 //function : VPerf
2020 //purpose  : Test the annimation of an object along a
2021 //           predifined trajectory
2022 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2023 //==============================================================================
2024
2025 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2026
2027   OSD_Timer myTimer;
2028   if (TheAISContext()->HasOpenedContext())
2029     TheAISContext()->CloseLocalContext();
2030
2031   Standard_Real Step=4*M_PI/180;
2032   Standard_Real Angle=0;
2033
2034   Handle(AIS_InteractiveObject) aIO;
2035   if (GetMapOfAIS().IsBound2(argv[1]))
2036     aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2037   if (aIO.IsNull())
2038     return 1;
2039
2040   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2041
2042   myTimer.Start();
2043
2044   if (atoi(argv[3])==1 ) {
2045     di<<" Primitives sensibles OFF"<<"\n";
2046     TheAISContext()->Deactivate(aIO);
2047   }
2048   else {
2049     di<<" Primitives sensibles ON"<<"\n";
2050   }
2051   // Movement par transformation
2052   if(atoi(argv[2]) ==1) {
2053     di<<" Calcul par Transformation"<<"\n";
2054     for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2055
2056       Angle=Step*myAngle;
2057       gp_Trsf myTransfo;
2058       myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2059       TheAISContext()->SetLocation(aShape,myTransfo);
2060       TheAISContext() ->UpdateCurrentViewer();
2061
2062     }
2063   }
2064   else {
2065     di<<" Calcul par Locations"<<"\n";
2066     gp_Trsf myAngleTrsf;
2067     myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step  );
2068     TopLoc_Location myDeltaAngle (myAngleTrsf);
2069     TopLoc_Location myTrueLoc;
2070
2071     for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2072
2073       Angle=Step*myAngle;
2074       myTrueLoc=myTrueLoc*myDeltaAngle;
2075       TheAISContext()->SetLocation(aShape,myTrueLoc );
2076       TheAISContext() ->UpdateCurrentViewer();
2077     }
2078   }
2079   if (atoi(argv[3])==1 ){
2080     // On reactive la selection des primitives sensibles
2081     TheAISContext()->Activate(aIO,0);
2082   }
2083   a3DView() -> Redraw();
2084   myTimer.Stop();
2085   di<<" Temps ecoule "<<"\n";
2086   myTimer.Show();
2087   return 0;
2088 }
2089
2090
2091 //==================================================================================
2092 // Function : VAnimation
2093 //==================================================================================
2094 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2095   if (argc != 5) {
2096     di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2097     return 1;
2098   }
2099
2100   Standard_Real thread = 4;
2101   Standard_Real angleA=0;
2102   Standard_Real angleB;
2103   Standard_Real X;
2104   gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2105
2106   BRep_Builder B;
2107   TopoDS_Shape CrankArm;
2108   TopoDS_Shape CylinderHead;
2109   TopoDS_Shape Propeller;
2110   TopoDS_Shape EngineBlock;
2111
2112   //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2113   //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2114   //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2115   //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2116   BRepTools::Read(CrankArm,argv[1],B);
2117   BRepTools::Read(CylinderHead,argv[2],B);
2118   BRepTools::Read(Propeller,argv[3],B);
2119   BRepTools::Read(EngineBlock,argv[4],B);
2120
2121   if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2122
2123
2124   OSD_Timer myTimer;
2125   myTimer.Start();
2126
2127   Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2128   Handle(AIS_Shape) myAisEngineBlock  = new AIS_Shape (EngineBlock);
2129   Handle(AIS_Shape) myAisCrankArm     = new AIS_Shape (CrankArm);
2130   Handle(AIS_Shape) myAisPropeller    = new AIS_Shape (Propeller);
2131
2132   GetMapOfAIS().Bind(myAisCylinderHead,"a");
2133   GetMapOfAIS().Bind(myAisEngineBlock,"b");
2134   GetMapOfAIS().Bind(myAisCrankArm,"c");
2135   GetMapOfAIS().Bind(myAisPropeller,"d");
2136
2137   TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2138   TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2139   TheAISContext()->SetColor(myAisPropeller   , Quantity_NOC_GREEN);
2140
2141   TheAISContext()->Display(myAisCylinderHead,Standard_False);
2142   TheAISContext()->Display(myAisEngineBlock,Standard_False );
2143   TheAISContext()->Display(myAisCrankArm,Standard_False    );
2144   TheAISContext()->Display(myAisPropeller,Standard_False);
2145
2146   TheAISContext()->Deactivate(myAisCylinderHead);
2147   TheAISContext()->Deactivate(myAisEngineBlock );
2148   TheAISContext()->Deactivate(myAisCrankArm    );
2149   TheAISContext()->Deactivate(myAisPropeller   );
2150
2151   // Boucle de mouvement
2152   for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2153
2154     angleA = thread*myAngle*M_PI/180;
2155     X = Sin(angleA)*3/8;
2156     angleB = atan(X / Sqrt(-X * X + 1));
2157     Standard_Real decal(25*0.6);
2158
2159
2160     //Build a transformation on the display
2161     gp_Trsf aPropellerTrsf;
2162     aPropellerTrsf.SetRotation(Ax1,angleA);
2163     TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2164
2165     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));
2166     gp_Trsf aCrankArmTrsf;
2167     aCrankArmTrsf.SetTransformation(   base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2168     TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2169
2170     TheAISContext()->UpdateCurrentViewer();
2171   }
2172
2173   TopoDS_Shape myNewCrankArm  =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2174   TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2175
2176   myAisCrankArm ->ResetLocation();
2177   myAisPropeller->ResetLocation();
2178
2179   myAisCrankArm  -> Set(myNewCrankArm );
2180   myAisPropeller -> Set(myNewPropeller);
2181
2182   TheAISContext()->Activate(myAisCylinderHead,0);
2183   TheAISContext()->Activate(myAisEngineBlock,0 );
2184   TheAISContext()->Activate(myAisCrankArm ,0   );
2185   TheAISContext()->Activate(myAisPropeller ,0  );
2186
2187   myTimer.Stop();
2188   myTimer.Show();
2189   myTimer.Start();
2190
2191   TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2192   TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2193
2194   TheAISContext()->UpdateCurrentViewer();
2195   a3DView()->Redraw();
2196
2197   myTimer.Stop();
2198   myTimer.Show();
2199
2200   return 0;
2201
2202 }
2203
2204 //==============================================================================
2205 //function : VShading
2206 //purpose  : Sharpen or roughten the quality of the shading
2207 //Draw arg : vshading ShapeName 0.1->0.00001  1 deg-> 30 deg
2208 //==============================================================================
2209 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2210 {
2211   Standard_Real    myDevCoef;
2212   Handle(AIS_InteractiveObject) TheAisIO;
2213
2214   // Verifications
2215   const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2216
2217   if (TheAISContext()->HasOpenedContext())
2218     TheAISContext()->CloseLocalContext();
2219
2220   if (argc < 3) {
2221     myDevCoef  = 0.0008;
2222   } else {
2223     myDevCoef  =atof(argv[2]);
2224   }
2225
2226   TCollection_AsciiString name=argv[1];
2227   if (GetMapOfAIS().IsBound2(name ))
2228     TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2229   if (TheAisIO.IsNull())
2230     TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2231
2232   if (HaveToSet)
2233     TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2234   else
2235     TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2236
2237   TheAISContext()->Redisplay(TheAisIO);
2238   return 0;
2239 }
2240 //==============================================================================
2241 //function : HaveMode
2242 //use      : VActivatedModes
2243 //==============================================================================
2244 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2245
2246 Standard_Boolean  HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode  )
2247 {
2248   TColStd_ListOfInteger List;
2249   TheAISContext()->ActivatedModes (TheAisIO,List);
2250   TColStd_ListIteratorOfListOfInteger it;
2251   Standard_Boolean Found=Standard_False;
2252   for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2253     if (it.Value()==mode ) Found=Standard_True;
2254   }
2255   return Found;
2256 }
2257
2258
2259
2260 //==============================================================================
2261 //function : VActivatedMode
2262 //author   : ege
2263 //purpose  : permet d'attribuer a chacune des shapes un mode d'activation
2264 //           (edges,vertex...)qui lui est propre et le mode de selection standard.
2265 //           La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2266 //             Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2267 //           qu'un nom et qu'un mode.
2268 //Draw arg : vsetam  [ShapeName] mode(0,1,2,3,4,5,6,7)
2269 //==============================================================================
2270 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2271
2272 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2273
2274 {
2275   Standard_Boolean ThereIsName = Standard_False ;
2276
2277   if(!a3DView().IsNull()){
2278
2279     const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2280     // verification des arguments
2281     if (HaveToSet) {
2282       if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2283       ThereIsName = (argc == 3);
2284     }
2285     else {
2286       // vunsetam
2287       if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2288       else {
2289         di<<" R.A.Z de tous les modes de selecion"<<"\n";
2290         di<<" Fermeture du Context local"<<"\n";
2291         if (TheAISContext()->HasOpenedContext())
2292           TheAISContext()->CloseLocalContext();
2293       }
2294     }
2295
2296     // IL n'y a aps de nom de shape passe en argument
2297     if (HaveToSet && !ThereIsName){
2298       Standard_Integer aMode=atoi(argv [1]);
2299
2300       const char *cmode="???";
2301       switch (aMode) {
2302       case 0: cmode = "Shape"; break;
2303       case 1: cmode = "Vertex"; break;
2304       case 2: cmode = "Edge"; break;
2305       case 3: cmode = "Wire"; break;
2306       case 4: cmode = "Face"; break;
2307       case 5: cmode = "Shell"; break;
2308       case 6: cmode = "Solid"; break;
2309       case 7: cmode = "Compound"; break;
2310       }
2311
2312       if( !TheAISContext()->HasOpenedContext() ) {
2313         // il n'y a pas de Context local d'ouvert
2314         // on en ouvre un et on charge toutes les shapes displayees
2315         // on load tous les objets displayees et on Activate les objets de la liste
2316         AIS_ListOfInteractive ListOfIO;
2317         // on sauve dans une AISListOfInteractive tous les objets currents
2318         if (TheAISContext()->NbCurrents()>0 ){
2319           TheAISContext()->UnhilightCurrents(Standard_False);
2320
2321           for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2322             ListOfIO.Append(TheAISContext()->Current() );
2323           }
2324         }
2325
2326         TheAISContext()->OpenLocalContext(Standard_False);
2327         ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2328           it (GetMapOfAIS());
2329         while(it.More()){
2330           Handle(AIS_InteractiveObject) aIO =
2331             Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2332           if (!aIO.IsNull())
2333             TheAISContext()->Load(aIO,0,Standard_False);
2334           it.Next();
2335         }
2336         // traitement des objets qui etaient currents dans le Contexte global
2337         if (!ListOfIO.IsEmpty() ) {
2338           // il y avait des objets currents
2339           AIS_ListIteratorOfListOfInteractive iter;
2340           for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2341             Handle(AIS_InteractiveObject) aIO=iter.Value();
2342             TheAISContext()->Activate(aIO,aMode);
2343             di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString()  <<"\n";
2344           }
2345         }
2346         else {
2347           // On applique le mode a tous les objets displayes
2348           ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2349             it2 (GetMapOfAIS());
2350           while(it2.More()){
2351             Handle(AIS_InteractiveObject) aIO =
2352               Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2353             if (!aIO.IsNull()) {
2354               di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2355               TheAISContext()->Activate(aIO,aMode);
2356             }
2357             it2.Next();
2358           }
2359         }
2360
2361       }
2362
2363       else {
2364         // un Context local est deja ouvert
2365         // Traitement des objets du Context local
2366         if (TheAISContext()->NbSelected()>0 ){
2367           TheAISContext()->UnhilightSelected(Standard_False);
2368           // il y a des objets selected,on les parcourt
2369           for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2370             Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2371
2372
2373             if (HaveMode(aIO,aMode) ) {
2374               di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2375               TheAISContext()->Deactivate(aIO,aMode);
2376             }
2377             else{
2378               di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2379               TheAISContext()->Activate(aIO,aMode);
2380             }
2381
2382           }
2383         }
2384         else{
2385           // il n'y a pas d'objets selected
2386           // tous les objets diplayes sont traites
2387           ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2388             it (GetMapOfAIS());
2389           while(it.More()){
2390             Handle(AIS_InteractiveObject) aIO =
2391               Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2392             if (!aIO.IsNull()) {
2393               if (HaveMode(aIO,aMode) ) {
2394                 di<<" Mode: "<<cmode<<" OFF pour "
2395                   <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2396                 TheAISContext()->Deactivate(aIO,aMode);
2397               }
2398               else{
2399                 di<<" Mode: "<<cmode<<" ON pour"
2400                   <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2401                 TheAISContext()->Activate(aIO,aMode);
2402               }
2403             }
2404             it.Next();
2405           }
2406         }
2407       }
2408     }
2409     else if (HaveToSet && ThereIsName){
2410       Standard_Integer aMode=atoi(argv [2]);
2411       Handle(AIS_InteractiveObject) aIO =
2412         Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2413
2414       if (!aIO.IsNull()) {
2415         const char *cmode="???";
2416
2417         switch (aMode) {
2418         case 0: cmode = "Shape"; break;
2419         case 1: cmode = "Vertex"; break;
2420         case 2: cmode = "Edge"; break;
2421         case 3: cmode = "Wire"; break;
2422         case 4: cmode = "Face"; break;
2423         case 5: cmode = "Shell"; break;
2424         case 6: cmode = "Solid"; break;
2425         case 7: cmode = "Compound"; break;
2426         }
2427
2428         if( !TheAISContext()->HasOpenedContext() ) {
2429           TheAISContext()->OpenLocalContext(Standard_False);
2430           // On charge tous les objets de la map
2431           ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2432           while(it.More()){
2433             Handle(AIS_InteractiveObject) aShape=
2434               Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2435             if (!aShape.IsNull())
2436               TheAISContext()->Load(aShape,0,Standard_False);
2437             it.Next();
2438           }
2439           TheAISContext()->Activate(aIO,aMode);
2440           di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2441         }
2442
2443         else {
2444           // un Context local est deja ouvert
2445           if (HaveMode(aIO,aMode) ) {
2446             di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2447             TheAISContext()->Deactivate(aIO,aMode);
2448           }
2449           else{
2450             di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2451             TheAISContext()->Activate(aIO,aMode);
2452           }
2453         }
2454       }
2455     }
2456   }
2457   return 0;
2458
2459 }
2460
2461
2462
2463 //==============================================================================
2464 // function : WhoAmI
2465 // user : vState
2466 //==============================================================================
2467 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2468
2469   // AIS_Datum
2470   if (theShape->Type()==AIS_KOI_Datum) {
2471     if      (theShape->Signature()==3 ) { di<<"  AIS_Trihedron"; }
2472     else if (theShape->Signature()==2 ) { di<<"  AIS_Axis"; }
2473     else if (theShape->Signature()==6 ) { di<<"  AIS_Circle"; }
2474     else if (theShape->Signature()==5 ) { di<<"  AIS_Line"; }
2475     else if (theShape->Signature()==7 ) { di<<"  AIS_Plane"; }
2476     else if (theShape->Signature()==1 ) { di<<"  AIS_Point"; }
2477     else if (theShape->Signature()==4 ) { di<<"  AIS_PlaneTrihedron"; }
2478   }
2479   // AIS_Shape
2480   else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<"  AIS_Shape"; }
2481   // AIS_Dimentions et AIS_Relations
2482   else if (theShape->Type()==AIS_KOI_Relation) {
2483     Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2484
2485     if      (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE)      {di<<"  AIS_AngleDimension";}
2486     else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH )         {di<<"  AIS_Chamf2/3dDimension/AIS_LengthDimension ";  }
2487     else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER  )      {di<<"  AIS_DiameterDimension ";}
2488     else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS  ) {di<<"  AIS_EllipseRadiusDimension ";}
2489     //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS  )  {di<<" AIS_FilletRadiusDimension "<<endl;}
2490     else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET  )        {di<<"  AIS_OffsetDimension ";}
2491     else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS  )        {di<<"  AIS_RadiusDimension ";}
2492     // AIS no repertorie.
2493     else {di<<"  Type Unknown.";}
2494   }
2495 }
2496
2497
2498
2499 //==============================================================================
2500 //function : VState
2501 //purpose  :
2502 //Draw arg : vstate [nameA] ... [nameN]
2503 //==============================================================================
2504 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2505 {
2506   TheAISContext()->CloseAllContexts();
2507   const Standard_Boolean ThereIsArguments=(argc>=2);
2508   const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2509   // Debut...
2510   // ==================
2511   // Il y a un argument
2512   // ==================
2513   if (ThereIsArguments) {
2514     for (int cpt=1;cpt<argc;cpt++) {
2515       // Verification que lq piece est bien bindee.
2516       if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2517         const Handle(AIS_InteractiveObject) theShape=
2518           Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2519                                                   (argv[cpt]));
2520         if (!theShape.IsNull()) {
2521           di<<argv[cpt];WhoAmI(theShape, di);
2522           if (TheAISContext()->IsDisplayed(theShape) ) {
2523             di<<"    Displayed"<<"\n";
2524           }
2525           else {
2526             di<<"    Not Displayed"<<"\n";
2527           }
2528         }
2529       }
2530       else {
2531         di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2532       }
2533     }
2534   }
2535   else if (ThereIsCurrent ) {
2536     for (TheAISContext() -> InitCurrent() ;
2537          TheAISContext() -> MoreCurrent() ;
2538          TheAISContext() ->NextCurrent() )
2539     {
2540       Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2541       di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2542       if (TheAISContext()->IsDisplayed(theShape) ) {
2543         di<<"    Displayed"<<"\n";
2544       }
2545       else {
2546         di<<"    Not Displayed"<<"\n";
2547       }
2548
2549     }
2550   }
2551   else {
2552     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2553       it(GetMapOfAIS());
2554     while ( it.More() ) {
2555       Handle(AIS_InteractiveObject) theShape =
2556         Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2557       if (!theShape.IsNull()) {
2558         di<<it.Key2().ToCString();
2559         WhoAmI(theShape, di);
2560         if (TheAISContext()->IsDisplayed(theShape) ) {
2561           di<<"    Displayed"<<"\n";
2562         }
2563         else {
2564           di<<"    Not Displayed"<<"\n";
2565         }
2566       }
2567       it.Next();
2568     }
2569   }
2570
2571   return 0;
2572 }
2573
2574
2575 //=======================================================================
2576 //function : PickObjects
2577 //purpose  :
2578 //=======================================================================
2579 Standard_Boolean  ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2580                                           const AIS_KindOfInteractive TheType,
2581                                           const Standard_Integer TheSignature,
2582                                           const Standard_Integer MaxPick)
2583 {
2584   Handle(AIS_InteractiveObject) IO;
2585   Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2586
2587   // step 1: prepare the data
2588   if(curindex !=0){
2589     Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2590     TheAISContext()->AddFilter(F1);
2591   }
2592
2593   // step 2 : wait for the selection...
2594 //  Standard_Boolean IsGood (Standard_False);
2595 //  Standard_Integer NbPick(0);
2596   Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2597   Standard_Integer NbPickFail(0);
2598   Standard_Integer argccc = 5;
2599   const char *bufff[] = { "A", "B", "C","D", "E" };
2600   const char **argvvv = (const char **) bufff;
2601
2602
2603   while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2604     while(ViewerMainLoop(argccc,argvvv)){}
2605     Standard_Integer NbStored = TheAISContext()->NbSelected();
2606     if((unsigned int ) NbStored != NbPickGood)
2607       NbPickGood= NbStored;
2608     else
2609       NbPickFail++;
2610     cout<<"NbPicked =  "<<NbPickGood<<" |  Nb Pick Fail :"<<NbPickFail<<endl;
2611   }
2612
2613   // step3 get result.
2614
2615   if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2616
2617   Standard_Integer i(0);
2618   for(TheAISContext()->InitSelected();
2619       TheAISContext()->MoreSelected();
2620       TheAISContext()->NextSelected()){
2621     i++;
2622     Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2623     arr->SetValue(i,IO2);
2624   }
2625
2626
2627   if(curindex>0)
2628     TheAISContext()->CloseLocalContext(curindex);
2629
2630   return Standard_True;
2631 }
2632
2633
2634 //=======================================================================
2635 //function : PickObject
2636 //purpose  :
2637 //=======================================================================
2638 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2639                                                      const Standard_Integer TheSignature,
2640                                                      const Standard_Integer MaxPick)
2641 {
2642   Handle(AIS_InteractiveObject) IO;
2643   Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2644
2645   // step 1: prepare the data
2646
2647   if(curindex !=0){
2648     Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2649     TheAISContext()->AddFilter(F1);
2650   }
2651
2652   // step 2 : wait for the selection...
2653   Standard_Boolean IsGood (Standard_False);
2654   Standard_Integer NbPick(0);
2655   Standard_Integer argccc = 5;
2656   const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2657   const char **argvvv = (const char **) bufff;
2658
2659
2660   while(!IsGood && NbPick<= MaxPick){
2661     while(ViewerMainLoop(argccc,argvvv)){}
2662     IsGood = (TheAISContext()->NbSelected()>0) ;
2663     NbPick++;
2664     cout<<"Nb Pick :"<<NbPick<<endl;
2665   }
2666
2667
2668   // step3 get result.
2669   if(IsGood){
2670     TheAISContext()->InitSelected();
2671     IO = TheAISContext()->SelectedInteractive();
2672   }
2673
2674   if(curindex!=0)
2675     TheAISContext()->CloseLocalContext(curindex);
2676   return IO;
2677 }
2678
2679 //=======================================================================
2680 //function : PickShape
2681 //purpose  : First Activate the rightmode + Put Filters to be able to
2682 //           pick objets that are of type <TheType>...
2683 //=======================================================================
2684
2685 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2686                                    const Standard_Integer MaxPick)
2687 {
2688
2689   // step 1: prepare the data
2690
2691   Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2692   TopoDS_Shape result;
2693
2694   if(TheType==TopAbs_SHAPE){
2695     Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2696     TheAISContext()->AddFilter(F1);
2697   }
2698   else{
2699     Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2700     TheAISContext()->AddFilter(TF);
2701     TheAISContext()->ActivateStandardMode(TheType);
2702
2703   }
2704
2705
2706   // step 2 : wait for the selection...
2707   Standard_Boolean NoShape (Standard_True);
2708   Standard_Integer NbPick(0);
2709   Standard_Integer argccc = 5;
2710   const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2711   const char **argvvv = (const char **) bufff;
2712
2713
2714   while(NoShape && NbPick<= MaxPick){
2715     while(ViewerMainLoop(argccc,argvvv)){}
2716     NoShape = (TheAISContext()->NbSelected()==0) ;
2717     NbPick++;
2718     cout<<"Nb Pick :"<<NbPick<<endl;
2719   }
2720
2721   // step3 get result.
2722
2723   if(!NoShape){
2724
2725     TheAISContext()->InitSelected();
2726     if(TheAISContext()->HasSelectedShape())
2727       result = TheAISContext()->SelectedShape();
2728     else{
2729       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2730       result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2731     }
2732   }
2733
2734   if(curindex>0)
2735     TheAISContext()->CloseLocalContext(curindex);
2736
2737   return result;
2738 }
2739
2740
2741 //=======================================================================
2742 //function : PickShapes
2743 //purpose  :
2744 //=======================================================================
2745 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2746                                          Handle(TopTools_HArray1OfShape)& thearr,
2747                                          const Standard_Integer MaxPick)
2748 {
2749
2750   Standard_Integer Taille = thearr->Length();
2751   if(Taille>1)
2752     cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2753
2754   // step 1: prepare the data
2755   Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2756   if(TheType==TopAbs_SHAPE){
2757     Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2758     TheAISContext()->AddFilter(F1);
2759   }
2760   else{
2761     Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2762     TheAISContext()->AddFilter(TF);
2763     TheAISContext()->ActivateStandardMode(TheType);
2764
2765   }
2766
2767   // step 2 : wait for the selection...
2768
2769   Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2770   Standard_Integer NbPickFail(0);
2771   Standard_Integer argccc = 5;
2772   const char *bufff[] = { "A", "B", "C","D", "E" };
2773   const char **argvvv = (const char **) bufff;
2774
2775
2776   while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2777     while(ViewerMainLoop(argccc,argvvv)){}
2778     Standard_Integer NbStored = TheAISContext()->NbSelected();
2779     if((unsigned int ) NbStored != NbPickGood)
2780       NbPickGood= NbStored;
2781     else
2782       NbPickFail++;
2783     cout<<"NbPicked =  "<<NbPickGood<<" |  Nb Pick Fail :"<<NbPickFail<<"\n";
2784   }
2785
2786   // step3 get result.
2787
2788   if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2789
2790   Standard_Integer i(0);
2791   for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2792     i++;
2793     if(TheAISContext()->HasSelectedShape())
2794       thearr->SetValue(i,TheAISContext()->SelectedShape());
2795     else{
2796       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2797       thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2798     }
2799   }
2800
2801   TheAISContext()->CloseLocalContext(curindex);
2802   return Standard_True;
2803 }
2804
2805
2806 //=======================================================================
2807 //function : VPickShape
2808 //purpose  :
2809 //=======================================================================
2810 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2811 {
2812   TopoDS_Shape PickSh;
2813   TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2814
2815   if(argc==1)
2816     theType = TopAbs_SHAPE;
2817   else{
2818     if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2819     else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2820     else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2821     else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2822     else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2823     else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2824     else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2825   }
2826
2827   static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2828   static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2829
2830   TCollection_AsciiString name;
2831
2832
2833   Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2834   if(NbToPick==1){
2835     PickSh = ViewerTest::PickShape(theType);
2836
2837     if(PickSh.IsNull())
2838       return 1;
2839     if(argc>2){
2840       name += argv[2];
2841     }
2842     else{
2843
2844       if(!PickSh.IsNull()){
2845         nbOfSub[Standard_Integer(theType)]++;
2846         name += "Picked_";
2847         name += nameType[Standard_Integer(theType)];
2848         TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2849         name +="_";
2850         name+=indxstring;
2851       }
2852     }
2853     // si on avait une petite methode pour voir si la shape
2854     // est deja dans la Double map, ca eviterait de creer....
2855     DBRep::Set(name.ToCString(),PickSh);
2856
2857     Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2858     GetMapOfAIS().Bind(newsh, name);
2859     TheAISContext()->Display(newsh);
2860     di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2861   }
2862
2863   // Plusieurs objets a picker, vite vite vite....
2864   //
2865   else{
2866     Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2867     Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2868     if(ViewerTest::PickShapes(theType,arr)){
2869       for(Standard_Integer i=1;i<=NbToPick;i++){
2870         PickSh = arr->Value(i);
2871         if(!PickSh.IsNull()){
2872           if(autonaming){
2873             nbOfSub[Standard_Integer(theType)]++;
2874             name.Clear();
2875             name += "Picked_";
2876             name += nameType[Standard_Integer(theType)];
2877             TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2878             name +="_";
2879             name+=indxstring;
2880           }
2881         }
2882         else
2883           name = argv[1+i];
2884
2885         DBRep::Set(name.ToCString(),PickSh);
2886         Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2887         GetMapOfAIS().Bind(newsh, name);
2888         di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2889         TheAISContext()->Display(newsh);
2890
2891       }
2892     }
2893   }
2894   return 0;
2895
2896 }
2897
2898
2899 //=======================================================================
2900 //function : VPickObject
2901 //purpose  : filters can be set (type of Object to pick....
2902 //
2903 //=======================================================================
2904 // Unused :
2905 #ifdef DEB
2906 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
2907 {
2908   // preparation de la nomination automatique
2909   static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
2910 //  static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
2911
2912 /*  TCollection_AsciiString name;
2913
2914   Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2915   if(NbToPick==1){
2916     PickSh = ViewerTest::PickObject(theType);
2917
2918     if(PickSh.IsNull())
2919       return 1;
2920     if(argc>2){
2921       name += argv[2];
2922     }
2923     else{
2924
2925       if(!PickSh.IsNull()){
2926         nbOfSub[Standard_Integer(theType)]++;
2927         name += "Picked_";
2928         name += nameType[Standard_Integer(theType)];
2929         TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2930         name +="_";
2931         name+=indxstring;
2932       }
2933     }
2934     // si on avait une petite methode pour voir si la shape
2935     // est deja dans la Double map, ca eviterait de creer....
2936     DBRep::Set(name.ToCString(),PickSh);
2937
2938     Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2939     GetMapOfAIS().Bind(newsh, name);
2940     TheAISContext()->Display(newsh);
2941     cout<<"Nom de la shape pickee : "<<name<<endl;
2942   }
2943
2944   // Plusieurs objets a picker, vite vite vite....
2945   //
2946   else{
2947     Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2948     Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2949     if(ViewerTest::PickShapes(theType,arr)){
2950       for(Standard_Integer i=1;i<=NbToPick;i++){
2951         PickSh = arr->Value(i);
2952         if(!PickSh.IsNull()){
2953           if(autonaming){
2954             nbOfSub[Standard_Integer(theType)]++;
2955             name.Clear();
2956             name += "Picked_";
2957             name += nameType[Standard_Integer(theType)];
2958             TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2959             name +="_";
2960             name+=indxstring;
2961           }
2962         }
2963         else
2964           name = argv[1+i];
2965
2966         DBRep::Set(name.ToCString(),PickSh);
2967         Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2968         GetMapOfAIS().Bind(newsh, name);
2969         cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
2970         TheAISContext()->Display(newsh);
2971
2972       }
2973     }
2974   }
2975   */
2976   return 0;
2977 }
2978 #endif
2979
2980 //=======================================================================
2981 //function : list of known objects
2982 //purpose  :
2983 //=======================================================================
2984 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
2985 {
2986   //                             1234567890         12345678901234567         123456789
2987   TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
2988   TCollection_AsciiString BlankLine(64,'_');
2989   Standard_Integer i ;
2990
2991   di<<"/n"<<BlankLine.ToCString()<<"\n";
2992
2993   for( i =0;i<=2;i++)
2994     Colum[i].Center(20,' ');
2995   for(i=0;i<=2;i++)
2996     di<<"|"<<Colum[i].ToCString();
2997   di<<"|"<<"\n";
2998
2999   di<<BlankLine.ToCString()<<"\n";
3000
3001   //  TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3002   const char ** names = GetTypeNames();
3003
3004   TCollection_AsciiString curstring;
3005   TCollection_AsciiString curcolum[3];
3006
3007
3008   // les objets de type Datum..
3009   curcolum[1]+="Datum";
3010   for(i =0;i<=6;i++){
3011     curcolum[0].Clear();
3012     curcolum[0] += names[i];
3013
3014     curcolum[2].Clear();
3015     curcolum[2]+=TCollection_AsciiString(i+1);
3016
3017     for(Standard_Integer j =0;j<=2;j++){
3018       curcolum[j].Center(20,' ');
3019       di<<"|"<<curcolum[j].ToCString();
3020     }
3021     di<<"|"<<"\n";
3022   }
3023   di<<BlankLine.ToCString()<<"\n";
3024
3025   // les objets de type shape
3026   curcolum[1].Clear();
3027   curcolum[1]+="Shape";
3028   curcolum[1].Center(20,' ');
3029
3030   for(i=0;i<=2;i++){
3031     curcolum[0].Clear();
3032     curcolum[0] += names[7+i];
3033     curcolum[2].Clear();
3034     curcolum[2]+=TCollection_AsciiString(i);
3035
3036     for(Standard_Integer j =0;j<=2;j++){
3037       curcolum[j].Center(20,' ');
3038       di<<"|"<<curcolum[j].ToCString();
3039     }
3040     di<<"|"<<"\n";
3041   }
3042   di<<BlankLine.ToCString()<<"\n";
3043   // les IO de type objet...
3044   curcolum[1].Clear();
3045   curcolum[1]+="Object";
3046   curcolum[1].Center(20,' ');
3047   for(i=0;i<=1;i++){
3048     curcolum[0].Clear();
3049     curcolum[0] += names[10+i];
3050     curcolum[2].Clear();
3051     curcolum[2]+=TCollection_AsciiString(i);
3052
3053     for(Standard_Integer j =0;j<=2;j++){
3054       curcolum[j].Center(20,' ');
3055       di<<"|"<<curcolum[j].ToCString();
3056     }
3057     di<<"|"<<"\n";
3058   }
3059   di<<BlankLine.ToCString()<<"\n";
3060   // les contraintes et dimensions.
3061   // pour l'instant on separe juste contraintes et dimensions...
3062   // plus tard, on detaillera toutes les sortes...
3063   curcolum[1].Clear();
3064   curcolum[1]+="Relation";
3065   curcolum[1].Center(20,' ');
3066   for(i=0;i<=1;i++){
3067     curcolum[0].Clear();
3068     curcolum[0] += names[12+i];
3069     curcolum[2].Clear();
3070     curcolum[2]+=TCollection_AsciiString(i);
3071
3072     for(Standard_Integer j =0;j<=2;j++){
3073       curcolum[j].Center(20,' ');
3074       di<<"|"<<curcolum[j].ToCString();
3075     }
3076     di<<"|"<<"\n";
3077   }
3078   di<<BlankLine.ToCString()<<"\n";
3079
3080
3081   return 0;
3082 }
3083
3084
3085 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3086 {
3087   if(argc!=2) return 1;
3088
3089   AIS_KindOfInteractive TheType;
3090   Standard_Integer TheSign(-1);
3091   GetTypeAndSignfromString(argv[1],TheType,TheSign);
3092
3093
3094   AIS_ListOfInteractive LIO;
3095
3096   // en attendant l'amelioration ais pour les dimensions...
3097   //
3098   Standard_Integer dimension_status(-1);
3099   if(TheType==AIS_KOI_Relation){
3100     dimension_status = TheSign ==1 ? 1 : 0;
3101     TheSign=-1;
3102   }
3103
3104   TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3105   Handle(AIS_InteractiveObject) curio;
3106   for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3107     curio  = it.Value();
3108
3109     if(dimension_status == -1)
3110       TheAISContext()->Erase(curio,Standard_False);
3111     else {
3112       AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3113       if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3114           (dimension_status==1 && KOD != AIS_KOD_NONE))
3115         TheAISContext()->Erase(curio,Standard_False);
3116     }
3117   }
3118   TheAISContext()->UpdateCurrentViewer();
3119   return 0;
3120 }
3121 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3122 {
3123   if(argc!=2) return 1;
3124
3125   AIS_KindOfInteractive TheType;
3126   Standard_Integer TheSign(-1);
3127   GetTypeAndSignfromString(argv[1],TheType,TheSign);
3128
3129   // en attendant l'amelioration ais pour les dimensions...
3130   //
3131   Standard_Integer dimension_status(-1);
3132   if(TheType==AIS_KOI_Relation){
3133     dimension_status = TheSign ==1 ? 1 : 0;
3134     TheSign=-1;
3135   }
3136
3137   AIS_ListOfInteractive LIO;
3138   TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3139   Handle(AIS_InteractiveObject) curio;
3140   for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3141     curio  = it.Value();
3142     if(dimension_status == -1)
3143       TheAISContext()->Display(curio,Standard_False);
3144     else {
3145       AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3146       if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3147           (dimension_status==1 && KOD != AIS_KOD_NONE))
3148         TheAISContext()->Display(curio,Standard_False);
3149     }
3150
3151   }
3152
3153   TheAISContext()->UpdateCurrentViewer();
3154   return 0;
3155 }
3156
3157 //==============================================================================
3158 //function : VSetTransMode
3159 //purpose  :
3160 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3161 //==============================================================================
3162
3163 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3164   // Verification des arguments
3165   if ( a3DView().IsNull() ) {
3166     ViewerTest::ViewerInit();
3167     di << "La commande vinit n'a pas ete appele avant" << "\n";
3168   }
3169
3170   if ( argc < 3 || argc > 8 ) {
3171     di << argv[0] << " Invalid number of arguments" << "\n";
3172     return 1;
3173   }
3174
3175   TCollection_AsciiString shapeName;
3176   shapeName = argv[1];
3177   Standard_Integer persFlag1 = atoi(argv[2]);
3178   Standard_Integer persFlag2 = 0;
3179   Standard_Integer persFlag3 = 0;
3180   gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3181   if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3182     persFlag2 = atoi(argv[3]);
3183   }
3184   if ( argc == 5 || argc == 8 ) {
3185     persFlag3 = atoi(argv[4]);
3186   }
3187   if ( argc >= 6 ) {
3188     origin.SetX( atof(argv[argc - 3]) );
3189     origin.SetY( atof(argv[argc - 2]) );
3190     origin.SetZ( atof(argv[argc - 1]) );
3191   }
3192
3193   Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3194   Handle(Standard_Transient) anObj;
3195   if ( IsBound ) {
3196     anObj = GetMapOfAIS().Find2(shapeName);
3197     if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3198       Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3199       aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3200       if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3201         di << argv[0] << " All persistence modifiers were removed" << "\n";
3202       }
3203     } else {
3204       di << argv[0] << " Wrong object type" << "\n";
3205       return 1;
3206     }
3207   } else { // Create the AIS_Shape from a name
3208     const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3209     if ( !aShape.IsNull() ) {
3210       GetMapOfAIS().Bind( aShape, shapeName );
3211       aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3212       TheAISContext()->Display( aShape, Standard_False );
3213     } else {
3214       di << argv[0] << " Object not found" << "\n";
3215       return 1;
3216     }
3217   }
3218
3219   // Upadate the screen and redraw the view
3220   TheAISContext()->UpdateCurrentViewer();
3221   return 0;
3222 }
3223
3224 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3225 {
3226   ifstream s(a[1]);
3227   BRep_Builder builder;
3228   TopoDS_Shape shape;
3229   BRepTools::Read(shape, s, builder);
3230   DBRep::Set(a[1], shape);
3231   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3232   Handle(AIS_Shape) ais = new AIS_Shape(shape);
3233   Ctx->Display(ais);
3234   return 0;
3235 }
3236 //============================================================================
3237 #include <AIS2D_InteractiveContext.hxx>
3238 #include <HLRAlgo_Projector.hxx>
3239 #include <Prs3d_Projector.hxx>
3240 #include <AIS2D_ProjShape.hxx>
3241 #include <gp_Ax2.hxx>
3242 #include <gp.hxx>
3243 Standard_Integer hlrtest(Draw_Interpretor&,   Standard_Integer n,   const char** a)
3244 {
3245
3246   Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3247   /////////////////////
3248   TopoDS_Shape aShape =  DBRep::Get(a[1]);
3249   aContext2D->EraseAll(Standard_True);
3250   //Standard_Integer aPolyAlgo = 0;
3251   Standard_Boolean IsPoly = Standard_False;
3252   gp_Ax2 anAx2 = gp::XOY();
3253
3254   //if(n > 2) aPolyAlgo = atoi(a[2]);
3255
3256   //IsPoly = aPolyAlgo > 0;
3257
3258   TopoDS_Shape aResult = aShape;
3259
3260
3261   if (n == 11)
3262   {
3263     Standard_Real x = atof(a[2]);
3264     Standard_Real y = atof(a[3]);
3265     Standard_Real z = atof(a[4]);
3266
3267     Standard_Real dx = atof(a[5]);
3268     Standard_Real dy = atof(a[6]);
3269     Standard_Real dz = atof(a[7]);
3270
3271     Standard_Real dx1 = atof(a[8]);
3272     Standard_Real dy1 = atof(a[9]);
3273     Standard_Real dz1 = atof(a[10]);
3274
3275     gp_Pnt anOrigin (x, y, z);
3276     gp_Dir aNormal  (dx, dy, dz);
3277     gp_Dir aDX      (dx1, dy1, dz1);
3278     anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3279   }
3280
3281
3282   HLRAlgo_Projector aProjector(anAx2);
3283
3284   //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3285
3286   //aProjector =  aProjector_t.Projector();
3287
3288   Handle(AIS2D_ProjShape) myDisplayableShape =
3289     new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3290
3291   myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3292                                 Standard_False, Standard_True, Standard_False);
3293
3294   myDisplayableShape->Add( aResult );
3295
3296
3297   aContext2D->Display( myDisplayableShape,Standard_True );
3298   aContext2D->UpdateCurrentViewer();
3299
3300   return 0;
3301 }
3302
3303 Standard_Integer phlrtest(Draw_Interpretor&,   Standard_Integer n,   const char** a)
3304 {
3305
3306   Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3307   /////////////////////
3308   TopoDS_Shape aShape =  DBRep::Get(a[1]);
3309   aContext2D->EraseAll(Standard_True);
3310   //Standard_Integer aPolyAlgo = 0;
3311   Standard_Boolean IsPoly = Standard_True;
3312   gp_Ax2 anAx2 = gp::XOY();
3313
3314   //if(n > 2) aPolyAlgo = atoi(a[2]);
3315
3316   //IsPoly = aPolyAlgo > 0;
3317
3318   TopoDS_Shape aResult = aShape;
3319
3320
3321   if (n == 11)
3322   {
3323     Standard_Real x = atof(a[2]);
3324     Standard_Real y = atof(a[3]);
3325     Standard_Real z = atof(a[4]);
3326
3327     Standard_Real dx = atof(a[5]);
3328     Standard_Real dy = atof(a[6]);
3329     Standard_Real dz = atof(a[7]);
3330
3331     Standard_Real dx1 = atof(a[8]);
3332     Standard_Real dy1 = atof(a[9]);
3333     Standard_Real dz1 = atof(a[10]);
3334
3335     gp_Pnt anOrigin (x, y, z);
3336     gp_Dir aNormal  (dx, dy, dz);
3337     gp_Dir aDX      (dx1, dy1, dz1);
3338     anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3339   }
3340
3341
3342   HLRAlgo_Projector aProjector(anAx2);
3343
3344   //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3345
3346   //aProjector =  aProjector_t.Projector();
3347
3348   Handle(AIS2D_ProjShape) myDisplayableShape =
3349     new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3350
3351   myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3352                                 Standard_False, Standard_True, Standard_False);
3353
3354   myDisplayableShape->Add( aResult );
3355
3356
3357   aContext2D->Display( myDisplayableShape,Standard_True );
3358   aContext2D->UpdateCurrentViewer();
3359
3360   return 0;
3361 }
3362
3363 //==============================================================================
3364 //function : ViewerTest::Commands
3365 //purpose  : Add all the viewer command in the Draw_Interpretor
3366 //==============================================================================
3367
3368 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3369 {
3370   ViewerTest::ViewerCommands(theCommands);
3371   ViewerTest::RelationCommands(theCommands);
3372   ViewerTest::ObjectCommands(theCommands);
3373   ViewerTest::FilletCommands(theCommands);
3374   ViewerTest::VoxelCommands(theCommands);
3375   ViewerTest::OpenGlCommands(theCommands);
3376
3377   const char *group = "AIS_Display";
3378
3379   // display
3380
3381   theCommands.Add("vdisplay",
3382                   "vdisplay         : vdisplay2 name1 [name2] ... [name n] ",
3383                   __FILE__,VDisplay2,group);
3384
3385   theCommands.Add("verase",
3386                   "verase      : verase2 [name1] ...  [name n] ",
3387                   __FILE__,VErase2,group);
3388
3389   theCommands.Add("vdonly",
3390                   "vdonly         : vdonly2 [name1] ...  [name n]",
3391                   __FILE__,VDonly2,group);
3392
3393   theCommands.Add("vdisplayall",
3394                   "vdisplayall         : vdisplayall",
3395                   __FILE__,VDisplayAll,group);
3396
3397   theCommands.Add("veraseall",
3398                   "veraseall        : veraseall ",
3399                   __FILE__,VEraseAll,group);
3400
3401   theCommands.Add("verasetype",
3402                   "verasetype        : verasetype <Type>  \n\t erase all the displayed objects of one given kind (see vtypes)",
3403                   __FILE__,VEraseType,group);
3404
3405   theCommands.Add("vdisplaytype",
3406                   "vdisplaytype        : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3407                   __FILE__,VDisplayType,group);
3408
3409   theCommands.Add("vdisplaymode",
3410                   "vdispmode       : vdispmode  [name] mode(1,2,..) : no name -> on selected objects ",
3411                   __FILE__,VDispMode,group);
3412
3413   theCommands.Add("verasemode",
3414                   "verasemode      : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3415                   __FILE__,VDispMode,group);
3416
3417   theCommands.Add("vsetdispmode",
3418                   "vsetdispmode    : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3419                   __FILE__,VDispMode,group);
3420
3421   theCommands.Add("vunsetdispmode",
3422                   "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3423                   __FILE__,VDispMode,group);
3424
3425   theCommands.Add("vdir",
3426                   "vdir",
3427                   __FILE__,VDebug,group);
3428
3429   theCommands.Add("vdump",
3430                   "<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",
3431                   __FILE__,VDump,group);
3432
3433   theCommands.Add("vsub",      "vsub 0/1 (off/on) [obj]        : Subintensity(on/off) of selected objects",
3434                   __FILE__,VSubInt,group);
3435
3436   theCommands.Add("vsetcolor",
3437                   "vsetcolor         : vsetcolor [name of shape] ColorName",
3438                   __FILE__,VColor2,group);
3439
3440   theCommands.Add("vunsetcolor",
3441                   "vunsetcolor     : vunsetcolor   [name of shape] ",
3442                   __FILE__,VColor2,group);
3443
3444   theCommands.Add("vsettransparency",
3445                   "vsettransparency          : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3446                   __FILE__,VTransparency,group);
3447
3448   theCommands.Add("vunsettransparency",
3449                   "vunsettransparency          : vtransparency [name of shape]",
3450                   __FILE__,VTransparency,group);
3451
3452   theCommands.Add("vsetmaterial",
3453                   "vmaterial          : vmaterial  [name of shape] MaterialName",
3454                   __FILE__,VMaterial,group);
3455
3456   theCommands.Add("vunsetmaterial",
3457                   "vmaterial          : vmaterial  [name of shape]",
3458                   __FILE__,VMaterial,group);
3459
3460   theCommands.Add("vsetwidth",
3461                   "vsetwidth          : vwidth  [name of shape] width(0->10)",
3462                   __FILE__,VWidth,group);
3463
3464   theCommands.Add("vunsetwidth",
3465                   "vunsetwidth          : vwidth  [name of shape]",
3466                   __FILE__,VWidth,group);
3467
3468   theCommands.Add("vsetinteriorstyle",
3469                   "vsetinteriorstyle    : vsetinteriorstyle [name of shape] style",
3470                   __FILE__,VInteriorStyle,group);
3471
3472   theCommands.Add("vardis",
3473                   "vardis          : display activeareas",
3474                   __FILE__,VDispAreas,group);
3475
3476   theCommands.Add("varera",
3477                   "varera           : erase activeareas",
3478                   __FILE__,VClearAreas,group);
3479
3480   theCommands.Add("vsensdis",
3481                   "vardisp           : display active entities",
3482                   __FILE__,VDispSensi,group);
3483   theCommands.Add("vsensera",
3484                   "vardisp           : erase  active entities",
3485                   __FILE__,VClearSensi,group);
3486
3487   theCommands.Add("vselprecision",
3488                   "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3489                   __FILE__,VSelPrecision,group);
3490
3491   theCommands.Add("vperf",
3492                   "vperf: vperf  ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3493                   __FILE__,VPerf,group);
3494
3495   theCommands.Add("vanimation",
3496                   "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3497                   __FILE__,VAnimation,group);
3498
3499   theCommands.Add("vsetshading",
3500                   "vsetshading  : vsetshading name Quality(default=0.0008) ",
3501                   __FILE__,VShading,group);
3502
3503   theCommands.Add("vunsetshading",
3504                   "vunsetshading :vunsetshading name ",
3505                   __FILE__,VShading,group);
3506
3507   theCommands.Add("vtexture",
3508                   "'vtexture NameOfShape TextureFile' \n \
3509                   or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3510                   or 'vtexture NameOfShape ?' to list available textures\n \
3511                   or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined  textures\n ",
3512                   __FILE__,VTexture,group);
3513
3514   theCommands.Add("vtexscale",
3515                   "'vtexscale  NameOfShape ScaleU ScaleV' \n \
3516                    or 'vtexscale NameOfShape ScaleUV' \n \
3517                    or 'vtexscale NameOfShape' to disable scaling\n ",
3518                   __FILE__,VTexture,group);
3519
3520   theCommands.Add("vtexorigin",
3521                   "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3522                    or 'vtexorigin NameOfShape UVOrigin' \n \
3523                    or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3524                   __FILE__,VTexture,group);
3525
3526   theCommands.Add("vtexrepeat",
3527                   "'vtexrepeat  NameOfShape URepeat VRepeat' \n \
3528                    or 'vtexrepeat NameOfShape UVRepeat \n \
3529                    or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3530                   VTexture,group);
3531
3532   theCommands.Add("vtexdefault",
3533                   "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3534                   VTexture,group);
3535
3536   theCommands.Add("vsetam",
3537                   "vsetActivatedModes: vsetam mode(1->7)  ",
3538                   __FILE__,VActivatedMode,group);
3539
3540   theCommands.Add("vunsetam",
3541                   "vunsetActivatedModes:   vunsetam  ",
3542                   __FILE__,VActivatedMode,group);
3543
3544   theCommands.Add("vstate",   "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all  ",
3545                   __FILE__,VState,group);
3546
3547   theCommands.Add("vpickshapes",
3548                   "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3549                   __FILE__,VPickShape,group);
3550
3551   theCommands.Add("vtypes",
3552                   "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3553                   VIOTypes,group);
3554
3555   theCommands.Add("vsettransmode",
3556                   "vsettransmode   : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3557                   __FILE__,VSetTransMode,group);
3558
3559   theCommands.Add("vr", "vr : reading of the shape",
3560                   __FILE__,vr, group);
3561
3562   theCommands.Add("hlrtest"       , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3563   theCommands.Add("phlrtest"       , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3564
3565 }
3566
3567 //=====================================================================
3568 //========================= for testing Draft and Rib =================
3569 //=====================================================================
3570 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3571 #include <DBRep.hxx>
3572 #include <TopoDS_Face.hxx>
3573 #include <gp_Pln.hxx>
3574 #include <AIS_KindOfSurface.hxx>
3575 #include <BRepOffsetAPI_DraftAngle.hxx>
3576 #include <Precision.hxx>
3577 #include <BRepAlgo.hxx>
3578 #include <OSD_Environment.hxx>
3579 #include <DrawTrSurf.hxx>
3580 //#include <DbgTools.hxx>
3581 //#include <FeatAlgo_MakeLinearForm.hxx>
3582
3583
3584
3585
3586 //=======================================================================
3587 //function : IsValid
3588 //purpose  :
3589 //=======================================================================
3590 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3591                                 const TopoDS_Shape& theResult,
3592                                 const Standard_Boolean closedSolid,
3593                                 const Standard_Boolean GeomCtrl)
3594 {
3595   OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3596   TCollection_AsciiString checkValid = check.Value();
3597   Standard_Boolean ToCheck = Standard_True;
3598   if (!checkValid.IsEmpty()) {
3599 #ifdef DEB
3600     cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3601 #endif
3602     if ( checkValid=="true" || checkValid=="TRUE" ) {
3603       ToCheck= Standard_False;
3604     }
3605   } else {
3606 #ifdef DEB
3607     cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3608 #endif
3609   }
3610   Standard_Boolean IsValid = Standard_True;
3611   if (ToCheck)
3612     IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3613   return IsValid;
3614
3615 }
3616
3617 //===============================================================================
3618 // TDraft : test draft, uses AIS Viewer
3619 // Solid Face Plane Angle  Reverse
3620 //===============================================================================
3621 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3622 {
3623   if (argc < 5) return 1;
3624 // argv[1] - TopoDS_Shape Solid
3625 // argv[2] - TopoDS_Shape Face
3626 // argv[3] - TopoDS_Shape Plane
3627 // argv[4] - Standard_Real Angle
3628 // argv[5] - Standard_Integer Reverse
3629
3630 //  sprintf(prefix, argv[1]);
3631   Standard_Real anAngle = 0;
3632   Standard_Boolean Rev = Standard_False;
3633   Standard_Integer rev = 0;
3634   TopoDS_Shape Solid  = GetShapeFromName(argv[1]);
3635   TopoDS_Shape face   = GetShapeFromName(argv[2]);
3636   TopoDS_Face Face    = TopoDS::Face(face);
3637   TopoDS_Shape Plane  = GetShapeFromName(argv[3]);
3638   if (Plane.IsNull ()) {
3639     di << "TEST : Plane is NULL" << "\n";
3640     return 1;
3641   }
3642   anAngle = atof(argv[4]);
3643   anAngle = 2*M_PI * anAngle / 360.0;
3644   gp_Pln aPln;
3645   Handle( Geom_Surface )aSurf;
3646   AIS_KindOfSurface aSurfType;
3647   Standard_Real Offset;
3648   gp_Dir aDir;
3649   if(argc > 4) { // == 5
3650     rev = atoi(argv[5]);
3651     Rev = (rev)? Standard_True : Standard_False;
3652   }
3653
3654   TopoDS_Face face2 = TopoDS::Face(Plane);
3655   if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3656     {
3657       di << "TEST : Can't find plane" << "\n";
3658       return 1;
3659     }
3660
3661   aDir = aPln.Axis().Direction();
3662   if (!aPln.Direct())
3663     aDir.Reverse();
3664   if (Plane.Orientation() == TopAbs_REVERSED)
3665     aDir.Reverse();
3666   di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3667
3668   BRepOffsetAPI_DraftAngle Draft (Solid);
3669
3670   if(Abs(anAngle)< Precision::Angular()) {
3671     di << "TEST : NULL angle" << "\n";
3672     return 1;}
3673
3674   if(Rev) anAngle = - anAngle;
3675   Draft.Add (Face, aDir, anAngle, aPln);
3676   Draft.Build ();
3677   if (!Draft.IsDone())  {
3678     di << "TEST : Draft Not DONE " << "\n";
3679     return 1;
3680   }
3681   TopTools_ListOfShape Larg;
3682   Larg.Append(Solid);
3683   if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3684     di << "TEST : DesignAlgo returns Not valid" << "\n";
3685     return 1;
3686   }
3687
3688   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3689   Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3690
3691   if ( !ais.IsNull() ) {
3692     ais->SetColor(DEFAULT_COLOR);
3693     ais->SetMaterial(DEFAULT_MATERIAL);
3694     // Display the AIS_Shape without redraw
3695     Ctx->Display(ais, Standard_False);
3696
3697     const char *Name = "draft1";
3698     Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3699     if (IsBound) {
3700       Handle(AIS_InteractiveObject) an_object =
3701         Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3702       if (!an_object.IsNull()) {
3703         Ctx->Remove(an_object,
3704                     Standard_True) ;
3705         GetMapOfAIS().UnBind2(Name) ;
3706       }
3707     }
3708     GetMapOfAIS().Bind(ais, Name);
3709 //  DBRep::Set("draft", ais->Shape());
3710   }
3711   Ctx->Display(ais, Standard_True);
3712   return 0;
3713 }
3714
3715
3716
3717 //============================================================================
3718 //  MyCommands
3719 //============================================================================
3720 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3721 {
3722
3723   DrawTrSurf::BasicCommands(theCommands);
3724   const char* group = "Check Features Operations commands";
3725
3726   theCommands.Add("Draft","Draft    Solid Face Plane Angle Reverse",
3727                   __FILE__,
3728                   &TDraft,group); //Draft_Modification
3729 }
3730
3731 //==============================================================================
3732 // ViewerTest::Factory
3733 //==============================================================================
3734 void ViewerTest::Factory(Draw_Interpretor& theDI)
3735 {
3736   // definition of Viewer Command
3737       ViewerTest::Commands(theDI);
3738       ViewerTest::AviCommands(theDI);
3739       Viewer2dTest::Commands(theDI);
3740 #ifdef DEB
3741       theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3742 #endif
3743 }
3744
3745 // Declare entry point PLUGINFACTORY
3746 DPLUGIN(ViewerTest)