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