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