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