0030611: Coding Rules - eliminate GCC compiler warnings -Wcatch-value
[occt.git] / src / ViewerTest / ViewerTest_ObjectCommands.cxx
1 // Created on: 1998-11-12
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <ViewerTest.hxx>
18
19 #include <AIS_PlaneTrihedron.hxx>
20
21 #include <Quantity_NameOfColor.hxx>
22 #include <Draw_Interpretor.hxx>
23 #include <Draw.hxx>
24 #include <Draw_Appli.hxx>
25 #include <DBRep.hxx>
26 #include <DBRep_DrawableShape.hxx>
27
28 #include <Font_BRepFont.hxx>
29 #include <Font_BRepTextBuilder.hxx>
30 #include <Font_FontMgr.hxx>
31
32 #include <NCollection_List.hxx>
33
34 #include <OSD_Chronometer.hxx>
35 #include <TCollection_AsciiString.hxx>
36 #include <V3d_Viewer.hxx>
37 #include <V3d_View.hxx>
38 #include <V3d.hxx>
39
40 #include <AIS_Shape.hxx>
41 #include <AIS_DisplayMode.hxx>
42 #include <AIS_PointCloud.hxx>
43 #include <TColStd_MapOfInteger.hxx>
44 #include <AIS_MapOfInteractive.hxx>
45 #include <ViewerTest_AutoUpdater.hxx>
46 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
47 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
48 #include <ViewerTest_EventManager.hxx>
49
50 #include <TopoDS_Solid.hxx>
51 #include <BRepTools.hxx>
52 #include <BRep_Builder.hxx>
53 #include <TopAbs_ShapeEnum.hxx>
54
55 #include <TopoDS.hxx>
56 #include <BRep_Tool.hxx>
57 #include <TopExp_Explorer.hxx>
58
59 #include <BRepAdaptor_Curve.hxx>
60 #include <BRepAdaptor_Surface.hxx>
61
62 #include <TopAbs.hxx>
63 #include <TopExp.hxx>
64 #include <TopoDS_Vertex.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Face.hxx>
67
68 #include <Draw_Window.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
70 #include <AIS_ListOfInteractive.hxx>
71 #include <AIS_ColoredShape.hxx>
72 #include <AIS_DisplayMode.hxx>
73 #include <AIS_Shape.hxx>
74
75 #include <AIS_InteractiveContext.hxx>
76 #include <Geom_Plane.hxx>
77 #include <gp_Pln.hxx>
78 #include <TCollection_ExtendedString.hxx>
79 #include <TCollection_HAsciiString.hxx>
80 #include <GC_MakePlane.hxx>
81 #include <gp_Circ.hxx>
82 #include <AIS_Axis.hxx>
83 #include <Geom_Axis2Placement.hxx>
84 #include <Geom_Axis1Placement.hxx>
85 #include <AIS_Trihedron.hxx>
86 #include <AIS_Axis.hxx>
87 #include <gp_Trsf.hxx>
88 #include <gp_Quaternion.hxx>
89 #include <TopLoc_Location.hxx>
90
91 #include <HLRAlgo_Projector.hxx>
92 #include <HLRBRep_Algo.hxx>
93 #include <HLRBRep_PolyAlgo.hxx>
94 #include <HLRBRep_PolyHLRToShape.hxx>
95 #include <HLRBRep_HLRToShape.hxx>
96 #include <Aspect_Window.hxx>
97
98 #include <Graphic3d_ArrayOfPoints.hxx>
99 #include <Graphic3d_ArrayOfSegments.hxx>
100 #include <Graphic3d_ArrayOfPolylines.hxx>
101 #include <Graphic3d_ArrayOfTriangles.hxx>
102 #include <Graphic3d_ArrayOfTriangleFans.hxx>
103 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
104 #include <Graphic3d_ArrayOfQuadrangles.hxx>
105 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
106 #include <Graphic3d_ArrayOfPolygons.hxx>
107 #include <Graphic3d_AttribBuffer.hxx>
108 #include <Graphic3d_AspectMarker3d.hxx>
109 #include <Graphic3d_Group.hxx>
110 #include <Standard_Real.hxx>
111
112 #include <AIS_Circle.hxx>
113 #include <BRepBuilderAPI_MakeEdge.hxx>
114 #include <BRepBuilderAPI_MakeFace.hxx>
115 #include <BRepBuilderAPI_MakeWire.hxx>
116 #include <Geom_Circle.hxx>
117 #include <GC_MakeCircle.hxx>
118 #include <Select3D_SensitiveCircle.hxx>
119 #include <SelectMgr_EntityOwner.hxx>
120 #include <SelectMgr_Selection.hxx>
121 #include <StdFail_NotDone.hxx>
122 #include <StdPrs_ShadedShape.hxx>
123 #include <TopoDS_Wire.hxx>
124
125 #include <AIS_MultipleConnectedInteractive.hxx>
126 #include <AIS_ConnectedInteractive.hxx>
127 #include <AIS_TextLabel.hxx>
128 #include <TopLoc_Location.hxx>
129 #include <TColStd_ListOfInteger.hxx>
130 #include <TColStd_ListIteratorOfListOfInteger.hxx>
131
132 #include <Select3D_SensitiveSegment.hxx>
133 #include <Select3D_SensitivePrimitiveArray.hxx>
134 #include <Select3D_SensitiveTriangle.hxx>
135 #include <Select3D_SensitiveCurve.hxx>
136 #include <Select3D_SensitivePoint.hxx>
137 #include <BRepAdaptor_Curve.hxx>
138 #include <StdPrs_Curve.hxx>
139
140 #include <BRepExtrema_ExtPC.hxx>
141 #include <BRepExtrema_ExtPF.hxx>
142
143 #include <Prs3d_Arrow.hxx>
144 #include <Prs3d_ArrowAspect.hxx>
145 #include <Prs3d_DatumAttribute.hxx>
146 #include <Prs3d_DatumAspect.hxx>
147 #include <Prs3d_Drawer.hxx>
148 #include <Prs3d_VertexDrawMode.hxx>
149 #include <Prs3d_LineAspect.hxx>
150 #include <Prs3d_PointAspect.hxx>
151 #include <Prs3d_Presentation.hxx>
152 #include <Prs3d_TextAspect.hxx>
153
154 #include <Image_AlienPixMap.hxx>
155 #include <TColStd_HArray1OfAsciiString.hxx>
156 #include <TColStd_HSequenceOfAsciiString.hxx>
157
158 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
159 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
160                                            const Handle(AIS_InteractiveObject)& theAISObj,
161                                            Standard_Boolean theReplaceIfExists = Standard_True);
162 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
163 extern Handle(AIS_InteractiveContext)& TheAISContext();
164
165 namespace
166 {
167   static bool convertToColor (const Handle(TColStd_HSequenceOfAsciiString)& theColorValues,
168                               Quantity_Color& theColor)
169   {
170     const char* anArgs[3] =
171     {
172       theColorValues->Size() >= 1 ? theColorValues->Value (1).ToCString() : "",
173       theColorValues->Size() >= 2 ? theColorValues->Value (2).ToCString() : "",
174       theColorValues->Size() >= 3 ? theColorValues->Value (3).ToCString() : ""
175     };
176     return ViewerTest::ParseColor (theColorValues->Size(), anArgs, theColor) != 0;
177   }
178
179   static bool convertToDatumPart (const TCollection_AsciiString& theValue,
180                                   Prs3d_DatumParts& theDatumPart)
181   {
182     TCollection_AsciiString aValue = theValue;
183     aValue.LowerCase();
184     if      (aValue == "origin")  theDatumPart = Prs3d_DP_Origin;
185     else if (aValue == "xaxis")   theDatumPart = Prs3d_DP_XAxis;
186     else if (aValue == "yaxis")   theDatumPart = Prs3d_DP_YAxis;
187     else if (aValue == "zaxis")   theDatumPart = Prs3d_DP_ZAxis;
188     else if (aValue == "xarrow")  theDatumPart = Prs3d_DP_XArrow;
189     else if (aValue == "yarrow")  theDatumPart = Prs3d_DP_YArrow;
190     else if (aValue == "zarrow")  theDatumPart = Prs3d_DP_ZArrow;
191     else if (aValue == "xoyaxis") theDatumPart = Prs3d_DP_XOYAxis;
192     else if (aValue == "yozaxis") theDatumPart = Prs3d_DP_YOZAxis;
193     else if (aValue == "xozaxis") theDatumPart = Prs3d_DP_XOZAxis;
194     else if (aValue == "whole")   theDatumPart = Prs3d_DP_None;
195     else
196     {
197       return false;
198     }
199     return true;
200   }
201
202   static void convertToDatumParts (const TCollection_AsciiString& theValue,
203                                    NCollection_List<Prs3d_DatumParts>& theParts)
204   {
205     TCollection_AsciiString aValue = theValue;
206     const Standard_Integer aSplitPos = theValue.Search ("|");
207     Prs3d_DatumParts aPart = Prs3d_DP_None;
208     if (aSplitPos > 0)
209     {
210       convertToDatumParts (theValue.SubString (aSplitPos + 1, theValue.Length()), theParts);
211       if (aSplitPos == 1) // first symbol
212       {
213         return;
214       }
215       aValue = theValue.SubString (1, aSplitPos - 1);
216     }
217     if (convertToDatumPart (aValue, aPart))
218     {
219       theParts.Append (aPart);
220     }
221   }
222
223   static bool convertToDatumAttribute (const TCollection_AsciiString& theValue,
224                                        Prs3d_DatumAttribute& theAttribute)
225   {
226     TCollection_AsciiString aValue = theValue;
227     aValue.LowerCase();
228     if      (aValue == "xaxislength")       theAttribute = Prs3d_DA_XAxisLength;
229     else if (aValue == "yaxislength")       theAttribute = Prs3d_DA_YAxisLength;
230     else if (aValue == "zaxislength")       theAttribute = Prs3d_DA_ZAxisLength;
231     else if (aValue == "tuberadiuspercent") theAttribute = Prs3d_DP_ShadingTubeRadiusPercent;
232     else if (aValue == "coneradiuspercent") theAttribute = Prs3d_DP_ShadingConeRadiusPercent;
233     else if (aValue == "conelengthpercent") theAttribute = Prs3d_DP_ShadingConeLengthPercent;
234     else if (aValue == "originradiuspercent") theAttribute = Prs3d_DP_ShadingOriginRadiusPercent;
235     else if (aValue == "shadingnumberoffacettes") theAttribute = Prs3d_DP_ShadingNumberOfFacettes;
236     else
237       return false;
238     return true;
239   }
240
241   static void convertToDatumAttributes (const TCollection_AsciiString& theValue,
242                                         NCollection_List<Prs3d_DatumAttribute>& theAttributes)
243   {
244     TCollection_AsciiString aValue = theValue;
245     const Standard_Integer aSplitPos = theValue.Search ("|");
246     Prs3d_DatumAttribute anAttribute = Prs3d_DA_XAxisLength;
247     if (aSplitPos > 0)
248     {
249       convertToDatumAttributes (theValue.SubString (aSplitPos + 1, theValue.Length()), theAttributes);
250       if (aSplitPos == 1) // first symbol
251       {
252         return;
253       }
254       aValue = theValue.SubString (1, aSplitPos - 1);
255     }
256     if (convertToDatumAttribute (aValue, anAttribute))
257     {
258       theAttributes.Append (anAttribute);
259     }
260   }
261
262   static bool convertToDatumAxes (const TCollection_AsciiString& theValue,
263                                   Prs3d_DatumAxes& theDatumAxes)
264   {
265     TCollection_AsciiString aValue = theValue;
266     aValue.LowerCase();
267     if      (aValue == "x")   theDatumAxes = Prs3d_DA_XAxis;
268     else if (aValue == "y")   theDatumAxes = Prs3d_DA_YAxis;
269     else if (aValue == "z")   theDatumAxes = Prs3d_DA_ZAxis;
270     else if (aValue == "xy")  theDatumAxes = Prs3d_DA_XYAxis;
271     else if (aValue == "zy")  theDatumAxes = Prs3d_DA_YZAxis;
272     else if (aValue == "xz")  theDatumAxes = Prs3d_DA_XZAxis;
273     else if (aValue == "xyz") theDatumAxes = Prs3d_DA_XYZAxis;
274     else
275     {
276       return false;
277     }
278     return true;
279   }
280
281   static Standard_Boolean setTrihedronParams (Standard_Integer  theArgsNb,
282                                               const char** theArgVec,
283                                               Handle(AIS_Trihedron) theTrihedron)
284   {
285     NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
286     TCollection_AsciiString aParseKey;
287     for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
288     {
289       TCollection_AsciiString anArg (theArgVec [anArgIt]);
290       if (anArg.Value (1) == '-'
291       && !anArg.IsRealValue())
292       {
293         aParseKey = anArg;
294         aParseKey.Remove (1);
295         aParseKey.LowerCase();
296         std::string aKey = aParseKey.ToCString();
297         aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString());
298         continue;
299       }
300
301       if (aParseKey.IsEmpty())
302       {
303         continue;
304       }
305
306       aMapOfArgs (aParseKey)->Append (anArg);
307     }
308
309     // Check parameters
310     if ((aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis"))
311     || (!aMapOfArgs.IsBound ("xaxis") &&  aMapOfArgs.IsBound ("zaxis")))
312     {
313       std::cout << "Syntax error: -xaxis and -zaxis parameters are to set together.\n";
314       return Standard_False;
315     }
316
317     Handle(TColStd_HSequenceOfAsciiString) aValues;
318     Handle(Geom_Axis2Placement) aComponent = theTrihedron->Component();
319     if (aMapOfArgs.Find ("origin", aValues))
320     {
321       aComponent->SetLocation (gp_Pnt (aValues->Value (1).RealValue(),
322                                        aValues->Value (2).RealValue(),
323                                        aValues->Value (3).RealValue()));
324     }
325     Handle(TColStd_HSequenceOfAsciiString) aXValues, aZValues;
326     if (aMapOfArgs.Find ("xaxis", aXValues) && aMapOfArgs.Find ("zaxis", aZValues))
327     {
328       gp_Dir aXDir (aXValues->Value (1).RealValue(),
329                     aXValues->Value (2).RealValue(),
330                     aXValues->Value (3).RealValue());
331
332       gp_Dir aZDir (aZValues->Value (1).RealValue(),
333                     aZValues->Value (2).RealValue(),
334                     aZValues->Value (3).RealValue());
335
336       if (!aZDir.IsNormal (aXDir, M_PI / 180.0))
337       {
338         std::cout << "Syntax error - parameters 'xaxis' and 'zaxis' are not applied as VectorX is not normal to VectorZ\n";
339         return Standard_False;
340       }
341
342       aComponent->SetAx2 (gp_Ax2 (aComponent->Location(), aZDir, aXDir));
343     }
344
345     if (aMapOfArgs.Find ("dispmode", aValues))
346     {
347       TCollection_AsciiString aValue (aValues->Value (1));
348       bool isWireframe = true;
349       if (aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
350         isWireframe = false;
351       theTrihedron->SetDatumDisplayMode (isWireframe ? Prs3d_DM_WireFrame
352                                                      : Prs3d_DM_Shaded);
353     }
354
355     if (aMapOfArgs.Find ("hidelabels", aValues))
356     {
357       Standard_Boolean toHideLabels = Standard_True;
358       if (aValues->Size() == 1)
359       {
360         ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideLabels);
361       }
362       else if (aValues->Size() != 0)
363       {
364         std::cout << "Syntax error: -hidelabels expects parameter 'on' or 'off' after.\n";
365         return Standard_False;
366       }
367
368       if (!theTrihedron->Attributes()->HasOwnDatumAspect())
369       {
370         theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
371       }
372       theTrihedron->Attributes()->DatumAspect()->SetDrawLabels (!toHideLabels);
373     }
374
375     if (aMapOfArgs.Find ("hidearrows", aValues))
376     {
377       Standard_Boolean toHideArrows = Standard_True;
378       if (aValues->Size() == 1)
379       {
380         ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideArrows);
381       }
382       else if (aValues->Size() != 0)
383       {
384         std::cout << "Syntax error: -hidearrows expects parameter 'on' or 'off' after.\n";
385         return Standard_False;
386       }
387
388       if (!theTrihedron->Attributes()->HasOwnDatumAspect())
389       {
390         theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
391       }
392       theTrihedron->Attributes()->DatumAspect()->SetDrawArrows (!toHideArrows);
393     }
394
395     if (aMapOfArgs.Find ("color", aValues))
396     {
397       NCollection_List<Prs3d_DatumParts> aParts;
398       if (aValues->Size() < 2)
399       {
400         std::cout << "Syntax error: -color wrong parameters.\n";
401         return Standard_False;
402       }
403
404       convertToDatumParts (aValues->Value(1), aParts);
405       aValues->Remove (1); // datum part is processed
406       Quantity_Color aColor;
407       if (!convertToColor (aValues, aColor))
408       {
409         std::cout << "Syntax error: -color wrong parameters.\n";
410         return Standard_False;
411       }
412
413       for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (aParts); anIterator.More(); anIterator.Next())
414       {
415         Prs3d_DatumParts aDatumPart = anIterator.Value();
416         if (aDatumPart == Prs3d_DP_None)
417         {
418           theTrihedron->SetColor (aColor);
419         }
420         else
421         {
422           theTrihedron->SetDatumPartColor (aDatumPart, aColor);
423         }
424       }
425     }
426
427     if (aMapOfArgs.Find ("textcolor", aValues))
428     {
429       Quantity_Color aColor;
430       if (!convertToColor (aValues, aColor))
431       {
432         std::cout << "Syntax error: -textcolor wrong parameters.\n";
433         return Standard_False;
434       }
435       theTrihedron->SetTextColor (aColor);
436     }
437
438     if (aMapOfArgs.Find ("arrowcolor", aValues))
439     {
440       Quantity_Color aColor;
441       if (!convertToColor (aValues, aColor))
442       {
443         std::cout << "Syntax error: -arrowcolor wrong parameters.\n";
444         return Standard_False;
445       }
446       theTrihedron->SetArrowColor (aColor);
447     }
448
449     if (aMapOfArgs.Find ("attribute", aValues))
450     {
451       NCollection_List<Prs3d_DatumAttribute> anAttributes;
452       if (aValues->Size() != 2)
453       {
454         std::cout << "Syntax error: -attribute wrong parameters.\n";
455         return Standard_False;
456       }
457
458       convertToDatumAttributes (aValues->Value (1), anAttributes);
459       if (!theTrihedron->Attributes()->HasOwnDatumAspect())
460         theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
461       for (NCollection_List<Prs3d_DatumAttribute>::Iterator anIterator (anAttributes); anIterator.More(); anIterator.Next())
462       {
463         theTrihedron->Attributes()->DatumAspect()->SetAttribute (anIterator.Value(), aValues->Value (2).RealValue());
464       }
465     }
466
467     if (aMapOfArgs.Find ("priority", aValues))
468     {
469       Prs3d_DatumParts aDatumPart;
470       if (aValues->Size() < 2
471       || !convertToDatumPart (aValues->Value (1), aDatumPart))
472       {
473         std::cout << "Syntax error: -priority wrong parameters.\n";
474         return Standard_False;
475       }
476       theTrihedron->SetSelectionPriority (aDatumPart, aValues->Value (2).IntegerValue());
477     }
478
479     if (aMapOfArgs.Find ("labels", aValues)
480      || aMapOfArgs.Find ("label", aValues))
481     {
482       Prs3d_DatumParts aDatumPart = Prs3d_DP_None;
483       if (aValues->Size() >= 2
484        && convertToDatumPart(aValues->Value(1), aDatumPart)
485        && aDatumPart >= Prs3d_DP_XAxis
486        && aDatumPart <= Prs3d_DP_ZAxis) // labels are set to axes only
487       {
488         theTrihedron->SetLabel (aDatumPart, aValues->Value (2));
489       }
490       else
491       {
492         std::cout << "Syntax error: -labels wrong parameters.\n";
493         return Standard_False;
494       }
495     }
496
497     if (aMapOfArgs.Find ("drawaxes", aValues))
498     {
499       Prs3d_DatumAxes aDatumAxes = Prs3d_DA_XAxis;
500       if (aValues->Size() < 1
501       || !convertToDatumAxes (aValues->Value (1), aDatumAxes))
502       {
503         std::cout << "Syntax error: -drawaxes wrong parameters.\n";
504         return Standard_False;
505       }
506       if (!theTrihedron->Attributes()->HasOwnDatumAspect())
507         theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
508       theTrihedron->Attributes()->DatumAspect()->SetDrawDatumAxes (aDatumAxes);
509     }
510     return Standard_True;
511   }
512
513   //! Auxiliary function to parse font aspect style argument
514   static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
515                                           Font_FontAspect&               theAspect)
516   {
517     if (theArg == "regular"
518      || *theArg.ToCString() == 'r')
519     {
520       theAspect = Font_FA_Regular;
521       return Standard_True;
522     }
523     else if (theArg == "bolditalic"
524           || theArg == "bold-italic"
525           || theArg == "italic-bold"
526           || theArg == "italicbold")
527     {
528       theAspect = Font_FA_BoldItalic;
529       return Standard_True;
530     }
531     else if (theArg == "bold"
532           || *theArg.ToCString() == 'b')
533     {
534       theAspect = Font_FA_Bold;
535       return Standard_True;
536     }
537     else if (theArg == "italic"
538           || *theArg.ToCString() == 'i')
539     {
540       theAspect = Font_FA_Italic;
541       return Standard_True;
542     }
543     return Standard_False;
544   }
545 }
546
547 //==============================================================================
548 //function : Vtrihedron 2d
549 //purpose  : Create a plane with a 2D  trihedron from a faceselection
550 //Draw arg : vtri2d  name
551 //==============================================================================
552 static int VTrihedron2D (Draw_Interpretor& /*theDI*/,
553                          Standard_Integer  theArgsNum,
554                          const char**      theArgVec)
555 {
556   if (theArgsNum != 2)
557   {
558     std::cerr << theArgVec[0]<< " error.\n";
559     return 1;
560   }
561
562   TopTools_ListOfShape aShapes;
563   ViewerTest::GetSelectedShapes (aShapes);
564
565   if (aShapes.Extent() != 1)
566   {
567     std::cerr << "Error: wrong number of selected shapes.\n";
568     return 1;
569   }
570
571   const TopoDS_Shape& aShape = aShapes.First();
572
573   TopoDS_Face     aFace = TopoDS::Face (aShape);
574   TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE);
575   TopoDS_Edge     anEdge0 = TopoDS::Edge (aFaceExp.Current());
576
577   gp_Pnt A,B,C;
578   if (aFaceExp.More())
579   {
580     aFaceExp.Next();
581     TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() );
582     BRepAdaptor_Curve aCurve0 (anEdge0);
583     BRepAdaptor_Curve aCurve1 (anEdge1);
584     A = aCurve1.Value (0.1);
585     B = aCurve1.Value (0.9);
586     C = aCurve0.Value (0.5);
587   }
588   else
589   {
590     BRepAdaptor_Curve aCurve0 (anEdge0);
591     A = aCurve0.Value (0.1);
592     B = aCurve0.Value (0.9);
593     C = aCurve0.Value (0.5);
594   }
595
596   GC_MakePlane aMkPlane (A,B,C);
597
598   Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value());
599   TCollection_AsciiString aName (theArgVec[1]);
600
601   VDisplayAISObject (aName, anAISPlaneTri);
602
603   return 0;
604 }
605
606 //=======================================================================
607 //function : VTrihedron
608 //purpose  :
609 //=======================================================================
610 static int VTrihedron (Draw_Interpretor& ,
611                        Standard_Integer theArgsNb,
612                        const char** theArgVec)
613 {
614   if (theArgsNb < 2)
615   {
616     std::cout << "Syntax error: the wrong number of input parameters.\n";
617     return 1;
618   }
619
620   TCollection_AsciiString aName (theArgVec[1]);
621   gp_Pln aWorkingPlane;
622   Standard_Boolean toUpdate = Standard_True;
623
624   NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
625   NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
626
627   Handle(AIS_Trihedron) aTrihedron;
628   Handle(AIS_InteractiveObject) anObject;
629   if (GetMapOfAIS().Find2 (aName, anObject))
630   {
631     aTrihedron = Handle(AIS_Trihedron)::DownCast (anObject);
632     if (aTrihedron.IsNull())
633     {
634       std::cout << "Syntax error: no trihedron with this name.\n";
635       return 1;
636     }
637   }
638   else
639   {
640     Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (gp_Pnt (0.0, 0.0, 0.0),
641                                                                       gp::DZ(), gp::DX());
642     aTrihedron = new AIS_Trihedron (aPlacement);
643   }
644
645   if (!setTrihedronParams (theArgsNb, theArgVec, aTrihedron))
646   {
647     return 1;
648   }
649
650   // Redisplay a dimension after parameter changing.
651   if (ViewerTest::GetAISContext()->IsDisplayed (aTrihedron))
652   {
653     ViewerTest::GetAISContext()->Redisplay (aTrihedron, toUpdate);
654   }
655   else
656   {
657     VDisplayAISObject (theArgVec[1], aTrihedron);
658   }
659
660   return 0;
661 }
662
663 //==============================================================================
664 //function : VSize
665 //author   : ege
666 //purpose  : Change the size of a named or selected trihedron
667 //           if no name : it affects the trihedrons witch are selected otherwise nothing is donne
668 //           if no value, the value is set at 100 by default
669 //Draw arg : vsize [name] [size]
670 //==============================================================================
671
672 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
673
674 {
675   // Declaration de booleens
676   Standard_Boolean             ThereIsName;
677   Standard_Boolean             ThereIsCurrent;
678   Standard_Real                value;
679   Standard_Boolean             hascol;
680
681   Quantity_Color col = Quantity_NOC_BLACK;
682
683   // Verification des arguments
684   if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;}
685
686   // Verification du nombre d'arguments
687   if (argc==1)      {ThereIsName=Standard_False;value=100;}
688   else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
689   else              {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
690
691   // On set le booleen ThereIsCurrent
692   if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
693   else {ThereIsCurrent=Standard_False;}
694
695
696
697   //===============================================================
698   // Il n'y a pas de nom  mais des objets selectionnes
699   //===============================================================
700   if (!ThereIsName && ThereIsCurrent)
701   {
702
703     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
704       it (GetMapOfAIS());
705
706     while ( it.More() ) {
707
708       Handle(AIS_InteractiveObject) aShape = it.Key1();
709
710       if (!aShape.IsNull() &&  TheAISContext()->IsSelected(aShape) )
711       {
712
713         // On verifie que l'AIS InteraciveObject selectionne est bien
714         // un AIS_Trihedron
715         if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
716
717           if (aShape->HasColor())
718           {
719             hascol = Standard_True;
720
721             // On recupere la couleur de aShape
722             aShape->Color (col);
723           }
724           else
725           {
726             hascol = Standard_False;
727           }
728
729           // On downcast aShape  de AIS_InteractiveObject a AIS_Trihedron
730           // pour lui appliquer la methode SetSize()
731           Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
732
733           // C'est bien un triedre,on chage sa valeur!
734           aTrihedron->SetSize(value);
735
736           // On donne la couleur au Trihedron
737           if(hascol)   aTrihedron->SetColor(col);
738           else         aTrihedron->UnsetColor();
739
740
741           // The trihedron hasn't be errased from the map
742           // so you just have to redisplay it
743           TheAISContext() ->Redisplay(aTrihedron,Standard_False);
744
745         }
746
747       }
748
749       it.Next();
750     }
751
752     TheAISContext() ->UpdateCurrentViewer();
753   }
754
755   //===============================================================
756   // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
757   //===============================================================
758
759
760
761   //===============================================================
762   // Il y a un nom de triedre passe en argument
763   //===============================================================
764   if (ThereIsName) {
765     TCollection_AsciiString name=argv[1];
766
767     // on verifie que ce nom correspond bien a une shape
768     Handle(AIS_InteractiveObject) aShape;
769     if (GetMapOfAIS().Find2(name, aShape))
770     {
771       // On verifie que l'AIS InteraciveObject est bien
772       // un AIS_Trihedron
773       if (!aShape.IsNull() &&
774         aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
775       {
776         if (aShape->HasColor())
777         {
778           hascol=Standard_True;
779
780           // On recupere la couleur de aShape
781           aShape->Color (col);
782         }
783         else
784         {
785           hascol = Standard_False;
786         }
787
788         // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
789         // pour lui appliquer la methode SetSize()
790         Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
791
792         // C'est bien un triedre,on chage sa valeur
793         aTrihedron->SetSize(value);
794
795         // On donne la couleur au Trihedron
796         if(hascol)   aTrihedron->SetColor(col);
797         else         aTrihedron->UnsetColor();
798
799         // The trihedron hasn't be errased from the map
800         // so you just have to redisplay it
801         TheAISContext() ->Redisplay(aTrihedron,Standard_False);
802
803         TheAISContext() ->UpdateCurrentViewer();
804       }
805     }
806   }
807   return 0;
808 }
809
810
811 //==============================================================================
812
813 //==============================================================================
814 //function : VPlaneTrihedron
815 //purpose  : Create a plane from a trihedron selection. If no arguments are set, the default
816 //Draw arg : vplanetri  name
817 //==============================================================================
818 #include <AIS_Plane.hxx>
819
820
821
822 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
823
824 {
825   // Verification des arguments
826   if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
827
828   if (TheAISContext()->NbSelected() != 1)
829   {
830     std::cerr << "Error: Wrong number of selected shapes.\n";
831     return 1;
832   }
833
834   TheAISContext()->InitSelected();
835   Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive();
836   Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest);
837   if (aPlane.IsNull())
838   {
839     std::cerr << "Error: Selected shape is not a plane.\n";
840     return 1;
841   }
842
843   VDisplayAISObject (argv[1], aPlane);
844
845   return 0;
846 }
847
848
849
850 //==============================================================================
851 // Fonction        First click      2de click
852 //
853 // vaxis           vertex           vertex
854 //                 edge             None
855 // vaxispara       edge             vertex
856 // vaxisortho      edge             Vertex
857 // vaxisinter      Face             Face
858 //==============================================================================
859
860 //==============================================================================
861 //function : VAxisBuilder
862 //purpose  :
863 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
864 //==============================================================================
865 #include <TopoDS_Edge.hxx>
866 #include <TopoDS_Vertex.hxx>
867 #include <TopExp.hxx>
868 #include <Geom_Line.hxx>
869
870 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
871 {
872   // Declarations
873   Standard_Boolean HasArg;
874   TCollection_AsciiString name;
875
876   // Verification
877   if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
878   if (argc==8) HasArg=Standard_True;
879   else HasArg=Standard_False;
880
881   name=argv[1];
882
883   TopTools_ListOfShape aShapes;
884   ViewerTest::GetSelectedShapes (aShapes);
885
886   // Cas ou il y a des arguments
887   // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
888   if (HasArg) {
889     Standard_Real coord[6];
890     for(Standard_Integer i=0;i<=5;i++){
891       coord[i]=Draw::Atof(argv[2+i]);
892     }
893     gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
894
895     gp_Vec myVect (p1,p2);
896     Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
897     Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
898     GetMapOfAIS().Bind (TheAxis,name);
899     TheAISContext()->Display(TheAxis, Standard_True);
900   }
901
902   // Pas d'arguments
903   else {
904     // fonction vaxis
905     // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
906     if ( !strcasecmp(argv[0], "vaxis")) {
907       if (aShapes.Extent() != 2 && aShapes.Extent() != 1)
908       {
909         std::cerr << "Error: Wrong number of selected shapes.\n";
910         return 1;
911       }
912
913       const TopoDS_Shape& aShapeA = aShapes.First();
914       if (aShapeA.ShapeType() == TopAbs_VERTEX)
915       {
916         if (aShapes.Extent() != 2)
917         {
918           std::cerr << "Error: Wron number of selected shapes.\n";
919           return 1;
920         }
921
922         const TopoDS_Shape& aShapeB = aShapes.Last();
923         if (aShapeB.ShapeType() != TopAbs_VERTEX)
924         {
925           std::cerr << "Syntax error: You should select two vertices or one edge.\n";
926           return 1;
927         }
928
929         // Construction de l'axe
930         gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
931         gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
932         gp_Vec V (A,B);
933         gp_Dir D (V);
934         Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
935         Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
936         GetMapOfAIS().Bind (TheAxis,name);
937         TheAISContext()->Display (TheAxis, Standard_True);
938       }
939       else
940       {
941         TopoDS_Edge    ed =TopoDS::Edge (aShapeA);
942         TopoDS_Vertex  Va,Vb;
943         TopExp::Vertices(ed,Va,Vb );
944         gp_Pnt A=BRep_Tool::Pnt(Va);
945         gp_Pnt B=BRep_Tool::Pnt(Vb);
946         gp_Vec  V (A,B);
947         gp_Dir   D (V);
948         Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
949         Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
950         GetMapOfAIS().Bind (TheAxis,name);
951         TheAISContext()->Display (TheAxis, Standard_True);
952       }
953
954     }
955
956     // Fonction axispara
957     // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
958     else if ( !strcasecmp(argv[0], "vaxispara"))
959     {
960       if (aShapes.Extent() != 2)
961       {
962         std::cerr << "Error: Wrong number of selected shapes.\n";
963         return 1;
964       }
965
966       const TopoDS_Shape& aShapeA = aShapes.First();
967       const TopoDS_Shape& aShapeB = aShapes.Last();
968       if (!(aShapeA.ShapeType() == TopAbs_EDGE
969          && aShapeB.ShapeType() == TopAbs_VERTEX))
970       {
971         std::cerr << "Syntax error: You should select face and then vertex.\n";
972         return 1;
973       }
974
975       TopoDS_Edge    ed=TopoDS::Edge (aShapeA);
976       gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
977       TopoDS_Vertex  Va,Vc;
978       TopExp::Vertices(ed,Va,Vc );
979       gp_Pnt A=BRep_Tool::Pnt(Va);
980       gp_Pnt C=BRep_Tool::Pnt(Vc);
981       gp_Vec  V (A,C);
982       gp_Dir   D (V);
983       Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
984       Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
985       GetMapOfAIS().Bind (TheAxis,name);
986       TheAISContext()->Display (TheAxis, Standard_True);
987
988     }
989
990     // Fonction axisortho
991     else
992     {
993       if (aShapes.Extent() != 2)
994       {
995         std::cerr << "Error: Wrong number of selected shapes.\n";
996         return 1;
997       }
998
999       const TopoDS_Shape& aShapeA = aShapes.First();
1000       const TopoDS_Shape& aShapeB = aShapes.Last();
1001       if (!(aShapeA.ShapeType() == TopAbs_EDGE
1002          && aShapeB.ShapeType() == TopAbs_VERTEX))
1003       {
1004         std::cerr << "Syntax error: You should select face and then vertex.\n";
1005         return 1;
1006       }
1007
1008       // Construction de l'axe
1009       TopoDS_Edge    ed=TopoDS::Edge(aShapeA) ;
1010       gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) );
1011       TopoDS_Vertex  Va,Vc;
1012       TopExp::Vertices(ed,Va,Vc );
1013       gp_Pnt A=BRep_Tool::Pnt(Va);
1014       gp_Pnt C=BRep_Tool::Pnt(Vc);
1015       gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z()  ,C.X()-A.X() ,C.X()-A.X() );
1016       gp_Vec  V (A,E);
1017       gp_Dir   D (V);
1018       Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1019       Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1020       GetMapOfAIS().Bind (TheAxis,name);
1021       TheAISContext()->Display (TheAxis, Standard_True);
1022
1023     }
1024
1025   }
1026   return 0;
1027 }
1028
1029
1030 //==============================================================================
1031 // Fonction        First click      Result
1032 //
1033 // vpoint          vertex           AIS_Point=Vertex
1034 //                 edge             AIS_Point=Middle of the edge
1035 //==============================================================================
1036
1037 //==============================================================================
1038 //function : VPointBuilder
1039 //purpose  : Build an AIS_Point from coordinates or with a selected vertex or edge
1040 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
1041 //==============================================================================
1042 #include <TopoDS_Edge.hxx>
1043 #include <TopoDS_Vertex.hxx>
1044 #include <TopExp.hxx>
1045 #include <AIS_Point.hxx>
1046 #include <Geom_CartesianPoint.hxx>
1047
1048 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1049 {
1050   // Declarations
1051   Standard_Boolean HasArg;
1052   TCollection_AsciiString name;
1053
1054   // Verification
1055   if (argc<2 || argc>5 ) {di<<" Syntaxe error\n";return 1;}
1056   if (argc==5) HasArg=Standard_True;
1057   else HasArg=Standard_False;
1058
1059   name=argv[1];
1060
1061   // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
1062   if (HasArg) {
1063     Standard_Real thecoord[3];
1064     for(Standard_Integer i=0;i<=2;i++)
1065       thecoord[i]=Draw::Atof(argv[2+i]);
1066     Handle(Geom_CartesianPoint )  myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
1067     Handle(AIS_Point)  myAISPoint=new AIS_Point(myGeomPoint );
1068     GetMapOfAIS().Bind (myAISPoint,name);
1069     TheAISContext()->Display (myAISPoint, Standard_True);
1070   }
1071
1072   // Il n'a pas d'arguments
1073   else
1074   {
1075     TopTools_ListOfShape aShapes;
1076     ViewerTest::GetSelectedShapes (aShapes);
1077
1078     if (aShapes.Extent() != 1)
1079     {
1080       std::cerr << "Error: Wrong number of selected shapes.\n";
1081       std::cerr << "\tYou should select one edge or vertex.\n";
1082       return 1;
1083     }
1084
1085     const TopoDS_Shape& aShapeA = aShapes.First();
1086
1087     if (aShapeA.ShapeType()==TopAbs_VERTEX )
1088     {
1089       gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(aShapeA ) );
1090       Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
1091       Handle(AIS_Point)  myAISPoint = new AIS_Point  (myGeomPoint );
1092       GetMapOfAIS().Bind(myAISPoint,name);
1093       TheAISContext()->Display (myAISPoint, Standard_True);
1094     }
1095     else
1096     {
1097       TopoDS_Edge myEdge=TopoDS::Edge(aShapeA);
1098       TopoDS_Vertex myVertexA,myVertexB;
1099       TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
1100       gp_Pnt A=BRep_Tool::Pnt(myVertexA );
1101       gp_Pnt B=BRep_Tool::Pnt(myVertexB );
1102       // M est le milieu de [AB]
1103       Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2  , (A.Y()+B.Y())/2  , (A.Z()+B.Z())/2  );
1104       Handle(AIS_Point)  myAISPointM = new AIS_Point  (myGeomPointM );
1105       GetMapOfAIS().Bind(myAISPointM,name);
1106       TheAISContext()->Display (myAISPointM, Standard_True);
1107     }
1108
1109   }
1110   return 0;
1111
1112 }
1113
1114 //==============================================================================
1115 // Function        1st click   2de click  3de click
1116 // vplane          Vertex      Vertex     Vertex
1117 //                 Vertex      Edge
1118 //                 Edge        Vertex
1119 //                 Face
1120 // vplanepara      Face        Vertex
1121 //                 Vertex      Face
1122 // vplaneortho     Face        Edge
1123 //                 Edge        Face
1124 //==============================================================================
1125
1126 //==============================================================================
1127 //function : VPlaneBuilder
1128 //purpose  : Build an AIS_Plane from selected entities or Named AIS components
1129 //Draw arg : vplane PlaneName [AxisName]  [PointName] [TypeOfSensitivity]
1130 //                            [PointName] [PointName] [PointName] [TypeOfSensitivity]
1131 //                            [PlaneName] [PointName] [TypeOfSensitivity]
1132 //==============================================================================
1133
1134 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
1135                                        Standard_Integer argc,
1136                                        const char** argv)
1137 {
1138   // Declarations
1139   Standard_Boolean hasArg;
1140   TCollection_AsciiString aName;
1141
1142   // Verification
1143   if (argc<2 || argc>6 )
1144   {
1145     std::cout<<" Syntax error\n";
1146     return 1;
1147   }
1148   if (argc == 6 || argc==5 || argc==4)
1149     hasArg=Standard_True;
1150   else 
1151     hasArg=Standard_False;
1152
1153   aName=argv[1];
1154
1155   // There are some arguments
1156   if (hasArg)
1157   {
1158     Handle(AIS_InteractiveObject) aShapeA;
1159     if (!GetMapOfAIS().Find2 (argv[2], aShapeA))
1160     {
1161       std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
1162       return 1;
1163     }
1164
1165     // The first argument is an AIS_Point
1166     if (!aShapeA.IsNull() &&
1167         aShapeA->Type()==AIS_KOI_Datum &&
1168         aShapeA->Signature()==1)
1169     {
1170         // The second argument must also be an AIS_Point
1171         Handle(AIS_InteractiveObject) aShapeB;
1172         if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1173         {
1174           std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
1175           return 1;
1176         }
1177         // If B is not an AIS_Point
1178         if (aShapeB.IsNull() ||
1179           (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1180         {
1181           std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
1182           return 1;
1183         }
1184         // The third object is an AIS_Point
1185         Handle(AIS_InteractiveObject) aShapeC;
1186         if (!GetMapOfAIS().Find2(argv[4], aShapeC)) 
1187         {
1188           std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
1189           return 1; 
1190         }
1191         // If C is not an AIS_Point
1192         if (aShapeC.IsNull() ||
1193           (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
1194         {
1195           std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
1196           return 1;
1197         }
1198
1199         // Treatment of objects A, B, C
1200         // Downcast an AIS_IO to AIS_Point
1201         Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
1202         Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
1203         Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
1204
1205         Handle(Geom_CartesianPoint ) aCartPointA = 
1206           Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
1207
1208         Handle(Geom_CartesianPoint ) aCartPointB = 
1209           Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
1210
1211         Handle(Geom_CartesianPoint ) aCartPointC = 
1212           Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
1213
1214         // Verification that the three points are different
1215         if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
1216            Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1217            Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
1218         {
1219           // B=A
1220           std::cout<<"vplane error: same points\n";return 1;
1221         }
1222         if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1223            Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1224            Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1225         {
1226           // C=A
1227           std::cout<<"vplane error: same points\n";return 1;
1228         }
1229         if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1230            Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1231            Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1232         {
1233           // C=B
1234           std::cout<<"vplane error: same points\n";return 1;
1235         }
1236
1237         gp_Pnt A = aCartPointA->Pnt();
1238         gp_Pnt B = aCartPointB->Pnt();
1239         gp_Pnt C = aCartPointC->Pnt();
1240
1241         // Construction of AIS_Plane
1242         GC_MakePlane MkPlane (A,B,C);
1243         Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1244         Handle(AIS_Plane)  anAISPlane = new AIS_Plane(aGeomPlane );
1245         GetMapOfAIS().Bind (anAISPlane,aName );
1246         if (argc == 6)
1247         {
1248           Standard_Integer aType = Draw::Atoi (argv[5]);
1249           if (aType != 0 && aType != 1)
1250           {
1251             std::cout << "vplane error: wrong type of sensitivity!\n"
1252                       << "Should be one of the following values:\n"
1253                       << "0 - Interior\n"
1254                       << "1 - Boundary"
1255                       << std::endl;
1256             return 1;
1257           }
1258           else
1259           {
1260             anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1261           }
1262         }
1263         TheAISContext()->Display (anAISPlane, Standard_True);
1264       }
1265
1266       // The first argument is an AIS_Axis
1267       // Creation of a plane orthogonal to the axis through a point
1268     else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1269       // The second argument should be an AIS_Point
1270       Handle(AIS_InteractiveObject) aShapeB;
1271       if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1272       {
1273         std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1274         return 1;
1275       }
1276       // If B is not an AIS_Point
1277       if (aShapeB.IsNull() ||
1278         (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1279       {
1280         std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1281         return 1;
1282       }
1283
1284       // Treatment of objects A and B
1285       Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1286       Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1287
1288       Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1289       Handle(Geom_Point) aGeomPointB = anAISPointB->Component()  ;
1290
1291       gp_Ax1 anAxis = aGeomLineA->Position();
1292       Handle(Geom_CartesianPoint) aCartPointB = 
1293         Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1294
1295       gp_Dir D =anAxis.Direction();
1296       gp_Pnt B = aCartPointB->Pnt();
1297
1298       // Construction of AIS_Plane
1299       Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1300       Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1301       GetMapOfAIS().Bind (anAISPlane,aName );
1302       if (argc == 5)
1303       {
1304         Standard_Integer aType = Draw::Atoi (argv[4]);
1305         if (aType != 0 && aType != 1)
1306         {
1307           std::cout << "vplane error: wrong type of sensitivity!\n"
1308                     << "Should be one of the following values:\n"
1309                     << "0 - Interior\n"
1310                     << "1 - Boundary"
1311                     << std::endl;
1312           return 1;
1313         }
1314         else
1315         {
1316           anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1317         }
1318       }
1319       TheAISContext()->Display (anAISPlane, Standard_True);
1320
1321     }
1322     // The first argumnet is an AIS_Plane
1323     // Creation of a plane parallel to the plane passing through the point
1324     else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1325     {
1326       // The second argument should be an AIS_Point
1327       Handle(AIS_InteractiveObject) aShapeB;
1328       if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1329       {
1330         std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1331         return 1;
1332       }
1333       // B should be an AIS_Point
1334       if (aShapeB.IsNull() ||
1335          (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1336       {
1337         std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1338         return 1;
1339       }
1340
1341       // Treatment of objects A and B
1342       Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1343       Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1344
1345       Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1346       Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1347
1348       Handle(Geom_CartesianPoint) aCartPointB = 
1349         Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1350       gp_Pnt B= aCartPointB->Pnt();
1351
1352       // Construction of an AIS_Plane
1353       Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1354       GetMapOfAIS().Bind (anAISPlane, aName);
1355       if (argc == 5)
1356       {
1357         Standard_Integer aType = Draw::Atoi (argv[4]);
1358         if (aType != 0 && aType != 1)
1359         {
1360           std::cout << "vplane error: wrong type of sensitivity!\n"
1361                     << "Should be one of the following values:\n"
1362                     << "0 - Interior\n"
1363                     << "1 - Boundary"
1364                     << std::endl;
1365           return 1;
1366         }
1367         else
1368         {
1369           anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1370         }
1371       }
1372       TheAISContext()->Display (anAISPlane, Standard_True);
1373     }
1374     // Error
1375     else
1376     {
1377       std::cout<<"vplane: error 1st object is not an AIS\n";
1378       return 1;
1379     }
1380   }
1381   // There are no arguments
1382   else 
1383   {
1384     TopTools_ListOfShape aShapes;
1385     ViewerTest::GetSelectedShapes (aShapes);
1386
1387     // Function vplane
1388     // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1389     if (!strcasecmp(argv[0], "vplane"))
1390     {
1391       if (aShapes.Extent() < 1 || aShapes.Extent() > 3)
1392       {
1393         std::cerr << "Error: Wront number of selected shapes.\n";
1394         std::cerr << "\tYou should one of variant: face, edge and vertex or three vertices.\n";
1395         return 1;
1396       }
1397
1398       const TopoDS_Shape& aShapeA = aShapes.First();
1399       if (aShapeA.ShapeType() == TopAbs_VERTEX)
1400       {
1401         if (aShapes.Extent() == 2)
1402         {
1403           const TopoDS_Shape& aShapeB = aShapes.Last();
1404           if (aShapeB.ShapeType() != TopAbs_EDGE)
1405           {
1406             std::cerr << "Syntax error: Together with vertex should be edge.\n";
1407             return 1;
1408           }
1409
1410           // Verify that the vertex is not on the edge ShapeB
1411           TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1412           TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1413
1414           BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1415           if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1416           {
1417             // The vertex is on the edge
1418             std::cout<<" vplane: error point is on the edge\n";
1419             return 1;
1420           }
1421           else
1422           {
1423             gp_Pnt A = BRep_Tool::Pnt(aVertA);
1424             TopoDS_Vertex aVBa, aVBb;
1425             TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1426             gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1427             gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1428             GC_MakePlane MkPlane (A, aBa, aBb);
1429             Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1430             Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1431             GetMapOfAIS().Bind (anAISPlane, aName);
1432             TheAISContext()->Display (anAISPlane, Standard_True);
1433           }
1434         }
1435         else if (aShapes.Extent() == 3)
1436         {
1437           TopTools_ListOfShape::Iterator anIter (aShapes);
1438
1439           anIter.Next();
1440           const TopoDS_Shape& aShapeB = anIter.Value();
1441
1442           anIter.Next();
1443           const TopoDS_Shape& aShapeC = anIter.Value();
1444
1445           if (!(aShapeB.ShapeType() == TopAbs_VERTEX
1446              && aShapeC.ShapeType() == TopAbs_VERTEX))
1447           {
1448             std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1449             return 1;
1450           }
1451
1452           gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1453           gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1454           gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1455           GC_MakePlane MkPlane(A, B, C);
1456           Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1457           Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1458           GetMapOfAIS().Bind (anAISPlane, aName);
1459           TheAISContext()->Display (anAISPlane, Standard_True);
1460         }
1461         else
1462         {
1463           std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1464           return 1;
1465         }
1466       }
1467       else if (aShapeA.ShapeType() == TopAbs_EDGE)
1468       {
1469         if (aShapes.Extent() != 2)
1470         {
1471           std::cerr << "Error: wrong number of selected shapes.\n";
1472           return 1;
1473         }
1474
1475         const TopoDS_Shape& aShapeB = aShapes.Last();
1476         if (aShapeB.ShapeType() != TopAbs_VERTEX)
1477         {
1478           std::cerr << "Syntax error: Together with edge should be vertex.\n";
1479           return 1;
1480         }
1481
1482         // Check that the vertex aShapeB is not on the edge
1483         TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1484         TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1485
1486         BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1487         if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1488         {
1489           // The vertex is on the edge
1490           std::cout<<" vplane: error point is on the edge\n";
1491           return 1;
1492         }
1493
1494         gp_Pnt B = BRep_Tool::Pnt(aVertB);
1495         TopoDS_Vertex aVAa, aVAb;
1496         TopExp::Vertices(anEdgeA, aVAa, aVAb);
1497         gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1498         gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1499         GC_MakePlane MkPlane (B,Aa,Ab);
1500         Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1501         Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1502         GetMapOfAIS().Bind (anAISPlane ,aName);
1503         TheAISContext()->Display (anAISPlane, Standard_True);
1504       }
1505       else if (aShapeA.ShapeType() == TopAbs_FACE)
1506       {
1507         TopoDS_Face aFace = TopoDS::Face(aShapeA);
1508         BRepAdaptor_Surface aSurface (aFace, Standard_False);
1509         if (aSurface.GetType()==GeomAbs_Plane)
1510         {
1511           gp_Pln aPlane = aSurface.Plane();
1512           Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1513           Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1514           GetMapOfAIS().Bind (anAISPlane, aName);
1515           TheAISContext()->Display (anAISPlane, Standard_True);
1516         }
1517         else
1518         {
1519           std::cout<<" vplane: error\n";
1520           return 1;
1521         }
1522       }
1523       else
1524       {
1525         std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1526         return 1;
1527       }
1528     }
1529
1530     // Function vPlanePara
1531     // ===================
1532     // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1533     else if (!strcasecmp(argv[0], "vplanepara"))
1534     {
1535       if (aShapes.Extent() != 2)
1536       {
1537         std::cerr << "Error: Wrong number of selected shapes.\n";
1538         return 1;
1539       }
1540
1541       const TopoDS_Shape* aShapeA = &aShapes.First();
1542       const TopoDS_Shape* aShapeB = &aShapes.Last();
1543       if (aShapeA->ShapeType() != TopAbs_VERTEX)
1544       {
1545         std::swap (aShapeA, aShapeB);
1546       }
1547
1548       if (!(aShapeA->ShapeType() == TopAbs_VERTEX
1549          && aShapeB->ShapeType() == TopAbs_FACE))
1550       {
1551         std::cerr << "Syntax error: you should select face and vertex.\n";
1552         return 1;
1553       }
1554
1555       gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA));
1556
1557       TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1558       BRepAdaptor_Surface aSurface (aFace, Standard_False);
1559       if (aSurface.GetType() == GeomAbs_Plane)
1560       {
1561         gp_Pln aPlane = aSurface.Plane();
1562         // Construct a plane parallel to aGeomPlane through A
1563         aPlane.SetLocation(A);
1564         Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1565         Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1566         GetMapOfAIS().Bind (aAISPlane ,aName);
1567         TheAISContext()->Display (aAISPlane, Standard_True);
1568       }
1569       else
1570       {
1571         std::cerr << "Error: Builded surface is not a plane.\n";
1572         return 1;
1573       }
1574     }
1575
1576     // Function vplaneortho
1577     // ====================
1578     // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1579     else
1580     {
1581       if (aShapes.Extent() != 2)
1582       {
1583         std::cerr << "Error: wrong number of selected shapes.\n";
1584         return 1;
1585       }
1586
1587       const TopoDS_Shape* aShapeA = &aShapes.First();
1588       const TopoDS_Shape* aShapeB = &aShapes.Last();
1589
1590       if (aShapeA->ShapeType() != TopAbs_EDGE)
1591       {
1592         std::swap (aShapeA, aShapeB);
1593       }
1594
1595       if (!(aShapeA->ShapeType() == TopAbs_EDGE
1596          && aShapeB->ShapeType() == TopAbs_FACE))
1597       {
1598         std::cerr << "Error: you should select edge and face.\n";
1599         return 1;
1600       }
1601
1602       // Construction of plane
1603       TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA);
1604       TopoDS_Vertex aVAa, aVAb;
1605       TopExp::Vertices(anEdgeA, aVAa, aVAb);
1606       gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1607       gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1608       gp_Vec ab (Aa,Ab);
1609
1610       gp_Dir Dab (ab);
1611       // Creation of rotation axis
1612       gp_Ax1 aRotAxis (Aa,Dab);
1613
1614       TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1615       // The edge must be parallel to the face
1616       BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1617       BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1618       // Compare to heights
1619       if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1620           >Precision::Confusion())
1621       {
1622         // the edge is not parallel to the face
1623         std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1624         return 1;
1625       }
1626       // the edge is OK
1627       BRepAdaptor_Surface aSurface (aFace, Standard_False);
1628       if (aSurface.GetType()==GeomAbs_Plane)
1629       {
1630         gp_Pln aPlane = aSurface.Plane();
1631         // It rotates a half turn round the axis of rotation
1632         aPlane.Rotate(aRotAxis , M_PI/2);
1633
1634         Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1635         // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1636         gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1637         Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1638         GetMapOfAIS().Bind (anAISPlane, aName);
1639         TheAISContext()->Display (anAISPlane, Standard_True);
1640       }
1641       else
1642       {
1643         std::cout<<" vplaneortho: error\n";
1644         return 1;
1645       }
1646     }
1647   }
1648   return 0;
1649 }
1650
1651 //===============================================================================================
1652 //function : VChangePlane
1653 //purpose  :
1654 //===============================================================================================
1655 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1656 {
1657   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1658   if (aContextAIS.IsNull())
1659   {
1660     std::cout << theArgVec[0] << "AIS context is not available.\n";
1661     return 1;
1662   }
1663
1664   if (theArgsNb < 3 || theArgsNb > 11)
1665   {
1666     std::cerr << theArgVec[0] 
1667               << ": incorrect number of command arguments.\n"
1668               << "Type help for more information.\n";
1669     return 1;
1670   }
1671
1672   TCollection_AsciiString aName (theArgVec[1]);
1673
1674   Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1675     ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1676     : NULL;
1677
1678   if ( aPlane.IsNull() )
1679   {
1680     std::cout << theArgVec[0] 
1681               << ": there is no interactive plane with the given name."
1682               << "Type help for more information.\n";
1683     return 1;
1684   }
1685
1686   Standard_Real aCenterX = aPlane->Center().X();
1687   Standard_Real aCenterY = aPlane->Center().Y();
1688   Standard_Real aCenterZ = aPlane->Center().Z();
1689
1690   Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1691   Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1692   Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1693
1694   Standard_Real aSizeX = 0.0;
1695   Standard_Real aSizeY = 0.0;
1696   aPlane->Size (aSizeX, aSizeY);
1697   Standard_Boolean isUpdate = Standard_True;
1698
1699   TCollection_AsciiString aPName, aPValue;
1700   for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1701   {
1702     const TCollection_AsciiString anArg = theArgVec[anArgIt];
1703     TCollection_AsciiString anArgCase = anArg;
1704     anArgCase.UpperCase();
1705     if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1706     {
1707       aPName.UpperCase();
1708       if (aPName.IsEqual ("X"))
1709       {
1710         aCenterX = aPValue.RealValue();
1711       }
1712       else if (aPName.IsEqual ("Y"))
1713       {
1714         aCenterY = aPValue.RealValue();
1715       }
1716       else if (aPName.IsEqual ("Z"))
1717       {
1718         aCenterZ = aPValue.RealValue();
1719       }
1720       else if (aPName.IsEqual ("DX"))
1721       {
1722         aDirX = aPValue.RealValue();
1723       }
1724       else if (aPName.IsEqual ("DY"))
1725       {
1726         aDirY = aPValue.RealValue();
1727       }
1728       else if (aPName.IsEqual ("DZ"))
1729       {
1730         aDirZ = aPValue.RealValue();
1731       }
1732       else if (aPName.IsEqual ("SX"))
1733       {
1734         aSizeX = aPValue.RealValue();
1735       }
1736       else if (aPName.IsEqual ("SY"))
1737       {
1738         aSizeY = aPValue.RealValue();
1739       }
1740     }
1741     else if (anArg.IsEqual ("NOUPDATE"))
1742     {
1743       isUpdate = Standard_False;
1744     }
1745   }
1746
1747   gp_Dir aDirection (aDirX, aDirY, aDirZ);
1748   gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1749   aPlane->SetCenter (aCenterPnt);
1750   aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1751   aPlane->SetSize (aSizeX, aSizeY);
1752
1753   aContextAIS->Update (aPlane, isUpdate);
1754
1755   return 0;
1756 }
1757
1758 //==============================================================================
1759 // Fonction  vline
1760 // ---------------  Uniquement par parametre. Pas de selection dans le viewer.
1761 //==============================================================================
1762
1763 //==============================================================================
1764 //function : VLineBuilder
1765 //purpose  : Build an AIS_Line
1766 //Draw arg : vline LineName  [AIS_PointName] [AIS_PointName]
1767 //                           [Xa] [Ya] [Za]   [Xb] [Yb] [Zb]
1768 //==============================================================================
1769 #include <Geom_CartesianPoint.hxx>
1770 #include <AIS_Line.hxx>
1771
1772
1773 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1774 {
1775   // Verifications
1776   if (argc!=4 && argc!=8 && argc!=2 )  {di<<"vline error: number of arguments not correct \n";return 1; }
1777
1778   // On recupere les parametres
1779   Handle(AIS_InteractiveObject) theShapeA;
1780   Handle(AIS_InteractiveObject) theShapeB;
1781
1782   // Parametres: AIS_Point AIS_Point
1783   // ===============================
1784   if (argc==4) {
1785     GetMapOfAIS().Find2 (argv[2], theShapeA);
1786     // On verifie que c'est bien une AIS_Point
1787     if (!theShapeA.IsNull() &&
1788       theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1789         // on recupere le deuxieme AIS_Point
1790         GetMapOfAIS().Find2 (argv[3], theShapeB);
1791         if (theShapeB.IsNull() ||
1792           (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1793         {
1794           di <<"vline error: wrong type of 2de argument.\n";
1795           return 1;
1796         }
1797       }
1798     else {di <<"vline error: wrong type of 1st argument.\n";return 1; }
1799     // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1800     Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1801     Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
1802
1803     Handle(Geom_Point ) myGeomPointBA=  theAISPointA->Component();
1804     Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
1805     //    Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1806
1807     Handle(Geom_Point ) myGeomPointB=  theAISPointB->Component();
1808     Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
1809     //    Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1810
1811     if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1812       // B=A
1813       di<<"vline error: same points\n";return 1;
1814     }
1815     // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1816     Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1817     GetMapOfAIS().Bind(theAISLine,argv[1] );
1818     TheAISContext()->Display (theAISLine, Standard_True);
1819
1820   }
1821
1822   // Parametres 6 Reals
1823   // ==================
1824
1825   else if (argc==8) {
1826     // On verifie que les deux points ne sont pas confondus
1827
1828     Standard_Real coord[6];
1829     for(Standard_Integer i=0;i<=2;i++){
1830       coord[i]=Draw::Atof(argv[2+i]);
1831       coord[i+3]=Draw::Atof(argv[5+i]);
1832     }
1833
1834     Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1835     Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1836
1837     Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1838     GetMapOfAIS().Bind(theAISLine,argv[1] );
1839     TheAISContext()->Display (theAISLine, Standard_True);
1840
1841   }
1842
1843   // Pas de parametres: Selection dans le viewer.
1844   // ============================================
1845
1846   else
1847   {
1848     TopTools_ListOfShape aShapes;
1849     ViewerTest::GetSelectedShapes (aShapes);
1850     if (aShapes.Extent() != 2)
1851     {
1852       std::cerr << "Error: wrong number of selected shapes.\n";
1853       return 1;
1854     }
1855
1856     const TopoDS_Shape& aShapeA = aShapes.First();
1857     const TopoDS_Shape& aShapeB = aShapes.Last();
1858
1859     if (!(aShapeA.ShapeType() == TopAbs_VERTEX
1860        && aShapeB.ShapeType() == TopAbs_VERTEX))
1861     {
1862       std::cerr << "Error: you should select two different vertex.\n";
1863       return 1;
1864     }
1865
1866     // Construction de la line
1867     gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1868     gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
1869
1870     Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1871     Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1872
1873     Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1874     GetMapOfAIS().Bind(theAISLine,argv[1] );
1875     TheAISContext()->Display (theAISLine, Standard_True);
1876   }
1877
1878   return 0;
1879 }
1880
1881 //==============================================================================
1882 // class   : FilledCircle
1883 // purpose : creates filled circle based on AIS_InteractiveObject 
1884 //           and Geom_Circle.
1885 //           This class is used to check method Matches() of class 
1886 //           Select3D_SensitiveCircle with member myFillStatus = Standard_True, 
1887 //           because none of AIS classes provides creation of 
1888 //           Select3D_SensitiveCircle with member myFillStatus = Standard_True 
1889 //           (look method ComputeSelection() )
1890 //============================================================================== 
1891
1892 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius) 
1893 {
1894   gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.))); 
1895   gp_Circ aCirc(anAxes, theRadius);
1896   Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1897   return aCircle;
1898 }
1899
1900 class FilledCircle : public AIS_InteractiveObject 
1901 {
1902 public:
1903     // CASCADE RTTI
1904     DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject); 
1905
1906     FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1907     FilledCircle(Handle(Geom_Circle) theCircle);
1908
1909 private:
1910     TopoDS_Face ComputeFace();
1911
1912     // Virtual methods implementation
1913     void Compute (  const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1914                   const Handle(Prs3d_Presentation)& thePresentation,
1915                   const Standard_Integer theMode) Standard_OVERRIDE;
1916
1917     void ComputeSelection (  const Handle(SelectMgr_Selection)& theSelection, 
1918                            const Standard_Integer theMode) Standard_OVERRIDE;
1919
1920 protected:
1921     Handle(Geom_Circle) myCircle;
1922     Standard_Boolean myFilledStatus;
1923
1924 }; 
1925
1926
1927 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius) 
1928 {
1929   myCircle = CreateCircle(theCenter, theRadius);
1930   myFilledStatus = Standard_True;
1931 }
1932
1933 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle) 
1934 {
1935   myCircle = theCircle;
1936   myFilledStatus = Standard_True;
1937 }
1938
1939 TopoDS_Face FilledCircle::ComputeFace() 
1940 {
1941   // Create edge from myCircle 
1942   BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1943   TopoDS_Edge anEdge = anEdgeMaker.Edge(); 
1944
1945   // Create wire from anEdge 
1946   BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1947   TopoDS_Wire aWire = aWireMaker.Wire();
1948
1949   // Create face from aWire
1950   BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1951   TopoDS_Face aFace = aFaceMaker.Face();
1952
1953   return aFace;
1954 }
1955
1956 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/, 
1957                            const Handle(Prs3d_Presentation) &thePresentation, 
1958                            const Standard_Integer theMode) 
1959 {
1960   thePresentation->Clear();
1961
1962   TopoDS_Face aFace = ComputeFace();
1963
1964   if (aFace.IsNull()) return;
1965   if (theMode != 0) return;
1966
1967   StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1968 }
1969
1970 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection, 
1971                                     const Standard_Integer /*theMode*/)
1972 {
1973   Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
1974   Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner, 
1975       myCircle, myFilledStatus);
1976   theSelection->Add(aSensitiveCircle);
1977 }
1978
1979 //==============================================================================
1980 // Fonction  vcircle
1981 // -----------------  Uniquement par parametre. Pas de selection dans le viewer.
1982 //==============================================================================
1983
1984 //==============================================================================
1985 //function : VCircleBuilder
1986 //purpose  : Build an AIS_Circle
1987 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
1988 //                              PointName PointName PointName IsFilled
1989 //==============================================================================
1990
1991 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
1992                     TCollection_AsciiString theName, 
1993                     Standard_Boolean isFilled) 
1994 {
1995   Handle(AIS_InteractiveObject) aCircle;
1996   if (isFilled) 
1997   {
1998     aCircle = new FilledCircle(theGeomCircle);
1999   }
2000   else
2001   {
2002     aCircle = new AIS_Circle(theGeomCircle);
2003     Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2004   }
2005
2006   // Check if there is an object with given name
2007   // and remove it from context
2008   if (GetMapOfAIS().IsBound2(theName)) 
2009   {
2010     Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2(theName);
2011     TheAISContext()->Remove(anInterObj, Standard_False);
2012     GetMapOfAIS().UnBind2(theName);
2013    }
2014
2015    // Bind the circle to its name
2016    GetMapOfAIS().Bind(aCircle, theName);
2017
2018    // Display the circle
2019    TheAISContext()->Display (aCircle, Standard_True);
2020   
2021 }
2022
2023 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2024 {
2025   // Verification of the arguments
2026   if (argc>6 || argc<2) 
2027   { 
2028     std::cout << "vcircle error: expect 4 arguments.\n"; 
2029     return 1; // TCL_ERROR 
2030   }
2031
2032   // There are all arguments
2033   if (argc == 6) 
2034   {
2035     // Get arguments
2036     TCollection_AsciiString aName(argv[1]);
2037     Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0;
2038
2039     Handle(AIS_InteractiveObject) theShapeA, theShapeB;
2040     GetMapOfAIS().Find2 (argv[2], theShapeA);
2041     GetMapOfAIS().Find2 (argv[3], theShapeB);
2042
2043     // Arguments: AIS_Point AIS_Point AIS_Point
2044     // ========================================
2045     if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2046       theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2047     {
2048       if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) 
2049       {
2050         std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2051         return 1; // TCL_ERROR 
2052       }
2053       // The third object must be a point
2054       Handle(AIS_InteractiveObject) theShapeC;
2055       GetMapOfAIS().Find2 (argv[4], theShapeC);
2056       if (theShapeC.IsNull() ||
2057         theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 ) 
2058       {
2059         std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2060         return 1; // TCL_ERROR 
2061       }
2062         // tag
2063         // Verify that the three points are different
2064         Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2065         Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2066         Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2067         
2068         Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2069         Handle(Geom_CartesianPoint) myCartPointA = 
2070           Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2071
2072         Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2073         Handle(Geom_CartesianPoint) myCartPointB =
2074           Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2075
2076         Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2077         Handle(Geom_CartesianPoint) myCartPointC =
2078           Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2079
2080         // Test A=B
2081         if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() && 
2082             Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() && 
2083             Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() ) 
2084         {
2085           std::cout << "vcircle error: Same points.\n"; 
2086           return 1; // TCL_ERROR 
2087         }
2088         // Test A=C
2089         if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2090             Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() && 
2091             Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() ) 
2092         {
2093           std::cout << "vcircle error: Same points.\n"; 
2094           return 1; // TCL_ERROR 
2095         }
2096         // Test B=C
2097         if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() && 
2098             Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() && 
2099             Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() ) 
2100         {
2101           std::cout << "vcircle error: Same points.\n"; 
2102           return 1;// TCL_ERROR 
2103         }
2104         // Construction of the circle
2105         GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(), 
2106           myCartPointB->Pnt(), myCartPointC->Pnt() );
2107         Handle (Geom_Circle) theGeomCircle;
2108         try 
2109         {
2110           theGeomCircle = Cir.Value();
2111         }
2112         catch (StdFail_NotDone const&)
2113         {
2114           std::cout << "vcircle error: can't create circle\n";
2115           return -1; // TCL_ERROR
2116         }
2117         
2118         DisplayCircle(theGeomCircle, aName, isFilled);
2119     }
2120
2121     // Arguments: AIS_Plane AIS_Point Real
2122     // ===================================
2123     else if (theShapeA->Type() == AIS_KOI_Datum && 
2124       theShapeA->Signature() == 7 ) 
2125     {
2126       if (theShapeB->Type() != AIS_KOI_Datum || 
2127         theShapeB->Signature() != 1 ) 
2128       {
2129         std::cout << "vcircle error: 2d element is a unexpected to be a point.\n"; 
2130         return 1; // TCL_ERROR 
2131       }
2132       // Check that the radius is >= 0
2133       if (Draw::Atof(argv[4]) <= 0 ) 
2134       {
2135         std::cout << "vcircle error: the radius must be >=0.\n"; 
2136         return 1; // TCL_ERROR 
2137       }
2138
2139       // Recover the normal to the plane
2140       Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2141       Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB); 
2142
2143       Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2144       Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2145       Handle(Geom_CartesianPoint) myCartPointB = 
2146         Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2147
2148       gp_Pln mygpPlane = myGeomPlane->Pln();
2149       gp_Ax1 thegpAxe = mygpPlane.Axis();
2150       gp_Dir theDir = thegpAxe.Direction();
2151       gp_Pnt theCenter = myCartPointB->Pnt();
2152       Standard_Real TheR = Draw::Atof(argv[4]);
2153       GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2154       Handle (Geom_Circle) theGeomCircle;
2155       try 
2156       {
2157         theGeomCircle = Cir.Value();
2158       }
2159       catch (StdFail_NotDone const&)
2160       {
2161         std::cout << "vcircle error: can't create circle\n";
2162         return -1; // TCL_ERROR
2163       }
2164
2165       DisplayCircle(theGeomCircle, aName, isFilled);
2166
2167     }
2168
2169     // Error
2170     else
2171     {
2172       std::cout << "vcircle error: 1st argument is a unexpected type.\n"; 
2173       return 1; // TCL_ERROR 
2174     }
2175
2176   }
2177   // No arguments: selection in the viewer
2178   // =========================================
2179   else 
2180   {
2181     // Get the name of the circle 
2182     TCollection_AsciiString aName(argv[1]);
2183
2184     TopTools_ListOfShape aShapes;
2185     ViewerTest::GetSelectedShapes (aShapes);
2186     if (aShapes.Extent() != 3 && aShapes.Extent() != 2)
2187     {
2188       std::cerr << "Error: Wrong number of selected shapes.\n";
2189       return 1;
2190     }
2191
2192     const TopoDS_Shape& aShapeA = aShapes.First();
2193     if (aShapeA.ShapeType() == TopAbs_VERTEX ) 
2194     {
2195       if (aShapes.Extent() != 3)
2196       {
2197         std::cerr << "Error: wrong number of selected shapes.\n";
2198         return 1;
2199       }
2200
2201       TopTools_ListOfShape::Iterator anIter (aShapes);
2202
2203       anIter.Next();
2204       const TopoDS_Shape& aShapeB = anIter.Value();
2205
2206       anIter.Next();
2207       const TopoDS_Shape& aShapeC = anIter.Value();
2208       
2209       // Get isFilled
2210       Standard_Boolean isFilled;
2211       std::cout << "Enter filled status (0 or 1)\n";
2212       cin >> isFilled;
2213
2214       // Construction of the circle
2215       gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
2216       gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2217       gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC));
2218
2219       GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2220       Handle (Geom_Circle) theGeomCircle;
2221       try 
2222       {
2223         theGeomCircle = Cir.Value();
2224       }
2225       catch (StdFail_NotDone const&)
2226       {
2227         std::cout << "vcircle error: can't create circle\n";
2228         return -1; // TCL_ERROR
2229       }
2230
2231       DisplayCircle(theGeomCircle, aName, isFilled);
2232
2233     }
2234     else if (aShapeA.ShapeType() == TopAbs_FACE)
2235     {
2236       const TopoDS_Shape& aShapeB = aShapes.Last();
2237
2238       // Recover the radius 
2239       Standard_Real theRad;
2240       do 
2241       {
2242         std::cout << " Enter the value of the radius:\n";
2243         cin >> theRad;
2244       } while (theRad <= 0);
2245       
2246       // Get filled status
2247       Standard_Boolean isFilled;
2248       std::cout << "Enter filled status (0 or 1)\n";
2249       cin >> isFilled;
2250
2251       // Recover the normal to the plane. tag
2252       TopoDS_Face myFace = TopoDS::Face(aShapeA);
2253       BRepAdaptor_Surface mySurface (myFace, Standard_False);
2254       gp_Pln myPlane = mySurface.Plane();
2255       Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2256       gp_Pln mygpPlane = theGeomPlane->Pln();
2257       gp_Ax1 thegpAxe = mygpPlane.Axis();
2258       gp_Dir theDir = thegpAxe.Direction();
2259
2260       // Recover the center
2261       gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2262
2263       // Construct the circle
2264       GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2265       Handle (Geom_Circle) theGeomCircle;
2266       try 
2267       {
2268         theGeomCircle = Cir.Value();
2269       }
2270       catch (StdFail_NotDone const&)
2271       {
2272         std::cout << "vcircle error: can't create circle\n";
2273         return -1; // TCL_ERROR
2274       }
2275
2276       DisplayCircle(theGeomCircle, aName, isFilled);
2277     }
2278     else
2279     {
2280       std::cerr << "Error: You should select face and vertex or three vertices.\n";
2281       return 1;
2282     }
2283   }
2284
2285   return 0;
2286 }
2287
2288 //=======================================================================
2289 //function : VDrawText
2290 //purpose  :
2291 //=======================================================================
2292 static int VDrawText (Draw_Interpretor& theDI,
2293                       Standard_Integer  theArgsNb,
2294                       const char**      theArgVec)
2295 {
2296   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2297   if (theArgsNb < 3)
2298   {
2299     std::cout << "Error: wrong number of arguments! See usage:\n";
2300     theDI.PrintHelp (theArgVec[0]);
2301     return 1;
2302   }
2303   else if (aContext.IsNull())
2304   {
2305     std::cout << "Error: no active view!\n";
2306     return 1;
2307   }
2308
2309   Standard_Integer           anArgIt = 1;
2310   TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2311   TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2312   Handle(AIS_TextLabel)      aTextPrs;
2313   ViewerTest_AutoUpdater     anAutoUpdater (aContext, ViewerTest::CurrentView());
2314
2315   Standard_Boolean isNewPrs = Standard_False;
2316   if (GetMapOfAIS().IsBound2 (aName))
2317   {
2318     aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2319   }
2320
2321   if (aTextPrs.IsNull())
2322   {
2323     isNewPrs = Standard_True;
2324     aTextPrs = new AIS_TextLabel();
2325     aTextPrs->SetFont ("Courier");
2326   }
2327
2328   aTextPrs->SetText (aText);
2329
2330   Handle(Graphic3d_TransformPers) aTrsfPers;
2331   Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2332
2333   Standard_Boolean aHasPlane = Standard_False;
2334   gp_Dir           aNormal;
2335   gp_Dir           aDirection;
2336   gp_Pnt           aPos;
2337
2338   for (; anArgIt < theArgsNb; ++anArgIt)
2339   {
2340     TCollection_AsciiString aParam (theArgVec[anArgIt]);
2341     aParam.LowerCase();
2342
2343     if (anAutoUpdater.parseRedrawMode (aParam))
2344     {
2345       continue;
2346     }
2347     else if (aParam == "-pos"
2348           || aParam == "-position")
2349     {
2350       if (anArgIt + 3 >= theArgsNb)
2351       {
2352         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2353         return 1;
2354       }
2355
2356       aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2357       aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2358       aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2359       aTextPrs->SetPosition (aPos);
2360     }
2361     else if (aParam == "-color")
2362     {
2363       if (anArgIt + 1 >= theArgsNb)
2364       {
2365         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2366         return 1;
2367       }
2368
2369       TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2370       Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2371       if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2372       {
2373         anArgIt += 1;
2374         aTextPrs->SetColor (aNameOfColor);
2375         continue;
2376       }
2377       else if (anArgIt + 3 >= theArgsNb)
2378       {
2379         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2380         return 1;
2381       }
2382
2383       TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2384       TCollection_AsciiString aBlue  (theArgVec[anArgIt + 3]);
2385       if (!aColor.IsRealValue()
2386        || !aGreen.IsRealValue()
2387        || !aBlue.IsRealValue())
2388       {
2389         std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2390         return 1;
2391       }
2392
2393       const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2394                                    aGreen.RealValue(),
2395                                    aBlue.RealValue());
2396
2397       aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2398       anArgIt += 3;
2399     }
2400     else if (aParam == "-halign")
2401     {
2402       if (++anArgIt >= theArgsNb)
2403       {
2404         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2405         return 1;
2406       }
2407
2408       TCollection_AsciiString aType (theArgVec[anArgIt]);
2409       aType.LowerCase();
2410       if (aType == "left")
2411       {
2412         aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2413       }
2414       else if (aType == "center")
2415       {
2416         aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2417       }
2418       else if (aType == "right")
2419       {
2420         aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2421       }
2422       else
2423       {
2424         std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2425         return 1;
2426       }
2427     }
2428     else if (aParam == "-valign")
2429     {
2430       if (++anArgIt >= theArgsNb)
2431       {
2432         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2433         return 1;
2434       }
2435
2436       TCollection_AsciiString aType (theArgVec[anArgIt]);
2437       aType.LowerCase();
2438       if (aType == "top")
2439       {
2440         aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2441       }
2442       else if (aType == "center")
2443       {
2444         aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2445       }
2446       else if (aType == "bottom")
2447       {
2448         aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2449       }
2450       else if (aType == "topfirstline")
2451       {
2452         aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2453       }
2454       else
2455       {
2456         std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2457         return 1;
2458       }
2459     }
2460     else if (aParam == "-angle")
2461     {
2462       if (++anArgIt >= theArgsNb)
2463       {
2464         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2465         return 1;
2466       }
2467
2468       aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2469     }
2470     else if (aParam == "-zoom")
2471     {
2472       if (++anArgIt >= theArgsNb)
2473       {
2474         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2475         return 1;
2476       }
2477
2478       aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2479     }
2480     else if (aParam == "-height")
2481     {
2482       if (++anArgIt >= theArgsNb)
2483       {
2484         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2485         return 1;
2486       }
2487
2488       aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2489     }
2490     else if (aParam == "-aspect")
2491     {
2492       if (++anArgIt >= theArgsNb)
2493       {
2494         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2495         return 1;
2496       }
2497
2498       TCollection_AsciiString anOption (theArgVec[anArgIt]);
2499       anOption.LowerCase();
2500       Font_FontAspect aFontAspect = Font_FA_Undefined;
2501       if (!parseFontStyle (anOption, aFontAspect))
2502       {
2503         std::cout << "Error: unknown font aspect '" << anOption << "'.\n";
2504         return 1;
2505       }
2506       aTextPrs->SetFontAspect (aFontAspect);
2507     }
2508     else if (aParam == "-font")
2509     {
2510       if (++anArgIt >= theArgsNb)
2511       {
2512         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2513         return 1;
2514       }
2515
2516       aTextPrs->SetFont (theArgVec[anArgIt]);
2517     }
2518     else if (aParam == "-plane")
2519     {
2520       if (anArgIt + 6 >= theArgsNb)
2521       {
2522         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2523         return 1;
2524       }
2525
2526       Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
2527       Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
2528       Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
2529       aNormal.SetCoord (aX, aY, aZ);
2530
2531       aX = Draw::Atof (theArgVec[++anArgIt]);
2532       aY = Draw::Atof (theArgVec[++anArgIt]);
2533       aZ = Draw::Atof (theArgVec[++anArgIt]);
2534       aDirection.SetCoord (aX, aY, aZ);
2535
2536       aHasPlane = Standard_True;
2537     }
2538     else if (aParam == "-flipping")
2539     {
2540       aTextPrs->SetFlipping (Standard_True);
2541     }
2542     else if (aParam == "-disptype"
2543           || aParam == "-displaytype")
2544     {
2545       if (++anArgIt >= theArgsNb)
2546       {
2547         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2548         return 1;
2549       }
2550       TCollection_AsciiString aType (theArgVec[anArgIt]);
2551       aType.LowerCase();
2552       if (aType == "subtitle")
2553         aDisplayType = Aspect_TODT_SUBTITLE;
2554       else if (aType == "decal")
2555         aDisplayType = Aspect_TODT_DEKALE;
2556       else if (aType == "blend")
2557         aDisplayType = Aspect_TODT_BLEND;
2558       else if (aType == "dimension")
2559         aDisplayType = Aspect_TODT_DIMENSION;
2560       else if (aType == "normal")
2561         aDisplayType = Aspect_TODT_NORMAL;
2562       else if (aType == "shadow")
2563         aDisplayType = Aspect_TODT_SHADOW;
2564       else
2565       {
2566         std::cout << "Error: wrong display type '" << aType << "'.\n";
2567         return 1;
2568       }
2569     }
2570     else if (aParam == "-subcolor"
2571           || aParam == "-subtitlecolor")
2572     {
2573       if (anArgIt + 1 >= theArgsNb)
2574       {
2575         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2576         return 1;
2577       }
2578
2579       TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2580       Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2581       if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2582       {
2583         anArgIt += 1;
2584         aTextPrs->SetColorSubTitle (aNameOfColor);
2585         continue;
2586       }
2587       else if (anArgIt + 3 >= theArgsNb)
2588       {
2589         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2590         return 1;
2591       }
2592
2593       TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2594       TCollection_AsciiString aBlue  (theArgVec[anArgIt + 3]);
2595       if (!aColor.IsRealValue()
2596        || !aGreen.IsRealValue()
2597        || !aBlue.IsRealValue())
2598       {
2599         std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2600         return 1;
2601       }
2602
2603       const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2604                                    aGreen.RealValue(),
2605                                    aBlue.RealValue());
2606
2607       aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2608       anArgIt += 3;
2609     }
2610     else if (aParam == "-2d")
2611     {
2612       aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d);
2613     }
2614     else if (aParam == "-trsfperspos"
2615           || aParam == "-perspos")
2616     {
2617       if (anArgIt + 2 >= theArgsNb)
2618       {
2619         std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2620         return 1;
2621       }
2622
2623       TCollection_AsciiString aX (theArgVec[++anArgIt]);
2624       TCollection_AsciiString aY (theArgVec[++anArgIt]);
2625       TCollection_AsciiString aZ = "0";
2626       if (!aX.IsIntegerValue()
2627        || !aY.IsIntegerValue())
2628       {
2629         std::cerr << "Error: wrong syntax at '" << aParam << "'.\n";
2630         return 1;
2631       }
2632       if (anArgIt + 1 < theArgsNb)
2633       {
2634         TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2635         if (aTemp.IsIntegerValue())
2636         {
2637           aZ = aTemp;
2638           ++anArgIt;
2639         }
2640       }
2641
2642       aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()));
2643     }
2644     else
2645     {
2646       std::cout << "Error: unknown argument '" << aParam << "'\n";
2647       return 1;
2648     }
2649   }
2650
2651   if (aHasPlane)
2652   {
2653     aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2654   }
2655
2656   aTextPrs->SetDisplayType (aDisplayType);
2657
2658   if (!aTrsfPers.IsNull())
2659   {
2660     aContext->SetTransformPersistence (aTextPrs, aTrsfPers);
2661     aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2662     if (aTextPrs->Position().Z() != 0)
2663     {
2664       aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
2665     }
2666   }
2667   else if (!aTextPrs->TransformPersistence().IsNull())
2668   {
2669     aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
2670   }
2671
2672   if (isNewPrs)
2673   {
2674     ViewerTest::Display (aName, aTextPrs, Standard_False);
2675   }
2676   else
2677   {
2678     aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
2679   }
2680   return 0;
2681 }
2682
2683 #include <math.h>
2684 #include <gp_Pnt.hxx>
2685 #include <Graphic3d_ArrayOfPoints.hxx>
2686 #include <Graphic3d_ArrayOfPrimitives.hxx>
2687 #include <Graphic3d_ArrayOfTriangles.hxx>
2688 #include <Poly_Array1OfTriangle.hxx>
2689 #include <Poly_Triangle.hxx>
2690 #include <Poly_Triangulation.hxx>
2691 #include <TColgp_Array1OfPnt.hxx>
2692 #include <TShort_Array1OfShortReal.hxx>
2693 #include <TShort_HArray1OfShortReal.hxx>
2694
2695 #include <AIS_Triangulation.hxx>
2696 #include <StdPrs_ToolTriangulatedShape.hxx>
2697 #include <Poly_Connect.hxx>
2698 #include <TColgp_Array1OfDir.hxx>
2699 #include <Graphic3d_GraphicDriver.hxx>
2700
2701 #include <TColStd_Array1OfInteger.hxx>
2702 #include <TColStd_HArray1OfInteger.hxx>
2703 #include <Prs3d_ShadingAspect.hxx>
2704 #include <Graphic3d_MaterialAspect.hxx>
2705 #include <Graphic3d_AspectFillArea3d.hxx>
2706
2707 #include <BRepPrimAPI_MakeCylinder.hxx>
2708 #include <TopoDS_Shape.hxx>
2709 #include <TopExp_Explorer.hxx>
2710 #include <TopAbs.hxx>
2711 #include <StdSelect_ShapeTypeFilter.hxx>
2712 #include <AIS_InteractiveObject.hxx>
2713
2714
2715 //===============================================================================================
2716 //function : CalculationOfSphere
2717 //author   : psn
2718 //purpose  : Create a Sphere
2719 //===============================================================================================
2720
2721 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2722                                                   int res ,
2723                                                   double Radius ){
2724   double mRadius = Radius;
2725   double mCenter[3] = {X,Y,Z};
2726   int mThetaResolution;
2727   int mPhiResolution;
2728   double mStartTheta = 0;//StartTheta;
2729   double mEndTheta = 360;//EndTheta;
2730   double mStartPhi = 0;//StartPhi;
2731   double mEndPhi = 180;//EndPhi;
2732   res = res < 4 ? 4 : res;
2733
2734   mThetaResolution = res;
2735   mPhiResolution = res;
2736
2737   int i, j;
2738   int jStart, jEnd, numOffset;
2739   double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2740   double startTheta, endTheta, startPhi, endPhi;
2741   int base, numPoles=0, thetaResolution, phiResolution;
2742
2743   int pts[3];
2744   int piece = -1;
2745   int numPieces = 1;
2746   if ( numPieces > mThetaResolution ) {
2747     numPieces = mThetaResolution;
2748   }
2749
2750   int localThetaResolution =  mThetaResolution;
2751   double localStartTheta =  mStartTheta;
2752   double localEndTheta =  mEndTheta;
2753
2754   while ( localEndTheta < localStartTheta ) {
2755     localEndTheta += 360.0;
2756   }
2757
2758   deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2759
2760   // Change the ivars based on pieces.
2761   int start, end;
2762   start = piece * localThetaResolution / numPieces;
2763   end = (piece+1) * localThetaResolution / numPieces;
2764   localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2765   localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2766   localThetaResolution = end - start;
2767
2768   // Create north pole if needed
2769   int number_point = 0;
2770   int number_pointArray = 0;
2771
2772   if ( mStartPhi <= 0.0 ) {
2773     number_pointArray++;
2774     numPoles++;
2775   }
2776   if ( mEndPhi >= 180.0 ) {
2777     number_pointArray++;
2778     numPoles++;
2779   }
2780
2781   // Check data, determine increments, and convert to radians
2782   startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2783   startTheta *= M_PI  / 180.0;
2784   endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2785   endTheta *= M_PI  / 180.0;
2786
2787
2788   startPhi = ( mStartPhi <  mEndPhi ?  mStartPhi :  mEndPhi);
2789   startPhi *= M_PI  / 180.0;
2790   endPhi = ( mEndPhi >  mStartPhi ?  mEndPhi :  mStartPhi);
2791   endPhi *= M_PI  / 180.0;
2792
2793   phiResolution =  mPhiResolution - numPoles;
2794   deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2795   thetaResolution = localThetaResolution;
2796   if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2797     ++localThetaResolution;
2798   }
2799   deltaTheta = (endTheta - startTheta) / thetaResolution;
2800
2801   jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2802   jEnd = ( mEndPhi >= 180.0 ?  mPhiResolution - 1 :  mPhiResolution);
2803
2804   // Create intermediate points
2805   for ( i = 0; i < localThetaResolution; i++ ) {
2806     for ( j = jStart; j < jEnd; j++ ) {
2807         number_pointArray++;
2808     }
2809   }
2810
2811   //Generate mesh connectivity
2812   base = phiResolution * localThetaResolution;
2813
2814   int number_triangle = 0 ;
2815   if ( mStartPhi <= 0.0 ) { // around north pole
2816     number_triangle += localThetaResolution;
2817   }
2818
2819   if ( mEndPhi >= 180.0 ) { // around south pole
2820     number_triangle += localThetaResolution;
2821   }
2822
2823   // bands in-between poles
2824   for ( i=0; i < localThetaResolution; i++){
2825     for ( j=0; j < (phiResolution-1); j++){
2826        number_triangle +=2;
2827     }
2828   }
2829
2830   Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2831   TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2832   Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2833
2834   if (  mStartPhi <= 0.0 ){
2835       x[0] =  mCenter[0];
2836       x[1] =  mCenter[1];
2837       x[2] =  mCenter[2] +  mRadius;
2838       PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2839   }
2840
2841   // Create south pole if needed
2842   if (  mEndPhi >= 180.0 ){
2843       x[0] =  mCenter[0];
2844       x[1] =  mCenter[1];
2845       x[2] =  mCenter[2] -  mRadius;
2846       PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2847   }
2848
2849   number_point = 3;
2850   for ( i=0; i < localThetaResolution; i++){
2851     theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2852     for ( j = jStart; j < jEnd; j++){
2853         phi = startPhi + j*deltaPhi;
2854         radius =  mRadius * sin((double)phi);
2855         n[0] = radius * cos((double)theta);
2856         n[1] = radius * sin((double)theta);
2857         n[2] =  mRadius * cos((double)phi);
2858         x[0] = n[0] +  mCenter[0];
2859         x[1] = n[1] +  mCenter[1];
2860         x[2] = n[2] +  mCenter[2];
2861         PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2862         number_point++;
2863       }
2864     }
2865
2866   numPoles = 3;
2867   number_triangle = 1;
2868   if ( mStartPhi <= 0.0 ){// around north pole
2869     for (i=0; i < localThetaResolution; i++){
2870         pts[0] = phiResolution*i + numPoles;
2871         pts[1] = (phiResolution*(i+1) % base) + numPoles;
2872         pts[2] = 1;
2873         pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2874         number_triangle++;
2875       }
2876     }
2877
2878   if (  mEndPhi >= 180.0 ){ // around south pole
2879     numOffset = phiResolution - 1 + numPoles;
2880     for (i=0; i < localThetaResolution; i++){
2881         pts[0] = phiResolution*i + numOffset;
2882         pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2883         pts[1] = numPoles - 1;
2884         pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2885         number_triangle++;
2886       }
2887     }
2888
2889   // bands in-between poles
2890
2891   for (i=0; i < localThetaResolution; i++){
2892     for (j=0; j < (phiResolution-1); j++){
2893         pts[0] = phiResolution*i + j + numPoles;
2894         pts[1] = pts[0] + 1;
2895         pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2896         pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2897         number_triangle++;
2898         pts[1] = pts[2];
2899         pts[2] = pts[1] - 1;
2900         pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2901         number_triangle++;
2902       }
2903     }
2904
2905   Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2906
2907   Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2908
2909   Standard_Integer index[3];
2910   Standard_Real Tol = Precision::Confusion();
2911
2912   gp_Dir Nor;
2913   for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2914       gp_XYZ eqPlan(0, 0, 0);
2915       for ( pc->Initialize(i); pc->More(); pc->Next()) {
2916         pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2917         gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2918         gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2919         gp_XYZ vv = v1^v2;
2920         Standard_Real mod = vv.Modulus();
2921         if(mod < Tol) continue;
2922         eqPlan += vv/mod;
2923       }
2924
2925       Standard_Real modmax = eqPlan.Modulus();
2926
2927       if(modmax > Tol)
2928         Nor = gp_Dir(eqPlan);
2929       else
2930         Nor = gp_Dir(0., 0., 1.);
2931       
2932       Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
2933       Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
2934       Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
2935       Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
2936   }
2937
2938   delete pc;
2939   polyTriangulation->SetNormals(Normals);
2940
2941   return polyTriangulation;
2942 }
2943
2944 //===============================================================================================
2945 //function : VDrawSphere
2946 //author   : psn
2947 //purpose  : Create an AIS shape.
2948 //===============================================================================================
2949 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2950 {
2951   // check for errors
2952   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2953   if (aContextAIS.IsNull())
2954   {
2955     std::cout << "Call vinit before!\n";
2956     return 1;
2957   }
2958   else if (argc < 3)
2959   {
2960     std::cout << "Use: " << argv[0]
2961               << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2962     return 1;
2963   }
2964
2965   // read the arguments
2966   TCollection_AsciiString aShapeName (argv[1]);
2967   Standard_Integer aResolution = Draw::Atoi (argv[2]);
2968   Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2969   Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2970   Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2971   Standard_Real aRadius =  (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2972   Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2973   Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
2974
2975   // remove AIS object with given name from map
2976   VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2977
2978   if (toPrintInfo)
2979     std::cout << "Compute Triangulation...\n";
2980   Handle(AIS_Triangulation) aShape
2981     = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2982                                                   aResolution,
2983                                                   aRadius));
2984   Standard_Integer aNumberPoints    = aShape->GetTriangulation()->Nodes().Length();
2985   Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2986
2987   // stupid initialization of Green color in RGBA space as integer
2988   // probably wrong for big-endian CPUs
2989   const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
2990
2991   // setup colors array per vertex
2992   Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2993   for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2994   {
2995     aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData()));
2996   }
2997   aShape->SetColors (aColorArray);
2998
2999   // show statistics
3000   Standard_Integer aPointsSize      = aNumberPoints * 3 * sizeof(float);  // 3x GLfloat
3001   Standard_Integer aNormalsSize     = aNumberPoints * 3 * sizeof(float);  // 3x GLfloat
3002   Standard_Integer aColorsSize      = aNumberPoints * 3 * sizeof(float);  // 3x GLfloat without alpha
3003   Standard_Integer aTrianglesSize   = aNumberTriangles * 3 * sizeof(int); // 3x GLint
3004   Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
3005   Standard_Integer aTotalSize       = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
3006   aTotalSize >>= 20; //MB
3007   aNormalsSize >>= 20;
3008   aColorsSize >>= 20;
3009   aTrianglesSize >>= 20;
3010   aPolyConnectSize >>= 20;
3011   if (toPrintInfo)
3012   {
3013     std::cout << "NumberOfPoints:    " << aNumberPoints << "\n"
3014       << "NumberOfTriangles: " << aNumberTriangles << "\n"
3015       << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
3016       << "Amount of memory for colors: " << aColorsSize << " Mb\n"
3017       << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
3018       << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
3019   }
3020
3021   // Setting material properties, very important for desirable visual result!
3022   Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
3023   aMat.SetAmbient  (0.2f);
3024   aMat.SetSpecular (0.5f);
3025   Handle(Graphic3d_AspectFillArea3d) anAspect
3026     = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3027                                       Quantity_NOC_RED,
3028                                       Quantity_NOC_YELLOW,
3029                                       Aspect_TOL_SOLID,
3030                                       1.0,
3031                                       aMat,
3032                                       aMat);
3033   Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3034   anAspect->SetDrawEdges (toShowEdges);
3035   aShAsp->SetAspect (anAspect);
3036   aShape->Attributes()->SetShadingAspect (aShAsp);
3037
3038   VDisplayAISObject (aShapeName, aShape);
3039   return 0;
3040 }
3041
3042 //=============================================================================
3043 //function : VComputeHLR
3044 //purpose  :
3045 //=============================================================================
3046
3047 static int VComputeHLR (Draw_Interpretor& ,
3048                         Standard_Integer theArgNb,
3049                         const char** theArgVec)
3050 {
3051   TCollection_AsciiString aShapeName, aHlrName;
3052   TopoDS_Shape aSh;
3053   gp_Pnt anEye;
3054   gp_Dir aDir;
3055   gp_Ax2 aProjAx;
3056   bool hasViewDirArg = false;
3057   Prs3d_TypeOfHLR anAlgoType = Prs3d_TOH_PolyAlgo;
3058   bool toShowTangentEdges = false, toShowHiddenEdges = false;
3059   int aNbIsolines = 0;
3060   if (Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext())
3061   {
3062     gp_Dir aRight;
3063     Handle(V3d_View) aView = ViewerTest::CurrentView();
3064     Standard_Integer aWidth, aHeight;
3065     Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3066     Standard_Real aRightX, aRightY, aRightZ;
3067     aView->Window()->Size (aWidth, aHeight);
3068
3069     aView->ConvertWithProj (aWidth, aHeight/2, 
3070                             aRightX, aRightY, aRightZ,
3071                             aDirX, aDirY, aDirZ);
3072     aView->ConvertWithProj (aWidth/2, aHeight/2, 
3073                             aCentX, aCentY, aCentZ,
3074                             aDirX, aDirY, aDirZ);
3075
3076     anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3077     aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3078     aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3079     aProjAx.SetLocation (anEye);
3080     aProjAx.SetDirection (aDir);
3081     aProjAx.SetXDirection (aRight);
3082   }
3083   for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3084   {
3085     TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3086     anArgCase.LowerCase();
3087     if (anArgIter + 1 < theArgNb
3088      && (anArgCase == "-algotype"
3089       || anArgCase == "-algo"
3090       || anArgCase == "-type"))
3091     {
3092       TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
3093       anArgNext.LowerCase();
3094       if (anArgNext == "polyalgo")
3095       {
3096         anAlgoType = Prs3d_TOH_PolyAlgo;
3097       }
3098       else if (anArgNext == "algo")
3099       {
3100         anAlgoType = Prs3d_TOH_Algo;
3101       }
3102       else
3103       {
3104         std::cout << "Syntax error: unknown algo type '" << anArgNext << "'\n";
3105         return 1;
3106       }
3107     }
3108     else if (anArgCase == "-showhiddenedges"
3109           || anArgCase == "-hiddenedges"
3110           || anArgCase == "-hidden")
3111     {
3112       toShowHiddenEdges = true;
3113       if (anArgIter + 1 < theArgNb
3114        && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowHiddenEdges))
3115       {
3116         ++anArgIter;
3117       }
3118     }
3119     else if (anArgCase == "-showtangentedges"
3120           || anArgCase == "-tangentedges"
3121           || anArgCase == "-tangent")
3122     {
3123       toShowTangentEdges = true;
3124       if (anArgIter + 1 < theArgNb
3125        && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowTangentEdges))
3126       {
3127         ++anArgIter;
3128       }
3129     }
3130     else if (anArgIter + 1 < theArgNb
3131           && (anArgCase == "-nbiso"
3132            || anArgCase == "-nbisolines"))
3133     {
3134       aNbIsolines = Draw::Atoi (theArgVec[++anArgIter]);
3135     }
3136     else if (aSh.IsNull())
3137     {
3138       aSh = DBRep::Get (theArgVec[anArgIter]);
3139       aShapeName = theArgVec[anArgIter];
3140       if (aSh.IsNull())
3141       {
3142         BRep_Builder aBrepBuilder;
3143         BRepTools::Read (aSh, theArgVec[anArgIter], aBrepBuilder);
3144         if (aSh.IsNull())
3145         {
3146           std::cout << "Syntax error: no shape with name " << theArgVec[anArgIter] << " found\n";
3147           return 1;
3148         }
3149       }
3150     }
3151     else if (aHlrName.IsEmpty())
3152     {
3153       aHlrName = theArgVec[anArgIter];
3154     }
3155     else if (!hasViewDirArg
3156           && anArgIter + 8 < theArgNb)
3157     {
3158       hasViewDirArg = true;
3159       gp_Dir anUp;
3160       anEye.SetCoord (Draw::Atof (theArgVec[anArgIter + 0]), Draw::Atof (theArgVec[anArgIter + 1]), Draw::Atof (theArgVec[anArgIter + 2]));
3161       aDir .SetCoord (Draw::Atof (theArgVec[anArgIter + 3]), Draw::Atof (theArgVec[anArgIter + 4]), Draw::Atof (theArgVec[anArgIter + 5]));
3162       anUp .SetCoord (Draw::Atof (theArgVec[anArgIter + 6]), Draw::Atof (theArgVec[anArgIter + 7]), Draw::Atof (theArgVec[anArgIter + 8]));
3163       aProjAx.SetLocation (anEye);
3164       aProjAx.SetDirection (aDir);
3165       aProjAx.SetYDirection (anUp);
3166       anArgIter += 8;
3167     }
3168     else
3169     {
3170       std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n";
3171       return 1;
3172     }
3173   }
3174
3175   if (aHlrName.IsEmpty() || aSh.IsNull()
3176    || (ViewerTest::GetAISContext().IsNull() && hasViewDirArg))
3177   {
3178     std::cout << "Syntax error: wrong number of arguments\n";
3179     return 1;
3180   }
3181
3182   HLRAlgo_Projector aProjector (aProjAx);
3183   TopoDS_Shape aVisible[6];
3184   TopoDS_Shape aHidden[6];
3185   if (anAlgoType == Prs3d_TOH_PolyAlgo)
3186   {
3187     Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3188     aPolyAlgo->Projector (aProjector);
3189     aPolyAlgo->Load (aSh);
3190     aPolyAlgo->Update();
3191
3192     HLRBRep_PolyHLRToShape aHLRToShape;
3193     aHLRToShape.Update (aPolyAlgo);
3194
3195     aVisible[HLRBRep_Sharp]   = aHLRToShape.VCompound();
3196     aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); // extract visible outlines
3197     aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3198     if (toShowTangentEdges)
3199     {
3200       aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3201     }
3202     if (toShowHiddenEdges)
3203     {
3204       aHidden[HLRBRep_Sharp]   = aHLRToShape.HCompound();
3205       aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3206       aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3207       if (toShowTangentEdges)
3208       {
3209         aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3210       }
3211     }
3212   }
3213   else
3214   {
3215     Handle(HLRBRep_Algo) aHlrAlgo = new HLRBRep_Algo();
3216     aHlrAlgo->Add (aSh, aNbIsolines);
3217     aHlrAlgo->Projector (aProjector);
3218     aHlrAlgo->Update();
3219     aHlrAlgo->Hide();
3220
3221     HLRBRep_HLRToShape aHLRToShape (aHlrAlgo);
3222     aVisible[HLRBRep_Sharp]   = aHLRToShape.VCompound();
3223     aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound();
3224     aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3225     if (toShowTangentEdges)
3226     {
3227       aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3228     }
3229     aVisible[HLRBRep_IsoLine] = aHLRToShape.IsoLineVCompound();
3230
3231     if (toShowHiddenEdges)
3232     {
3233       aHidden[HLRBRep_Sharp]   = aHLRToShape.HCompound();
3234       aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3235       aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3236       if (toShowTangentEdges)
3237       {
3238         aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3239       }
3240       aHidden[HLRBRep_IsoLine] = aHLRToShape.IsoLineHCompound();
3241     }
3242     // extract 3d
3243     //aVisible[HLRBRep_Sharp]   = aHLRToShape.CompoundOfEdges (HLRBRep_Sharp, Standard_True, Standard_True);
3244     //aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound3d();
3245   }
3246
3247   TopoDS_Compound aCompRes, aCompVis, aCompHid;
3248   BRep_Builder aBuilder;
3249   aBuilder.MakeCompound (aCompVis);
3250   aBuilder.MakeCompound (aCompHid);
3251   aBuilder.MakeCompound (aCompRes);
3252   for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3253   {
3254     if (!aVisible[aTypeIter].IsNull())
3255     {
3256       aBuilder.Add (aCompVis, aVisible[aTypeIter]);
3257     }
3258     if (!aHidden[aTypeIter].IsNull())
3259     {
3260       aBuilder.Add (aCompHid, aHidden[aTypeIter]);
3261     }
3262   }
3263   aBuilder.Add (aCompRes, aCompVis);
3264   aBuilder.Add (aCompRes, aCompHid);
3265
3266   // create an AIS shape and display it
3267   if (!ViewerTest::GetAISContext().IsNull())
3268   {
3269     Handle(AIS_ColoredShape) anObject = new AIS_ColoredShape (aCompRes);
3270     if (toShowHiddenEdges)
3271     {
3272       Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect (Quantity_Color (Quantity_NOC_RED), Aspect_TOL_DASH, 1.0f);
3273       for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3274       {
3275         if (!aHidden[aTypeIter].IsNull())
3276         {
3277           Handle(AIS_ColoredDrawer) aDrawer = anObject->CustomAspects (aHidden[aTypeIter]);
3278           aDrawer->SetLineAspect (aLineAspect);
3279           aDrawer->SetWireAspect (aLineAspect);
3280           aDrawer->SetFreeBoundaryAspect (aLineAspect);
3281           aDrawer->SetUnFreeBoundaryAspect (aLineAspect);
3282         }
3283       }
3284     }
3285     ViewerTest::Display (aHlrName, anObject, true);
3286   }
3287
3288   DBRep::Set (aHlrName.ToCString(), aCompRes);
3289   return 0;
3290 }
3291
3292 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3293 // manipulating and displaying such an array with AIS context
3294
3295 class MyPArrayObject : public AIS_InteractiveObject
3296 {
3297
3298 public:
3299
3300   MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives)& thePArray) : myPArray (thePArray) {}
3301
3302   MyPArrayObject (Graphic3d_TypeOfPrimitiveArray thePrimType,
3303                   const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3304                   const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect)
3305   {
3306     Init (thePrimType, theDesc, theMarkerAspect, Standard_False);
3307   }
3308
3309   //! Initialize the array from specified description.
3310   Standard_Boolean Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3311                          const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3312                          const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3313                          Standard_Boolean theToPatch);
3314
3315   DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
3316
3317   virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
3318
3319 private:
3320
3321   void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3322                 const Handle(Prs3d_Presentation)& aPresentation,
3323                 const Standard_Integer aMode) Standard_OVERRIDE;
3324
3325   void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3326                          const Standard_Integer /*theMode*/) Standard_OVERRIDE;
3327
3328   bool CheckInputCommand (const TCollection_AsciiString theCommand,
3329                           const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3330                           Standard_Integer &theArgIndex,
3331                           Standard_Integer theArgCount,
3332                           Standard_Integer theMaxArgs);
3333
3334 protected:
3335
3336   Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3337   Handle(Graphic3d_ArrayOfPrimitives) myPArray;
3338
3339 };
3340
3341 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3342                               const Handle(Prs3d_Presentation)& thePrs,
3343                               const Standard_Integer theMode)
3344 {
3345   if (myPArray.IsNull() || theMode != 0)
3346   {
3347     return;
3348   }
3349
3350   Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
3351   if (!myMarkerAspect.IsNull())
3352   {
3353     aGroup->SetGroupPrimitivesAspect (myMarkerAspect);
3354   }
3355   else
3356   {
3357     aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
3358   }
3359   aGroup->AddPrimitiveArray (myPArray);
3360 }
3361
3362 Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3363                                        const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3364                                        const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3365                                        Standard_Boolean theToPatch)
3366 {
3367   myMarkerAspect = theMarkerAspect;
3368   if (!theToPatch)
3369   {
3370     myPArray.Nullify();
3371   }
3372
3373   // Parsing array description
3374   Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3375   Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None;
3376
3377   const Standard_Integer anArgsCount = theDesc->Length();
3378   TCollection_AsciiString aCommand;
3379   for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3380   {
3381     aCommand = theDesc->Value (anArgIndex);
3382     aCommand.LowerCase();
3383
3384     if (CheckInputCommand ("-deinterleaved", theDesc, anArgIndex, 0, anArgsCount))
3385     {
3386       anArrayFlags |= Graphic3d_ArrayFlags_AttribsDeinterleaved;
3387     }
3388     else if (CheckInputCommand ("-mutable", theDesc, anArgIndex, 0, anArgsCount))
3389     {
3390       anArrayFlags |= Graphic3d_ArrayFlags_AttribsMutable;
3391       anArrayFlags |= Graphic3d_ArrayFlags_IndexesMutable;
3392     }
3393     // vertex command
3394     else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3395     {
3396       // vertex has a normal or normal with color or texel
3397       if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3398       {
3399         anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal;
3400       }
3401
3402       // vertex has a color
3403       if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3404       {
3405         anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor;
3406       }
3407
3408       // vertex has a texel
3409       if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3410       {
3411         anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel;
3412       }
3413
3414       aVertexNum++;
3415     }
3416     // bound command
3417     else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3418     {
3419       // bound has color
3420       if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3421       {
3422         anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor;
3423       }
3424
3425       aBoundNum++;
3426     }
3427     // edge command
3428     else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3429     {
3430       aEdgeNum++;
3431     }
3432     // unknown command
3433     else
3434       anArgIndex++;
3435   }
3436
3437   if (myPArray.IsNull())
3438   {
3439     myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
3440   }
3441   else
3442   {
3443     if (myPArray->Type() != thePrimType
3444     ||  aVertexNum > myPArray->VertexNumberAllocated()
3445     ||  aEdgeNum   > myPArray->EdgeNumberAllocated()
3446     ||  aBoundNum  > myPArray->BoundNumberAllocated()
3447     || !myPArray->Attributes()->IsMutable()
3448     || (!myPArray->Indices().IsNull() && !myPArray->Indices()->IsMutable()))
3449     {
3450       std::cout << "Syntax error: array cannot be patched\n";
3451       return Standard_False;
3452     }
3453
3454     myPArray->Attributes()->NbElements = aVertexNum;
3455     if (Handle(Graphic3d_AttribBuffer) anAttribs = Handle(Graphic3d_AttribBuffer)::DownCast (myPArray->Attributes()))
3456     {
3457       anAttribs->Invalidate (0, aVertexNum - 1);
3458     }
3459     if (!myPArray->Indices().IsNull())
3460     {
3461       myPArray->Indices()->NbElements = aEdgeNum;
3462     }
3463     if (!myPArray->Bounds().IsNull())
3464     {
3465       myPArray->Bounds()->NbBounds = aBoundNum;
3466     }
3467   }
3468
3469   Standard_Integer aVertIndex = 0;
3470   for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3471   {
3472     aCommand = theDesc->Value (anArgIndex);
3473     aCommand.LowerCase();
3474     if (!aCommand.IsAscii()
3475       || aCommand.IsEmpty())
3476     {
3477       break;
3478     }
3479
3480     // skip beautifiers (syntax is not actually validated)
3481     if (aCommand == "-deinterleaved"
3482      || aCommand == "-mutable"
3483      || aCommand.Value (1) == '('
3484      || aCommand.Value (1) == ')'
3485      || aCommand.Value (1) == ',')
3486     {
3487       ++anArgIndex;
3488     }
3489     // vertex command
3490     else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3491     {
3492       const Graphic3d_Vec3 aVert ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3493                                   (float )theDesc->Value (anArgIndex - 2).RealValue(),
3494                                   (float )theDesc->Value (anArgIndex - 1).RealValue());
3495       if ((anArrayFlags & Graphic3d_ArrayFlags_AttribsDeinterleaved) != 0
3496        || (anArrayFlags & Graphic3d_ArrayFlags_AttribsMutable) != 0)
3497       {
3498         ++aVertIndex;
3499         myPArray->SetVertice (aVertIndex, aVert.x(), aVert.y(), aVert.z());
3500       }
3501       else
3502       {
3503         aVertIndex = myPArray->AddVertex (aVert);
3504       }
3505
3506       // vertex has a normal or normal with color or texel
3507       if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3508       {
3509         const Graphic3d_Vec3 aNorm ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3510                                     (float )theDesc->Value (anArgIndex - 2).RealValue(),
3511                                     (float )theDesc->Value (anArgIndex - 1).RealValue());
3512         myPArray->SetVertexNormal (aVertIndex, aNorm.x(), aNorm.y(), aNorm.z());
3513       }
3514       
3515       if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3516       {
3517         const Graphic3d_Vec3d aCol (theDesc->Value (anArgIndex - 3).RealValue(),
3518                                     theDesc->Value (anArgIndex - 2).RealValue(),
3519                                     theDesc->Value (anArgIndex - 1).RealValue());
3520         myPArray->SetVertexColor (aVertIndex, aCol.r(), aCol.g(), aCol.b());
3521       }
3522       if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3523       {
3524         const Graphic3d_Vec2 aTex ((float )theDesc->Value (anArgIndex - 2).RealValue(),
3525                                    (float )theDesc->Value (anArgIndex - 1).RealValue());
3526         myPArray->SetVertexTexel (aVertIndex, aTex.x(), aTex.y());
3527       }
3528     }
3529     // bounds command
3530     else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3531     {
3532       Standard_Integer aVertCount = theDesc->Value (anArgIndex - 1).IntegerValue();
3533
3534       if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3535         myPArray->AddBound (aVertCount,
3536                             theDesc->Value (anArgIndex - 3).RealValue(),
3537                             theDesc->Value (anArgIndex - 2).RealValue(),
3538                             theDesc->Value (anArgIndex - 1).RealValue());
3539
3540       else
3541         myPArray->AddBound (aVertCount);
3542     }
3543     // edge command
3544     else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3545     {
3546       const Standard_Integer anEdge = theDesc->Value (anArgIndex - 1).IntegerValue();
3547       myPArray->AddEdge (anEdge);
3548     }
3549     // unknown command
3550     else
3551     {
3552       std::cout << "Syntax error: unknown argument '" << theDesc->Value(anArgIndex) << "'\n";
3553       return Standard_False;
3554     }
3555   }
3556   return Standard_True;
3557 }
3558
3559 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3560                                        const Standard_Integer theMode)
3561 {
3562   if (theMode != 0
3563    || myPArray.IsNull())
3564   {
3565     return;
3566   }
3567
3568   Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
3569   if (Handle(Graphic3d_ArrayOfTriangles) aTris = Handle(Graphic3d_ArrayOfTriangles)::DownCast (myPArray))
3570   {
3571     Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3572     aSensitive->InitTriangulation (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3573     theSelection->Add (aSensitive);
3574   }
3575   else if (Handle(Graphic3d_ArrayOfSegments) aSegs = Handle(Graphic3d_ArrayOfSegments)::DownCast (myPArray))
3576   {
3577     if (aSegs->EdgeNumber() > 0)
3578     {
3579       for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->EdgeNumber(); aPntIter += 2)
3580       {
3581         Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aSegs->Edge (aPntIter)), aSegs->Vertice (aSegs->Edge (aPntIter + 1)));
3582         aSeg->SetSensitivityFactor (4);
3583         theSelection->Add (aSeg);
3584       }
3585     }
3586     else
3587     {
3588       for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->VertexNumber(); aPntIter += 2)
3589       {
3590         Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aPntIter), aSegs->Vertice (aPntIter + 1));
3591         aSeg->SetSensitivityFactor (4);
3592         theSelection->Add (aSeg);
3593       }
3594     }
3595   }
3596   else
3597   {
3598     Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3599     aSensitive->SetSensitivityFactor (8);
3600     aSensitive->InitPoints (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3601     theSelection->Add (aSensitive);
3602   }
3603 }
3604
3605 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3606                                        const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3607                                        Standard_Integer &theArgIndex,
3608                                        Standard_Integer theArgCount,
3609                                        Standard_Integer theMaxArgs)
3610 {
3611   // check if there is more elements than expected
3612   if (theArgIndex >= theMaxArgs)
3613     return false;
3614
3615   TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3616   aStrCommand.LowerCase();
3617   if (aStrCommand.Search(theCommand) != 1 ||
3618       theArgIndex + (theArgCount - 1) >= theMaxArgs)
3619     return false;
3620
3621   // go to the first data element
3622   theArgIndex++;
3623
3624   // check data if it can be converted to numeric
3625   for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3626   {
3627     aStrCommand = theArgsArray->Value (theArgIndex);
3628     if (!aStrCommand.IsRealValue())
3629       return false;
3630   }
3631
3632   return true;
3633 }
3634
3635 //=============================================================================
3636 //function : VDrawPArray
3637 //purpose  : Draws primitives array from list of vertexes, bounds, edges
3638 //=============================================================================
3639
3640 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3641 {
3642   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3643   if (aContextAIS.IsNull())
3644   {
3645     std::cout << "Error: no active Viewer\n";
3646     return 1;
3647   }
3648   else if (argc < 3)
3649   {
3650     std::cout << "Syntax error: wrong number of arguments\n";
3651     return 1;
3652   }
3653
3654   // read the arguments
3655   Standard_Integer anArgIndex = 1;
3656   TCollection_AsciiString aName (argv[anArgIndex++]);
3657   TCollection_AsciiString anArrayType (argv[anArgIndex++]);
3658   anArrayType.LowerCase();
3659   Handle(MyPArrayObject) aPObject;
3660   if (anArrayType == "-shape")
3661   {
3662     Standard_CString aShapeName = argv[anArgIndex++];
3663     TopoDS_Shape aShape = DBRep::Get (aShapeName);
3664     Handle(Graphic3d_ArrayOfPrimitives) aTris = StdPrs_ShadedShape::FillTriangles (aShape);
3665     if (aShape.IsNull())
3666     {
3667       std::cout << "Syntax error: shape '" << aShapeName << "' is not found\n";
3668       return 1;
3669     }
3670     else if (aTris.IsNull())
3671     {
3672       std::cout << "Syntax error: shape '" << aShapeName << "' is not triangulated\n";
3673       return 1;
3674     }
3675
3676     aPObject = new MyPArrayObject (aTris);
3677     ViewerTest::Display (aName, aPObject);
3678     return 0;
3679   }
3680   else if (anArrayType == "-patch"
3681         || anArrayType == "-modify"
3682         || anArrayType == "-edit")
3683   {
3684     if (argc >= 3)
3685     {
3686       anArrayType = argv[anArgIndex++];
3687       anArrayType.LowerCase();
3688     }
3689
3690     if (GetMapOfAIS().IsBound2 (aName))
3691     {
3692       aPObject = Handle(MyPArrayObject)::DownCast (GetMapOfAIS().Find2 (aName));
3693     }
3694     if (aPObject.IsNull())
3695     {
3696       std::cout << "Syntax error: object '" << aName << "' cannot be found\n";
3697       return 1;
3698     }
3699   }
3700
3701   Standard_Boolean hasVertex = Standard_False;
3702
3703   Graphic3d_TypeOfPrimitiveArray aPrimType = Graphic3d_TOPA_UNDEFINED;
3704   if (anArrayType == "points")
3705   {
3706     aPrimType = Graphic3d_TOPA_POINTS;
3707   }
3708   else if (anArrayType == "segments")
3709   {
3710     aPrimType = Graphic3d_TOPA_SEGMENTS;
3711   }
3712   else if (anArrayType == "polylines")
3713   {
3714     aPrimType = Graphic3d_TOPA_POLYLINES;
3715   }
3716   else if (anArrayType == "triangles")
3717   {
3718     aPrimType = Graphic3d_TOPA_TRIANGLES;
3719   }
3720   else if (anArrayType == "trianglefans")
3721   {
3722     aPrimType = Graphic3d_TOPA_TRIANGLEFANS;
3723   }
3724   else if (anArrayType == "trianglestrips")
3725   {
3726     aPrimType = Graphic3d_TOPA_TRIANGLESTRIPS;
3727   }
3728   else if (anArrayType == "quads")
3729   {
3730     aPrimType = Graphic3d_TOPA_QUADRANGLES;
3731   }
3732   else if (anArrayType == "quadstrips")
3733   {
3734     aPrimType = Graphic3d_TOPA_QUADRANGLESTRIPS;
3735   }
3736   else if (anArrayType == "polygons")
3737   {
3738     aPrimType = Graphic3d_TOPA_POLYGONS;
3739   }
3740   if (aPrimType == Graphic3d_TOPA_UNDEFINED)
3741   {
3742     std::cout << "Syntax error: unexpected type of primitives array\n";
3743     return 1;
3744   }
3745
3746   Standard_Integer aLowerArg = anArgIndex;
3747   Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 3);
3748   for (; anArgIndex < argc; ++anArgIndex)
3749   {
3750     TCollection_AsciiString aCommand (argv[anArgIndex]);
3751     aCommand.LowerCase();
3752     if (!aCommand.IsAscii())
3753     {
3754       di << "Unexpected argument: #" << anArgIndex - 1 << " , "
3755          << "should be an array element: 'v', 'b', 'e' \n";
3756       break;
3757     }
3758
3759     if (aCommand == "v")
3760     {
3761       hasVertex = Standard_True;
3762     }
3763
3764     anArgsArray->SetValue (anArgIndex - aLowerArg, aCommand);
3765   }
3766
3767   if (!hasVertex)
3768   {
3769     di << "You should pass any verticies in the list of array elements\n";
3770     return 1;
3771   }
3772
3773   Handle(Graphic3d_AspectMarker3d)    anAspPoints;
3774   if (aPrimType == Graphic3d_TOPA_POINTS)
3775   {
3776     anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3777   }
3778
3779   // create primitives array object
3780   if (aPObject.IsNull())
3781   {
3782     // register the object in map
3783     aPObject = new MyPArrayObject (aPrimType, anArgsArray, anAspPoints);
3784     VDisplayAISObject (aName, aPObject);
3785   }
3786   else
3787   {
3788     aPObject->Init (aPrimType, anArgsArray, anAspPoints, Standard_True);
3789     ViewerTest::CurrentView()->Redraw();
3790   }
3791   return 0;
3792 }
3793
3794 namespace
3795 {
3796   //! Auxiliary function for parsing translation vector - either 2D or 3D.
3797   static Standard_Integer parseTranslationVec (Standard_Integer theArgNb,
3798                                                const char**     theArgVec,
3799                                                gp_Vec&          theVec)
3800   {
3801     if (theArgNb < 2)
3802     {
3803       return 0;
3804     }
3805
3806     TCollection_AsciiString anX (theArgVec[0]);
3807     TCollection_AsciiString anY (theArgVec[1]);
3808     if (!anX.IsRealValue()
3809      || !anY.IsRealValue())
3810     {
3811       return 0;
3812     }
3813
3814     theVec.SetX (anX.RealValue());
3815     theVec.SetY (anY.RealValue());
3816     if (theArgNb >= 3)
3817     {
3818       TCollection_AsciiString anZ (theArgVec[2]);
3819       if (anZ.IsRealValue())
3820       {
3821         theVec.SetZ (anZ.RealValue());
3822         return 3;
3823       }
3824     }
3825     return 2;
3826   }
3827 }
3828
3829 //=======================================================================
3830 //function : VSetLocation
3831 //purpose  : Change location of AIS interactive object
3832 //=======================================================================
3833
3834 static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
3835                                       Standard_Integer  theArgNb,
3836                                       const char**      theArgVec)
3837 {
3838   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3839   ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3840   if (aContext.IsNull())
3841   {
3842     std::cout << "Error: no active view!\n";
3843     return 1;
3844   }
3845
3846   Standard_Boolean toPrintInfo = Standard_True;
3847   Handle(AIS_InteractiveObject) anObj;
3848   TCollection_AsciiString aCmdName (theArgVec[0]);
3849   aCmdName.LowerCase();
3850   for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3851   {
3852     TCollection_AsciiString anArg = theArgVec[anArgIter];
3853     anArg.LowerCase();
3854     if (anUpdateTool.parseRedrawMode (anArg))
3855     {
3856       continue;
3857     }
3858     else if (anObj.IsNull())
3859     {
3860       const TCollection_AsciiString aName (theArgVec[anArgIter]);
3861       GetMapOfAIS().Find2 (aName, anObj);
3862       if (anObj.IsNull())
3863       {
3864         std::cout << "Error: object '" << aName << "' is not displayed!\n";
3865         return 1;
3866       }
3867     }
3868     else if (anArg == "-reset")
3869     {
3870       toPrintInfo = Standard_False;
3871       aContext->SetLocation (anObj, gp_Trsf());
3872     }
3873     else if (anArg == "-copyfrom"
3874           || anArg == "-copy")
3875     {
3876       if (anArgIter + 1 >= theArgNb)
3877       {
3878         std::cout << "Syntax error at '" << anArg << "'\n";
3879         return 1;
3880       }
3881
3882       const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]);
3883       Handle(AIS_InteractiveObject) anObj2;
3884       GetMapOfAIS().Find2 (aName2, anObj2);
3885       if (anObj2.IsNull())
3886       {
3887         std::cout << "Error: object '" << aName2 << "' is not displayed!\n";
3888         return 1;
3889       }
3890
3891       ++anArgIter;
3892       aContext->SetLocation (anObj, anObj2->LocalTransformation());
3893     }
3894     else if (anArg == "-rotate")
3895     {
3896       toPrintInfo = Standard_False;
3897       if (anArgIter + 7 >= theArgNb)
3898       {
3899         std::cout << "Syntax error at '" << anArg << "'\n";
3900         return 1;
3901       }
3902
3903       gp_Trsf aTrsf;
3904       aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]),
3905                                          Draw::Atof (theArgVec[anArgIter + 2]),
3906                                          Draw::Atof (theArgVec[anArgIter + 3])),
3907                                  gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]),
3908                                          Draw::Atof (theArgVec[anArgIter + 5]),
3909                                          Draw::Atof (theArgVec[anArgIter + 6]))),
3910                                          Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0));
3911       anArgIter += 7;
3912
3913       aTrsf = anObj->LocalTransformation() * aTrsf;
3914       aContext->SetLocation (anObj, aTrsf);
3915     }
3916     else if (anArg == "-translate")
3917     {
3918       toPrintInfo = Standard_False;
3919       gp_Vec aLocVec;
3920       Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
3921       anArgIter += aNbParsed;
3922       if (aNbParsed == 0)
3923       {
3924         std::cout << "Syntax error at '" << anArg << "'\n";
3925         return 1;
3926       }
3927
3928       gp_Trsf aTrsf;
3929       aTrsf.SetTranslationPart (aLocVec);
3930       aTrsf = anObj->LocalTransformation() * aTrsf;
3931       aContext->SetLocation (anObj, aTrsf);
3932     }
3933     else if (anArg == "-scale"
3934           || anArg == "-setscale")
3935     {
3936       toPrintInfo = Standard_False;
3937       gp_XYZ aScaleLoc;
3938       Standard_Real aScale = 1.0;
3939       Standard_Boolean toPrintScale = Standard_True;
3940       Standard_Boolean hasScaleLoc  = Standard_False;
3941       if (anArgIter + 4 < theArgNb)
3942       {
3943         TCollection_AsciiString aScaleArgs[4] =
3944         {
3945           TCollection_AsciiString (theArgVec[anArgIter + 1]),
3946           TCollection_AsciiString (theArgVec[anArgIter + 2]),
3947           TCollection_AsciiString (theArgVec[anArgIter + 3]),
3948           TCollection_AsciiString (theArgVec[anArgIter + 4])
3949         };
3950         Standard_Integer aScaleArgIter = 0;
3951         for (; aScaleArgIter < 4; ++aScaleArgIter)
3952         {
3953           if (!aScaleArgs[aScaleArgIter].IsRealValue())
3954           {
3955             break;
3956           }
3957         }
3958         if (aScaleArgIter == 4)
3959         {
3960           aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue());
3961           aScale = aScaleArgs[3].RealValue();
3962           anArgIter += 4;
3963           toPrintScale = Standard_False;
3964           hasScaleLoc  = Standard_True;
3965         }
3966         else if (aScaleArgIter >= 1)
3967         {
3968           aScale = aScaleArgs[0].RealValue();
3969           ++anArgIter;
3970           toPrintScale = Standard_False;
3971         }
3972       }
3973       else if (anArgIter + 1 < theArgNb)
3974       {
3975         TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]);
3976         if (aScaleArg.IsRealValue())
3977         {
3978           aScale = aScaleArg.RealValue();
3979           ++anArgIter;
3980           toPrintScale = Standard_False;
3981         }
3982       }
3983
3984       if (toPrintScale)
3985       {
3986         if (anArg == "-setscale")
3987         {
3988           std::cout << "Syntax error at '" << anArg << "'\n";
3989           return 1;
3990         }
3991
3992         char aText[1024];
3993         Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor());
3994         theDI << aText;
3995         continue;
3996       }
3997
3998       if (anArg == "-setscale")
3999       {
4000         gp_Trsf aTrsf = anObj->LocalTransformation();
4001         if (hasScaleLoc)
4002         {
4003           aTrsf.SetScale (aScaleLoc, aScale);
4004         }
4005         else
4006         {
4007           aTrsf.SetScaleFactor (aScale);
4008         }
4009         aContext->SetLocation (anObj, aTrsf);
4010       }
4011       else
4012       {
4013         gp_Trsf aTrsf;
4014         if (hasScaleLoc)
4015         {
4016           aTrsf.SetScale (aScaleLoc, aScale);
4017           aTrsf = anObj->LocalTransformation() * aTrsf;
4018         }
4019         else
4020         {
4021           aTrsf = anObj->LocalTransformation();
4022           aTrsf.SetScaleFactor (aTrsf.ScaleFactor() * aScale);
4023         }
4024         aContext->SetLocation (anObj, aTrsf);
4025       }
4026     }
4027     else if (anArg == "-mirror")
4028     {
4029       toPrintInfo = Standard_False;
4030       if (anArgIter + 6 >= theArgNb)
4031       {
4032         std::cout << "Syntax error at '" << anArg << "'\n";
4033         return 1;
4034       }
4035
4036       gp_Trsf aTrsf;
4037       aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
4038                                        Draw::Atof(theArgVec[theArgNb - 5]),
4039                                        Draw::Atof(theArgVec[theArgNb - 4])),
4040                                gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
4041                                        Draw::Atof(theArgVec[theArgNb - 2]),
4042                                        Draw::Atof(theArgVec[theArgNb - 1]))));
4043       anArgIter += 6;
4044       aTrsf = anObj->LocalTransformation() * aTrsf;
4045       aContext->SetLocation (anObj, aTrsf);
4046     }
4047     else if (anArg == "-setrotation"
4048           || anArg == "-rotation")
4049     {
4050       toPrintInfo = Standard_False;
4051       if (anArgIter + 4 < theArgNb)
4052       {
4053         TCollection_AsciiString aQuatArgs[4] =
4054         {
4055           TCollection_AsciiString (theArgVec[anArgIter + 1]),
4056           TCollection_AsciiString (theArgVec[anArgIter + 2]),
4057           TCollection_AsciiString (theArgVec[anArgIter + 3]),
4058           TCollection_AsciiString (theArgVec[anArgIter + 4])
4059         };
4060         Standard_Integer aQuatArgIter = 0;
4061         for (; aQuatArgIter < 4; ++aQuatArgIter)
4062         {
4063           if (!aQuatArgs[aQuatArgIter].IsRealValue())
4064           {
4065             break;
4066           }
4067         }
4068
4069         if (aQuatArgIter == 4)
4070         {
4071           anArgIter += 4;
4072           const gp_Quaternion aQuat (aQuatArgs[0].RealValue(),
4073                                      aQuatArgs[1].RealValue(),
4074                                      aQuatArgs[2].RealValue(),
4075                                      aQuatArgs[3].RealValue());
4076           gp_Trsf aTrsf = anObj->LocalTransformation();
4077           aTrsf.SetRotation (aQuat);
4078           aContext->SetLocation (anObj, aTrsf);
4079           continue;
4080         }
4081         else if (anArg == "-setrotation")
4082         {
4083           std::cout << "Syntax error at '" << anArg << "'\n";
4084           return 1;
4085         }
4086       }
4087
4088       char aText[1024];
4089       const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation();
4090       Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W());
4091       theDI << aText;
4092     }
4093     else if (anArg == "-setlocation"
4094           || anArg == "-location")
4095     {
4096       toPrintInfo = Standard_False;
4097       gp_Vec aLocVec;
4098       Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
4099       anArgIter += aNbParsed;
4100       if (aNbParsed != 0)
4101       {
4102         gp_Trsf aTrsf = anObj->LocalTransformation();
4103         aTrsf.SetTranslationPart (aLocVec);
4104         aContext->SetLocation (anObj, aTrsf);
4105       }
4106       else if (anArg == "-setlocation")
4107       {
4108         std::cout << "Syntax error at '" << anArg << "'\n";
4109         return 1;
4110       }
4111
4112       char aText[1024];
4113       const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart();
4114       Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z());
4115       theDI << aText;
4116     }
4117     else if (aCmdName == "vsetlocation")
4118     {
4119       // compatibility with old syntax
4120       gp_Vec aLocVec;
4121       Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec);
4122       if (aNbParsed == 0)
4123       {
4124         std::cout << "Syntax error at '" << anArg << "'\n";
4125         return 1;
4126       }
4127       anArgIter = anArgIter + aNbParsed - 1;
4128
4129       gp_Trsf aTrsf;
4130       aTrsf.SetTranslationPart (aLocVec);
4131       aContext->SetLocation (anObj, aTrsf);
4132       toPrintInfo = Standard_False;
4133     }
4134     else
4135     {
4136       std::cout << "Error: unknown argument '" << anArg << "'\n";
4137       return 1;
4138     }
4139   }
4140
4141   if (anObj.IsNull())
4142   {
4143     std::cout << "Syntax error - wrong number of arguments\n";
4144     return 1;
4145   }
4146   else if (!toPrintInfo)
4147   {
4148     return 0;
4149   }
4150
4151   const gp_Trsf       aTrsf = anObj->LocalTransformation();
4152   const gp_XYZ        aLoc  = aTrsf.TranslationPart();
4153   const gp_Quaternion aRot  = aTrsf.GetRotation();
4154   char aText[4096];
4155   Sprintf (aText, "Location: %g %g %g\n"
4156                   "Rotation: %g %g %g %g\n"
4157                   "Scale:    %g\n",
4158                   aLoc.X(), aLoc.Y(), aLoc.Z(),
4159                   aRot.X(), aRot.Y(), aRot.Z(), aRot.W(),
4160                   aTrsf.ScaleFactor());
4161   theDI << aText;
4162   return 0;
4163 }
4164
4165 //===============================================================================================
4166 //function : VConnect
4167 //purpose  : Creates and displays AIS_ConnectedInteractive object from input object and location 
4168 //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
4169 //===============================================================================================
4170
4171 static Standard_Integer VConnect (Draw_Interpretor& /*di*/, 
4172                                   Standard_Integer argc, 
4173                                   const char ** argv) 
4174 {
4175   // Check the viewer
4176   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4177   if (aContext.IsNull())
4178   {
4179     std::cout << "vconnect error : call vinit before\n";
4180     return 1; // TCL_ERROR
4181   }
4182   // Check argumnets 
4183   if (argc < 6)
4184   {
4185     std::cout << "vconnect error: expect at least 5 arguments\n";
4186     return 1; // TCL_ERROR
4187   }
4188
4189   // Get values
4190   Standard_Integer anArgIter = 1;
4191   TCollection_AsciiString aName (argv[anArgIter++]);
4192   Handle(AIS_MultipleConnectedInteractive) anOriginObject;
4193   TCollection_AsciiString aColorString (argv[argc-1]);
4194   Standard_CString aColorName = "";
4195   Standard_Boolean hasColor = Standard_False;
4196   if (aColorString.Search ("color=") != -1)
4197   {
4198     hasColor = Standard_True;
4199     aColorString.Remove (1, 6);
4200     aColorName = aColorString.ToCString();
4201   }
4202   Handle(AIS_InteractiveObject) anObject;
4203
4204   // AIS_MultipleConnectedInteractive
4205   const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
4206   for (Standard_Integer i = 5; i < aNbShapes; ++i)
4207   {
4208     TCollection_AsciiString anOriginObjectName (argv[i]);
4209     if (aName.IsEqual (anOriginObjectName))
4210     {
4211       std::cout << "vconnect error: equal names for connected objects\n";
4212       continue;
4213     }
4214     if (GetMapOfAIS().Find2 (anOriginObjectName, anObject))
4215     {
4216       if (anObject.IsNull())
4217       {
4218         std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4219         continue;
4220       }
4221     }
4222     else
4223     {
4224       Standard_CString aOriginName = anOriginObjectName.ToCString();
4225       TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4226       if (aTDShape.IsNull())
4227       {
4228         std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4229         continue;
4230       }
4231       anObject = new AIS_Shape (aTDShape);
4232       aContext->Load (anObject);
4233       anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
4234     }
4235
4236     if (anOriginObject.IsNull())
4237     {
4238       anOriginObject = new AIS_MultipleConnectedInteractive();
4239     }
4240
4241     anOriginObject->Connect (anObject);
4242   }
4243   if (anOriginObject.IsNull())
4244   {
4245     std::cout << "vconect error : can't connect input objects\n";
4246     return 1; // TCL_ERROR
4247   }
4248
4249   // Get location data
4250   Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4251   Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4252   Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4253
4254   // Create transformation
4255   gp_Vec aTranslation (aXo, aYo, aZo);
4256
4257   gp_Trsf aTrsf; 
4258   aTrsf.SetTranslationPart (aTranslation);
4259   TopLoc_Location aLocation (aTrsf);
4260
4261   anOriginObject->SetLocalTransformation (aTrsf);
4262
4263   // Check if there is another object with given name
4264   // and remove it from context
4265   Handle(AIS_InteractiveObject) anObj;
4266   if (GetMapOfAIS().Find2 (aName, anObj))
4267   {
4268     TheAISContext()->Remove(anObj, Standard_False);
4269     GetMapOfAIS().UnBind2(aName);
4270   }
4271
4272   // Bind connected object to its name
4273   GetMapOfAIS().Bind (anOriginObject, aName);
4274
4275   // Display connected object
4276   TheAISContext()->Display (anOriginObject, Standard_True);
4277
4278   return 0;
4279 }
4280
4281 //===============================================================================================
4282 //function : VConnectTo
4283 //purpose  : Creates and displays AIS_ConnectedInteractive object from input object and location 
4284 //Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
4285 //===============================================================================================
4286
4287 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/, 
4288                                     Standard_Integer argc, 
4289                                     const char ** argv) 
4290 {
4291   // Check the viewer
4292   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4293   ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4294   if (aContext.IsNull())
4295   {
4296     std::cout << "vconnect error : call vinit before\n";
4297     return 1; // TCL_ERROR
4298   }
4299   // Check argumnets 
4300   if (argc != 6 && argc != 7)
4301   {
4302     std::cout << "vconnect error: expect at least 5 arguments\n";
4303     return 1; // TCL_ERROR
4304   }
4305
4306   // Get values
4307   Standard_Integer anArgIter = 1;
4308   TCollection_AsciiString aName (argv[anArgIter++]);
4309   Handle(AIS_InteractiveObject) anOriginObject;
4310
4311   TCollection_AsciiString anOriginObjectName(argv[5]);
4312   if (aName.IsEqual (anOriginObjectName))
4313   {
4314     std::cout << "vconnect error: equal names for connected objects\n"; 
4315     return 1; // TCL_ERROR
4316   }
4317   if (GetMapOfAIS().Find2 (anOriginObjectName, anOriginObject))
4318   {
4319     if (anOriginObject.IsNull())
4320     {
4321       std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4322       return 1; // TCL_ERROR
4323     }
4324   }
4325   else
4326   {
4327     Standard_CString aOriginName = anOriginObjectName.ToCString();
4328     TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4329     if (aTDShape.IsNull())
4330     {
4331       std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4332       return 1; // TCL_ERROR
4333     }
4334     anOriginObject = new AIS_Shape (aTDShape);
4335     GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
4336   }
4337  
4338   // Get location data
4339   Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4340   Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4341   Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4342
4343   // Create transformation
4344   gp_Vec aTranslation (aXo, aYo, aZo);
4345
4346   gp_Trsf aTrsf; 
4347   aTrsf.SetTranslationPart (aTranslation);
4348  
4349   Handle(AIS_ConnectedInteractive) aConnected;
4350
4351   aConnected = new AIS_ConnectedInteractive();
4352
4353   aConnected->Connect (anOriginObject, aTrsf);
4354
4355   // Check if there is another object with given name
4356   // and remove it from context
4357   Handle(AIS_InteractiveObject) anObj;
4358   if (GetMapOfAIS().Find2 (aName, anObj))
4359   {
4360     TheAISContext()->Remove (anObj, Standard_False);
4361     GetMapOfAIS().UnBind2(aName);
4362   }
4363
4364   // Bind connected object to its name
4365   GetMapOfAIS().Bind (aConnected, aName);
4366
4367   if (argc == 7)
4368   {
4369     TCollection_AsciiString anArg = argv[6];
4370     anArg.LowerCase();
4371     if (anArg == "-nodisplay")
4372       return 0;
4373
4374     if (!anUpdateTool.parseRedrawMode (anArg))
4375     {
4376       std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
4377     }
4378   }
4379
4380   // Display connected object
4381   TheAISContext()->Display (aConnected, Standard_False);
4382
4383   return 0;
4384 }
4385
4386 //=======================================================================
4387 //function : VDisconnect
4388 //purpose  :
4389 //=======================================================================
4390 static Standard_Integer VDisconnect (Draw_Interpretor& di,
4391                                      Standard_Integer argc,
4392                                      const char ** argv)
4393 {
4394   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4395   if (aContext.IsNull())
4396   {
4397     std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4398     return 1;
4399   }
4400   
4401   if (argc != 3)
4402   {
4403     std::cout << "ERROR : Usage : " << argv[0] << " name object\n";
4404     return 1;
4405   }
4406
4407   TCollection_AsciiString aName (argv[1]);
4408   TCollection_AsciiString anObject (argv[2]);
4409   Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
4410
4411   // find objects
4412   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4413   Handle(AIS_MultipleConnectedInteractive) anAssembly;
4414   if (!aMap.IsBound2 (aName) )
4415   {
4416     std::cout << "Use 'vdisplay' before\n";
4417     return 1;
4418   }
4419
4420   anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4421   if (anAssembly.IsNull())
4422   {
4423     di << "Not an assembly\n";
4424     return 1;
4425   }
4426
4427   Handle(AIS_InteractiveObject) anIObj;
4428   if (!aMap.Find2 (anObject, anIObj))
4429   {
4430     // try to interpret second argument as child number
4431     if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
4432     {
4433       Standard_Integer aCounter = 1;
4434       for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4435       {
4436         if (aCounter == anObjectNumber)
4437         {
4438           anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4439           break;
4440         }
4441         ++aCounter;
4442       }
4443     }
4444     else
4445     {
4446       std::cout << "Use 'vdisplay' before\n";
4447       return 1;
4448     }    
4449   }
4450
4451   aContext->Disconnect (anAssembly, anIObj);
4452   aContext->UpdateCurrentViewer();
4453   return 0;
4454 }
4455
4456 //=======================================================================
4457 //function : VAddConnected
4458 //purpose  :
4459 //=======================================================================
4460 static Standard_Integer VAddConnected (Draw_Interpretor& di,
4461                                        Standard_Integer argc,
4462                                        const char ** argv)
4463 {
4464   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4465   if (aContext.IsNull())
4466   {
4467     std::cout << argv[0] << "error : use 'vinit' command before \n";
4468     return 1;
4469   }
4470   
4471   if (argc != 6)
4472   {
4473     std::cout << argv[0] << " error: expect 5 arguments\n";
4474     return 1;
4475   }
4476
4477   TCollection_AsciiString aName (argv[1]);
4478   TCollection_AsciiString anObject (argv[5]);
4479   Standard_Real aX = Draw::Atof (argv[2]);
4480   Standard_Real aY = Draw::Atof (argv[3]);
4481   Standard_Real aZ = Draw::Atof (argv[4]);
4482
4483   // find object
4484   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4485   Handle(AIS_MultipleConnectedInteractive) anAssembly;
4486   if (!aMap.IsBound2 (aName) )
4487   {
4488     std::cout << "Use 'vdisplay' before\n";
4489     return 1;
4490   }
4491
4492   anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4493   if (anAssembly.IsNull())
4494   {
4495     di << "Not an assembly\n";
4496     return 1;
4497   }
4498
4499   Handle(AIS_InteractiveObject) anIObj;
4500   if (!aMap.Find2 (anObject, anIObj))
4501   {
4502       std::cout << "Use 'vdisplay' before\n";
4503       return 1; 
4504   }
4505
4506   gp_Trsf aTrsf;
4507   aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4508  
4509   anAssembly->Connect (anIObj, aTrsf);
4510   TheAISContext()->Display (anAssembly, Standard_False);
4511   TheAISContext()->RecomputeSelectionOnly (anAssembly);
4512   aContext->UpdateCurrentViewer();
4513
4514   return 0;
4515 }
4516
4517 //=======================================================================
4518 //function : VListConnected
4519 //purpose  :
4520 //=======================================================================
4521 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4522                                         Standard_Integer argc,
4523                                         const char ** argv)
4524 {
4525   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4526   if (aContext.IsNull())
4527   {
4528     std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4529     return 1;
4530   }
4531   
4532   if (argc != 2)
4533   {
4534     std::cout << "ERROR : Usage : " << argv[0] << " name\n";
4535     return 1;
4536   }
4537
4538   TCollection_AsciiString aName (argv[1]);
4539
4540   // find object
4541   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4542   Handle(AIS_MultipleConnectedInteractive) anAssembly;
4543   if (!aMap.IsBound2 (aName) )
4544   {
4545     std::cout << "Use 'vdisplay' before\n";
4546     return 1;
4547   }
4548
4549   anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4550   if (anAssembly.IsNull())
4551   {
4552     std::cout << "Not an assembly\n";
4553     return 1;
4554   }
4555
4556   std::cout << "Children of " << aName << ":\n";
4557
4558   Standard_Integer aCounter = 1;
4559   for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4560   {
4561     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4562     if (GetMapOfAIS().IsBound1 (anObj))
4563     {
4564       TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anObj);
4565       std::cout << aCounter << ")  " << aCuurrentName << "    (" << anIter.Value()->DynamicType()->Name() << ")";
4566     }
4567
4568     std::cout << aCounter << ")  " << anIter.Value()->DynamicType()->Name();
4569
4570     Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4571     if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4572     {
4573       std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4574     }
4575     std::cout << std::endl;
4576     
4577     ++aCounter;
4578   }
4579
4580   return 0;
4581 }
4582
4583 //===============================================================================================
4584 //function : VSetSelectionMode
4585 //purpose  : vselmode
4586 //===============================================================================================
4587 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4588                                            Standard_Integer  theNbArgs,
4589                                            const char**      theArgv)
4590 {
4591   // Check errors
4592   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4593   if (anAISContext.IsNull())
4594   {
4595     std::cout << "Error: no active Viewer\n";
4596     return 1;
4597   }
4598
4599   NCollection_Sequence<TCollection_AsciiString> anObjNames;
4600   Standard_Integer aSelectionMode = -1;
4601   Standard_Boolean toTurnOn = Standard_True;
4602   AIS_SelectionModesConcurrency aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4603   for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4604   {
4605     TCollection_AsciiString anArgCase (theArgv[anArgIter]);
4606     anArgCase.LowerCase();
4607     if (anArgCase == "-set"
4608      || anArgCase == "-replace"
4609      || anArgCase == "-single"
4610      || anArgCase == "-exclusive")
4611     {
4612       aSelModeConcurrency = AIS_SelectionModesConcurrency_Single;
4613     }
4614     else if (anArgCase == "-add"
4615           || anArgCase == "-combine"
4616           || anArgCase == "-combination"
4617           || anArgCase == "-multiple")
4618     {
4619       aSelModeConcurrency = AIS_SelectionModesConcurrency_Multiple;
4620     }
4621     else if (anArgCase == "-globalorlocal"
4622           || anArgCase == "-localorglobal")
4623     {
4624       aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4625     }
4626     else
4627     {
4628       anObjNames.Append (theArgv[anArgIter]);
4629     }
4630   }
4631   if (anObjNames.Size() < 2
4632   || !ViewerTest::ParseOnOff (anObjNames.Last().ToCString(), toTurnOn))
4633   {
4634     std::cout << "Syntax error: wrong number of arguments\n";
4635     return 1;
4636   }
4637   anObjNames.Remove (anObjNames.Upper());
4638   {
4639     const TCollection_AsciiString aSelModeString = anObjNames.Last();
4640     anObjNames.Remove (anObjNames.Upper());
4641     TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4642     if (aSelModeString.IsIntegerValue())
4643     {
4644       aSelectionMode = aSelModeString.IntegerValue();
4645     }
4646     else if (TopAbs::ShapeTypeFromString (aSelModeString.ToCString(), aShapeType))
4647     {
4648       aSelectionMode = AIS_Shape::SelectionMode (aShapeType);
4649     }
4650     else
4651     {
4652       std::cout << "Syntax error: unknown selection mode '" << aSelModeString  << "'\n";
4653       return 1;
4654     }
4655   }
4656
4657   AIS_ListOfInteractive aTargetIOs;
4658   for (NCollection_Sequence<TCollection_AsciiString>::Iterator anObjIter (anObjNames); anObjIter.More(); anObjIter.Next())
4659   {
4660     const TCollection_AsciiString& aNameIO = anObjIter.Value();
4661     Handle(AIS_InteractiveObject) anIO;
4662     GetMapOfAIS().Find2 (aNameIO, anIO);
4663     if (anIO.IsNull())
4664     {
4665       std::cout << "Syntax error: undefined presentable object " << aNameIO << "\n";
4666       return 1;
4667     }
4668     aTargetIOs.Append (anIO);
4669   }
4670   if (aTargetIOs.IsEmpty())
4671   {
4672     anAISContext->DisplayedObjects (aTargetIOs);
4673   }
4674
4675   for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4676   {
4677     const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4678     anAISContext->SetSelectionModeActive (anIO, aSelectionMode, toTurnOn, aSelModeConcurrency);
4679   }
4680   return 0;
4681 }
4682
4683 //===============================================================================================
4684 //function : VSelectionNext
4685 //purpose  : 
4686 //===============================================================================================
4687 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4688                                  Standard_Integer /*theArgsNb*/,
4689                                  const char** /*theArgVec*/)
4690 {
4691   // Check errors
4692   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4693   Handle(V3d_View) aView = ViewerTest::CurrentView();
4694
4695   if (anAISContext.IsNull())
4696   {
4697     std::cerr << "Call vinit before!" << std::endl;
4698     return 1;
4699   }
4700
4701   anAISContext->HilightNextDetected (aView);
4702   return 0;
4703 }
4704
4705 //===============================================================================================
4706 //function : VSelectionPrevious
4707 //purpose  : 
4708 //===============================================================================================
4709 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4710                                  Standard_Integer /*theArgsNb*/,
4711                                  const char** /*theArgVec*/)
4712 {
4713   // Check errors
4714   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4715   Handle(V3d_View) aView = ViewerTest::CurrentView();
4716
4717   if (anAISContext.IsNull())
4718   {
4719     std::cerr << "Call vinit before!" << std::endl;
4720     return 1;
4721   }
4722
4723   anAISContext->HilightPreviousDetected (aView);
4724   return 0;
4725 }
4726
4727 //===========================================================================
4728 //function : VTriangle 
4729 //Draw arg : vtriangle Name PointName PointName PointName
4730 //purpose  : creates and displays Triangle
4731 //===========================================================================
4732 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4733                                    Standard_Integer argc,
4734                                    const char ** argv)
4735 {
4736   const Standard_Boolean isTri = TCollection_AsciiString (argv[0]) == "vtriangle";
4737   Handle(Graphic3d_ArrayOfPrimitives) aPrims;
4738   if (isTri)
4739   {
4740     aPrims = new Graphic3d_ArrayOfTriangles (3);
4741   }
4742   else
4743   {
4744     aPrims = new Graphic3d_ArrayOfSegments (2);
4745   }
4746
4747   if (argc != (2 + aPrims->VertexNumberAllocated()))
4748   {
4749     std::cout << "Syntax error: wrong number of arguments\n";
4750     return 1;
4751   }
4752
4753   gp_Pnt aPnts[3];
4754   for (Standard_Integer aPntIter = 0; aPntIter < aPrims->VertexNumberAllocated(); ++aPntIter)
4755   {
4756     const TCollection_AsciiString aName (argv[2 + aPntIter]);
4757     if (Handle(AIS_Point) aPntPrs = Handle(AIS_Point)::DownCast (GetMapOfAIS().IsBound2 (aName) ? GetMapOfAIS().Find2 (aName) : NULL))
4758     {
4759       aPnts[aPntIter] = aPntPrs->Component()->Pnt();
4760     }
4761     else
4762     {
4763       TopoDS_Shape aShape = DBRep::Get (argv[2 + aPntIter]);
4764       if (aShape.IsNull()
4765        || aShape.ShapeType() != TopAbs_VERTEX)
4766       {
4767         std::cout << "Syntax error: argument " << aName << " must be a point\n";
4768         return 1;
4769       }
4770       aPnts[aPntIter] = BRep_Tool::Pnt (TopoDS::Vertex (aShape));
4771     }
4772
4773     for (Standard_Integer aPnt2Iter = 0; aPnt2Iter < aPntIter; ++aPnt2Iter)
4774     {
4775       if (aPnts[aPnt2Iter].IsEqual (aPnts[aPntIter], Precision::Confusion()))
4776       {
4777         std::cout << "Syntax error: points should not be equal\n";
4778         return 1;
4779       }
4780     }
4781
4782     aPrims->AddVertex (aPnts[aPntIter]);
4783   }
4784
4785   Handle(AIS_InteractiveObject) aPrs = new MyPArrayObject (aPrims);
4786   if (!isTri)
4787   {
4788     aPrs->Attributes()->SetupOwnShadingAspect();
4789     aPrs->Attributes()->ShadingAspect()->Aspect()->SetColor (aPrs->Attributes()->LineAspect()->Aspect()->Color());
4790   }
4791   ViewerTest::Display (argv[1], aPrs);
4792   return 0;
4793 }
4794
4795 //=======================================================================
4796 //function : VObjZLayer
4797 //purpose  : Set or get z layer id for presentable object
4798 //=======================================================================
4799
4800 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4801                                     Standard_Integer argc,
4802                                     const char ** argv)
4803 {
4804   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4805   if (aContext.IsNull())
4806   {
4807     di << argv[0] << "Call 'vinit' before!\n";
4808     return 1;
4809   }
4810
4811   // get operation
4812   TCollection_AsciiString aOperation;
4813   if (argc >= 2)
4814     aOperation = TCollection_AsciiString (argv [1]);
4815
4816   // check for correct arguments
4817   if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4818       !(argc == 3 && aOperation.IsEqual ("get")))
4819   {
4820     di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4821     di << " set - set layer id for interactive object, layerid - z layer id\n";
4822     di << " get - get layer id of interactive object\n";
4823     di << " argument layerid should be passed for set operation only\n";
4824     return 1;
4825   }
4826
4827   // find object
4828   TCollection_AsciiString aName (argv[2]);
4829   Handle(AIS_InteractiveObject) anInterObj;
4830   GetMapOfAIS().Find2 (aName, anInterObj);
4831   if (anInterObj.IsNull())
4832   {
4833     std::cout << "Syntax error: object '" << aName << "' is not displayed\n";
4834     return 1;
4835   }
4836
4837   // process operation
4838   if (aOperation.IsEqual ("set"))
4839   {
4840     Standard_Integer aLayerId = Draw::Atoi (argv [3]);
4841     aContext->SetZLayer (anInterObj, aLayerId);
4842   }
4843   else if (aOperation.IsEqual ("get"))
4844   {
4845     di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4846   }
4847   
4848   return 0;
4849 }
4850
4851 //=======================================================================
4852 //function : VPolygonOffset
4853 //purpose  : Set or get polygon offset parameters
4854 //=======================================================================
4855 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
4856                                        Standard_Integer argc,
4857                                        const char ** argv)
4858 {
4859   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4860   if (aContext.IsNull())
4861   {
4862     std::cout << argv[0] << " Call 'vinit' before!\n";
4863     return 1;
4864   }
4865
4866   if (argc > 2 && argc != 5)
4867   {
4868     std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4869       "without arguments prints the default values" << std::endl;
4870     return 1;
4871   }
4872
4873   // find object
4874   Handle(AIS_InteractiveObject) anInterObj;
4875   if (argc >= 2)
4876   {
4877     TCollection_AsciiString aName (argv[1]);
4878     if (!GetMapOfAIS().Find2 (aName, anInterObj)
4879       || anInterObj.IsNull())
4880     {
4881       std::cout << "Syntax error: object '" << aName << "' is not displayed\n";
4882       return 1;
4883     }
4884   }
4885
4886   Standard_Integer aMode;
4887   Standard_ShortReal    aFactor, aUnits;
4888   if (argc == 5)
4889   {
4890     aMode   = Draw::Atoi(argv[2]);
4891     aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4892     aUnits  = (Standard_ShortReal) Draw::Atof(argv[4]);
4893
4894     anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4895     aContext->UpdateCurrentViewer();
4896     return 0;
4897   }
4898   else if (argc == 2)
4899   {
4900     if (anInterObj->HasPolygonOffsets())
4901     {
4902       anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4903       std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4904       std::cout << "\tMode: "   << aMode   << std::endl;
4905       std::cout << "\tFactor: " << aFactor << std::endl;
4906       std::cout << "\tUnits: "  << aUnits  << std::endl;
4907       return 0;
4908     }
4909     else
4910     {
4911       std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4912     }
4913   }
4914
4915   std::cout << "Default polygon offset parameters:" << std::endl;
4916   aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4917   std::cout << "\tMode: "   << aMode   << std::endl;
4918   std::cout << "\tFactor: " << aFactor << std::endl;
4919   std::cout << "\tUnits: "  << aUnits  << std::endl;
4920
4921   return 0;
4922 }
4923
4924 // This class is used for testing markers.
4925 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
4926 {
4927
4928 public:
4929
4930   ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
4931                                  const Standard_Integer& thePointsOnSide,
4932                                  Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
4933   {
4934     myStartPoint = theStartPoint;
4935     myPointsOnSide = thePointsOnSide;
4936     myMarkerAspect = theMarkerAspect;
4937   }
4938
4939   DEFINE_STANDARD_RTTI_INLINE(ViewerTest_MarkersArrayObject,AIS_InteractiveObject);
4940
4941 private:
4942
4943   void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
4944                 const Handle(Prs3d_Presentation)& aPresentation,
4945                 const Standard_Integer aMode) Standard_OVERRIDE;
4946
4947   void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4948                          const Standard_Integer /*theMode*/) Standard_OVERRIDE;
4949
4950 protected:
4951
4952   gp_XYZ myStartPoint;
4953   Standard_Integer myPointsOnSide;
4954   Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
4955 };
4956
4957
4958 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
4959                               const Handle(Prs3d_Presentation)& aPresentation,
4960                               const Standard_Integer /*aMode*/)
4961 {
4962   Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
4963   if (myPointsOnSide == 1)
4964   {
4965     anArray->AddVertex (myStartPoint);
4966   }
4967   else
4968   {
4969     for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4970     {
4971       for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4972       {
4973         for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4974         {
4975           anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4976           anArray->SetVertexColor (anArray->VertexNumber(),
4977                                    i / myPointsOnSide,
4978                                    j / myPointsOnSide,
4979                                    k / myPointsOnSide);
4980         }
4981       }
4982     }
4983   }
4984
4985   aPresentation->Clear();
4986   if (!myMarkerAspect.IsNull())
4987   {
4988     Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
4989   }
4990   Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
4991 }
4992
4993 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4994                                        const Standard_Integer /*theMode*/)
4995 {
4996   Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
4997
4998   if (myPointsOnSide == 1)
4999   {
5000     gp_Pnt aPoint (myStartPoint);
5001     Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5002     theSelection->Add (aSensetivePoint);
5003   }
5004   else
5005   {
5006     for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5007     {
5008       for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5009       {
5010         for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5011         {
5012           gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5013           Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5014           theSelection->Add (aSensetivePoint);
5015         }
5016       }
5017     }
5018   }
5019 }
5020 //=======================================================================
5021 //function : VMarkersTest
5022 //purpose  : Draws an array of markers for testing purposes.
5023 //=======================================================================
5024 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5025                                       Standard_Integer  theArgNb,
5026                                       const char**      theArgVec)
5027 {
5028   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5029   if (aContext.IsNull())
5030   {
5031     std::cerr << "Call 'vinit' before!\n";
5032     return 1;
5033   }
5034
5035   if (theArgNb < 5)
5036   {
5037     std::cerr << "Usage :\n " << theArgVec[0]
5038               << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5039     return 1;
5040   }
5041
5042   Standard_Integer anArgIter = 1;
5043
5044   TCollection_AsciiString aName (theArgVec[anArgIter++]);
5045   TCollection_AsciiString aFileName;
5046   gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5047                Atof (theArgVec[anArgIter + 1]),
5048                Atof (theArgVec[anArgIter + 2]));
5049   anArgIter += 3;
5050
5051   Standard_Integer aPointsOnSide = 10;
5052   Standard_Integer aMarkerType   = -1;
5053   Standard_Real    aScale        = 1.0;
5054   for (; anArgIter < theArgNb; ++anArgIter)
5055   {
5056     const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5057     if (anArg.Search ("PointsOnSide=") > -1)
5058     {
5059       aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5060     }
5061     else if (anArg.Search ("MarkerType=") > -1)
5062     {
5063       aMarkerType = anArg.Token ("=", 2).IntegerValue();
5064     }
5065     else if (anArg.Search ("Scale=") > -1)
5066     {
5067       aScale = anArg.Token ("=", 2).RealValue();
5068     }
5069     else if (anArg.Search ("FileName=") > -1)
5070     {
5071       aFileName = anArg.Token ("=", 2);
5072     }
5073     else
5074     {
5075       std::cerr << "Wrong argument: " << anArg << "\n";
5076       return 1;
5077     }
5078   }
5079
5080   Handle(Graphic3d_AspectMarker3d) anAspect;
5081   Handle(Image_AlienPixMap) anImage;
5082   Quantity_Color aColor (Quantity_NOC_GREEN1);
5083   if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5084    && !aFileName.IsEmpty())
5085   {
5086     anImage = new Image_AlienPixMap();
5087     if (!anImage->Load (aFileName))
5088     {
5089       std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5090       return 1;
5091     }
5092     if (anImage->Format() == Image_Format_Gray)
5093     {
5094       anImage->SetFormat (Image_Format_Alpha);
5095     }
5096     else if (anImage->Format() == Image_Format_GrayF)
5097     {
5098       anImage->SetFormat (Image_Format_AlphaF);
5099     }
5100     anAspect = new Graphic3d_AspectMarker3d (anImage);
5101   }
5102   else
5103   {
5104     anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5105   }
5106
5107   Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5108   VDisplayAISObject (aName, aMarkersArray);
5109
5110   return 0;
5111 }
5112
5113 //=======================================================================
5114 //function : TextToBrep
5115 //purpose  : Tool for conversion text to occt-shapes
5116 //=======================================================================
5117 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5118                        Standard_Integer  theArgNb,
5119                        const char**      theArgVec)
5120 {
5121   // Check arguments
5122   if (theArgNb < 3)
5123   {
5124     std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5125     return 1;
5126   }
5127
5128   Standard_Integer anArgIt = 1;
5129   Standard_CString aName   = theArgVec[anArgIt++];
5130   Standard_CString aText   = theArgVec[anArgIt++];
5131
5132   Font_BRepFont           aFont;
5133   TCollection_AsciiString aFontName ("Courier");
5134   Standard_Real           aTextHeight        = 16.0;
5135   Font_FontAspect         aFontAspect        = Font_FA_Regular;
5136   Standard_Boolean        anIsCompositeCurve = Standard_False;
5137   gp_Ax3                  aPenAx3    (gp::XOY());
5138   gp_Dir                  aNormal    (0.0, 0.0, 1.0);
5139   gp_Dir                  aDirection (1.0, 0.0, 0.0);
5140   gp_Pnt                  aPenLoc;
5141
5142   Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT;
5143   Graphic3d_VerticalTextAlignment   aVJustification = Graphic3d_VTA_BOTTOM;
5144
5145   for (; anArgIt < theArgNb; ++anArgIt)
5146   {
5147     TCollection_AsciiString aParam (theArgVec[anArgIt]);
5148     aParam.LowerCase();
5149
5150     if (aParam == "-pos"
5151      || aParam == "-position")
5152     {
5153       if (anArgIt + 3 >= theArgNb)
5154       {
5155         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5156         return 1;
5157       }
5158
5159       aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt]));
5160       aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt]));
5161       aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt]));
5162     }
5163     else if (aParam == "-halign")
5164     {
5165       if (++anArgIt >= theArgNb)
5166       {
5167         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5168         return 1;
5169       }
5170
5171       TCollection_AsciiString aType (theArgVec[anArgIt]);
5172       aType.LowerCase();
5173       if (aType == "left")
5174       {
5175         aHJustification = Graphic3d_HTA_LEFT;
5176       }
5177       else if (aType == "center")
5178       {
5179         aHJustification = Graphic3d_HTA_CENTER;
5180       }
5181       else if (aType == "right")
5182       {
5183         aHJustification = Graphic3d_HTA_RIGHT;
5184       }
5185       else
5186       {
5187         std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5188         return 1;
5189       }
5190     }
5191     else if (aParam == "-valign")
5192     {
5193       if (++anArgIt >= theArgNb)
5194       {
5195         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5196         return 1;
5197       }
5198
5199       TCollection_AsciiString aType (theArgVec[anArgIt]);
5200       aType.LowerCase();
5201       if (aType == "top")
5202       {
5203         aVJustification = Graphic3d_VTA_TOP;
5204       }
5205       else if (aType == "center")
5206       {
5207         aVJustification = Graphic3d_VTA_CENTER;
5208       }
5209       else if (aType == "bottom")
5210       {
5211         aVJustification = Graphic3d_VTA_BOTTOM;
5212       }
5213       else if (aType == "topfirstline")
5214       {
5215         aVJustification = Graphic3d_VTA_TOPFIRSTLINE;
5216       }
5217       else
5218       {
5219         std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5220         return 1;
5221       }
5222     }
5223     else if (aParam == "-height")
5224     {
5225       if (++anArgIt >= theArgNb)
5226       {
5227         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5228         return 1;
5229       }
5230
5231       aTextHeight = Draw::Atof(theArgVec[anArgIt]);
5232     }
5233     else if (aParam == "-aspect")
5234     {
5235       if (++anArgIt >= theArgNb)
5236       {
5237         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5238         return 1;
5239       }
5240
5241       TCollection_AsciiString anOption (theArgVec[anArgIt]);
5242       anOption.LowerCase();
5243       if (!parseFontStyle (anOption, aFontAspect))
5244       {
5245         std::cout << "Error: unknown font aspect '" << anOption << "'.\n";
5246         return 1;
5247       }
5248     }
5249     else if (aParam == "-font")
5250     {
5251       if (++anArgIt >= theArgNb)
5252       {
5253         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5254         return 1;
5255       }
5256
5257       aFontName = theArgVec[anArgIt];
5258     }
5259     else if (aParam == "-composite")
5260     {
5261       if (++anArgIt >= theArgNb)
5262       {
5263         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5264         return 1;
5265       }
5266
5267       ViewerTest::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve);
5268     }
5269     else if (aParam == "-plane")
5270     {
5271       if (anArgIt + 6 >= theArgNb)
5272       {
5273         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5274         return 1;
5275       }
5276
5277       Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
5278       Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
5279       Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
5280       aNormal.SetCoord (aX, aY, aZ);
5281
5282       aX = Draw::Atof (theArgVec[++anArgIt]);
5283       aY = Draw::Atof (theArgVec[++anArgIt]);
5284       aZ = Draw::Atof (theArgVec[++anArgIt]);
5285       aDirection.SetCoord (aX, aY, aZ);
5286     }
5287     else
5288     {
5289       std::cerr << "Warning! Unknown argument '" << aParam << "'\n";
5290     }
5291   }
5292
5293   aFont.SetCompositeCurveMode (anIsCompositeCurve);
5294   if (!aFont.Init (aFontName.ToCString(), aFontAspect, aTextHeight))
5295   {
5296     std::cerr << "Font initialization error\n";
5297     return 1;
5298   }
5299
5300   aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection);
5301
5302   Font_BRepTextBuilder aBuilder;
5303   DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification));
5304   return 0;
5305 }
5306
5307 //=======================================================================
5308 //function : VFont
5309 //purpose  : Font management
5310 //=======================================================================
5311
5312 static int VFont (Draw_Interpretor& theDI,
5313                   Standard_Integer  theArgNb,
5314                   const char**      theArgVec)
5315 {
5316   Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5317   if (theArgNb < 2)
5318   {
5319     // just print the list of available fonts
5320     Standard_Boolean isFirst = Standard_True;
5321     const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts();
5322     for (Font_NListOfSystemFont::Iterator anIter (aFonts); anIter.More(); anIter.Next())
5323     {
5324       const Handle(Font_SystemFont)& aFont = anIter.Value();
5325       if (!isFirst)
5326       {
5327         theDI << "\n";
5328       }
5329
5330       theDI << aFont->ToString();
5331       isFirst = Standard_False;
5332     }
5333     return 0;
5334   }
5335
5336   for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5337   {
5338     const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5339     TCollection_AsciiString anArgCase (anArg);
5340     anArgCase.LowerCase();
5341     if (anArgIter + 1 < theArgNb
5342      && (anArgCase == "-find"
5343       || anArgCase == "find"))
5344     {
5345       Standard_CString aFontName   = theArgVec[++anArgIter];
5346       Font_FontAspect  aFontAspect = Font_FA_Undefined;
5347       if (++anArgIter < theArgNb)
5348       {
5349         anArgCase = theArgVec[anArgIter];
5350         anArgCase.LowerCase();
5351         if (!parseFontStyle (anArgCase, aFontAspect))
5352         {
5353           --anArgIter;
5354         }
5355       }
5356
5357       if (Handle(Font_SystemFont) aFont = aMgr->FindFont (aFontName, aFontAspect))
5358       {
5359         theDI << aFont->ToString();
5360       }
5361       else
5362       {
5363         std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5364       }
5365     }
5366     else if (anArgIter + 1 < theArgNb
5367           && (anArgCase == "-add"
5368            || anArgCase == "add"
5369            || anArgCase == "-register"
5370            || anArgCase == "register"))
5371     {
5372       ++anArgIter;
5373       Standard_CString aFontPath = theArgVec[anArgIter++];
5374       TCollection_AsciiString aFontName;
5375       Font_FontAspect  aFontAspect = Font_FA_Undefined;
5376       Standard_Integer isSingelStroke = -1;
5377       for (; anArgIter < theArgNb; ++anArgIter)
5378       {
5379         anArgCase = theArgVec[anArgIter];
5380         anArgCase.LowerCase();
5381         if (aFontAspect == Font_FontAspect_UNDEFINED
5382          && parseFontStyle (anArgCase, aFontAspect))
5383         {
5384           continue;
5385         }
5386         else if (anArgCase == "singlestroke"
5387               || anArgCase == "singleline"
5388               || anArgCase == "oneline")
5389         {
5390           isSingelStroke = 1;
5391         }
5392         else if (aFontName.IsEmpty())
5393         {
5394           aFontName = theArgVec[anArgIter];
5395         }
5396         else
5397         {
5398           --anArgIter;
5399           break;
5400         }
5401       }
5402
5403       Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5404       if (aFont.IsNull())
5405       {
5406         std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5407         continue;
5408       }
5409
5410       if (aFontAspect != Font_FontAspect_UNDEFINED
5411       || !aFontName.IsEmpty())
5412       {
5413         TCollection_AsciiString aName = aFont->FontName();
5414         if (!aFontName.IsEmpty())
5415         {
5416           aName = aFontName;
5417         }
5418         Handle(Font_SystemFont) aFont2 = new Font_SystemFont (aName);
5419         if (aFontAspect != Font_FontAspect_UNDEFINED)
5420         {
5421           aFont2->SetFontPath (aFontAspect, aFontPath);
5422         }
5423         else
5424         {
5425           for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
5426           {
5427             aFont2->SetFontPath ((Font_FontAspect )anAspectIter, aFont->FontPath ((Font_FontAspect )anAspectIter));
5428           }
5429         }
5430         aFont = aFont2;
5431       }
5432       if (isSingelStroke != -1)
5433       {
5434         aFont->SetSingleStrokeFont (isSingelStroke == 1);
5435       }
5436
5437       aMgr->RegisterFont (aFont, Standard_True);
5438       theDI << aFont->ToString();
5439     }
5440     else if (anArgCase == "-verbose"
5441           || anArgCase == "-trace")
5442     {
5443       bool toEnable = true;
5444       if (anArgIter + 1 < theArgNb
5445        && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
5446       {
5447         ++anArgIter;
5448       }
5449       aMgr->SetTraceAliases (toEnable);
5450     }
5451     else
5452     {
5453       std::cerr << "Warning! Unknown argument '" << anArg << "'\n";
5454     }
5455   }
5456
5457   return 0;
5458 }
5459
5460 //=======================================================================
5461 //function : VVertexMode
5462 //purpose  : Switches vertex display mode for AIS_Shape or displays the current value
5463 //=======================================================================
5464
5465 static int VVertexMode (Draw_Interpretor& theDI,
5466                          Standard_Integer  theArgNum,
5467                          const char**      theArgs)
5468 {
5469   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5470   if (aContext.IsNull())
5471   {
5472     std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5473     return 1;
5474   }
5475
5476   // No arguments --> print the current default vertex draw mode
5477   if (theArgNum == 1)
5478   {
5479     Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5480     theDI <<  "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5481     return 0;
5482   }
5483
5484   // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5485   TCollection_AsciiString aParam (theArgs[1]);
5486   if (aParam == "-set")
5487   {
5488     if (theArgNum == 2)
5489     {
5490       std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5491       std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5492       return 1;
5493     }
5494
5495     TCollection_AsciiString aModeStr (theArgs[2]);
5496     Prs3d_VertexDrawMode aNewMode =
5497        aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5498       (aModeStr == "all"      ? Prs3d_VDM_All :
5499                                 Prs3d_VDM_Inherited);
5500
5501     Standard_Boolean aRedrawNeeded = Standard_False;
5502     AIS_ListOfInteractive anObjs;
5503
5504     // No object(s) specified -> use all displayed
5505     if (theArgNum == 3)
5506     {
5507       theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5508       aContext->DisplayedObjects (anObjs);
5509       aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5510       aRedrawNeeded = Standard_True;
5511     }
5512
5513     Handle(AIS_InteractiveObject) anObject;
5514     for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5515     {
5516       TCollection_AsciiString aName (theArgs[aCount]);
5517       if (!GetMapOfAIS().Find2 (aName, anObject))
5518       {
5519         theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5520         continue;
5521       }
5522       anObjs.Append (anObject);
5523     }
5524
5525     for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5526     {
5527       anObject = anIt.Value();
5528       anObject->Attributes()->SetVertexDrawMode (aNewMode);
5529       aContext->Redisplay (anObject, Standard_False);
5530       aRedrawNeeded = Standard_True;
5531     }
5532
5533     if (aRedrawNeeded)
5534       ViewerTest::CurrentView()->Redraw();
5535
5536     return 0;
5537   }
5538
5539   Handle(AIS_InteractiveObject) anObject;
5540   if (theArgNum > 2
5541   || !GetMapOfAIS().Find2 (aParam, anObject))
5542   {
5543     std::cout << "Error: invalid number of arguments" << std::endl;
5544     return 1;
5545   }
5546
5547   // One argument (object name) --> print the current vertex draw mode for the object
5548   Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5549   theDI <<  "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5550   return 0;
5551 }
5552
5553 //=======================================================================
5554 //function : VPointCloud
5555 //purpose  : Create interactive object for arbitary set of points.
5556 //=======================================================================
5557 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5558                                      Standard_Integer  theArgNum,
5559                                      const char**      theArgs)
5560 {
5561   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5562   if (anAISContext.IsNull())
5563   {
5564     std::cerr << "Error: no active view!\n";
5565     return 1;
5566   }
5567
5568   // command to execute
5569   enum Command
5570   {
5571     CloudForShape, // generate point cloud for shape
5572     CloudSphere,   // generate point cloud for generic sphere
5573     Unknow
5574   };
5575
5576   // count number of non-optional command arguments
5577   Command aCmd = Unknow;
5578   Standard_Integer aCmdArgs = 0;
5579   for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5580   {
5581     Standard_CString anArg = theArgs[anArgIter];
5582     TCollection_AsciiString aFlag (anArg);
5583     aFlag.LowerCase();
5584     if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5585     {
5586       aCmdArgs++;
5587     }
5588   }
5589   switch (aCmdArgs)
5590   {
5591     case 2  : aCmd = CloudForShape; break;
5592     case 7  : aCmd = CloudSphere; break;
5593     default :
5594       std::cout << "Error: wrong number of arguments! See usage:\n";
5595       theDI.PrintHelp (theArgs[0]);
5596       return 1;
5597   }
5598
5599   // parse options
5600   Standard_Boolean toRandColors = Standard_False;
5601   Standard_Boolean hasNormals   = Standard_True;
5602   Standard_Boolean isSetArgNorm = Standard_False;
5603   Standard_Boolean hasUV        = Standard_False;
5604   for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5605   {
5606     Standard_CString anArg = theArgs[anArgIter];
5607     TCollection_AsciiString aFlag (anArg);
5608     aFlag.LowerCase();
5609     if (aFlag == "-randcolors"
5610      || aFlag == "-randcolor")
5611     {
5612       if (isSetArgNorm && hasNormals)
5613       {
5614         std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5615         return 1;
5616       }
5617       toRandColors = Standard_True;
5618       hasNormals   = Standard_False;
5619     }
5620     else if (aFlag == "-normals"
5621           || aFlag == "-normal")
5622     {
5623       if (toRandColors)
5624       {
5625         std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5626         return 1;
5627       }
5628       isSetArgNorm = Standard_True;
5629       hasNormals   = Standard_True;
5630     }
5631     else if (aFlag == "-nonormals"
5632           || aFlag == "-nonormal")
5633     {
5634       isSetArgNorm = Standard_True;
5635       hasNormals   = Standard_False;
5636     }
5637     else if (aFlag == "-uv"
5638           || aFlag == "-texels")
5639     {
5640       hasUV = Standard_True;
5641     }
5642   }
5643
5644   Standard_CString aName = theArgs[1];
5645   Graphic3d_ArrayFlags aFlags = Graphic3d_ArrayFlags_None;
5646   if (hasNormals)
5647   {
5648     aFlags |= Graphic3d_ArrayFlags_VertexNormal;
5649   }
5650   if (toRandColors)
5651   {
5652     aFlags |= Graphic3d_ArrayFlags_VertexColor;
5653   }
5654   if (hasUV)
5655   {
5656     aFlags |= Graphic3d_ArrayFlags_VertexTexel;
5657   }
5658
5659   // generate arbitrary set of points
5660   Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
5661   if (aCmd == CloudForShape)
5662   {
5663     Standard_CString aShapeName = theArgs[2];
5664     TopoDS_Shape     aShape     = DBRep::Get (aShapeName);
5665
5666     if (aShape.IsNull())
5667     {
5668       std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
5669       return 1;
5670     }
5671
5672     // calculate number of points
5673     TopLoc_Location  aLocation;
5674     Standard_Integer aNbPoints = 0;
5675     for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5676     {
5677       const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5678       Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5679       if (!aTriangulation.IsNull())
5680       {
5681         aNbPoints += aTriangulation->NbNodes();
5682       }
5683     }
5684     if (aNbPoints < 3)
5685     {
5686       std::cout << "Error: shape should be triangulated!\n";
5687       return 1;
5688     }
5689
5690     anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags);
5691     for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5692     {
5693       const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5694       Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5695       if (aTriangulation.IsNull())
5696       {
5697         continue;
5698       }
5699
5700       const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
5701       const gp_Trsf&            aTrsf  = aLocation.Transformation();
5702
5703       // extract normals from nodes
5704       TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
5705       if (hasNormals)
5706       {
5707         Poly_Connect aPolyConnect (aTriangulation);
5708         StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
5709       }
5710
5711       for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
5712       {
5713         gp_Pnt aPoint = aNodes (aNodeIter);
5714         if (!aLocation.IsIdentity())
5715         {
5716           aPoint.Transform (aTrsf);
5717           if (hasNormals)
5718           {
5719             aNormals (aNodeIter).Transform (aTrsf);
5720           }
5721         }
5722
5723         // add vertex into array of points
5724         const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5725         if (toRandColors)
5726         {
5727           Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
5728                                  1.0, 0.5, Quantity_TOC_HLS);
5729           anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5730         }
5731
5732         if (hasNormals)
5733         {
5734           anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
5735         }
5736         if (hasUV
5737          && aTriangulation->HasUVNodes())
5738         {
5739           anArrayPoints->SetVertexTexel (anIndexOfPoint, aTriangulation->UVNode (aNodeIter));
5740         }
5741       }
5742     }
5743   }
5744   else if (aCmd == CloudSphere)
5745   {
5746     Standard_Real aCenterX       = Draw::Atof (theArgs[2]);
5747     Standard_Real aCenterY       = Draw::Atof (theArgs[3]);
5748     Standard_Real aCenterZ       = Draw::Atof (theArgs[4]);
5749     Standard_Real aRadius        = Draw::Atof (theArgs[5]);
5750     Standard_Integer aNbPoints   = Draw::Atoi (theArgs[6]);
5751
5752     TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
5753     aDistribution.LowerCase();
5754     if ( aDistribution != "surface" && aDistribution != "volume" )
5755     {
5756       std::cout << "Error: wrong arguments! See usage:\n";
5757       theDI.PrintHelp (theArgs[0]);
5758       return 1;
5759     }
5760     Standard_Boolean isSurface = aDistribution == "surface";
5761
5762     gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
5763
5764     anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags);
5765     for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
5766     {
5767       Standard_Real anAlpha   = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5768       Standard_Real aBeta     = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5769       Standard_Real aDistance = isSurface ?
5770         aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
5771
5772       gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
5773                    Sin (anAlpha),
5774                    Cos (anAlpha) * Cos (aBeta));
5775       gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
5776
5777       const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5778       if (toRandColors)
5779       {
5780         Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
5781                                1.0, 0.5, Quantity_TOC_HLS);
5782         anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5783       }
5784
5785       if (hasNormals)
5786       {
5787         anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
5788       }
5789       if (hasUV)
5790       {
5791         anArrayPoints->SetVertexTexel (anIndexOfPoint, gp_Pnt2d (anAlpha / 2.0 * M_PI,
5792                                                                  aBeta   / 2.0 * M_PI));
5793       }
5794     }
5795   }
5796
5797   // set array of points in point cloud object
5798   Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
5799   aPointCloud->SetPoints (anArrayPoints);
5800   VDisplayAISObject (aName, aPointCloud);
5801   return 0;
5802 }
5803
5804 //=======================================================================
5805 //function : VPriority
5806 //purpose  : Prints or sets the display priority for an object
5807 //=======================================================================
5808
5809 static int VPriority (Draw_Interpretor& theDI,
5810                       Standard_Integer  theArgNum,
5811                       const char**      theArgs)
5812 {
5813   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5814   ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5815   if (aContext.IsNull())
5816   {
5817     std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5818     return 1;
5819   }
5820
5821   TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
5822   Standard_Integer aPriority = -1;
5823   Standard_Integer aNbArgs   = theArgNum;
5824   if (aLastArg.IsIntegerValue())
5825   {
5826     aPriority = aLastArg.IntegerValue();
5827     --aNbArgs;
5828     if (aPriority < 0 || aPriority > 10)
5829     {
5830       std::cout << "Error: the specified display priority value '" << aLastArg
5831                 << "' is outside the valid range [0..10]" << std::endl;
5832       return 1;
5833     }
5834   }
5835   else
5836   {
5837     anUpdateTool.Invalidate();
5838   }
5839
5840   if (aNbArgs < 2)
5841   {
5842     std::cout << "Error: wrong number of arguments! See usage:\n";
5843     theDI.PrintHelp (theArgs[0]);
5844     return 1;
5845   }
5846
5847   for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
5848   {
5849     if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
5850     {
5851       continue;
5852     }
5853
5854     TCollection_AsciiString aName (theArgs[anArgIter]);
5855     Handle(AIS_InteractiveObject) anIObj;
5856     GetMapOfAIS().Find2 (aName, anIObj);
5857     if (anIObj.IsNull())
5858     {
5859       std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
5860       return 1;
5861     }
5862
5863     if (aPriority < 1)
5864     {
5865       theDI << aContext->DisplayPriority (anIObj) << " ";
5866     }
5867     else
5868     {
5869       aContext->SetDisplayPriority (anIObj, aPriority);
5870     }
5871   }
5872   return 0;
5873 }
5874
5875 //! Auxiliary class for command vnormals.
5876 class MyShapeWithNormals : public AIS_Shape
5877 {
5878   DEFINE_STANDARD_RTTI_INLINE(MyShapeWithNormals, AIS_Shape);
5879 public:
5880
5881   Standard_Real    NormalLength;
5882   Standard_Integer NbAlongU;
5883   Standard_Integer NbAlongV;
5884   Standard_Boolean ToUseMesh;
5885   Standard_Boolean ToOrient;
5886
5887 public:
5888
5889   //! Main constructor.
5890   MyShapeWithNormals (const TopoDS_Shape& theShape)
5891   : AIS_Shape   (theShape),
5892     NormalLength(10),
5893     NbAlongU  (1),
5894     NbAlongV  (1),
5895     ToUseMesh (Standard_False),
5896     ToOrient  (Standard_False) {}
5897
5898 protected:
5899
5900   //! Comnpute presentation.
5901   virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
5902                         const Handle(Prs3d_Presentation)&           thePrs,
5903                         const Standard_Integer                      theMode) Standard_OVERRIDE
5904   {
5905     AIS_Shape::Compute (thePrsMgr, thePrs, theMode);
5906
5907     NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormalMap;
5908     if (ToUseMesh)
5909     {
5910       DBRep_DrawableShape::addMeshNormals (aNormalMap, myshape, NormalLength);
5911     }
5912     else
5913     {
5914       DBRep_DrawableShape::addSurfaceNormals (aNormalMap, myshape, NormalLength, NbAlongU, NbAlongV);
5915     }
5916
5917     Handle(Graphic3d_Group) aPrsGroup = Prs3d_Root::NewGroup (thePrs);
5918     aPrsGroup->SetGroupPrimitivesAspect (myDrawer->ArrowAspect()->Aspect());
5919
5920     const Standard_Real aArrowAngle  = myDrawer->ArrowAspect()->Angle();
5921     const Standard_Real aArrowLength = myDrawer->ArrowAspect()->Length();
5922     for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormalMap);
5923          aFaceIt.More(); aFaceIt.Next())
5924     {
5925       const Standard_Boolean toReverse = ToOrient && aFaceIt.Key().Orientation() == TopAbs_REVERSED;
5926       Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (2 * aFaceIt.Value().Size());
5927       for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aPntIt (aFaceIt.Value()); aPntIt.More(); aPntIt.Next())
5928       {
5929         std::pair<gp_Pnt, gp_Pnt> aPair = aPntIt.Value();
5930         if (toReverse)
5931         {
5932           const gp_Vec aDir = aPair.first.XYZ() - aPair.second.XYZ();
5933           aPair.second = aPair.first.XYZ() + aDir.XYZ();
5934         }
5935
5936         aSegments->AddVertex (aPair.first);
5937         aSegments->AddVertex (aPair.second);
5938         Prs3d_Arrow::Draw (aPrsGroup, aPair.second, gp_Vec(aPair.first, aPair.second), aArrowAngle, aArrowLength);
5939       }
5940
5941       aPrsGroup->AddPrimitiveArray (aSegments);
5942     }
5943   }
5944
5945 };
5946
5947 //=======================================================================
5948 //function : VNormals
5949 //purpose  : Displays/Hides normals calculated on shape geometry or retrieved from triangulation
5950 //=======================================================================
5951 static int VNormals (Draw_Interpretor& theDI,
5952                      Standard_Integer  theArgNum,
5953                      const char**      theArgs)
5954 {
5955   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5956   if (aContext.IsNull())
5957   {
5958     std::cout << "Error: no view available, call 'vinit' before!\n";
5959     return 1;
5960   }
5961   else if (theArgNum < 2)
5962   {
5963     std::cout << "Error: wrong number of arguments! See usage:\n";
5964     theDI.PrintHelp (theArgs[0]);
5965     return 1;
5966   }
5967
5968   Standard_Integer anArgIter = 1;
5969   Standard_CString aShapeName = theArgs[anArgIter++];
5970   TopoDS_Shape     aShape     = DBRep::Get (aShapeName);
5971   Standard_Boolean isOn = Standard_True;
5972   if (aShape.IsNull())
5973   {
5974     std::cout << "Error: shape with name '" << aShapeName << "' is not found\n";
5975     return 1;
5976   }
5977
5978   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5979   Handle(MyShapeWithNormals) aShapePrs;
5980   if (aMap.IsBound2 (aShapeName))
5981   {
5982     aShapePrs = Handle(MyShapeWithNormals)::DownCast (aMap.Find2 (aShapeName));
5983   }
5984
5985   Standard_Boolean isUseMesh = Standard_False;
5986   Standard_Real    aLength = 10.0;
5987   Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
5988   Standard_Boolean isOriented = Standard_False;
5989   for (; anArgIter < theArgNum; ++anArgIter)
5990   {
5991     TCollection_AsciiString aParam (theArgs[anArgIter]);
5992     aParam.LowerCase();
5993     if (anArgIter == 2
5994      && ViewerTest::ParseOnOff (aParam.ToCString(), isOn))
5995     {
5996       continue;
5997     }
5998     else if (aParam == "-usemesh"
5999           || aParam == "-mesh")
6000     {
6001       isUseMesh = Standard_True;
6002     }
6003     else if (aParam == "-length"
6004           || aParam == "-len")
6005     {
6006       ++anArgIter;
6007       aLength = anArgIter < theArgNum ? Draw::Atof (theArgs[anArgIter]) : 0.0;
6008       if (Abs (aLength) <= gp::Resolution())
6009       {
6010         std::cout << "Syntax error: length should not be zero\n";
6011         return 1;
6012       }
6013     }
6014     else if (aParam == "-orient"
6015           || aParam == "-oriented")
6016     {
6017       isOriented = Standard_True;
6018       if (anArgIter + 1 < theArgNum
6019         && ViewerTest::ParseOnOff (theArgs[anArgIter + 1], isOriented))
6020       {
6021         ++anArgIter;
6022       }
6023     }
6024     else if (aParam == "-nbalongu"
6025           || aParam == "-nbu")
6026     {
6027       ++anArgIter;
6028       aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6029       if (aNbAlongU < 1)
6030       {
6031         std::cout << "Syntax error: NbAlongU should be >=1\n";
6032         return 1;
6033       }
6034     }
6035     else if (aParam == "-nbalongv"
6036           || aParam == "-nbv")
6037     {
6038       ++anArgIter;
6039       aNbAlongV = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6040       if (aNbAlongV < 1)
6041       {
6042         std::cout << "Syntax error: NbAlongV should be >=1\n";
6043         return 1;
6044       }
6045     }
6046     else if (aParam == "-nbalong"
6047           || aParam == "-nbuv")
6048     {
6049       ++anArgIter;
6050       aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6051       aNbAlongV = aNbAlongU;
6052       if (aNbAlongU < 1)
6053       {
6054         std::cout << "Syntax error: NbAlong should be >=1\n";
6055         return 1;
6056       }
6057     }
6058     else
6059     {
6060       std::cout << "Syntax error: unknwon argument '" << aParam << "'\n";
6061       return 1;
6062     }
6063   }
6064
6065   if (isOn)
6066   {
6067     if (aShapePrs.IsNull())
6068     {
6069       aShapePrs = new MyShapeWithNormals (aShape);
6070     }
6071     aShapePrs->ToUseMesh    = isUseMesh;
6072     aShapePrs->ToOrient     = isOriented;
6073     aShapePrs->NormalLength = aLength;
6074     aShapePrs->NbAlongU     = aNbAlongU;
6075     aShapePrs->NbAlongV     = aNbAlongV;
6076     VDisplayAISObject (aShapeName, aShapePrs);
6077   }
6078   else if (!aShapePrs.IsNull())
6079   {
6080     VDisplayAISObject (aShapeName, new AIS_Shape (aShape));
6081   }
6082
6083   return 0;
6084 }
6085
6086 //=======================================================================
6087 //function : ObjectsCommands
6088 //purpose  :
6089 //=======================================================================
6090
6091 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
6092 {
6093   const char *group ="AISObjects";
6094
6095   theCommands.Add ("vtrihedron",
6096                    "vtrihedron : vtrihedron name"
6097                    "\n\t\t: [-dispMode {wireframe|shading} ]"
6098                    "\n\t\t: [-origin x y z ]"
6099                    "\n\t\t: [-zaxis u v w -xaxis u v w ]"
6100                    "\n\t\t: [-drawAxes {X|Y|Z|XY|YZ|XZ|XYZ}]"
6101                    "\n\t\t: [-hideLabels {on|off}]"
6102                    "\n\t\t: [-hideArrows {on|off}]"
6103                    "\n\t\t: [-label {XAxis|YAxis|ZAxis} value]"
6104                    "\n\t\t: [-attribute {XAxisLength|YAxisLength|ZAxisLength"
6105                    "\n\t\t:             |TubeRadiusPercent|ConeRadiusPercent"
6106                    "\n\t\t:             |ConeLengthPercent|OriginRadiusPercent"
6107                    "\n\t\t:             |ShadingNumberOfFacettes} value]"
6108                    "\n\t\t: [-color {Origin|XAxis|YAxis|ZAxis|XOYAxis|YOZAxis"
6109                    "\n\t\t:         |XOZAxis|Whole} {r g b | colorName}]"
6110                    "\n\t\t: [-textColor {r g b | colorName}]"
6111                    "\n\t\t: [-arrowColor {r g b | colorName}]"
6112                    "\n\t\t: [-priority {Origin|XAxis|YAxis|ZAxis|XArrow"
6113                    "\n\t\t:            |YArrow|ZArrow|XOYAxis|YOZAxis"
6114                    "\n\t\t:            |XOZAxis|Whole} value]"
6115                    "\n\t\t:"
6116                    "\n\t\t: Creates a new *AIS_Trihedron* object or changes parameters of "
6117                    "\n\t\t: existing trihedron. If no argument is set,"
6118                    "\n\t\t: the default trihedron (0XYZ) is created."
6119                    "\n\t\t: -dispMode mode of visualization: wf - wireframe,"
6120                    "\n\t\t:                                  sh - shading."
6121                    "\n\t\t:               Default value is wireframe."
6122                    "\n\t\t: -origin allows to set trihedron location."
6123                    "\n\t\t: -zaxis/-xaxis allows to set trihedron X and Z"
6124                    "\n\t\t:               directions. The directions should"
6125                    "\n\t\t:               be orthogonal. Y direction is calculated."
6126                    "\n\t\t: -drawAxes allows to set what axes are drawn in the"
6127                    "\n\t\t:           trihedron, default state is XYZ"
6128                    "\n\t\t: -hideLabels allows to show/hide trihedron labels"
6129                    "\n\t\t: -hideArrows allows to show/hide trihedron arrows"
6130                    "\n\t\t: -label allows to change default X/Y/Z titles of axes"
6131                    "\n\t\t: -attribute sets parameters of trihedron"
6132                    "\n\t\t: -color sets color properties of parts of trihedron"
6133                    "\n\t\t: -textColor sets color properties of trihedron labels"
6134                    "\n\t\t: -arrowColor sets color properties of trihedron arrows"
6135                    "\n\t\t: -priority allows to change default selection priority"
6136                    "\n\t\t: of trihedron components",
6137                    __FILE__,VTrihedron,group);
6138
6139   theCommands.Add("vtri2d",
6140     "vtri2d Name"
6141     "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.",
6142     __FILE__,VTrihedron2D ,group);
6143
6144   theCommands.Add("vplanetri",
6145     "vplanetri name"
6146     "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default",
6147     __FILE__,VPlaneTrihedron ,group);
6148
6149   theCommands.Add("vsize",
6150     "vsize       : vsize [name(Default=Current)] [size(Default=100)] "
6151     "\n\t\t: Changes the size of a named or selected trihedron."
6152     "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done."
6153     "\n\t\t: If the value is not defined: it is set to 100 by default.",
6154     __FILE__,VSize,group);
6155
6156   theCommands.Add("vaxis",
6157     "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]"
6158     "\n\t\t: Creates an axis. If  the values are not defined, an axis is created by interactive selection of two vertices or one edge",
6159     __FILE__,VAxisBuilder,group);
6160
6161   theCommands.Add("vaxispara",
6162     "vaxispara name "
6163     "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.",
6164     __FILE__,VAxisBuilder,group);
6165
6166   theCommands.Add("vaxisortho",
6167     "vaxisortho name "
6168     "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.",
6169     __FILE__,VAxisBuilder,group);
6170
6171   theCommands.Add("vpoint",
6172     "vpoint  PointName [Xa] [Ya] [Za] "
6173     "\n\t\t: Creates a point from coordinates. If the values are not defined,"
6174     "\n\t\t: a point is created by interactive selection of a vertice or an edge (in the center of the edge).",
6175     __FILE__,VPointBuilder,group);
6176
6177   theCommands.Add("vplane",
6178     "vplane  PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]"
6179     "\n\t\t: Creates a plane from named or interactively selected entities."
6180     "\n\t\t: TypeOfSensitivity:"
6181     "\n\t\t:   0 - Interior"
6182     "\n\t\t:   1 - Boundary",
6183     __FILE__,VPlaneBuilder,group);
6184
6185   theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
6186     "   vchangeplane <plane_name>"
6187     " [x=center_x y=center_y z=center_z]"
6188     " [dx=dir_x dy=dir_y dz=dir_z]"
6189     " [sx=size_x sy=size_y]"
6190     " [noupdate]\n"
6191     "   - changes parameters of the plane:\n"
6192     "   - x y z     - center\n"
6193     "   - dx dy dz  - normal\n"
6194     "   - sx sy     - plane sizes\n"
6195     "   - noupdate  - do not update/redisplay the plane in context\n"
6196     "   Please enter coordinates in format \"param=value\" in arbitrary order.",
6197     __FILE__, VChangePlane, group);
6198
6199   theCommands.Add("vplanepara",
6200     "vplanepara  PlaneName  "
6201     "\n\t\t: Creates a plane from interactively selected vertex and face.",
6202     __FILE__,VPlaneBuilder,group);
6203
6204   theCommands.Add("vplaneortho",
6205     "vplaneortho  PlaneName  "
6206     "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ",
6207     __FILE__,VPlaneBuilder,group);
6208
6209   theCommands.Add("vline",
6210     "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb]  "
6211     "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ",
6212     __FILE__,VLineBuilder,group);
6213
6214   theCommands.Add("vcircle",
6215     "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]"
6216     "\n\t\t: Creates a circle from named or interactively selected entities."
6217     "\n\t\t: Parameter IsFilled is defined as 0 or 1.",
6218     __FILE__,VCircleBuilder,group);
6219
6220   theCommands.Add ("vdrawtext",
6221                    "vdrawtext name text"
6222                    "\n\t\t: [-pos X=0 Y=0 Z=0]"
6223                    "\n\t\t: [-color {R G B|name}=yellow]"
6224                    "\n\t\t: [-halign {left|center|right}=left]"
6225                    "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6226                    "\n\t\t: [-angle angle=0]"
6227                    "\n\t\t: [-zoom {0|1}=0]"
6228                    "\n\t\t: [-height height=16]"
6229                    "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]"
6230                    "\n\t\t: [-font font=Times]"
6231                    "\n\t\t: [-2d]"
6232                    "\n\t\t: [-perspos {X Y Z}=0 0 0], where"
6233                    "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window"
6234                    "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..."
6235                    "\n\t\t Z coordinate defines the gap from border of view window (except center position)."
6236                    "\n\t\t: [-disptype {blend|decal|shadow|subtitle|dimension|normal}=normal}"
6237                    "\n\t\t: [-subcolor {R G B|name}=white]"
6238                    "\n\t\t: [-noupdate]"
6239                    "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]"
6240                    "\n\t\t: [-flipping]"
6241                    "\n\t\t: Display text label at specified position.",
6242     __FILE__, VDrawText, group);
6243
6244   theCommands.Add("vdrawsphere",
6245     "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
6246     __FILE__,VDrawSphere,group);
6247
6248   theCommands.Add ("vlocation",
6249                 "vlocation name"
6250       "\n\t\t:   [-reset]"
6251       "\n\t\t:   [-copyFrom otherName]"
6252       "\n\t\t:   [-translate X Y [Z]]"
6253       "\n\t\t:   [-rotate x y z dx dy dz angle]"
6254       "\n\t\t:   [-scale [X Y Z] scale]"
6255       "\n\t\t:   [-mirror x y z dx dy dz]"
6256       "\n\t\t:   [-setLocation X Y [Z]]"
6257       "\n\t\t:   [-setRotation QX QY QZ QW]"
6258       "\n\t\t:   [-setScale [X Y Z] scale]"
6259       "\n\t\t: Object local transformation management:"
6260       "\n\t\t:   -reset       reset transformation to identity"
6261       "\n\t\t:   -translate   translate object"
6262       "\n\t\t:   -rotate      applies rotation to local transformation"
6263       "\n\t\t:   -scale       applies scale    to local transformation"
6264       "\n\t\t:   -mirror      applies mirror   to local transformation"
6265       "\n\t\t:   -setLocation assign object location"
6266       "\n\t\t:   -setRotation assign object rotation (quaternion)"
6267       "\n\t\t:   -setScale    assign object scale factor",
6268         __FILE__, VSetLocation, group);
6269   theCommands.Add ("vsetlocation",
6270                    "alias for vlocation",
6271         __FILE__, VSetLocation, group);
6272
6273   theCommands.Add ("vcomputehlr",
6274                 "vcomputehlr shapeInput hlrResult [-algoType {algo|polyAlgo}=polyAlgo]"
6275       "\n\t\t:   [eyeX eyeY eyeZ dirX dirY dirZ upX upY upZ]"
6276       "\n\t\t:   [-showTangentEdges {on|off}=off] [-nbIsolines N=0] [-showHiddenEdges {on|off}=off]"
6277       "\n\t\t: Arguments:"
6278       "\n\t\t:  shapeInput - name of the initial shape"
6279       "\n\t\t:  hlrResult - result HLR object from initial shape"
6280       "\n\t\t:  eye, dir are eye position and look direction"
6281       "\n\t\t:  up is the look up direction vector"
6282       "\n\t\t:  -algoType HLR algorithm to use"
6283       "\n\t\t:  -showTangentEdges include tangent edges"
6284       "\n\t\t:  -nbIsolines include isolines"
6285       "\n\t\t:  -showHiddenEdges include hidden edges"
6286       "\n\t\t: Use vtop to see projected HLR shape.",
6287     __FILE__, VComputeHLR, group);
6288
6289   theCommands.Add("vdrawparray",
6290                 "vdrawparray name TypeOfArray={points|segments|polylines|triangles"
6291       "\n\t\t:                                |trianglefans|trianglestrips|quads|quadstrips|polygons}"
6292       "\n\t\t:              [-deinterleaved|-mutable]"
6293       "\n\t\t:              [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [texel={'t' tx ty}]]"
6294       "\n\t\t:              [bound= {'b' nbVertices [bound_color={'c' r g b}]]"
6295       "\n\t\t:              [edge=  {'e' vertexId]"
6296       "\n\t\t:              [-shape shapeName] [-patch]"
6297       "\n\t\t: Commands create an Interactive Object for specified Primitive Array definition (Graphic3d_ArrayOfPrimitives)"
6298       "\n\t\t: with the main purpose is covering various combinations by tests",
6299     __FILE__,VDrawPArray,group);
6300
6301   theCommands.Add("vconnect", 
6302     "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]"
6303     "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.",
6304     __FILE__, VConnect, group);
6305
6306   theCommands.Add("vconnectto",
6307     "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
6308     "  Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6309     "\n\t\t:   -nodisplay - only creates interactive object, but not displays it",
6310     __FILE__, VConnectTo,group);
6311
6312   theCommands.Add("vdisconnect",
6313     "vdisconnect assembly_name (object_name | object_number | 'all')"
6314     "  Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6315     __FILE__,VDisconnect,group);
6316
6317   theCommands.Add("vaddconnected",
6318     "vaddconnected assembly_name object_name"
6319     "Adds object to assembly.",
6320     __FILE__,VAddConnected,group);
6321
6322   theCommands.Add("vlistconnected",
6323     "vlistconnected assembly_name"
6324     "Lists objects in assembly.",
6325     __FILE__,VListConnected,group);
6326
6327
6328   theCommands.Add("vselmode", 
6329                 "vselmode [object] selectionMode {on|off}"
6330       "\n\t\t:            [{-add|-set|-globalOrLocal}=-globalOrLocal]"
6331       "\n\t\t: Switches selection mode for the specified object or for all objects in context."
6332       "\n\t\t: Selection mode is either an integer number specific to Interactive Object,"
6333       "\n\t\t: or sub-shape type in case of AIS_Shape:"
6334       "\n\t\t:   Shape, Vertex, Edge, Wire, Face, Shell, Solid, CompSolid, Compound"
6335       "\n\t\t: The integer mode 0 (Shape in case of AIS_Shape) is reserved for selecting object as whole."
6336       "\n\t\t: Additional options:"
6337       "\n\t\t:  -add           already activated selection modes will be left activated"
6338       "\n\t\t:  -set           already activated selection modes will be deactivated"
6339       "\n\t\t:  -globalOrLocal (default) if new mode is Global selection mode,"
6340       "\n\t\t:                 then active local selection modes will be deactivated"
6341       "\n\t\t:                 and the samthen active local selection modes will be deactivated",
6342     __FILE__, VSetSelectionMode, group);
6343
6344   theCommands.Add("vselnext",
6345     "vselnext : hilight next detected",
6346     __FILE__, VSelectionNext, group);
6347
6348   theCommands.Add("vselprev",
6349     "vselnext : hilight previous detected",
6350     __FILE__, VSelectionPrevious, group);
6351
6352   theCommands.Add("vtriangle",
6353     "vtriangle Name PointName PointName PointName"
6354     "\n\t\t: Creates and displays a filled triangle from named points.", 
6355     __FILE__, VTriangle,group);
6356
6357   theCommands.Add("vsegment",
6358     "vsegment Name PointName PointName"
6359     "\n\t\t: Creates and displays a segment from named points.", 
6360     __FILE__, VTriangle,group);
6361
6362   theCommands.Add("vobjzlayer",
6363     "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6364     __FILE__, VObjZLayer, group);
6365   
6366   theCommands.Add("vpolygonoffset",
6367     "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6368     __FILE__, VPolygonOffset, group);
6369
6370   theCommands.Add ("vmarkerstest",
6371                    "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6372                    __FILE__, VMarkersTest, group);
6373
6374   theCommands.Add ("text2brep",
6375                    "text2brep: name text"
6376                    "\n\t\t: [-pos X=0 Y=0 Z=0]"
6377                    "\n\t\t: [-halign {left|center|right}=left]"
6378                    "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6379                    "\n\t\t: [-height height=16]"
6380                    "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]"
6381                    "\n\t\t: [-font font=Courier]"
6382                    "\n\t\t: [-composite {on|off}=off]"
6383                    "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]",
6384                    __FILE__, TextToBRep, group);
6385   theCommands.Add ("vfont",
6386                             "vfont [-add pathToFont [fontName] [regular,bold,italic,boldItalic=undefined] [singleStroke]]"
6387                    "\n\t\t:        [-find fontName [regular,bold,italic,boldItalic=undefined]] [-verbose {on|off}]",
6388                    __FILE__, VFont, group);
6389
6390   theCommands.Add ("vvertexmode",
6391                    "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6392                    "vvertexmode - prints the default vertex draw mode\n"
6393                    "vvertexmode name - prints the vertex draw mode of the given object\n"
6394                    "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6395                    "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6396                    __FILE__, VVertexMode, group);
6397
6398   theCommands.Add ("vpointcloud",
6399                    "vpointcloud name shape [-randColor] [-normals] [-noNormals] [-uv]"
6400                    "\n\t\t: Create an interactive object for arbitary set of points"
6401                    "\n\t\t: from triangulated shape."
6402                    "\n"
6403                    "vpointcloud name x y z r npts {surface|volume}\n"
6404                    "            ... [-randColor] [-normals] [-noNormals] [-uv]"
6405                    "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6406                    "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6407                    "\n\t\t:"
6408                    "\n\t\t: Additional options:"
6409                    "\n\t\t:  -randColor - generate random color per point"
6410                    "\n\t\t:  -normals   - generate normal per point (default)"
6411                    "\n\t\t:  -noNormals - do not generate normal per point"
6412                    "\n",
6413                    __FILE__, VPointCloud, group);
6414
6415   theCommands.Add("vpriority",
6416     "vpriority [-noupdate|-update] name [value]\n\t\t  prints or sets the display priority for an object",
6417     __FILE__,
6418     VPriority, group);
6419
6420   theCommands.Add ("vnormals",
6421                    "vnormals usage:\n"
6422                    "vnormals Shape [{on|off}=on] [-length {10}] [-nbAlongU {1}] [-nbAlongV {1}] [-nbAlong {1}]"
6423                    "\n\t\t:        [-useMesh] [-oriented {0}1}=0]"
6424                    "\n\t\t:  Displays/Hides normals calculated on shape geometry or retrieved from triangulation",
6425                    __FILE__, VNormals, group);
6426 }