0025198: Draw Harness - add -noupdate option to vsetlocation command
[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-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 // Modified by  Eric Gouthiere [sep-oct 98] -> add commands for display...
18 // Modified by  Robert Coublanc [nov 16-17-18 1998]
19 //             -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
20 //                                                  ViewerTest_ObjectCommands.cxx
21 //                                                  ViewerTest_RelationCommands.cxx
22 //             -add Functions and commands for interactive selection of shapes and objects
23 //              in AIS Viewers. (PickShape(s), PickObject(s),
24
25 #include <Standard_Stream.hxx>
26
27 #include <ViewerTest.hxx>
28
29 #include <TopLoc_Location.hxx>
30 #include <TopTools_HArray1OfShape.hxx>
31 #include <TColStd_HArray1OfTransient.hxx>
32 #include <TColStd_HSequenceOfAsciiString.hxx>
33 #include <OSD_Timer.hxx>
34 #include <Geom_Axis2Placement.hxx>
35 #include <Geom_Axis1Placement.hxx>
36 #include <gp_Trsf.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <BRepAdaptor_Curve.hxx>
39 #include <StdSelect_ShapeTypeFilter.hxx>
40 #include <AIS.hxx>
41 #include <AIS_Drawer.hxx>
42 #include <AIS_ColoredShape.hxx>
43 #include <AIS_InteractiveObject.hxx>
44 #include <AIS_Trihedron.hxx>
45 #include <AIS_Axis.hxx>
46 #include <AIS_Relation.hxx>
47 #include <AIS_TypeFilter.hxx>
48 #include <AIS_SignatureFilter.hxx>
49 #include <AIS_LocalContext.hxx>
50 #include <AIS_ListOfInteractive.hxx>
51 #include <AIS_ListIteratorOfListOfInteractive.hxx>
52 #include <Aspect_InteriorStyle.hxx>
53 #include <Aspect_Window.hxx>
54 #include <Graphic3d_AspectFillArea3d.hxx>
55 #include <Graphic3d_AspectLine3d.hxx>
56 #include <Graphic3d_TextureRoot.hxx>
57 #include <Image_AlienPixMap.hxx>
58 #include <Prs3d_ShadingAspect.hxx>
59 #include <Prs3d_IsoAspect.hxx>
60 #include <TopTools_MapOfShape.hxx>
61 #include <ViewerTest_AutoUpdater.hxx>
62
63 #include <stdio.h>
64
65 #include <Draw_Interpretor.hxx>
66 #include <TCollection_AsciiString.hxx>
67 #include <Draw_PluginMacro.hxx>
68
69 // avoid warnings on 'extern "C"' functions returning C++ classes
70 #ifdef WNT
71 #define _CRT_SECURE_NO_DEPRECATE
72 #pragma warning(4:4190)
73 #pragma warning (disable:4996)
74 #endif
75
76 #include <NIS_InteractiveContext.hxx>
77 #include <NIS_Triangulated.hxx>
78 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
79
80 #include <Quantity_Color.hxx>
81 #include <Quantity_NameOfColor.hxx>
82
83 #include <Graphic3d_NameOfMaterial.hxx>
84
85 #define DEFAULT_COLOR    Quantity_NOC_GOLDENROD
86 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
87
88 //=======================================================================
89 //function : GetColorFromName
90 //purpose  : get the Quantity_NameOfColor from a string
91 //=======================================================================
92
93 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
94 {
95   for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
96   {
97     Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
98     if (strcasecmp (theName, aColorName) == 0)
99     {
100       return Quantity_NameOfColor (anIter);
101     }
102   }
103
104   return DEFAULT_COLOR;
105 }
106
107 //=======================================================================
108 //function : GetTypeNames
109 //purpose  :
110 //=======================================================================
111 static const char** GetTypeNames()
112 {
113   static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
114                           "Shape","ConnectedShape","MultiConn.Shape",
115                           "ConnectedInter.","MultiConn.",
116                           "Constraint","Dimension"};
117   static const char** ThePointer = names;
118   return ThePointer;
119 }
120
121 //=======================================================================
122 //function : GetTypeAndSignfromString
123 //purpose  :
124 //=======================================================================
125 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
126 {
127   const char ** thefullnames = GetTypeNames();
128   Standard_Integer index(-1);
129
130   for(Standard_Integer i=0;i<=13 && index==-1;i++)
131     if(!strcasecmp(name,thefullnames[i]))
132       index = i;
133
134   if(index ==-1){
135     TheType = AIS_KOI_None;
136     TheSign = -1;
137     return;
138   }
139
140   if(index<=6){
141     TheType = AIS_KOI_Datum;
142     TheSign = index+1;
143   }
144   else if (index <=9){
145     TheType = AIS_KOI_Shape;
146     TheSign = index-7;
147   }
148   else if(index<=11){
149     TheType = AIS_KOI_Object;
150     TheSign = index-10;
151   }
152   else{
153     TheType = AIS_KOI_Relation;
154     TheSign = index-12;
155   }
156
157 }
158
159
160
161 #include <string.h>
162 #include <Draw_Interpretor.hxx>
163 #include <Draw.hxx>
164 #include <Draw_Appli.hxx>
165 #include <DBRep.hxx>
166
167
168 #include <TCollection_AsciiString.hxx>
169 #include <V3d_Viewer.hxx>
170 #include <V3d_View.hxx>
171 #include <V3d.hxx>
172
173 #include <AIS_InteractiveContext.hxx>
174 #include <AIS_Shape.hxx>
175 #include <AIS_TexturedShape.hxx>
176 #include <AIS_DisplayMode.hxx>
177 #include <TColStd_MapOfInteger.hxx>
178 #include <AIS_MapOfInteractive.hxx>
179 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
180 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
181 #include <ViewerTest_EventManager.hxx>
182
183 #include <TopoDS_Solid.hxx>
184 #include <BRepTools.hxx>
185 #include <BRep_Builder.hxx>
186 #include <TopAbs_ShapeEnum.hxx>
187
188 #include <TopoDS.hxx>
189 #include <BRep_Tool.hxx>
190
191
192 #include <Draw_Window.hxx>
193 #include <AIS_ListIteratorOfListOfInteractive.hxx>
194 #include <AIS_ListOfInteractive.hxx>
195 #include <AIS_DisplayMode.hxx>
196 #include <TopTools_ListOfShape.hxx>
197 #include <BRepOffsetAPI_MakeThickSolid.hxx>
198 #include <BRepOffset.hxx>
199
200 //==============================================================================
201 //  VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
202 //==============================================================================
203 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
204   static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
205   return TheMap;
206 }
207
208
209 //==============================================================================
210 //function : VDisplayAISObject
211 //purpose  : register interactive object in the map of AIS objects;
212 //           if other object with such name already registered, it will be kept
213 //           or replaced depending on value of <theReplaceIfExists>,
214 //           if "true" - the old object will be cleared from AIS context;
215 //           returns Standard_True if <theAISObj> registered in map;
216 //==============================================================================
217 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
218                                                     const Handle(AIS_InteractiveObject)& theAISObj,
219                                                     Standard_Boolean theReplaceIfExists = Standard_True)
220 {
221   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
222   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
223   if (aContextAIS.IsNull())
224   {
225     std::cout << "AIS context is not available.\n";
226     return Standard_False;
227   }
228
229   if (aMap.IsBound2 (theName))
230   {
231     if (!theReplaceIfExists)
232     {
233       std::cout << "Other interactive object has been already "
234                 << "registered with name: " << theName << ".\n"
235                 << "Please use another name.\n";
236       return Standard_False;
237     }
238
239     // stop displaying object
240     Handle(AIS_InteractiveObject) anOldObj =
241        Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
242
243     if (!anOldObj.IsNull())
244       aContextAIS->Clear (anOldObj, Standard_True);
245
246     // remove name and old object from map
247     aMap.UnBind2 (theName);
248   }
249
250   if (theAISObj.IsNull())
251   {
252     // object with specified name already unbound
253     return Standard_True;
254   }
255
256   // unbind AIS object if was bound with another name
257   aMap.UnBind1 (theAISObj);
258
259   // can be registered without rebinding
260   aMap.Bind (theAISObj, theName);
261   aContextAIS->Display (theAISObj, Standard_True);
262   return Standard_True;
263 }
264
265 static TColStd_MapOfInteger theactivatedmodes(8);
266 static TColStd_ListOfTransient theEventMgrs;
267
268 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
269                                 const Handle(AIS_InteractiveContext)& Ctx)
270 {
271   theEventMgrs.Clear();
272   theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
273 }
274
275 static Handle(V3d_View)&  a3DView()
276 {
277   static Handle(V3d_View) Viou;
278   return Viou;
279 }
280
281
282 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
283   static Handle(AIS_InteractiveContext) aContext;
284   return aContext;
285 }
286
287 const Handle(V3d_View)& ViewerTest::CurrentView()
288 {
289   return a3DView();
290 }
291 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
292 {
293   a3DView() = V;
294 }
295
296 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
297 {
298   static Handle(NIS_InteractiveContext) aContext;
299   if (aContext.IsNull()) {
300     aContext = new NIS_InteractiveContext;
301     aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
302   }
303   return aContext;
304 }
305
306 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
307 {
308   return TheAISContext();
309 }
310
311 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
312 {
313   TheAISContext() = aCtx;
314   ViewerTest::ResetEventManager();
315 }
316
317 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
318 {
319   return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
320 }
321
322 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
323 {
324   return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
325 }
326
327
328 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
329   theEventMgrs.Prepend(EM);
330 }
331
332 void ViewerTest::UnsetEventManager()
333 {
334   theEventMgrs.RemoveFirst();
335 }
336
337
338 void ViewerTest::ResetEventManager()
339 {
340   const Handle(NIS_View) aView =
341     Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
342   VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
343 }
344
345 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
346 {
347   Handle(ViewerTest_EventManager) EM;
348   if(theEventMgrs.IsEmpty()) return EM;
349   Handle(Standard_Transient) Tr =  theEventMgrs.First();
350   EM = *((Handle(ViewerTest_EventManager)*)&Tr);
351   return EM;
352 }
353
354 //=======================================================================
355 //function : Get Context and active view
356 //purpose  :
357 //=======================================================================
358 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
359                                        Handle(V3d_View)&               theView)
360 {
361   theCtx  = ViewerTest::GetAISContext();
362   theView = ViewerTest::CurrentView();
363   if (theCtx.IsNull()
364    || theView.IsNull())
365   {
366     std::cout << "Error: cannot find an active view!\n";
367     return Standard_False;
368   }
369   return Standard_True;
370 }
371
372 //==============================================================================
373 //function : GetShapeFromName
374 //purpose  : Compute an Shape from a draw variable or a file name
375 //==============================================================================
376
377 static TopoDS_Shape GetShapeFromName(const char* name)
378 {
379   TopoDS_Shape S = DBRep::Get(name);
380
381   if ( S.IsNull() ) {
382         BRep_Builder aBuilder;
383         BRepTools::Read( S, name, aBuilder);
384   }
385
386   return S;
387 }
388
389 //==============================================================================
390 //function : GetAISShapeFromName
391 //purpose  : Compute an AIS_Shape from a draw variable or a file name
392 //==============================================================================
393 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
394 {
395   Handle(AIS_Shape) retsh;
396
397   if(GetMapOfAIS().IsBound2(name)){
398     const Handle(AIS_InteractiveObject) IO =
399       Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
400     if (!IO.IsNull()) {
401       if(IO->Type()==AIS_KOI_Shape) {
402         if(IO->Signature()==0){
403           retsh = *((Handle(AIS_Shape)*)&IO);
404         }
405         else
406           cout << "an Object which is not an AIS_Shape "
407             "already has this name!!!"<<endl;
408       }
409     }
410     return retsh;
411   }
412
413
414   TopoDS_Shape S = GetShapeFromName(name);
415   if ( !S.IsNull() ) {
416     retsh = new AIS_Shape(S);
417   }
418   return retsh;
419 }
420
421
422 //==============================================================================
423 //function : Clear
424 //purpose  : Remove all the object from the viewer
425 //==============================================================================
426 void ViewerTest::Clear()
427 {
428   if ( !a3DView().IsNull() ) {
429     if (TheAISContext()->HasOpenedContext())
430       TheAISContext()->CloseLocalContext();
431     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
432     while ( it.More() ) {
433       cout << "Remove " << it.Key2() << endl;
434       if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
435         const Handle(AIS_InteractiveObject) anObj =
436           Handle(AIS_InteractiveObject)::DownCast (it.Key1());
437         TheAISContext()->Remove(anObj,Standard_False);
438       } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
439         const Handle(NIS_InteractiveObject) anObj =
440           Handle(NIS_InteractiveObject)::DownCast (it.Key1());
441         TheNISContext()->Remove(anObj);
442       }
443       it.Next();
444     }
445     TheAISContext()->UpdateCurrentViewer();
446 //    TheNISContext()->UpdateViews();
447     GetMapOfAIS().Clear();
448   }
449 }
450
451 //==============================================================================
452 //function : StandardModesActivation
453 //purpose  : Activate a selection mode, vertex, edge, wire ..., in a local
454 //           Context
455 //==============================================================================
456 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
457 {
458   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
459   if(mode==0) {
460     if (TheAISContext()->HasOpenedContext())
461       aContext->CloseLocalContext();
462   } else {
463
464     if(!aContext->HasOpenedContext()) {
465       // To unhilight the preselected object
466       aContext->UnhilightCurrents(Standard_False);
467       // Open a local Context in order to be able to select subshape from
468       // the selected shape if any or for all if there is no selection
469       if (!aContext->FirstCurrentObject().IsNull()){
470         aContext->OpenLocalContext(Standard_False);
471
472         for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
473           aContext->Load(       aContext->Current(),-1,Standard_True);
474         }
475       }
476       else
477         aContext->OpenLocalContext();
478     }
479
480     const char *cmode="???";
481
482     switch (mode) {
483     case 0: cmode = "Shape"; break;
484     case 1: cmode = "Vertex"; break;
485     case 2: cmode = "Edge"; break;
486     case 3: cmode = "Wire"; break;
487     case 4: cmode = "Face"; break;
488     case 5: cmode = "Shell"; break;
489     case 6: cmode = "Solid"; break;
490     case 7: cmode = "Compsolid"; break;
491     case 8: cmode = "Compound"; break;
492     }
493
494     if(theactivatedmodes.Contains(mode))
495       { // Desactivate
496         aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
497         theactivatedmodes.Remove(mode);
498         cout<<"Mode "<< cmode <<" OFF"<<endl;
499       }
500     else
501       { // Activate
502         aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
503         theactivatedmodes.Add(mode);
504         cout<<"Mode "<< cmode << " ON" << endl;
505       }
506   }
507 }
508
509 //==============================================================================
510 //function : CopyIsoAspect
511 //purpose  : Returns copy Prs3d_IsoAspect with new number of isolines.
512 //==============================================================================
513 static Handle(Prs3d_IsoAspect) CopyIsoAspect
514       (const Handle(Prs3d_IsoAspect) &theIsoAspect,
515        const Standard_Integer theNbIsos)
516 {
517   Quantity_Color    aColor;
518   Aspect_TypeOfLine aType;
519   Standard_Real     aWidth;
520
521   theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
522
523   Handle(Prs3d_IsoAspect) aResult =
524     new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
525
526   return aResult;
527 }
528
529 //==============================================================================
530 //function : visos
531 //purpose  : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
532 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
533 //==============================================================================
534 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
535 {
536   if (TheAISContext().IsNull()) {
537     di << argv[0] << " Call 'vinit' before!\n";
538     return 1;
539   }
540
541   if (argc <= 1) {
542     di << "Current number of isos : " <<
543       TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
544       TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
545     di << "IsoOnPlane mode is " <<
546       (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
547
548     return 0;
549   }
550
551   Standard_Integer aLastInd = argc - 1;
552   Standard_Boolean isChanged = Standard_False;
553   Standard_Integer aNbUIsos = 0;
554   Standard_Integer aNbVIsos = 0;
555
556   if (aLastInd >= 3) {
557     Standard_Boolean isIsoOnPlane = Standard_False;
558
559     if (strcmp(argv[aLastInd], "1") == 0) {
560       isIsoOnPlane = Standard_True;
561       isChanged    = Standard_True;
562     } else if (strcmp(argv[aLastInd], "0") == 0) {
563       isIsoOnPlane = Standard_False;
564       isChanged    = Standard_True;
565     }
566
567     if (isChanged) {
568       aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
569       aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
570       aLastInd -= 3;
571
572       di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
573       di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
574
575       TheAISContext()->IsoOnPlane(isIsoOnPlane);
576
577       if (aLastInd == 0) {
578         // If there are no shapes provided set the default numbers.
579         TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
580         TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
581       }
582     }
583   }
584
585   Standard_Integer i;
586
587   for (i = 1; i <= aLastInd; i++) {
588     TCollection_AsciiString name(argv[i]);
589     Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
590
591     if (IsBound) {
592       const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
593       if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
594         const Handle(AIS_InteractiveObject) aShape =
595         Handle(AIS_InteractiveObject)::DownCast (anObj);
596         Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
597         Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
598         Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
599
600         if (isChanged) {
601           CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
602           CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
603           TheAISContext()->SetLocalAttributes
604                   (aShape, CurDrawer, Standard_False);
605           TheAISContext()->Redisplay(aShape);
606         } else {
607           di << "Number of isos for " << argv[i] << " : "
608              << aUIso->Number() << " " << aVIso->Number() << "\n";
609         }
610       } else {
611         di << argv[i] << ": Not an AIS interactive object!\n";
612       }
613     } else {
614       di << argv[i] << ": Use 'vdisplay' before\n";
615     }
616   }
617
618   if (isChanged) {
619     TheAISContext()->UpdateCurrentViewer();
620   }
621
622   return 0;
623 }
624
625 //==============================================================================
626 //function : VDispAreas,VDispSensitive,...
627 //purpose  :
628 //==============================================================================
629 static Standard_Integer VDispAreas (Draw_Interpretor& ,
630                                     Standard_Integer  theArgNb,
631                                     Standard_CString* )
632 {
633   if (theArgNb > 1)
634   {
635     std::cout << "Error: wrong syntax!\n";
636     return 1;
637   }
638
639   Handle(AIS_InteractiveContext) aCtx;
640   Handle(V3d_View)               aView;
641   if (!getCtxAndView (aCtx, aView))
642   {
643     return 1;
644   }
645
646   aCtx->DisplayActiveAreas (aView);
647   return 0;
648 }
649 static Standard_Integer VClearAreas (Draw_Interpretor& ,
650                                      Standard_Integer  theArgNb,
651                                      Standard_CString* )
652 {
653   if (theArgNb > 1)
654   {
655     std::cout << "Error: wrong syntax!\n";
656     return 1;
657   }
658
659   Handle(AIS_InteractiveContext) aCtx;
660   Handle(V3d_View)               aView;
661   if (!getCtxAndView (aCtx, aView))
662   {
663     return 1;
664   }
665
666   aCtx->ClearActiveAreas (aView);
667   return 0;
668
669 }
670 static Standard_Integer VDispSensi (Draw_Interpretor& ,
671                                     Standard_Integer  theArgNb,
672                                     Standard_CString* )
673 {
674   if (theArgNb > 1)
675   {
676     std::cout << "Error: wrong syntax!\n";
677     return 1;
678   }
679
680   Handle(AIS_InteractiveContext) aCtx;
681   Handle(V3d_View)               aView;
682   if (!getCtxAndView (aCtx, aView))
683   {
684     return 1;
685   }
686
687   aCtx->DisplayActiveSensitive (aView);
688   return 0;
689
690 }
691
692 static Standard_Integer VClearSensi (Draw_Interpretor& ,
693                                      Standard_Integer  theArgNb,
694                                      Standard_CString* )
695 {
696   if (theArgNb > 1)
697   {
698     std::cout << "Error: wrong syntax!\n";
699     return 1;
700   }
701
702   Handle(AIS_InteractiveContext) aCtx;
703   Handle(V3d_View)               aView;
704   if (!getCtxAndView (aCtx, aView))
705   {
706     return 1;
707   }
708   aCtx->ClearActiveSensitive (aView);
709   return 0;
710 }
711
712 //==============================================================================
713 //function : VDir
714 //purpose  : To list the displayed object with their attributes
715 //==============================================================================
716 static int VDir (Draw_Interpretor& theDI,
717                  Standard_Integer ,
718                  const char** )
719 {
720   if (!a3DView().IsNull())
721   {
722     return 0;
723   }
724
725   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
726        anIter.More(); anIter.Next())
727   {
728     theDI << "\t" << anIter.Key2().ToCString() << "\n";
729   }
730   return 0;
731 }
732
733 //==============================================================================
734 //function : VSelPrecision
735 //purpose  : To set the selection precision mode and tolerance value
736 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
737 //           value (integer number of pixel for window mode, double value of
738 //           sensitivity for view mode). Without arguments the function just
739 //           prints the current precision mode and the corresponding tolerance.
740 //==============================================================================
741 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
742 {
743   if( argc > 3 )
744   {
745     di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
746     return 1;
747   }
748
749   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
750   if( aContext.IsNull() )
751     return 1;
752
753   if( argc == 1 )
754   {
755     StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
756     if( aMode == StdSelect_SM_WINDOW )
757     {
758       Standard_Integer aPixelTolerance = aContext->PixelTolerance();
759       di << "Precision mode  : 0 (window)\n";
760       di << "Pixel tolerance : " << aPixelTolerance << "\n";
761     }
762     else if( aMode == StdSelect_SM_VIEW )
763     {
764       Standard_Real aSensitivity = aContext->Sensitivity();
765       di << "Precision mode : 1 (view)\n";
766       di << "Sensitivity    : " << aSensitivity << "\n";
767     }
768   }
769   else if( argc > 1 )
770   {
771     StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
772     aContext->SetSensitivityMode( aMode );
773     if( argc > 2 )
774     {
775       if( aMode == StdSelect_SM_WINDOW )
776       {
777         Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
778         aContext->SetPixelTolerance( aPixelTolerance );
779       }
780       else if( aMode == StdSelect_SM_VIEW )
781       {
782         Standard_Real aSensitivity = Draw::Atof( argv[2] );
783         aContext->SetSensitivity( aSensitivity );
784       }
785     }
786   }
787   return 0;
788 }
789
790 //==============================================================================
791 //function : VDump
792 //purpose  : To dump the active view snapshot to image file
793 //==============================================================================
794 static Standard_Integer VDump (Draw_Interpretor& theDI,
795                                Standard_Integer  theArgNb,
796                                Standard_CString* theArgVec)
797 {
798   if (theArgNb < 2)
799   {
800     std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
801     return 1;
802   }
803
804   Standard_Integer      anArgIter   = 1;
805   Standard_CString      aFilePath   = theArgVec[anArgIter++];
806   Graphic3d_BufferType  aBufferType = Graphic3d_BT_RGB;
807   V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
808   Standard_Integer      aWidth      = 0;
809   Standard_Integer      aHeight     = 0;
810   for (; anArgIter < theArgNb; ++anArgIter)
811   {
812     TCollection_AsciiString anArg (theArgVec[anArgIter]);
813     anArg.LowerCase();
814     if (anArg == "rgba")
815     {
816       aBufferType = Graphic3d_BT_RGBA;
817     }
818     else if (anArg == "rgb")
819     {
820       aBufferType = Graphic3d_BT_RGB;
821     }
822     else if (anArg == "depth")
823     {
824       aBufferType = Graphic3d_BT_Depth;
825     }
826     else if (anArg == "l"
827           || anArg == "left")
828     {
829       aStereoOpts = V3d_SDO_LEFT_EYE;
830     }
831     else if (anArg == "r"
832           || anArg == "right")
833     {
834       aStereoOpts = V3d_SDO_RIGHT_EYE;
835     }
836     else if (anArg == "mono")
837     {
838       aStereoOpts = V3d_SDO_MONO;
839     }
840     else if (anArg == "w"
841           || anArg == "width")
842     {
843       if (aWidth  != 0)
844       {
845         std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
846         return 1;
847       }
848       else if (++anArgIter >= theArgNb)
849       {
850         std::cout << "Error: integer value is expected right after 'width'\n";
851         return 1;
852       }
853       aWidth = Draw::Atoi (theArgVec[anArgIter]);
854     }
855     else if (anArg == "h"
856           || anArg == "height")
857     {
858       if (aHeight != 0)
859       {
860         std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
861         return 1;
862       }
863       if (++anArgIter >= theArgNb)
864       {
865         std::cout << "Error: integer value is expected right after 'height'\n";
866         return 1;
867       }
868       aHeight = Draw::Atoi (theArgVec[anArgIter]);
869     }
870     else if (anArg.IsIntegerValue())
871     {
872       // compatibility with old syntax
873       if (aWidth  != 0
874        || aHeight != 0)
875       {
876         std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
877         return 1;
878       }
879       else if (++anArgIter >= theArgNb)
880       {
881         std::cout << "Error: height value is expected right after width\n";
882         return 1;
883       }
884       aWidth  = Draw::Atoi (theArgVec[anArgIter - 1]);
885       aHeight = Draw::Atoi (theArgVec[anArgIter]);
886     }
887     else
888     {
889       std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
890       return 1;
891     }
892   }
893   if ((aWidth <= 0 && aHeight >  0)
894    || (aWidth >  0 && aHeight <= 0))
895   {
896     std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
897     return 1;
898   }
899
900   Handle(V3d_View) aView = ViewerTest::CurrentView();
901   if (aView.IsNull())
902   {
903     std::cout << "Error: cannot find an active view!\n";
904     return 1;
905   }
906
907   if (aWidth <= 0 || aHeight <= 0)
908   {
909     if (aStereoOpts != V3d_SDO_MONO)
910     {
911       aView->Window()->Size (aWidth, aHeight);
912     }
913     else
914     {
915       if (!aView->Dump (aFilePath, aBufferType))
916       {
917         theDI << "Fail: view dump failed!\n";
918       }
919       return 0;
920     }
921   }
922
923   Image_AlienPixMap aPixMap;
924   if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
925   {
926     theDI << "Fail: view dump failed!\n";
927     return 0;
928   }
929
930   if (aPixMap.SizeX() != Standard_Size(aWidth)
931    || aPixMap.SizeY() != Standard_Size(aHeight))
932   {
933     theDI << "Fail: dumped dimensions "    << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
934           << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
935   }
936   if (!aPixMap.Save (aFilePath))
937   {
938     theDI << "Fail: image can not be saved!\n";
939   }
940   return 0;
941 }
942
943
944 //==============================================================================
945 //function : Displays,Erase...
946 //purpose  :
947 //Draw arg :
948 //==============================================================================
949 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
950                             const Standard_Integer Mode,
951                             const Standard_Integer TypeOfOperation,
952                             const Standard_Boolean Upd)
953 {
954   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
955
956   switch(TypeOfOperation){
957   case 1:
958     Ctx->Display(IO,Mode,Upd);
959     break;
960   case 2:{
961     Ctx->Erase(IO,Upd);
962     break;
963   }
964   case 3:{
965     if(IO.IsNull())
966       Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
967     else
968       Ctx->SetDisplayMode(IO,Mode,Upd);
969     break;
970   }
971   case 4:{
972     if(IO.IsNull())
973       Ctx->SetDisplayMode(0,Upd);
974     else
975       Ctx->UnsetDisplayMode(IO,Upd);
976     break;
977   }
978   }
979   return 0;
980 }
981
982 //=======================================================================
983 //function :
984 //purpose  :
985 //=======================================================================
986 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
987 {
988
989   TCollection_AsciiString name;
990   if(argc>3)
991     return 1;
992   // display others presentations
993   Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
994     (strcasecmp(argv[0],"verasemode")==0) ? 2 :
995       (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
996         (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
997
998   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
999
1000   //unset displaymode.. comportement particulier...
1001   if(TypeOfOperation==4){
1002     if(argc==1){
1003       if(Ctx->NbCurrents()==0 ||
1004          Ctx->NbSelected()==0){
1005         Handle(AIS_InteractiveObject) IO;
1006         VwrTst_DispErase(IO,-1,4,Standard_False);
1007       }
1008       else if(!Ctx->HasOpenedContext()){
1009         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1010           VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1011       }
1012       else{
1013         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1014           VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1015       Ctx->UpdateCurrentViewer();
1016     }
1017     else{
1018       Handle(AIS_InteractiveObject) IO;
1019       name = argv[1];
1020       if(GetMapOfAIS().IsBound2(name)){
1021         IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1022         if (!IO.IsNull())
1023           VwrTst_DispErase(IO,-1,4,Standard_True);
1024       }
1025     }
1026   }
1027   else if(argc==2){
1028     Standard_Integer Dmode = Draw::Atoi(argv[1]);
1029     if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1030       Handle(AIS_InteractiveObject) IO;
1031       VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1032     }
1033     if(!Ctx->HasOpenedContext()){
1034       // set/unset display mode sur le Contexte...
1035       for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1036         VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1037       }
1038       Ctx->UpdateCurrentViewer();
1039     }
1040     else{
1041       for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1042         Ctx->Display(Ctx->Interactive(),Dmode);
1043     }
1044   }
1045   else{
1046     Handle(AIS_InteractiveObject) IO;
1047     name = argv[1];
1048     if(GetMapOfAIS().IsBound2(name))
1049       IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1050     if (!IO.IsNull())
1051       VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1052   }
1053   return 0;
1054 }
1055
1056
1057 //=======================================================================
1058 //function :
1059 //purpose  :
1060 //=======================================================================
1061 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1062 {
1063   if(argc==1) return 1;
1064   Standard_Integer On = Draw::Atoi(argv[1]);
1065   const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1066
1067   if(argc==2){
1068
1069     if(!Ctx->HasOpenedContext()){
1070       di<<"sub intensite ";
1071       if(On==1) di<<"On";
1072       else di<<"Off";
1073       di<<" pour "<<Ctx->NbCurrents()<<"  objets"<<"\n";
1074       for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1075         if(On==1){
1076           Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1077         else{
1078           di <<"passage dans off"<<"\n";
1079           Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1080         }
1081       }
1082     }
1083     else{
1084       for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1085         if(On==1){
1086           Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1087         else{
1088           Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1089       }
1090     }
1091     Ctx->UpdateCurrentViewer();
1092   }
1093   else {
1094     Handle(AIS_InteractiveObject) IO;
1095     TCollection_AsciiString name = argv[2];
1096     if(GetMapOfAIS().IsBound2(name)){
1097       IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1098       if (!IO.IsNull()) {
1099         if(On==1)
1100           Ctx->SubIntensityOn(IO);
1101         else
1102           Ctx->SubIntensityOff(IO);
1103       }
1104     }
1105     else return 1;
1106   }
1107   return 0;
1108 }
1109
1110 //! Auxiliary class to iterate presentations from different collections.
1111 class ViewTest_PrsIter
1112 {
1113 public:
1114
1115   //! Create and initialize iterator object.
1116   ViewTest_PrsIter (const TCollection_AsciiString& theName)
1117   : mySource (IterSource_All)
1118   {
1119     NCollection_Sequence<TCollection_AsciiString> aNames;
1120     if (!theName.IsEmpty())
1121     aNames.Append (theName);
1122     Init (aNames);
1123   }
1124
1125   //! Create and initialize iterator object.
1126   ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1127   : mySource (IterSource_All)
1128   {
1129     Init (theNames);
1130   }
1131
1132   //! Initialize the iterator.
1133   void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1134   {
1135     Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1136     mySeq = theNames;
1137     mySelIter.Nullify();
1138     myCurrent.Nullify();
1139     myCurrentTrs.Nullify();
1140     if (!mySeq.IsEmpty())
1141     {
1142       mySource = IterSource_List;
1143       mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1144     }
1145     else if (aCtx->NbCurrents() > 0)
1146     {
1147       mySource  = IterSource_Selected;
1148       mySelIter = aCtx;
1149       mySelIter->InitCurrent();
1150     }
1151     else
1152     {
1153       mySource = IterSource_All;
1154       myMapIter.Initialize (GetMapOfAIS());
1155     }
1156     initCurrent();
1157   }
1158
1159   const TCollection_AsciiString& CurrentName() const
1160   {
1161     return myCurrentName;
1162   }
1163
1164   const Handle(AIS_InteractiveObject)& Current() const
1165   {
1166     return myCurrent;
1167   }
1168
1169   const Handle(Standard_Transient)& CurrentTrs() const
1170   {
1171     return myCurrentTrs;
1172   }
1173
1174   //! @return true if iterator points to valid object within collection
1175   Standard_Boolean More() const
1176   {
1177     switch (mySource)
1178     {
1179       case IterSource_All:      return myMapIter.More();
1180       case IterSource_List:     return mySeqIter.More();
1181       case IterSource_Selected: return mySelIter->MoreCurrent();
1182     }
1183     return Standard_False;
1184   }
1185
1186   //! Go to the next item.
1187   void Next()
1188   {
1189     myCurrentName.Clear();
1190     myCurrentTrs.Nullify();
1191     myCurrent.Nullify();
1192     switch (mySource)
1193     {
1194       case IterSource_All:
1195       {
1196         myMapIter.Next();
1197         break;
1198       }
1199       case IterSource_List:
1200       {
1201         mySeqIter.Next();
1202         break;
1203       }
1204       case IterSource_Selected:
1205       {
1206         mySelIter->NextCurrent();
1207         break;
1208       }
1209     }
1210     initCurrent();
1211   }
1212
1213 private:
1214
1215   void initCurrent()
1216   {
1217     switch (mySource)
1218     {
1219       case IterSource_All:
1220       {
1221         if (myMapIter.More())
1222         {
1223           myCurrentName = myMapIter.Key2();
1224           myCurrentTrs  = myMapIter.Key1();
1225           myCurrent     = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1226         }
1227         break;
1228       }
1229       case IterSource_List:
1230       {
1231         if (mySeqIter.More())
1232         {
1233           if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1234           {
1235             std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1236             return;
1237           }
1238           myCurrentName = mySeqIter.Value();
1239           myCurrentTrs  = GetMapOfAIS().Find2 (mySeqIter.Value());
1240           myCurrent     = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1241         }
1242         break;
1243       }
1244       case IterSource_Selected:
1245       {
1246         if (mySelIter->MoreCurrent())
1247         {
1248           myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1249           myCurrent     = mySelIter->Current();
1250         }
1251         break;
1252       }
1253     }
1254   }
1255
1256 private:
1257
1258   enum IterSource
1259   {
1260     IterSource_All,
1261     IterSource_List,
1262     IterSource_Selected
1263   };
1264
1265 private:
1266
1267   Handle(AIS_InteractiveContext) mySelIter;    //!< iterator for current (selected) objects (IterSource_Selected)
1268   ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1269   NCollection_Sequence<TCollection_AsciiString>           mySeq;
1270   NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1271
1272   TCollection_AsciiString        myCurrentName;//!< current item name
1273   Handle(Standard_Transient)     myCurrentTrs; //!< current item (as transient object)
1274   Handle(AIS_InteractiveObject)  myCurrent;    //!< current item
1275
1276   IterSource                     mySource;     //!< iterated collection
1277
1278 };
1279
1280 //==============================================================================
1281 //function : VInteriorStyle
1282 //purpose  : sets interior style of the a selected or named or displayed shape
1283 //==============================================================================
1284 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1285                               Standard_Integer  theArgNb,
1286                               const char**      theArgVec)
1287 {
1288   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1289   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1290   if (aCtx.IsNull())
1291   {
1292     std::cerr << "Error: no active view!\n";
1293     return 1;
1294   }
1295
1296   Standard_Integer anArgIter = 1;
1297   for (; anArgIter < theArgNb; ++anArgIter)
1298   {
1299     if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1300     {
1301       break;
1302     }
1303   }
1304   TCollection_AsciiString aName;
1305   if (theArgNb - anArgIter == 2)
1306   {
1307     aName = theArgVec[anArgIter++];
1308   }
1309   else if (theArgNb - anArgIter != 1)
1310   {
1311     std::cout << "Error: wrong number of arguments! See usage:\n";
1312     theDI.PrintHelp (theArgVec[0]);
1313     return 1;
1314   }
1315   Standard_Integer        anInterStyle = Aspect_IS_SOLID;
1316   TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1317   aStyleArg.LowerCase();
1318   if (aStyleArg == "empty")
1319   {
1320     anInterStyle = 0;
1321   }
1322   else if (aStyleArg == "hollow")
1323   {
1324     anInterStyle = 1;
1325   }
1326   else if (aStyleArg == "hatch")
1327   {
1328     anInterStyle = 2;
1329   }
1330   else if (aStyleArg == "solid")
1331   {
1332     anInterStyle = 3;
1333   }
1334   else if (aStyleArg == "hiddenline")
1335   {
1336     anInterStyle = 4;
1337   }
1338   else
1339   {
1340     anInterStyle = aStyleArg.IntegerValue();
1341   }
1342   if (anInterStyle < Aspect_IS_EMPTY
1343    || anInterStyle > Aspect_IS_HIDDENLINE)
1344   {
1345     std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1346               << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1347     return 1;
1348   }
1349
1350   if (!aName.IsEmpty()
1351    && !GetMapOfAIS().IsBound2 (aName))
1352   {
1353     std::cout << "Error: object " << aName << " is not displayed!\n";
1354     return 1;
1355   }
1356
1357   if (aCtx->HasOpenedContext())
1358   {
1359     aCtx->CloseLocalContext();
1360   }
1361   for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1362   {
1363     const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1364     if (!anIO.IsNull())
1365     {
1366       const Handle(Prs3d_Drawer)& aDrawer        = anIO->Attributes();
1367       Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1368       Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1369       aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1370       aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1371     }
1372   }
1373   return 0;
1374 }
1375
1376 //! Auxiliary structure for VAspects
1377 struct ViewerTest_AspectsChangeSet
1378 {
1379   Standard_Integer         ToSetColor;
1380   Quantity_Color           Color;
1381
1382   Standard_Integer         ToSetLineWidth;
1383   Standard_Real            LineWidth;
1384
1385   Standard_Integer         ToSetTransparency;
1386   Standard_Real            Transparency;
1387
1388   Standard_Integer         ToSetMaterial;
1389   Graphic3d_NameOfMaterial Material;
1390   TCollection_AsciiString  MatName;
1391
1392   NCollection_Sequence<TopoDS_Shape> SubShapes;
1393
1394   //! Empty constructor
1395   ViewerTest_AspectsChangeSet()
1396   : ToSetColor        (0),
1397     Color             (DEFAULT_COLOR),
1398     ToSetLineWidth    (0),
1399     LineWidth         (1.0),
1400     ToSetTransparency (0),
1401     Transparency      (0.0),
1402     ToSetMaterial     (0),
1403     Material (Graphic3d_NOM_DEFAULT) {}
1404
1405   //! @return true if no changes have been requested
1406   Standard_Boolean IsEmpty() const
1407   {
1408     return ToSetLineWidth    == 0
1409         && ToSetTransparency == 0
1410         && ToSetColor        == 0
1411         && ToSetMaterial     == 0;
1412   }
1413
1414   //! @return true if properties are valid
1415   Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1416   {
1417     Standard_Boolean isOk = Standard_True;
1418     if (LineWidth <= 0.0
1419      || LineWidth >  10.0)
1420     {
1421       std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1422       isOk = Standard_False;
1423     }
1424     if (Transparency < 0.0
1425      || Transparency > 1.0)
1426     {
1427       std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1428       isOk = Standard_False;
1429     }
1430     if (theIsSubPart
1431      && ToSetTransparency)
1432     {
1433       std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1434       isOk = Standard_False;
1435     }
1436     if (ToSetMaterial == 1
1437      && Material == Graphic3d_NOM_DEFAULT)
1438     {
1439       std::cout << "Error: unknown material " << MatName << ".\n";
1440       isOk = Standard_False;
1441     }
1442     return isOk;
1443   }
1444
1445 };
1446
1447 //==============================================================================
1448 //function : VAspects
1449 //purpose  :
1450 //==============================================================================
1451 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1452                                   Standard_Integer  theArgNb,
1453                                   const char**      theArgVec)
1454 {
1455   TCollection_AsciiString aCmdName (theArgVec[0]);
1456   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1457   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1458   if (aCtx.IsNull())
1459   {
1460     std::cerr << "Error: no active view!\n";
1461     return 1;
1462   }
1463
1464   Standard_Integer anArgIter = 1;
1465   NCollection_Sequence<TCollection_AsciiString> aNames;
1466   for (; anArgIter < theArgNb; ++anArgIter)
1467   {
1468     TCollection_AsciiString anArg = theArgVec[anArgIter];
1469     if (anUpdateTool.parseRedrawMode (anArg))
1470     {
1471       continue;
1472     }
1473     else if (!anArg.IsEmpty()
1474            && anArg.Value (1) != '-')
1475     {
1476       aNames.Append (anArg);
1477     }
1478     else
1479     {
1480       break;
1481     }
1482   }
1483
1484   NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1485   aChanges.Append (ViewerTest_AspectsChangeSet());
1486   ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1487
1488   // parse syntax of legacy commands
1489   if (aCmdName == "vsetwidth")
1490   {
1491     if (aNames.IsEmpty()
1492     || !aNames.Last().IsRealValue())
1493     {
1494       std::cout << "Error: not enough arguments!\n";
1495       return 1;
1496     }
1497     aChangeSet->ToSetLineWidth = 1;
1498     aChangeSet->LineWidth = aNames.Last().RealValue();
1499     aNames.Remove (aNames.Length());
1500   }
1501   else if (aCmdName == "vunsetwidth")
1502   {
1503     aChangeSet->ToSetLineWidth = -1;
1504   }
1505   else if (aCmdName == "vsetcolor")
1506   {
1507     if (aNames.IsEmpty())
1508     {
1509       std::cout << "Error: not enough arguments!\n";
1510       return 1;
1511     }
1512     aChangeSet->ToSetColor = 1;
1513     aChangeSet->Color  = ViewerTest::GetColorFromName (aNames.Last().ToCString());
1514     aNames.Remove (aNames.Length());
1515   }
1516   else if (aCmdName == "vunsetcolor")
1517   {
1518     aChangeSet->ToSetColor = -1;
1519   }
1520   else if (aCmdName == "vsettransparency")
1521   {
1522     if (aNames.IsEmpty()
1523     || !aNames.Last().IsRealValue())
1524     {
1525       std::cout << "Error: not enough arguments!\n";
1526       return 1;
1527     }
1528     aChangeSet->ToSetTransparency = 1;
1529     aChangeSet->Transparency  = aNames.Last().RealValue();
1530     aNames.Remove (aNames.Length());
1531   }
1532   else if (aCmdName == "vunsettransparency")
1533   {
1534     aChangeSet->ToSetTransparency = -1;
1535   }
1536   else if (aCmdName == "vsetmaterial")
1537   {
1538     if (aNames.IsEmpty())
1539     {
1540       std::cout << "Error: not enough arguments!\n";
1541       return 1;
1542     }
1543     aChangeSet->ToSetMaterial = 1;
1544     aChangeSet->MatName  = aNames.Last();
1545     aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1546     aNames.Remove (aNames.Length());
1547   }
1548   else if (aCmdName == "vunsetmaterial")
1549   {
1550     aChangeSet->ToSetMaterial = -1;
1551   }
1552   else if (anArgIter >= theArgNb)
1553   {
1554     std::cout << "Error: not enough arguments!\n";
1555     return 1;
1556   }
1557
1558   if (!aChangeSet->IsEmpty())
1559   {
1560     anArgIter = theArgNb;
1561   }
1562   for (; anArgIter < theArgNb; ++anArgIter)
1563   {
1564     TCollection_AsciiString anArg = theArgVec[anArgIter];
1565     anArg.LowerCase();
1566     if (anArg == "-setwidth"
1567      || anArg == "-setlinewidth")
1568     {
1569       if (++anArgIter >= theArgNb)
1570       {
1571         std::cout << "Error: wrong syntax at " << anArg << "\n";
1572         return 1;
1573       }
1574       aChangeSet->ToSetLineWidth = 1;
1575       aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1576     }
1577     else if (anArg == "-unsetwidth"
1578           || anArg == "-unsetlinewidth")
1579     {
1580       aChangeSet->ToSetLineWidth = -1;
1581       aChangeSet->LineWidth = 1.0;
1582     }
1583     else if (anArg == "-settransp"
1584           || anArg == "-settransparency")
1585     {
1586       if (++anArgIter >= theArgNb)
1587       {
1588         std::cout << "Error: wrong syntax at " << anArg << "\n";
1589         return 1;
1590       }
1591       aChangeSet->ToSetTransparency = 1;
1592       aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1593       if (aChangeSet->Transparency >= 0.0
1594        && aChangeSet->Transparency <= Precision::Confusion())
1595       {
1596         aChangeSet->ToSetTransparency = -1;
1597         aChangeSet->Transparency = 0.0;
1598       }
1599     }
1600     else if (anArg == "-setalpha")
1601     {
1602       if (++anArgIter >= theArgNb)
1603       {
1604         std::cout << "Error: wrong syntax at " << anArg << "\n";
1605         return 1;
1606       }
1607       aChangeSet->ToSetTransparency = 1;
1608       aChangeSet->Transparency  = Draw::Atof (theArgVec[anArgIter]);
1609       if (aChangeSet->Transparency < 0.0
1610        || aChangeSet->Transparency > 1.0)
1611       {
1612         std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1613         return 1;
1614       }
1615       aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1616       if (aChangeSet->Transparency >= 0.0
1617        && aChangeSet->Transparency <= Precision::Confusion())
1618       {
1619         aChangeSet->ToSetTransparency = -1;
1620         aChangeSet->Transparency = 0.0;
1621       }
1622     }
1623     else if (anArg == "-unsettransp"
1624           || anArg == "-unsettransparency"
1625           || anArg == "-unsetalpha"
1626           || anArg == "-opaque")
1627     {
1628       aChangeSet->ToSetTransparency = -1;
1629       aChangeSet->Transparency = 0.0;
1630     }
1631     else if (anArg == "-setcolor")
1632     {
1633       if (++anArgIter >= theArgNb)
1634       {
1635         std::cout << "Error: wrong syntax at " << anArg << "\n";
1636         return 1;
1637       }
1638       aChangeSet->ToSetColor = 1;
1639       aChangeSet->Color = ViewerTest::GetColorFromName (theArgVec[anArgIter]);
1640     }
1641     else if (anArg == "-unsetcolor")
1642     {
1643       aChangeSet->ToSetColor = -1;
1644       aChangeSet->Color = DEFAULT_COLOR;
1645     }
1646     else if (anArg == "-setmat"
1647           || anArg == "-setmaterial")
1648     {
1649       if (++anArgIter >= theArgNb)
1650       {
1651         std::cout << "Error: wrong syntax at " << anArg << "\n";
1652         return 1;
1653       }
1654       aChangeSet->ToSetMaterial = 1;
1655       aChangeSet->MatName  = theArgVec[anArgIter];
1656       aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1657     }
1658     else if (anArg == "-unsetmat"
1659           || anArg == "-unsetmaterial")
1660     {
1661       aChangeSet->ToSetMaterial = -1;
1662       aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1663     }
1664     else if (anArg == "-subshape"
1665           || anArg == "-subshapes")
1666     {
1667       if (aNames.IsEmpty())
1668       {
1669         std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1670         return 1;
1671       }
1672
1673       aChanges.Append (ViewerTest_AspectsChangeSet());
1674       aChangeSet = &aChanges.ChangeLast();
1675
1676       for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1677       {
1678         Standard_CString aSubShapeName = theArgVec[anArgIter];
1679         if (*aSubShapeName == '-')
1680         {
1681           --anArgIter;
1682           break;
1683         }
1684
1685         TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1686         if (aSubShape.IsNull())
1687         {
1688           std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1689           return 1;
1690         }
1691         aChangeSet->SubShapes.Append (aSubShape);
1692       }
1693
1694       if (aChangeSet->SubShapes.IsEmpty())
1695       {
1696         std::cerr << "Error: empty list is specified after -subshapes!\n";
1697         return 1;
1698       }
1699     }
1700     else if (anArg == "-unset")
1701     {
1702       aChangeSet->ToSetLineWidth = -1;
1703       aChangeSet->LineWidth = 1.0;
1704       aChangeSet->ToSetTransparency = -1;
1705       aChangeSet->Transparency = 0.0;
1706       aChangeSet->ToSetColor = -1;
1707       aChangeSet->Color = DEFAULT_COLOR;
1708       aChangeSet->ToSetMaterial = -1;
1709       aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1710     }
1711     else
1712     {
1713       std::cout << "Error: wrong syntax at " << anArg << "\n";
1714       return 1;
1715     }
1716   }
1717
1718   Standard_Boolean isFirst = Standard_True;
1719   for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1720        aChangesIter.More(); aChangesIter.Next())
1721   {
1722     if (!aChangesIter.Value().Validate (!isFirst))
1723     {
1724       return 1;
1725     }
1726     isFirst = Standard_False;
1727   }
1728
1729   if (aCtx->HasOpenedContext())
1730   {
1731     aCtx->CloseLocalContext();
1732   }
1733   for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
1734   {
1735     const TCollection_AsciiString& aName = aPrsIter.CurrentName();
1736     Handle(AIS_InteractiveObject)  aPrs  = aPrsIter.Current();
1737     Handle(AIS_ColoredShape) aColoredPrs;
1738     Standard_Boolean toDisplay = Standard_False;
1739     if (aChanges.Length() > 1)
1740     {
1741       Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
1742       if (aShapePrs.IsNull())
1743       {
1744         std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
1745         return 1;
1746       }
1747       aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
1748       if (aColoredPrs.IsNull())
1749       {
1750         aColoredPrs = new AIS_ColoredShape (aShapePrs);
1751         aCtx->Remove (aShapePrs, Standard_False);
1752         GetMapOfAIS().UnBind2 (aName);
1753         GetMapOfAIS().Bind (aColoredPrs, aName);
1754         toDisplay = Standard_True;
1755         aShapePrs = aColoredPrs;
1756         aPrs      = aColoredPrs;
1757       }
1758     }
1759
1760     if (!aPrs.IsNull())
1761     {
1762       NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1763       aChangeSet = &aChangesIter.ChangeValue();
1764       if (aChangeSet->ToSetMaterial == 1)
1765       {
1766         aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
1767       }
1768       else if (aChangeSet->ToSetMaterial == -1)
1769       {
1770         aCtx->UnsetMaterial (aPrs, Standard_False);
1771       }
1772       if (aChangeSet->ToSetColor == 1)
1773       {
1774         aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
1775       }
1776       else if (aChangeSet->ToSetColor == -1)
1777       {
1778         aCtx->UnsetColor (aPrs, Standard_False);
1779       }
1780       if (aChangeSet->ToSetTransparency == 1)
1781       {
1782         aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
1783       }
1784       else if (aChangeSet->ToSetTransparency == -1)
1785       {
1786         aCtx->UnsetTransparency (aPrs, Standard_False);
1787       }
1788       if (aChangeSet->ToSetLineWidth == 1)
1789       {
1790         aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
1791       }
1792       else if (aChangeSet->ToSetLineWidth == -1)
1793       {
1794         aCtx->UnsetWidth (aPrs, Standard_False);
1795       }
1796
1797       for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
1798       {
1799         aChangeSet = &aChangesIter.ChangeValue();
1800         for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
1801              aSubShapeIter.More(); aSubShapeIter.Next())
1802         {
1803           const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
1804           if (aChangeSet->ToSetColor == 1)
1805           {
1806             aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
1807           }
1808           if (aChangeSet->ToSetLineWidth == 1)
1809           {
1810             aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
1811           }
1812           if (aChangeSet->ToSetColor     == -1
1813            || aChangeSet->ToSetLineWidth == -1)
1814           {
1815             aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
1816           }
1817         }
1818       }
1819       if (toDisplay)
1820       {
1821         aCtx->Display (aPrs, Standard_False);
1822       }
1823       else if (!aColoredPrs.IsNull())
1824       {
1825         aColoredPrs->Redisplay();
1826       }
1827     }
1828     else
1829     {
1830       Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
1831       Handle(NIS_Triangulated)      aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
1832       if (!aNisObj.IsNull())
1833       {
1834         if (aChangeSet->ToSetTransparency != 0)
1835         {
1836           aNisObj->SetTransparency (aChangeSet->Transparency);
1837         }
1838       }
1839       if (!aNisTri.IsNull())
1840       {
1841         if (aChangeSet->ToSetColor != 0)
1842         {
1843           aNisTri->SetColor (aChangeSet->Color);
1844         }
1845         if (aChangeSet->ToSetLineWidth != 0)
1846         {
1847           aNisTri->SetLineWidth (aChangeSet->LineWidth);
1848         }
1849       }
1850     }
1851   }
1852   return 0;
1853 }
1854
1855 //==============================================================================
1856 //function : VDonly2
1857 //author   : ege
1858 //purpose  : Display only a selected or named  object
1859 //           if there is no selected or named object s, nothing is done
1860 //==============================================================================
1861 static int VDonly2 (Draw_Interpretor& ,
1862                     Standard_Integer  theArgNb,
1863                     const char**      theArgVec)
1864 {
1865   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1866   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1867   if (aCtx.IsNull())
1868   {
1869     std::cerr << "Error: no active view!\n";
1870     return 1;
1871   }
1872
1873   if (aCtx->HasOpenedContext())
1874   {
1875     aCtx->CloseLocalContext();
1876   }
1877
1878   Standard_Integer anArgIter = 1;
1879   for (; anArgIter < theArgNb; ++anArgIter)
1880   {
1881     if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1882     {
1883       break;
1884     }
1885   }
1886
1887   NCollection_Map<Handle(Standard_Transient)> aDispSet;
1888   if (anArgIter >= theArgNb)
1889   {
1890     // display only selected objects
1891     if (aCtx->NbCurrents() < 1)
1892     {
1893       return 0;
1894     }
1895
1896     for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
1897     {
1898       aDispSet.Add (aCtx->Current());
1899     }
1900   }
1901   else
1902   {
1903     // display only specified objects
1904     for (; anArgIter < theArgNb; ++anArgIter)
1905     {
1906       TCollection_AsciiString aName = theArgVec[anArgIter];
1907       if (GetMapOfAIS().IsBound2 (aName))
1908       {
1909         const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1910         if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1911         {
1912           const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
1913           aCtx->Display (aShape, Standard_False);
1914         }
1915         else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1916         {
1917           Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
1918           TheNISContext()->Display (aShape);
1919         }
1920         aDispSet.Add (anObj);
1921       }
1922     }
1923   }
1924
1925   // weed out other objects
1926   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
1927   {
1928     if (aDispSet.Contains (anIter.Key1()))
1929     {
1930       continue;
1931     }
1932
1933     if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1934     {
1935       const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1936       aCtx->Erase (aShape, Standard_False);
1937     }
1938     else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1939     {
1940       const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1941       TheNISContext()->Erase (aShape);
1942     }
1943   }
1944   return 0;
1945 }
1946
1947 //==============================================================================
1948 //function : VRemove
1949 //purpose  : Removes selected or named objects.
1950 //           If there is no selected or named objects,
1951 //           all objects in the viewer can be removed with argument -all.
1952 //           If -context is in arguments, the object is not deleted from the map of
1953 //           objects (deleted only from the current context).
1954 //==============================================================================
1955 int VRemove (Draw_Interpretor& theDI,
1956              Standard_Integer  theArgNb,
1957              const char**      theArgVec)
1958 {
1959   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1960   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1961   if (aCtx.IsNull())
1962   {
1963     std::cout << "Error: no active view!\n";
1964     return 1;
1965   }
1966
1967   aCtx->CloseAllContexts (Standard_False);
1968
1969   Standard_Boolean isContextOnly = Standard_False;
1970   Standard_Boolean toRemoveAll   = Standard_False;
1971   Standard_Boolean toPrintInfo   = Standard_True;
1972
1973   Standard_Integer anArgIter = 1;
1974   for (; anArgIter < theArgNb; ++anArgIter)
1975   {
1976     TCollection_AsciiString anArg = theArgVec[anArgIter];
1977     anArg.LowerCase();
1978     if (anArg == "-context")
1979     {
1980       isContextOnly = Standard_True;
1981     }
1982     else if (anArg == "-all")
1983     {
1984       toRemoveAll = Standard_True;
1985     }
1986     else if (anArg == "-noinfo")
1987     {
1988       toPrintInfo = Standard_False;
1989     }
1990     else if (!anUpdateTool.parseRedrawMode (anArg))
1991     {
1992       break;
1993     }
1994   }
1995   if (toRemoveAll
1996    && anArgIter < theArgNb)
1997   {
1998     std::cout << "Error: wrong syntax!\n";
1999     return 1;
2000   }
2001
2002   NCollection_List<TCollection_AsciiString> anIONameList;
2003   if (toRemoveAll)
2004   {
2005     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2006          anIter.More(); anIter.Next())
2007     {
2008       anIONameList.Append (anIter.Key2());
2009     }
2010   }
2011   else if (anArgIter < theArgNb) // removed objects names are in argument list
2012   {
2013     for (; anArgIter < theArgNb; ++anArgIter)
2014     {
2015       TCollection_AsciiString aName = theArgVec[anArgIter];
2016       if (!GetMapOfAIS().IsBound2 (aName))
2017       {
2018         theDI << aName.ToCString() << " was not bound to some object.\n";
2019         continue;
2020       }
2021
2022       const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2023
2024       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2025       if (!anIO.IsNull())
2026       {
2027         if (anIO->GetContext() != aCtx)
2028         {
2029           theDI << aName.ToCString() << " was not displayed in current context.\n";
2030           theDI << "Please activate view with this object displayed and try again.\n";
2031           continue;
2032         }
2033
2034         anIONameList.Append (aName);
2035         continue;
2036       }
2037
2038       const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2039       if (!aNisIO.IsNull())
2040       {
2041         anIONameList.Append (aName);
2042       }
2043     }
2044   }
2045   else if (aCtx->NbCurrents() > 0
2046         || TheNISContext()->GetSelected().Extent() > 0)
2047   {
2048     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2049          anIter.More(); anIter.Next())
2050     {
2051       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2052       if (!anIO.IsNull())
2053       {
2054         if (!aCtx->IsCurrent (anIO))
2055         {
2056           continue;
2057         }
2058
2059         anIONameList.Append (anIter.Key2());
2060         continue;
2061       }
2062
2063       const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2064       if (!aNisIO.IsNull())
2065       {
2066         if (!TheNISContext()->IsSelected (aNisIO))
2067         {
2068           continue;
2069         }
2070
2071         anIONameList.Append (anIter.Key2());
2072       }
2073     }
2074   }
2075
2076   // Unbind all removed objects from the map of displayed IO.
2077   for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2078        anIter.More(); anIter.Next())
2079   {
2080     const Handle(AIS_InteractiveObject) anIO  = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2081     if (!anIO.IsNull())
2082     {
2083       aCtx->Remove (anIO, Standard_False);
2084       if (toPrintInfo)
2085       {
2086         theDI << anIter.Value().ToCString() << " was removed\n";
2087       }
2088     }
2089     else
2090     {
2091       const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2092       if (!aNisIO.IsNull())
2093       {
2094         TheNISContext()->Remove (aNisIO);
2095         if (toPrintInfo)
2096         {
2097           theDI << anIter.Value().ToCString() << " was removed\n";
2098         }
2099       }
2100     }
2101     if (!isContextOnly)
2102     {
2103       GetMapOfAIS().UnBind2 (anIter.Value());
2104     }
2105   }
2106   return 0;
2107 }
2108
2109 //==============================================================================
2110 //function : VErase
2111 //purpose  : Erase some selected or named objects
2112 //           if there is no selected or named objects, the whole viewer is erased
2113 //==============================================================================
2114 int VErase (Draw_Interpretor& theDI,
2115             Standard_Integer  theArgNb,
2116             const char**      theArgVec)
2117 {
2118   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2119   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2120   if (aCtx.IsNull())
2121   {
2122     std::cout << "Error: no active view!\n";
2123     return 1;
2124   }
2125   aCtx->CloseAllContexts (Standard_False);
2126
2127   const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2128
2129   Standard_Integer anArgIter = 1;
2130   for (; anArgIter < theArgNb; ++anArgIter)
2131   {
2132     if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2133     {
2134       break;
2135     }
2136   }
2137
2138   if (anArgIter < theArgNb)
2139   {
2140     if (toEraseAll)
2141     {
2142       std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2143       return 1;
2144     }
2145
2146     // has a list of names
2147     for (; anArgIter < theArgNb; ++anArgIter)
2148     {
2149       TCollection_AsciiString aName = theArgVec[anArgIter];
2150       if (!GetMapOfAIS().IsBound2 (aName))
2151       {
2152         continue;
2153       }
2154
2155       const Handle(Standard_Transient)    anObj = GetMapOfAIS().Find2 (aName);
2156       const Handle(AIS_InteractiveObject) anIO  = Handle(AIS_InteractiveObject)::DownCast (anObj);
2157       theDI << aName.ToCString() << " ";
2158       if (!anIO.IsNull())
2159       {
2160         aCtx->Erase (anIO, Standard_False);
2161       }
2162       else
2163       {
2164         const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2165         if (!aNisIO.IsNull())
2166         {
2167           TheNISContext()->Erase (aNisIO);
2168         }
2169       }
2170     }
2171   }
2172   else if (!toEraseAll
2173         && aCtx->NbCurrents() > 0)
2174   {
2175     // remove all currently selected objects
2176     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2177          anIter.More(); anIter.Next())
2178     {
2179       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2180       if (!anIO.IsNull()
2181        && aCtx->IsCurrent (anIO))
2182       {
2183         theDI << anIter.Key2().ToCString() << " ";
2184         aCtx->Erase (anIO, Standard_False);
2185       }
2186     }
2187   }
2188   else
2189   {
2190     // erase entire viewer
2191     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2192          anIter.More(); anIter.Next())
2193     {
2194       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2195       if (!anIO.IsNull())
2196       {
2197         aCtx->Erase (anIO, Standard_False);
2198       }
2199       else
2200       {
2201         const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2202         if (!aNisIO.IsNull())
2203         {
2204           TheNISContext()->Erase (aNisIO);
2205         }
2206       }
2207     }
2208   }
2209   return 0;
2210 }
2211
2212 //==============================================================================
2213 //function : VDisplayAll
2214 //author   : ege
2215 //purpose  : Display all the objects of the Map
2216 //==============================================================================
2217 static int VDisplayAll (Draw_Interpretor& ,
2218                         Standard_Integer  theArgNb,
2219                         const char**      theArgVec)
2220
2221 {
2222   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2223   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2224   if (aCtx.IsNull())
2225   {
2226     std::cout << "Error: no active view!\n";
2227     return 1;
2228   }
2229
2230   Standard_Integer anArgIter = 1;
2231   for (; anArgIter < theArgNb; ++anArgIter)
2232   {
2233     if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2234     {
2235       break;
2236     }
2237   }
2238   if (anArgIter < theArgNb)
2239   {
2240     std::cout << theArgVec[0] << "Error: wrong syntax\n";
2241     return 1;
2242   }
2243
2244   if (aCtx->HasOpenedContext())
2245   {
2246     aCtx->CloseLocalContext();
2247   }
2248
2249   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2250        anIter.More(); anIter.Next())
2251   {
2252     if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2253     {
2254       const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2255       aCtx->Erase (aShape, Standard_False);
2256     }
2257     else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2258     {
2259       const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2260       TheNISContext()->Erase (aShape);
2261     }
2262   }
2263
2264   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2265        anIter.More(); anIter.Next())
2266   {
2267     if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2268     {
2269       const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2270       aCtx->Display (aShape, Standard_False);
2271     }
2272     else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2273     {
2274       Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2275       TheNISContext()->Display (aShape);
2276     }
2277   }
2278   return 0;
2279 }
2280
2281 //! Auxiliary method to find presentation
2282 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2283                                                      const Handle(AIS_InteractiveObject)&  theIO,
2284                                                      const Standard_Integer                theMode)
2285 {
2286   if (theIO.IsNull())
2287   {
2288     return Handle(PrsMgr_Presentation)();
2289   }
2290
2291   if (theMode != -1)
2292   {
2293     if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2294     {
2295       return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2296     }
2297   }
2298   else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2299   {
2300     return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2301   }
2302   else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2303   {
2304     return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2305   }
2306   return Handle(PrsMgr_Presentation)();
2307 }
2308
2309 enum ViewerTest_BndAction
2310 {
2311   BndAction_Hide,
2312   BndAction_Show,
2313   BndAction_Print
2314 };
2315
2316 //! Auxiliary method to print bounding box of presentation
2317 inline void bndPresentation (Draw_Interpretor&                  theDI,
2318                              const Handle(PrsMgr_Presentation)& thePrs,
2319                              const TCollection_AsciiString&     theName,
2320                              const ViewerTest_BndAction         theAction)
2321 {
2322   switch (theAction)
2323   {
2324     case BndAction_Hide:
2325     {
2326       thePrs->Presentation()->GraphicUnHighlight();
2327       break;
2328     }
2329     case BndAction_Show:
2330     {
2331       thePrs->Presentation()->BoundBox();
2332       break;
2333     }
2334     case BndAction_Print:
2335     {
2336       Graphic3d_Vec3d aMin, aMax;
2337       thePrs->Presentation()->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
2338                                             aMax.x(), aMax.y(), aMax.z());
2339       theDI << theName  << "\n"
2340             << aMin.x() << " " << aMin.y() << " " << aMin.z() << " "
2341             << aMax.x() << " " << aMax.y() << " " << aMax.z() << "\n";
2342       break;
2343     }
2344   }
2345 }
2346
2347 //==============================================================================
2348 //function : VBounding
2349 //purpose  :
2350 //==============================================================================
2351 int VBounding (Draw_Interpretor& theDI,
2352                Standard_Integer  theArgNb,
2353                const char**      theArgVec)
2354 {
2355   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2356   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2357   if (aCtx.IsNull())
2358   {
2359     std::cout << "Error: no active view!\n";
2360     return 1;
2361   }
2362
2363   ViewerTest_BndAction anAction = BndAction_Show;
2364   Standard_Integer     aMode    = -1;
2365
2366   Standard_Integer anArgIter = 1;
2367   for (; anArgIter < theArgNb; ++anArgIter)
2368   {
2369     TCollection_AsciiString anArg (theArgVec[anArgIter]);
2370     anArg.LowerCase();
2371     if (anArg == "-print")
2372     {
2373       anAction = BndAction_Print;
2374     }
2375     else if (anArg == "-show")
2376     {
2377       anAction = BndAction_Show;
2378     }
2379     else if (anArg == "-hide")
2380     {
2381       anAction = BndAction_Hide;
2382     }
2383     else if (anArg == "-mode")
2384     {
2385       if (++anArgIter >= theArgNb)
2386       {
2387         std::cout << "Error: wrong syntax at " << anArg << "\n";
2388         return 1;
2389       }
2390       aMode = Draw::Atoi (theArgVec[anArgIter]);
2391     }
2392     else if (!anUpdateTool.parseRedrawMode (anArg))
2393     {
2394       break;
2395     }
2396   }
2397
2398   if (anArgIter < theArgNb)
2399   {
2400     // has a list of names
2401     for (; anArgIter < theArgNb; ++anArgIter)
2402     {
2403       TCollection_AsciiString aName = theArgVec[anArgIter];
2404       if (!GetMapOfAIS().IsBound2 (aName))
2405       {
2406         std::cout << "Error: presentation " << aName << " does not exist\n";
2407         return 1;
2408       }
2409
2410       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2411       Handle(PrsMgr_Presentation)   aPrs = findPresentation (aCtx, anIO, aMode);
2412       if (aPrs.IsNull())
2413       {
2414         std::cout << "Error: presentation " << aName << " does not exist\n";
2415         return 1;
2416       }
2417       bndPresentation (theDI, aPrs, aName, anAction);
2418     }
2419   }
2420   else if (aCtx->NbCurrents() > 0)
2421   {
2422     // remove all currently selected objects
2423     for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2424     {
2425       Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2426       Handle(PrsMgr_Presentation)   aPrs = findPresentation (aCtx, anIO, aMode);
2427       if (!aPrs.IsNull())
2428       {
2429         bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2430       }
2431     }
2432   }
2433   else
2434   {
2435     // all objects
2436     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2437          anIter.More(); anIter.Next())
2438     {
2439       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2440       Handle(PrsMgr_Presentation)   aPrs = findPresentation (aCtx, anIO, aMode);
2441       if (!aPrs.IsNull())
2442       {
2443         bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2444       }
2445     }
2446   }
2447   return 0;
2448 }
2449
2450 //==============================================================================
2451 //function : VTexture
2452 //purpose  :
2453 //==============================================================================
2454 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2455 {
2456   TCollection_AsciiString aCommandName (theArgv[0]);
2457
2458   NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
2459   if (aCommandName == "vtexture")
2460   {
2461     if (theArgsNb < 2)
2462     {
2463       std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2464       std::cout << "Type help for more information.\n";
2465       return 1;
2466     }
2467
2468     // look for options of vtexture command
2469     TCollection_AsciiString aParseKey;
2470     for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2471     {
2472       TCollection_AsciiString anArg (theArgv [anArgIt]);
2473
2474       anArg.UpperCase();
2475       if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2476       {
2477         aParseKey = anArg;
2478         aParseKey.Remove (1);
2479         aParseKey.UpperCase();
2480         aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
2481         continue;
2482       }
2483
2484       if (aParseKey.IsEmpty())
2485       {
2486         continue;
2487       }
2488
2489       aMapOfArgs(aParseKey)->Append (anArg);
2490     }
2491   }
2492   else if (aCommandName == "vtexscale"
2493         || aCommandName == "vtexorigin"
2494         || aCommandName == "vtexrepeat")
2495   {
2496     // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2497     // equal to -scale, -origin, -repeat options of vtexture command
2498     if (theArgsNb < 2 || theArgsNb > 4)
2499     {
2500       std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2501       std::cout << "Type help for more information.\n";
2502       return 1;
2503     }
2504
2505     Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
2506     if (theArgsNb == 2)
2507     {
2508       anArgs->Append ("OFF");
2509     }
2510     else if (theArgsNb == 4)
2511     {
2512       anArgs->Append (TCollection_AsciiString (theArgv[2]));
2513       anArgs->Append (TCollection_AsciiString (theArgv[3]));
2514     }
2515
2516     TCollection_AsciiString anArgKey;
2517     if (aCommandName == "vtexscale")
2518     {
2519       anArgKey = "SCALE";
2520     }
2521     else if (aCommandName == "vtexorigin")
2522     {
2523       anArgKey = "ORIGIN";
2524     }
2525     else
2526     {
2527       anArgKey = "REPEAT";
2528     }
2529
2530     aMapOfArgs.Bind (anArgKey, anArgs);
2531   }
2532   else if (aCommandName == "vtexdefault")
2533   {
2534     // scan for parameters of vtexdefault command
2535     // equal to -default option of vtexture command
2536     aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
2537   }
2538
2539   // Check arguments for validity
2540   NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
2541   for (; aMapIt.More(); aMapIt.Next())
2542   {
2543     const TCollection_AsciiString& aKey = aMapIt.Key();
2544     const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
2545
2546     // -scale, -origin, -repeat: one argument "off", or two real values
2547     if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
2548       && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2549        || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
2550     {
2551       continue;
2552     }
2553
2554     // -modulate: single argument "on" / "off"
2555     if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
2556     {
2557       continue;
2558     }
2559
2560     // -default: no arguments
2561     if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
2562     {
2563       continue;
2564     }
2565
2566     TCollection_AsciiString aLowerKey;
2567     aLowerKey  = "-";
2568     aLowerKey += aKey;
2569     aLowerKey.LowerCase();
2570     std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
2571     std::cout << "Type help for more information.\n";
2572     return 1;
2573   }
2574
2575   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
2576   if (anAISContext.IsNull())
2577   {
2578     std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
2579     return 1;
2580   }
2581
2582   Standard_Integer aPreviousMode = 0;
2583
2584   ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
2585
2586   TCollection_AsciiString aShapeName (theArgv[1]);
2587   Handle(AIS_InteractiveObject) anIO;
2588
2589   const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
2590   if (aMapOfIO.IsBound2 (aShapeName))
2591   {
2592     anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
2593   }
2594
2595   if (anIO.IsNull())
2596   {
2597     std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
2598     return 1;
2599   }
2600
2601   Handle(AIS_TexturedShape) aTexturedIO;
2602   if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
2603   {
2604     aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
2605     aPreviousMode = aTexturedIO->DisplayMode();
2606   }
2607   else
2608   {
2609     anAISContext->Clear (anIO, Standard_False);
2610     aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
2611     GetMapOfAIS().UnBind1 (anIO);
2612     GetMapOfAIS().UnBind2 (aShapeName);
2613     GetMapOfAIS().Bind (aTexturedIO, aShapeName);
2614   }
2615
2616   // -------------------------------------------
2617   //  Turn texturing on/off - only for vtexture
2618   // -------------------------------------------
2619
2620   if (aCommandName == "vtexture")
2621   {
2622     TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
2623
2624     if (aTextureArg.IsEmpty())
2625     {
2626       std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
2627       std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
2628
2629       anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
2630       if (aPreviousMode == 3)
2631       {
2632         anAISContext->RecomputePrsOnly (aTexturedIO);
2633       }
2634
2635       anAISContext->Display (aTexturedIO, Standard_True);
2636       return 0;
2637     }
2638     else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
2639     {
2640       if (aTextureArg == "?")
2641       {
2642         TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
2643
2644         theDi << "\n Files in current directory : \n" << "\n";
2645         theDi.Eval ("glob -nocomplain *");
2646
2647         TCollection_AsciiString aCmnd ("glob -nocomplain ");
2648         aCmnd += aTextureFolder;
2649         aCmnd += "/* ";
2650
2651         theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
2652         theDi.Eval (aCmnd.ToCString());
2653         return 0;
2654       }
2655       else
2656       {
2657         aTexturedIO->SetTextureFileName (aTextureArg);
2658       }
2659     }
2660   }
2661
2662   // ------------------------------------
2663   //  Process other options and commands
2664   // ------------------------------------
2665
2666   Handle(TColStd_HSequenceOfAsciiString) aValues;
2667   if (aMapOfArgs.Find ("DEFAULT", aValues))
2668   {
2669     aTexturedIO->SetTextureRepeat (Standard_False);
2670     aTexturedIO->SetTextureOrigin (Standard_False);
2671     aTexturedIO->SetTextureScale  (Standard_False);
2672     aTexturedIO->EnableTextureModulate();
2673   }
2674   else
2675   {
2676     if (aMapOfArgs.Find ("SCALE", aValues))
2677     {
2678       if (aValues->Value(1) != "OFF")
2679       {
2680         aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2681       }
2682       else
2683       {
2684         aTexturedIO->SetTextureScale (Standard_False);
2685       }
2686     }
2687
2688     if (aMapOfArgs.Find ("ORIGIN", aValues))
2689     {
2690       if (aValues->Value(1) != "OFF")
2691       {
2692         aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2693       }
2694       else
2695       {
2696         aTexturedIO->SetTextureOrigin (Standard_False);
2697       }
2698     }
2699
2700     if (aMapOfArgs.Find ("REPEAT", aValues))
2701     {
2702       if (aValues->Value(1) != "OFF")
2703       {
2704         aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2705       }
2706       else
2707       {
2708         aTexturedIO->SetTextureRepeat (Standard_False);
2709       }
2710     }
2711
2712     if (aMapOfArgs.Find ("MODULATE", aValues))
2713     {
2714       if (aValues->Value(1) == "ON")
2715       {
2716         aTexturedIO->EnableTextureModulate();
2717       }
2718       else
2719       {
2720         aTexturedIO->DisableTextureModulate();
2721       }
2722     }
2723   }
2724
2725   if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
2726   {
2727     anAISContext->RecomputePrsOnly (aTexturedIO);
2728   }
2729   else
2730   {
2731     anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
2732     anAISContext->Display (aTexturedIO, Standard_True);
2733     anAISContext->Update (aTexturedIO,Standard_True);
2734   }
2735
2736   return 0;
2737 }
2738
2739 //==============================================================================
2740 //function : VDisplay2
2741 //author   : ege
2742 //purpose  : Display an object from its name
2743 //==============================================================================
2744 static int VDisplay2 (Draw_Interpretor& theDI,
2745                       Standard_Integer  theArgNb,
2746                       const char**      theArgVec)
2747 {
2748   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2749   if (theArgNb < 2)
2750   {
2751     std::cout << theArgVec[0] << "Error: wrong syntax!\n";
2752     return 1;
2753   }
2754   else if (aCtx.IsNull())
2755   {
2756     ViewerTest::ViewerInit();
2757     std::cout << "Command vinit should be called before!\n";
2758     // return 1;
2759     aCtx = ViewerTest::GetAISContext();
2760   }
2761
2762   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2763   if (aCtx->HasOpenedContext())
2764   {
2765     aCtx->CloseLocalContext();
2766   }
2767
2768   Standard_Integer isMutable = -1;
2769   for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2770   {
2771     const TCollection_AsciiString aName     = theArgVec[anArgIter];
2772     TCollection_AsciiString       aNameCase = aName;
2773     aNameCase.LowerCase();
2774     if (anUpdateTool.parseRedrawMode (aName))
2775     {
2776       continue;
2777     }
2778     else if (aNameCase == "-mutable")
2779     {
2780       isMutable = 1;
2781       continue;
2782     }
2783     else if (!GetMapOfAIS().IsBound2 (aName))
2784     {
2785       // create the AIS_Shape from a name
2786       const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
2787       if (!aShape.IsNull())
2788       {
2789         if (isMutable != -1)
2790         {
2791           aShape->SetMutable (isMutable == 1);
2792         }
2793         GetMapOfAIS().Bind (aShape, aName);
2794         aCtx->Display (aShape, Standard_False);
2795       }
2796       continue;
2797     }
2798
2799     Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2800     if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
2801     {
2802       Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2803       if (isMutable != -1)
2804       {
2805         aShape->SetMutable (isMutable == 1);
2806       }
2807
2808       if (aShape->Type() == AIS_KOI_Datum)
2809       {
2810         aCtx->Display (aShape, Standard_False);
2811       }
2812       else
2813       {
2814         theDI << "Display " << aName.ToCString() << "\n";
2815         // get the Shape from a name
2816         TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
2817
2818         // update the Shape in the AIS_Shape
2819         Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
2820         if (!aShapePrs.IsNull())
2821         {
2822           aShapePrs->Set (aNewShape);
2823         }
2824         aCtx->Redisplay (aShape, Standard_False);
2825         aCtx->Display   (aShape, Standard_False);
2826       }
2827     }
2828     else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
2829     {
2830       Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2831       TheNISContext()->Display (aShape);
2832     }
2833   }
2834   return 0;
2835 }
2836
2837 //===============================================================================================
2838 //function : VUpdate
2839 //purpose  :
2840 //===============================================================================================
2841 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2842 {
2843   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2844   if (aContextAIS.IsNull())
2845   {
2846     std::cout << theArgVec[0] << "AIS context is not available.\n";
2847     return 1;
2848   }
2849
2850   if (theArgsNb < 2)
2851   {
2852     std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
2853     return 1;
2854   }
2855
2856   const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
2857
2858   AIS_ListOfInteractive aListOfIO;
2859
2860   for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2861   {
2862     TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
2863
2864     Handle(AIS_InteractiveObject) anAISObj;
2865     if (anAISMap.IsBound2 (aName))
2866     {
2867       anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
2868     }
2869
2870     if (anAISObj.IsNull())
2871     {
2872       std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
2873       return 1;
2874     }
2875
2876     aListOfIO.Append (anAISObj);
2877   }
2878
2879   AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
2880   for (; anIOIt.More(); anIOIt.Next())
2881   {
2882     aContextAIS->Update (anIOIt.Value(), Standard_False);
2883   }
2884
2885   aContextAIS->UpdateCurrentViewer();
2886
2887   return 0;
2888 }
2889
2890 //==============================================================================
2891 //function : VPerf
2892 //purpose  : Test the annimation of an object along a
2893 //           predifined trajectory
2894 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2895 //==============================================================================
2896
2897 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2898
2899   OSD_Timer myTimer;
2900   if (TheAISContext()->HasOpenedContext())
2901     TheAISContext()->CloseLocalContext();
2902
2903   Standard_Real Step=4*M_PI/180;
2904   Standard_Real Angle=0;
2905
2906   Handle(AIS_InteractiveObject) aIO;
2907   if (GetMapOfAIS().IsBound2(argv[1]))
2908     aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2909   if (aIO.IsNull())
2910     return 1;
2911
2912   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2913
2914   myTimer.Start();
2915
2916   if (Draw::Atoi(argv[3])==1 ) {
2917     di<<" Primitives sensibles OFF"<<"\n";
2918     TheAISContext()->Deactivate(aIO);
2919   }
2920   else {
2921     di<<" Primitives sensibles ON"<<"\n";
2922   }
2923   // Movement par transformation
2924   if(Draw::Atoi(argv[2]) ==1) {
2925     di<<" Calcul par Transformation"<<"\n";
2926     for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2927
2928       Angle=Step*myAngle;
2929       gp_Trsf myTransfo;
2930       myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2931       TheAISContext()->SetLocation(aShape,myTransfo);
2932       TheAISContext() ->UpdateCurrentViewer();
2933
2934     }
2935   }
2936   else {
2937     di<<" Calcul par Locations"<<"\n";
2938     gp_Trsf myAngleTrsf;
2939     myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step  );
2940     TopLoc_Location myDeltaAngle (myAngleTrsf);
2941     TopLoc_Location myTrueLoc;
2942
2943     for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2944
2945       Angle=Step*myAngle;
2946       myTrueLoc=myTrueLoc*myDeltaAngle;
2947       TheAISContext()->SetLocation(aShape,myTrueLoc );
2948       TheAISContext() ->UpdateCurrentViewer();
2949     }
2950   }
2951   if (Draw::Atoi(argv[3])==1 ){
2952     // On reactive la selection des primitives sensibles
2953     TheAISContext()->Activate(aIO,0);
2954   }
2955   a3DView() -> Redraw();
2956   myTimer.Stop();
2957   di<<" Temps ecoule "<<"\n";
2958   myTimer.Show();
2959   return 0;
2960 }
2961
2962
2963 //==================================================================================
2964 // Function : VAnimation
2965 //==================================================================================
2966 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2967   if (argc != 5) {
2968     di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2969     return 1;
2970   }
2971
2972   Standard_Real thread = 4;
2973   Standard_Real angleA=0;
2974   Standard_Real angleB;
2975   Standard_Real X;
2976   gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2977
2978   BRep_Builder B;
2979   TopoDS_Shape CrankArm;
2980   TopoDS_Shape CylinderHead;
2981   TopoDS_Shape Propeller;
2982   TopoDS_Shape EngineBlock;
2983
2984   //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2985   //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2986   //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2987   //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2988   BRepTools::Read(CrankArm,argv[1],B);
2989   BRepTools::Read(CylinderHead,argv[2],B);
2990   BRepTools::Read(Propeller,argv[3],B);
2991   BRepTools::Read(EngineBlock,argv[4],B);
2992
2993   if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2994
2995
2996   OSD_Timer myTimer;
2997   myTimer.Start();
2998
2999   Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3000   Handle(AIS_Shape) myAisEngineBlock  = new AIS_Shape (EngineBlock);
3001   Handle(AIS_Shape) myAisCrankArm     = new AIS_Shape (CrankArm);
3002   Handle(AIS_Shape) myAisPropeller    = new AIS_Shape (Propeller);
3003
3004   GetMapOfAIS().Bind(myAisCylinderHead,"a");
3005   GetMapOfAIS().Bind(myAisEngineBlock,"b");
3006   GetMapOfAIS().Bind(myAisCrankArm,"c");
3007   GetMapOfAIS().Bind(myAisPropeller,"d");
3008
3009   myAisCylinderHead->SetMutable (Standard_True);
3010   myAisEngineBlock ->SetMutable (Standard_True);
3011   myAisCrankArm    ->SetMutable (Standard_True);
3012   myAisPropeller   ->SetMutable (Standard_True);
3013
3014   TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3015   TheAISContext()->SetColor (myAisEngineBlock,  Quantity_NOC_RED);
3016   TheAISContext()->SetColor (myAisPropeller,    Quantity_NOC_GREEN);
3017
3018   TheAISContext()->Display (myAisCylinderHead, Standard_False);
3019   TheAISContext()->Display (myAisEngineBlock,  Standard_False);
3020   TheAISContext()->Display (myAisCrankArm,     Standard_False);
3021   TheAISContext()->Display (myAisPropeller,    Standard_False);
3022
3023   TheAISContext()->Deactivate(myAisCylinderHead);
3024   TheAISContext()->Deactivate(myAisEngineBlock );
3025   TheAISContext()->Deactivate(myAisCrankArm    );
3026   TheAISContext()->Deactivate(myAisPropeller   );
3027
3028   // Boucle de mouvement
3029   for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3030
3031     angleA = thread*myAngle*M_PI/180;
3032     X = Sin(angleA)*3/8;
3033     angleB = atan(X / Sqrt(-X * X + 1));
3034     Standard_Real decal(25*0.6);
3035
3036
3037     //Build a transformation on the display
3038     gp_Trsf aPropellerTrsf;
3039     aPropellerTrsf.SetRotation(Ax1,angleA);
3040     TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3041
3042     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));
3043     gp_Trsf aCrankArmTrsf;
3044     aCrankArmTrsf.SetTransformation(   base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3045     TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3046
3047     TheAISContext()->UpdateCurrentViewer();
3048   }
3049
3050   TopoDS_Shape myNewCrankArm  =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3051   TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3052
3053   myAisCrankArm ->ResetTransformation();
3054   myAisPropeller->ResetTransformation();
3055
3056   myAisCrankArm  -> Set(myNewCrankArm );
3057   myAisPropeller -> Set(myNewPropeller);
3058
3059   TheAISContext()->Activate(myAisCylinderHead,0);
3060   TheAISContext()->Activate(myAisEngineBlock,0 );
3061   TheAISContext()->Activate(myAisCrankArm ,0   );
3062   TheAISContext()->Activate(myAisPropeller ,0  );
3063
3064   myTimer.Stop();
3065   myTimer.Show();
3066   myTimer.Start();
3067
3068   TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3069   TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3070
3071   TheAISContext()->UpdateCurrentViewer();
3072   a3DView()->Redraw();
3073
3074   myTimer.Stop();
3075   myTimer.Show();
3076
3077   return 0;
3078
3079 }
3080
3081 //==============================================================================
3082 //function : VShading
3083 //purpose  : Sharpen or roughten the quality of the shading
3084 //Draw arg : vshading ShapeName 0.1->0.00001  1 deg-> 30 deg
3085 //==============================================================================
3086 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3087 {
3088   Standard_Real    myDevCoef;
3089   Handle(AIS_InteractiveObject) TheAisIO;
3090
3091   // Verifications
3092   const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3093
3094   if (TheAISContext()->HasOpenedContext())
3095     TheAISContext()->CloseLocalContext();
3096
3097   if (argc < 3) {
3098     myDevCoef  = 0.0008;
3099   } else {
3100     myDevCoef  =Draw::Atof(argv[2]);
3101   }
3102
3103   TCollection_AsciiString name=argv[1];
3104   if (GetMapOfAIS().IsBound2(name ))
3105     TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3106   if (TheAisIO.IsNull())
3107     TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3108
3109   if (HaveToSet)
3110     TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
3111   else
3112     TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3113
3114   TheAISContext()->Redisplay(TheAisIO);
3115   return 0;
3116 }
3117 //==============================================================================
3118 //function : HaveMode
3119 //use      : VActivatedModes
3120 //==============================================================================
3121 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3122
3123 Standard_Boolean  HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode  )
3124 {
3125   TColStd_ListOfInteger List;
3126   TheAISContext()->ActivatedModes (TheAisIO,List);
3127   TColStd_ListIteratorOfListOfInteger it;
3128   Standard_Boolean Found=Standard_False;
3129   for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3130     if (it.Value()==mode ) Found=Standard_True;
3131   }
3132   return Found;
3133 }
3134
3135
3136
3137 //==============================================================================
3138 //function : VActivatedMode
3139 //author   : ege
3140 //purpose  : permet d'attribuer a chacune des shapes un mode d'activation
3141 //           (edges,vertex...)qui lui est propre et le mode de selection standard.
3142 //           La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3143 //             Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3144 //           qu'un nom et qu'un mode.
3145 //Draw arg : vsetam  [ShapeName] mode(0,1,2,3,4,5,6,7)
3146 //==============================================================================
3147 #include <AIS_ListIteratorOfListOfInteractive.hxx>
3148
3149 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3150
3151 {
3152   Standard_Boolean ThereIsName = Standard_False ;
3153
3154   if(!a3DView().IsNull()){
3155
3156     const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
3157     // verification des arguments
3158     if (HaveToSet) {
3159       if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
3160       ThereIsName = (argc == 3);
3161     }
3162     else {
3163       // vunsetam
3164       if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3165       else {
3166         di<<" R.A.Z de tous les modes de selecion"<<"\n";
3167         di<<" Fermeture du Context local"<<"\n";
3168         if (TheAISContext()->HasOpenedContext())
3169           TheAISContext()->CloseLocalContext();
3170       }
3171     }
3172
3173     // IL n'y a aps de nom de shape passe en argument
3174     if (HaveToSet && !ThereIsName){
3175       Standard_Integer aMode=Draw::Atoi(argv [1]);
3176
3177       const char *cmode="???";
3178       switch (aMode) {
3179       case 0: cmode = "Shape"; break;
3180       case 1: cmode = "Vertex"; break;
3181       case 2: cmode = "Edge"; break;
3182       case 3: cmode = "Wire"; break;
3183       case 4: cmode = "Face"; break;
3184       case 5: cmode = "Shell"; break;
3185       case 6: cmode = "Solid"; break;
3186       case 7: cmode = "Compound"; break;
3187       }
3188
3189       if( !TheAISContext()->HasOpenedContext() ) {
3190         // il n'y a pas de Context local d'ouvert
3191         // on en ouvre un et on charge toutes les shapes displayees
3192         // on load tous les objets displayees et on Activate les objets de la liste
3193         AIS_ListOfInteractive ListOfIO;
3194         // on sauve dans une AISListOfInteractive tous les objets currents
3195         if (TheAISContext()->NbCurrents()>0 ){
3196           TheAISContext()->UnhilightCurrents(Standard_False);
3197
3198           for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3199             ListOfIO.Append(TheAISContext()->Current() );
3200           }
3201         }
3202
3203         TheAISContext()->OpenLocalContext(Standard_False);
3204         ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3205           it (GetMapOfAIS());
3206         while(it.More()){
3207           Handle(AIS_InteractiveObject) aIO =
3208             Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3209           if (!aIO.IsNull())
3210             TheAISContext()->Load(aIO,0,Standard_False);
3211           it.Next();
3212         }
3213         // traitement des objets qui etaient currents dans le Contexte global
3214         if (!ListOfIO.IsEmpty() ) {
3215           // il y avait des objets currents
3216           AIS_ListIteratorOfListOfInteractive iter;
3217           for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3218             Handle(AIS_InteractiveObject) aIO=iter.Value();
3219             TheAISContext()->Activate(aIO,aMode);
3220             di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString()  <<"\n";
3221           }
3222         }
3223         else {
3224           // On applique le mode a tous les objets displayes
3225           ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3226             it2 (GetMapOfAIS());
3227           while(it2.More()){
3228             Handle(AIS_InteractiveObject) aIO =
3229               Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
3230             if (!aIO.IsNull()) {
3231               di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
3232               TheAISContext()->Activate(aIO,aMode);
3233             }
3234             it2.Next();
3235           }
3236         }
3237
3238       }
3239
3240       else {
3241         // un Context local est deja ouvert
3242         // Traitement des objets du Context local
3243         if (TheAISContext()->NbSelected()>0 ){
3244           TheAISContext()->UnhilightSelected(Standard_False);
3245           // il y a des objets selected,on les parcourt
3246           for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
3247             Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
3248
3249
3250             if (HaveMode(aIO,aMode) ) {
3251               di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3252               TheAISContext()->Deactivate(aIO,aMode);
3253             }
3254             else{
3255               di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3256               TheAISContext()->Activate(aIO,aMode);
3257             }
3258
3259           }
3260         }
3261         else{
3262           // il n'y a pas d'objets selected
3263           // tous les objets diplayes sont traites
3264           ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3265             it (GetMapOfAIS());
3266           while(it.More()){
3267             Handle(AIS_InteractiveObject) aIO =
3268               Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3269             if (!aIO.IsNull()) {
3270               if (HaveMode(aIO,aMode) ) {
3271                 di<<" Mode: "<<cmode<<" OFF pour "
3272                   <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3273                 TheAISContext()->Deactivate(aIO,aMode);
3274               }
3275               else{
3276                 di<<" Mode: "<<cmode<<" ON pour"
3277                   <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3278                 TheAISContext()->Activate(aIO,aMode);
3279               }
3280             }
3281             it.Next();
3282           }
3283         }
3284       }
3285     }
3286     else if (HaveToSet && ThereIsName){
3287       Standard_Integer aMode=Draw::Atoi(argv [2]);
3288       Handle(AIS_InteractiveObject) aIO =
3289         Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3290
3291       if (!aIO.IsNull()) {
3292         const char *cmode="???";
3293
3294         switch (aMode) {
3295         case 0: cmode = "Shape"; break;
3296         case 1: cmode = "Vertex"; break;
3297         case 2: cmode = "Edge"; break;
3298         case 3: cmode = "Wire"; break;
3299         case 4: cmode = "Face"; break;
3300         case 5: cmode = "Shell"; break;
3301         case 6: cmode = "Solid"; break;
3302         case 7: cmode = "Compound"; break;
3303         }
3304
3305         if( !TheAISContext()->HasOpenedContext() ) {
3306           TheAISContext()->OpenLocalContext(Standard_False);
3307           // On charge tous les objets de la map
3308           ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
3309           while(it.More()){
3310             Handle(AIS_InteractiveObject) aShape=
3311               Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3312             if (!aShape.IsNull())
3313               TheAISContext()->Load(aShape,0,Standard_False);
3314             it.Next();
3315           }
3316           TheAISContext()->Activate(aIO,aMode);
3317           di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3318         }
3319
3320         else {
3321           // un Context local est deja ouvert
3322           if (HaveMode(aIO,aMode) ) {
3323             di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
3324             TheAISContext()->Deactivate(aIO,aMode);
3325           }
3326           else{
3327             di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3328             TheAISContext()->Activate(aIO,aMode);
3329           }
3330         }
3331       }
3332     }
3333   }
3334   return 0;
3335 }
3336
3337 //! Auxiliary method to print Interactive Object information
3338 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
3339                      const Handle(Standard_Transient)&                     theObject,
3340                      Draw_Interpretor&                                     theDI)
3341 {
3342   const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
3343   if (anObj.IsNull())
3344   {
3345     theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
3346     return;
3347   }
3348
3349   theDI << (TheAISContext()->IsDisplayed  (anObj) ? "Displayed"  : "Hidden   ")
3350         << (TheAISContext()->IsSelected   (anObj) ? " Selected" : "         ")
3351         << (theDetected.Contains (anObj)          ? " Detected" : "         ")
3352         << " Type: ";
3353   if (anObj->Type() == AIS_KOI_Datum)
3354   {
3355     // AIS_Datum
3356     if      (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
3357     else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
3358     else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
3359     else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
3360     else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
3361     else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
3362     else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
3363   }
3364   // AIS_Shape
3365   else if (anObj->Type()      == AIS_KOI_Shape
3366         && anObj->Signature() == 0)
3367   {
3368     theDI << " AIS_Shape";
3369   }
3370   else if (anObj->Type() == AIS_KOI_Relation)
3371   {
3372     // AIS_Dimention and AIS_Relation
3373     Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
3374     switch (aRelation->KindOfDimension())
3375     {
3376       case AIS_KOD_PLANEANGLE:     theDI << " AIS_AngleDimension"; break;
3377       case AIS_KOD_LENGTH:         theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
3378       case AIS_KOD_DIAMETER:       theDI << " AIS_DiameterDimension"; break;
3379       case AIS_KOD_ELLIPSERADIUS:  theDI << " AIS_EllipseRadiusDimension"; break;
3380       //case AIS_KOD_FILLETRADIUS:   theDI << " AIS_FilletRadiusDimension "; break;
3381       case AIS_KOD_OFFSET:         theDI << " AIS_OffsetDimension"; break;
3382       case AIS_KOD_RADIUS:         theDI << " AIS_RadiusDimension"; break;
3383       default:                     theDI << " UNKNOWN dimension"; break;
3384     }
3385   }
3386   else
3387   {
3388     theDI << " UserPrs";
3389   }
3390   theDI << " (" << theObject->DynamicType()->Name() << ")";
3391 }
3392
3393 //! Print information about locally selected sub-shapes
3394 static void localCtxInfo (Draw_Interpretor& theDI)
3395 {
3396   Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3397   if (!aCtx->HasOpenedContext())
3398   {
3399     return;
3400   }
3401
3402   TCollection_AsciiString aPrevName;
3403   Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
3404   for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
3405   {
3406     const TopoDS_Shape      aSubShape = aCtxLoc->SelectedShape();
3407     const Handle(AIS_Shape) aShapeIO  = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
3408     if (aSubShape.IsNull()
3409       || aShapeIO.IsNull()
3410       || !GetMapOfAIS().IsBound1 (aShapeIO))
3411     {
3412       continue;
3413     }
3414
3415     const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
3416     TopTools_MapOfShape aFilter;
3417     Standard_Integer    aNumber = 0;
3418     const TopoDS_Shape  aShape  = aShapeIO->Shape();
3419     for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
3420          anIter.More(); anIter.Next())
3421     {
3422       if (!aFilter.Add (anIter.Current()))
3423       {
3424         continue; // filter duplicates
3425       }
3426
3427       ++aNumber;
3428       if (!anIter.Current().IsSame (aSubShape))
3429       {
3430         continue;
3431       }
3432
3433       Standard_CString aShapeName = NULL;
3434       switch (aSubShape.ShapeType())
3435       {
3436         case TopAbs_COMPOUND:  aShapeName = " Compound"; break;
3437         case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
3438         case TopAbs_SOLID:     aShapeName = "    Solid"; break;
3439         case TopAbs_SHELL:     aShapeName = "    Shell"; break;
3440         case TopAbs_FACE:      aShapeName = "     Face"; break;
3441         case TopAbs_WIRE:      aShapeName = "     Wire"; break;
3442         case TopAbs_EDGE:      aShapeName = "     Edge"; break;
3443         case TopAbs_VERTEX:    aShapeName = "   Vertex"; break;
3444         default:
3445         case TopAbs_SHAPE:     aShapeName = "    Shape"; break;
3446       }
3447
3448       if (aParentName != aPrevName)
3449       {
3450         theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
3451         aPrevName = aParentName;
3452       }
3453       theDI << "  " << aShapeName << " #" << aNumber << "\n";
3454       break;
3455     }
3456   }
3457 }
3458
3459 //==============================================================================
3460 //function : VState
3461 //purpose  :
3462 //Draw arg : vstate [nameA] ... [nameN]
3463 //==============================================================================
3464 static Standard_Integer VState (Draw_Interpretor& theDI,
3465                                 Standard_Integer  theArgNb,
3466                                 Standard_CString* theArgVec)
3467 {
3468   Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3469   if (aCtx.IsNull())
3470   {
3471     std::cerr << "Error: No opened viewer!\n";
3472     return 1;
3473   }
3474
3475   NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
3476   for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
3477   {
3478     aDetected.Add (aCtx->DetectedCurrentObject());
3479   }
3480
3481   const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
3482   if (theArgNb >= 2
3483    && !toShowAll)
3484   {
3485     for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3486     {
3487       const TCollection_AsciiString anObjName = theArgVec[anArgIter];
3488       if (!GetMapOfAIS().IsBound2 (anObjName))
3489       {
3490         theDI << anObjName << " doesn't exist!\n";
3491         continue;
3492       }
3493
3494       const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
3495       TCollection_AsciiString aName = anObjName;
3496       aName.LeftJustify (20, ' ');
3497       theDI << "  " << aName << " ";
3498       objInfo (aDetected, anObjTrans, theDI);
3499       theDI << "\n";
3500     }
3501     return 0;
3502   }
3503
3504   if (aCtx->NbCurrents() > 0
3505    && !toShowAll)
3506   {
3507     for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
3508     {
3509       Handle(AIS_InteractiveObject) anObj = aCtx->Current();
3510       TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
3511       aName.LeftJustify (20, ' ');
3512       theDI << aName << " ";
3513       objInfo (aDetected, anObj, theDI);
3514       theDI << "\n";
3515     }
3516     return 0;
3517   }
3518
3519   theDI << "Neutral-point state:\n";
3520   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
3521        anObjIter.More(); anObjIter.Next())
3522   {
3523     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
3524     if (anObj.IsNull())
3525     {
3526       continue;
3527     }
3528
3529     TCollection_AsciiString aName = anObjIter.Key2();
3530     aName.LeftJustify (20, ' ');
3531     theDI << "  " << aName << " ";
3532     objInfo (aDetected, anObj, theDI);
3533     theDI << "\n";
3534   }
3535   localCtxInfo (theDI);
3536   return 0;
3537 }
3538
3539 //=======================================================================
3540 //function : PickObjects
3541 //purpose  :
3542 //=======================================================================
3543 Standard_Boolean  ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
3544                                           const AIS_KindOfInteractive TheType,
3545                                           const Standard_Integer TheSignature,
3546                                           const Standard_Integer MaxPick)
3547 {
3548   Handle(AIS_InteractiveObject) IO;
3549   Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3550
3551   // step 1: prepare the data
3552   if(curindex !=0){
3553     Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3554     TheAISContext()->AddFilter(F1);
3555   }
3556
3557   // step 2 : wait for the selection...
3558 //  Standard_Boolean IsGood (Standard_False);
3559 //  Standard_Integer NbPick(0);
3560   Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
3561   Standard_Integer NbPickFail(0);
3562   Standard_Integer argccc = 5;
3563   const char *bufff[] = { "A", "B", "C","D", "E" };
3564   const char **argvvv = (const char **) bufff;
3565
3566
3567   while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3568     while(ViewerMainLoop(argccc,argvvv)){}
3569     Standard_Integer NbStored = TheAISContext()->NbSelected();
3570     if((unsigned int ) NbStored != NbPickGood)
3571       NbPickGood= NbStored;
3572     else
3573       NbPickFail++;
3574     cout<<"NbPicked =  "<<NbPickGood<<" |  Nb Pick Fail :"<<NbPickFail<<endl;
3575   }
3576
3577   // step3 get result.
3578
3579   if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3580
3581   Standard_Integer i(0);
3582   for(TheAISContext()->InitSelected();
3583       TheAISContext()->MoreSelected();
3584       TheAISContext()->NextSelected()){
3585     i++;
3586     Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
3587     arr->SetValue(i,IO2);
3588   }
3589
3590
3591   if(curindex>0)
3592     TheAISContext()->CloseLocalContext(curindex);
3593
3594   return Standard_True;
3595 }
3596
3597
3598 //=======================================================================
3599 //function : PickObject
3600 //purpose  :
3601 //=======================================================================
3602 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
3603                                                      const Standard_Integer TheSignature,
3604                                                      const Standard_Integer MaxPick)
3605 {
3606   Handle(AIS_InteractiveObject) IO;
3607   Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3608
3609   // step 1: prepare the data
3610
3611   if(curindex !=0){
3612     Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3613     TheAISContext()->AddFilter(F1);
3614   }
3615
3616   // step 2 : wait for the selection...
3617   Standard_Boolean IsGood (Standard_False);
3618   Standard_Integer NbPick(0);
3619   Standard_Integer argccc = 5;
3620   const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3621   const char **argvvv = (const char **) bufff;
3622
3623
3624   while(!IsGood && NbPick<= MaxPick){
3625     while(ViewerMainLoop(argccc,argvvv)){}
3626     IsGood = (TheAISContext()->NbSelected()>0) ;
3627     NbPick++;
3628     cout<<"Nb Pick :"<<NbPick<<endl;
3629   }
3630
3631
3632   // step3 get result.
3633   if(IsGood){
3634     TheAISContext()->InitSelected();
3635     IO = TheAISContext()->SelectedInteractive();
3636   }
3637
3638   if(curindex!=0)
3639     TheAISContext()->CloseLocalContext(curindex);
3640   return IO;
3641 }
3642
3643 //=======================================================================
3644 //function : PickShape
3645 //purpose  : First Activate the rightmode + Put Filters to be able to
3646 //           pick objets that are of type <TheType>...
3647 //=======================================================================
3648
3649 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
3650                                    const Standard_Integer MaxPick)
3651 {
3652
3653   // step 1: prepare the data
3654
3655   Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3656   TopoDS_Shape result;
3657
3658   if(TheType==TopAbs_SHAPE){
3659     Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3660     TheAISContext()->AddFilter(F1);
3661   }
3662   else{
3663     Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3664     TheAISContext()->AddFilter(TF);
3665     TheAISContext()->ActivateStandardMode(TheType);
3666
3667   }
3668
3669
3670   // step 2 : wait for the selection...
3671   Standard_Boolean NoShape (Standard_True);
3672   Standard_Integer NbPick(0);
3673   Standard_Integer argccc = 5;
3674   const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3675   const char **argvvv = (const char **) bufff;
3676
3677
3678   while(NoShape && NbPick<= MaxPick){
3679     while(ViewerMainLoop(argccc,argvvv)){}
3680     NoShape = (TheAISContext()->NbSelected()==0) ;
3681     NbPick++;
3682     cout<<"Nb Pick :"<<NbPick<<endl;
3683   }
3684
3685   // step3 get result.
3686
3687   if(!NoShape){
3688
3689     TheAISContext()->InitSelected();
3690     if(TheAISContext()->HasSelectedShape())
3691       result = TheAISContext()->SelectedShape();
3692     else{
3693       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3694       result = (*((Handle(AIS_Shape)*) &IO))->Shape();
3695     }
3696   }
3697
3698   if(curindex>0)
3699     TheAISContext()->CloseLocalContext(curindex);
3700
3701   return result;
3702 }
3703
3704
3705 //=======================================================================
3706 //function : PickShapes
3707 //purpose  :
3708 //=======================================================================
3709 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
3710                                          Handle(TopTools_HArray1OfShape)& thearr,
3711                                          const Standard_Integer MaxPick)
3712 {
3713
3714   Standard_Integer Taille = thearr->Length();
3715   if(Taille>1)
3716     cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
3717
3718   // step 1: prepare the data
3719   Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3720   if(TheType==TopAbs_SHAPE){
3721     Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3722     TheAISContext()->AddFilter(F1);
3723   }
3724   else{
3725     Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3726     TheAISContext()->AddFilter(TF);
3727     TheAISContext()->ActivateStandardMode(TheType);
3728
3729   }
3730
3731   // step 2 : wait for the selection...
3732
3733   Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
3734   Standard_Integer NbPickFail(0);
3735   Standard_Integer argccc = 5;
3736   const char *bufff[] = { "A", "B", "C","D", "E" };
3737   const char **argvvv = (const char **) bufff;
3738
3739
3740   while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3741     while(ViewerMainLoop(argccc,argvvv)){}
3742     Standard_Integer NbStored = TheAISContext()->NbSelected();
3743     if((unsigned int ) NbStored != NbPickGood)
3744       NbPickGood= NbStored;
3745     else
3746       NbPickFail++;
3747     cout<<"NbPicked =  "<<NbPickGood<<" |  Nb Pick Fail :"<<NbPickFail<<"\n";
3748   }
3749
3750   // step3 get result.
3751
3752   if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3753
3754   Standard_Integer i(0);
3755   for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
3756     i++;
3757     if(TheAISContext()->HasSelectedShape())
3758       thearr->SetValue(i,TheAISContext()->SelectedShape());
3759     else{
3760       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3761       thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
3762     }
3763   }
3764
3765   TheAISContext()->CloseLocalContext(curindex);
3766   return Standard_True;
3767 }
3768
3769
3770 //=======================================================================
3771 //function : VPickShape
3772 //purpose  :
3773 //=======================================================================
3774 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3775 {
3776   TopoDS_Shape PickSh;
3777   TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
3778
3779   if(argc==1)
3780     theType = TopAbs_SHAPE;
3781   else{
3782     if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
3783     else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
3784     else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
3785     else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
3786     else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
3787     else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
3788     else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
3789   }
3790
3791   static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
3792   static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
3793
3794   TCollection_AsciiString name;
3795
3796
3797   Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3798   if(NbToPick==1){
3799     PickSh = ViewerTest::PickShape(theType);
3800
3801     if(PickSh.IsNull())
3802       return 1;
3803     if(argc>2){
3804       name += argv[2];
3805     }
3806     else{
3807
3808       if(!PickSh.IsNull()){
3809         nbOfSub[Standard_Integer(theType)]++;
3810         name += "Picked_";
3811         name += nameType[Standard_Integer(theType)];
3812         TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3813         name +="_";
3814         name+=indxstring;
3815       }
3816     }
3817     // si on avait une petite methode pour voir si la shape
3818     // est deja dans la Double map, ca eviterait de creer....
3819     DBRep::Set(name.ToCString(),PickSh);
3820
3821     Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3822     GetMapOfAIS().Bind(newsh, name);
3823     TheAISContext()->Display(newsh);
3824     di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
3825   }
3826
3827   // Plusieurs objets a picker, vite vite vite....
3828   //
3829   else{
3830     Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3831     Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3832     if(ViewerTest::PickShapes(theType,arr)){
3833       for(Standard_Integer i=1;i<=NbToPick;i++){
3834         PickSh = arr->Value(i);
3835         if(!PickSh.IsNull()){
3836           if(autonaming){
3837             nbOfSub[Standard_Integer(theType)]++;
3838             name.Clear();
3839             name += "Picked_";
3840             name += nameType[Standard_Integer(theType)];
3841             TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3842             name +="_";
3843             name+=indxstring;
3844           }
3845         }
3846         else
3847           name = argv[1+i];
3848
3849         DBRep::Set(name.ToCString(),PickSh);
3850         Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3851         GetMapOfAIS().Bind(newsh, name);
3852         di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3853         TheAISContext()->Display(newsh);
3854
3855       }
3856     }
3857   }
3858   return 0;
3859 }
3860
3861 //=======================================================================
3862 //function : list of known objects
3863 //purpose  :
3864 //=======================================================================
3865 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3866 {
3867   //                             1234567890         12345678901234567         123456789
3868   TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3869   TCollection_AsciiString BlankLine(64,'_');
3870   Standard_Integer i ;
3871
3872   di<<"/n"<<BlankLine.ToCString()<<"\n";
3873
3874   for( i =0;i<=2;i++)
3875     Colum[i].Center(20,' ');
3876   for(i=0;i<=2;i++)
3877     di<<"|"<<Colum[i].ToCString();
3878   di<<"|"<<"\n";
3879
3880   di<<BlankLine.ToCString()<<"\n";
3881
3882   //  TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3883   const char ** names = GetTypeNames();
3884
3885   TCollection_AsciiString curstring;
3886   TCollection_AsciiString curcolum[3];
3887
3888
3889   // les objets de type Datum..
3890   curcolum[1]+="Datum";
3891   for(i =0;i<=6;i++){
3892     curcolum[0].Clear();
3893     curcolum[0] += names[i];
3894
3895     curcolum[2].Clear();
3896     curcolum[2]+=TCollection_AsciiString(i+1);
3897
3898     for(Standard_Integer j =0;j<=2;j++){
3899       curcolum[j].Center(20,' ');
3900       di<<"|"<<curcolum[j].ToCString();
3901     }
3902     di<<"|"<<"\n";
3903   }
3904   di<<BlankLine.ToCString()<<"\n";
3905
3906   // les objets de type shape
3907   curcolum[1].Clear();
3908   curcolum[1]+="Shape";
3909   curcolum[1].Center(20,' ');
3910
3911   for(i=0;i<=2;i++){
3912     curcolum[0].Clear();
3913     curcolum[0] += names[7+i];
3914     curcolum[2].Clear();
3915     curcolum[2]+=TCollection_AsciiString(i);
3916
3917     for(Standard_Integer j =0;j<=2;j++){
3918       curcolum[j].Center(20,' ');
3919       di<<"|"<<curcolum[j].ToCString();
3920     }
3921     di<<"|"<<"\n";
3922   }
3923   di<<BlankLine.ToCString()<<"\n";
3924   // les IO de type objet...
3925   curcolum[1].Clear();
3926   curcolum[1]+="Object";
3927   curcolum[1].Center(20,' ');
3928   for(i=0;i<=1;i++){
3929     curcolum[0].Clear();
3930     curcolum[0] += names[10+i];
3931     curcolum[2].Clear();
3932     curcolum[2]+=TCollection_AsciiString(i);
3933
3934     for(Standard_Integer j =0;j<=2;j++){
3935       curcolum[j].Center(20,' ');
3936       di<<"|"<<curcolum[j].ToCString();
3937     }
3938     di<<"|"<<"\n";
3939   }
3940   di<<BlankLine.ToCString()<<"\n";
3941   // les contraintes et dimensions.
3942   // pour l'instant on separe juste contraintes et dimensions...
3943   // plus tard, on detaillera toutes les sortes...
3944   curcolum[1].Clear();
3945   curcolum[1]+="Relation";
3946   curcolum[1].Center(20,' ');
3947   for(i=0;i<=1;i++){
3948     curcolum[0].Clear();
3949     curcolum[0] += names[12+i];
3950     curcolum[2].Clear();
3951     curcolum[2]+=TCollection_AsciiString(i);
3952
3953     for(Standard_Integer j =0;j<=2;j++){
3954       curcolum[j].Center(20,' ');
3955       di<<"|"<<curcolum[j].ToCString();
3956     }
3957     di<<"|"<<"\n";
3958   }
3959   di<<BlankLine.ToCString()<<"\n";
3960
3961
3962   return 0;
3963 }
3964
3965
3966 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3967 {
3968   if(argc!=2) return 1;
3969
3970   AIS_KindOfInteractive TheType;
3971   Standard_Integer TheSign(-1);
3972   GetTypeAndSignfromString(argv[1],TheType,TheSign);
3973
3974
3975   AIS_ListOfInteractive LIO;
3976
3977   // en attendant l'amelioration ais pour les dimensions...
3978   //
3979   Standard_Integer dimension_status(-1);
3980   if(TheType==AIS_KOI_Relation){
3981     dimension_status = TheSign ==1 ? 1 : 0;
3982     TheSign=-1;
3983   }
3984
3985   TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3986   Handle(AIS_InteractiveObject) curio;
3987   for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3988     curio  = it.Value();
3989
3990     if(dimension_status == -1)
3991       TheAISContext()->Erase(curio,Standard_False);
3992     else {
3993       AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3994       if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3995           (dimension_status==1 && KOD != AIS_KOD_NONE))
3996         TheAISContext()->Erase(curio,Standard_False);
3997     }
3998   }
3999   TheAISContext()->UpdateCurrentViewer();
4000   return 0;
4001 }
4002 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4003 {
4004   if(argc!=2) return 1;
4005
4006   AIS_KindOfInteractive TheType;
4007   Standard_Integer TheSign(-1);
4008   GetTypeAndSignfromString(argv[1],TheType,TheSign);
4009
4010   // en attendant l'amelioration ais pour les dimensions...
4011   //
4012   Standard_Integer dimension_status(-1);
4013   if(TheType==AIS_KOI_Relation){
4014     dimension_status = TheSign ==1 ? 1 : 0;
4015     TheSign=-1;
4016   }
4017
4018   AIS_ListOfInteractive LIO;
4019   TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
4020   Handle(AIS_InteractiveObject) curio;
4021   for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4022     curio  = it.Value();
4023     if(dimension_status == -1)
4024       TheAISContext()->Display(curio,Standard_False);
4025     else {
4026       AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4027       if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4028           (dimension_status==1 && KOD != AIS_KOD_NONE))
4029         TheAISContext()->Display(curio,Standard_False);
4030     }
4031
4032   }
4033
4034   TheAISContext()->UpdateCurrentViewer();
4035   return 0;
4036 }
4037
4038 //==============================================================================
4039 //function : VSetTransMode
4040 //purpose  :
4041 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
4042 //==============================================================================
4043
4044 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4045   // Verification des arguments
4046   if ( a3DView().IsNull() ) {
4047     ViewerTest::ViewerInit();
4048     di << "La commande vinit n'a pas ete appele avant" << "\n";
4049   }
4050
4051   if ( argc < 3 || argc > 8 ) {
4052     di << argv[0] << " Invalid number of arguments" << "\n";
4053     return 1;
4054   }
4055
4056   TCollection_AsciiString shapeName;
4057   shapeName = argv[1];
4058   Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
4059   Standard_Integer persFlag2 = 0;
4060   Standard_Integer persFlag3 = 0;
4061   gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
4062   if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
4063     persFlag2 = Draw::Atoi(argv[3]);
4064   }
4065   if ( argc == 5 || argc == 8 ) {
4066     persFlag3 = Draw::Atoi(argv[4]);
4067   }
4068   if ( argc >= 6 ) {
4069     origin.SetX( Draw::Atof(argv[argc - 3]) );
4070     origin.SetY( Draw::Atof(argv[argc - 2]) );
4071     origin.SetZ( Draw::Atof(argv[argc - 1]) );
4072   }
4073
4074   Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
4075   Handle(Standard_Transient) anObj;
4076   if ( IsBound ) {
4077     anObj = GetMapOfAIS().Find2(shapeName);
4078     if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
4079       Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
4080       aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4081       if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
4082         di << argv[0] << " All persistence modifiers were removed" << "\n";
4083       }
4084     } else {
4085       di << argv[0] << " Wrong object type" << "\n";
4086       return 1;
4087     }
4088   } else { // Create the AIS_Shape from a name
4089     const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
4090     if ( !aShape.IsNull() ) {
4091       GetMapOfAIS().Bind( aShape, shapeName );
4092       aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4093       TheAISContext()->Display( aShape, Standard_False );
4094     } else {
4095       di << argv[0] << " Object not found" << "\n";
4096       return 1;
4097     }
4098   }
4099
4100   // Upadate the screen and redraw the view
4101   TheAISContext()->UpdateCurrentViewer();
4102   return 0;
4103 }
4104
4105 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
4106 {
4107   ifstream s(a[1]);
4108   BRep_Builder builder;
4109   TopoDS_Shape shape;
4110   BRepTools::Read(shape, s, builder);
4111   DBRep::Set(a[1], shape);
4112   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4113   Handle(AIS_Shape) ais = new AIS_Shape(shape);
4114   Ctx->Display(ais);
4115   return 0;
4116 }
4117
4118 //==============================================================================
4119 //function : ViewerTest::Commands
4120 //purpose  : Add all the viewer command in the Draw_Interpretor
4121 //==============================================================================
4122
4123 void ViewerTest::Commands(Draw_Interpretor& theCommands)
4124 {
4125   ViewerTest::ViewerCommands(theCommands);
4126   ViewerTest::RelationCommands(theCommands);
4127   ViewerTest::ObjectCommands(theCommands);
4128   ViewerTest::FilletCommands(theCommands);
4129   ViewerTest::VoxelCommands(theCommands);
4130   ViewerTest::OpenGlCommands(theCommands);
4131
4132   const char *group = "AIS_Display";
4133
4134   // display
4135   theCommands.Add("visos",
4136                   "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
4137                   "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
4138                   __FILE__, visos, group);
4139
4140   theCommands.Add("vdisplay",
4141                   "vdisplay [-noupdate|-update] [-mutable] name1 [name2] ... [name n]"
4142       "\n\t\t: Displays named objects."
4143       "\n\t\t: Option -noupdate suppresses viewer redraw call."
4144       "\n\t\t: Option -mutable enables optimizations for mutable objects."
4145                   __FILE__,VDisplay2,group);
4146
4147   theCommands.Add ("vupdate",
4148       "vupdate name1 [name2] ... [name n]"
4149       "\n\t\t: Updates named objects in interactive context",
4150       __FILE__, VUpdate, group);
4151
4152   theCommands.Add("verase",
4153       "verase [-noupdate|-update] [name1] ...  [name n]"
4154       "\n\t\t: Erases selected or named objects."
4155       "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
4156                   __FILE__, VErase, group);
4157
4158   theCommands.Add("vremove",
4159     "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ...  [name n]"
4160     "or vremove [-context] -all to remove all objects"
4161       "\n\t\t: Removes selected or named objects."
4162       "\n\t\t  If -context is in arguments, the objects are not deleted"
4163       "\n\t\t  from the map of objects and names."
4164       "\n\t\t: Option -noupdate suppresses viewer redraw call."
4165       "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
4166       __FILE__, VRemove, group);
4167
4168   theCommands.Add("vdonly",
4169                   "vdonly [-noupdate|-update] [name1] ...  [name n]"
4170       "\n\t\t: Displays only selected or named objects",
4171                   __FILE__,VDonly2,group);
4172
4173   theCommands.Add("vdisplayall",
4174                   "Displays all erased interactive objects (see vdir and vstate)",
4175                   __FILE__,VDisplayAll,group);
4176
4177   theCommands.Add("veraseall",
4178                   "Erases all objects displayed in the viewer",
4179                   __FILE__, VErase, group);
4180
4181   theCommands.Add("verasetype",
4182                   "verasetype <Type>"
4183       "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
4184                   __FILE__,VEraseType,group);
4185
4186   theCommands.Add("vbounding",
4187               "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
4188       "\n\t\t:           [-print] [-hide]"
4189       "\n\t\t: Temporarily display bounding box of specified Interactive"
4190       "\n\t\t: Objects, or print it to console if -print is specified."
4191       "\n\t\t: Already displayed box might be hidden by -hide option.",
4192                   __FILE__,VBounding,group);
4193
4194   theCommands.Add("vdisplaytype",
4195                   "vdisplaytype        : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
4196                   __FILE__,VDisplayType,group);
4197
4198   theCommands.Add("vdisplaymode",
4199                   "vdispmode       : vdispmode  [name] mode(1,2,..) : no name -> on selected objects ",
4200                   __FILE__,VDispMode,group);
4201
4202   theCommands.Add("verasemode",
4203                   "verasemode      : verasemode [name] mode(1,2,..) : no name -> on selected objects",
4204                   __FILE__,VDispMode,group);
4205
4206   theCommands.Add("vsetdispmode",
4207                   "vsetdispmode [name] mode(1,2,..)"
4208       "\n\t\t: Sets display mode for all, selected or named objects.",
4209                   __FILE__,VDispMode,group);
4210
4211   theCommands.Add("vunsetdispmode",
4212                   "vunsetdispmode [name]"
4213       "\n\t\t: Unsets custom display mode for selected or named objects.",
4214                   __FILE__,VDispMode,group);
4215
4216   theCommands.Add("vdir",
4217                   "Lists all objects displayed in 3D viewer",
4218                   __FILE__,VDir,group);
4219
4220   theCommands.Add("vdump",
4221     #ifdef HAVE_FREEIMAGE
4222               "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4223       "\n\t\t:                                    [width Width=0 height Height=0]"
4224       "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
4225     #else
4226               "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4227       "\n\t\t:                        [width Width=0 height Height=0]"
4228       "\n\t\t: Dumps content of the active view into PPM image file",
4229     #endif
4230                   __FILE__,VDump,group);
4231
4232   theCommands.Add("vsub",      "vsub 0/1 (off/on) [obj]        : Subintensity(on/off) of selected objects",
4233                   __FILE__,VSubInt,group);
4234
4235   theCommands.Add("vaspects",
4236               "vaspects [-noupdate|-update] [name1 [name2 [...]]]"
4237       "\n\t\t:          [-setcolor ColorName] [-unsetcolor]"
4238       "\n\t\t:          [-setmaterial MatName] [-unsetmaterial]"
4239       "\n\t\t:          [-settransparency Transp] [-unsettransparency]"
4240       "\n\t\t:          [-setwidth LineWidth] [-unsetwidth]"
4241       "\n\t\t:          [-subshapes subname1 [subname2 [...]]]"
4242       "\n\t\t: Manage presentation properties of all, selected or named objects."
4243       "\n\t\t: When -subshapes is specified than following properties will be"
4244       "\n\t\t: assigned to specified sub-shapes.",
4245                   __FILE__,VAspects,group);
4246
4247   theCommands.Add("vsetcolor",
4248       "vsetcolor [-noupdate|-update] [name] ColorName"
4249       "\n\t\t: Sets color for all, selected or named objects."
4250       "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
4251                   __FILE__,VAspects,group);
4252
4253   theCommands.Add("vunsetcolor",
4254                   "vunsetcolor [-noupdate|-update] [name]"
4255       "\n\t\t: Resets color for all, selected or named objects."
4256       "\n\t\t: Alias for vaspects -unsetcolor [name].",
4257                   __FILE__,VAspects,group);
4258
4259   theCommands.Add("vsettransparency",
4260                   "vsettransparency [-noupdate|-update] [name] Coefficient"
4261       "\n\t\t: Sets transparency for all, selected or named objects."
4262       "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
4263       "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
4264                   __FILE__,VAspects,group);
4265
4266   theCommands.Add("vunsettransparency",
4267                   "vunsettransparency [-noupdate|-update] [name]"
4268       "\n\t\t: Resets transparency for all, selected or named objects."
4269       "\n\t\t: Alias for vaspects -unsettransp [name].",
4270                   __FILE__,VAspects,group);
4271
4272   theCommands.Add("vsetmaterial",
4273                   "vsetmaterial [-noupdate|-update] [name] MaterialName"
4274       "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
4275                   __FILE__,VAspects,group);
4276
4277   theCommands.Add("vunsetmaterial",
4278                   "vunsetmaterial [-noupdate|-update] [name]"
4279       "\n\t\t: Alias for vaspects -unsetmaterial [name].",
4280                   __FILE__,VAspects,group);
4281
4282   theCommands.Add("vsetwidth",
4283                   "vsetwidth [-noupdate|-update] [name] width(0->10)"
4284       "\n\t\t: Alias for vaspects -setwidth [name] width.",
4285                   __FILE__,VAspects,group);
4286
4287   theCommands.Add("vunsetwidth",
4288                   "vunsetwidth [-noupdate|-update] [name]"
4289       "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
4290                   __FILE__,VAspects,group);
4291
4292   theCommands.Add("vsetinteriorstyle",
4293                   "vsetinteriorstyle [-noupdate|-update] [name] style"
4294       "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
4295                   __FILE__,VSetInteriorStyle,group);
4296
4297   theCommands.Add("vardis",
4298                   "vardis          : display activeareas",
4299                   __FILE__,VDispAreas,group);
4300
4301   theCommands.Add("varera",
4302                   "varera           : erase activeareas",
4303                   __FILE__,VClearAreas,group);
4304
4305   theCommands.Add("vsensdis",
4306                   "vardisp           : display active entities",
4307                   __FILE__,VDispSensi,group);
4308   theCommands.Add("vsensera",
4309                   "vardisp           : erase  active entities",
4310                   __FILE__,VClearSensi,group);
4311
4312   theCommands.Add("vselprecision",
4313                   "vselprecision : vselprecision [precision_mode [tolerance_value]]",
4314                   __FILE__,VSelPrecision,group);
4315
4316   theCommands.Add("vperf",
4317                   "vperf: vperf  ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
4318                   __FILE__,VPerf,group);
4319
4320   theCommands.Add("vanimation",
4321                   "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
4322                   __FILE__,VAnimation,group);
4323
4324   theCommands.Add("vsetshading",
4325                   "vsetshading  : vsetshading name Quality(default=0.0008) ",
4326                   __FILE__,VShading,group);
4327
4328   theCommands.Add("vunsetshading",
4329                   "vunsetshading :vunsetshading name ",
4330                   __FILE__,VShading,group);
4331
4332   theCommands.Add ("vtexture",
4333                    "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
4334                    "                         [-scale u v]  [-scale off]\n"
4335                    "                         [-origin u v] [-origin off]\n"
4336                    "                         [-repeat u v] [-repeat off]\n"
4337                    "                         [-modulate {on | off}]"
4338                    "                         [-default]'\n"
4339                    " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
4340                    " specifying one of the predefined textures.\n"
4341                    " The options are: \n"
4342                    "  -scale u v : enable texture scaling and set scale factors\n"
4343                    "  -scale off : disable texture scaling\n"
4344                    "  -origin u v : enable texture origin positioning and set the origin\n"
4345                    "  -origin off : disable texture origin positioning\n"
4346                    "  -repeat u v : enable texture repeat and set texture coordinate scaling\n"
4347                    "  -repeat off : disable texture repeat\n"
4348                    "  -modulate {on | off} : enable or disable texture modulation\n"
4349                    "  -default : sets texture mapping default parameters\n"
4350                    "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
4351                    "or 'vtexture NameOfShape ?' to list available textures\n",
4352                     __FILE__, VTexture, group);
4353
4354   theCommands.Add("vtexscale",
4355                   "'vtexscale  NameOfShape ScaleU ScaleV' \n \
4356                    or 'vtexscale NameOfShape ScaleUV' \n \
4357                    or 'vtexscale NameOfShape' to disable scaling\n ",
4358                   __FILE__,VTexture,group);
4359
4360   theCommands.Add("vtexorigin",
4361                   "'vtexorigin NameOfShape UOrigin VOrigin' \n \
4362                    or 'vtexorigin NameOfShape UVOrigin' \n \
4363                    or 'vtexorigin NameOfShape' to disable origin positioning\n ",
4364                   __FILE__,VTexture,group);
4365
4366   theCommands.Add("vtexrepeat",
4367                   "'vtexrepeat  NameOfShape URepeat VRepeat' \n \
4368                    or 'vtexrepeat NameOfShape UVRepeat \n \
4369                    or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
4370                   VTexture,group);
4371
4372   theCommands.Add("vtexdefault",
4373                   "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
4374                   VTexture,group);
4375
4376   theCommands.Add("vsetam",
4377                   "vsetActivatedModes: vsetam mode(1->7)  ",
4378                   __FILE__,VActivatedMode,group);
4379
4380   theCommands.Add("vunsetam",
4381                   "vunsetActivatedModes:   vunsetam  ",
4382                   __FILE__,VActivatedMode,group);
4383
4384   theCommands.Add("vstate",
4385       "vstate [name1] ... [nameN]"
4386       "\n\t\t: Reports show/hidden state for selected or named objects",
4387                   __FILE__,VState,group);
4388
4389   theCommands.Add("vpickshapes",
4390                   "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
4391                   __FILE__,VPickShape,group);
4392
4393   theCommands.Add("vtypes",
4394                   "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
4395                   VIOTypes,group);
4396
4397   theCommands.Add("vsettransmode",
4398                   "vsettransmode   : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
4399                   __FILE__,VSetTransMode,group);
4400
4401   theCommands.Add("vr", "vr : reading of the shape",
4402                   __FILE__,vr, group);
4403
4404 }
4405
4406 //=====================================================================
4407 //========================= for testing Draft and Rib =================
4408 //=====================================================================
4409 #include <BRepOffsetAPI_MakeThickSolid.hxx>
4410 #include <DBRep.hxx>
4411 #include <TopoDS_Face.hxx>
4412 #include <gp_Pln.hxx>
4413 #include <AIS_KindOfSurface.hxx>
4414 #include <BRepOffsetAPI_DraftAngle.hxx>
4415 #include <Precision.hxx>
4416 #include <BRepAlgo.hxx>
4417 #include <OSD_Environment.hxx>
4418 #include <DrawTrSurf.hxx>
4419 //#include <DbgTools.hxx>
4420 //#include <FeatAlgo_MakeLinearForm.hxx>
4421
4422
4423
4424
4425 //=======================================================================
4426 //function : IsValid
4427 //purpose  :
4428 //=======================================================================
4429 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
4430                                 const TopoDS_Shape& theResult,
4431                                 const Standard_Boolean closedSolid,
4432                                 const Standard_Boolean GeomCtrl)
4433 {
4434   OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
4435   TCollection_AsciiString checkValid = check.Value();
4436   Standard_Boolean ToCheck = Standard_True;
4437   if (!checkValid.IsEmpty()) {
4438 #ifdef DEB
4439     cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
4440 #endif
4441     if ( checkValid=="true" || checkValid=="TRUE" ) {
4442       ToCheck= Standard_False;
4443     }
4444   } else {
4445 #ifdef DEB
4446     cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
4447 #endif
4448   }
4449   Standard_Boolean IsValid = Standard_True;
4450   if (ToCheck)
4451     IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
4452   return IsValid;
4453
4454 }
4455
4456 //===============================================================================
4457 // TDraft : test draft, uses AIS Viewer
4458 // Solid Face Plane Angle  Reverse
4459 //===============================================================================
4460 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4461 {
4462   if (argc < 5) return 1;
4463 // argv[1] - TopoDS_Shape Solid
4464 // argv[2] - TopoDS_Shape Face
4465 // argv[3] - TopoDS_Shape Plane
4466 // argv[4] - Standard_Real Angle
4467 // argv[5] - Standard_Integer Reverse
4468
4469 //  Sprintf(prefix, argv[1]);
4470   Standard_Real anAngle = 0;
4471   Standard_Boolean Rev = Standard_False;
4472   Standard_Integer rev = 0;
4473   TopoDS_Shape Solid  = GetShapeFromName(argv[1]);
4474   TopoDS_Shape face   = GetShapeFromName(argv[2]);
4475   TopoDS_Face Face    = TopoDS::Face(face);
4476   TopoDS_Shape Plane  = GetShapeFromName(argv[3]);
4477   if (Plane.IsNull ()) {
4478     di << "TEST : Plane is NULL" << "\n";
4479     return 1;
4480   }
4481   anAngle = Draw::Atof(argv[4]);
4482   anAngle = 2*M_PI * anAngle / 360.0;
4483   gp_Pln aPln;
4484   Handle( Geom_Surface )aSurf;
4485   AIS_KindOfSurface aSurfType;
4486   Standard_Real Offset;
4487   gp_Dir aDir;
4488   if(argc > 4) { // == 5
4489     rev = Draw::Atoi(argv[5]);
4490     Rev = (rev)? Standard_True : Standard_False;
4491   }
4492
4493   TopoDS_Face face2 = TopoDS::Face(Plane);
4494   if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
4495     {
4496       di << "TEST : Can't find plane" << "\n";
4497       return 1;
4498     }
4499
4500   aDir = aPln.Axis().Direction();
4501   if (!aPln.Direct())
4502     aDir.Reverse();
4503   if (Plane.Orientation() == TopAbs_REVERSED)
4504     aDir.Reverse();
4505   di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
4506
4507   BRepOffsetAPI_DraftAngle Draft (Solid);
4508
4509   if(Abs(anAngle)< Precision::Angular()) {
4510     di << "TEST : NULL angle" << "\n";
4511     return 1;}
4512
4513   if(Rev) anAngle = - anAngle;
4514   Draft.Add (Face, aDir, anAngle, aPln);
4515   Draft.Build ();
4516   if (!Draft.IsDone())  {
4517     di << "TEST : Draft Not DONE " << "\n";
4518     return 1;
4519   }
4520   TopTools_ListOfShape Larg;
4521   Larg.Append(Solid);
4522   if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
4523     di << "TEST : DesignAlgo returns Not valid" << "\n";
4524     return 1;
4525   }
4526
4527   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4528   Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
4529
4530   if ( !ais.IsNull() ) {
4531     ais->SetColor(DEFAULT_COLOR);
4532     ais->SetMaterial(DEFAULT_MATERIAL);
4533     // Display the AIS_Shape without redraw
4534     Ctx->Display(ais, Standard_False);
4535
4536     const char *Name = "draft1";
4537     Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
4538     if (IsBound) {
4539       Handle(AIS_InteractiveObject) an_object =
4540         Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
4541       if (!an_object.IsNull()) {
4542         Ctx->Remove(an_object,
4543                     Standard_True) ;
4544         GetMapOfAIS().UnBind2(Name) ;
4545       }
4546     }
4547     GetMapOfAIS().Bind(ais, Name);
4548 //  DBRep::Set("draft", ais->Shape());
4549   }
4550   Ctx->Display(ais, Standard_True);
4551   return 0;
4552 }
4553
4554 //==============================================================================
4555 //function : splitParameter
4556 //purpose  : Split parameter string to parameter name and parameter value
4557 //==============================================================================
4558 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
4559                                              TCollection_AsciiString&       theName,
4560                                              TCollection_AsciiString&       theValue)
4561 {
4562   Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
4563
4564   if (aParamNameEnd == 0)
4565   {
4566     return Standard_False;
4567   }
4568
4569   TCollection_AsciiString aString (theString);
4570   if (aParamNameEnd != 0)
4571   {
4572     theValue = aString.Split (aParamNameEnd);
4573     aString.Split (aString.Length() - 1);
4574     theName = aString;
4575   }
4576
4577   return Standard_True;
4578 }
4579
4580 //============================================================================
4581 //  MyCommands
4582 //============================================================================
4583 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
4584 {
4585
4586   DrawTrSurf::BasicCommands(theCommands);
4587   const char* group = "Check Features Operations commands";
4588
4589   theCommands.Add("Draft","Draft    Solid Face Plane Angle Reverse",
4590                   __FILE__,
4591                   &TDraft,group); //Draft_Modification
4592 }
4593
4594 //==============================================================================
4595 // ViewerTest::Factory
4596 //==============================================================================
4597 void ViewerTest::Factory(Draw_Interpretor& theDI)
4598 {
4599   // definition of Viewer Command
4600   ViewerTest::Commands(theDI);
4601   ViewerTest::AviCommands(theDI);
4602
4603 #ifdef DEB
4604       theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
4605 #endif
4606 }
4607
4608 // Declare entry point PLUGINFACTORY
4609 DPLUGIN(ViewerTest)