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