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