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