0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[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 <ViewerTest_CmdParser.hxx>
29
30 #include <TopLoc_Location.hxx>
31 #include <TopTools_HArray1OfShape.hxx>
32 #include <TColStd_HArray1OfTransient.hxx>
33 #include <TColStd_SequenceOfAsciiString.hxx>
34 #include <TColStd_HSequenceOfAsciiString.hxx>
35 #include <TColStd_MapOfTransient.hxx>
36 #include <OSD_Timer.hxx>
37 #include <Geom_Axis2Placement.hxx>
38 #include <Geom_Axis1Placement.hxx>
39 #include <gp_Trsf.hxx>
40 #include <TopExp_Explorer.hxx>
41 #include <BRepAdaptor_Curve.hxx>
42 #include <StdSelect_ShapeTypeFilter.hxx>
43 #include <AIS.hxx>
44 #include <AIS_ColoredShape.hxx>
45 #include <AIS_InteractiveObject.hxx>
46 #include <AIS_Trihedron.hxx>
47 #include <AIS_Axis.hxx>
48 #include <AIS_Relation.hxx>
49 #include <AIS_TypeFilter.hxx>
50 #include <AIS_SignatureFilter.hxx>
51 #include <AIS_LocalContext.hxx>
52 #include <AIS_ListOfInteractive.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <Aspect_InteriorStyle.hxx>
55 #include <Aspect_Window.hxx>
56 #include <Graphic3d_AspectFillArea3d.hxx>
57 #include <Graphic3d_AspectLine3d.hxx>
58 #include <Graphic3d_CStructure.hxx>
59 #include <Graphic3d_TextureRoot.hxx>
60 #include <Image_AlienPixMap.hxx>
61 #include <Prs3d_Drawer.hxx>
62 #include <Prs3d_ShadingAspect.hxx>
63 #include <Prs3d_IsoAspect.hxx>
64 #include <Prs3d_PointAspect.hxx>
65 #include <Select3D_SensitiveWire.hxx>
66 #include <Select3D_SensitivePrimitiveArray.hxx>
67 #include <SelectMgr_EntityOwner.hxx>
68 #include <StdSelect_BRepOwner.hxx>
69 #include <StdSelect_ViewerSelector3d.hxx>
70 #include <TopTools_MapOfShape.hxx>
71 #include <ViewerTest_AutoUpdater.hxx>
72
73 #include <stdio.h>
74
75 #include <Draw_Interpretor.hxx>
76 #include <TCollection_AsciiString.hxx>
77 #include <Draw_PluginMacro.hxx>
78
79 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
80
81 #include <Quantity_Color.hxx>
82 #include <Quantity_NameOfColor.hxx>
83
84 #include <Graphic3d_NameOfMaterial.hxx>
85
86 #define DEFAULT_COLOR              Quantity_NOC_GOLDENROD
87 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
88 #define DEFAULT_MATERIAL           Graphic3d_NOM_BRASS
89
90 //=======================================================================
91 //function : GetColorFromName
92 //purpose  : get the Quantity_NameOfColor from a string
93 //=======================================================================
94
95 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
96 {
97   Quantity_NameOfColor aColor = DEFAULT_COLOR;
98   Quantity_Color::ColorFromName (theName, aColor);
99   return aColor;
100 }
101
102 //=======================================================================
103 //function : ParseColor
104 //purpose  :
105 //=======================================================================
106
107 Standard_Integer ViewerTest::ParseColor (Standard_Integer  theArgNb,
108                                          const char**      theArgVec,
109                                          Quantity_Color&   theColor)
110 {
111   Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
112   if (theArgNb >= 1
113    && Quantity_Color::ColorFromName (theArgVec[0], aColor))
114   {
115     theColor = aColor;
116     return 1;
117   }
118   else if (theArgNb >= 3)
119   {
120     const TCollection_AsciiString anRgbStr[3] =
121     {
122       theArgVec[0],
123       theArgVec[1],
124       theArgVec[2]
125     };
126     if (!anRgbStr[0].IsRealValue()
127      || !anRgbStr[1].IsRealValue()
128      || !anRgbStr[2].IsRealValue())
129     {
130       return 0;
131     }
132
133     Graphic3d_Vec4d anRgb;
134     anRgb.x() = anRgbStr[0].RealValue();
135     anRgb.y() = anRgbStr[1].RealValue();
136     anRgb.z() = anRgbStr[2].RealValue();
137     if (anRgb.x() < 0.0 || anRgb.x() > 1.0
138      || anRgb.y() < 0.0 || anRgb.y() > 1.0
139      || anRgb.z() < 0.0 || anRgb.z() > 1.0)
140     {
141       std::cout << "Error: RGB color values should be within range 0..1!\n";
142       return 0;
143     }
144
145     theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
146     return 3;
147   }
148
149   return 0;
150 }
151
152 //=======================================================================
153 //function : ParseOnOff
154 //purpose  :
155 //=======================================================================
156 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString  theArg,
157                                          Standard_Boolean& theIsOn)
158 {
159   TCollection_AsciiString aFlag(theArg);
160   aFlag.LowerCase();
161   if (aFlag == "on"
162    || aFlag == "1")
163   {
164     theIsOn = Standard_True;
165     return Standard_True;
166   }
167   else if (aFlag == "off"
168         || aFlag == "0")
169   {
170     theIsOn = Standard_False;
171     return Standard_True;
172   }
173   return Standard_False;
174 }
175
176 //=======================================================================
177 //function : GetTypeNames
178 //purpose  :
179 //=======================================================================
180 static const char** GetTypeNames()
181 {
182   static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
183                           "Shape","ConnectedShape","MultiConn.Shape",
184                           "ConnectedInter.","MultiConn.",
185                           "Constraint","Dimension"};
186   static const char** ThePointer = names;
187   return ThePointer;
188 }
189
190 //=======================================================================
191 //function : GetTypeAndSignfromString
192 //purpose  :
193 //=======================================================================
194 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
195 {
196   const char ** thefullnames = GetTypeNames();
197   Standard_Integer index(-1);
198
199   for(Standard_Integer i=0;i<=13 && index==-1;i++)
200     if(!strcasecmp(name,thefullnames[i]))
201       index = i;
202
203   if(index ==-1){
204     TheType = AIS_KOI_None;
205     TheSign = -1;
206     return;
207   }
208
209   if(index<=6){
210     TheType = AIS_KOI_Datum;
211     TheSign = index+1;
212   }
213   else if (index <=9){
214     TheType = AIS_KOI_Shape;
215     TheSign = index-7;
216   }
217   else if(index<=11){
218     TheType = AIS_KOI_Object;
219     TheSign = index-10;
220   }
221   else{
222     TheType = AIS_KOI_Relation;
223     TheSign = index-12;
224   }
225
226 }
227
228
229
230 #include <string.h>
231 #include <Draw_Interpretor.hxx>
232 #include <Draw.hxx>
233 #include <Draw_Appli.hxx>
234 #include <DBRep.hxx>
235
236
237 #include <TCollection_AsciiString.hxx>
238 #include <V3d_Viewer.hxx>
239 #include <V3d_View.hxx>
240 #include <V3d.hxx>
241
242 #include <AIS_InteractiveContext.hxx>
243 #include <AIS_Shape.hxx>
244 #include <AIS_TexturedShape.hxx>
245 #include <AIS_DisplayMode.hxx>
246 #include <TColStd_MapOfInteger.hxx>
247 #include <AIS_MapOfInteractive.hxx>
248 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
249 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
250 #include <ViewerTest_EventManager.hxx>
251
252 #include <TopoDS_Solid.hxx>
253 #include <BRepTools.hxx>
254 #include <BRep_Builder.hxx>
255 #include <TopAbs_ShapeEnum.hxx>
256
257 #include <TopoDS.hxx>
258 #include <BRep_Tool.hxx>
259
260
261 #include <Draw_Window.hxx>
262 #include <AIS_ListIteratorOfListOfInteractive.hxx>
263 #include <AIS_ListOfInteractive.hxx>
264 #include <AIS_DisplayMode.hxx>
265 #include <TopTools_ListOfShape.hxx>
266 #include <BRepOffsetAPI_MakeThickSolid.hxx>
267 #include <BRepOffset.hxx>
268
269 //==============================================================================
270 //  VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
271 //==============================================================================
272 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
273   static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
274   return TheMap;
275 }
276
277 //=======================================================================
278 //function : Display
279 //purpose  :
280 //=======================================================================
281 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString&       theName,
282                                       const Handle(AIS_InteractiveObject)& theObject,
283                                       const Standard_Boolean               theToUpdate,
284                                       const Standard_Boolean               theReplaceIfExists)
285 {
286   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
287   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
288   if (aCtx.IsNull())
289   {
290     std::cout << "Error: AIS context is not available.\n";
291     return Standard_False;
292   }
293
294   if (aMap.IsBound2 (theName))
295   {
296     if (!theReplaceIfExists)
297     {
298       std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
299                 << "Please use another name.\n";
300       return Standard_False;
301     }
302
303     Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
304     if (!anOldObj.IsNull())
305     {
306       aCtx->Remove (anOldObj, Standard_True);
307     }
308     aMap.UnBind2 (theName);
309   }
310
311   if (theObject.IsNull())
312   {
313     // object with specified name has been already unbound
314     return Standard_True;
315   }
316
317   // unbind AIS object if it was bound with another name
318   aMap.UnBind1 (theObject);
319
320   // can be registered without rebinding
321   aMap.Bind (theObject, theName);
322   aCtx->Display (theObject, theToUpdate);
323   return Standard_True;
324 }
325
326 //! Alias for ViewerTest::Display(), compatibility with old code.
327 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString&       theName,
328                                                     const Handle(AIS_InteractiveObject)& theObject,
329                                                     Standard_Boolean theReplaceIfExists = Standard_True)
330 {
331   return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
332 }
333
334 static TColStd_MapOfInteger theactivatedmodes(8);
335 static TColStd_ListOfTransient theEventMgrs;
336
337 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
338                                 const Handle(AIS_InteractiveContext)& Ctx)
339 {
340   theEventMgrs.Clear();
341   theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
342 }
343
344 static Handle(V3d_View)&  a3DView()
345 {
346   static Handle(V3d_View) Viou;
347   return Viou;
348 }
349
350
351 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
352   static Handle(AIS_InteractiveContext) aContext;
353   return aContext;
354 }
355
356 const Handle(V3d_View)& ViewerTest::CurrentView()
357 {
358   return a3DView();
359 }
360 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
361 {
362   a3DView() = V;
363 }
364
365 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
366 {
367   return TheAISContext();
368 }
369
370 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
371 {
372   TheAISContext() = aCtx;
373   ViewerTest::ResetEventManager();
374 }
375
376 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
377 {
378   return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
379 }
380
381 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
382 {
383   return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
384 }
385
386
387 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
388   theEventMgrs.Prepend(EM);
389 }
390
391 void ViewerTest::UnsetEventManager()
392 {
393   theEventMgrs.RemoveFirst();
394 }
395
396
397 void ViewerTest::ResetEventManager()
398 {
399   const Handle(V3d_View) aView = ViewerTest::CurrentView();
400   VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
401 }
402
403 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
404 {
405   Handle(ViewerTest_EventManager) EM;
406   if(theEventMgrs.IsEmpty()) return EM;
407   Handle(Standard_Transient) Tr =  theEventMgrs.First();
408   EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
409   return EM;
410 }
411
412 //=======================================================================
413 //function : Get Context and active view
414 //purpose  :
415 //=======================================================================
416 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
417                                        Handle(V3d_View)&               theView)
418 {
419   theCtx  = ViewerTest::GetAISContext();
420   theView = ViewerTest::CurrentView();
421   if (theCtx.IsNull()
422    || theView.IsNull())
423   {
424     std::cout << "Error: cannot find an active view!\n";
425     return Standard_False;
426   }
427   return Standard_True;
428 }
429
430 //==============================================================================
431 //function : GetShapeFromName
432 //purpose  : Compute an Shape from a draw variable or a file name
433 //==============================================================================
434
435 static TopoDS_Shape GetShapeFromName(const char* name)
436 {
437   TopoDS_Shape S = DBRep::Get(name);
438
439   if ( S.IsNull() ) {
440         BRep_Builder aBuilder;
441         BRepTools::Read( S, name, aBuilder);
442   }
443
444   return S;
445 }
446
447 //==============================================================================
448 //function : GetAISShapeFromName
449 //purpose  : Compute an AIS_Shape from a draw variable or a file name
450 //==============================================================================
451 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
452 {
453   Handle(AIS_Shape) retsh;
454
455   if(GetMapOfAIS().IsBound2(name)){
456     const Handle(AIS_InteractiveObject) IO =
457       Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
458     if (!IO.IsNull()) {
459       if(IO->Type()==AIS_KOI_Shape) {
460         if(IO->Signature()==0){
461           retsh = Handle(AIS_Shape)::DownCast (IO);
462         }
463         else
464           cout << "an Object which is not an AIS_Shape "
465             "already has this name!!!"<<endl;
466       }
467     }
468     return retsh;
469   }
470
471
472   TopoDS_Shape S = GetShapeFromName(name);
473   if ( !S.IsNull() ) {
474     retsh = new AIS_Shape(S);
475   }
476   return retsh;
477 }
478
479
480 //==============================================================================
481 //function : Clear
482 //purpose  : Remove all the object from the viewer
483 //==============================================================================
484 void ViewerTest::Clear()
485 {
486   if ( !a3DView().IsNull() ) {
487     if (TheAISContext()->HasOpenedContext())
488       TheAISContext()->CloseLocalContext();
489     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
490     while ( it.More() ) {
491       cout << "Remove " << it.Key2() << endl;
492       const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
493       TheAISContext()->Remove(anObj,Standard_False);
494       it.Next();
495     }
496     TheAISContext()->RebuildSelectionStructs();
497     TheAISContext()->UpdateCurrentViewer();
498     GetMapOfAIS().Clear();
499   }
500 }
501
502 //==============================================================================
503 //function : StandardModesActivation
504 //purpose  : Activate a selection mode, vertex, edge, wire ..., in a local
505 //           Context
506 //==============================================================================
507 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
508 {
509   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
510   if(mode==0) {
511     if (TheAISContext()->HasOpenedContext())
512       aContext->CloseLocalContext();
513   } else {
514
515     if(!aContext->HasOpenedContext()) {
516       // To unhilight the preselected object
517       aContext->UnhilightSelected(Standard_False);
518       // Open a local Context in order to be able to select subshape from
519       // the selected shape if any or for all if there is no selection
520       if (!aContext->FirstSelectedObject().IsNull()){
521         aContext->OpenLocalContext(Standard_False);
522
523         for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
524           aContext->Load(       aContext->SelectedInteractive(),-1,Standard_True);
525         }
526       }
527       else
528         aContext->OpenLocalContext();
529     }
530
531     const char *cmode="???";
532
533     switch (mode) {
534     case 0: cmode = "Shape"; break;
535     case 1: cmode = "Vertex"; break;
536     case 2: cmode = "Edge"; break;
537     case 3: cmode = "Wire"; break;
538     case 4: cmode = "Face"; break;
539     case 5: cmode = "Shell"; break;
540     case 6: cmode = "Solid"; break;
541     case 7: cmode = "Compsolid"; break;
542     case 8: cmode = "Compound"; break;
543     }
544
545     if(theactivatedmodes.Contains(mode))
546       { // Desactivate
547         aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
548         theactivatedmodes.Remove(mode);
549         cout<<"Mode "<< cmode <<" OFF"<<endl;
550       }
551     else
552       { // Activate
553         aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
554         theactivatedmodes.Add(mode);
555         cout<<"Mode "<< cmode << " ON" << endl;
556       }
557   }
558 }
559
560 //==============================================================================
561 //function : CopyIsoAspect
562 //purpose  : Returns copy Prs3d_IsoAspect with new number of isolines.
563 //==============================================================================
564 static Handle(Prs3d_IsoAspect) CopyIsoAspect
565       (const Handle(Prs3d_IsoAspect) &theIsoAspect,
566        const Standard_Integer theNbIsos)
567 {
568   Quantity_Color    aColor = theIsoAspect->Aspect()->Color();
569   Aspect_TypeOfLine aType  = theIsoAspect->Aspect()->Type();
570   Standard_Real     aWidth = theIsoAspect->Aspect()->Width();
571
572   Handle(Prs3d_IsoAspect) aResult =
573     new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
574
575   return aResult;
576 }
577
578 //==============================================================================
579 //function : visos
580 //purpose  : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
581 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
582 //==============================================================================
583 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
584 {
585   if (TheAISContext().IsNull()) {
586     di << argv[0] << " Call 'vinit' before!\n";
587     return 1;
588   }
589
590   if (argc <= 1) {
591     di << "Current number of isos : " <<
592       TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
593       TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
594     di << "IsoOnPlane mode is " <<
595       (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
596     di << "IsoOnTriangulation mode is " <<
597       (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
598     return 0;
599   }
600
601   Standard_Integer aLastInd = argc - 1;
602   Standard_Boolean isChanged = Standard_False;
603   Standard_Integer aNbUIsos = 0;
604   Standard_Integer aNbVIsos = 0;
605
606   if (aLastInd >= 3) {
607     Standard_Boolean isIsoOnPlane = Standard_False;
608
609     if (strcmp(argv[aLastInd], "1") == 0) {
610       isIsoOnPlane = Standard_True;
611       isChanged    = Standard_True;
612     } else if (strcmp(argv[aLastInd], "0") == 0) {
613       isIsoOnPlane = Standard_False;
614       isChanged    = Standard_True;
615     }
616
617     if (isChanged) {
618       aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
619       aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
620       aLastInd -= 3;
621
622       di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
623       di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
624
625       TheAISContext()->IsoOnPlane(isIsoOnPlane);
626
627       if (aLastInd == 0) {
628         // If there are no shapes provided set the default numbers.
629         TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
630         TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
631       }
632     }
633   }
634
635   Standard_Integer i;
636
637   for (i = 1; i <= aLastInd; i++) {
638     TCollection_AsciiString name(argv[i]);
639     Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
640
641     if (IsBound) {
642       const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
643       if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
644         const Handle(AIS_InteractiveObject) aShape =
645         Handle(AIS_InteractiveObject)::DownCast (anObj);
646         Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
647         Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
648         Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
649
650         if (isChanged) {
651           CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
652           CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
653           TheAISContext()->SetLocalAttributes
654                   (aShape, CurDrawer, Standard_False);
655           TheAISContext()->Redisplay(aShape);
656         } else {
657           di << "Number of isos for " << argv[i] << " : "
658              << aUIso->Number() << " " << aVIso->Number() << "\n";
659         }
660       } else {
661         di << argv[i] << ": Not an AIS interactive object!\n";
662       }
663     } else {
664       di << argv[i] << ": Use 'vdisplay' before\n";
665     }
666   }
667
668   if (isChanged) {
669     TheAISContext()->UpdateCurrentViewer();
670   }
671
672   return 0;
673 }
674
675 static Standard_Integer VDispSensi (Draw_Interpretor& ,
676                                     Standard_Integer  theArgNb,
677                                     Standard_CString* )
678 {
679   if (theArgNb > 1)
680   {
681     std::cout << "Error: wrong syntax!\n";
682     return 1;
683   }
684
685   Handle(AIS_InteractiveContext) aCtx;
686   Handle(V3d_View)               aView;
687   if (!getCtxAndView (aCtx, aView))
688   {
689     return 1;
690   }
691
692   aCtx->DisplayActiveSensitive (aView);
693   return 0;
694
695 }
696
697 static Standard_Integer VClearSensi (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   aCtx->ClearActiveSensitive (aView);
714   return 0;
715 }
716
717 //==============================================================================
718 //function : VDir
719 //purpose  : To list the displayed object with their attributes
720 //==============================================================================
721 static int VDir (Draw_Interpretor& theDI,
722                  Standard_Integer ,
723                  const char** )
724 {
725   if (!a3DView().IsNull())
726   {
727     return 0;
728   }
729
730   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
731        anIter.More(); anIter.Next())
732   {
733     theDI << "\t" << anIter.Key2().ToCString() << "\n";
734   }
735   return 0;
736 }
737
738 //! Auxiliary enumeration
739 enum ViewerTest_StereoPair
740 {
741   ViewerTest_SP_Single,
742   ViewerTest_SP_SideBySide,
743   ViewerTest_SP_OverUnder
744 };
745
746 //==============================================================================
747 //function : VDump
748 //purpose  : To dump the active view snapshot to image file
749 //==============================================================================
750 static Standard_Integer VDump (Draw_Interpretor& theDI,
751                                Standard_Integer  theArgNb,
752                                Standard_CString* theArgVec)
753 {
754   if (theArgNb < 2)
755   {
756     std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
757     return 1;
758   }
759
760   Standard_Integer      anArgIter   = 1;
761   Standard_CString      aFilePath   = theArgVec[anArgIter++];
762   ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
763   V3d_ImageDumpOptions  aParams;
764   aParams.BufferType    = Graphic3d_BT_RGB;
765   aParams.StereoOptions = V3d_SDO_MONO;
766   for (; anArgIter < theArgNb; ++anArgIter)
767   {
768     TCollection_AsciiString anArg (theArgVec[anArgIter]);
769     anArg.LowerCase();
770     if (anArg == "-buffer")
771     {
772       if (++anArgIter >= theArgNb)
773       {
774         std::cout << "Error: wrong syntax at '" << anArg << "'\n";
775         return 1;
776       }
777
778       TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
779       aBufArg.LowerCase();
780       if (aBufArg == "rgba")
781       {
782         aParams.BufferType = Graphic3d_BT_RGBA;
783       }
784       else if (aBufArg == "rgb")
785       {
786         aParams.BufferType = Graphic3d_BT_RGB;
787       }
788       else if (aBufArg == "depth")
789       {
790         aParams.BufferType = Graphic3d_BT_Depth;
791       }
792       else
793       {
794         std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
795         return 1;
796       }
797     }
798     else if (anArg == "-stereo")
799     {
800       if (++anArgIter >= theArgNb)
801       {
802         std::cout << "Error: wrong syntax at '" << anArg << "'\n";
803         return 1;
804       }
805
806       TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
807       aStereoArg.LowerCase();
808       if (aStereoArg == "l"
809        || aStereoArg == "left")
810       {
811         aParams.StereoOptions = V3d_SDO_LEFT_EYE;
812       }
813       else if (aStereoArg == "r"
814             || aStereoArg == "right")
815       {
816         aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
817       }
818       else if (aStereoArg == "mono")
819       {
820         aParams.StereoOptions = V3d_SDO_MONO;
821       }
822       else if (aStereoArg == "blended"
823             || aStereoArg == "blend"
824             || aStereoArg == "stereo")
825       {
826         aParams.StereoOptions = V3d_SDO_BLENDED;
827       }
828       else if (aStereoArg == "sbs"
829             || aStereoArg == "sidebyside")
830       {
831         aStereoPair = ViewerTest_SP_SideBySide;
832       }
833       else if (aStereoArg == "ou"
834             || aStereoArg == "overunder")
835       {
836         aStereoPair = ViewerTest_SP_OverUnder;
837       }
838       else
839       {
840         std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
841         return 1;
842       }
843     }
844     else if (anArg == "-rgba"
845           || anArg ==  "rgba")
846     {
847       aParams.BufferType = Graphic3d_BT_RGBA;
848     }
849     else if (anArg == "-rgb"
850           || anArg ==  "rgb")
851     {
852       aParams.BufferType = Graphic3d_BT_RGB;
853     }
854     else if (anArg == "-depth"
855           || anArg ==  "depth")
856     {
857       aParams.BufferType = Graphic3d_BT_Depth;
858     }
859     else if (anArg == "-width"
860           || anArg ==  "width"
861           || anArg ==  "sizex")
862     {
863       if (aParams.Width != 0)
864       {
865         std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
866         return 1;
867       }
868       else if (++anArgIter >= theArgNb)
869       {
870         std::cout << "Error: integer value is expected right after 'width'\n";
871         return 1;
872       }
873       aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
874     }
875     else if (anArg == "-height"
876           || anArg ==  "height"
877           || anArg ==  "-sizey")
878     {
879       if (aParams.Height != 0)
880       {
881         std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
882         return 1;
883       }
884       else if (++anArgIter >= theArgNb)
885       {
886         std::cout << "Error: integer value is expected right after 'height'\n";
887         return 1;
888       }
889       aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
890     }
891     else if (anArg == "-tile"
892           || anArg == "-tilesize")
893     {
894       if (++anArgIter >= theArgNb)
895       {
896         std::cout << "Error: integer value is expected right after 'tileSize'\n";
897         return 1;
898       }
899       aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
900     }
901     else
902     {
903       std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
904       return 1;
905     }
906   }
907   if ((aParams.Width <= 0 && aParams.Height >  0)
908    || (aParams.Width >  0 && aParams.Height <= 0))
909   {
910     std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
911     return 1;
912   }
913
914   Handle(V3d_View) aView = ViewerTest::CurrentView();
915   if (aView.IsNull())
916   {
917     std::cout << "Error: cannot find an active view!\n";
918     return 1;
919   }
920
921   if (aParams.Width <= 0 || aParams.Height <= 0)
922   {
923     aView->Window()->Size (aParams.Width, aParams.Height);
924   }
925
926   Image_AlienPixMap aPixMap;
927
928   bool isBigEndian = Image_PixMap::IsBigEndianHost();
929   Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
930   switch (aParams.BufferType)
931   {
932     case Graphic3d_BT_RGB:   aFormat = isBigEndian ? Image_PixMap::ImgRGB  : Image_PixMap::ImgBGR;  break;
933     case Graphic3d_BT_RGBA:  aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
934     case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
935   }
936
937   switch (aStereoPair)
938   {
939     case ViewerTest_SP_Single:
940     {
941       if (!aView->ToPixMap (aPixMap, aParams))
942       {
943         theDI << "Fail: view dump failed!\n";
944         return 0;
945       }
946       else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
947             || aPixMap.SizeY() != Standard_Size(aParams.Height))
948       {
949         theDI << "Fail: dumped dimensions "    << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
950               << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
951       }
952       break;
953     }
954     case ViewerTest_SP_SideBySide:
955     {
956       if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
957       {
958         theDI << "Fail: not enough memory for image allocation!\n";
959         return 0;
960       }
961
962       Image_PixMap aPixMapL, aPixMapR;
963       aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
964                             aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
965       aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
966                             aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
967
968       aParams.StereoOptions = V3d_SDO_LEFT_EYE;
969       Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
970       aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
971       isOk          = isOk && aView->ToPixMap (aPixMapR, aParams);
972       if (!isOk)
973       {
974         theDI << "Fail: view dump failed!\n";
975         return 0;
976       }
977       break;
978     }
979     case ViewerTest_SP_OverUnder:
980     {
981       if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
982       {
983         theDI << "Fail: not enough memory for image allocation!\n";
984         return 0;
985       }
986
987       Image_PixMap aPixMapL, aPixMapR;
988       aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
989                             aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
990       aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
991                             aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
992
993       aParams.StereoOptions = V3d_SDO_LEFT_EYE;
994       Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
995       aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
996       isOk          = isOk && aView->ToPixMap (aPixMapR, aParams);
997       if (!isOk)
998       {
999         theDI << "Fail: view dump failed!\n";
1000         return 0;
1001       }
1002       break;
1003     }
1004   }
1005
1006   if (!aPixMap.Save (aFilePath))
1007   {
1008     theDI << "Fail: image can not be saved!\n";
1009   }
1010   return 0;
1011 }
1012
1013 enum TypeOfDispOperation
1014 {
1015   TypeOfDispOperation_SetDispMode,
1016   TypeOfDispOperation_UnsetDispMode
1017 };
1018
1019 //! Displays,Erase...
1020 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1021                                                 const Standard_Integer theMode,
1022                                                 const TypeOfDispOperation theType,
1023                                                 const Standard_Boolean theToUpdate)
1024 {
1025   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1026   switch (theType)
1027   {
1028     case TypeOfDispOperation_SetDispMode:
1029     {
1030       if (!thePrs.IsNull())
1031       {
1032         aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1033       }
1034       else
1035       {
1036         aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1037       }
1038       break;
1039     }
1040     case TypeOfDispOperation_UnsetDispMode:
1041     {
1042       if (!thePrs.IsNull())
1043       {
1044         aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1045       }
1046       else
1047       {
1048         aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1049       }
1050       break;
1051     }
1052   }
1053 }
1054
1055 //=======================================================================
1056 //function :
1057 //purpose  :
1058 //=======================================================================
1059 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1060 {
1061   if (argc < 1
1062    || argc > 3)
1063   {
1064     std::cout << "Syntax error: wrong number of arguments\n";
1065     return 1;
1066   }
1067
1068   TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1069                             ? TypeOfDispOperation_UnsetDispMode
1070                             : TypeOfDispOperation_SetDispMode;
1071   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1072   if (aType == TypeOfDispOperation_UnsetDispMode)
1073   {
1074     if (argc == 1)
1075     {
1076       if (aCtx->NbSelected() == 0)
1077       {
1078         VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1079       }
1080       else
1081       {
1082         for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1083         {
1084           VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1085         }
1086       }
1087       aCtx->UpdateCurrentViewer();
1088     }
1089     else
1090     {
1091       TCollection_AsciiString aName = argv[1];
1092       if (GetMapOfAIS().IsBound2 (aName))
1093       {
1094         Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1095         if (!aPrs.IsNull())
1096         {
1097           VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1098         }
1099       }
1100     }
1101   }
1102   else if (argc == 2)
1103   {
1104     Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1105     if (aCtx->NbSelected() == 0
1106      && aType == TypeOfDispOperation_SetDispMode)
1107     {
1108       VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1109     }
1110     for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1111     {
1112       VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1113     }
1114     aCtx->UpdateCurrentViewer();
1115   }
1116   else
1117   {
1118     Handle(AIS_InteractiveObject) aPrs;
1119     TCollection_AsciiString aName (argv[1]);
1120     if (GetMapOfAIS().IsBound2 (aName))
1121     {
1122       aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1123     }
1124     if (!aPrs.IsNull())
1125     {
1126       VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1127     }
1128   }
1129   return 0;
1130 }
1131
1132
1133 //=======================================================================
1134 //function :
1135 //purpose  :
1136 //=======================================================================
1137 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1138 {
1139   if(argc==1) return 1;
1140   Standard_Integer On = Draw::Atoi(argv[1]);
1141   const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1142
1143   if(argc==2)
1144   {
1145     TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1146     di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1147     for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1148     {
1149       if(On==1)
1150       {
1151         Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1152       }
1153       else
1154       {
1155         Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1156       }
1157     }
1158
1159     Ctx->UpdateCurrentViewer();
1160   }
1161   else {
1162     Handle(AIS_InteractiveObject) IO;
1163     TCollection_AsciiString name = argv[2];
1164     if(GetMapOfAIS().IsBound2(name)){
1165       IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1166       if (!IO.IsNull()) {
1167         if(On==1)
1168           Ctx->SubIntensityOn(IO);
1169         else
1170           Ctx->SubIntensityOff(IO);
1171       }
1172     }
1173     else return 1;
1174   }
1175   return 0;
1176 }
1177
1178 //! Auxiliary class to iterate presentations from different collections.
1179 class ViewTest_PrsIter
1180 {
1181 public:
1182
1183   //! Create and initialize iterator object.
1184   ViewTest_PrsIter (const TCollection_AsciiString& theName)
1185   : mySource (IterSource_All)
1186   {
1187     NCollection_Sequence<TCollection_AsciiString> aNames;
1188     if (!theName.IsEmpty())
1189     aNames.Append (theName);
1190     Init (aNames);
1191   }
1192
1193   //! Create and initialize iterator object.
1194   ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1195   : mySource (IterSource_All)
1196   {
1197     Init (theNames);
1198   }
1199
1200   //! Initialize the iterator.
1201   void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1202   {
1203     Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1204     mySeq = theNames;
1205     mySelIter.Nullify();
1206     myCurrent.Nullify();
1207     myCurrentTrs.Nullify();
1208     if (!mySeq.IsEmpty())
1209     {
1210       mySource = IterSource_List;
1211       mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1212     }
1213     else if (aCtx->NbSelected() > 0)
1214     {
1215       mySource  = IterSource_Selected;
1216       mySelIter = aCtx;
1217       mySelIter->InitSelected();
1218     }
1219     else
1220     {
1221       mySource = IterSource_All;
1222       myMapIter.Initialize (GetMapOfAIS());
1223     }
1224     initCurrent();
1225   }
1226
1227   const TCollection_AsciiString& CurrentName() const
1228   {
1229     return myCurrentName;
1230   }
1231
1232   const Handle(AIS_InteractiveObject)& Current() const
1233   {
1234     return myCurrent;
1235   }
1236
1237   const Handle(Standard_Transient)& CurrentTrs() const
1238   {
1239     return myCurrentTrs;
1240   }
1241
1242   //! @return true if iterator points to valid object within collection
1243   Standard_Boolean More() const
1244   {
1245     switch (mySource)
1246     {
1247       case IterSource_All:      return myMapIter.More();
1248       case IterSource_List:     return mySeqIter.More();
1249       case IterSource_Selected: return mySelIter->MoreSelected();
1250     }
1251     return Standard_False;
1252   }
1253
1254   //! Go to the next item.
1255   void Next()
1256   {
1257     myCurrentName.Clear();
1258     myCurrentTrs.Nullify();
1259     myCurrent.Nullify();
1260     switch (mySource)
1261     {
1262       case IterSource_All:
1263       {
1264         myMapIter.Next();
1265         break;
1266       }
1267       case IterSource_List:
1268       {
1269         mySeqIter.Next();
1270         break;
1271       }
1272       case IterSource_Selected:
1273       {
1274         mySelIter->NextSelected();
1275         break;
1276       }
1277     }
1278     initCurrent();
1279   }
1280
1281 private:
1282
1283   void initCurrent()
1284   {
1285     switch (mySource)
1286     {
1287       case IterSource_All:
1288       {
1289         if (myMapIter.More())
1290         {
1291           myCurrentName = myMapIter.Key2();
1292           myCurrentTrs  = myMapIter.Key1();
1293           myCurrent     = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1294         }
1295         break;
1296       }
1297       case IterSource_List:
1298       {
1299         if (mySeqIter.More())
1300         {
1301           if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1302           {
1303             std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1304             return;
1305           }
1306           myCurrentName = mySeqIter.Value();
1307           myCurrentTrs  = GetMapOfAIS().Find2 (mySeqIter.Value());
1308           myCurrent     = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1309         }
1310         break;
1311       }
1312       case IterSource_Selected:
1313       {
1314         if (mySelIter->MoreSelected())
1315         {
1316           myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1317           myCurrent     = mySelIter->SelectedInteractive();
1318         }
1319         break;
1320       }
1321     }
1322   }
1323
1324 private:
1325
1326   enum IterSource
1327   {
1328     IterSource_All,
1329     IterSource_List,
1330     IterSource_Selected
1331   };
1332
1333 private:
1334
1335   Handle(AIS_InteractiveContext) mySelIter;    //!< iterator for current (selected) objects (IterSource_Selected)
1336   ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1337   NCollection_Sequence<TCollection_AsciiString>           mySeq;
1338   NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1339
1340   TCollection_AsciiString        myCurrentName;//!< current item name
1341   Handle(Standard_Transient)     myCurrentTrs; //!< current item (as transient object)
1342   Handle(AIS_InteractiveObject)  myCurrent;    //!< current item
1343
1344   IterSource                     mySource;     //!< iterated collection
1345
1346 };
1347
1348 //==============================================================================
1349 //function : VInteriorStyle
1350 //purpose  : sets interior style of the a selected or named or displayed shape
1351 //==============================================================================
1352 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1353                               Standard_Integer  theArgNb,
1354                               const char**      theArgVec)
1355 {
1356   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1357   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1358   if (aCtx.IsNull())
1359   {
1360     std::cerr << "Error: no active view!\n";
1361     return 1;
1362   }
1363
1364   Standard_Integer anArgIter = 1;
1365   for (; anArgIter < theArgNb; ++anArgIter)
1366   {
1367     if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1368     {
1369       break;
1370     }
1371   }
1372   TCollection_AsciiString aName;
1373   if (theArgNb - anArgIter == 2)
1374   {
1375     aName = theArgVec[anArgIter++];
1376   }
1377   else if (theArgNb - anArgIter != 1)
1378   {
1379     std::cout << "Error: wrong number of arguments! See usage:\n";
1380     theDI.PrintHelp (theArgVec[0]);
1381     return 1;
1382   }
1383   Standard_Integer        anInterStyle = Aspect_IS_SOLID;
1384   TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1385   aStyleArg.LowerCase();
1386   if (aStyleArg == "empty")
1387   {
1388     anInterStyle = 0;
1389   }
1390   else if (aStyleArg == "hollow")
1391   {
1392     anInterStyle = 1;
1393   }
1394   else if (aStyleArg == "hatch")
1395   {
1396     anInterStyle = 2;
1397   }
1398   else if (aStyleArg == "solid")
1399   {
1400     anInterStyle = 3;
1401   }
1402   else if (aStyleArg == "hiddenline")
1403   {
1404     anInterStyle = 4;
1405   }
1406   else
1407   {
1408     anInterStyle = aStyleArg.IntegerValue();
1409   }
1410   if (anInterStyle < Aspect_IS_EMPTY
1411    || anInterStyle > Aspect_IS_HIDDENLINE)
1412   {
1413     std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1414               << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1415     return 1;
1416   }
1417
1418   if (!aName.IsEmpty()
1419    && !GetMapOfAIS().IsBound2 (aName))
1420   {
1421     std::cout << "Error: object " << aName << " is not displayed!\n";
1422     return 1;
1423   }
1424
1425   if (aCtx->HasOpenedContext())
1426   {
1427     aCtx->CloseLocalContext();
1428   }
1429   for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1430   {
1431     const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1432     if (!anIO.IsNull())
1433     {
1434       const Handle(Prs3d_Drawer)& aDrawer        = anIO->Attributes();
1435       Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1436       Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1437       aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1438       aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1439     }
1440   }
1441   return 0;
1442 }
1443
1444 //! Auxiliary structure for VAspects
1445 struct ViewerTest_AspectsChangeSet
1446 {
1447   Standard_Integer         ToSetVisibility;
1448   Standard_Integer         Visibility;
1449
1450   Standard_Integer         ToSetColor;
1451   Quantity_Color           Color;
1452
1453   Standard_Integer         ToSetLineWidth;
1454   Standard_Real            LineWidth;
1455
1456   Standard_Integer         ToSetTypeOfLine;
1457   Aspect_TypeOfLine        TypeOfLine;
1458
1459   Standard_Integer         ToSetTransparency;
1460   Standard_Real            Transparency;
1461
1462   Standard_Integer         ToSetMaterial;
1463   Graphic3d_NameOfMaterial Material;
1464   TCollection_AsciiString  MatName;
1465
1466   NCollection_Sequence<TopoDS_Shape> SubShapes;
1467
1468   Standard_Integer         ToSetShowFreeBoundary;
1469   Standard_Integer         ToSetFreeBoundaryWidth;
1470   Standard_Real            FreeBoundaryWidth;
1471   Standard_Integer         ToSetFreeBoundaryColor;
1472   Quantity_Color           FreeBoundaryColor;
1473
1474   Standard_Integer         ToEnableIsoOnTriangulation;
1475
1476   Standard_Integer         ToSetMaxParamValue;
1477   Standard_Real            MaxParamValue;
1478
1479   Standard_Integer         ToSetSensitivity;
1480   Standard_Integer         SelectionMode;
1481   Standard_Integer         Sensitivity;
1482
1483   //! Empty constructor
1484   ViewerTest_AspectsChangeSet()
1485   : ToSetVisibility   (0),
1486     Visibility        (1),
1487     ToSetColor        (0),
1488     Color             (DEFAULT_COLOR),
1489     ToSetLineWidth    (0),
1490     LineWidth         (1.0),
1491     ToSetTypeOfLine   (0),
1492     TypeOfLine        (Aspect_TOL_SOLID),
1493     ToSetTransparency (0),
1494     Transparency      (0.0),
1495     ToSetMaterial     (0),
1496     Material          (Graphic3d_NOM_DEFAULT),
1497     ToSetShowFreeBoundary      (0),
1498     ToSetFreeBoundaryWidth     (0),
1499     FreeBoundaryWidth          (1.0),
1500     ToSetFreeBoundaryColor     (0),
1501     FreeBoundaryColor          (DEFAULT_FREEBOUNDARY_COLOR),
1502     ToEnableIsoOnTriangulation (-1),
1503     ToSetMaxParamValue (0),
1504     MaxParamValue (500000),
1505     ToSetSensitivity (0),
1506     SelectionMode (-1),
1507     Sensitivity (-1) {}
1508
1509   //! @return true if no changes have been requested
1510   Standard_Boolean IsEmpty() const
1511   {
1512     return ToSetVisibility        == 0
1513         && ToSetLineWidth         == 0
1514         && ToSetTransparency      == 0
1515         && ToSetColor             == 0
1516         && ToSetMaterial          == 0
1517         && ToSetShowFreeBoundary  == 0
1518         && ToSetFreeBoundaryColor == 0
1519         && ToSetFreeBoundaryWidth == 0
1520         && ToSetMaxParamValue     == 0
1521         && ToSetSensitivity       == 0;
1522   }
1523
1524   //! @return true if properties are valid
1525   Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1526   {
1527     Standard_Boolean isOk = Standard_True;
1528     if (Visibility != 0 && Visibility != 1)
1529     {
1530       std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1531       isOk = Standard_False;
1532     }
1533     if (LineWidth <= 0.0
1534      || LineWidth >  10.0)
1535     {
1536       std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1537       isOk = Standard_False;
1538     }
1539     if (Transparency < 0.0
1540      || Transparency > 1.0)
1541     {
1542       std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1543       isOk = Standard_False;
1544     }
1545     if (theIsSubPart
1546      && ToSetTransparency)
1547     {
1548       std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1549       isOk = Standard_False;
1550     }
1551     if (ToSetMaterial == 1
1552      && Material == Graphic3d_NOM_DEFAULT)
1553     {
1554       std::cout << "Error: unknown material " << MatName << ".\n";
1555       isOk = Standard_False;
1556     }
1557     if (FreeBoundaryWidth <= 0.0
1558      || FreeBoundaryWidth >  10.0)
1559     {
1560       std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1561       isOk = Standard_False;
1562     }
1563     if (MaxParamValue < 0.0)
1564     {
1565       std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1566       isOk = Standard_False;
1567     }
1568     if (Sensitivity <= 0 && ToSetSensitivity)
1569     {
1570       std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1571       isOk = Standard_False;
1572     }
1573     return isOk;
1574   }
1575
1576 };
1577
1578 //==============================================================================
1579 //function : VAspects
1580 //purpose  :
1581 //==============================================================================
1582 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1583                                   Standard_Integer  theArgNb,
1584                                   const char**      theArgVec)
1585 {
1586   TCollection_AsciiString aCmdName (theArgVec[0]);
1587   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1588   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1589   if (aCtx.IsNull())
1590   {
1591     std::cerr << "Error: no active view!\n";
1592     return 1;
1593   }
1594
1595   Standard_Integer anArgIter = 1;
1596   Standard_Boolean isDefaults = Standard_False;
1597   NCollection_Sequence<TCollection_AsciiString> aNames;
1598   for (; anArgIter < theArgNb; ++anArgIter)
1599   {
1600     TCollection_AsciiString anArg = theArgVec[anArgIter];
1601     if (anUpdateTool.parseRedrawMode (anArg))
1602     {
1603       continue;
1604     }
1605     else if (!anArg.IsEmpty()
1606            && anArg.Value (1) != '-')
1607     {
1608       aNames.Append (anArg);
1609     }
1610     else
1611     {
1612       if (anArg == "-defaults")
1613       {
1614         isDefaults = Standard_True;
1615         ++anArgIter;
1616       }
1617       break;
1618     }
1619   }
1620
1621   if (!aNames.IsEmpty() && isDefaults)
1622   {
1623     std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1624     return 1;
1625   }
1626
1627   NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1628   aChanges.Append (ViewerTest_AspectsChangeSet());
1629   ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1630
1631   // parse syntax of legacy commands
1632   if (aCmdName == "vsetwidth")
1633   {
1634     if (aNames.IsEmpty()
1635     || !aNames.Last().IsRealValue())
1636     {
1637       std::cout << "Error: not enough arguments!\n";
1638       return 1;
1639     }
1640     aChangeSet->ToSetLineWidth = 1;
1641     aChangeSet->LineWidth = aNames.Last().RealValue();
1642     aNames.Remove (aNames.Length());
1643   }
1644   else if (aCmdName == "vunsetwidth")
1645   {
1646     aChangeSet->ToSetLineWidth = -1;
1647   }
1648   else if (aCmdName == "vsetcolor")
1649   {
1650     if (aNames.IsEmpty())
1651     {
1652       std::cout << "Error: not enough arguments!\n";
1653       return 1;
1654     }
1655     aChangeSet->ToSetColor = 1;
1656
1657     Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1658     Standard_Boolean     isOk   = Standard_False;
1659     if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1660     {
1661       aChangeSet->Color = aColor;
1662       aNames.Remove (aNames.Length());
1663       isOk = Standard_True;
1664     }
1665     else if (aNames.Length() >= 3)
1666     {
1667       const TCollection_AsciiString anRgbStr[3] =
1668       {
1669         aNames.Value (aNames.Upper() - 2),
1670         aNames.Value (aNames.Upper() - 1),
1671         aNames.Value (aNames.Upper() - 0)
1672       };
1673       isOk = anRgbStr[0].IsRealValue()
1674           && anRgbStr[1].IsRealValue()
1675           && anRgbStr[2].IsRealValue();
1676       if (isOk)
1677       {
1678         Graphic3d_Vec4d anRgb;
1679         anRgb.x() = anRgbStr[0].RealValue();
1680         anRgb.y() = anRgbStr[1].RealValue();
1681         anRgb.z() = anRgbStr[2].RealValue();
1682         if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1683          || anRgb.y() < 0.0 || anRgb.y() > 1.0
1684          || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1685         {
1686           std::cout << "Error: RGB color values should be within range 0..1!\n";
1687           return 1;
1688         }
1689         aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1690         aNames.Remove (aNames.Length());
1691         aNames.Remove (aNames.Length());
1692         aNames.Remove (aNames.Length());
1693       }
1694     }
1695     if (!isOk)
1696     {
1697       std::cout << "Error: not enough arguments!\n";
1698       return 1;
1699     }
1700   }
1701   else if (aCmdName == "vunsetcolor")
1702   {
1703     aChangeSet->ToSetColor = -1;
1704   }
1705   else if (aCmdName == "vsettransparency")
1706   {
1707     if (aNames.IsEmpty()
1708     || !aNames.Last().IsRealValue())
1709     {
1710       std::cout << "Error: not enough arguments!\n";
1711       return 1;
1712     }
1713     aChangeSet->ToSetTransparency = 1;
1714     aChangeSet->Transparency  = aNames.Last().RealValue();
1715     aNames.Remove (aNames.Length());
1716   }
1717   else if (aCmdName == "vunsettransparency")
1718   {
1719     aChangeSet->ToSetTransparency = -1;
1720   }
1721   else if (aCmdName == "vsetmaterial")
1722   {
1723     if (aNames.IsEmpty())
1724     {
1725       std::cout << "Error: not enough arguments!\n";
1726       return 1;
1727     }
1728     aChangeSet->ToSetMaterial = 1;
1729     aChangeSet->MatName  = aNames.Last();
1730     aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1731     aNames.Remove (aNames.Length());
1732   }
1733   else if (aCmdName == "vunsetmaterial")
1734   {
1735     aChangeSet->ToSetMaterial = -1;
1736   }
1737   else if (anArgIter >= theArgNb)
1738   {
1739     std::cout << "Error: not enough arguments!\n";
1740     return 1;
1741   }
1742
1743   if (!aChangeSet->IsEmpty())
1744   {
1745     anArgIter = theArgNb;
1746   }
1747   for (; anArgIter < theArgNb; ++anArgIter)
1748   {
1749     TCollection_AsciiString anArg = theArgVec[anArgIter];
1750     anArg.LowerCase();
1751     if (anArg == "-setwidth"
1752      || anArg == "-setlinewidth")
1753     {
1754       if (++anArgIter >= theArgNb)
1755       {
1756         std::cout << "Error: wrong syntax at " << anArg << "\n";
1757         return 1;
1758       }
1759       aChangeSet->ToSetLineWidth = 1;
1760       aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1761     }
1762     else if (anArg == "-unsetwidth"
1763           || anArg == "-unsetlinewidth")
1764     {
1765       aChangeSet->ToSetLineWidth = -1;
1766       aChangeSet->LineWidth = 1.0;
1767     }
1768     else if (anArg == "-settransp"
1769           || anArg == "-settransparency")
1770     {
1771       if (++anArgIter >= theArgNb)
1772       {
1773         std::cout << "Error: wrong syntax at " << anArg << "\n";
1774         return 1;
1775       }
1776       aChangeSet->ToSetTransparency = 1;
1777       aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1778       if (aChangeSet->Transparency >= 0.0
1779        && aChangeSet->Transparency <= Precision::Confusion())
1780       {
1781         aChangeSet->ToSetTransparency = -1;
1782         aChangeSet->Transparency = 0.0;
1783       }
1784     }
1785     else if (anArg == "-setvis"
1786           || anArg == "-setvisibility")
1787     {
1788       if (++anArgIter >= theArgNb)
1789       {
1790         std::cout << "Error: wrong syntax at " << anArg << "\n";
1791         return 1;
1792       }
1793
1794       aChangeSet->ToSetVisibility = 1;
1795       aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1796     }
1797     else if (anArg == "-setalpha")
1798     {
1799       if (++anArgIter >= theArgNb)
1800       {
1801         std::cout << "Error: wrong syntax at " << anArg << "\n";
1802         return 1;
1803       }
1804       aChangeSet->ToSetTransparency = 1;
1805       aChangeSet->Transparency  = Draw::Atof (theArgVec[anArgIter]);
1806       if (aChangeSet->Transparency < 0.0
1807        || aChangeSet->Transparency > 1.0)
1808       {
1809         std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1810         return 1;
1811       }
1812       aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1813       if (aChangeSet->Transparency >= 0.0
1814        && aChangeSet->Transparency <= Precision::Confusion())
1815       {
1816         aChangeSet->ToSetTransparency = -1;
1817         aChangeSet->Transparency = 0.0;
1818       }
1819     }
1820     else if (anArg == "-unsettransp"
1821           || anArg == "-unsettransparency"
1822           || anArg == "-unsetalpha"
1823           || anArg == "-opaque")
1824     {
1825       aChangeSet->ToSetTransparency = -1;
1826       aChangeSet->Transparency = 0.0;
1827     }
1828     else if (anArg == "-setcolor")
1829     {
1830       Standard_Integer aNbComps  = 0;
1831       Standard_Integer aCompIter = anArgIter + 1;
1832       for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1833       {
1834         if (theArgVec[aCompIter][0] == '-')
1835         {
1836           break;
1837         }
1838       }
1839       switch (aNbComps)
1840       {
1841         case 1:
1842         {
1843           Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1844           Standard_CString     aName  = theArgVec[anArgIter + 1];
1845           if (!Quantity_Color::ColorFromName (aName, aColor))
1846           {
1847             std::cout << "Error: unknown color name '" << aName << "'\n";
1848             return 1;
1849           }
1850           aChangeSet->Color = aColor;
1851           break;
1852         }
1853         case 3:
1854         {
1855           Graphic3d_Vec3d anRgb;
1856           anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1857           anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1858           anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1859           if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1860            || anRgb.y() < 0.0 || anRgb.y() > 1.0
1861            || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1862           {
1863             std::cout << "Error: RGB color values should be within range 0..1!\n";
1864             return 1;
1865           }
1866           aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1867           break;
1868         }
1869         default:
1870         {
1871           std::cout << "Error: wrong syntax at " << anArg << "\n";
1872           return 1;
1873         }
1874       }
1875       aChangeSet->ToSetColor = 1;
1876       anArgIter += aNbComps;
1877     }
1878     else if (anArg == "-setlinetype")
1879     {
1880       if (++anArgIter >= theArgNb)
1881       {
1882         std::cout << "Error: wrong syntax at " << anArg << "\n";
1883         return 1;
1884       }
1885
1886       TCollection_AsciiString aValue (theArgVec[anArgIter]);
1887       aValue.LowerCase();
1888
1889       if (aValue.IsEqual ("solid"))
1890       {
1891         aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1892       }
1893       else if (aValue.IsEqual ("dot"))
1894       {
1895         aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1896       }
1897       else if (aValue.IsEqual ("dash"))
1898       {
1899         aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1900       }
1901       else if (aValue.IsEqual ("dotdash"))
1902       {
1903         aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1904       }
1905       else
1906       {
1907         std::cout << "Error: wrong syntax at " << anArg << "\n";
1908         return 1;
1909       }
1910
1911       aChangeSet->ToSetTypeOfLine = 1;
1912     }
1913     else if (anArg == "-unsetlinetype")
1914     {
1915       aChangeSet->ToSetTypeOfLine = -1;
1916     }
1917     else if (anArg == "-unsetcolor")
1918     {
1919       aChangeSet->ToSetColor = -1;
1920       aChangeSet->Color = DEFAULT_COLOR;
1921     }
1922     else if (anArg == "-setmat"
1923           || anArg == "-setmaterial")
1924     {
1925       if (++anArgIter >= theArgNb)
1926       {
1927         std::cout << "Error: wrong syntax at " << anArg << "\n";
1928         return 1;
1929       }
1930       aChangeSet->ToSetMaterial = 1;
1931       aChangeSet->MatName  = theArgVec[anArgIter];
1932       aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1933     }
1934     else if (anArg == "-unsetmat"
1935           || anArg == "-unsetmaterial")
1936     {
1937       aChangeSet->ToSetMaterial = -1;
1938       aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1939     }
1940     else if (anArg == "-subshape"
1941           || anArg == "-subshapes")
1942     {
1943       if (isDefaults)
1944       {
1945         std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1946         return 1;
1947       }
1948
1949       if (aNames.IsEmpty())
1950       {
1951         std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1952         return 1;
1953       }
1954
1955       aChanges.Append (ViewerTest_AspectsChangeSet());
1956       aChangeSet = &aChanges.ChangeLast();
1957
1958       for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1959       {
1960         Standard_CString aSubShapeName = theArgVec[anArgIter];
1961         if (*aSubShapeName == '-')
1962         {
1963           --anArgIter;
1964           break;
1965         }
1966
1967         TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1968         if (aSubShape.IsNull())
1969         {
1970           std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1971           return 1;
1972         }
1973         aChangeSet->SubShapes.Append (aSubShape);
1974       }
1975
1976       if (aChangeSet->SubShapes.IsEmpty())
1977       {
1978         std::cerr << "Error: empty list is specified after -subshapes!\n";
1979         return 1;
1980       }
1981     }
1982     else if (anArg == "-freeboundary"
1983           || anArg == "-fb")
1984     {
1985       if (++anArgIter >= theArgNb)
1986       {
1987         std::cout << "Error: wrong syntax at " << anArg << "\n";
1988         return 1;
1989       }
1990       TCollection_AsciiString aValue (theArgVec[anArgIter]);
1991       aValue.LowerCase();
1992       if (aValue == "on"
1993        || aValue == "1")
1994       {
1995         aChangeSet->ToSetShowFreeBoundary = 1;
1996       }
1997       else if (aValue == "off"
1998             || aValue == "0")
1999       {
2000         aChangeSet->ToSetShowFreeBoundary = -1;
2001       }
2002       else
2003       {
2004         std::cout << "Error: wrong syntax at " << anArg << "\n";
2005         return 1;
2006       }
2007     }
2008     else if (anArg == "-setfreeboundarywidth"
2009           || anArg == "-setfbwidth")
2010     {
2011       if (++anArgIter >= theArgNb)
2012       {
2013         std::cout << "Error: wrong syntax at " << anArg << "\n";
2014         return 1;
2015       }
2016       aChangeSet->ToSetFreeBoundaryWidth = 1;
2017       aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2018     }
2019     else if (anArg == "-unsetfreeboundarywidth"
2020           || anArg == "-unsetfbwidth")
2021     {
2022       aChangeSet->ToSetFreeBoundaryWidth = -1;
2023       aChangeSet->FreeBoundaryWidth = 1.0;
2024     }
2025     else if (anArg == "-setfreeboundarycolor"
2026           || anArg == "-setfbcolor")
2027     {
2028       Standard_Integer aNbComps  = 0;
2029       Standard_Integer aCompIter = anArgIter + 1;
2030       for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2031       {
2032         if (theArgVec[aCompIter][0] == '-')
2033         {
2034           break;
2035         }
2036       }
2037       switch (aNbComps)
2038       {
2039         case 1:
2040         {
2041           Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2042           Standard_CString     aName  = theArgVec[anArgIter + 1];
2043           if (!Quantity_Color::ColorFromName (aName, aColor))
2044           {
2045             std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2046             return 1;
2047           }
2048           aChangeSet->FreeBoundaryColor = aColor;
2049           break;
2050         }
2051         case 3:
2052         {
2053           Graphic3d_Vec3d anRgb;
2054           anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2055           anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2056           anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2057           if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2058            || anRgb.y() < 0.0 || anRgb.y() > 1.0
2059            || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2060           {
2061             std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2062             return 1;
2063           }
2064           aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2065           break;
2066         }
2067         default:
2068         {
2069           std::cout << "Error: wrong syntax at " << anArg << "\n";
2070           return 1;
2071         }
2072       }
2073       aChangeSet->ToSetFreeBoundaryColor = 1;
2074       anArgIter += aNbComps;
2075     }
2076     else if (anArg == "-unsetfreeboundarycolor"
2077           || anArg == "-unsetfbcolor")
2078     {
2079       aChangeSet->ToSetFreeBoundaryColor = -1;
2080       aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2081     }
2082     else if (anArg == "-unset")
2083     {
2084       aChangeSet->ToSetVisibility = 1;
2085       aChangeSet->Visibility = 1;
2086       aChangeSet->ToSetLineWidth = -1;
2087       aChangeSet->LineWidth = 1.0;
2088       aChangeSet->ToSetTypeOfLine = -1;
2089       aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2090       aChangeSet->ToSetTransparency = -1;
2091       aChangeSet->Transparency = 0.0;
2092       aChangeSet->ToSetColor = -1;
2093       aChangeSet->Color = DEFAULT_COLOR;
2094       aChangeSet->ToSetMaterial = -1;
2095       aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2096       aChangeSet->ToSetShowFreeBoundary = -1;
2097       aChangeSet->ToSetFreeBoundaryColor = -1;
2098       aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2099       aChangeSet->ToSetFreeBoundaryWidth = -1;
2100       aChangeSet->FreeBoundaryWidth = 1.0;
2101     }
2102     else if (anArg == "-isoontriangulation"
2103           || anArg == "-isoontriang")
2104     {
2105       if (++anArgIter >= theArgNb)
2106       {
2107         std::cout << "Error: wrong syntax at " << anArg << "\n";
2108         return 1;
2109       }
2110       TCollection_AsciiString aValue (theArgVec[anArgIter]);
2111       aValue.LowerCase();
2112       if (aValue == "on"
2113         || aValue == "1")
2114       {
2115         aChangeSet->ToEnableIsoOnTriangulation = 1;
2116       }
2117       else if (aValue == "off"
2118         || aValue == "0")
2119       {
2120         aChangeSet->ToEnableIsoOnTriangulation = 0;
2121       }
2122       else
2123       {
2124         std::cout << "Error: wrong syntax at " << anArg << "\n";
2125         return 1;
2126       }
2127     }
2128     else if (anArg == "-setmaxparamvalue")
2129     {
2130       if (++anArgIter >= theArgNb)
2131       {
2132         std::cout << "Error: wrong syntax at " << anArg << "\n";
2133         return 1;
2134       }
2135       aChangeSet->ToSetMaxParamValue = 1;
2136       aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2137     }
2138     else if (anArg == "-setsensitivity")
2139     {
2140       if (isDefaults)
2141       {
2142         std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2143         return 1;
2144       }
2145
2146       if (aNames.IsEmpty())
2147       {
2148         std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2149         return 1;
2150       }
2151
2152       if (anArgIter + 2 >= theArgNb)
2153       {
2154         std::cout << "Error: wrong syntax at " << anArg << "\n";
2155         return 1;
2156       }
2157       aChangeSet->ToSetSensitivity = 1;
2158       aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2159       aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2160     }
2161     else
2162     {
2163       std::cout << "Error: wrong syntax at " << anArg << "\n";
2164       return 1;
2165     }
2166   }
2167
2168   Standard_Boolean isFirst = Standard_True;
2169   for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2170        aChangesIter.More(); aChangesIter.Next())
2171   {
2172     if (!aChangesIter.Value().Validate (!isFirst))
2173     {
2174       return 1;
2175     }
2176     isFirst = Standard_False;
2177   }
2178
2179   if (aCtx->HasOpenedContext())
2180   {
2181     aCtx->CloseLocalContext();
2182   }
2183
2184   // special case for -defaults parameter.
2185   // all changed values will be set to DefaultDrawer.
2186   if (isDefaults)
2187   {
2188     const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2189
2190     if (aChangeSet->ToSetLineWidth != 0)
2191     {
2192       aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2193       aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2194       aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2195       aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2196     }
2197     if (aChangeSet->ToSetColor != 0)
2198     {
2199       aDrawer->ShadingAspect()->SetColor        (aChangeSet->Color);
2200       aDrawer->LineAspect()->SetColor           (aChangeSet->Color);
2201       aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2202       aDrawer->SeenLineAspect()->SetColor       (aChangeSet->Color);
2203       aDrawer->WireAspect()->SetColor           (aChangeSet->Color);
2204       aDrawer->PointAspect()->SetColor          (aChangeSet->Color);
2205     }
2206     if (aChangeSet->ToSetTypeOfLine != 0)
2207     {
2208       aDrawer->LineAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
2209       aDrawer->WireAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
2210       aDrawer->FreeBoundaryAspect()->SetTypeOfLine   (aChangeSet->TypeOfLine);
2211       aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2212       aDrawer->SeenLineAspect()->SetTypeOfLine       (aChangeSet->TypeOfLine);
2213     }
2214     if (aChangeSet->ToSetTransparency != 0)
2215     {
2216       aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2217     }
2218     if (aChangeSet->ToSetMaterial != 0)
2219     {
2220       aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2221     }
2222     if (aChangeSet->ToSetShowFreeBoundary == 1)
2223     {
2224       aDrawer->SetFreeBoundaryDraw (Standard_True);
2225     }
2226     else if (aChangeSet->ToSetShowFreeBoundary == -1)
2227     {
2228       aDrawer->SetFreeBoundaryDraw (Standard_False);
2229     }
2230     if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2231     {
2232       aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2233     }
2234     if (aChangeSet->ToSetFreeBoundaryColor != 0)
2235     {
2236       aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2237     }
2238     if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2239     {
2240       aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2241     }
2242     if (aChangeSet->ToSetMaxParamValue != 0)
2243     {
2244       aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2245     }
2246
2247     // redisplay all objects in context
2248     for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2249     {
2250       Handle(AIS_InteractiveObject)  aPrs = aPrsIter.Current();
2251       if (!aPrs.IsNull())
2252       {
2253         aCtx->Redisplay (aPrs, Standard_False);
2254       }
2255     }
2256     return 0;
2257   }
2258
2259   for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2260   {
2261     const TCollection_AsciiString& aName   = aPrsIter.CurrentName();
2262     Handle(AIS_InteractiveObject)  aPrs    = aPrsIter.Current();
2263     Handle(Prs3d_Drawer)           aDrawer = aPrs->Attributes();
2264     Handle(AIS_ColoredShape) aColoredPrs;
2265     Standard_Boolean toDisplay = Standard_False;
2266     Standard_Boolean toRedisplay = Standard_False;
2267     if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2268     {
2269       Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2270       if (aShapePrs.IsNull())
2271       {
2272         std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2273         return 1;
2274       }
2275       aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2276       if (aColoredPrs.IsNull())
2277       {
2278         aColoredPrs = new AIS_ColoredShape (aShapePrs);
2279         if (aShapePrs->HasDisplayMode())
2280         {
2281           aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2282         }
2283         aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2284         aCtx->Remove (aShapePrs, Standard_False);
2285         GetMapOfAIS().UnBind2 (aName);
2286         GetMapOfAIS().Bind (aColoredPrs, aName);
2287         toDisplay = Standard_True;
2288         aShapePrs = aColoredPrs;
2289         aPrs      = aColoredPrs;
2290       }
2291     }
2292
2293     if (!aPrs.IsNull())
2294     {
2295       NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2296       aChangeSet = &aChangesIter.ChangeValue();
2297       if (aChangeSet->ToSetVisibility == 1)
2298       {
2299         Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2300         aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2301       }
2302       else if (aChangeSet->ToSetMaterial == 1)
2303       {
2304         aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2305       }
2306       else if (aChangeSet->ToSetMaterial == -1)
2307       {
2308         aCtx->UnsetMaterial (aPrs, Standard_False);
2309       }
2310       if (aChangeSet->ToSetColor == 1)
2311       {
2312         aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2313       }
2314       else if (aChangeSet->ToSetColor == -1)
2315       {
2316         aCtx->UnsetColor (aPrs, Standard_False);
2317       }
2318       if (aChangeSet->ToSetTransparency == 1)
2319       {
2320         aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2321       }
2322       else if (aChangeSet->ToSetTransparency == -1)
2323       {
2324         aCtx->UnsetTransparency (aPrs, Standard_False);
2325       }
2326       if (aChangeSet->ToSetLineWidth == 1)
2327       {
2328         aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2329       }
2330       else if (aChangeSet->ToSetLineWidth == -1)
2331       {
2332         aCtx->UnsetWidth (aPrs, Standard_False);
2333       }
2334       else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2335       {
2336         aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2337         toRedisplay = Standard_True;
2338       }
2339       else if (aChangeSet->ToSetSensitivity != 0)
2340       {
2341         aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2342       }
2343       if (!aDrawer.IsNull())
2344       {
2345         if (aChangeSet->ToSetShowFreeBoundary == 1)
2346         {
2347           aDrawer->SetFreeBoundaryDraw (Standard_True);
2348           toRedisplay = Standard_True;
2349         }
2350         else if (aChangeSet->ToSetShowFreeBoundary == -1)
2351         {
2352           aDrawer->SetFreeBoundaryDraw (Standard_False);
2353           toRedisplay = Standard_True;
2354         }
2355         if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2356         {
2357           Handle(Prs3d_LineAspect) aBoundaryAspect =
2358               new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2359           *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2360           aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2361           aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2362           toRedisplay = Standard_True;
2363         }
2364         if (aChangeSet->ToSetFreeBoundaryColor != 0)
2365         {
2366           Handle(Prs3d_LineAspect) aBoundaryAspect =
2367               new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2368           *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2369           aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2370           aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2371           toRedisplay = Standard_True;
2372         }
2373         if (aChangeSet->ToSetTypeOfLine != 0)
2374         {
2375           aDrawer->LineAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
2376           aDrawer->WireAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
2377           aDrawer->FreeBoundaryAspect()->SetTypeOfLine   (aChangeSet->TypeOfLine);
2378           aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2379           aDrawer->SeenLineAspect()->SetTypeOfLine       (aChangeSet->TypeOfLine);
2380           toRedisplay = Standard_True;
2381         }
2382         if (aChangeSet->ToSetMaxParamValue != 0)
2383         {
2384           aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2385         }
2386       }
2387
2388       for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2389       {
2390         aChangeSet = &aChangesIter.ChangeValue();
2391         for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2392              aSubShapeIter.More(); aSubShapeIter.Next())
2393         {
2394           const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2395           if (aChangeSet->ToSetVisibility == 1)
2396           {
2397             Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2398             aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2399           }
2400           if (aChangeSet->ToSetColor == 1)
2401           {
2402             aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2403           }
2404           if (aChangeSet->ToSetLineWidth == 1)
2405           {
2406             aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2407           }
2408           if (aChangeSet->ToSetColor     == -1
2409            || aChangeSet->ToSetLineWidth == -1)
2410           {
2411             aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2412           }
2413           if (aChangeSet->ToSetMaxParamValue != 0)
2414           {
2415             Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2416             aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2417           }
2418           if (aChangeSet->ToSetSensitivity != 0)
2419           {
2420             aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2421           }
2422         }
2423       }
2424       if (toDisplay)
2425       {
2426         aCtx->Display (aPrs, Standard_False);
2427       }
2428       if (toRedisplay)
2429       {
2430         aCtx->Redisplay (aPrs, Standard_False);
2431       }
2432       else if (!aColoredPrs.IsNull())
2433       {
2434         aCtx->Redisplay (aColoredPrs, Standard_False);
2435       }
2436     }
2437   }
2438   return 0;
2439 }
2440
2441 //==============================================================================
2442 //function : VDonly2
2443 //author   : ege
2444 //purpose  : Display only a selected or named  object
2445 //           if there is no selected or named object s, nothing is done
2446 //==============================================================================
2447 static int VDonly2 (Draw_Interpretor& ,
2448                     Standard_Integer  theArgNb,
2449                     const char**      theArgVec)
2450 {
2451   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2452   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2453   if (aCtx.IsNull())
2454   {
2455     std::cerr << "Error: no active view!\n";
2456     return 1;
2457   }
2458
2459   if (aCtx->HasOpenedContext())
2460   {
2461     aCtx->CloseLocalContext();
2462   }
2463
2464   Standard_Integer anArgIter = 1;
2465   for (; anArgIter < theArgNb; ++anArgIter)
2466   {
2467     if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2468     {
2469       break;
2470     }
2471   }
2472
2473   NCollection_Map<Handle(Standard_Transient)> aDispSet;
2474   if (anArgIter >= theArgNb)
2475   {
2476     // display only selected objects
2477     if (aCtx->NbSelected() < 1)
2478     {
2479       return 0;
2480     }
2481
2482     for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2483     {
2484       aDispSet.Add (aCtx->SelectedInteractive());
2485     }
2486   }
2487   else
2488   {
2489     // display only specified objects
2490     for (; anArgIter < theArgNb; ++anArgIter)
2491     {
2492       TCollection_AsciiString aName = theArgVec[anArgIter];
2493       if (GetMapOfAIS().IsBound2 (aName))
2494       {
2495         const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2496         if (!aShape.IsNull())
2497         {
2498           aCtx->Display (aShape, Standard_False);
2499           aDispSet.Add (aShape);
2500         }
2501       }
2502     }
2503   }
2504
2505   // weed out other objects
2506   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2507   {
2508     if (aDispSet.Contains (anIter.Key1()))
2509     {
2510       continue;
2511     }
2512
2513     const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2514     if (aShape.IsNull())
2515     {
2516       aCtx->Erase (aShape, Standard_False);
2517     }
2518   }
2519   return 0;
2520 }
2521
2522 //==============================================================================
2523 //function : VRemove
2524 //purpose  : Removes selected or named objects.
2525 //           If there is no selected or named objects,
2526 //           all objects in the viewer can be removed with argument -all.
2527 //           If -context is in arguments, the object is not deleted from the map of
2528 //           objects (deleted only from the current context).
2529 //==============================================================================
2530 int VRemove (Draw_Interpretor& theDI,
2531              Standard_Integer  theArgNb,
2532              const char**      theArgVec)
2533 {
2534   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2535   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2536   if (aCtx.IsNull())
2537   {
2538     std::cerr << "Error: no active view!\n";
2539     return 1;
2540   }
2541
2542   Standard_Boolean isContextOnly = Standard_False;
2543   Standard_Boolean toRemoveAll   = Standard_False;
2544   Standard_Boolean toPrintInfo   = Standard_True;
2545   Standard_Boolean toRemoveLocal = Standard_False;
2546
2547   Standard_Integer anArgIter = 1;
2548   for (; anArgIter < theArgNb; ++anArgIter)
2549   {
2550     TCollection_AsciiString anArg = theArgVec[anArgIter];
2551     anArg.LowerCase();
2552     if (anArg == "-context")
2553     {
2554       isContextOnly = Standard_True;
2555     }
2556     else if (anArg == "-all")
2557     {
2558       toRemoveAll = Standard_True;
2559     }
2560     else if (anArg == "-noinfo")
2561     {
2562       toPrintInfo = Standard_False;
2563     }
2564     else if (anArg == "-local")
2565     {
2566       toRemoveLocal = Standard_True;
2567     }
2568     else if (anUpdateTool.parseRedrawMode (anArg))
2569     {
2570       continue;
2571     }
2572     else
2573     {
2574       break;
2575     }
2576   }
2577   if (toRemoveAll
2578    && anArgIter < theArgNb)
2579   {
2580     std::cerr << "Error: wrong syntax!\n";
2581     return 1;
2582   }
2583
2584   if (toRemoveLocal && !aCtx->HasOpenedContext())
2585   {
2586     std::cerr << "Error: local selection context is not open.\n";
2587     return 1;
2588   }
2589   else if (!toRemoveLocal && aCtx->HasOpenedContext())
2590   {
2591     aCtx->CloseAllContexts (Standard_False);
2592   }
2593
2594   NCollection_List<TCollection_AsciiString> anIONameList;
2595   if (toRemoveAll)
2596   {
2597     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2598          anIter.More(); anIter.Next())
2599     {
2600       anIONameList.Append (anIter.Key2());
2601     }
2602   }
2603   else if (anArgIter < theArgNb) // removed objects names are in argument list
2604   {
2605     for (; anArgIter < theArgNb; ++anArgIter)
2606     {
2607       TCollection_AsciiString aName = theArgVec[anArgIter];
2608       if (!GetMapOfAIS().IsBound2 (aName))
2609       {
2610         theDI << aName.ToCString() << " was not bound to some object.\n";
2611         continue;
2612       }
2613
2614       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2615       if (anIO->GetContext() != aCtx)
2616       {
2617         theDI << aName.ToCString() << " was not displayed in current context.\n";
2618         theDI << "Please activate view with this object displayed and try again.\n";
2619         continue;
2620       }
2621
2622       anIONameList.Append (aName);
2623       continue;
2624     }
2625   }
2626   else if (aCtx->NbSelected() > 0)
2627   {
2628     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2629          anIter.More(); anIter.Next())
2630     {
2631       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2632       if (!aCtx->IsSelected (anIO))
2633       {
2634         continue;
2635       }
2636
2637       anIONameList.Append (anIter.Key2());
2638       continue;
2639     }
2640   }
2641
2642   // Unbind all removed objects from the map of displayed IO.
2643   for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2644        anIter.More(); anIter.Next())
2645   {
2646     const Handle(AIS_InteractiveObject) anIO  = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2647     aCtx->Remove (anIO, Standard_False);
2648     if (toPrintInfo)
2649     {
2650       theDI << anIter.Value().ToCString() << " was removed\n";
2651     }
2652     if (!isContextOnly)
2653     {
2654       GetMapOfAIS().UnBind2 (anIter.Value());
2655     }
2656   }
2657
2658   // Close local context if it is empty
2659   TColStd_MapOfTransient aLocalIO;
2660   if (aCtx->HasOpenedContext()
2661    && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2662   {
2663     aCtx->CloseAllContexts (Standard_False);
2664   }
2665
2666   return 0;
2667 }
2668
2669 //==============================================================================
2670 //function : VErase
2671 //purpose  : Erase some selected or named objects
2672 //           if there is no selected or named objects, the whole viewer is erased
2673 //==============================================================================
2674 int VErase (Draw_Interpretor& theDI,
2675             Standard_Integer  theArgNb,
2676             const char**      theArgVec)
2677 {
2678   const Handle(AIS_InteractiveContext)& aCtx  = ViewerTest::GetAISContext();
2679   const Handle(V3d_View)&               aView = ViewerTest::CurrentView();
2680   ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2681   if (aCtx.IsNull())
2682   {
2683     std::cerr << "Error: no active view!\n";
2684     return 1;
2685   }
2686
2687   const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2688
2689   Standard_Integer anArgIter = 1;
2690   Standard_Boolean toEraseLocal  = Standard_False;
2691   Standard_Boolean toEraseInView = Standard_False;
2692   TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2693   for (; anArgIter < theArgNb; ++anArgIter)
2694   {
2695     TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2696     anArgCase.LowerCase();
2697     if (anUpdateTool.parseRedrawMode (anArgCase))
2698     {
2699       continue;
2700     }
2701     else if (anArgCase == "-local")
2702     {
2703       toEraseLocal = Standard_True;
2704     }
2705     else if (anArgCase == "-view"
2706           || anArgCase == "-inview")
2707     {
2708       toEraseInView = Standard_True;
2709     }
2710     else
2711     {
2712       aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2713     }
2714   }
2715
2716   if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2717   {
2718     std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2719     return 1;
2720   }
2721
2722   if (toEraseLocal && !aCtx->HasOpenedContext())
2723   {
2724     std::cerr << "Error: local selection context is not open.\n";
2725     return 1;
2726   }
2727   else if (!toEraseLocal && aCtx->HasOpenedContext())
2728   {
2729     aCtx->CloseAllContexts (Standard_False);
2730   }
2731
2732   if (!aNamesOfEraseIO.IsEmpty())
2733   {
2734     // Erase named objects
2735     for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2736     {
2737       TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2738       if (!GetMapOfAIS().IsBound2 (aName))
2739       {
2740         continue;
2741       }
2742
2743       const Handle(Standard_Transient)    anObj = GetMapOfAIS().Find2 (aName);
2744       const Handle(AIS_InteractiveObject) anIO  = Handle(AIS_InteractiveObject)::DownCast (anObj);
2745       theDI << aName.ToCString() << " ";
2746       if (!anIO.IsNull())
2747       {
2748         if (toEraseInView)
2749         {
2750           aCtx->SetViewAffinity (anIO, aView, Standard_False);
2751         }
2752         else
2753         {
2754           aCtx->Erase (anIO, Standard_False);
2755         }
2756       }
2757     }
2758   }
2759   else if (!toEraseAll && aCtx->NbSelected() > 0)
2760   {
2761     // Erase selected objects
2762     const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
2763     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2764          anIter.More(); anIter.Next())
2765     {
2766       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2767       if (!anIO.IsNull()
2768        && aCtx->IsSelected (anIO))
2769       {
2770         theDI << anIter.Key2().ToCString() << " ";
2771         if (toEraseInView)
2772         {
2773           aCtx->SetViewAffinity (anIO, aView, Standard_False);
2774         }
2775         else if (aHasOpenedContext)
2776         {
2777           aCtx->Erase (anIO, Standard_False);
2778         }
2779       }
2780     }
2781
2782     if (!toEraseInView)
2783     {
2784       aCtx->EraseSelected (Standard_False);
2785     }
2786   }
2787   else
2788   {
2789     // Erase all objects
2790     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2791          anIter.More(); anIter.Next())
2792     {
2793       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2794       if (!anIO.IsNull())
2795       {
2796         if (toEraseInView)
2797         {
2798           aCtx->SetViewAffinity (anIO, aView, Standard_False);
2799         }
2800         else
2801         {
2802           aCtx->Erase (anIO, Standard_False);
2803         }
2804       }
2805     }
2806   }
2807
2808   return 0;
2809 }
2810
2811 //==============================================================================
2812 //function : VDisplayAll
2813 //author   : ege
2814 //purpose  : Display all the objects of the Map
2815 //==============================================================================
2816 static int VDisplayAll (Draw_Interpretor& ,
2817                         Standard_Integer  theArgNb,
2818                         const char**      theArgVec)
2819
2820 {
2821   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2822   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2823   if (aCtx.IsNull())
2824   {
2825     std::cerr << "Error: no active view!\n";
2826     return 1;
2827   }
2828
2829   Standard_Integer anArgIter = 1;
2830   Standard_Boolean toDisplayLocal = Standard_False;
2831   for (; anArgIter < theArgNb; ++anArgIter)
2832   {
2833     TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2834     anArgCase.LowerCase();
2835     if (anArgCase == "-local")
2836     {
2837       toDisplayLocal = Standard_True;
2838     }
2839     else if (anUpdateTool.parseRedrawMode (anArgCase))
2840     {
2841       continue;
2842     }
2843     else
2844     {
2845       break;
2846     }
2847   }
2848   if (anArgIter < theArgNb)
2849   {
2850     std::cout << theArgVec[0] << "Error: wrong syntax\n";
2851     return 1;
2852   }
2853
2854   if (toDisplayLocal && !aCtx->HasOpenedContext())
2855   {
2856     std::cerr << "Error: local selection context is not open.\n";
2857     return 1;
2858   }
2859   else if (!toDisplayLocal && aCtx->HasOpenedContext())
2860   {
2861     aCtx->CloseLocalContext (Standard_False);
2862   }
2863
2864   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2865        anIter.More(); anIter.Next())
2866   {
2867     const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2868     aCtx->Erase (aShape, Standard_False);
2869   }
2870
2871   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2872        anIter.More(); anIter.Next())
2873   {
2874     const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2875     aCtx->Display (aShape, Standard_False);
2876   }
2877   return 0;
2878 }
2879
2880 //! Auxiliary method to check if presentation exists
2881 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
2882                                    const Handle(AIS_InteractiveObject)&  theIO,
2883                                    const Standard_Integer                theMode)
2884 {
2885   if (theIO.IsNull() || theCtx.IsNull())
2886   {
2887     return -1;
2888   }
2889
2890   if (theMode != -1)
2891   {
2892     if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2893     {
2894       return theMode;
2895     }
2896   }
2897   else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2898   {
2899     return theIO->DisplayMode();
2900   }
2901   else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2902   {
2903     return theCtx->DisplayMode();
2904   }
2905
2906   return -1;
2907 }
2908
2909 enum ViewerTest_BndAction
2910 {
2911   BndAction_Hide,
2912   BndAction_Show,
2913   BndAction_Print
2914 };
2915
2916 //! Auxiliary method to print bounding box of presentation
2917 inline void bndPresentation (Draw_Interpretor&                         theDI,
2918                              const Handle(PrsMgr_PresentationManager)& theMgr,
2919                              const Handle(AIS_InteractiveObject)&      theObj,
2920                              const Standard_Integer                    theDispMode,
2921                              const TCollection_AsciiString&            theName,
2922                              const ViewerTest_BndAction                theAction,
2923                              const Handle(Graphic3d_HighlightStyle)&   theStyle)
2924 {
2925   switch (theAction)
2926   {
2927     case BndAction_Hide:
2928     {
2929       theMgr->Unhighlight (theObj, theDispMode);
2930       break;
2931     }
2932     case BndAction_Show:
2933     {
2934       theMgr->Color (theObj, theStyle, theDispMode);
2935       break;
2936     }
2937     case BndAction_Print:
2938     {
2939       Bnd_Box aBox;
2940       for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
2941       {
2942         if (aPrsIter.Value().Mode() != theDispMode)
2943           continue;
2944
2945         aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
2946       }
2947       gp_Pnt aMin = aBox.CornerMin();
2948       gp_Pnt aMax = aBox.CornerMax();
2949       theDI << theName  << "\n"
2950             << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2951             << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2952       break;
2953     }
2954   }
2955 }
2956
2957 //==============================================================================
2958 //function : VBounding
2959 //purpose  :
2960 //==============================================================================
2961 int VBounding (Draw_Interpretor& theDI,
2962                Standard_Integer  theArgNb,
2963                const char**      theArgVec)
2964 {
2965   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2966   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2967   if (aCtx.IsNull())
2968   {
2969     std::cout << "Error: no active view!\n";
2970     return 1;
2971   }
2972
2973   ViewerTest_BndAction anAction = BndAction_Show;
2974   Standard_Integer     aMode    = -1;
2975
2976   Handle(Graphic3d_HighlightStyle) aStyle;
2977
2978   Standard_Integer anArgIter = 1;
2979   for (; anArgIter < theArgNb; ++anArgIter)
2980   {
2981     TCollection_AsciiString anArg (theArgVec[anArgIter]);
2982     anArg.LowerCase();
2983     if (anArg == "-print")
2984     {
2985       anAction = BndAction_Print;
2986     }
2987     else if (anArg == "-show")
2988     {
2989       anAction = BndAction_Show;
2990     }
2991     else if (anArg == "-hide")
2992     {
2993       anAction = BndAction_Hide;
2994     }
2995     else if (anArg == "-mode")
2996     {
2997       if (++anArgIter >= theArgNb)
2998       {
2999         std::cout << "Error: wrong syntax at " << anArg << "\n";
3000         return 1;
3001       }
3002       aMode = Draw::Atoi (theArgVec[anArgIter]);
3003     }
3004     else if (!anUpdateTool.parseRedrawMode (anArg))
3005     {
3006       break;
3007     }
3008   }
3009
3010   if (anAction == BndAction_Show)
3011     aStyle = new Graphic3d_HighlightStyle (Aspect_TOHM_BOUNDBOX, Quantity_NOC_GRAY99, 0.0);
3012
3013   Standard_Integer aHighlightedMode = -1;
3014   if (anArgIter < theArgNb)
3015   {
3016     // has a list of names
3017     for (; anArgIter < theArgNb; ++anArgIter)
3018     {
3019       TCollection_AsciiString aName = theArgVec[anArgIter];
3020       if (!GetMapOfAIS().IsBound2 (aName))
3021       {
3022         std::cout << "Error: presentation " << aName << " does not exist\n";
3023         return 1;
3024       }
3025
3026       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3027       aHighlightedMode = checkMode (aCtx, anIO, aMode);
3028       if (aHighlightedMode == -1)
3029       {
3030         std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3031         return 1;
3032       }
3033       bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3034     }
3035   }
3036   else if (aCtx->NbSelected() > 0)
3037   {
3038     // remove all currently selected objects
3039     for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3040     {
3041       Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3042       aHighlightedMode = checkMode (aCtx, anIO, aMode);
3043       if (aHighlightedMode != -1)
3044       {
3045         bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3046           GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3047       }
3048     }
3049   }
3050   else
3051   {
3052     // all objects
3053     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3054          anIter.More(); anIter.Next())
3055     {
3056       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3057       aHighlightedMode = checkMode (aCtx, anIO, aMode);
3058       if (aHighlightedMode != -1)
3059       {
3060         bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3061       }
3062     }
3063   }
3064   return 0;
3065 }
3066
3067 //==============================================================================
3068 //function : VTexture
3069 //purpose  :
3070 //==============================================================================
3071 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
3072 {
3073   TCollection_AsciiString aCommandName (theArgv[0]);
3074
3075   NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3076   if (aCommandName == "vtexture")
3077   {
3078     if (theArgsNb < 2)
3079     {
3080       std::cout << theArgv[0] << ":  invalid arguments.\n";
3081       std::cout << "Type help for more information.\n";
3082       return 1;
3083     }
3084
3085     // look for options of vtexture command
3086     TCollection_AsciiString aParseKey;
3087     for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3088     {
3089       TCollection_AsciiString anArg (theArgv [anArgIt]);
3090
3091       anArg.UpperCase();
3092       if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3093       {
3094         aParseKey = anArg;
3095         aParseKey.Remove (1);
3096         aParseKey.UpperCase();
3097         aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3098         continue;
3099       }
3100
3101       if (aParseKey.IsEmpty())
3102       {
3103         continue;
3104       }
3105
3106       aMapOfArgs(aParseKey)->Append (anArg);
3107     }
3108   }
3109   else if (aCommandName == "vtexscale"
3110         || aCommandName == "vtexorigin"
3111         || aCommandName == "vtexrepeat")
3112   {
3113     // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3114     // equal to -scale, -origin, -repeat options of vtexture command
3115     if (theArgsNb < 2 || theArgsNb > 4)
3116     {
3117       std::cout << theArgv[0] << ":  invalid arguments.\n";
3118       std::cout << "Type help for more information.\n";
3119       return 1;
3120     }
3121
3122     Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
3123     if (theArgsNb == 2)
3124     {
3125       anArgs->Append ("OFF");
3126     }
3127     else if (theArgsNb == 4)
3128     {
3129       anArgs->Append (TCollection_AsciiString (theArgv[2]));
3130       anArgs->Append (TCollection_AsciiString (theArgv[3]));
3131     }
3132
3133     TCollection_AsciiString anArgKey;
3134     if (aCommandName == "vtexscale")
3135     {
3136       anArgKey = "SCALE";
3137     }
3138     else if (aCommandName == "vtexorigin")
3139     {
3140       anArgKey = "ORIGIN";
3141     }
3142     else
3143     {
3144       anArgKey = "REPEAT";
3145     }
3146
3147     aMapOfArgs.Bind (anArgKey, anArgs);
3148   }
3149   else if (aCommandName == "vtexdefault")
3150   {
3151     // scan for parameters of vtexdefault command
3152     // equal to -default option of vtexture command
3153     aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
3154   }
3155
3156   // Check arguments for validity
3157   NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3158   for (; aMapIt.More(); aMapIt.Next())
3159   {
3160     const TCollection_AsciiString& aKey = aMapIt.Key();
3161     const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3162
3163     // -scale, -origin, -repeat: one argument "off", or two real values
3164     if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3165       && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3166        || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3167     {
3168       continue;
3169     }
3170
3171     // -modulate: single argument "on" / "off"
3172     if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3173     {
3174       continue;
3175     }
3176
3177     // -default: no arguments
3178     if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3179     {
3180       continue;
3181     }
3182
3183     TCollection_AsciiString aLowerKey;
3184     aLowerKey  = "-";
3185     aLowerKey += aKey;
3186     aLowerKey.LowerCase();
3187     std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3188     std::cout << "Type help for more information.\n";
3189     return 1;
3190   }
3191
3192   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3193   if (anAISContext.IsNull())
3194   {
3195     std::cout << aCommandName << ":  please use 'vinit' command to initialize view.\n";
3196     return 1;
3197   }
3198
3199   Standard_Integer aPreviousMode = 0;
3200
3201   TCollection_AsciiString aShapeName (theArgv[1]);
3202   Handle(AIS_InteractiveObject) anIO;
3203
3204   const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3205   if (aMapOfIO.IsBound2 (aShapeName))
3206   {
3207     anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3208   }
3209
3210   if (anIO.IsNull())
3211   {
3212     std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3213     return 1;
3214   }
3215
3216   Handle(AIS_TexturedShape) aTexturedIO;
3217   if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3218   {
3219     aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3220     aPreviousMode = aTexturedIO->DisplayMode();
3221   }
3222   else
3223   {
3224     aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3225
3226     if (anIO->HasTransformation())
3227     {
3228       const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3229       aTexturedIO->SetLocalTransformation (aLocalTrsf);
3230     }
3231
3232     anAISContext->Remove (anIO, Standard_False);
3233     GetMapOfAIS().UnBind1 (anIO);
3234     GetMapOfAIS().UnBind2 (aShapeName);
3235     GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3236   }
3237
3238   // -------------------------------------------
3239   //  Turn texturing on/off - only for vtexture
3240   // -------------------------------------------
3241
3242   if (aCommandName == "vtexture")
3243   {
3244     TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3245
3246     if (aTextureArg.IsEmpty())
3247     {
3248       std::cout << aCommandName << ":  Texture mapping disabled.\n";
3249       std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
3250
3251       anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3252       if (aPreviousMode == 3)
3253       {
3254         anAISContext->RecomputePrsOnly (aTexturedIO);
3255       }
3256
3257       anAISContext->Display (aTexturedIO, Standard_True);
3258       return 0;
3259     }
3260     else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3261     {
3262       if (aTextureArg == "?")
3263       {
3264         TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3265
3266         theDi << "\n Files in current directory : \n\n";
3267         theDi.Eval ("glob -nocomplain *");
3268
3269         TCollection_AsciiString aCmnd ("glob -nocomplain ");
3270         aCmnd += aTextureFolder;
3271         aCmnd += "/* ";
3272
3273         theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
3274         theDi.Eval (aCmnd.ToCString());
3275         return 0;
3276       }
3277       else
3278       {
3279         aTexturedIO->SetTextureFileName (aTextureArg);
3280       }
3281     }
3282   }
3283
3284   // ------------------------------------
3285   //  Process other options and commands
3286   // ------------------------------------
3287
3288   Handle(TColStd_HSequenceOfAsciiString) aValues;
3289   if (aMapOfArgs.Find ("DEFAULT", aValues))
3290   {
3291     aTexturedIO->SetTextureRepeat (Standard_False);
3292     aTexturedIO->SetTextureOrigin (Standard_False);
3293     aTexturedIO->SetTextureScale  (Standard_False);
3294     aTexturedIO->EnableTextureModulate();
3295   }
3296   else
3297   {
3298     if (aMapOfArgs.Find ("SCALE", aValues))
3299     {
3300       if (aValues->Value(1) != "OFF")
3301       {
3302         aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3303       }
3304       else
3305       {
3306         aTexturedIO->SetTextureScale (Standard_False);
3307       }
3308     }
3309
3310     if (aMapOfArgs.Find ("ORIGIN", aValues))
3311     {
3312       if (aValues->Value(1) != "OFF")
3313       {
3314         aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3315       }
3316       else
3317       {
3318         aTexturedIO->SetTextureOrigin (Standard_False);
3319       }
3320     }
3321
3322     if (aMapOfArgs.Find ("REPEAT", aValues))
3323     {
3324       if (aValues->Value(1) != "OFF")
3325       {
3326         aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3327       }
3328       else
3329       {
3330         aTexturedIO->SetTextureRepeat (Standard_False);
3331       }
3332     }
3333
3334     if (aMapOfArgs.Find ("MODULATE", aValues))
3335     {
3336       if (aValues->Value(1) == "ON")
3337       {
3338         aTexturedIO->EnableTextureModulate();
3339       }
3340       else
3341       {
3342         aTexturedIO->DisableTextureModulate();
3343       }
3344     }
3345   }
3346
3347   if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3348   {
3349     anAISContext->RecomputePrsOnly (aTexturedIO);
3350   }
3351   else
3352   {
3353     anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3354     anAISContext->Display (aTexturedIO, Standard_True);
3355     anAISContext->Update (aTexturedIO,Standard_True);
3356   }
3357
3358   return 0;
3359 }
3360
3361 //! Auxiliary method to parse transformation persistence flags
3362 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3363                                            Graphic3d_TransModeFlags&      theFlags)
3364 {
3365   if (theFlagString == "zoom")
3366   {
3367     theFlags = Graphic3d_TMF_ZoomPers;
3368   }
3369   else if (theFlagString == "rotate")
3370   {
3371     theFlags = Graphic3d_TMF_RotatePers;
3372   }
3373   else if (theFlagString == "zoomrotate")
3374   {
3375     theFlags = Graphic3d_TMF_ZoomRotatePers;
3376   }
3377   else if (theFlagString == "trihedron"
3378         || theFlagString == "triedron")
3379   {
3380     theFlags = Graphic3d_TMF_TriedronPers;
3381   }
3382   else if (theFlagString == "none")
3383   {
3384     theFlags = Graphic3d_TMF_None;
3385   }
3386   else
3387   {
3388     return Standard_False;
3389   }
3390
3391   return Standard_True;
3392 }
3393
3394 //! Auxiliary method to parse transformation persistence flags
3395 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
3396                                              Aspect_TypeOfTriedronPosition& theCorner)
3397 {
3398   TCollection_AsciiString aString (theString);
3399   aString.LowerCase();
3400   if (aString == "center")
3401   {
3402     theCorner = Aspect_TOTP_CENTER;
3403   }
3404   else if (aString == "top"
3405         || aString == "upper")
3406   {
3407     theCorner = Aspect_TOTP_TOP;
3408   }
3409   else if (aString == "bottom"
3410         || aString == "lower")
3411   {
3412     theCorner = Aspect_TOTP_BOTTOM;
3413   }
3414   else if (aString == "left")
3415   {
3416     theCorner = Aspect_TOTP_LEFT;
3417   }
3418   else if (aString == "right")
3419   {
3420     theCorner = Aspect_TOTP_RIGHT;
3421   }
3422   else if (aString == "topleft"
3423         || aString == "leftupper"
3424         || aString == "upperleft")
3425   {
3426     theCorner = Aspect_TOTP_LEFT_UPPER;
3427   }
3428   else if (aString == "bottomleft"
3429         || aString == "leftlower"
3430         || aString == "lowerleft")
3431   {
3432     theCorner = Aspect_TOTP_LEFT_LOWER;
3433   }
3434   else if (aString == "topright"
3435         || aString == "rightupper"
3436         || aString == "upperright")
3437   {
3438     theCorner = Aspect_TOTP_RIGHT_UPPER;
3439   }
3440   else if (aString == "bottomright"
3441         || aString == "lowerright"
3442         || aString == "rightlower")
3443   {
3444     theCorner = Aspect_TOTP_RIGHT_LOWER;
3445   }
3446   else
3447   {
3448     return Standard_False;
3449   }
3450
3451   return Standard_True;
3452 }
3453
3454 //==============================================================================
3455 //function : VDisplay2
3456 //author   : ege
3457 //purpose  : Display an object from its name
3458 //==============================================================================
3459 static int VDisplay2 (Draw_Interpretor& theDI,
3460                       Standard_Integer  theArgNb,
3461                       const char**      theArgVec)
3462 {
3463   if (theArgNb < 2)
3464   {
3465     std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3466     return 1;
3467   }
3468
3469   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3470   if (aCtx.IsNull())
3471   {
3472     ViewerTest::ViewerInit();
3473     aCtx = ViewerTest::GetAISContext();
3474   }
3475
3476   // Parse input arguments
3477   ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3478   Standard_Integer   isMutable      = -1;
3479   Graphic3d_ZLayerId aZLayer        = Graphic3d_ZLayerId_UNKNOWN;
3480   Standard_Boolean   toDisplayLocal = Standard_False;
3481   Standard_Boolean   toReDisplay    = Standard_False;
3482   Standard_Integer   isSelectable   = -1;
3483   Standard_Integer   anObjDispMode  = -2;
3484   Standard_Integer   anObjHighMode  = -2;
3485   Standard_Boolean   toSetTrsfPers  = Standard_False;
3486   Handle(Graphic3d_TransformPers) aTrsfPers;
3487   TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3488   AIS_DisplayStatus aDispStatus = AIS_DS_None;
3489   Standard_Integer toDisplayInView = Standard_False;
3490   for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3491   {
3492     const TCollection_AsciiString aName     = theArgVec[anArgIter];
3493     TCollection_AsciiString       aNameCase = aName;
3494     aNameCase.LowerCase();
3495     if (anUpdateTool.parseRedrawMode (aName))
3496     {
3497       continue;
3498     }
3499     else if (aNameCase == "-mutable")
3500     {
3501       isMutable = 1;
3502     }
3503     else if (aNameCase == "-neutral")
3504     {
3505       aDispStatus = AIS_DS_Displayed;
3506     }
3507     else if (aNameCase == "-immediate"
3508           || aNameCase == "-top")
3509     {
3510       aZLayer = Graphic3d_ZLayerId_Top;
3511     }
3512     else if (aNameCase == "-topmost")
3513     {
3514       aZLayer = Graphic3d_ZLayerId_Topmost;
3515     }
3516     else if (aNameCase == "-osd"
3517           || aNameCase == "-toposd"
3518           || aNameCase == "-overlay")
3519     {
3520       aZLayer = Graphic3d_ZLayerId_TopOSD;
3521     }
3522     else if (aNameCase == "-botosd"
3523           || aNameCase == "-underlay")
3524     {
3525       aZLayer = Graphic3d_ZLayerId_BotOSD;
3526     }
3527     else if (aNameCase == "-select"
3528           || aNameCase == "-selectable")
3529     {
3530       isSelectable = 1;
3531     }
3532     else if (aNameCase == "-noselect"
3533           || aNameCase == "-noselection")
3534     {
3535       isSelectable = 0;
3536     }
3537     else if (aNameCase == "-dispmode"
3538           || aNameCase == "-displaymode")
3539     {
3540       if (++anArgIter >= theArgNb)
3541       {
3542         std::cerr << "Error: wrong syntax at " << aName << ".\n";
3543         return 1;
3544       }
3545
3546       anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3547     }
3548     else if (aNameCase == "-highmode"
3549           || aNameCase == "-highlightmode")
3550     {
3551       if (++anArgIter >= theArgNb)
3552       {
3553         std::cerr << "Error: wrong syntax at " << aName << ".\n";
3554         return 1;
3555       }
3556
3557       anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3558     }
3559     else if (aNameCase == "-3d")
3560     {
3561       toSetTrsfPers  = Standard_True;
3562       aTrsfPers.Nullify();
3563     }
3564     else if (aNameCase == "-2d"
3565           || aNameCase == "-trihedron"
3566           || aNameCase == "-triedron")
3567     {
3568       toSetTrsfPers  = Standard_True;
3569       aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3570
3571       if (anArgIter + 1 < theArgNb)
3572       {
3573         Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
3574         if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
3575         {
3576           ++anArgIter;
3577           aTrsfPers->SetCorner2d (aCorner);
3578
3579           if (anArgIter + 2 < theArgNb)
3580           {
3581             TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
3582             TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
3583             if (anX.IsIntegerValue()
3584              && anY.IsIntegerValue())
3585             {
3586               anArgIter += 2;
3587               aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
3588             }
3589           }
3590         }
3591       }
3592     }
3593     else if (aNameCase == "-trsfpers"
3594           || aNameCase == "-pers")
3595     {
3596       if (++anArgIter >= theArgNb
3597        || !aTrsfPers.IsNull())
3598       {
3599         std::cerr << "Error: wrong syntax at " << aName << ".\n";
3600         return 1;
3601       }
3602
3603       toSetTrsfPers  = Standard_True;
3604       Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3605       TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3606       aPersFlags.LowerCase();
3607       if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3608       {
3609         std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3610         return 1;
3611       }
3612
3613       if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
3614       {
3615         aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3616       }
3617       else if (aTrsfPersFlags != Graphic3d_TMF_None)
3618       {
3619         aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
3620       }
3621     }
3622     else if (aNameCase == "-trsfperspos"
3623           || aNameCase == "-perspos")
3624     {
3625       if (anArgIter + 2 >= theArgNb
3626        || aTrsfPers.IsNull())
3627       {
3628         std::cerr << "Error: wrong syntax at " << aName << ".\n";
3629         return 1;
3630       }
3631
3632       TCollection_AsciiString aX (theArgVec[++anArgIter]);
3633       TCollection_AsciiString aY (theArgVec[++anArgIter]);
3634       TCollection_AsciiString aZ = "0";
3635       if (!aX.IsRealValue()
3636        || !aY.IsRealValue())
3637       {
3638         std::cerr << "Error: wrong syntax at " << aName << ".\n";
3639         return 1;
3640       }
3641       if (anArgIter + 1 < theArgNb)
3642       {
3643         TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3644         if (aTemp.IsRealValue())
3645         {
3646           aZ = aTemp;
3647           ++anArgIter;
3648         }
3649       }
3650
3651       const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
3652       if (aTrsfPers->IsZoomOrRotate())
3653       {
3654         aTrsfPers->SetAnchorPoint (aPnt);
3655       }
3656       else if (aTrsfPers->IsTrihedronOr2d())
3657       {
3658         aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
3659       }
3660     }
3661     else if (aNameCase == "-layer")
3662     {
3663       if (++anArgIter >= theArgNb)
3664       {
3665         std::cerr << "Error: wrong syntax at " << aName << ".\n";
3666         return 1;
3667       }
3668
3669       TCollection_AsciiString aValue (theArgVec[anArgIter]);
3670       if (!aValue.IsIntegerValue())
3671       {
3672         std::cerr << "Error: wrong syntax at " << aName << ".\n";
3673         return 1;
3674       }
3675
3676       aZLayer = aValue.IntegerValue();
3677     }
3678     else if (aNameCase == "-view"
3679           || aNameCase == "-inview")
3680     {
3681       toDisplayInView = Standard_True;
3682     }
3683     else if (aNameCase == "-local")
3684     {
3685       aDispStatus = AIS_DS_Temporary;
3686       toDisplayLocal = Standard_True;
3687     }
3688     else if (aNameCase == "-redisplay")
3689     {
3690       toReDisplay = Standard_True;
3691     }
3692     else
3693     {
3694       aNamesOfDisplayIO.Append (aName);
3695     }
3696   }
3697
3698   if (aNamesOfDisplayIO.IsEmpty())
3699   {
3700     std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3701     return 1;
3702   }
3703
3704   // Prepare context for display
3705   if (toDisplayLocal && !aCtx->HasOpenedContext())
3706   {
3707     aCtx->OpenLocalContext (Standard_False);
3708   }
3709   else if (!toDisplayLocal && aCtx->HasOpenedContext())
3710   {
3711     aCtx->CloseAllContexts (Standard_False);
3712   }
3713
3714   // Display interactive objects
3715   for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3716   {
3717     const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3718
3719     if (!GetMapOfAIS().IsBound2 (aName))
3720     {
3721       // create the AIS_Shape from a name
3722       const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3723       if (!aShape.IsNull())
3724       {
3725         if (isMutable != -1)
3726         {
3727           aShape->SetMutable (isMutable == 1);
3728         }
3729         if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3730         {
3731           aShape->SetZLayer (aZLayer);
3732         }
3733         if (toSetTrsfPers)
3734         {
3735           aCtx->SetTransformPersistence (aShape, aTrsfPers);
3736         }
3737         if (anObjDispMode != -2)
3738         {
3739           aShape->SetDisplayMode (anObjDispMode);
3740         }
3741         if (anObjHighMode != -2)
3742         {
3743           aShape->SetHilightMode (anObjHighMode);
3744         }
3745         if (!toDisplayLocal)
3746           GetMapOfAIS().Bind (aShape, aName);
3747
3748         Standard_Integer aDispMode = aShape->HasDisplayMode()
3749                                    ? aShape->DisplayMode()
3750                                    : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3751                                     ? aCtx->DisplayMode()
3752                                     : 0);
3753         Standard_Integer aSelMode = -1;
3754         if (isSelectable ==  1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3755         {
3756           aSelMode = aShape->GlobalSelectionMode();
3757         }
3758
3759         aCtx->Display (aShape, aDispMode, aSelMode,
3760                        Standard_False, aShape->AcceptShapeDecomposition(),
3761                        aDispStatus);
3762         if (toDisplayInView)
3763         {
3764           for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
3765           {
3766             aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
3767           }
3768           aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3769         }
3770       }
3771       else
3772       {
3773         std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3774       }
3775       continue;
3776     }
3777
3778     Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3779     if (isMutable != -1)
3780     {
3781       aShape->SetMutable (isMutable == 1);
3782     }
3783     if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3784     {
3785       aShape->SetZLayer (aZLayer);
3786     }
3787     if (toSetTrsfPers)
3788     {
3789       aCtx->SetTransformPersistence (aShape, aTrsfPers);
3790     }
3791     if (anObjDispMode != -2)
3792     {
3793       aShape->SetDisplayMode (anObjDispMode);
3794     }
3795     if (anObjHighMode != -2)
3796     {
3797       aShape->SetHilightMode (anObjHighMode);
3798     }
3799     Standard_Integer aDispMode = aShape->HasDisplayMode()
3800                                 ? aShape->DisplayMode()
3801                                 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3802                                 ? aCtx->DisplayMode()
3803                                 : 0);
3804     Standard_Integer aSelMode = -1;
3805     if (isSelectable ==  1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
3806     {
3807       aSelMode = aShape->GlobalSelectionMode();
3808     }
3809
3810     if (aShape->Type() == AIS_KOI_Datum)
3811     {
3812       aCtx->Display (aShape, Standard_False);
3813     }
3814     else
3815     {
3816       theDI << "Display " << aName.ToCString() << "\n";
3817
3818       // update the Shape in the AIS_Shape
3819       TopoDS_Shape      aNewShape = GetShapeFromName (aName.ToCString());
3820       Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3821       if (!aShapePrs.IsNull())
3822       {
3823         if (!aShapePrs->Shape().IsEqual (aNewShape))
3824         {
3825           toReDisplay = Standard_True;
3826         }
3827         aShapePrs->Set (aNewShape);
3828       }
3829       if (toReDisplay)
3830       {
3831         aCtx->Redisplay (aShape, Standard_False);
3832       }
3833
3834       if (aSelMode == -1)
3835       {
3836         aCtx->Erase (aShape);
3837       }
3838       aCtx->Display (aShape, aDispMode, aSelMode,
3839                      Standard_False, aShape->AcceptShapeDecomposition(),
3840                      aDispStatus);
3841       if (toDisplayInView)
3842       {
3843         aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3844       }
3845     }
3846   }
3847
3848   return 0;
3849 }
3850
3851 //===============================================================================================
3852 //function : VUpdate
3853 //purpose  :
3854 //===============================================================================================
3855 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3856 {
3857   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3858   if (aContextAIS.IsNull())
3859   {
3860     std::cout << theArgVec[0] << "AIS context is not available.\n";
3861     return 1;
3862   }
3863
3864   if (theArgsNb < 2)
3865   {
3866     std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3867     return 1;
3868   }
3869
3870   const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3871
3872   AIS_ListOfInteractive aListOfIO;
3873
3874   for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3875   {
3876     TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3877
3878     Handle(AIS_InteractiveObject) anAISObj;
3879     if (anAISMap.IsBound2 (aName))
3880     {
3881       anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3882     }
3883
3884     if (anAISObj.IsNull())
3885     {
3886       std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3887       return 1;
3888     }
3889
3890     aListOfIO.Append (anAISObj);
3891   }
3892
3893   AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3894   for (; anIOIt.More(); anIOIt.Next())
3895   {
3896     aContextAIS->Update (anIOIt.Value(), Standard_False);
3897   }
3898
3899   aContextAIS->UpdateCurrentViewer();
3900
3901   return 0;
3902 }
3903
3904 //==============================================================================
3905 //function : VPerf
3906 //purpose  : Test the annimation of an object along a
3907 //           predifined trajectory
3908 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3909 //==============================================================================
3910
3911 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3912
3913   OSD_Timer myTimer;
3914   if (TheAISContext()->HasOpenedContext())
3915     TheAISContext()->CloseLocalContext();
3916
3917   Standard_Real Step=4*M_PI/180;
3918   Standard_Real Angle=0;
3919
3920   Handle(AIS_InteractiveObject) aIO;
3921   if (GetMapOfAIS().IsBound2(argv[1]))
3922     aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3923   if (aIO.IsNull())
3924     return 1;
3925
3926   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3927
3928   myTimer.Start();
3929
3930   if (Draw::Atoi(argv[3])==1 ) {
3931     di<<" Primitives sensibles OFF\n";
3932     TheAISContext()->Deactivate(aIO);
3933   }
3934   else {
3935     di<<" Primitives sensibles ON\n";
3936   }
3937   // Movement par transformation
3938   if(Draw::Atoi(argv[2]) ==1) {
3939     di<<" Calcul par Transformation\n";
3940     for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3941
3942       Angle=Step*myAngle;
3943       gp_Trsf myTransfo;
3944       myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3945       TheAISContext()->SetLocation(aShape,myTransfo);
3946       TheAISContext() ->UpdateCurrentViewer();
3947
3948     }
3949   }
3950   else {
3951     di<<" Calcul par Locations\n";
3952     gp_Trsf myAngleTrsf;
3953     myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step  );
3954     TopLoc_Location myDeltaAngle (myAngleTrsf);
3955     TopLoc_Location myTrueLoc;
3956
3957     for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3958
3959       Angle=Step*myAngle;
3960       myTrueLoc=myTrueLoc*myDeltaAngle;
3961       TheAISContext()->SetLocation(aShape,myTrueLoc );
3962       TheAISContext() ->UpdateCurrentViewer();
3963     }
3964   }
3965   if (Draw::Atoi(argv[3])==1 ){
3966     // On reactive la selection des primitives sensibles
3967     TheAISContext()->Activate(aIO,0);
3968   }
3969   a3DView() -> Redraw();
3970   myTimer.Stop();
3971   di<<" Temps ecoule \n";
3972   myTimer.Show();
3973   return 0;
3974 }
3975
3976
3977 //==================================================================================
3978 // Function : VAnimation
3979 //==================================================================================
3980 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3981   if (argc != 5) {
3982     di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile\n";
3983     return 1;
3984   }
3985
3986   Standard_Real thread = 4;
3987   Standard_Real angleA=0;
3988   Standard_Real angleB;
3989   Standard_Real X;
3990   gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3991
3992   BRep_Builder B;
3993   TopoDS_Shape CrankArm;
3994   TopoDS_Shape CylinderHead;
3995   TopoDS_Shape Propeller;
3996   TopoDS_Shape EngineBlock;
3997
3998   //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3999   //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
4000   //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
4001   //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
4002   BRepTools::Read(CrankArm,argv[1],B);
4003   BRepTools::Read(CylinderHead,argv[2],B);
4004   BRepTools::Read(Propeller,argv[3],B);
4005   BRepTools::Read(EngineBlock,argv[4],B);
4006
4007   if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure.\n";}
4008
4009
4010   OSD_Timer myTimer;
4011   myTimer.Start();
4012
4013   Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
4014   Handle(AIS_Shape) myAisEngineBlock  = new AIS_Shape (EngineBlock);
4015   Handle(AIS_Shape) myAisCrankArm     = new AIS_Shape (CrankArm);
4016   Handle(AIS_Shape) myAisPropeller    = new AIS_Shape (Propeller);
4017
4018   GetMapOfAIS().Bind(myAisCylinderHead,"a");
4019   GetMapOfAIS().Bind(myAisEngineBlock,"b");
4020   GetMapOfAIS().Bind(myAisCrankArm,"c");
4021   GetMapOfAIS().Bind(myAisPropeller,"d");
4022
4023   myAisCylinderHead->SetMutable (Standard_True);
4024   myAisEngineBlock ->SetMutable (Standard_True);
4025   myAisCrankArm    ->SetMutable (Standard_True);
4026   myAisPropeller   ->SetMutable (Standard_True);
4027
4028   TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
4029   TheAISContext()->SetColor (myAisEngineBlock,  Quantity_NOC_RED);
4030   TheAISContext()->SetColor (myAisPropeller,    Quantity_NOC_GREEN);
4031
4032   TheAISContext()->Display (myAisCylinderHead, Standard_False);
4033   TheAISContext()->Display (myAisEngineBlock,  Standard_False);
4034   TheAISContext()->Display (myAisCrankArm,     Standard_False);
4035   TheAISContext()->Display (myAisPropeller,    Standard_False);
4036
4037   TheAISContext()->Deactivate(myAisCylinderHead);
4038   TheAISContext()->Deactivate(myAisEngineBlock );
4039   TheAISContext()->Deactivate(myAisCrankArm    );
4040   TheAISContext()->Deactivate(myAisPropeller   );
4041
4042   // Boucle de mouvement
4043   for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
4044
4045     angleA = thread*myAngle*M_PI/180;
4046     X = Sin(angleA)*3/8;
4047     angleB = atan(X / Sqrt(-X * X + 1));
4048     Standard_Real decal(25*0.6);
4049
4050
4051     //Build a transformation on the display
4052     gp_Trsf aPropellerTrsf;
4053     aPropellerTrsf.SetRotation(Ax1,angleA);
4054     TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
4055
4056     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));
4057     gp_Trsf aCrankArmTrsf;
4058     aCrankArmTrsf.SetTransformation(   base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
4059     TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
4060
4061     TheAISContext()->UpdateCurrentViewer();
4062   }
4063
4064   TopoDS_Shape myNewCrankArm  =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
4065   TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
4066
4067   myAisCrankArm ->ResetTransformation();
4068   myAisPropeller->ResetTransformation();
4069
4070   myAisCrankArm  -> Set(myNewCrankArm );
4071   myAisPropeller -> Set(myNewPropeller);
4072
4073   TheAISContext()->Activate(myAisCylinderHead,0);
4074   TheAISContext()->Activate(myAisEngineBlock,0 );
4075   TheAISContext()->Activate(myAisCrankArm ,0   );
4076   TheAISContext()->Activate(myAisPropeller ,0  );
4077
4078   myTimer.Stop();
4079   myTimer.Show();
4080   myTimer.Start();
4081
4082   TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
4083   TheAISContext()->Redisplay(myAisPropeller,Standard_False);
4084
4085   TheAISContext()->UpdateCurrentViewer();
4086   a3DView()->Redraw();
4087
4088   myTimer.Stop();
4089   myTimer.Show();
4090
4091   return 0;
4092
4093 }
4094
4095 //==============================================================================
4096 //function : VShading
4097 //purpose  : Sharpen or roughten the quality of the shading
4098 //Draw arg : vshading ShapeName 0.1->0.00001  1 deg-> 30 deg
4099 //==============================================================================
4100 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4101 {
4102   Standard_Real    myDevCoef;
4103   Handle(AIS_InteractiveObject) TheAisIO;
4104
4105   // Verifications
4106   const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4107
4108   if (TheAISContext()->HasOpenedContext())
4109     TheAISContext()->CloseLocalContext();
4110
4111   if (argc < 3) {
4112     myDevCoef  = 0.0008;
4113   } else {
4114     myDevCoef  =Draw::Atof(argv[2]);
4115   }
4116
4117   TCollection_AsciiString name=argv[1];
4118   if (GetMapOfAIS().IsBound2(name ))
4119     TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4120   if (TheAisIO.IsNull())
4121     TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4122
4123   if (HaveToSet)
4124     TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4125   else
4126     TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4127
4128   TheAISContext()->Redisplay(TheAisIO);
4129   return 0;
4130 }
4131 //==============================================================================
4132 //function : HaveMode
4133 //use      : VActivatedModes
4134 //==============================================================================
4135 #include <TColStd_ListIteratorOfListOfInteger.hxx>
4136
4137 Standard_Boolean  HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode  )
4138 {
4139   TColStd_ListOfInteger List;
4140   TheAISContext()->ActivatedModes (TheAisIO,List);
4141   TColStd_ListIteratorOfListOfInteger it;
4142   Standard_Boolean Found=Standard_False;
4143   for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4144     if (it.Value()==mode ) Found=Standard_True;
4145   }
4146   return Found;
4147 }
4148
4149
4150
4151 //==============================================================================
4152 //function : VActivatedMode
4153 //author   : ege
4154 //purpose  : permet d'attribuer a chacune des shapes un mode d'activation
4155 //           (edges,vertex...)qui lui est propre et le mode de selection standard.
4156 //           La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4157 //             Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4158 //           qu'un nom et qu'un mode.
4159 //Draw arg : vsetam  [ShapeName] mode(0,1,2,3,4,5,6,7)
4160 //==============================================================================
4161 #include <AIS_ListIteratorOfListOfInteractive.hxx>
4162
4163 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4164
4165 {
4166   Standard_Boolean ThereIsName = Standard_False ;
4167
4168   if(!a3DView().IsNull()){
4169
4170     const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
4171     // verification des arguments
4172     if (HaveToSet) {
4173       if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
4174       ThereIsName = (argc == 3);
4175     }
4176     else {
4177       // vunsetam
4178       if (argc>1) {di<<" Syntaxe error\n";return 1;}
4179       else {
4180         di<<" R.A.Z de tous les modes de selecion\n";
4181         di<<" Fermeture du Context local\n";
4182         if (TheAISContext()->HasOpenedContext())
4183           TheAISContext()->CloseLocalContext();
4184       }
4185     }
4186
4187     // IL n'y a aps de nom de shape passe en argument
4188     if (HaveToSet && !ThereIsName){
4189       Standard_Integer aMode=Draw::Atoi(argv [1]);
4190
4191       const char *cmode="???";
4192       switch (aMode) {
4193       case 0: cmode = "Shape"; break;
4194       case 1: cmode = "Vertex"; break;
4195       case 2: cmode = "Edge"; break;
4196       case 3: cmode = "Wire"; break;
4197       case 4: cmode = "Face"; break;
4198       case 5: cmode = "Shell"; break;
4199       case 6: cmode = "Solid"; break;
4200       case 7: cmode = "Compound"; break;
4201       }
4202
4203       if( !TheAISContext()->HasOpenedContext() ) {
4204         // il n'y a pas de Context local d'ouvert
4205         // on en ouvre un et on charge toutes les shapes displayees
4206         // on load tous les objets displayees et on Activate les objets de la liste
4207         AIS_ListOfInteractive ListOfIO;
4208         // on sauve dans une AISListOfInteractive tous les objets currents
4209         if (TheAISContext()->NbSelected()>0 ){
4210           TheAISContext()->UnhilightSelected(Standard_False);
4211
4212           for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4213             ListOfIO.Append(TheAISContext()->SelectedInteractive() );
4214           }
4215         }
4216
4217         TheAISContext()->OpenLocalContext(Standard_False);
4218         ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4219           it (GetMapOfAIS());
4220         while(it.More()){
4221           Handle(AIS_InteractiveObject) aIO =
4222             Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4223           if (!aIO.IsNull())
4224             TheAISContext()->Load(aIO,0,Standard_False);
4225           it.Next();
4226         }
4227         // traitement des objets qui etaient currents dans le Contexte global
4228         if (!ListOfIO.IsEmpty() ) {
4229           // il y avait des objets currents
4230           AIS_ListIteratorOfListOfInteractive iter;
4231           for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4232             Handle(AIS_InteractiveObject) aIO=iter.Value();
4233             TheAISContext()->Activate(aIO,aMode);
4234             di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString()  <<"\n";
4235           }
4236         }
4237         else {
4238           // On applique le mode a tous les objets displayes
4239           ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4240             it2 (GetMapOfAIS());
4241           while(it2.More()){
4242             Handle(AIS_InteractiveObject) aIO =
4243               Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4244             if (!aIO.IsNull()) {
4245               di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4246               TheAISContext()->Activate(aIO,aMode);
4247             }
4248             it2.Next();
4249           }
4250         }
4251
4252       }
4253
4254       else {
4255         // un Context local est deja ouvert
4256         // Traitement des objets du Context local
4257         if (TheAISContext()->NbSelected()>0 ){
4258           TheAISContext()->UnhilightSelected(Standard_False);
4259           // il y a des objets selected,on les parcourt
4260           for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4261             Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
4262
4263
4264             if (HaveMode(aIO,aMode) ) {
4265               di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4266               TheAISContext()->Deactivate(aIO,aMode);
4267             }
4268             else{
4269               di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4270               TheAISContext()->Activate(aIO,aMode);
4271             }
4272
4273           }
4274         }
4275         else{
4276           // il n'y a pas d'objets selected
4277           // tous les objets diplayes sont traites
4278           ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4279             it (GetMapOfAIS());
4280           while(it.More()){
4281             Handle(AIS_InteractiveObject) aIO =
4282               Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4283             if (!aIO.IsNull()) {
4284               if (HaveMode(aIO,aMode) ) {
4285                 di<<" Mode: "<<cmode<<" OFF pour "
4286                   <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4287                 TheAISContext()->Deactivate(aIO,aMode);
4288               }
4289               else{
4290                 di<<" Mode: "<<cmode<<" ON pour"
4291                   <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4292                 TheAISContext()->Activate(aIO,aMode);
4293               }
4294             }
4295             it.Next();
4296           }
4297         }
4298       }
4299     }
4300     else if (HaveToSet && ThereIsName){
4301       Standard_Integer aMode=Draw::Atoi(argv [2]);
4302       Handle(AIS_InteractiveObject) aIO =
4303         Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4304
4305       if (!aIO.IsNull()) {
4306         const char *cmode="???";
4307
4308         switch (aMode) {
4309         case 0: cmode = "Shape"; break;
4310         case 1: cmode = "Vertex"; break;
4311         case 2: cmode = "Edge"; break;
4312         case 3: cmode = "Wire"; break;
4313         case 4: cmode = "Face"; break;
4314         case 5: cmode = "Shell"; break;
4315         case 6: cmode = "Solid"; break;
4316         case 7: cmode = "Compound"; break;
4317         }
4318
4319         if( !TheAISContext()->HasOpenedContext() ) {
4320           TheAISContext()->OpenLocalContext(Standard_False);
4321           // On charge tous les objets de la map
4322           ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4323           while(it.More()){
4324             Handle(AIS_InteractiveObject) aShape=
4325               Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4326             if (!aShape.IsNull())
4327               TheAISContext()->Load(aShape,0,Standard_False);
4328             it.Next();
4329           }
4330           TheAISContext()->Activate(aIO,aMode);
4331           di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4332         }
4333
4334         else {
4335           // un Context local est deja ouvert
4336           if (HaveMode(aIO,aMode) ) {
4337             di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4338             TheAISContext()->Deactivate(aIO,aMode);
4339           }
4340           else{
4341             di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4342             TheAISContext()->Activate(aIO,aMode);
4343           }
4344         }
4345       }
4346     }
4347   }
4348   return 0;
4349 }
4350
4351 //! Auxiliary method to print Interactive Object information
4352 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4353                      const Handle(Standard_Transient)&                     theObject,
4354                      Draw_Interpretor&                                     theDI)
4355 {
4356   const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4357   if (anObj.IsNull())
4358   {
4359     theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4360     return;
4361   }
4362
4363   theDI << (TheAISContext()->IsDisplayed  (anObj) ? "Displayed"  : "Hidden   ")
4364         << (TheAISContext()->IsSelected   (anObj) ? " Selected" : "         ")
4365         << (theDetected.Contains (anObj)          ? " Detected" : "         ")
4366         << " Type: ";
4367   if (anObj->Type() == AIS_KOI_Datum)
4368   {
4369     // AIS_Datum
4370     if      (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4371     else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4372     else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4373     else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4374     else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4375     else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4376     else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4377   }
4378   // AIS_Shape
4379   else if (anObj->Type()      == AIS_KOI_Shape
4380         && anObj->Signature() == 0)
4381   {
4382     theDI << " AIS_Shape";
4383   }
4384   else if (anObj->Type() == AIS_KOI_Relation)
4385   {
4386     // AIS_Dimention and AIS_Relation
4387     Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4388     switch (aRelation->KindOfDimension())
4389     {
4390       case AIS_KOD_PLANEANGLE:     theDI << " AIS_AngleDimension"; break;
4391       case AIS_KOD_LENGTH:         theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4392       case AIS_KOD_DIAMETER:       theDI << " AIS_DiameterDimension"; break;
4393       case AIS_KOD_ELLIPSERADIUS:  theDI << " AIS_EllipseRadiusDimension"; break;
4394       //case AIS_KOD_FILLETRADIUS:   theDI << " AIS_FilletRadiusDimension "; break;
4395       case AIS_KOD_OFFSET:         theDI << " AIS_OffsetDimension"; break;
4396       case AIS_KOD_RADIUS:         theDI << " AIS_RadiusDimension"; break;
4397       default:                     theDI << " UNKNOWN dimension"; break;
4398     }
4399   }
4400   else
4401   {
4402     theDI << " UserPrs";
4403   }
4404   theDI << " (" << theObject->DynamicType()->Name() << ")";
4405 }
4406
4407 //! Print information about locally selected sub-shapes
4408 template <typename T>
4409 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4410 {
4411   const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4412   TCollection_AsciiString aPrevName;
4413   for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4414   {
4415     const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4416     const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4417     if (aShapeIO.IsNull() || anOwner.IsNull())
4418       continue;
4419     if (isGlobalCtx)
4420     {
4421       if (anOwner == aShapeIO->GlobalSelOwner())
4422         continue;
4423     }
4424     const TopoDS_Shape      aSubShape = theContext->SelectedShape();
4425     if (aSubShape.IsNull()
4426       || aShapeIO.IsNull()
4427       || !GetMapOfAIS().IsBound1 (aShapeIO))
4428     {
4429       continue;
4430     }
4431
4432     const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4433     TopTools_MapOfShape aFilter;
4434     Standard_Integer    aNumber = 0;
4435     const TopoDS_Shape  aShape  = aShapeIO->Shape();
4436     for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4437          anIter.More(); anIter.Next())
4438     {
4439       if (!aFilter.Add (anIter.Current()))
4440       {
4441         continue; // filter duplicates
4442       }
4443
4444       ++aNumber;
4445       if (!anIter.Current().IsSame (aSubShape))
4446       {
4447         continue;
4448       }
4449
4450       Standard_CString aShapeName = NULL;
4451       switch (aSubShape.ShapeType())
4452       {
4453         case TopAbs_COMPOUND:  aShapeName = " Compound"; break;
4454         case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4455         case TopAbs_SOLID:     aShapeName = "    Solid"; break;
4456         case TopAbs_SHELL:     aShapeName = "    Shell"; break;
4457         case TopAbs_FACE:      aShapeName = "     Face"; break;
4458         case TopAbs_WIRE:      aShapeName = "     Wire"; break;
4459         case TopAbs_EDGE:      aShapeName = "     Edge"; break;
4460         case TopAbs_VERTEX:    aShapeName = "   Vertex"; break;
4461         default:
4462         case TopAbs_SHAPE:     aShapeName = "    Shape"; break;
4463       }
4464
4465       if (aParentName != aPrevName)
4466       {
4467         theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4468         aPrevName = aParentName;
4469       }
4470       theDI << "  " << aShapeName << " #" << aNumber << "\n";
4471       break;
4472     }
4473   }
4474 }
4475
4476 //==============================================================================
4477 //function : VState
4478 //purpose  :
4479 //==============================================================================
4480 static Standard_Integer VState (Draw_Interpretor& theDI,
4481                                 Standard_Integer  theArgNb,
4482                                 Standard_CString* theArgVec)
4483 {
4484   Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4485   if (aCtx.IsNull())
4486   {
4487     std::cerr << "Error: No opened viewer!\n";
4488     return 1;
4489   }
4490
4491   Standard_Boolean toPrintEntities = Standard_False;
4492   Standard_Boolean toCheckSelected = Standard_False;
4493
4494   for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4495   {
4496     TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4497     anOption.LowerCase();
4498     if (anOption == "-detectedentities"
4499       || anOption == "-entities")
4500     {
4501       toPrintEntities = Standard_True;
4502     }
4503     else if (anOption == "-hasselected")
4504     {
4505       toCheckSelected = Standard_True;
4506     }
4507   }
4508
4509   if (toCheckSelected)
4510   {
4511     aCtx->InitSelected();
4512     TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4513     theDI << "Check if context has selected shape: " << hasSelected << "\n";
4514
4515     return 0;
4516   }
4517
4518   if (toPrintEntities)
4519   {
4520     theDI << "Detected entities:\n";
4521     Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4522     SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4523     for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4524     {
4525       const SelectMgr_SortCriterion&              aPickData = aSelector->PickedData (aPickIter);
4526       const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4527       Handle(SelectMgr_EntityOwner) anOwner    = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4528       Handle(AIS_InteractiveObject) anObj      = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4529       TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4530       aName.LeftJustify (20, ' ');
4531       char anInfoStr[512];
4532       Sprintf (anInfoStr,
4533                " Depth: %g Distance: %g Point: %g %g %g",
4534                aPickData.Depth,
4535                aPickData.MinDist,
4536                aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4537       theDI << "  " << aName
4538             << anInfoStr
4539             << " (" << anEntity->DynamicType()->Name() << ")"
4540             << "\n";
4541
4542       Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4543       if (!aBRepOwner.IsNull())
4544       {
4545         theDI << "                       Detected Shape: "
4546               << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4547               << "\n";
4548       }
4549
4550       Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4551       if (!aWire.IsNull())
4552       {
4553         Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4554         theDI << "                       Detected Child: "
4555               << aSen->DynamicType()->Name()
4556               << "\n";
4557       }
4558
4559       Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4560       if (!aPrimArr.IsNull())
4561       {
4562         theDI << "                       Detected Element: "
4563               << aPrimArr->LastDetectedElement()
4564               << "\n";
4565       }
4566     }
4567     return 0;
4568   }
4569
4570   NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4571   for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4572   {
4573     aDetected.Add (aCtx->DetectedCurrentObject());
4574   }
4575
4576   const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4577   if (theArgNb >= 2
4578    && !toShowAll)
4579   {
4580     for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4581     {
4582       const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4583       if (!GetMapOfAIS().IsBound2 (anObjName))
4584       {
4585         theDI << anObjName << " doesn't exist!\n";
4586         continue;
4587       }
4588
4589       const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4590       TCollection_AsciiString aName = anObjName;
4591       aName.LeftJustify (20, ' ');
4592       theDI << "  " << aName << " ";
4593       objInfo (aDetected, anObjTrans, theDI);
4594       theDI << "\n";
4595     }
4596     return 0;
4597   }
4598
4599   if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4600   {
4601     NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
4602     for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
4603     {
4604       const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4605       const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4606       // handle whole object selection
4607       if (anOwner == anObj->GlobalSelOwner())
4608       {
4609         TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4610         aName.LeftJustify (20, ' ');
4611         theDI << aName << " ";
4612         objInfo (aDetected, anObj, theDI);
4613         theDI << "\n";
4614       }
4615     }
4616
4617     // process selected sub-shapes
4618     printLocalSelectionInfo (aCtx, theDI);
4619
4620     return 0;
4621   }
4622
4623   theDI << "Neutral-point state:\n";
4624   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4625        anObjIter.More(); anObjIter.Next())
4626   {
4627     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4628     if (anObj.IsNull())
4629     {
4630       continue;
4631     }
4632
4633     TCollection_AsciiString aName = anObjIter.Key2();
4634     aName.LeftJustify (20, ' ');
4635     theDI << "  " << aName << " ";
4636     objInfo (aDetected, anObj, theDI);
4637     theDI << "\n";
4638   }
4639   printLocalSelectionInfo (aCtx, theDI);
4640   if (aCtx->HasOpenedContext())
4641     printLocalSelectionInfo (aCtx->LocalContext(), theDI);
4642   return 0;
4643 }
4644
4645 //=======================================================================
4646 //function : PickObjects
4647 //purpose  :
4648 //=======================================================================
4649 Standard_Boolean  ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4650                                           const AIS_KindOfInteractive TheType,
4651                                           const Standard_Integer TheSignature,
4652                                           const Standard_Integer MaxPick)
4653 {
4654   Handle(AIS_InteractiveObject) IO;
4655   Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4656
4657   // step 1: prepare the data
4658   if(curindex !=0){
4659     Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4660     TheAISContext()->AddFilter(F1);
4661   }
4662
4663   // step 2 : wait for the selection...
4664   Standard_Integer NbPickGood (0),NbToReach(arr->Length());
4665   Standard_Integer NbPickFail(0);
4666   Standard_Integer argccc = 5;
4667   const char *bufff[] = { "A", "B", "C","D", "E" };
4668   const char **argvvv = (const char **) bufff;
4669
4670
4671   while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4672     while(ViewerMainLoop(argccc,argvvv)){}
4673     Standard_Integer NbStored = TheAISContext()->NbSelected();
4674     if(NbStored != NbPickGood)
4675       NbPickGood= NbStored;
4676     else
4677       NbPickFail++;
4678     cout<<"NbPicked =  "<<NbPickGood<<" |  Nb Pick Fail :"<<NbPickFail<<endl;
4679   }
4680
4681   // step3 get result.
4682
4683   if (NbPickFail >= NbToReach)
4684     return Standard_False;
4685
4686   Standard_Integer i(0);
4687   for(TheAISContext()->InitSelected();
4688       TheAISContext()->MoreSelected();
4689       TheAISContext()->NextSelected()){
4690     i++;
4691     Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4692     arr->SetValue(i,IO2);
4693   }
4694
4695
4696   if(curindex>0)
4697     TheAISContext()->CloseLocalContext(curindex);
4698
4699   return Standard_True;
4700 }
4701
4702
4703 //=======================================================================
4704 //function : PickObject
4705 //purpose  :
4706 //=======================================================================
4707 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4708                                                      const Standard_Integer TheSignature,
4709                                                      const Standard_Integer MaxPick)
4710 {
4711   Handle(AIS_InteractiveObject) IO;
4712   Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4713
4714   // step 1: prepare the data
4715
4716   if(curindex !=0){
4717     Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4718     TheAISContext()->AddFilter(F1);
4719   }
4720
4721   // step 2 : wait for the selection...
4722   Standard_Boolean IsGood (Standard_False);
4723   Standard_Integer NbPick(0);
4724   Standard_Integer argccc = 5;
4725   const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4726   const char **argvvv = (const char **) bufff;
4727
4728
4729   while(!IsGood && NbPick<= MaxPick){
4730     while(ViewerMainLoop(argccc,argvvv)){}
4731     IsGood = (TheAISContext()->NbSelected()>0) ;
4732     NbPick++;
4733     cout<<"Nb Pick :"<<NbPick<<endl;
4734   }
4735
4736
4737   // step3 get result.
4738   if(IsGood){
4739     TheAISContext()->InitSelected();
4740     IO = TheAISContext()->SelectedInteractive();
4741   }
4742
4743   if(curindex!=0)
4744     TheAISContext()->CloseLocalContext(curindex);
4745   return IO;
4746 }
4747
4748 //=======================================================================
4749 //function : PickShape
4750 //purpose  : First Activate the rightmode + Put Filters to be able to
4751 //           pick objets that are of type <TheType>...
4752 //=======================================================================
4753
4754 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4755                                    const Standard_Integer MaxPick)
4756 {
4757
4758   // step 1: prepare the data
4759
4760   Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4761   TopoDS_Shape result;
4762
4763   if(TheType==TopAbs_SHAPE){
4764     Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4765     TheAISContext()->AddFilter(F1);
4766   }
4767   else{
4768     Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4769     TheAISContext()->AddFilter(TF);
4770     TheAISContext()->ActivateStandardMode(TheType);
4771
4772   }
4773
4774
4775   // step 2 : wait for the selection...
4776   Standard_Boolean NoShape (Standard_True);
4777   Standard_Integer NbPick(0);
4778   Standard_Integer argccc = 5;
4779   const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4780   const char **argvvv = (const char **) bufff;
4781
4782
4783   while(NoShape && NbPick<= MaxPick){
4784     while(ViewerMainLoop(argccc,argvvv)){}
4785     NoShape = (TheAISContext()->NbSelected()==0) ;
4786     NbPick++;
4787     cout<<"Nb Pick :"<<NbPick<<endl;
4788   }
4789
4790   // step3 get result.
4791
4792   if(!NoShape){
4793
4794     TheAISContext()->InitSelected();
4795     if(TheAISContext()->HasSelectedShape())
4796       result = TheAISContext()->SelectedShape();
4797     else{
4798       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4799       result = Handle(AIS_Shape)::DownCast (IO)->Shape();
4800     }
4801   }
4802
4803   if(curindex>0)
4804     TheAISContext()->CloseLocalContext(curindex);
4805
4806   return result;
4807 }
4808
4809
4810 //=======================================================================
4811 //function : PickShapes
4812 //purpose  :
4813 //=======================================================================
4814 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4815                                          Handle(TopTools_HArray1OfShape)& thearr,
4816                                          const Standard_Integer MaxPick)
4817 {
4818
4819   Standard_Integer Taille = thearr->Length();
4820   if(Taille>1)
4821     cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
4822
4823   // step 1: prepare the data
4824   Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4825   if(TheType==TopAbs_SHAPE){
4826     Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4827     TheAISContext()->AddFilter(F1);
4828   }
4829   else{
4830     Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4831     TheAISContext()->AddFilter(TF);
4832     TheAISContext()->ActivateStandardMode(TheType);
4833
4834   }
4835
4836   // step 2 : wait for the selection...
4837   Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
4838   Standard_Integer NbPickFail(0);
4839   Standard_Integer argccc = 5;
4840   const char *bufff[] = { "A", "B", "C","D", "E" };
4841   const char **argvvv = (const char **) bufff;
4842
4843
4844   while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4845     while(ViewerMainLoop(argccc,argvvv)){}
4846     Standard_Integer NbStored = TheAISContext()->NbSelected();
4847     if (NbStored != NbPickGood)
4848       NbPickGood= NbStored;
4849     else
4850       NbPickFail++;
4851     cout<<"NbPicked =  "<<NbPickGood<<" |  Nb Pick Fail :"<<NbPickFail<<"\n";
4852   }
4853
4854   // step3 get result.
4855
4856   if (NbPickFail >= NbToReach)
4857     return Standard_False;
4858
4859   Standard_Integer i(0);
4860   for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4861     i++;
4862     if(TheAISContext()->HasSelectedShape())
4863       thearr->SetValue(i,TheAISContext()->SelectedShape());
4864     else{
4865       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4866       thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
4867     }
4868   }
4869
4870   TheAISContext()->CloseLocalContext(curindex);
4871   return Standard_True;
4872 }
4873
4874
4875 //=======================================================================
4876 //function : VPickShape
4877 //purpose  :
4878 //=======================================================================
4879 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4880 {
4881   TopoDS_Shape PickSh;
4882   TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4883
4884   if(argc==1)
4885     theType = TopAbs_SHAPE;
4886   else{
4887     if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4888     else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4889     else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4890     else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4891     else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4892     else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4893     else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4894   }
4895
4896   static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4897   static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4898
4899   TCollection_AsciiString name;
4900
4901
4902   Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4903   if(NbToPick==1){
4904     PickSh = ViewerTest::PickShape(theType);
4905
4906     if(PickSh.IsNull())
4907       return 1;
4908     if(argc>2){
4909       name += argv[2];
4910     }
4911     else{
4912
4913       if(!PickSh.IsNull()){
4914         nbOfSub[Standard_Integer(theType)]++;
4915         name += "Picked_";
4916         name += nameType[Standard_Integer(theType)];
4917         TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4918         name +="_";
4919         name+=indxstring;
4920       }
4921     }
4922     // si on avait une petite methode pour voir si la shape
4923     // est deja dans la Double map, ca eviterait de creer....
4924     DBRep::Set(name.ToCString(),PickSh);
4925
4926     Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4927     GetMapOfAIS().Bind(newsh, name);
4928     TheAISContext()->Display(newsh);
4929     di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4930   }
4931
4932   // Plusieurs objets a picker, vite vite vite....
4933   //
4934   else{
4935     Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4936     Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4937     if(ViewerTest::PickShapes(theType,arr)){
4938       for(Standard_Integer i=1;i<=NbToPick;i++){
4939         PickSh = arr->Value(i);
4940         if(!PickSh.IsNull()){
4941           if(autonaming){
4942             nbOfSub[Standard_Integer(theType)]++;
4943             name.Clear();
4944             name += "Picked_";
4945             name += nameType[Standard_Integer(theType)];
4946             TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4947             name +="_";
4948             name+=indxstring;
4949           }
4950         }
4951         else
4952           name = argv[1+i];
4953
4954         DBRep::Set(name.ToCString(),PickSh);
4955         Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4956         GetMapOfAIS().Bind(newsh, name);
4957         di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4958         TheAISContext()->Display(newsh);
4959
4960       }
4961     }
4962   }
4963   return 0;
4964 }
4965
4966 //=======================================================================
4967 //function : VPickSelected
4968 //purpose  :
4969 //=======================================================================
4970 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4971 {
4972   static Standard_Integer aCount = 0;
4973   TCollection_AsciiString aName = "PickedShape_";
4974
4975   if (theArgNb > 1)
4976   {
4977     aName = theArgs[1];
4978   }
4979   else
4980   {
4981     aName = aName + aCount++ + "_";
4982   }
4983
4984   Standard_Integer anIdx = 0;
4985   for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4986   {
4987     TopoDS_Shape aShape;
4988     if (TheAISContext()->HasSelectedShape())
4989     {
4990       aShape = TheAISContext()->SelectedShape();
4991     }
4992     else
4993     {
4994       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4995       aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
4996     }
4997
4998     TCollection_AsciiString aCurrentName = aName;
4999     if (anIdx > 0)
5000     {
5001       aCurrentName += anIdx;
5002     }
5003
5004     DBRep::Set ((aCurrentName).ToCString(), aShape);
5005
5006     Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5007     GetMapOfAIS().Bind (aNewShape, aCurrentName);
5008     TheAISContext()->Display (aNewShape);
5009   }
5010
5011   return 0;
5012 }
5013
5014 //=======================================================================
5015 //function : list of known objects
5016 //purpose  :
5017 //=======================================================================
5018 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5019 {
5020   //                             1234567890         12345678901234567         123456789
5021   TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5022   TCollection_AsciiString BlankLine(64,'_');
5023   Standard_Integer i ;
5024
5025   di<<"/n"<<BlankLine.ToCString()<<"\n";
5026
5027   for( i =0;i<=2;i++)
5028     Colum[i].Center(20,' ');
5029   for(i=0;i<=2;i++)
5030     di<<"|"<<Colum[i].ToCString();
5031   di<<"|\n";
5032
5033   di<<BlankLine.ToCString()<<"\n";
5034
5035   //  TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5036   const char ** names = GetTypeNames();
5037
5038   TCollection_AsciiString curstring;
5039   TCollection_AsciiString curcolum[3];
5040
5041
5042   // les objets de type Datum..
5043   curcolum[1]+="Datum";
5044   for(i =0;i<=6;i++){
5045     curcolum[0].Clear();
5046     curcolum[0] += names[i];
5047
5048     curcolum[2].Clear();
5049     curcolum[2]+=TCollection_AsciiString(i+1);
5050
5051     for(Standard_Integer j =0;j<=2;j++){
5052       curcolum[j].Center(20,' ');
5053       di<<"|"<<curcolum[j].ToCString();
5054     }
5055     di<<"|\n";
5056   }
5057   di<<BlankLine.ToCString()<<"\n";
5058
5059   // les objets de type shape
5060   curcolum[1].Clear();
5061   curcolum[1]+="Shape";
5062   curcolum[1].Center(20,' ');
5063
5064   for(i=0;i<=2;i++){
5065     curcolum[0].Clear();
5066     curcolum[0] += names[7+i];
5067     curcolum[2].Clear();
5068     curcolum[2]+=TCollection_AsciiString(i);
5069
5070     for(Standard_Integer j =0;j<=2;j++){
5071       curcolum[j].Center(20,' ');
5072       di<<"|"<<curcolum[j].ToCString();
5073     }
5074     di<<"|\n";
5075   }
5076   di<<BlankLine.ToCString()<<"\n";
5077   // les IO de type objet...
5078   curcolum[1].Clear();
5079   curcolum[1]+="Object";
5080   curcolum[1].Center(20,' ');
5081   for(i=0;i<=1;i++){
5082     curcolum[0].Clear();
5083     curcolum[0] += names[10+i];
5084     curcolum[2].Clear();
5085     curcolum[2]+=TCollection_AsciiString(i);
5086
5087     for(Standard_Integer j =0;j<=2;j++){
5088       curcolum[j].Center(20,' ');
5089       di<<"|"<<curcolum[j].ToCString();
5090     }
5091     di<<"|\n";
5092   }
5093   di<<BlankLine.ToCString()<<"\n";
5094   // les contraintes et dimensions.
5095   // pour l'instant on separe juste contraintes et dimensions...
5096   // plus tard, on detaillera toutes les sortes...
5097   curcolum[1].Clear();
5098   curcolum[1]+="Relation";
5099   curcolum[1].Center(20,' ');
5100   for(i=0;i<=1;i++){
5101     curcolum[0].Clear();
5102     curcolum[0] += names[12+i];
5103     curcolum[2].Clear();
5104     curcolum[2]+=TCollection_AsciiString(i);
5105
5106     for(Standard_Integer j =0;j<=2;j++){
5107       curcolum[j].Center(20,' ');
5108       di<<"|"<<curcolum[j].ToCString();
5109     }
5110     di<<"|\n";
5111   }
5112   di<<BlankLine.ToCString()<<"\n";
5113
5114
5115   return 0;
5116 }
5117
5118
5119 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5120 {
5121   if(argc!=2) return 1;
5122
5123   AIS_KindOfInteractive TheType;
5124   Standard_Integer TheSign(-1);
5125   GetTypeAndSignfromString(argv[1],TheType,TheSign);
5126
5127
5128   AIS_ListOfInteractive LIO;
5129
5130   // en attendant l'amelioration ais pour les dimensions...
5131   //
5132   Standard_Integer dimension_status(-1);
5133   if(TheType==AIS_KOI_Relation){
5134     dimension_status = TheSign ==1 ? 1 : 0;
5135     TheSign=-1;
5136   }
5137
5138   TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5139   Handle(AIS_InteractiveObject) curio;
5140   for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5141     curio  = it.Value();
5142
5143     if(dimension_status == -1)
5144       TheAISContext()->Erase(curio,Standard_False);
5145     else {
5146       AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5147       if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5148           (dimension_status==1 && KOD != AIS_KOD_NONE))
5149         TheAISContext()->Erase(curio,Standard_False);
5150     }
5151   }
5152   TheAISContext()->UpdateCurrentViewer();
5153   return 0;
5154 }
5155 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5156 {
5157   if(argc!=2) return 1;
5158
5159   AIS_KindOfInteractive TheType;
5160   Standard_Integer TheSign(-1);
5161   GetTypeAndSignfromString(argv[1],TheType,TheSign);
5162
5163   // en attendant l'amelioration ais pour les dimensions...
5164   //
5165   Standard_Integer dimension_status(-1);
5166   if(TheType==AIS_KOI_Relation){
5167     dimension_status = TheSign ==1 ? 1 : 0;
5168     TheSign=-1;
5169   }
5170
5171   AIS_ListOfInteractive LIO;
5172   TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5173   Handle(AIS_InteractiveObject) curio;
5174   for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5175     curio  = it.Value();
5176     if(dimension_status == -1)
5177       TheAISContext()->Display(curio,Standard_False);
5178     else {
5179       AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5180       if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5181           (dimension_status==1 && KOD != AIS_KOD_NONE))
5182         TheAISContext()->Display(curio,Standard_False);
5183     }
5184
5185   }
5186
5187   TheAISContext()->UpdateCurrentViewer();
5188   return 0;
5189 }
5190
5191 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5192 {
5193   ifstream s(a[1]);
5194   BRep_Builder builder;
5195   TopoDS_Shape shape;
5196   BRepTools::Read(shape, s, builder);
5197   DBRep::Set(a[1], shape);
5198   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5199   Handle(AIS_Shape) ais = new AIS_Shape(shape);
5200   Ctx->Display(ais);
5201   return 0;
5202 }
5203
5204 //===============================================================================================
5205 //function : VBsdf
5206 //purpose  :
5207 //===============================================================================================
5208 static int VBsdf (Draw_Interpretor& theDi,
5209                   Standard_Integer  theArgsNb,
5210                   const char**      theArgVec)
5211 {
5212   Handle(V3d_View)   aView   = ViewerTest::CurrentView();
5213   Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5214   if (aView.IsNull()
5215    || aViewer.IsNull())
5216   {
5217     std::cerr << "No active viewer!\n";
5218     return 1;
5219   }
5220
5221   ViewerTest_CmdParser aCmd;
5222
5223   aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5224   aCmd.AddOption ("print|echo|p", "Print BSDF");
5225
5226   aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5227   aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5228   aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5229   aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5230   aCmd.AddOption ("le", "Self-emitted radiance");
5231
5232   aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5233
5234   aCmd.AddOption ("roughness|r",    "Roughness of material (Blinn's exponent)");
5235   aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5236   aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5237
5238   aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5239
5240   aCmd.Parse (theArgsNb, theArgVec);
5241
5242   if (aCmd.HasOption ("help"))
5243   {
5244     theDi.PrintHelp (theArgVec[0]);
5245     return 0;
5246   }
5247
5248   TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5249
5250   // find object
5251   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5252   if (!aMap.IsBound2 (aName) )
5253   {
5254     std::cerr << "Use 'vdisplay' before\n";
5255     return 1;
5256   }
5257
5258   Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5259   Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5260   Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5261
5262   if (aCmd.HasOption ("print"))
5263   {
5264     Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5265
5266     std::cout << "\n"
5267       << "Kd:               " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5268       << "Kr:               " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5269       << "Kt:               " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5270       << "Ks:               " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5271       << "Le:               " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5272       << "Fresnel:          ";
5273
5274     if (aFresnel.x() >= 0.f)
5275     {
5276       std::cout
5277         << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5278     }
5279     else if (aFresnel.x() >= -1.5f)
5280     {
5281       std::cout
5282         << "|Constant| " << aFresnel.z() << "\n";
5283     }
5284     else if (aFresnel.x() >= -2.5f)
5285     {
5286       std::cout
5287         << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5288     }
5289     else
5290     {
5291       std::cout
5292         << "|Dielectric| " << aFresnel.y() << "\n";
5293     }
5294
5295
5296     std::cout 
5297       << "Roughness:        " << aBSDF.Roughness           << "\n"
5298       << "Absorption coeff: " << aBSDF.AbsorptionCoeff     << "\n"
5299       << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5300                               << aBSDF.AbsorptionColor.g() << ", "
5301                               << aBSDF.AbsorptionColor.b() << "\n";
5302
5303     return 0;
5304   }
5305
5306   if (aCmd.HasOption ("roughness", 1, Standard_True))
5307   {
5308     aCmd.Arg ("roughness", 0);
5309     aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5310   }
5311
5312   if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5313   {
5314     aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5315   }
5316
5317   if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5318   {
5319     aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5320   }
5321
5322   if (aCmd.HasOption ("kd", 3))
5323   {
5324     aBSDF.Kd = aCmd.ArgVec3f ("kd");
5325   }
5326   else if (aCmd.HasOption ("kd", 1, Standard_True))
5327   {
5328     aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5329   }
5330
5331   if (aCmd.HasOption ("kr", 3))
5332   {
5333     aBSDF.Kr = aCmd.ArgVec3f ("kr");
5334   }
5335   else if (aCmd.HasOption ("kr", 1, Standard_True))
5336   {
5337     aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5338   }
5339
5340   if (aCmd.HasOption ("kt", 3))
5341   {
5342     aBSDF.Kt = aCmd.ArgVec3f ("kt");
5343   }
5344   else if (aCmd.HasOption ("kt", 1, Standard_True))
5345   {
5346     aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5347   }
5348
5349   if (aCmd.HasOption ("ks", 3))
5350   {
5351     aBSDF.Ks = aCmd.ArgVec3f ("ks");
5352   }
5353   else if (aCmd.HasOption ("ks", 1, Standard_True))
5354   {
5355     aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5356   }
5357
5358   if (aCmd.HasOption ("le", 3))
5359   {
5360     aBSDF.Le = aCmd.ArgVec3f ("le");
5361   }
5362   else if (aCmd.HasOption ("le", 1, Standard_True))
5363   {
5364     aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5365   }
5366
5367   const std::string aFresnelErrorMessage =
5368     "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5369
5370   if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5371   {
5372     std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5373     std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5374
5375     if (aFresnelType == "schlick")
5376     {
5377       aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5378         Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5379                         static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5380                         static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5381     }
5382     else
5383     {
5384       std::cout << aFresnelErrorMessage;
5385     }
5386   }
5387   else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5388   {
5389     std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5390     std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5391
5392     if (aFresnelType == "conductor")
5393     {
5394       aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5395         static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5396         static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5397     }
5398     else
5399     {
5400       std::cout << aFresnelErrorMessage;
5401     }
5402   }
5403   else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5404   {
5405     std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5406     std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5407
5408     if (aFresnelType == "dielectric")
5409     {
5410       aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5411         static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5412     }
5413     else if (aFresnelType == "constant")
5414     {
5415       aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5416         static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5417     }
5418     else
5419     {
5420       std::cout << aFresnelErrorMessage;
5421     }
5422   }
5423
5424   if (aCmd.HasOption ("normalize"))
5425   {
5426     aBSDF.Normalize();
5427   }
5428
5429   aMaterial.SetBSDF (aBSDF);
5430   anIObj->SetMaterial (aMaterial);
5431
5432   aView->Redraw();
5433
5434   return 0;
5435 }
5436
5437 //==============================================================================
5438 //function : VLoadSelection
5439 //purpose  : Adds given objects to map of AIS and loads selection primitives for them
5440 //==============================================================================
5441 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5442                                         Standard_Integer theArgNb,
5443                                         const char** theArgVec)
5444 {
5445   if (theArgNb < 2)
5446   {
5447     std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5448     return 1;
5449   }
5450
5451   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5452   if (aCtx.IsNull())
5453   {
5454     ViewerTest::ViewerInit();
5455     aCtx = ViewerTest::GetAISContext();
5456   }
5457
5458   // Parse input arguments
5459   TColStd_SequenceOfAsciiString aNamesOfIO;
5460   Standard_Boolean isLocal = Standard_False;
5461   for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5462   {
5463     const TCollection_AsciiString aName     = theArgVec[anArgIter];
5464     TCollection_AsciiString       aNameCase = aName;
5465     aNameCase.LowerCase();
5466     if (aNameCase == "-local")
5467     {
5468       isLocal = Standard_True;
5469     }
5470     else
5471     {
5472       aNamesOfIO.Append (aName);
5473     }
5474   }
5475
5476   if (aNamesOfIO.IsEmpty())
5477   {
5478     std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5479     return 1;
5480   }
5481
5482   // Prepare context
5483   if (isLocal && !aCtx->HasOpenedContext())
5484   {
5485     aCtx->OpenLocalContext (Standard_False);
5486   }
5487   else if (!isLocal && aCtx->HasOpenedContext())
5488   {
5489     aCtx->CloseAllContexts (Standard_False);
5490   }
5491
5492   // Load selection of interactive objects
5493   for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5494   {
5495     const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5496
5497     Handle(AIS_InteractiveObject) aShape;
5498     if (GetMapOfAIS().IsBound2 (aName))
5499       aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5500     else
5501       aShape = GetAISShapeFromName (aName.ToCString());
5502
5503     if (!aShape.IsNull())
5504     {
5505       if (!GetMapOfAIS().IsBound2 (aName))
5506       {
5507         GetMapOfAIS().Bind (aShape, aName);
5508       }
5509
5510       aCtx->Load (aShape, -1, Standard_False);
5511       aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
5512     }
5513   }
5514
5515   return 0;
5516 }
5517
5518 //==============================================================================
5519 //function : ViewerTest::Commands
5520 //purpose  : Add all the viewer command in the Draw_Interpretor
5521 //==============================================================================
5522
5523 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5524 {
5525   ViewerTest::ViewerCommands(theCommands);
5526   ViewerTest::RelationCommands(theCommands);
5527   ViewerTest::ObjectCommands(theCommands);
5528   ViewerTest::FilletCommands(theCommands);
5529   ViewerTest::OpenGlCommands(theCommands);
5530
5531   const char *group = "AIS_Display";
5532
5533   // display
5534   theCommands.Add("visos",
5535       "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5536       "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5537       __FILE__, visos, group);
5538
5539   theCommands.Add("vdisplay",
5540               "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5541       "\n\t\t:          [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5542       "\n\t\t:                            [-trsfPersPos X Y [Z]] [-3d]"
5543       "\n\t\t:          [-2d|-trihedron [{top|bottom|left|right|topLeft"
5544       "\n\t\t:                           |topRight|bottomLeft|bottomRight}"
5545       "\n\t\t:                                         [offsetX offsetY]]]"
5546       "\n\t\t:          [-dispMode mode] [-highMode mode]"
5547       "\n\t\t:          [-layer index] [-top|-topmost|-overlay|-underlay]"
5548       "\n\t\t:          [-redisplay]"
5549       "\n\t\t:          name1 [name2] ... [name n]"
5550       "\n\t\t: Displays named objects."
5551       "\n\t\t: Option -local enables displaying of objects in local"
5552       "\n\t\t: selection context. Local selection context will be opened"
5553       "\n\t\t: if there is not any."
5554       "\n\t\t:  -noupdate    Suppresses viewer redraw call."
5555       "\n\t\t:  -mutable     Enables optimizations for mutable objects."
5556       "\n\t\t:  -neutral     Draws objects in main viewer."
5557       "\n\t\t:  -layer       Sets z-layer for objects."
5558       "\n\t\t:               Alternatively -overlay|-underlay|-top|-topmost"
5559       "\n\t\t:               options can be used for the default z-layers."
5560       "\n\t\t:  -top         Draws object on top of main presentations"
5561       "\n\t\t:               but below topmost."
5562       "\n\t\t:  -topmost     Draws in overlay for 3D presentations."
5563       "\n\t\t:               with independent Depth."
5564       "\n\t\t:  -overlay     Draws objects in overlay for 2D presentations."
5565       "\n\t\t:               (On-Screen-Display)"
5566       "\n\t\t:  -underlay    Draws objects in underlay for 2D presentations."
5567       "\n\t\t:               (On-Screen-Display)"
5568       "\n\t\t:  -selectable|-noselect Controls selection of objects."
5569       "\n\t\t:  -trsfPers    Sets a transform persistence flags."
5570       "\n\t\t:  -trsfPersPos Sets an anchor point for transform persistence."
5571       "\n\t\t:  -2d          Displays object in screen coordinates."
5572       "\n\t\t:               (DY looks up)"
5573       "\n\t\t:  -dispmode    Sets display mode for objects."
5574       "\n\t\t:  -highmode    Sets hilight mode for objects."
5575       "\n\t\t:  -redisplay   Recomputes presentation of objects.",
5576       __FILE__, VDisplay2, group);
5577
5578   theCommands.Add ("vupdate",
5579       "vupdate name1 [name2] ... [name n]"
5580       "\n\t\t: Updates named objects in interactive context",
5581       __FILE__, VUpdate, group);
5582
5583   theCommands.Add("verase",
5584       "verase [-noupdate|-update] [-local] [name1] ...  [name n]"
5585       "\n\t\t: Erases selected or named objects."
5586       "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5587       "\n\t\t: Option -local enables erasing of selected or named objects without"
5588       "\n\t\t: closing local selection context.",
5589       __FILE__, VErase, group);
5590
5591   theCommands.Add("vremove",
5592       "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ...  [name n]"
5593       "or vremove [-context] -all to remove all objects"
5594       "\n\t\t: Removes selected or named objects."
5595       "\n\t\t  If -context is in arguments, the objects are not deleted"
5596       "\n\t\t  from the map of objects and names."
5597       "\n\t\t: Option -local enables removing of selected or named objects without"
5598       "\n\t\t: closing local selection context. Empty local selection context will be"
5599       "\n\t\t: closed."
5600       "\n\t\t: Option -noupdate suppresses viewer redraw call."
5601       "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5602       __FILE__, VRemove, group);
5603
5604   theCommands.Add("vdonly",
5605                   "vdonly [-noupdate|-update] [name1] ...  [name n]"
5606       "\n\t\t: Displays only selected or named objects",
5607                   __FILE__,VDonly2,group);
5608
5609   theCommands.Add("vdisplayall",
5610       "vidsplayall [-local]"
5611       "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5612       "\n\t\t: Option -local enables displaying of the objects in local"
5613       "\n\t\t: selection context.",
5614       __FILE__, VDisplayAll, group);
5615
5616   theCommands.Add("veraseall",
5617       "veraseall [-local]"
5618       "\n\t\t: Erases all objects displayed in the viewer."
5619       "\n\t\t: Option -local enables erasing of the objects in local"
5620       "\n\t\t: selection context.",
5621       __FILE__, VErase, group);
5622
5623   theCommands.Add("verasetype",
5624       "verasetype <Type>"
5625       "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5626       __FILE__, VEraseType, group);
5627   theCommands.Add("vbounding",
5628               "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5629       "\n\t\t:           [-print] [-hide]"
5630       "\n\t\t: Temporarily display bounding box of specified Interactive"
5631       "\n\t\t: Objects, or print it to console if -print is specified."
5632       "\n\t\t: Already displayed box might be hidden by -hide option.",
5633                   __FILE__,VBounding,group);
5634
5635   theCommands.Add("vdisplaytype",
5636                   "vdisplaytype        : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5637                   __FILE__,VDisplayType,group);
5638
5639   theCommands.Add("vsetdispmode",
5640                   "vsetdispmode [name] mode(1,2,..)"
5641       "\n\t\t: Sets display mode for all, selected or named objects.",
5642                   __FILE__,VDispMode,group);
5643
5644   theCommands.Add("vunsetdispmode",
5645                   "vunsetdispmode [name]"
5646       "\n\t\t: Unsets custom display mode for selected or named objects.",
5647                   __FILE__,VDispMode,group);
5648
5649   theCommands.Add("vdir",
5650                   "Lists all objects displayed in 3D viewer",
5651                   __FILE__,VDir,group);
5652
5653 #ifdef HAVE_FREEIMAGE
5654   #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5655 #else
5656   #define DUMP_FORMATS "{ppm}"
5657 #endif
5658   theCommands.Add("vdump",
5659               "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5660       "\n\t\t:       [-buffer rgb|rgba|depth=rgb]"
5661       "\n\t\t:       [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5662       "\n\t\t:       [-tileSize Size=0]"
5663       "\n\t\t: Dumps content of the active view into image file",
5664                   __FILE__,VDump,group);
5665
5666   theCommands.Add("vsub",      "vsub 0/1 (off/on) [obj]        : Subintensity(on/off) of selected objects",
5667                   __FILE__,VSubInt,group);
5668
5669   theCommands.Add("vaspects",
5670               "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5671       "\n\t\t:          [-setVisibility 0|1]"
5672       "\n\t\t:          [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5673       "\n\t\t:          [-setMaterial MatName] [-unsetMaterial]"
5674       "\n\t\t:          [-setTransparency Transp] [-unsetTransparency]"
5675       "\n\t\t:          [-setWidth LineWidth] [-unsetWidth]"
5676       "\n\t\t:          [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
5677       "\n\t\t:          [-freeBoundary {off/on | 0/1}]"
5678       "\n\t\t:          [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5679       "\n\t\t:          [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5680       "\n\t\t:          [-subshapes subname1 [subname2 [...]]]"
5681       "\n\t\t:          [-isoontriangulation 0|1]"
5682       "\n\t\t:          [-setMaxParamValue {value}]"
5683       "\n\t\t:          [-setSensitivity {selection_mode} {value}]"
5684       "\n\t\t: Manage presentation properties of all, selected or named objects."
5685       "\n\t\t: When -subshapes is specified than following properties will be"
5686       "\n\t\t: assigned to specified sub-shapes."
5687       "\n\t\t: When -defaults is specified than presentation properties will be"
5688       "\n\t\t: assigned to all objects that have not their own specified properties"
5689       "\n\t\t: and to all objects to be displayed in the future."
5690       "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5691                   __FILE__,VAspects,group);
5692
5693   theCommands.Add("vsetcolor",
5694       "vsetcolor [-noupdate|-update] [name] ColorName"
5695       "\n\t\t: Sets color for all, selected or named objects."
5696       "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5697                   __FILE__,VAspects,group);
5698
5699   theCommands.Add("vunsetcolor",
5700                   "vunsetcolor [-noupdate|-update] [name]"
5701       "\n\t\t: Resets color for all, selected or named objects."
5702       "\n\t\t: Alias for vaspects -unsetcolor [name].",
5703                   __FILE__,VAspects,group);
5704
5705   theCommands.Add("vsettransparency",
5706                   "vsettransparency [-noupdate|-update] [name] Coefficient"
5707       "\n\t\t: Sets transparency for all, selected or named objects."
5708       "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5709       "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5710                   __FILE__,VAspects,group);
5711
5712   theCommands.Add("vunsettransparency",
5713                   "vunsettransparency [-noupdate|-update] [name]"
5714       "\n\t\t: Resets transparency for all, selected or named objects."
5715       "\n\t\t: Alias for vaspects -unsettransp [name].",
5716                   __FILE__,VAspects,group);
5717
5718   theCommands.Add("vsetmaterial",
5719                   "vsetmaterial [-noupdate|-update] [name] MaterialName"
5720       "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5721                   __FILE__,VAspects,group);
5722
5723   theCommands.Add("vunsetmaterial",
5724                   "vunsetmaterial [-noupdate|-update] [name]"
5725       "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5726                   __FILE__,VAspects,group);
5727
5728   theCommands.Add("vsetwidth",
5729                   "vsetwidth [-noupdate|-update] [name] width(0->10)"
5730       "\n\t\t: Alias for vaspects -setwidth [name] width.",
5731                   __FILE__,VAspects,group);
5732
5733   theCommands.Add("vunsetwidth",
5734                   "vunsetwidth [-noupdate|-update] [name]"
5735       "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5736                   __FILE__,VAspects,group);
5737
5738   theCommands.Add("vsetinteriorstyle",
5739                   "vsetinteriorstyle [-noupdate|-update] [name] style"
5740       "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5741                   __FILE__,VSetInteriorStyle,group);
5742
5743   theCommands.Add("vsensdis",
5744       "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5745       "\n\t\t: Standard entity types are those defined in Select3D package:"
5746       "\n\t\t: - sensitive box"
5747       "\n\t\t: - sensitive face"
5748       "\n\t\t: - sensitive curve"
5749       "\n\t\t: - sensitive segment"
5750       "\n\t\t: - sensitive circle"
5751       "\n\t\t: - sensitive point"
5752       "\n\t\t: - sensitive triangulation"
5753       "\n\t\t: - sensitive triangle"
5754       "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5755       __FILE__,VDispSensi,group);
5756
5757   theCommands.Add("vsensera",
5758       "vsensera : erase active entities",
5759       __FILE__,VClearSensi,group);
5760
5761   theCommands.Add("vperf",
5762       "vperf: vperf  ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
5763       "\n\t\t: Tests the animation of an object along a predefined trajectory.",
5764       __FILE__,VPerf,group);
5765
5766   theCommands.Add("vanimation",
5767                   "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5768                   __FILE__,VAnimation,group);
5769
5770   theCommands.Add("vsetshading",
5771       "vsetshading  : vsetshading name Quality(default=0.0008) "
5772       "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
5773       __FILE__,VShading,group);
5774
5775   theCommands.Add("vunsetshading",
5776       "vunsetshading :vunsetshading name "
5777       "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
5778       __FILE__,VShading,group);
5779
5780   theCommands.Add ("vtexture",
5781                    "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5782                    "                         [-scale u v]  [-scale off]\n"
5783                    "                         [-origin u v] [-origin off]\n"
5784                    "                         [-repeat u v] [-repeat off]\n"
5785                    "                         [-modulate {on | off}]"
5786                    "                         [-default]'\n"
5787                    " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5788                    " specifying one of the predefined textures.\n"
5789                    " The options are: \n"
5790                    "  -scale u v : enable texture scaling and set scale factors\n"
5791                    "  -scale off : disable texture scaling\n"
5792                    "  -origin u v : enable texture origin positioning and set the origin\n"
5793                    "  -origin off : disable texture origin positioning\n"
5794                    "  -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5795                    "  -repeat off : disable texture repeat\n"
5796                    "  -modulate {on | off} : enable or disable texture modulation\n"
5797                    "  -default : sets texture mapping default parameters\n"
5798                    "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5799                    "or 'vtexture NameOfShape ?' to list available textures\n",
5800                     __FILE__, VTexture, group);
5801
5802   theCommands.Add("vtexscale",
5803                   "'vtexscale  NameOfShape ScaleU ScaleV' \n \
5804                    or 'vtexscale NameOfShape ScaleUV' \n \
5805                    or 'vtexscale NameOfShape' to disable scaling\n ",
5806                   __FILE__,VTexture,group);
5807
5808   theCommands.Add("vtexorigin",
5809                   "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5810                    or 'vtexorigin NameOfShape UVOrigin' \n \
5811                    or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5812                   __FILE__,VTexture,group);
5813
5814   theCommands.Add("vtexrepeat",
5815                   "'vtexrepeat  NameOfShape URepeat VRepeat' \n \
5816                    or 'vtexrepeat NameOfShape UVRepeat \n \
5817                    or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5818                   VTexture,group);
5819
5820   theCommands.Add("vtexdefault",
5821                   "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5822                   VTexture,group);
5823
5824   theCommands.Add("vsetam",
5825       "vsetam [shapename] mode"
5826       "\n\t\t: Activates selection mode for all selected or named shapes."
5827       "\n\t\t: Mod can be:"
5828       "\n\t\t:   0 - for shape itself" 
5829       "\n\t\t:   1 - vertices"
5830       "\n\t\t:   2 - edges"
5831       "\n\t\t:   3 - wires"
5832       "\n\t\t:   4 - faces"
5833       "\n\t\t:   5 - shells"
5834       "\n\t\t:   6 - solids"
5835       "\n\t\t:   7 - compounds"
5836       __FILE__,VActivatedMode,group);
5837
5838   theCommands.Add("vunsetam",
5839       "vunsetam : Deactivates all selection modes for all shapes.",
5840       __FILE__,VActivatedMode,group);
5841
5842   theCommands.Add("vstate",
5843       "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5844       "\n\t\t: Reports show/hidden state for selected or named objects"
5845       "\n\t\t:   -entities - print low-level information about detected entities"
5846       "\n\t\t:   -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5847                   __FILE__,VState,group);
5848
5849   theCommands.Add("vpickshapes",
5850                   "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5851                   __FILE__,VPickShape,group);
5852
5853   theCommands.Add("vtypes",
5854                   "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5855                   VIOTypes,group);
5856
5857   theCommands.Add("vr",
5858       "vr filename"
5859       "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
5860                   __FILE__,vr, group);
5861
5862   theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5863     __FILE__, VPickSelected, group);
5864
5865   theCommands.Add ("vloadselection",
5866     "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5867     "\n\t\t: primitives for the shapes with names given without displaying them."
5868     "\n\t\t:   -local - open local context before selection computation",
5869     __FILE__, VLoadSelection, group);
5870
5871   theCommands.Add("vbsdf", "vbsdf [name] [options]"
5872     "\nAdjusts parameters of material BSDF:"
5873     "\n    -help : Shows this message"
5874     "\n    -print : Print BSDF"
5875     "\n    -kd : Weight of the Lambertian BRDF"
5876     "\n    -kr : Weight of the reflection BRDF"
5877     "\n    -kt : Weight of the transmission BTDF"
5878     "\n    -ks : Weight of the glossy Blinn BRDF"
5879     "\n    -le : Self-emitted radiance"
5880     "\n    -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5881     "\n               Schlick x y z, Dielectric x, Conductor x y"
5882     "\n    -roughness : Roughness of material (Blinn's exponent)"
5883     "\n    -absorpcoeff : Absorption coefficient (only for transparent material)"
5884     "\n    -absorpcolor : Absorption color (only for transparent material)"
5885     "\n    -normalize : Normalize BSDF coefficients",
5886     __FILE__, VBsdf, group);
5887
5888 }
5889
5890 //=====================================================================
5891 //========================= for testing Draft and Rib =================
5892 //=====================================================================
5893 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5894 #include <DBRep.hxx>
5895 #include <TopoDS_Face.hxx>
5896 #include <gp_Pln.hxx>
5897 #include <AIS_KindOfSurface.hxx>
5898 #include <BRepOffsetAPI_DraftAngle.hxx>
5899 #include <Precision.hxx>
5900 #include <BRepAlgo.hxx>
5901 #include <OSD_Environment.hxx>
5902 #include <DrawTrSurf.hxx>
5903 //#include <DbgTools.hxx>
5904 //#include <FeatAlgo_MakeLinearForm.hxx>
5905
5906
5907
5908
5909 //=======================================================================
5910 //function : IsValid
5911 //purpose  :
5912 //=======================================================================
5913 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5914                                 const TopoDS_Shape& theResult,
5915                                 const Standard_Boolean closedSolid,
5916                                 const Standard_Boolean GeomCtrl)
5917 {
5918   OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5919   TCollection_AsciiString checkValid = check.Value();
5920   Standard_Boolean ToCheck = Standard_True;
5921   if (!checkValid.IsEmpty()) {
5922 #ifdef OCCT_DEBUG
5923     cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5924 #endif
5925     if ( checkValid=="true" || checkValid=="TRUE" ) {
5926       ToCheck= Standard_False;
5927     }
5928   } else {
5929 #ifdef OCCT_DEBUG
5930     cout <<"DONT_SWITCH_IS_VALID non positionne\n";
5931 #endif
5932   }
5933   Standard_Boolean IsValid = Standard_True;
5934   if (ToCheck)
5935     IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5936   return IsValid;
5937
5938 }
5939
5940 //===============================================================================
5941 // TDraft : test draft, uses AIS Viewer
5942 // Solid Face Plane Angle  Reverse
5943 //===============================================================================
5944 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5945 {
5946   if (argc < 5) return 1;
5947 // argv[1] - TopoDS_Shape Solid
5948 // argv[2] - TopoDS_Shape Face
5949 // argv[3] - TopoDS_Shape Plane
5950 // argv[4] - Standard_Real Angle
5951 // argv[5] - Standard_Integer Reverse
5952
5953 //  Sprintf(prefix, argv[1]);
5954   Standard_Real anAngle = 0;
5955   Standard_Boolean Rev = Standard_False;
5956   Standard_Integer rev = 0;
5957   TopoDS_Shape Solid  = GetShapeFromName(argv[1]);
5958   TopoDS_Shape face   = GetShapeFromName(argv[2]);
5959   TopoDS_Face Face    = TopoDS::Face(face);
5960   TopoDS_Shape Plane  = GetShapeFromName(argv[3]);
5961   if (Plane.IsNull ()) {
5962     di << "TEST : Plane is NULL\n";
5963     return 1;
5964   }
5965   anAngle = Draw::Atof(argv[4]);
5966   anAngle = 2*M_PI * anAngle / 360.0;
5967   gp_Pln aPln;
5968   Handle( Geom_Surface )aSurf;
5969   AIS_KindOfSurface aSurfType;
5970   Standard_Real Offset;
5971   gp_Dir aDir;
5972   if(argc > 4) { // == 5
5973     rev = Draw::Atoi(argv[5]);
5974     Rev = (rev)? Standard_True : Standard_False;
5975   }
5976
5977   TopoDS_Face face2 = TopoDS::Face(Plane);
5978   if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5979     {
5980       di << "TEST : Can't find plane\n";
5981       return 1;
5982     }
5983
5984   aDir = aPln.Axis().Direction();
5985   if (!aPln.Direct())
5986     aDir.Reverse();
5987   if (Plane.Orientation() == TopAbs_REVERSED)
5988     aDir.Reverse();
5989   di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5990
5991   BRepOffsetAPI_DraftAngle Draft (Solid);
5992
5993   if(Abs(anAngle)< Precision::Angular()) {
5994     di << "TEST : NULL angle\n";
5995     return 1;}
5996
5997   if(Rev) anAngle = - anAngle;
5998   Draft.Add (Face, aDir, anAngle, aPln);
5999   Draft.Build ();
6000   if (!Draft.IsDone())  {
6001     di << "TEST : Draft Not DONE \n";
6002     return 1;
6003   }
6004   TopTools_ListOfShape Larg;
6005   Larg.Append(Solid);
6006   if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6007     di << "TEST : DesignAlgo returns Not valid\n";
6008     return 1;
6009   }
6010
6011   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6012   Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6013
6014   if ( !ais.IsNull() ) {
6015     ais->SetColor(DEFAULT_COLOR);
6016     ais->SetMaterial(DEFAULT_MATERIAL);
6017     // Display the AIS_Shape without redraw
6018     Ctx->Display(ais, Standard_False);
6019
6020     const char *Name = "draft1";
6021     Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6022     if (IsBound) {
6023       Handle(AIS_InteractiveObject) an_object =
6024         Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6025       if (!an_object.IsNull()) {
6026         Ctx->Remove(an_object,
6027                     Standard_True) ;
6028         GetMapOfAIS().UnBind2(Name) ;
6029       }
6030     }
6031     GetMapOfAIS().Bind(ais, Name);
6032 //  DBRep::Set("draft", ais->Shape());
6033   }
6034   Ctx->Display(ais, Standard_True);
6035   return 0;
6036 }
6037
6038 //==============================================================================
6039 //function : splitParameter
6040 //purpose  : Split parameter string to parameter name and parameter value
6041 //==============================================================================
6042 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6043                                              TCollection_AsciiString&       theName,
6044                                              TCollection_AsciiString&       theValue)
6045 {
6046   Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6047
6048   if (aParamNameEnd == 0)
6049   {
6050     return Standard_False;
6051   }
6052
6053   TCollection_AsciiString aString (theString);
6054   if (aParamNameEnd != 0)
6055   {
6056     theValue = aString.Split (aParamNameEnd);
6057     aString.Split (aString.Length() - 1);
6058     theName = aString;
6059   }
6060
6061   return Standard_True;
6062 }
6063
6064 //============================================================================
6065 //  MyCommands
6066 //============================================================================
6067 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6068 {
6069
6070   DrawTrSurf::BasicCommands(theCommands);
6071   const char* group = "Check Features Operations commands";
6072
6073   theCommands.Add("Draft","Draft    Solid Face Plane Angle Reverse",
6074                   __FILE__,
6075                   &TDraft,group); //Draft_Modification
6076 }
6077
6078 //==============================================================================
6079 // ViewerTest::Factory
6080 //==============================================================================
6081 void ViewerTest::Factory(Draw_Interpretor& theDI)
6082 {
6083   // definition of Viewer Command
6084   ViewerTest::Commands(theDI);
6085
6086 #ifdef OCCT_DEBUG
6087       theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6088 #endif
6089 }
6090
6091 // Declare entry point PLUGINFACTORY
6092 DPLUGIN(ViewerTest)