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