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