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