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