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