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