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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <ViewerTest.hxx>
19 #include <AIS_PlaneTrihedron.hxx>
21 #include <Quantity_NameOfColor.hxx>
22 #include <Draw_Interpretor.hxx>
24 #include <Draw_Appli.hxx>
26 #include <DBRep_DrawableShape.hxx>
28 #include <Font_BRepFont.hxx>
29 #include <Font_BRepTextBuilder.hxx>
30 #include <Font_FontMgr.hxx>
32 #include <NCollection_List.hxx>
34 #include <OSD_Chronometer.hxx>
35 #include <TCollection_AsciiString.hxx>
36 #include <V3d_Viewer.hxx>
37 #include <V3d_View.hxx>
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>
50 #include <TopoDS_Solid.hxx>
51 #include <BRepTools.hxx>
52 #include <BRep_Builder.hxx>
53 #include <TopAbs_ShapeEnum.hxx>
56 #include <BRep_Tool.hxx>
57 #include <TopExp_Explorer.hxx>
59 #include <BRepAdaptor_Curve.hxx>
60 #include <BRepAdaptor_Surface.hxx>
64 #include <TopoDS_Vertex.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Face.hxx>
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>
75 #include <AIS_InteractiveContext.hxx>
76 #include <Geom_Plane.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>
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>
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>
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>
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>
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>
140 #include <BRepExtrema_ExtPC.hxx>
141 #include <BRepExtrema_ExtPF.hxx>
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>
154 #include <Image_AlienPixMap.hxx>
155 #include <TColStd_HArray1OfAsciiString.hxx>
156 #include <TColStd_HSequenceOfAsciiString.hxx>
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();
167 static bool convertToColor (const Handle(TColStd_HSequenceOfAsciiString)& theColorValues,
168 Quantity_Color& theColor)
170 const char* anArgs[3] =
172 theColorValues->Size() >= 1 ? theColorValues->Value (1).ToCString() : "",
173 theColorValues->Size() >= 2 ? theColorValues->Value (2).ToCString() : "",
174 theColorValues->Size() >= 3 ? theColorValues->Value (3).ToCString() : ""
176 return ViewerTest::ParseColor (theColorValues->Size(), anArgs, theColor) != 0;
179 static bool convertToDatumPart (const TCollection_AsciiString& theValue,
180 Prs3d_DatumParts& theDatumPart)
182 TCollection_AsciiString aValue = theValue;
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;
202 static void convertToDatumParts (const TCollection_AsciiString& theValue,
203 NCollection_List<Prs3d_DatumParts>& theParts)
205 TCollection_AsciiString aValue = theValue;
206 const Standard_Integer aSplitPos = theValue.Search ("|");
207 Prs3d_DatumParts aPart = Prs3d_DP_None;
210 convertToDatumParts (theValue.SubString (aSplitPos + 1, theValue.Length()), theParts);
211 if (aSplitPos == 1) // first symbol
215 aValue = theValue.SubString (1, aSplitPos - 1);
217 if (convertToDatumPart (aValue, aPart))
219 theParts.Append (aPart);
223 static bool convertToDatumAttribute (const TCollection_AsciiString& theValue,
224 Prs3d_DatumAttribute& theAttribute)
226 TCollection_AsciiString aValue = theValue;
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;
241 static void convertToDatumAttributes (const TCollection_AsciiString& theValue,
242 NCollection_List<Prs3d_DatumAttribute>& theAttributes)
244 TCollection_AsciiString aValue = theValue;
245 const Standard_Integer aSplitPos = theValue.Search ("|");
246 Prs3d_DatumAttribute anAttribute = Prs3d_DA_XAxisLength;
249 convertToDatumAttributes (theValue.SubString (aSplitPos + 1, theValue.Length()), theAttributes);
250 if (aSplitPos == 1) // first symbol
254 aValue = theValue.SubString (1, aSplitPos - 1);
256 if (convertToDatumAttribute (aValue, anAttribute))
258 theAttributes.Append (anAttribute);
262 static bool convertToDatumAxes (const TCollection_AsciiString& theValue,
263 Prs3d_DatumAxes& theDatumAxes)
265 TCollection_AsciiString aValue = theValue;
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;
281 static Standard_Boolean setTrihedronParams (Standard_Integer theArgsNb,
282 const char** theArgVec,
283 Handle(AIS_Trihedron) theTrihedron)
285 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
286 TCollection_AsciiString aParseKey;
287 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
289 TCollection_AsciiString anArg (theArgVec [anArgIt]);
290 if (anArg.Value (1) == '-'
291 && !anArg.IsRealValue())
294 aParseKey.Remove (1);
295 aParseKey.LowerCase();
296 std::string aKey = aParseKey.ToCString();
297 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString());
301 if (aParseKey.IsEmpty())
306 aMapOfArgs (aParseKey)->Append (anArg);
310 if ((aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis"))
311 || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")))
313 std::cout << "Syntax error: -xaxis and -zaxis parameters are to set together.\n";
314 return Standard_False;
317 Handle(TColStd_HSequenceOfAsciiString) aValues;
318 Handle(Geom_Axis2Placement) aComponent = theTrihedron->Component();
319 if (aMapOfArgs.Find ("origin", aValues))
321 aComponent->SetLocation (gp_Pnt (aValues->Value (1).RealValue(),
322 aValues->Value (2).RealValue(),
323 aValues->Value (3).RealValue()));
325 Handle(TColStd_HSequenceOfAsciiString) aXValues, aZValues;
326 if (aMapOfArgs.Find ("xaxis", aXValues) && aMapOfArgs.Find ("zaxis", aZValues))
328 gp_Dir aXDir (aXValues->Value (1).RealValue(),
329 aXValues->Value (2).RealValue(),
330 aXValues->Value (3).RealValue());
332 gp_Dir aZDir (aZValues->Value (1).RealValue(),
333 aZValues->Value (2).RealValue(),
334 aZValues->Value (3).RealValue());
336 if (!aZDir.IsNormal (aXDir, M_PI / 180.0))
338 std::cout << "Syntax error - parameters 'xaxis' and 'zaxis' are not applied as VectorX is not normal to VectorZ\n";
339 return Standard_False;
342 aComponent->SetAx2 (gp_Ax2 (aComponent->Location(), aZDir, aXDir));
345 if (aMapOfArgs.Find ("dispmode", aValues))
347 TCollection_AsciiString aValue (aValues->Value (1));
348 bool isWireframe = true;
349 if (aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
351 theTrihedron->SetDatumDisplayMode (isWireframe ? Prs3d_DM_WireFrame
355 if (aMapOfArgs.Find ("hidelabels", aValues))
357 Standard_Boolean toHideLabels = Standard_True;
358 if (aValues->Size() == 1)
360 ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideLabels);
362 else if (aValues->Size() != 0)
364 std::cout << "Syntax error: -hidelabels expects parameter 'on' or 'off' after.\n";
365 return Standard_False;
368 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
370 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
372 theTrihedron->Attributes()->DatumAspect()->SetDrawLabels (!toHideLabels);
375 if (aMapOfArgs.Find ("hidearrows", aValues))
377 Standard_Boolean toHideArrows = Standard_True;
378 if (aValues->Size() == 1)
380 ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideArrows);
382 else if (aValues->Size() != 0)
384 std::cout << "Syntax error: -hidearrows expects parameter 'on' or 'off' after.\n";
385 return Standard_False;
388 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
390 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
392 theTrihedron->Attributes()->DatumAspect()->SetDrawArrows (!toHideArrows);
395 if (aMapOfArgs.Find ("color", aValues))
397 NCollection_List<Prs3d_DatumParts> aParts;
398 if (aValues->Size() < 2)
400 std::cout << "Syntax error: -color wrong parameters.\n";
401 return Standard_False;
404 convertToDatumParts (aValues->Value(1), aParts);
405 aValues->Remove (1); // datum part is processed
406 Quantity_Color aColor;
407 if (!convertToColor (aValues, aColor))
409 std::cout << "Syntax error: -color wrong parameters.\n";
410 return Standard_False;
413 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (aParts); anIterator.More(); anIterator.Next())
415 Prs3d_DatumParts aDatumPart = anIterator.Value();
416 if (aDatumPart == Prs3d_DP_None)
418 theTrihedron->SetColor (aColor);
422 theTrihedron->SetDatumPartColor (aDatumPart, aColor);
427 if (aMapOfArgs.Find ("textcolor", aValues))
429 Quantity_Color aColor;
430 if (!convertToColor (aValues, aColor))
432 std::cout << "Syntax error: -textcolor wrong parameters.\n";
433 return Standard_False;
435 theTrihedron->SetTextColor (aColor);
438 if (aMapOfArgs.Find ("arrowcolor", aValues))
440 Quantity_Color aColor;
441 if (!convertToColor (aValues, aColor))
443 std::cout << "Syntax error: -arrowcolor wrong parameters.\n";
444 return Standard_False;
446 theTrihedron->SetArrowColor (aColor);
449 if (aMapOfArgs.Find ("attribute", aValues))
451 NCollection_List<Prs3d_DatumAttribute> anAttributes;
452 if (aValues->Size() != 2)
454 std::cout << "Syntax error: -attribute wrong parameters.\n";
455 return Standard_False;
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())
463 theTrihedron->Attributes()->DatumAspect()->SetAttribute (anIterator.Value(), aValues->Value (2).RealValue());
467 if (aMapOfArgs.Find ("priority", aValues))
469 Prs3d_DatumParts aDatumPart;
470 if (aValues->Size() < 2
471 || !convertToDatumPart (aValues->Value (1), aDatumPart))
473 std::cout << "Syntax error: -priority wrong parameters.\n";
474 return Standard_False;
476 theTrihedron->SetSelectionPriority (aDatumPart, aValues->Value (2).IntegerValue());
479 if (aMapOfArgs.Find ("labels", aValues)
480 || aMapOfArgs.Find ("label", aValues))
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
488 theTrihedron->SetLabel (aDatumPart, aValues->Value (2));
492 std::cout << "Syntax error: -labels wrong parameters.\n";
493 return Standard_False;
497 if (aMapOfArgs.Find ("drawaxes", aValues))
499 Prs3d_DatumAxes aDatumAxes = Prs3d_DA_XAxis;
500 if (aValues->Size() < 1
501 || !convertToDatumAxes (aValues->Value (1), aDatumAxes))
503 std::cout << "Syntax error: -drawaxes wrong parameters.\n";
504 return Standard_False;
506 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
507 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
508 theTrihedron->Attributes()->DatumAspect()->SetDrawDatumAxes (aDatumAxes);
510 return Standard_True;
513 //! Auxiliary function to parse font aspect style argument
514 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
515 Font_FontAspect& theAspect)
517 if (theArg == "regular"
518 || *theArg.ToCString() == 'r')
520 theAspect = Font_FA_Regular;
521 return Standard_True;
523 else if (theArg == "bolditalic"
524 || theArg == "bold-italic"
525 || theArg == "italic-bold"
526 || theArg == "italicbold")
528 theAspect = Font_FA_BoldItalic;
529 return Standard_True;
531 else if (theArg == "bold"
532 || *theArg.ToCString() == 'b')
534 theAspect = Font_FA_Bold;
535 return Standard_True;
537 else if (theArg == "italic"
538 || *theArg.ToCString() == 'i')
540 theAspect = Font_FA_Italic;
541 return Standard_True;
543 return Standard_False;
546 //! Auxiliary function to parse font strict level argument
547 static Standard_Integer parseFontStrictLevel (const Standard_Integer theArgNb,
548 const char** theArgVec,
549 Font_StrictLevel& theLevel)
553 TCollection_AsciiString anArg (theArgVec[0]);
557 theLevel = Font_StrictLevel_Any;
560 else if (anArg == "aliases")
562 theLevel = Font_StrictLevel_Aliases;
565 else if (anArg == "strict")
567 theLevel = Font_StrictLevel_Strict;
571 theLevel = Font_StrictLevel_Strict;
576 //==============================================================================
577 //function : Vtrihedron 2d
578 //purpose : Create a plane with a 2D trihedron from a faceselection
579 //Draw arg : vtri2d name
580 //==============================================================================
581 static int VTrihedron2D (Draw_Interpretor& /*theDI*/,
582 Standard_Integer theArgsNum,
583 const char** theArgVec)
587 std::cerr << theArgVec[0]<< " error.\n";
591 TopTools_ListOfShape aShapes;
592 ViewerTest::GetSelectedShapes (aShapes);
594 if (aShapes.Extent() != 1)
596 std::cerr << "Error: wrong number of selected shapes.\n";
600 const TopoDS_Shape& aShape = aShapes.First();
602 TopoDS_Face aFace = TopoDS::Face (aShape);
603 TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE);
604 TopoDS_Edge anEdge0 = TopoDS::Edge (aFaceExp.Current());
610 TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() );
611 BRepAdaptor_Curve aCurve0 (anEdge0);
612 BRepAdaptor_Curve aCurve1 (anEdge1);
613 A = aCurve1.Value (0.1);
614 B = aCurve1.Value (0.9);
615 C = aCurve0.Value (0.5);
619 BRepAdaptor_Curve aCurve0 (anEdge0);
620 A = aCurve0.Value (0.1);
621 B = aCurve0.Value (0.9);
622 C = aCurve0.Value (0.5);
625 GC_MakePlane aMkPlane (A,B,C);
627 Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value());
628 TCollection_AsciiString aName (theArgVec[1]);
630 VDisplayAISObject (aName, anAISPlaneTri);
635 //=======================================================================
636 //function : VTrihedron
638 //=======================================================================
639 static int VTrihedron (Draw_Interpretor& ,
640 Standard_Integer theArgsNb,
641 const char** theArgVec)
645 std::cout << "Syntax error: the wrong number of input parameters.\n";
649 TCollection_AsciiString aName (theArgVec[1]);
650 gp_Pln aWorkingPlane;
651 Standard_Boolean toUpdate = Standard_True;
653 NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
654 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
656 Handle(AIS_Trihedron) aTrihedron;
657 Handle(AIS_InteractiveObject) anObject;
658 if (GetMapOfAIS().Find2 (aName, anObject))
660 aTrihedron = Handle(AIS_Trihedron)::DownCast (anObject);
661 if (aTrihedron.IsNull())
663 std::cout << "Syntax error: no trihedron with this name.\n";
669 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (gp_Pnt (0.0, 0.0, 0.0),
671 aTrihedron = new AIS_Trihedron (aPlacement);
674 if (!setTrihedronParams (theArgsNb, theArgVec, aTrihedron))
679 // Redisplay a dimension after parameter changing.
680 if (ViewerTest::GetAISContext()->IsDisplayed (aTrihedron))
682 ViewerTest::GetAISContext()->Redisplay (aTrihedron, toUpdate);
686 VDisplayAISObject (theArgVec[1], aTrihedron);
692 //==============================================================================
695 //purpose : Change the size of a named or selected trihedron
696 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
697 // if no value, the value is set at 100 by default
698 //Draw arg : vsize [name] [size]
699 //==============================================================================
701 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
704 // Declaration de booleens
705 Standard_Boolean ThereIsName;
706 Standard_Boolean ThereIsCurrent;
708 Standard_Boolean hascol;
710 Quantity_Color col = Quantity_NOC_BLACK;
712 // Verification des arguments
713 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;}
715 // Verification du nombre d'arguments
716 if (argc==1) {ThereIsName=Standard_False;value=100;}
717 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
718 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
720 // On set le booleen ThereIsCurrent
721 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
722 else {ThereIsCurrent=Standard_False;}
726 //===============================================================
727 // Il n'y a pas de nom mais des objets selectionnes
728 //===============================================================
729 if (!ThereIsName && ThereIsCurrent)
732 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
735 while ( it.More() ) {
737 Handle(AIS_InteractiveObject) aShape = it.Key1();
739 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
742 // On verifie que l'AIS InteraciveObject selectionne est bien
744 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
746 if (aShape->HasColor())
748 hascol = Standard_True;
750 // On recupere la couleur de aShape
755 hascol = Standard_False;
758 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
759 // pour lui appliquer la methode SetSize()
760 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
762 // C'est bien un triedre,on chage sa valeur!
763 aTrihedron->SetSize(value);
765 // On donne la couleur au Trihedron
766 if(hascol) aTrihedron->SetColor(col);
767 else aTrihedron->UnsetColor();
770 // The trihedron hasn't be errased from the map
771 // so you just have to redisplay it
772 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
781 TheAISContext() ->UpdateCurrentViewer();
784 //===============================================================
785 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
786 //===============================================================
790 //===============================================================
791 // Il y a un nom de triedre passe en argument
792 //===============================================================
794 TCollection_AsciiString name=argv[1];
796 // on verifie que ce nom correspond bien a une shape
797 Handle(AIS_InteractiveObject) aShape;
798 if (GetMapOfAIS().Find2(name, aShape))
800 // On verifie que l'AIS InteraciveObject est bien
802 if (!aShape.IsNull() &&
803 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
805 if (aShape->HasColor())
807 hascol=Standard_True;
809 // On recupere la couleur de aShape
814 hascol = Standard_False;
817 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
818 // pour lui appliquer la methode SetSize()
819 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
821 // C'est bien un triedre,on chage sa valeur
822 aTrihedron->SetSize(value);
824 // On donne la couleur au Trihedron
825 if(hascol) aTrihedron->SetColor(col);
826 else aTrihedron->UnsetColor();
828 // The trihedron hasn't be errased from the map
829 // so you just have to redisplay it
830 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
832 TheAISContext() ->UpdateCurrentViewer();
840 //==============================================================================
842 //==============================================================================
843 //function : VPlaneTrihedron
844 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
845 //Draw arg : vplanetri name
846 //==============================================================================
847 #include <AIS_Plane.hxx>
851 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
854 // Verification des arguments
855 if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
857 if (TheAISContext()->NbSelected() != 1)
859 std::cerr << "Error: Wrong number of selected shapes.\n";
863 TheAISContext()->InitSelected();
864 Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive();
865 Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest);
868 std::cerr << "Error: Selected shape is not a plane.\n";
872 VDisplayAISObject (argv[1], aPlane);
879 //==============================================================================
880 // Fonction First click 2de click
882 // vaxis vertex vertex
884 // vaxispara edge vertex
885 // vaxisortho edge Vertex
886 // vaxisinter Face Face
887 //==============================================================================
889 //==============================================================================
890 //function : VAxisBuilder
892 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
893 //==============================================================================
894 #include <TopoDS_Edge.hxx>
895 #include <TopoDS_Vertex.hxx>
896 #include <TopExp.hxx>
897 #include <Geom_Line.hxx>
899 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
902 Standard_Boolean HasArg;
903 TCollection_AsciiString name;
906 if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
907 if (argc==8) HasArg=Standard_True;
908 else HasArg=Standard_False;
912 TopTools_ListOfShape aShapes;
913 ViewerTest::GetSelectedShapes (aShapes);
915 // Cas ou il y a des arguments
916 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
918 Standard_Real coord[6];
919 for(Standard_Integer i=0;i<=5;i++){
920 coord[i]=Draw::Atof(argv[2+i]);
922 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
924 gp_Vec myVect (p1,p2);
925 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
926 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
927 GetMapOfAIS().Bind (TheAxis,name);
928 TheAISContext()->Display(TheAxis, Standard_True);
934 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
935 if ( !strcasecmp(argv[0], "vaxis")) {
936 if (aShapes.Extent() != 2 && aShapes.Extent() != 1)
938 std::cerr << "Error: Wrong number of selected shapes.\n";
942 const TopoDS_Shape& aShapeA = aShapes.First();
943 if (aShapeA.ShapeType() == TopAbs_VERTEX)
945 if (aShapes.Extent() != 2)
947 std::cerr << "Error: Wron number of selected shapes.\n";
951 const TopoDS_Shape& aShapeB = aShapes.Last();
952 if (aShapeB.ShapeType() != TopAbs_VERTEX)
954 std::cerr << "Syntax error: You should select two vertices or one edge.\n";
958 // Construction de l'axe
959 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
960 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
963 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
964 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
965 GetMapOfAIS().Bind (TheAxis,name);
966 TheAISContext()->Display (TheAxis, Standard_True);
970 TopoDS_Edge ed =TopoDS::Edge (aShapeA);
972 TopExp::Vertices(ed,Va,Vb );
973 gp_Pnt A=BRep_Tool::Pnt(Va);
974 gp_Pnt B=BRep_Tool::Pnt(Vb);
977 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
978 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
979 GetMapOfAIS().Bind (TheAxis,name);
980 TheAISContext()->Display (TheAxis, Standard_True);
986 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
987 else if ( !strcasecmp(argv[0], "vaxispara"))
989 if (aShapes.Extent() != 2)
991 std::cerr << "Error: Wrong number of selected shapes.\n";
995 const TopoDS_Shape& aShapeA = aShapes.First();
996 const TopoDS_Shape& aShapeB = aShapes.Last();
997 if (!(aShapeA.ShapeType() == TopAbs_EDGE
998 && aShapeB.ShapeType() == TopAbs_VERTEX))
1000 std::cerr << "Syntax error: You should select face and then vertex.\n";
1004 TopoDS_Edge ed=TopoDS::Edge (aShapeA);
1005 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1006 TopoDS_Vertex Va,Vc;
1007 TopExp::Vertices(ed,Va,Vc );
1008 gp_Pnt A=BRep_Tool::Pnt(Va);
1009 gp_Pnt C=BRep_Tool::Pnt(Vc);
1012 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1013 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1014 GetMapOfAIS().Bind (TheAxis,name);
1015 TheAISContext()->Display (TheAxis, Standard_True);
1019 // Fonction axisortho
1022 if (aShapes.Extent() != 2)
1024 std::cerr << "Error: Wrong number of selected shapes.\n";
1028 const TopoDS_Shape& aShapeA = aShapes.First();
1029 const TopoDS_Shape& aShapeB = aShapes.Last();
1030 if (!(aShapeA.ShapeType() == TopAbs_EDGE
1031 && aShapeB.ShapeType() == TopAbs_VERTEX))
1033 std::cerr << "Syntax error: You should select face and then vertex.\n";
1037 // Construction de l'axe
1038 TopoDS_Edge ed=TopoDS::Edge(aShapeA) ;
1039 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) );
1040 TopoDS_Vertex Va,Vc;
1041 TopExp::Vertices(ed,Va,Vc );
1042 gp_Pnt A=BRep_Tool::Pnt(Va);
1043 gp_Pnt C=BRep_Tool::Pnt(Vc);
1044 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
1047 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1048 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1049 GetMapOfAIS().Bind (TheAxis,name);
1050 TheAISContext()->Display (TheAxis, Standard_True);
1059 //==============================================================================
1060 // Fonction First click Result
1062 // vpoint vertex AIS_Point=Vertex
1063 // edge AIS_Point=Middle of the edge
1064 //==============================================================================
1066 //==============================================================================
1067 //function : VPointBuilder
1068 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
1069 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
1070 //==============================================================================
1071 #include <TopoDS_Edge.hxx>
1072 #include <TopoDS_Vertex.hxx>
1073 #include <TopExp.hxx>
1074 #include <AIS_Point.hxx>
1075 #include <Geom_CartesianPoint.hxx>
1077 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1080 Standard_Boolean HasArg;
1081 TCollection_AsciiString name;
1084 if (argc<2 || argc>5 ) {di<<" Syntaxe error\n";return 1;}
1085 if (argc==5) HasArg=Standard_True;
1086 else HasArg=Standard_False;
1090 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
1092 Standard_Real thecoord[3];
1093 for(Standard_Integer i=0;i<=2;i++)
1094 thecoord[i]=Draw::Atof(argv[2+i]);
1095 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
1096 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
1097 GetMapOfAIS().Bind (myAISPoint,name);
1098 TheAISContext()->Display (myAISPoint, Standard_True);
1101 // Il n'a pas d'arguments
1104 TopTools_ListOfShape aShapes;
1105 ViewerTest::GetSelectedShapes (aShapes);
1107 if (aShapes.Extent() != 1)
1109 std::cerr << "Error: Wrong number of selected shapes.\n";
1110 std::cerr << "\tYou should select one edge or vertex.\n";
1114 const TopoDS_Shape& aShapeA = aShapes.First();
1116 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1118 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(aShapeA ) );
1119 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
1120 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
1121 GetMapOfAIS().Bind(myAISPoint,name);
1122 TheAISContext()->Display (myAISPoint, Standard_True);
1126 TopoDS_Edge myEdge=TopoDS::Edge(aShapeA);
1127 TopoDS_Vertex myVertexA,myVertexB;
1128 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
1129 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
1130 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
1131 // M est le milieu de [AB]
1132 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
1133 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
1134 GetMapOfAIS().Bind(myAISPointM,name);
1135 TheAISContext()->Display (myAISPointM, Standard_True);
1143 //==============================================================================
1144 // Function 1st click 2de click 3de click
1145 // vplane Vertex Vertex Vertex
1149 // vplanepara Face Vertex
1151 // vplaneortho Face Edge
1153 //==============================================================================
1155 //==============================================================================
1156 //function : VPlaneBuilder
1157 //purpose : Build an AIS_Plane from selected entities or Named AIS components
1158 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
1159 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
1160 // [PlaneName] [PointName] [TypeOfSensitivity]
1161 //==============================================================================
1163 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
1164 Standard_Integer argc,
1168 Standard_Boolean hasArg;
1169 TCollection_AsciiString aName;
1172 if (argc<2 || argc>6 )
1174 std::cout<<" Syntax error\n";
1177 if (argc == 6 || argc==5 || argc==4)
1178 hasArg=Standard_True;
1180 hasArg=Standard_False;
1184 // There are some arguments
1187 Handle(AIS_InteractiveObject) aShapeA;
1188 if (!GetMapOfAIS().Find2 (argv[2], aShapeA))
1190 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
1194 // The first argument is an AIS_Point
1195 if (!aShapeA.IsNull() &&
1196 aShapeA->Type()==AIS_KOI_Datum &&
1197 aShapeA->Signature()==1)
1199 // The second argument must also be an AIS_Point
1200 Handle(AIS_InteractiveObject) aShapeB;
1201 if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1203 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
1206 // If B is not an AIS_Point
1207 if (aShapeB.IsNull() ||
1208 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1210 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
1213 // The third object is an AIS_Point
1214 Handle(AIS_InteractiveObject) aShapeC;
1215 if (!GetMapOfAIS().Find2(argv[4], aShapeC))
1217 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
1220 // If C is not an AIS_Point
1221 if (aShapeC.IsNull() ||
1222 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
1224 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
1228 // Treatment of objects A, B, C
1229 // Downcast an AIS_IO to AIS_Point
1230 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
1231 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
1232 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
1234 Handle(Geom_CartesianPoint ) aCartPointA =
1235 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
1237 Handle(Geom_CartesianPoint ) aCartPointB =
1238 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
1240 Handle(Geom_CartesianPoint ) aCartPointC =
1241 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
1243 // Verification that the three points are different
1244 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
1245 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1246 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
1249 std::cout<<"vplane error: same points\n";return 1;
1251 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1252 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1253 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1256 std::cout<<"vplane error: same points\n";return 1;
1258 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1259 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1260 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1263 std::cout<<"vplane error: same points\n";return 1;
1266 gp_Pnt A = aCartPointA->Pnt();
1267 gp_Pnt B = aCartPointB->Pnt();
1268 gp_Pnt C = aCartPointC->Pnt();
1270 // Construction of AIS_Plane
1271 GC_MakePlane MkPlane (A,B,C);
1272 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1273 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1274 GetMapOfAIS().Bind (anAISPlane,aName );
1277 Standard_Integer aType = Draw::Atoi (argv[5]);
1278 if (aType != 0 && aType != 1)
1280 std::cout << "vplane error: wrong type of sensitivity!\n"
1281 << "Should be one of the following values:\n"
1289 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1292 TheAISContext()->Display (anAISPlane, Standard_True);
1295 // The first argument is an AIS_Axis
1296 // Creation of a plane orthogonal to the axis through a point
1297 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1298 // The second argument should be an AIS_Point
1299 Handle(AIS_InteractiveObject) aShapeB;
1300 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1302 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1305 // If B is not an AIS_Point
1306 if (aShapeB.IsNull() ||
1307 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1309 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1313 // Treatment of objects A and B
1314 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1315 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1317 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1318 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1320 gp_Ax1 anAxis = aGeomLineA->Position();
1321 Handle(Geom_CartesianPoint) aCartPointB =
1322 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1324 gp_Dir D =anAxis.Direction();
1325 gp_Pnt B = aCartPointB->Pnt();
1327 // Construction of AIS_Plane
1328 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1329 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1330 GetMapOfAIS().Bind (anAISPlane,aName );
1333 Standard_Integer aType = Draw::Atoi (argv[4]);
1334 if (aType != 0 && aType != 1)
1336 std::cout << "vplane error: wrong type of sensitivity!\n"
1337 << "Should be one of the following values:\n"
1345 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1348 TheAISContext()->Display (anAISPlane, Standard_True);
1351 // The first argumnet is an AIS_Plane
1352 // Creation of a plane parallel to the plane passing through the point
1353 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1355 // The second argument should be an AIS_Point
1356 Handle(AIS_InteractiveObject) aShapeB;
1357 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1359 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1362 // B should be an AIS_Point
1363 if (aShapeB.IsNull() ||
1364 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1366 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1370 // Treatment of objects A and B
1371 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1372 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1374 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1375 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1377 Handle(Geom_CartesianPoint) aCartPointB =
1378 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1379 gp_Pnt B= aCartPointB->Pnt();
1381 // Construction of an AIS_Plane
1382 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1383 GetMapOfAIS().Bind (anAISPlane, aName);
1386 Standard_Integer aType = Draw::Atoi (argv[4]);
1387 if (aType != 0 && aType != 1)
1389 std::cout << "vplane error: wrong type of sensitivity!\n"
1390 << "Should be one of the following values:\n"
1398 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1401 TheAISContext()->Display (anAISPlane, Standard_True);
1406 std::cout<<"vplane: error 1st object is not an AIS\n";
1410 // There are no arguments
1413 TopTools_ListOfShape aShapes;
1414 ViewerTest::GetSelectedShapes (aShapes);
1417 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1418 if (!strcasecmp(argv[0], "vplane"))
1420 if (aShapes.Extent() < 1 || aShapes.Extent() > 3)
1422 std::cerr << "Error: Wront number of selected shapes.\n";
1423 std::cerr << "\tYou should one of variant: face, edge and vertex or three vertices.\n";
1427 const TopoDS_Shape& aShapeA = aShapes.First();
1428 if (aShapeA.ShapeType() == TopAbs_VERTEX)
1430 if (aShapes.Extent() == 2)
1432 const TopoDS_Shape& aShapeB = aShapes.Last();
1433 if (aShapeB.ShapeType() != TopAbs_EDGE)
1435 std::cerr << "Syntax error: Together with vertex should be edge.\n";
1439 // Verify that the vertex is not on the edge ShapeB
1440 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1441 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1443 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1444 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1446 // The vertex is on the edge
1447 std::cout<<" vplane: error point is on the edge\n";
1452 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1453 TopoDS_Vertex aVBa, aVBb;
1454 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1455 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1456 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1457 GC_MakePlane MkPlane (A, aBa, aBb);
1458 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1459 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1460 GetMapOfAIS().Bind (anAISPlane, aName);
1461 TheAISContext()->Display (anAISPlane, Standard_True);
1464 else if (aShapes.Extent() == 3)
1466 TopTools_ListOfShape::Iterator anIter (aShapes);
1469 const TopoDS_Shape& aShapeB = anIter.Value();
1472 const TopoDS_Shape& aShapeC = anIter.Value();
1474 if (!(aShapeB.ShapeType() == TopAbs_VERTEX
1475 && aShapeC.ShapeType() == TopAbs_VERTEX))
1477 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1481 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1482 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1483 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1484 GC_MakePlane MkPlane(A, B, C);
1485 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1486 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1487 GetMapOfAIS().Bind (anAISPlane, aName);
1488 TheAISContext()->Display (anAISPlane, Standard_True);
1492 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1496 else if (aShapeA.ShapeType() == TopAbs_EDGE)
1498 if (aShapes.Extent() != 2)
1500 std::cerr << "Error: wrong number of selected shapes.\n";
1504 const TopoDS_Shape& aShapeB = aShapes.Last();
1505 if (aShapeB.ShapeType() != TopAbs_VERTEX)
1507 std::cerr << "Syntax error: Together with edge should be vertex.\n";
1511 // Check that the vertex aShapeB is not on the edge
1512 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1513 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1515 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1516 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1518 // The vertex is on the edge
1519 std::cout<<" vplane: error point is on the edge\n";
1523 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1524 TopoDS_Vertex aVAa, aVAb;
1525 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1526 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1527 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1528 GC_MakePlane MkPlane (B,Aa,Ab);
1529 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1530 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1531 GetMapOfAIS().Bind (anAISPlane ,aName);
1532 TheAISContext()->Display (anAISPlane, Standard_True);
1534 else if (aShapeA.ShapeType() == TopAbs_FACE)
1536 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1537 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1538 if (aSurface.GetType()==GeomAbs_Plane)
1540 gp_Pln aPlane = aSurface.Plane();
1541 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1542 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1543 GetMapOfAIS().Bind (anAISPlane, aName);
1544 TheAISContext()->Display (anAISPlane, Standard_True);
1548 std::cout<<" vplane: error\n";
1554 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1559 // Function vPlanePara
1560 // ===================
1561 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1562 else if (!strcasecmp(argv[0], "vplanepara"))
1564 if (aShapes.Extent() != 2)
1566 std::cerr << "Error: Wrong number of selected shapes.\n";
1570 const TopoDS_Shape* aShapeA = &aShapes.First();
1571 const TopoDS_Shape* aShapeB = &aShapes.Last();
1572 if (aShapeA->ShapeType() != TopAbs_VERTEX)
1574 std::swap (aShapeA, aShapeB);
1577 if (!(aShapeA->ShapeType() == TopAbs_VERTEX
1578 && aShapeB->ShapeType() == TopAbs_FACE))
1580 std::cerr << "Syntax error: you should select face and vertex.\n";
1584 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA));
1586 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1587 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1588 if (aSurface.GetType() == GeomAbs_Plane)
1590 gp_Pln aPlane = aSurface.Plane();
1591 // Construct a plane parallel to aGeomPlane through A
1592 aPlane.SetLocation(A);
1593 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1594 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1595 GetMapOfAIS().Bind (aAISPlane ,aName);
1596 TheAISContext()->Display (aAISPlane, Standard_True);
1600 std::cerr << "Error: Builded surface is not a plane.\n";
1605 // Function vplaneortho
1606 // ====================
1607 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1610 if (aShapes.Extent() != 2)
1612 std::cerr << "Error: wrong number of selected shapes.\n";
1616 const TopoDS_Shape* aShapeA = &aShapes.First();
1617 const TopoDS_Shape* aShapeB = &aShapes.Last();
1619 if (aShapeA->ShapeType() != TopAbs_EDGE)
1621 std::swap (aShapeA, aShapeB);
1624 if (!(aShapeA->ShapeType() == TopAbs_EDGE
1625 && aShapeB->ShapeType() == TopAbs_FACE))
1627 std::cerr << "Error: you should select edge and face.\n";
1631 // Construction of plane
1632 TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA);
1633 TopoDS_Vertex aVAa, aVAb;
1634 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1635 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1636 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1640 // Creation of rotation axis
1641 gp_Ax1 aRotAxis (Aa,Dab);
1643 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1644 // The edge must be parallel to the face
1645 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1646 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1647 // Compare to heights
1648 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1649 >Precision::Confusion())
1651 // the edge is not parallel to the face
1652 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1656 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1657 if (aSurface.GetType()==GeomAbs_Plane)
1659 gp_Pln aPlane = aSurface.Plane();
1660 // It rotates a half turn round the axis of rotation
1661 aPlane.Rotate(aRotAxis , M_PI/2);
1663 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1664 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1665 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1666 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1667 GetMapOfAIS().Bind (anAISPlane, aName);
1668 TheAISContext()->Display (anAISPlane, Standard_True);
1672 std::cout<<" vplaneortho: error\n";
1680 //===============================================================================================
1681 //function : VChangePlane
1683 //===============================================================================================
1684 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1686 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1687 if (aContextAIS.IsNull())
1689 std::cout << theArgVec[0] << "AIS context is not available.\n";
1693 if (theArgsNb < 3 || theArgsNb > 11)
1695 std::cerr << theArgVec[0]
1696 << ": incorrect number of command arguments.\n"
1697 << "Type help for more information.\n";
1701 TCollection_AsciiString aName (theArgVec[1]);
1703 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1704 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1707 if ( aPlane.IsNull() )
1709 std::cout << theArgVec[0]
1710 << ": there is no interactive plane with the given name."
1711 << "Type help for more information.\n";
1715 Standard_Real aCenterX = aPlane->Center().X();
1716 Standard_Real aCenterY = aPlane->Center().Y();
1717 Standard_Real aCenterZ = aPlane->Center().Z();
1719 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1720 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1721 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1723 Standard_Real aSizeX = 0.0;
1724 Standard_Real aSizeY = 0.0;
1725 aPlane->Size (aSizeX, aSizeY);
1726 Standard_Boolean isUpdate = Standard_True;
1728 TCollection_AsciiString aPName, aPValue;
1729 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1731 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1732 TCollection_AsciiString anArgCase = anArg;
1733 anArgCase.UpperCase();
1734 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1737 if (aPName.IsEqual ("X"))
1739 aCenterX = aPValue.RealValue();
1741 else if (aPName.IsEqual ("Y"))
1743 aCenterY = aPValue.RealValue();
1745 else if (aPName.IsEqual ("Z"))
1747 aCenterZ = aPValue.RealValue();
1749 else if (aPName.IsEqual ("DX"))
1751 aDirX = aPValue.RealValue();
1753 else if (aPName.IsEqual ("DY"))
1755 aDirY = aPValue.RealValue();
1757 else if (aPName.IsEqual ("DZ"))
1759 aDirZ = aPValue.RealValue();
1761 else if (aPName.IsEqual ("SX"))
1763 aSizeX = aPValue.RealValue();
1765 else if (aPName.IsEqual ("SY"))
1767 aSizeY = aPValue.RealValue();
1770 else if (anArg.IsEqual ("NOUPDATE"))
1772 isUpdate = Standard_False;
1776 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1777 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1778 aPlane->SetCenter (aCenterPnt);
1779 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1780 aPlane->SetSize (aSizeX, aSizeY);
1782 aContextAIS->Update (aPlane, isUpdate);
1787 //==============================================================================
1789 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1790 //==============================================================================
1792 //==============================================================================
1793 //function : VLineBuilder
1794 //purpose : Build an AIS_Line
1795 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1796 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1797 //==============================================================================
1798 #include <Geom_CartesianPoint.hxx>
1799 #include <AIS_Line.hxx>
1802 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1805 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; }
1807 // On recupere les parametres
1808 Handle(AIS_InteractiveObject) theShapeA;
1809 Handle(AIS_InteractiveObject) theShapeB;
1811 // Parametres: AIS_Point AIS_Point
1812 // ===============================
1814 GetMapOfAIS().Find2 (argv[2], theShapeA);
1815 // On verifie que c'est bien une AIS_Point
1816 if (!theShapeA.IsNull() &&
1817 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1818 // on recupere le deuxieme AIS_Point
1819 GetMapOfAIS().Find2 (argv[3], theShapeB);
1820 if (theShapeB.IsNull() ||
1821 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1823 di <<"vline error: wrong type of 2de argument.\n";
1827 else {di <<"vline error: wrong type of 1st argument.\n";return 1; }
1828 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1829 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1830 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
1832 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1833 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
1834 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1836 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1837 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
1838 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1840 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1842 di<<"vline error: same points\n";return 1;
1844 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1845 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1846 GetMapOfAIS().Bind(theAISLine,argv[1] );
1847 TheAISContext()->Display (theAISLine, Standard_True);
1851 // Parametres 6 Reals
1852 // ==================
1855 // On verifie que les deux points ne sont pas confondus
1857 Standard_Real coord[6];
1858 for(Standard_Integer i=0;i<=2;i++){
1859 coord[i]=Draw::Atof(argv[2+i]);
1860 coord[i+3]=Draw::Atof(argv[5+i]);
1863 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1864 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1866 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1867 GetMapOfAIS().Bind(theAISLine,argv[1] );
1868 TheAISContext()->Display (theAISLine, Standard_True);
1872 // Pas de parametres: Selection dans le viewer.
1873 // ============================================
1877 TopTools_ListOfShape aShapes;
1878 ViewerTest::GetSelectedShapes (aShapes);
1879 if (aShapes.Extent() != 2)
1881 std::cerr << "Error: wrong number of selected shapes.\n";
1885 const TopoDS_Shape& aShapeA = aShapes.First();
1886 const TopoDS_Shape& aShapeB = aShapes.Last();
1888 if (!(aShapeA.ShapeType() == TopAbs_VERTEX
1889 && aShapeB.ShapeType() == TopAbs_VERTEX))
1891 std::cerr << "Error: you should select two different vertex.\n";
1895 // Construction de la line
1896 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1897 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
1899 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1900 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1902 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1903 GetMapOfAIS().Bind(theAISLine,argv[1] );
1904 TheAISContext()->Display (theAISLine, Standard_True);
1910 //==============================================================================
1911 // class : FilledCircle
1912 // purpose : creates filled circle based on AIS_InteractiveObject
1914 // This class is used to check method Matches() of class
1915 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1916 // because none of AIS classes provides creation of
1917 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1918 // (look method ComputeSelection() )
1919 //==============================================================================
1921 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1923 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1924 gp_Circ aCirc(anAxes, theRadius);
1925 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1929 class FilledCircle : public AIS_InteractiveObject
1933 DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject);
1935 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1936 FilledCircle(Handle(Geom_Circle) theCircle);
1939 TopoDS_Face ComputeFace();
1941 // Virtual methods implementation
1942 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1943 const Handle(Prs3d_Presentation)& thePresentation,
1944 const Standard_Integer theMode) Standard_OVERRIDE;
1946 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1947 const Standard_Integer theMode) Standard_OVERRIDE;
1950 Handle(Geom_Circle) myCircle;
1951 Standard_Boolean myFilledStatus;
1956 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1958 myCircle = CreateCircle(theCenter, theRadius);
1959 myFilledStatus = Standard_True;
1962 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1964 myCircle = theCircle;
1965 myFilledStatus = Standard_True;
1968 TopoDS_Face FilledCircle::ComputeFace()
1970 // Create edge from myCircle
1971 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1972 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1974 // Create wire from anEdge
1975 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1976 TopoDS_Wire aWire = aWireMaker.Wire();
1978 // Create face from aWire
1979 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1980 TopoDS_Face aFace = aFaceMaker.Face();
1985 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1986 const Handle(Prs3d_Presentation) &thePresentation,
1987 const Standard_Integer theMode)
1989 thePresentation->Clear();
1991 TopoDS_Face aFace = ComputeFace();
1993 if (aFace.IsNull()) return;
1994 if (theMode != 0) return;
1996 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1999 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
2000 const Standard_Integer /*theMode*/)
2002 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2003 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2004 myCircle, myFilledStatus);
2005 theSelection->Add(aSensitiveCircle);
2008 //==============================================================================
2010 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2011 //==============================================================================
2013 //==============================================================================
2014 //function : VCircleBuilder
2015 //purpose : Build an AIS_Circle
2016 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2017 // PointName PointName PointName IsFilled
2018 //==============================================================================
2020 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2021 TCollection_AsciiString theName,
2022 Standard_Boolean isFilled)
2024 Handle(AIS_InteractiveObject) aCircle;
2027 aCircle = new FilledCircle(theGeomCircle);
2031 aCircle = new AIS_Circle(theGeomCircle);
2032 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2035 // Check if there is an object with given name
2036 // and remove it from context
2037 if (GetMapOfAIS().IsBound2(theName))
2039 Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2(theName);
2040 TheAISContext()->Remove(anInterObj, Standard_False);
2041 GetMapOfAIS().UnBind2(theName);
2044 // Bind the circle to its name
2045 GetMapOfAIS().Bind(aCircle, theName);
2047 // Display the circle
2048 TheAISContext()->Display (aCircle, Standard_True);
2052 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2054 // Verification of the arguments
2055 if (argc>6 || argc<2)
2057 std::cout << "vcircle error: expect 4 arguments.\n";
2058 return 1; // TCL_ERROR
2061 // There are all arguments
2065 TCollection_AsciiString aName(argv[1]);
2066 Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0;
2068 Handle(AIS_InteractiveObject) theShapeA, theShapeB;
2069 GetMapOfAIS().Find2 (argv[2], theShapeA);
2070 GetMapOfAIS().Find2 (argv[3], theShapeB);
2072 // Arguments: AIS_Point AIS_Point AIS_Point
2073 // ========================================
2074 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2075 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2077 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2079 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2080 return 1; // TCL_ERROR
2082 // The third object must be a point
2083 Handle(AIS_InteractiveObject) theShapeC;
2084 GetMapOfAIS().Find2 (argv[4], theShapeC);
2085 if (theShapeC.IsNull() ||
2086 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2088 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2089 return 1; // TCL_ERROR
2092 // Verify that the three points are different
2093 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2094 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2095 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2097 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2098 Handle(Geom_CartesianPoint) myCartPointA =
2099 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2101 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2102 Handle(Geom_CartesianPoint) myCartPointB =
2103 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2105 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2106 Handle(Geom_CartesianPoint) myCartPointC =
2107 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2110 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2111 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2112 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2114 std::cout << "vcircle error: Same points.\n";
2115 return 1; // TCL_ERROR
2118 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2119 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2120 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2122 std::cout << "vcircle error: Same points.\n";
2123 return 1; // TCL_ERROR
2126 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2127 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2128 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2130 std::cout << "vcircle error: Same points.\n";
2131 return 1;// TCL_ERROR
2133 // Construction of the circle
2134 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2135 myCartPointB->Pnt(), myCartPointC->Pnt() );
2136 Handle (Geom_Circle) theGeomCircle;
2139 theGeomCircle = Cir.Value();
2141 catch (StdFail_NotDone const&)
2143 std::cout << "vcircle error: can't create circle\n";
2144 return -1; // TCL_ERROR
2147 DisplayCircle(theGeomCircle, aName, isFilled);
2150 // Arguments: AIS_Plane AIS_Point Real
2151 // ===================================
2152 else if (theShapeA->Type() == AIS_KOI_Datum &&
2153 theShapeA->Signature() == 7 )
2155 if (theShapeB->Type() != AIS_KOI_Datum ||
2156 theShapeB->Signature() != 1 )
2158 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2159 return 1; // TCL_ERROR
2161 // Check that the radius is >= 0
2162 if (Draw::Atof(argv[4]) <= 0 )
2164 std::cout << "vcircle error: the radius must be >=0.\n";
2165 return 1; // TCL_ERROR
2168 // Recover the normal to the plane
2169 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2170 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2172 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2173 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2174 Handle(Geom_CartesianPoint) myCartPointB =
2175 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2177 gp_Pln mygpPlane = myGeomPlane->Pln();
2178 gp_Ax1 thegpAxe = mygpPlane.Axis();
2179 gp_Dir theDir = thegpAxe.Direction();
2180 gp_Pnt theCenter = myCartPointB->Pnt();
2181 Standard_Real TheR = Draw::Atof(argv[4]);
2182 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2183 Handle (Geom_Circle) theGeomCircle;
2186 theGeomCircle = Cir.Value();
2188 catch (StdFail_NotDone const&)
2190 std::cout << "vcircle error: can't create circle\n";
2191 return -1; // TCL_ERROR
2194 DisplayCircle(theGeomCircle, aName, isFilled);
2201 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2202 return 1; // TCL_ERROR
2206 // No arguments: selection in the viewer
2207 // =========================================
2210 // Get the name of the circle
2211 TCollection_AsciiString aName(argv[1]);
2213 TopTools_ListOfShape aShapes;
2214 ViewerTest::GetSelectedShapes (aShapes);
2215 if (aShapes.Extent() != 3 && aShapes.Extent() != 2)
2217 std::cerr << "Error: Wrong number of selected shapes.\n";
2221 const TopoDS_Shape& aShapeA = aShapes.First();
2222 if (aShapeA.ShapeType() == TopAbs_VERTEX )
2224 if (aShapes.Extent() != 3)
2226 std::cerr << "Error: wrong number of selected shapes.\n";
2230 TopTools_ListOfShape::Iterator anIter (aShapes);
2233 const TopoDS_Shape& aShapeB = anIter.Value();
2236 const TopoDS_Shape& aShapeC = anIter.Value();
2239 Standard_Boolean isFilled;
2240 std::cout << "Enter filled status (0 or 1)\n";
2243 // Construction of the circle
2244 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
2245 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2246 gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC));
2248 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2249 Handle (Geom_Circle) theGeomCircle;
2252 theGeomCircle = Cir.Value();
2254 catch (StdFail_NotDone const&)
2256 std::cout << "vcircle error: can't create circle\n";
2257 return -1; // TCL_ERROR
2260 DisplayCircle(theGeomCircle, aName, isFilled);
2263 else if (aShapeA.ShapeType() == TopAbs_FACE)
2265 const TopoDS_Shape& aShapeB = aShapes.Last();
2267 // Recover the radius
2268 Standard_Real theRad;
2271 std::cout << " Enter the value of the radius:\n";
2273 } while (theRad <= 0);
2275 // Get filled status
2276 Standard_Boolean isFilled;
2277 std::cout << "Enter filled status (0 or 1)\n";
2280 // Recover the normal to the plane. tag
2281 TopoDS_Face myFace = TopoDS::Face(aShapeA);
2282 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2283 gp_Pln myPlane = mySurface.Plane();
2284 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2285 gp_Pln mygpPlane = theGeomPlane->Pln();
2286 gp_Ax1 thegpAxe = mygpPlane.Axis();
2287 gp_Dir theDir = thegpAxe.Direction();
2289 // Recover the center
2290 gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2292 // Construct the circle
2293 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2294 Handle (Geom_Circle) theGeomCircle;
2297 theGeomCircle = Cir.Value();
2299 catch (StdFail_NotDone const&)
2301 std::cout << "vcircle error: can't create circle\n";
2302 return -1; // TCL_ERROR
2305 DisplayCircle(theGeomCircle, aName, isFilled);
2309 std::cerr << "Error: You should select face and vertex or three vertices.\n";
2317 //=======================================================================
2318 //function : VDrawText
2320 //=======================================================================
2321 static int VDrawText (Draw_Interpretor& theDI,
2322 Standard_Integer theArgsNb,
2323 const char** theArgVec)
2325 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2328 std::cout << "Error: wrong number of arguments! See usage:\n";
2329 theDI.PrintHelp (theArgVec[0]);
2332 else if (aContext.IsNull())
2334 std::cout << "Error: no active view!\n";
2338 Standard_Integer anArgIt = 1;
2339 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2340 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2341 Handle(AIS_TextLabel) aTextPrs;
2342 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2344 Standard_Boolean isNewPrs = Standard_False;
2345 if (GetMapOfAIS().IsBound2 (aName))
2347 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2350 if (aTextPrs.IsNull())
2352 isNewPrs = Standard_True;
2353 aTextPrs = new AIS_TextLabel();
2354 aTextPrs->SetFont ("Courier");
2357 aTextPrs->SetText (aText);
2359 Handle(Graphic3d_TransformPers) aTrsfPers;
2360 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2362 Standard_Boolean aHasPlane = Standard_False;
2367 for (; anArgIt < theArgsNb; ++anArgIt)
2369 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2372 if (anAutoUpdater.parseRedrawMode (aParam))
2376 else if (aParam == "-pos"
2377 || aParam == "-position")
2379 if (anArgIt + 3 >= theArgsNb)
2381 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2385 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2386 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2387 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2388 aTextPrs->SetPosition (aPos);
2390 else if (aParam == "-color")
2392 if (anArgIt + 1 >= theArgsNb)
2394 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2398 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2399 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2400 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2403 aTextPrs->SetColor (aNameOfColor);
2406 else if (anArgIt + 3 >= theArgsNb)
2408 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2412 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2413 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2414 if (!aColor.IsRealValue()
2415 || !aGreen.IsRealValue()
2416 || !aBlue.IsRealValue())
2418 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2422 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2426 aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2429 else if (aParam == "-halign")
2431 if (++anArgIt >= theArgsNb)
2433 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2437 TCollection_AsciiString aType (theArgVec[anArgIt]);
2439 if (aType == "left")
2441 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2443 else if (aType == "center")
2445 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2447 else if (aType == "right")
2449 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2453 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2457 else if (aParam == "-valign")
2459 if (++anArgIt >= theArgsNb)
2461 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2465 TCollection_AsciiString aType (theArgVec[anArgIt]);
2469 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2471 else if (aType == "center")
2473 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2475 else if (aType == "bottom")
2477 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2479 else if (aType == "topfirstline")
2481 aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2485 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2489 else if (aParam == "-angle")
2491 if (++anArgIt >= theArgsNb)
2493 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2497 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2499 else if (aParam == "-zoom")
2501 if (++anArgIt >= theArgsNb)
2503 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2507 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2509 else if (aParam == "-height")
2511 if (++anArgIt >= theArgsNb)
2513 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2517 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2519 else if (aParam == "-aspect")
2521 if (++anArgIt >= theArgsNb)
2523 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2527 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2528 anOption.LowerCase();
2529 Font_FontAspect aFontAspect = Font_FA_Undefined;
2530 if (!parseFontStyle (anOption, aFontAspect))
2532 std::cout << "Error: unknown font aspect '" << anOption << "'.\n";
2535 aTextPrs->SetFontAspect (aFontAspect);
2537 else if (aParam == "-font")
2539 if (++anArgIt >= theArgsNb)
2541 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2545 aTextPrs->SetFont (theArgVec[anArgIt]);
2547 else if (aParam == "-plane")
2549 if (anArgIt + 6 >= theArgsNb)
2551 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2555 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
2556 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
2557 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
2558 aNormal.SetCoord (aX, aY, aZ);
2560 aX = Draw::Atof (theArgVec[++anArgIt]);
2561 aY = Draw::Atof (theArgVec[++anArgIt]);
2562 aZ = Draw::Atof (theArgVec[++anArgIt]);
2563 aDirection.SetCoord (aX, aY, aZ);
2565 aHasPlane = Standard_True;
2567 else if (aParam == "-flipping")
2569 aTextPrs->SetFlipping (Standard_True);
2571 else if (aParam == "-disptype"
2572 || aParam == "-displaytype")
2574 if (++anArgIt >= theArgsNb)
2576 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2579 TCollection_AsciiString aType (theArgVec[anArgIt]);
2581 if (aType == "subtitle")
2582 aDisplayType = Aspect_TODT_SUBTITLE;
2583 else if (aType == "decal")
2584 aDisplayType = Aspect_TODT_DEKALE;
2585 else if (aType == "blend")
2586 aDisplayType = Aspect_TODT_BLEND;
2587 else if (aType == "dimension")
2588 aDisplayType = Aspect_TODT_DIMENSION;
2589 else if (aType == "normal")
2590 aDisplayType = Aspect_TODT_NORMAL;
2591 else if (aType == "shadow")
2592 aDisplayType = Aspect_TODT_SHADOW;
2595 std::cout << "Error: wrong display type '" << aType << "'.\n";
2599 else if (aParam == "-subcolor"
2600 || aParam == "-subtitlecolor")
2602 if (anArgIt + 1 >= theArgsNb)
2604 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2608 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2609 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2610 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2613 aTextPrs->SetColorSubTitle (aNameOfColor);
2616 else if (anArgIt + 3 >= theArgsNb)
2618 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2622 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2623 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2624 if (!aColor.IsRealValue()
2625 || !aGreen.IsRealValue()
2626 || !aBlue.IsRealValue())
2628 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2632 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2636 aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2639 else if (aParam == "-2d")
2641 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d);
2643 else if (aParam == "-trsfperspos"
2644 || aParam == "-perspos")
2646 if (anArgIt + 2 >= theArgsNb)
2648 std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2652 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2653 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2654 TCollection_AsciiString aZ = "0";
2655 if (!aX.IsIntegerValue()
2656 || !aY.IsIntegerValue())
2658 std::cerr << "Error: wrong syntax at '" << aParam << "'.\n";
2661 if (anArgIt + 1 < theArgsNb)
2663 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2664 if (aTemp.IsIntegerValue())
2671 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()));
2675 std::cout << "Error: unknown argument '" << aParam << "'\n";
2682 aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2685 aTextPrs->SetDisplayType (aDisplayType);
2687 if (!aTrsfPers.IsNull())
2689 aContext->SetTransformPersistence (aTextPrs, aTrsfPers);
2690 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2691 if (aTextPrs->Position().Z() != 0)
2693 aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
2696 else if (!aTextPrs->TransformPersistence().IsNull())
2698 aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
2703 ViewerTest::Display (aName, aTextPrs, Standard_False);
2707 aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
2713 #include <gp_Pnt.hxx>
2714 #include <Graphic3d_ArrayOfPoints.hxx>
2715 #include <Graphic3d_ArrayOfPrimitives.hxx>
2716 #include <Graphic3d_ArrayOfTriangles.hxx>
2717 #include <Poly_Array1OfTriangle.hxx>
2718 #include <Poly_Triangle.hxx>
2719 #include <Poly_Triangulation.hxx>
2720 #include <TColgp_Array1OfPnt.hxx>
2721 #include <TShort_Array1OfShortReal.hxx>
2722 #include <TShort_HArray1OfShortReal.hxx>
2724 #include <AIS_Triangulation.hxx>
2725 #include <StdPrs_ToolTriangulatedShape.hxx>
2726 #include <Poly_Connect.hxx>
2727 #include <TColgp_Array1OfDir.hxx>
2728 #include <Graphic3d_GraphicDriver.hxx>
2730 #include <TColStd_Array1OfInteger.hxx>
2731 #include <TColStd_HArray1OfInteger.hxx>
2732 #include <Prs3d_ShadingAspect.hxx>
2733 #include <Graphic3d_MaterialAspect.hxx>
2734 #include <Graphic3d_AspectFillArea3d.hxx>
2736 #include <BRepPrimAPI_MakeCylinder.hxx>
2737 #include <TopoDS_Shape.hxx>
2738 #include <TopExp_Explorer.hxx>
2739 #include <TopAbs.hxx>
2740 #include <StdSelect_ShapeTypeFilter.hxx>
2741 #include <AIS_InteractiveObject.hxx>
2744 //===============================================================================================
2745 //function : CalculationOfSphere
2747 //purpose : Create a Sphere
2748 //===============================================================================================
2750 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2753 double mRadius = Radius;
2754 double mCenter[3] = {X,Y,Z};
2755 int mThetaResolution;
2757 double mStartTheta = 0;//StartTheta;
2758 double mEndTheta = 360;//EndTheta;
2759 double mStartPhi = 0;//StartPhi;
2760 double mEndPhi = 180;//EndPhi;
2761 res = res < 4 ? 4 : res;
2763 mThetaResolution = res;
2764 mPhiResolution = res;
2767 int jStart, jEnd, numOffset;
2768 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2769 double startTheta, endTheta, startPhi, endPhi;
2770 int base, numPoles=0, thetaResolution, phiResolution;
2775 if ( numPieces > mThetaResolution ) {
2776 numPieces = mThetaResolution;
2779 int localThetaResolution = mThetaResolution;
2780 double localStartTheta = mStartTheta;
2781 double localEndTheta = mEndTheta;
2783 while ( localEndTheta < localStartTheta ) {
2784 localEndTheta += 360.0;
2787 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2789 // Change the ivars based on pieces.
2791 start = piece * localThetaResolution / numPieces;
2792 end = (piece+1) * localThetaResolution / numPieces;
2793 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2794 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2795 localThetaResolution = end - start;
2797 // Create north pole if needed
2798 int number_point = 0;
2799 int number_pointArray = 0;
2801 if ( mStartPhi <= 0.0 ) {
2802 number_pointArray++;
2805 if ( mEndPhi >= 180.0 ) {
2806 number_pointArray++;
2810 // Check data, determine increments, and convert to radians
2811 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2812 startTheta *= M_PI / 180.0;
2813 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2814 endTheta *= M_PI / 180.0;
2817 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2818 startPhi *= M_PI / 180.0;
2819 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2820 endPhi *= M_PI / 180.0;
2822 phiResolution = mPhiResolution - numPoles;
2823 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2824 thetaResolution = localThetaResolution;
2825 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2826 ++localThetaResolution;
2828 deltaTheta = (endTheta - startTheta) / thetaResolution;
2830 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2831 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2833 // Create intermediate points
2834 for ( i = 0; i < localThetaResolution; i++ ) {
2835 for ( j = jStart; j < jEnd; j++ ) {
2836 number_pointArray++;
2840 //Generate mesh connectivity
2841 base = phiResolution * localThetaResolution;
2843 int number_triangle = 0 ;
2844 if ( mStartPhi <= 0.0 ) { // around north pole
2845 number_triangle += localThetaResolution;
2848 if ( mEndPhi >= 180.0 ) { // around south pole
2849 number_triangle += localThetaResolution;
2852 // bands in-between poles
2853 for ( i=0; i < localThetaResolution; i++){
2854 for ( j=0; j < (phiResolution-1); j++){
2855 number_triangle +=2;
2859 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2860 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2861 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2863 if ( mStartPhi <= 0.0 ){
2866 x[2] = mCenter[2] + mRadius;
2867 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2870 // Create south pole if needed
2871 if ( mEndPhi >= 180.0 ){
2874 x[2] = mCenter[2] - mRadius;
2875 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2879 for ( i=0; i < localThetaResolution; i++){
2880 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2881 for ( j = jStart; j < jEnd; j++){
2882 phi = startPhi + j*deltaPhi;
2883 radius = mRadius * sin((double)phi);
2884 n[0] = radius * cos((double)theta);
2885 n[1] = radius * sin((double)theta);
2886 n[2] = mRadius * cos((double)phi);
2887 x[0] = n[0] + mCenter[0];
2888 x[1] = n[1] + mCenter[1];
2889 x[2] = n[2] + mCenter[2];
2890 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2896 number_triangle = 1;
2897 if ( mStartPhi <= 0.0 ){// around north pole
2898 for (i=0; i < localThetaResolution; i++){
2899 pts[0] = phiResolution*i + numPoles;
2900 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2902 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2907 if ( mEndPhi >= 180.0 ){ // around south pole
2908 numOffset = phiResolution - 1 + numPoles;
2909 for (i=0; i < localThetaResolution; i++){
2910 pts[0] = phiResolution*i + numOffset;
2911 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2912 pts[1] = numPoles - 1;
2913 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2918 // bands in-between poles
2920 for (i=0; i < localThetaResolution; i++){
2921 for (j=0; j < (phiResolution-1); j++){
2922 pts[0] = phiResolution*i + j + numPoles;
2923 pts[1] = pts[0] + 1;
2924 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2925 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2928 pts[2] = pts[1] - 1;
2929 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2934 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2936 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2938 Standard_Integer index[3];
2939 Standard_Real Tol = Precision::Confusion();
2942 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2943 gp_XYZ eqPlan(0, 0, 0);
2944 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2945 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2946 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2947 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2949 Standard_Real mod = vv.Modulus();
2950 if(mod < Tol) continue;
2954 Standard_Real modmax = eqPlan.Modulus();
2957 Nor = gp_Dir(eqPlan);
2959 Nor = gp_Dir(0., 0., 1.);
2961 Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
2962 Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
2963 Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
2964 Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
2968 polyTriangulation->SetNormals(Normals);
2970 return polyTriangulation;
2973 //===============================================================================================
2974 //function : VDrawSphere
2976 //purpose : Create an AIS shape.
2977 //===============================================================================================
2978 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2981 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2982 if (aContextAIS.IsNull())
2984 std::cout << "Call vinit before!\n";
2989 std::cout << "Use: " << argv[0]
2990 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2994 // read the arguments
2995 TCollection_AsciiString aShapeName (argv[1]);
2996 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2997 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2998 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2999 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
3000 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
3001 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
3002 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
3004 // remove AIS object with given name from map
3005 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
3008 std::cout << "Compute Triangulation...\n";
3009 Handle(AIS_Triangulation) aShape
3010 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
3013 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
3014 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
3016 // stupid initialization of Green color in RGBA space as integer
3017 // probably wrong for big-endian CPUs
3018 const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
3020 // setup colors array per vertex
3021 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
3022 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
3024 aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData()));
3026 aShape->SetColors (aColorArray);
3029 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3030 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3031 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
3032 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
3033 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
3034 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
3035 aTotalSize >>= 20; //MB
3036 aNormalsSize >>= 20;
3038 aTrianglesSize >>= 20;
3039 aPolyConnectSize >>= 20;
3042 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
3043 << "NumberOfTriangles: " << aNumberTriangles << "\n"
3044 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
3045 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
3046 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
3047 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
3050 // Setting material properties, very important for desirable visual result!
3051 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
3052 aMat.SetAmbient (0.2f);
3053 aMat.SetSpecular (0.5f);
3054 Handle(Graphic3d_AspectFillArea3d) anAspect
3055 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3057 Quantity_NOC_YELLOW,
3062 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3063 anAspect->SetDrawEdges (toShowEdges);
3064 aShAsp->SetAspect (anAspect);
3065 aShape->Attributes()->SetShadingAspect (aShAsp);
3067 VDisplayAISObject (aShapeName, aShape);
3071 //=============================================================================
3072 //function : VComputeHLR
3074 //=============================================================================
3076 static int VComputeHLR (Draw_Interpretor& ,
3077 Standard_Integer theArgNb,
3078 const char** theArgVec)
3080 TCollection_AsciiString aShapeName, aHlrName;
3085 bool hasViewDirArg = false;
3086 Prs3d_TypeOfHLR anAlgoType = Prs3d_TOH_PolyAlgo;
3087 bool toShowTangentEdges = false, toShowHiddenEdges = false;
3088 int aNbIsolines = 0;
3089 if (Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext())
3092 Handle(V3d_View) aView = ViewerTest::CurrentView();
3093 Standard_Integer aWidth, aHeight;
3094 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3095 Standard_Real aRightX, aRightY, aRightZ;
3096 aView->Window()->Size (aWidth, aHeight);
3098 aView->ConvertWithProj (aWidth, aHeight/2,
3099 aRightX, aRightY, aRightZ,
3100 aDirX, aDirY, aDirZ);
3101 aView->ConvertWithProj (aWidth/2, aHeight/2,
3102 aCentX, aCentY, aCentZ,
3103 aDirX, aDirY, aDirZ);
3105 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3106 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3107 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3108 aProjAx.SetLocation (anEye);
3109 aProjAx.SetDirection (aDir);
3110 aProjAx.SetXDirection (aRight);
3112 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3114 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3115 anArgCase.LowerCase();
3116 if (anArgIter + 1 < theArgNb
3117 && (anArgCase == "-algotype"
3118 || anArgCase == "-algo"
3119 || anArgCase == "-type"))
3121 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
3122 anArgNext.LowerCase();
3123 if (anArgNext == "polyalgo")
3125 anAlgoType = Prs3d_TOH_PolyAlgo;
3127 else if (anArgNext == "algo")
3129 anAlgoType = Prs3d_TOH_Algo;
3133 std::cout << "Syntax error: unknown algo type '" << anArgNext << "'\n";
3137 else if (anArgCase == "-showhiddenedges"
3138 || anArgCase == "-hiddenedges"
3139 || anArgCase == "-hidden")
3141 toShowHiddenEdges = true;
3142 if (anArgIter + 1 < theArgNb
3143 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowHiddenEdges))
3148 else if (anArgCase == "-showtangentedges"
3149 || anArgCase == "-tangentedges"
3150 || anArgCase == "-tangent")
3152 toShowTangentEdges = true;
3153 if (anArgIter + 1 < theArgNb
3154 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowTangentEdges))
3159 else if (anArgIter + 1 < theArgNb
3160 && (anArgCase == "-nbiso"
3161 || anArgCase == "-nbisolines"))
3163 aNbIsolines = Draw::Atoi (theArgVec[++anArgIter]);
3165 else if (aSh.IsNull())
3167 aSh = DBRep::Get (theArgVec[anArgIter]);
3168 aShapeName = theArgVec[anArgIter];
3171 BRep_Builder aBrepBuilder;
3172 BRepTools::Read (aSh, theArgVec[anArgIter], aBrepBuilder);
3175 std::cout << "Syntax error: no shape with name " << theArgVec[anArgIter] << " found\n";
3180 else if (aHlrName.IsEmpty())
3182 aHlrName = theArgVec[anArgIter];
3184 else if (!hasViewDirArg
3185 && anArgIter + 8 < theArgNb)
3187 hasViewDirArg = true;
3189 anEye.SetCoord (Draw::Atof (theArgVec[anArgIter + 0]), Draw::Atof (theArgVec[anArgIter + 1]), Draw::Atof (theArgVec[anArgIter + 2]));
3190 aDir .SetCoord (Draw::Atof (theArgVec[anArgIter + 3]), Draw::Atof (theArgVec[anArgIter + 4]), Draw::Atof (theArgVec[anArgIter + 5]));
3191 anUp .SetCoord (Draw::Atof (theArgVec[anArgIter + 6]), Draw::Atof (theArgVec[anArgIter + 7]), Draw::Atof (theArgVec[anArgIter + 8]));
3192 aProjAx.SetLocation (anEye);
3193 aProjAx.SetDirection (aDir);
3194 aProjAx.SetYDirection (anUp);
3199 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n";
3204 if (aHlrName.IsEmpty() || aSh.IsNull()
3205 || (ViewerTest::GetAISContext().IsNull() && hasViewDirArg))
3207 std::cout << "Syntax error: wrong number of arguments\n";
3211 HLRAlgo_Projector aProjector (aProjAx);
3212 TopoDS_Shape aVisible[6];
3213 TopoDS_Shape aHidden[6];
3214 if (anAlgoType == Prs3d_TOH_PolyAlgo)
3216 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3217 aPolyAlgo->Projector (aProjector);
3218 aPolyAlgo->Load (aSh);
3219 aPolyAlgo->Update();
3221 HLRBRep_PolyHLRToShape aHLRToShape;
3222 aHLRToShape.Update (aPolyAlgo);
3224 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3225 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); // extract visible outlines
3226 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3227 if (toShowTangentEdges)
3229 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3231 if (toShowHiddenEdges)
3233 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3234 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3235 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3236 if (toShowTangentEdges)
3238 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3244 Handle(HLRBRep_Algo) aHlrAlgo = new HLRBRep_Algo();
3245 aHlrAlgo->Add (aSh, aNbIsolines);
3246 aHlrAlgo->Projector (aProjector);
3250 HLRBRep_HLRToShape aHLRToShape (aHlrAlgo);
3251 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3252 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound();
3253 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3254 if (toShowTangentEdges)
3256 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3258 aVisible[HLRBRep_IsoLine] = aHLRToShape.IsoLineVCompound();
3260 if (toShowHiddenEdges)
3262 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3263 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3264 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3265 if (toShowTangentEdges)
3267 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3269 aHidden[HLRBRep_IsoLine] = aHLRToShape.IsoLineHCompound();
3272 //aVisible[HLRBRep_Sharp] = aHLRToShape.CompoundOfEdges (HLRBRep_Sharp, Standard_True, Standard_True);
3273 //aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound3d();
3276 TopoDS_Compound aCompRes, aCompVis, aCompHid;
3277 BRep_Builder aBuilder;
3278 aBuilder.MakeCompound (aCompVis);
3279 aBuilder.MakeCompound (aCompHid);
3280 aBuilder.MakeCompound (aCompRes);
3281 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3283 if (!aVisible[aTypeIter].IsNull())
3285 aBuilder.Add (aCompVis, aVisible[aTypeIter]);
3287 if (!aHidden[aTypeIter].IsNull())
3289 aBuilder.Add (aCompHid, aHidden[aTypeIter]);
3292 aBuilder.Add (aCompRes, aCompVis);
3293 aBuilder.Add (aCompRes, aCompHid);
3295 // create an AIS shape and display it
3296 if (!ViewerTest::GetAISContext().IsNull())
3298 Handle(AIS_ColoredShape) anObject = new AIS_ColoredShape (aCompRes);
3299 if (toShowHiddenEdges)
3301 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect (Quantity_Color (Quantity_NOC_RED), Aspect_TOL_DASH, 1.0f);
3302 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3304 if (!aHidden[aTypeIter].IsNull())
3306 Handle(AIS_ColoredDrawer) aDrawer = anObject->CustomAspects (aHidden[aTypeIter]);
3307 aDrawer->SetLineAspect (aLineAspect);
3308 aDrawer->SetWireAspect (aLineAspect);
3309 aDrawer->SetFreeBoundaryAspect (aLineAspect);
3310 aDrawer->SetUnFreeBoundaryAspect (aLineAspect);
3314 ViewerTest::Display (aHlrName, anObject, true);
3317 DBRep::Set (aHlrName.ToCString(), aCompRes);
3321 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3322 // manipulating and displaying such an array with AIS context
3324 class MyPArrayObject : public AIS_InteractiveObject
3329 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives)& thePArray) : myPArray (thePArray) {}
3331 MyPArrayObject (Graphic3d_TypeOfPrimitiveArray thePrimType,
3332 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3333 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect)
3335 Init (thePrimType, theDesc, theMarkerAspect, Standard_False);
3338 //! Initialize the array from specified description.
3339 Standard_Boolean Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3340 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3341 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3342 Standard_Boolean theToPatch);
3344 DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
3346 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
3350 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3351 const Handle(Prs3d_Presentation)& aPresentation,
3352 const Standard_Integer aMode) Standard_OVERRIDE;
3354 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3355 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
3357 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3358 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3359 Standard_Integer &theArgIndex,
3360 Standard_Integer theArgCount,
3361 Standard_Integer theMaxArgs);
3365 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3366 Handle(Graphic3d_ArrayOfPrimitives) myPArray;
3370 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3371 const Handle(Prs3d_Presentation)& thePrs,
3372 const Standard_Integer theMode)
3374 if (myPArray.IsNull() || theMode != 0)
3379 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
3380 if (!myMarkerAspect.IsNull())
3382 aGroup->SetGroupPrimitivesAspect (myMarkerAspect);
3386 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
3388 aGroup->AddPrimitiveArray (myPArray);
3391 Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3392 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3393 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3394 Standard_Boolean theToPatch)
3396 myMarkerAspect = theMarkerAspect;
3402 // Parsing array description
3403 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3404 Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None;
3406 const Standard_Integer anArgsCount = theDesc->Length();
3407 TCollection_AsciiString aCommand;
3408 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3410 aCommand = theDesc->Value (anArgIndex);
3411 aCommand.LowerCase();
3413 if (CheckInputCommand ("-deinterleaved", theDesc, anArgIndex, 0, anArgsCount))
3415 anArrayFlags |= Graphic3d_ArrayFlags_AttribsDeinterleaved;
3417 else if (CheckInputCommand ("-mutable", theDesc, anArgIndex, 0, anArgsCount))
3419 anArrayFlags |= Graphic3d_ArrayFlags_AttribsMutable;
3420 anArrayFlags |= Graphic3d_ArrayFlags_IndexesMutable;
3423 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3425 // vertex has a normal or normal with color or texel
3426 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3428 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal;
3431 // vertex has a color
3432 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3434 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor;
3437 // vertex has a texel
3438 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3440 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel;
3446 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3449 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3451 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor;
3457 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3466 if (myPArray.IsNull())
3468 myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
3472 if (myPArray->Type() != thePrimType
3473 || aVertexNum > myPArray->VertexNumberAllocated()
3474 || aEdgeNum > myPArray->EdgeNumberAllocated()
3475 || aBoundNum > myPArray->BoundNumberAllocated()
3476 || !myPArray->Attributes()->IsMutable()
3477 || (!myPArray->Indices().IsNull() && !myPArray->Indices()->IsMutable()))
3479 std::cout << "Syntax error: array cannot be patched\n";
3480 return Standard_False;
3483 myPArray->Attributes()->NbElements = aVertexNum;
3484 if (Handle(Graphic3d_AttribBuffer) anAttribs = Handle(Graphic3d_AttribBuffer)::DownCast (myPArray->Attributes()))
3486 anAttribs->Invalidate (0, aVertexNum - 1);
3488 if (!myPArray->Indices().IsNull())
3490 myPArray->Indices()->NbElements = aEdgeNum;
3492 if (!myPArray->Bounds().IsNull())
3494 myPArray->Bounds()->NbBounds = aBoundNum;
3498 Standard_Integer aVertIndex = 0;
3499 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3501 aCommand = theDesc->Value (anArgIndex);
3502 aCommand.LowerCase();
3503 if (!aCommand.IsAscii()
3504 || aCommand.IsEmpty())
3509 // skip beautifiers (syntax is not actually validated)
3510 if (aCommand == "-deinterleaved"
3511 || aCommand == "-mutable"
3512 || aCommand.Value (1) == '('
3513 || aCommand.Value (1) == ')'
3514 || aCommand.Value (1) == ',')
3519 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3521 const Graphic3d_Vec3 aVert ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3522 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3523 (float )theDesc->Value (anArgIndex - 1).RealValue());
3524 if ((anArrayFlags & Graphic3d_ArrayFlags_AttribsDeinterleaved) != 0
3525 || (anArrayFlags & Graphic3d_ArrayFlags_AttribsMutable) != 0)
3528 myPArray->SetVertice (aVertIndex, aVert.x(), aVert.y(), aVert.z());
3532 aVertIndex = myPArray->AddVertex (aVert);
3535 // vertex has a normal or normal with color or texel
3536 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3538 const Graphic3d_Vec3 aNorm ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3539 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3540 (float )theDesc->Value (anArgIndex - 1).RealValue());
3541 myPArray->SetVertexNormal (aVertIndex, aNorm.x(), aNorm.y(), aNorm.z());
3544 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3546 const Graphic3d_Vec3d aCol (theDesc->Value (anArgIndex - 3).RealValue(),
3547 theDesc->Value (anArgIndex - 2).RealValue(),
3548 theDesc->Value (anArgIndex - 1).RealValue());
3549 myPArray->SetVertexColor (aVertIndex, aCol.r(), aCol.g(), aCol.b());
3551 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3553 const Graphic3d_Vec2 aTex ((float )theDesc->Value (anArgIndex - 2).RealValue(),
3554 (float )theDesc->Value (anArgIndex - 1).RealValue());
3555 myPArray->SetVertexTexel (aVertIndex, aTex.x(), aTex.y());
3559 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3561 Standard_Integer aVertCount = theDesc->Value (anArgIndex - 1).IntegerValue();
3563 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3564 myPArray->AddBound (aVertCount,
3565 theDesc->Value (anArgIndex - 3).RealValue(),
3566 theDesc->Value (anArgIndex - 2).RealValue(),
3567 theDesc->Value (anArgIndex - 1).RealValue());
3570 myPArray->AddBound (aVertCount);
3573 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3575 const Standard_Integer anEdge = theDesc->Value (anArgIndex - 1).IntegerValue();
3576 myPArray->AddEdge (anEdge);
3581 std::cout << "Syntax error: unknown argument '" << theDesc->Value(anArgIndex) << "'\n";
3582 return Standard_False;
3585 return Standard_True;
3588 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3589 const Standard_Integer theMode)
3592 || myPArray.IsNull())
3597 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
3598 if (Handle(Graphic3d_ArrayOfTriangles) aTris = Handle(Graphic3d_ArrayOfTriangles)::DownCast (myPArray))
3600 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3601 aSensitive->InitTriangulation (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3602 theSelection->Add (aSensitive);
3604 else if (Handle(Graphic3d_ArrayOfSegments) aSegs = Handle(Graphic3d_ArrayOfSegments)::DownCast (myPArray))
3606 if (aSegs->EdgeNumber() > 0)
3608 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->EdgeNumber(); aPntIter += 2)
3610 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aSegs->Edge (aPntIter)), aSegs->Vertice (aSegs->Edge (aPntIter + 1)));
3611 aSeg->SetSensitivityFactor (4);
3612 theSelection->Add (aSeg);
3617 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->VertexNumber(); aPntIter += 2)
3619 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aPntIter), aSegs->Vertice (aPntIter + 1));
3620 aSeg->SetSensitivityFactor (4);
3621 theSelection->Add (aSeg);
3627 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3628 aSensitive->SetSensitivityFactor (8);
3629 aSensitive->InitPoints (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3630 theSelection->Add (aSensitive);
3634 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3635 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3636 Standard_Integer &theArgIndex,
3637 Standard_Integer theArgCount,
3638 Standard_Integer theMaxArgs)
3640 // check if there is more elements than expected
3641 if (theArgIndex >= theMaxArgs)
3644 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3645 aStrCommand.LowerCase();
3646 if (aStrCommand.Search(theCommand) != 1 ||
3647 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3650 // go to the first data element
3653 // check data if it can be converted to numeric
3654 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3656 aStrCommand = theArgsArray->Value (theArgIndex);
3657 if (!aStrCommand.IsRealValue())
3664 //=============================================================================
3665 //function : VDrawPArray
3666 //purpose : Draws primitives array from list of vertexes, bounds, edges
3667 //=============================================================================
3669 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3671 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3672 if (aContextAIS.IsNull())
3674 std::cout << "Error: no active Viewer\n";
3679 std::cout << "Syntax error: wrong number of arguments\n";
3683 // read the arguments
3684 Standard_Integer anArgIndex = 1;
3685 TCollection_AsciiString aName (argv[anArgIndex++]);
3686 TCollection_AsciiString anArrayType (argv[anArgIndex++]);
3687 anArrayType.LowerCase();
3688 Handle(MyPArrayObject) aPObject;
3689 if (anArrayType == "-shape")
3691 Standard_CString aShapeName = argv[anArgIndex++];
3692 TopoDS_Shape aShape = DBRep::Get (aShapeName);
3693 Handle(Graphic3d_ArrayOfPrimitives) aTris = StdPrs_ShadedShape::FillTriangles (aShape);
3694 if (aShape.IsNull())
3696 std::cout << "Syntax error: shape '" << aShapeName << "' is not found\n";
3699 else if (aTris.IsNull())
3701 std::cout << "Syntax error: shape '" << aShapeName << "' is not triangulated\n";
3705 aPObject = new MyPArrayObject (aTris);
3706 ViewerTest::Display (aName, aPObject);
3709 else if (anArrayType == "-patch"
3710 || anArrayType == "-modify"
3711 || anArrayType == "-edit")
3715 anArrayType = argv[anArgIndex++];
3716 anArrayType.LowerCase();
3719 if (GetMapOfAIS().IsBound2 (aName))
3721 aPObject = Handle(MyPArrayObject)::DownCast (GetMapOfAIS().Find2 (aName));
3723 if (aPObject.IsNull())
3725 std::cout << "Syntax error: object '" << aName << "' cannot be found\n";
3730 Standard_Boolean hasVertex = Standard_False;
3732 Graphic3d_TypeOfPrimitiveArray aPrimType = Graphic3d_TOPA_UNDEFINED;
3733 if (anArrayType == "points")
3735 aPrimType = Graphic3d_TOPA_POINTS;
3737 else if (anArrayType == "segments")
3739 aPrimType = Graphic3d_TOPA_SEGMENTS;
3741 else if (anArrayType == "polylines")
3743 aPrimType = Graphic3d_TOPA_POLYLINES;
3745 else if (anArrayType == "triangles")
3747 aPrimType = Graphic3d_TOPA_TRIANGLES;
3749 else if (anArrayType == "trianglefans")
3751 aPrimType = Graphic3d_TOPA_TRIANGLEFANS;
3753 else if (anArrayType == "trianglestrips")
3755 aPrimType = Graphic3d_TOPA_TRIANGLESTRIPS;
3757 else if (anArrayType == "quads")
3759 aPrimType = Graphic3d_TOPA_QUADRANGLES;
3761 else if (anArrayType == "quadstrips")
3763 aPrimType = Graphic3d_TOPA_QUADRANGLESTRIPS;
3765 else if (anArrayType == "polygons")
3767 aPrimType = Graphic3d_TOPA_POLYGONS;
3769 if (aPrimType == Graphic3d_TOPA_UNDEFINED)
3771 std::cout << "Syntax error: unexpected type of primitives array\n";
3775 Standard_Integer aLowerArg = anArgIndex;
3776 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 3);
3777 for (; anArgIndex < argc; ++anArgIndex)
3779 TCollection_AsciiString aCommand (argv[anArgIndex]);
3780 aCommand.LowerCase();
3781 if (!aCommand.IsAscii())
3783 di << "Unexpected argument: #" << anArgIndex - 1 << " , "
3784 << "should be an array element: 'v', 'b', 'e' \n";
3788 if (aCommand == "v")
3790 hasVertex = Standard_True;
3793 anArgsArray->SetValue (anArgIndex - aLowerArg, aCommand);
3798 di << "You should pass any verticies in the list of array elements\n";
3802 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3803 if (aPrimType == Graphic3d_TOPA_POINTS)
3805 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3808 // create primitives array object
3809 if (aPObject.IsNull())
3811 // register the object in map
3812 aPObject = new MyPArrayObject (aPrimType, anArgsArray, anAspPoints);
3813 VDisplayAISObject (aName, aPObject);
3817 aPObject->Init (aPrimType, anArgsArray, anAspPoints, Standard_True);
3818 ViewerTest::CurrentView()->Redraw();
3825 //! Auxiliary function for parsing translation vector - either 2D or 3D.
3826 static Standard_Integer parseTranslationVec (Standard_Integer theArgNb,
3827 const char** theArgVec,
3835 TCollection_AsciiString anX (theArgVec[0]);
3836 TCollection_AsciiString anY (theArgVec[1]);
3837 if (!anX.IsRealValue()
3838 || !anY.IsRealValue())
3843 theVec.SetX (anX.RealValue());
3844 theVec.SetY (anY.RealValue());
3847 TCollection_AsciiString anZ (theArgVec[2]);
3848 if (anZ.IsRealValue())
3850 theVec.SetZ (anZ.RealValue());
3858 //=======================================================================
3859 //function : VSetLocation
3860 //purpose : Change location of AIS interactive object
3861 //=======================================================================
3863 static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
3864 Standard_Integer theArgNb,
3865 const char** theArgVec)
3867 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3868 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3869 if (aContext.IsNull())
3871 std::cout << "Error: no active view!\n";
3875 Standard_Boolean toPrintInfo = Standard_True;
3876 Handle(AIS_InteractiveObject) anObj;
3877 TCollection_AsciiString aCmdName (theArgVec[0]);
3878 aCmdName.LowerCase();
3879 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3881 TCollection_AsciiString anArg = theArgVec[anArgIter];
3883 if (anUpdateTool.parseRedrawMode (anArg))
3887 else if (anObj.IsNull())
3889 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3890 GetMapOfAIS().Find2 (aName, anObj);
3893 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3897 else if (anArg == "-reset")
3899 toPrintInfo = Standard_False;
3900 aContext->SetLocation (anObj, gp_Trsf());
3902 else if (anArg == "-copyfrom"
3903 || anArg == "-copy")
3905 if (anArgIter + 1 >= theArgNb)
3907 std::cout << "Syntax error at '" << anArg << "'\n";
3911 const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]);
3912 Handle(AIS_InteractiveObject) anObj2;
3913 GetMapOfAIS().Find2 (aName2, anObj2);
3914 if (anObj2.IsNull())
3916 std::cout << "Error: object '" << aName2 << "' is not displayed!\n";
3921 aContext->SetLocation (anObj, anObj2->LocalTransformation());
3923 else if (anArg == "-rotate")
3925 toPrintInfo = Standard_False;
3926 if (anArgIter + 7 >= theArgNb)
3928 std::cout << "Syntax error at '" << anArg << "'\n";
3933 aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]),
3934 Draw::Atof (theArgVec[anArgIter + 2]),
3935 Draw::Atof (theArgVec[anArgIter + 3])),
3936 gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]),
3937 Draw::Atof (theArgVec[anArgIter + 5]),
3938 Draw::Atof (theArgVec[anArgIter + 6]))),
3939 Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0));
3942 aTrsf = anObj->LocalTransformation() * aTrsf;
3943 aContext->SetLocation (anObj, aTrsf);
3945 else if (anArg == "-translate")
3947 toPrintInfo = Standard_False;
3949 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
3950 anArgIter += aNbParsed;
3953 std::cout << "Syntax error at '" << anArg << "'\n";
3958 aTrsf.SetTranslationPart (aLocVec);
3959 aTrsf = anObj->LocalTransformation() * aTrsf;
3960 aContext->SetLocation (anObj, aTrsf);
3962 else if (anArg == "-scale"
3963 || anArg == "-setscale")
3965 toPrintInfo = Standard_False;
3967 Standard_Real aScale = 1.0;
3968 Standard_Boolean toPrintScale = Standard_True;
3969 Standard_Boolean hasScaleLoc = Standard_False;
3970 if (anArgIter + 4 < theArgNb)
3972 TCollection_AsciiString aScaleArgs[4] =
3974 TCollection_AsciiString (theArgVec[anArgIter + 1]),
3975 TCollection_AsciiString (theArgVec[anArgIter + 2]),
3976 TCollection_AsciiString (theArgVec[anArgIter + 3]),
3977 TCollection_AsciiString (theArgVec[anArgIter + 4])
3979 Standard_Integer aScaleArgIter = 0;
3980 for (; aScaleArgIter < 4; ++aScaleArgIter)
3982 if (!aScaleArgs[aScaleArgIter].IsRealValue())
3987 if (aScaleArgIter == 4)
3989 aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue());
3990 aScale = aScaleArgs[3].RealValue();
3992 toPrintScale = Standard_False;
3993 hasScaleLoc = Standard_True;
3995 else if (aScaleArgIter >= 1)
3997 aScale = aScaleArgs[0].RealValue();
3999 toPrintScale = Standard_False;
4002 else if (anArgIter + 1 < theArgNb)
4004 TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]);
4005 if (aScaleArg.IsRealValue())
4007 aScale = aScaleArg.RealValue();
4009 toPrintScale = Standard_False;
4015 if (anArg == "-setscale")
4017 std::cout << "Syntax error at '" << anArg << "'\n";
4022 Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor());
4027 if (anArg == "-setscale")
4029 gp_Trsf aTrsf = anObj->LocalTransformation();
4032 aTrsf.SetScale (aScaleLoc, aScale);
4036 aTrsf.SetScaleFactor (aScale);
4038 aContext->SetLocation (anObj, aTrsf);
4045 aTrsf.SetScale (aScaleLoc, aScale);
4046 aTrsf = anObj->LocalTransformation() * aTrsf;
4050 aTrsf = anObj->LocalTransformation();
4051 aTrsf.SetScaleFactor (aTrsf.ScaleFactor() * aScale);
4053 aContext->SetLocation (anObj, aTrsf);
4056 else if (anArg == "-mirror")
4058 toPrintInfo = Standard_False;
4059 if (anArgIter + 6 >= theArgNb)
4061 std::cout << "Syntax error at '" << anArg << "'\n";
4066 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
4067 Draw::Atof(theArgVec[theArgNb - 5]),
4068 Draw::Atof(theArgVec[theArgNb - 4])),
4069 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
4070 Draw::Atof(theArgVec[theArgNb - 2]),
4071 Draw::Atof(theArgVec[theArgNb - 1]))));
4073 aTrsf = anObj->LocalTransformation() * aTrsf;
4074 aContext->SetLocation (anObj, aTrsf);
4076 else if (anArg == "-setrotation"
4077 || anArg == "-rotation")
4079 toPrintInfo = Standard_False;
4080 if (anArgIter + 4 < theArgNb)
4082 TCollection_AsciiString aQuatArgs[4] =
4084 TCollection_AsciiString (theArgVec[anArgIter + 1]),
4085 TCollection_AsciiString (theArgVec[anArgIter + 2]),
4086 TCollection_AsciiString (theArgVec[anArgIter + 3]),
4087 TCollection_AsciiString (theArgVec[anArgIter + 4])
4089 Standard_Integer aQuatArgIter = 0;
4090 for (; aQuatArgIter < 4; ++aQuatArgIter)
4092 if (!aQuatArgs[aQuatArgIter].IsRealValue())
4098 if (aQuatArgIter == 4)
4101 const gp_Quaternion aQuat (aQuatArgs[0].RealValue(),
4102 aQuatArgs[1].RealValue(),
4103 aQuatArgs[2].RealValue(),
4104 aQuatArgs[3].RealValue());
4105 gp_Trsf aTrsf = anObj->LocalTransformation();
4106 aTrsf.SetRotation (aQuat);
4107 aContext->SetLocation (anObj, aTrsf);
4110 else if (anArg == "-setrotation")
4112 std::cout << "Syntax error at '" << anArg << "'\n";
4118 const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation();
4119 Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W());
4122 else if (anArg == "-setlocation"
4123 || anArg == "-location")
4125 toPrintInfo = Standard_False;
4127 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
4128 anArgIter += aNbParsed;
4131 gp_Trsf aTrsf = anObj->LocalTransformation();
4132 aTrsf.SetTranslationPart (aLocVec);
4133 aContext->SetLocation (anObj, aTrsf);
4135 else if (anArg == "-setlocation")
4137 std::cout << "Syntax error at '" << anArg << "'\n";
4142 const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart();
4143 Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z());
4146 else if (aCmdName == "vsetlocation")
4148 // compatibility with old syntax
4150 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec);
4153 std::cout << "Syntax error at '" << anArg << "'\n";
4156 anArgIter = anArgIter + aNbParsed - 1;
4159 aTrsf.SetTranslationPart (aLocVec);
4160 aContext->SetLocation (anObj, aTrsf);
4161 toPrintInfo = Standard_False;
4165 std::cout << "Error: unknown argument '" << anArg << "'\n";
4172 std::cout << "Syntax error - wrong number of arguments\n";
4175 else if (!toPrintInfo)
4180 const gp_Trsf aTrsf = anObj->LocalTransformation();
4181 const gp_XYZ aLoc = aTrsf.TranslationPart();
4182 const gp_Quaternion aRot = aTrsf.GetRotation();
4184 Sprintf (aText, "Location: %g %g %g\n"
4185 "Rotation: %g %g %g %g\n"
4187 aLoc.X(), aLoc.Y(), aLoc.Z(),
4188 aRot.X(), aRot.Y(), aRot.Z(), aRot.W(),
4189 aTrsf.ScaleFactor());
4194 //===============================================================================================
4195 //function : VConnect
4196 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4197 //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
4198 //===============================================================================================
4200 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
4201 Standard_Integer argc,
4205 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4206 if (aContext.IsNull())
4208 std::cout << "vconnect error : call vinit before\n";
4209 return 1; // TCL_ERROR
4214 std::cout << "vconnect error: expect at least 5 arguments\n";
4215 return 1; // TCL_ERROR
4219 Standard_Integer anArgIter = 1;
4220 TCollection_AsciiString aName (argv[anArgIter++]);
4221 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
4222 TCollection_AsciiString aColorString (argv[argc-1]);
4223 Standard_CString aColorName = "";
4224 Standard_Boolean hasColor = Standard_False;
4225 if (aColorString.Search ("color=") != -1)
4227 hasColor = Standard_True;
4228 aColorString.Remove (1, 6);
4229 aColorName = aColorString.ToCString();
4231 Handle(AIS_InteractiveObject) anObject;
4233 // AIS_MultipleConnectedInteractive
4234 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
4235 for (Standard_Integer i = 5; i < aNbShapes; ++i)
4237 TCollection_AsciiString anOriginObjectName (argv[i]);
4238 if (aName.IsEqual (anOriginObjectName))
4240 std::cout << "vconnect error: equal names for connected objects\n";
4243 if (GetMapOfAIS().Find2 (anOriginObjectName, anObject))
4245 if (anObject.IsNull())
4247 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4253 Standard_CString aOriginName = anOriginObjectName.ToCString();
4254 TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4255 if (aTDShape.IsNull())
4257 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4260 anObject = new AIS_Shape (aTDShape);
4261 aContext->Load (anObject);
4262 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
4265 if (anOriginObject.IsNull())
4267 anOriginObject = new AIS_MultipleConnectedInteractive();
4270 anOriginObject->Connect (anObject);
4272 if (anOriginObject.IsNull())
4274 std::cout << "vconect error : can't connect input objects\n";
4275 return 1; // TCL_ERROR
4278 // Get location data
4279 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4280 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4281 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4283 // Create transformation
4284 gp_Vec aTranslation (aXo, aYo, aZo);
4287 aTrsf.SetTranslationPart (aTranslation);
4288 TopLoc_Location aLocation (aTrsf);
4290 anOriginObject->SetLocalTransformation (aTrsf);
4292 // Check if there is another object with given name
4293 // and remove it from context
4294 Handle(AIS_InteractiveObject) anObj;
4295 if (GetMapOfAIS().Find2 (aName, anObj))
4297 TheAISContext()->Remove(anObj, Standard_False);
4298 GetMapOfAIS().UnBind2(aName);
4301 // Bind connected object to its name
4302 GetMapOfAIS().Bind (anOriginObject, aName);
4304 // Display connected object
4305 TheAISContext()->Display (anOriginObject, Standard_True);
4310 //===============================================================================================
4311 //function : VConnectTo
4312 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4313 //Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
4314 //===============================================================================================
4316 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
4317 Standard_Integer argc,
4321 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4322 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4323 if (aContext.IsNull())
4325 std::cout << "vconnect error : call vinit before\n";
4326 return 1; // TCL_ERROR
4329 if (argc != 6 && argc != 7)
4331 std::cout << "vconnect error: expect at least 5 arguments\n";
4332 return 1; // TCL_ERROR
4336 Standard_Integer anArgIter = 1;
4337 TCollection_AsciiString aName (argv[anArgIter++]);
4338 Handle(AIS_InteractiveObject) anOriginObject;
4340 TCollection_AsciiString anOriginObjectName(argv[5]);
4341 if (aName.IsEqual (anOriginObjectName))
4343 std::cout << "vconnect error: equal names for connected objects\n";
4344 return 1; // TCL_ERROR
4346 if (GetMapOfAIS().Find2 (anOriginObjectName, anOriginObject))
4348 if (anOriginObject.IsNull())
4350 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4351 return 1; // TCL_ERROR
4356 Standard_CString aOriginName = anOriginObjectName.ToCString();
4357 TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4358 if (aTDShape.IsNull())
4360 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4361 return 1; // TCL_ERROR
4363 anOriginObject = new AIS_Shape (aTDShape);
4364 GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
4367 // Get location data
4368 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4369 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4370 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4372 // Create transformation
4373 gp_Vec aTranslation (aXo, aYo, aZo);
4376 aTrsf.SetTranslationPart (aTranslation);
4378 Handle(AIS_ConnectedInteractive) aConnected;
4380 aConnected = new AIS_ConnectedInteractive();
4382 aConnected->Connect (anOriginObject, aTrsf);
4384 // Check if there is another object with given name
4385 // and remove it from context
4386 Handle(AIS_InteractiveObject) anObj;
4387 if (GetMapOfAIS().Find2 (aName, anObj))
4389 TheAISContext()->Remove (anObj, Standard_False);
4390 GetMapOfAIS().UnBind2(aName);
4393 // Bind connected object to its name
4394 GetMapOfAIS().Bind (aConnected, aName);
4398 TCollection_AsciiString anArg = argv[6];
4400 if (anArg == "-nodisplay")
4403 if (!anUpdateTool.parseRedrawMode (anArg))
4405 std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
4409 // Display connected object
4410 TheAISContext()->Display (aConnected, Standard_False);
4415 //=======================================================================
4416 //function : VDisconnect
4418 //=======================================================================
4419 static Standard_Integer VDisconnect (Draw_Interpretor& di,
4420 Standard_Integer argc,
4423 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4424 if (aContext.IsNull())
4426 std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4432 std::cout << "ERROR : Usage : " << argv[0] << " name object\n";
4436 TCollection_AsciiString aName (argv[1]);
4437 TCollection_AsciiString anObject (argv[2]);
4438 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
4441 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4442 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4443 if (!aMap.IsBound2 (aName) )
4445 std::cout << "Use 'vdisplay' before\n";
4449 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4450 if (anAssembly.IsNull())
4452 di << "Not an assembly\n";
4456 Handle(AIS_InteractiveObject) anIObj;
4457 if (!aMap.Find2 (anObject, anIObj))
4459 // try to interpret second argument as child number
4460 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
4462 Standard_Integer aCounter = 1;
4463 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4465 if (aCounter == anObjectNumber)
4467 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4475 std::cout << "Use 'vdisplay' before\n";
4480 aContext->Disconnect (anAssembly, anIObj);
4481 aContext->UpdateCurrentViewer();
4485 //=======================================================================
4486 //function : VAddConnected
4488 //=======================================================================
4489 static Standard_Integer VAddConnected (Draw_Interpretor& di,
4490 Standard_Integer argc,
4493 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4494 if (aContext.IsNull())
4496 std::cout << argv[0] << "error : use 'vinit' command before \n";
4502 std::cout << argv[0] << " error: expect 5 arguments\n";
4506 TCollection_AsciiString aName (argv[1]);
4507 TCollection_AsciiString anObject (argv[5]);
4508 Standard_Real aX = Draw::Atof (argv[2]);
4509 Standard_Real aY = Draw::Atof (argv[3]);
4510 Standard_Real aZ = Draw::Atof (argv[4]);
4513 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4514 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4515 if (!aMap.IsBound2 (aName) )
4517 std::cout << "Use 'vdisplay' before\n";
4521 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4522 if (anAssembly.IsNull())
4524 di << "Not an assembly\n";
4528 Handle(AIS_InteractiveObject) anIObj;
4529 if (!aMap.Find2 (anObject, anIObj))
4531 std::cout << "Use 'vdisplay' before\n";
4536 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4538 anAssembly->Connect (anIObj, aTrsf);
4539 TheAISContext()->Display (anAssembly, Standard_False);
4540 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4541 aContext->UpdateCurrentViewer();
4546 //=======================================================================
4547 //function : VListConnected
4549 //=======================================================================
4550 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4551 Standard_Integer argc,
4554 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4555 if (aContext.IsNull())
4557 std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4563 std::cout << "ERROR : Usage : " << argv[0] << " name\n";
4567 TCollection_AsciiString aName (argv[1]);
4570 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4571 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4572 if (!aMap.IsBound2 (aName) )
4574 std::cout << "Use 'vdisplay' before\n";
4578 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4579 if (anAssembly.IsNull())
4581 std::cout << "Not an assembly\n";
4585 std::cout << "Children of " << aName << ":\n";
4587 Standard_Integer aCounter = 1;
4588 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4590 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4591 if (GetMapOfAIS().IsBound1 (anObj))
4593 TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anObj);
4594 std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4597 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4599 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4600 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4602 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4604 std::cout << std::endl;
4612 //===============================================================================================
4613 //function : VSetSelectionMode
4614 //purpose : vselmode
4615 //===============================================================================================
4616 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4617 Standard_Integer theNbArgs,
4618 const char** theArgv)
4621 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4622 if (anAISContext.IsNull())
4624 std::cout << "Error: no active Viewer\n";
4628 NCollection_Sequence<TCollection_AsciiString> anObjNames;
4629 Standard_Integer aSelectionMode = -1;
4630 Standard_Boolean toTurnOn = Standard_True;
4631 AIS_SelectionModesConcurrency aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4632 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4634 TCollection_AsciiString anArgCase (theArgv[anArgIter]);
4635 anArgCase.LowerCase();
4636 if (anArgCase == "-set"
4637 || anArgCase == "-replace"
4638 || anArgCase == "-single"
4639 || anArgCase == "-exclusive")
4641 aSelModeConcurrency = AIS_SelectionModesConcurrency_Single;
4643 else if (anArgCase == "-add"
4644 || anArgCase == "-combine"
4645 || anArgCase == "-combination"
4646 || anArgCase == "-multiple")
4648 aSelModeConcurrency = AIS_SelectionModesConcurrency_Multiple;
4650 else if (anArgCase == "-globalorlocal"
4651 || anArgCase == "-localorglobal")
4653 aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4657 anObjNames.Append (theArgv[anArgIter]);
4660 if (anObjNames.Size() < 2
4661 || !ViewerTest::ParseOnOff (anObjNames.Last().ToCString(), toTurnOn))
4663 std::cout << "Syntax error: wrong number of arguments\n";
4666 anObjNames.Remove (anObjNames.Upper());
4668 const TCollection_AsciiString aSelModeString = anObjNames.Last();
4669 anObjNames.Remove (anObjNames.Upper());
4670 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4671 if (aSelModeString.IsIntegerValue())
4673 aSelectionMode = aSelModeString.IntegerValue();
4675 else if (TopAbs::ShapeTypeFromString (aSelModeString.ToCString(), aShapeType))
4677 aSelectionMode = AIS_Shape::SelectionMode (aShapeType);
4681 std::cout << "Syntax error: unknown selection mode '" << aSelModeString << "'\n";
4686 AIS_ListOfInteractive aTargetIOs;
4687 for (NCollection_Sequence<TCollection_AsciiString>::Iterator anObjIter (anObjNames); anObjIter.More(); anObjIter.Next())
4689 const TCollection_AsciiString& aNameIO = anObjIter.Value();
4690 Handle(AIS_InteractiveObject) anIO;
4691 GetMapOfAIS().Find2 (aNameIO, anIO);
4694 std::cout << "Syntax error: undefined presentable object " << aNameIO << "\n";
4697 aTargetIOs.Append (anIO);
4699 if (aTargetIOs.IsEmpty())
4701 anAISContext->DisplayedObjects (aTargetIOs);
4704 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4706 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4707 anAISContext->SetSelectionModeActive (anIO, aSelectionMode, toTurnOn, aSelModeConcurrency);
4712 //===============================================================================================
4713 //function : VSelectionNext
4715 //===============================================================================================
4716 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4717 Standard_Integer /*theArgsNb*/,
4718 const char** /*theArgVec*/)
4721 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4722 Handle(V3d_View) aView = ViewerTest::CurrentView();
4724 if (anAISContext.IsNull())
4726 std::cerr << "Call vinit before!" << std::endl;
4730 anAISContext->HilightNextDetected (aView);
4734 //===============================================================================================
4735 //function : VSelectionPrevious
4737 //===============================================================================================
4738 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4739 Standard_Integer /*theArgsNb*/,
4740 const char** /*theArgVec*/)
4743 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4744 Handle(V3d_View) aView = ViewerTest::CurrentView();
4746 if (anAISContext.IsNull())
4748 std::cerr << "Call vinit before!" << std::endl;
4752 anAISContext->HilightPreviousDetected (aView);
4756 //===========================================================================
4757 //function : VTriangle
4758 //Draw arg : vtriangle Name PointName PointName PointName
4759 //purpose : creates and displays Triangle
4760 //===========================================================================
4761 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4762 Standard_Integer argc,
4765 const Standard_Boolean isTri = TCollection_AsciiString (argv[0]) == "vtriangle";
4766 Handle(Graphic3d_ArrayOfPrimitives) aPrims;
4769 aPrims = new Graphic3d_ArrayOfTriangles (3);
4773 aPrims = new Graphic3d_ArrayOfSegments (2);
4776 if (argc != (2 + aPrims->VertexNumberAllocated()))
4778 std::cout << "Syntax error: wrong number of arguments\n";
4783 for (Standard_Integer aPntIter = 0; aPntIter < aPrims->VertexNumberAllocated(); ++aPntIter)
4785 const TCollection_AsciiString aName (argv[2 + aPntIter]);
4786 if (Handle(AIS_Point) aPntPrs = Handle(AIS_Point)::DownCast (GetMapOfAIS().IsBound2 (aName) ? GetMapOfAIS().Find2 (aName) : NULL))
4788 aPnts[aPntIter] = aPntPrs->Component()->Pnt();
4792 TopoDS_Shape aShape = DBRep::Get (argv[2 + aPntIter]);
4794 || aShape.ShapeType() != TopAbs_VERTEX)
4796 std::cout << "Syntax error: argument " << aName << " must be a point\n";
4799 aPnts[aPntIter] = BRep_Tool::Pnt (TopoDS::Vertex (aShape));
4802 for (Standard_Integer aPnt2Iter = 0; aPnt2Iter < aPntIter; ++aPnt2Iter)
4804 if (aPnts[aPnt2Iter].IsEqual (aPnts[aPntIter], Precision::Confusion()))
4806 std::cout << "Syntax error: points should not be equal\n";
4811 aPrims->AddVertex (aPnts[aPntIter]);
4814 Handle(AIS_InteractiveObject) aPrs = new MyPArrayObject (aPrims);
4817 aPrs->Attributes()->SetupOwnShadingAspect();
4818 aPrs->Attributes()->ShadingAspect()->Aspect()->SetColor (aPrs->Attributes()->LineAspect()->Aspect()->Color());
4820 ViewerTest::Display (argv[1], aPrs);
4824 //=======================================================================
4825 //function : VObjZLayer
4826 //purpose : Set or get z layer id for presentable object
4827 //=======================================================================
4829 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4830 Standard_Integer argc,
4833 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4834 if (aContext.IsNull())
4836 di << argv[0] << "Call 'vinit' before!\n";
4841 TCollection_AsciiString aOperation;
4843 aOperation = TCollection_AsciiString (argv [1]);
4845 // check for correct arguments
4846 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4847 !(argc == 3 && aOperation.IsEqual ("get")))
4849 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4850 di << " set - set layer id for interactive object, layerid - z layer id\n";
4851 di << " get - get layer id of interactive object\n";
4852 di << " argument layerid should be passed for set operation only\n";
4857 TCollection_AsciiString aName (argv[2]);
4858 Handle(AIS_InteractiveObject) anInterObj;
4859 GetMapOfAIS().Find2 (aName, anInterObj);
4860 if (anInterObj.IsNull())
4862 std::cout << "Syntax error: object '" << aName << "' is not displayed\n";
4866 // process operation
4867 if (aOperation.IsEqual ("set"))
4869 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
4870 aContext->SetZLayer (anInterObj, aLayerId);
4872 else if (aOperation.IsEqual ("get"))
4874 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4880 //=======================================================================
4881 //function : VPolygonOffset
4882 //purpose : Set or get polygon offset parameters
4883 //=======================================================================
4884 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
4885 Standard_Integer argc,
4888 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4889 if (aContext.IsNull())
4891 std::cout << argv[0] << " Call 'vinit' before!\n";
4895 if (argc > 2 && argc != 5)
4897 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4898 "without arguments prints the default values" << std::endl;
4903 Handle(AIS_InteractiveObject) anInterObj;
4906 TCollection_AsciiString aName (argv[1]);
4907 if (!GetMapOfAIS().Find2 (aName, anInterObj)
4908 || anInterObj.IsNull())
4910 std::cout << "Syntax error: object '" << aName << "' is not displayed\n";
4915 Standard_Integer aMode;
4916 Standard_ShortReal aFactor, aUnits;
4919 aMode = Draw::Atoi(argv[2]);
4920 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4921 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
4923 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4924 aContext->UpdateCurrentViewer();
4929 if (anInterObj->HasPolygonOffsets())
4931 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4932 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4933 std::cout << "\tMode: " << aMode << std::endl;
4934 std::cout << "\tFactor: " << aFactor << std::endl;
4935 std::cout << "\tUnits: " << aUnits << std::endl;
4940 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4944 std::cout << "Default polygon offset parameters:" << std::endl;
4945 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4946 std::cout << "\tMode: " << aMode << std::endl;
4947 std::cout << "\tFactor: " << aFactor << std::endl;
4948 std::cout << "\tUnits: " << aUnits << std::endl;
4953 // This class is used for testing markers.
4954 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
4959 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
4960 const Standard_Integer& thePointsOnSide,
4961 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
4963 myStartPoint = theStartPoint;
4964 myPointsOnSide = thePointsOnSide;
4965 myMarkerAspect = theMarkerAspect;
4968 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_MarkersArrayObject,AIS_InteractiveObject);
4972 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
4973 const Handle(Prs3d_Presentation)& aPresentation,
4974 const Standard_Integer aMode) Standard_OVERRIDE;
4976 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4977 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
4981 gp_XYZ myStartPoint;
4982 Standard_Integer myPointsOnSide;
4983 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
4987 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
4988 const Handle(Prs3d_Presentation)& aPresentation,
4989 const Standard_Integer /*aMode*/)
4991 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
4992 if (myPointsOnSide == 1)
4994 anArray->AddVertex (myStartPoint);
4998 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5000 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5002 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5004 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5005 anArray->SetVertexColor (anArray->VertexNumber(),
5008 k / myPointsOnSide);
5014 aPresentation->Clear();
5015 if (!myMarkerAspect.IsNull())
5017 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
5019 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
5022 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5023 const Standard_Integer /*theMode*/)
5025 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
5027 if (myPointsOnSide == 1)
5029 gp_Pnt aPoint (myStartPoint);
5030 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5031 theSelection->Add (aSensetivePoint);
5035 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5037 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5039 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5041 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5042 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5043 theSelection->Add (aSensetivePoint);
5049 //=======================================================================
5050 //function : VMarkersTest
5051 //purpose : Draws an array of markers for testing purposes.
5052 //=======================================================================
5053 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5054 Standard_Integer theArgNb,
5055 const char** theArgVec)
5057 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5058 if (aContext.IsNull())
5060 std::cerr << "Call 'vinit' before!\n";
5066 std::cerr << "Usage :\n " << theArgVec[0]
5067 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5071 Standard_Integer anArgIter = 1;
5073 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5074 TCollection_AsciiString aFileName;
5075 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5076 Atof (theArgVec[anArgIter + 1]),
5077 Atof (theArgVec[anArgIter + 2]));
5080 Standard_Integer aPointsOnSide = 10;
5081 Standard_Integer aMarkerType = -1;
5082 Standard_Real aScale = 1.0;
5083 for (; anArgIter < theArgNb; ++anArgIter)
5085 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5086 if (anArg.Search ("PointsOnSide=") > -1)
5088 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5090 else if (anArg.Search ("MarkerType=") > -1)
5092 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5094 else if (anArg.Search ("Scale=") > -1)
5096 aScale = anArg.Token ("=", 2).RealValue();
5098 else if (anArg.Search ("FileName=") > -1)
5100 aFileName = anArg.Token ("=", 2);
5104 std::cerr << "Wrong argument: " << anArg << "\n";
5109 Handle(Graphic3d_AspectMarker3d) anAspect;
5110 Handle(Image_AlienPixMap) anImage;
5111 Quantity_Color aColor (Quantity_NOC_GREEN1);
5112 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5113 && !aFileName.IsEmpty())
5115 anImage = new Image_AlienPixMap();
5116 if (!anImage->Load (aFileName))
5118 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5121 if (anImage->Format() == Image_Format_Gray)
5123 anImage->SetFormat (Image_Format_Alpha);
5125 else if (anImage->Format() == Image_Format_GrayF)
5127 anImage->SetFormat (Image_Format_AlphaF);
5129 anAspect = new Graphic3d_AspectMarker3d (anImage);
5133 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5136 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5137 VDisplayAISObject (aName, aMarkersArray);
5142 //=======================================================================
5143 //function : TextToBrep
5144 //purpose : Tool for conversion text to occt-shapes
5145 //=======================================================================
5146 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5147 Standard_Integer theArgNb,
5148 const char** theArgVec)
5153 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5157 Standard_Integer anArgIt = 1;
5158 Standard_CString aName = theArgVec[anArgIt++];
5159 Standard_CString aText = theArgVec[anArgIt++];
5161 Font_BRepFont aFont;
5162 TCollection_AsciiString aFontName ("Courier");
5163 Standard_Real aTextHeight = 16.0;
5164 Font_FontAspect aFontAspect = Font_FA_Regular;
5165 Standard_Boolean anIsCompositeCurve = Standard_False;
5166 gp_Ax3 aPenAx3 (gp::XOY());
5167 gp_Dir aNormal (0.0, 0.0, 1.0);
5168 gp_Dir aDirection (1.0, 0.0, 0.0);
5171 Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT;
5172 Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM;
5173 Font_StrictLevel aStrictLevel = Font_StrictLevel_Any;
5174 for (; anArgIt < theArgNb; ++anArgIt)
5176 TCollection_AsciiString aParam (theArgVec[anArgIt]);
5179 if (aParam == "-pos"
5180 || aParam == "-position")
5182 if (anArgIt + 3 >= theArgNb)
5184 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5188 aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt]));
5189 aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt]));
5190 aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt]));
5192 else if (aParam == "-halign")
5194 if (++anArgIt >= theArgNb)
5196 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5200 TCollection_AsciiString aType (theArgVec[anArgIt]);
5202 if (aType == "left")
5204 aHJustification = Graphic3d_HTA_LEFT;
5206 else if (aType == "center")
5208 aHJustification = Graphic3d_HTA_CENTER;
5210 else if (aType == "right")
5212 aHJustification = Graphic3d_HTA_RIGHT;
5216 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5220 else if (aParam == "-valign")
5222 if (++anArgIt >= theArgNb)
5224 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5228 TCollection_AsciiString aType (theArgVec[anArgIt]);
5232 aVJustification = Graphic3d_VTA_TOP;
5234 else if (aType == "center")
5236 aVJustification = Graphic3d_VTA_CENTER;
5238 else if (aType == "bottom")
5240 aVJustification = Graphic3d_VTA_BOTTOM;
5242 else if (aType == "topfirstline")
5244 aVJustification = Graphic3d_VTA_TOPFIRSTLINE;
5248 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5252 else if (aParam == "-height")
5254 if (++anArgIt >= theArgNb)
5256 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5260 aTextHeight = Draw::Atof(theArgVec[anArgIt]);
5262 else if (aParam == "-aspect")
5264 if (++anArgIt >= theArgNb)
5266 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5270 TCollection_AsciiString anOption (theArgVec[anArgIt]);
5271 anOption.LowerCase();
5272 if (!parseFontStyle (anOption, aFontAspect))
5274 std::cout << "Error: unknown font aspect '" << anOption << "'.\n";
5278 else if (aParam == "-font")
5280 if (++anArgIt >= theArgNb)
5282 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5286 aFontName = theArgVec[anArgIt];
5288 else if (aParam == "-strict")
5290 anArgIt += parseFontStrictLevel (theArgNb - anArgIt - 1,
5291 theArgVec + anArgIt + 1,
5294 else if (aParam == "-composite")
5296 if (++anArgIt >= theArgNb)
5298 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5302 ViewerTest::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve);
5304 else if (aParam == "-plane")
5306 if (anArgIt + 6 >= theArgNb)
5308 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5312 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
5313 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
5314 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
5315 aNormal.SetCoord (aX, aY, aZ);
5317 aX = Draw::Atof (theArgVec[++anArgIt]);
5318 aY = Draw::Atof (theArgVec[++anArgIt]);
5319 aZ = Draw::Atof (theArgVec[++anArgIt]);
5320 aDirection.SetCoord (aX, aY, aZ);
5324 std::cerr << "Warning! Unknown argument '" << aParam << "'\n";
5328 aFont.SetCompositeCurveMode (anIsCompositeCurve);
5329 if (!aFont.FindAndInit (aFontName.ToCString(), aFontAspect, aTextHeight, aStrictLevel))
5331 std::cout << "Error: unable to load Font\n";
5335 aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection);
5337 Font_BRepTextBuilder aBuilder;
5338 DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification));
5342 //=======================================================================
5344 //purpose : Font management
5345 //=======================================================================
5347 static int VFont (Draw_Interpretor& theDI,
5348 Standard_Integer theArgNb,
5349 const char** theArgVec)
5351 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5354 // just print the list of available fonts
5355 Standard_Boolean isFirst = Standard_True;
5356 const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts();
5357 for (Font_NListOfSystemFont::Iterator anIter (aFonts); anIter.More(); anIter.Next())
5359 const Handle(Font_SystemFont)& aFont = anIter.Value();
5365 theDI << aFont->ToString();
5366 isFirst = Standard_False;
5371 Font_StrictLevel aStrictLevel = Font_StrictLevel_Any;
5372 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5374 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5375 TCollection_AsciiString anArgCase (anArg);
5376 anArgCase.LowerCase();
5377 if (anArgCase == "-strict")
5379 anArgIter += parseFontStrictLevel (theArgNb - anArgIter - 1,
5380 theArgVec + anArgIter + 1,
5383 else if (anArgIter + 1 < theArgNb
5384 && (anArgCase == "-find"
5385 || anArgCase == "find"))
5387 Standard_CString aFontName = theArgVec[++anArgIter];
5388 Font_FontAspect aFontAspect = Font_FA_Undefined;
5389 if (++anArgIter < theArgNb)
5391 anArgCase = theArgVec[anArgIter];
5392 anArgCase.LowerCase();
5393 if (!parseFontStyle (anArgCase, aFontAspect))
5399 if (Handle(Font_SystemFont) aFont = aMgr->FindFont (aFontName, aStrictLevel, aFontAspect))
5401 theDI << aFont->ToString();
5405 std::cout << "Error: font '" << aFontName << "' is not found!\n";
5408 else if (anArgIter + 1 < theArgNb
5409 && (anArgCase == "-add"
5410 || anArgCase == "add"
5411 || anArgCase == "-register"
5412 || anArgCase == "register"))
5415 Standard_CString aFontPath = theArgVec[anArgIter++];
5416 TCollection_AsciiString aFontName;
5417 Font_FontAspect aFontAspect = Font_FA_Undefined;
5418 Standard_Integer isSingelStroke = -1;
5419 for (; anArgIter < theArgNb; ++anArgIter)
5421 anArgCase = theArgVec[anArgIter];
5422 anArgCase.LowerCase();
5423 if (aFontAspect == Font_FontAspect_UNDEFINED
5424 && parseFontStyle (anArgCase, aFontAspect))
5428 else if (anArgCase == "singlestroke"
5429 || anArgCase == "singleline"
5430 || anArgCase == "oneline")
5434 else if (aFontName.IsEmpty())
5436 aFontName = theArgVec[anArgIter];
5445 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5448 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5452 if (aFontAspect != Font_FontAspect_UNDEFINED
5453 || !aFontName.IsEmpty())
5455 TCollection_AsciiString aName = aFont->FontName();
5456 if (!aFontName.IsEmpty())
5460 Handle(Font_SystemFont) aFont2 = new Font_SystemFont (aName);
5461 if (aFontAspect != Font_FontAspect_UNDEFINED)
5463 aFont2->SetFontPath (aFontAspect, aFontPath);
5467 for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
5469 aFont2->SetFontPath ((Font_FontAspect )anAspectIter, aFont->FontPath ((Font_FontAspect )anAspectIter));
5474 if (isSingelStroke != -1)
5476 aFont->SetSingleStrokeFont (isSingelStroke == 1);
5479 aMgr->RegisterFont (aFont, Standard_True);
5480 theDI << aFont->ToString();
5482 else if (anArgCase == "-verbose"
5483 || anArgCase == "-trace")
5485 bool toEnable = true;
5486 if (anArgIter + 1 < theArgNb
5487 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
5491 aMgr->SetTraceAliases (toEnable);
5495 std::cerr << "Warning! Unknown argument '" << anArg << "'\n";
5502 //=======================================================================
5503 //function : VVertexMode
5504 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
5505 //=======================================================================
5507 static int VVertexMode (Draw_Interpretor& theDI,
5508 Standard_Integer theArgNum,
5509 const char** theArgs)
5511 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5512 if (aContext.IsNull())
5514 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5518 // No arguments --> print the current default vertex draw mode
5521 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5522 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5526 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5527 TCollection_AsciiString aParam (theArgs[1]);
5528 if (aParam == "-set")
5532 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5533 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5537 TCollection_AsciiString aModeStr (theArgs[2]);
5538 Prs3d_VertexDrawMode aNewMode =
5539 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5540 (aModeStr == "all" ? Prs3d_VDM_All :
5541 Prs3d_VDM_Inherited);
5543 Standard_Boolean aRedrawNeeded = Standard_False;
5544 AIS_ListOfInteractive anObjs;
5546 // No object(s) specified -> use all displayed
5549 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5550 aContext->DisplayedObjects (anObjs);
5551 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5552 aRedrawNeeded = Standard_True;
5555 Handle(AIS_InteractiveObject) anObject;
5556 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5558 TCollection_AsciiString aName (theArgs[aCount]);
5559 if (!GetMapOfAIS().Find2 (aName, anObject))
5561 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5564 anObjs.Append (anObject);
5567 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5569 anObject = anIt.Value();
5570 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5571 aContext->Redisplay (anObject, Standard_False);
5572 aRedrawNeeded = Standard_True;
5576 ViewerTest::CurrentView()->Redraw();
5581 Handle(AIS_InteractiveObject) anObject;
5583 || !GetMapOfAIS().Find2 (aParam, anObject))
5585 std::cout << "Error: invalid number of arguments" << std::endl;
5589 // One argument (object name) --> print the current vertex draw mode for the object
5590 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5591 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5595 //=======================================================================
5596 //function : VPointCloud
5597 //purpose : Create interactive object for arbitary set of points.
5598 //=======================================================================
5599 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5600 Standard_Integer theArgNum,
5601 const char** theArgs)
5603 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5604 if (anAISContext.IsNull())
5606 std::cerr << "Error: no active view!\n";
5610 // command to execute
5613 CloudForShape, // generate point cloud for shape
5614 CloudSphere, // generate point cloud for generic sphere
5618 // count number of non-optional command arguments
5619 Command aCmd = Unknow;
5620 Standard_Integer aCmdArgs = 0;
5621 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5623 Standard_CString anArg = theArgs[anArgIter];
5624 TCollection_AsciiString aFlag (anArg);
5626 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5633 case 2 : aCmd = CloudForShape; break;
5634 case 7 : aCmd = CloudSphere; break;
5636 std::cout << "Error: wrong number of arguments! See usage:\n";
5637 theDI.PrintHelp (theArgs[0]);
5642 Standard_Boolean toRandColors = Standard_False;
5643 Standard_Boolean hasNormals = Standard_True;
5644 Standard_Boolean isSetArgNorm = Standard_False;
5645 Standard_Boolean hasUV = Standard_False;
5646 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5648 Standard_CString anArg = theArgs[anArgIter];
5649 TCollection_AsciiString aFlag (anArg);
5651 if (aFlag == "-randcolors"
5652 || aFlag == "-randcolor")
5654 if (isSetArgNorm && hasNormals)
5656 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5659 toRandColors = Standard_True;
5660 hasNormals = Standard_False;
5662 else if (aFlag == "-normals"
5663 || aFlag == "-normal")
5667 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5670 isSetArgNorm = Standard_True;
5671 hasNormals = Standard_True;
5673 else if (aFlag == "-nonormals"
5674 || aFlag == "-nonormal")
5676 isSetArgNorm = Standard_True;
5677 hasNormals = Standard_False;
5679 else if (aFlag == "-uv"
5680 || aFlag == "-texels")
5682 hasUV = Standard_True;
5686 Standard_CString aName = theArgs[1];
5687 Graphic3d_ArrayFlags aFlags = Graphic3d_ArrayFlags_None;
5690 aFlags |= Graphic3d_ArrayFlags_VertexNormal;
5694 aFlags |= Graphic3d_ArrayFlags_VertexColor;
5698 aFlags |= Graphic3d_ArrayFlags_VertexTexel;
5701 // generate arbitrary set of points
5702 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
5703 if (aCmd == CloudForShape)
5705 Standard_CString aShapeName = theArgs[2];
5706 TopoDS_Shape aShape = DBRep::Get (aShapeName);
5708 if (aShape.IsNull())
5710 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
5714 // calculate number of points
5715 TopLoc_Location aLocation;
5716 Standard_Integer aNbPoints = 0;
5717 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5719 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5720 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5721 if (!aTriangulation.IsNull())
5723 aNbPoints += aTriangulation->NbNodes();
5728 std::cout << "Error: shape should be triangulated!\n";
5732 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags);
5733 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5735 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5736 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5737 if (aTriangulation.IsNull())
5742 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
5743 const gp_Trsf& aTrsf = aLocation.Transformation();
5745 // extract normals from nodes
5746 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
5749 Poly_Connect aPolyConnect (aTriangulation);
5750 StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
5753 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
5755 gp_Pnt aPoint = aNodes (aNodeIter);
5756 if (!aLocation.IsIdentity())
5758 aPoint.Transform (aTrsf);
5761 aNormals (aNodeIter).Transform (aTrsf);
5765 // add vertex into array of points
5766 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5769 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
5770 1.0, 0.5, Quantity_TOC_HLS);
5771 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5776 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
5779 && aTriangulation->HasUVNodes())
5781 anArrayPoints->SetVertexTexel (anIndexOfPoint, aTriangulation->UVNode (aNodeIter));
5786 else if (aCmd == CloudSphere)
5788 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
5789 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
5790 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
5791 Standard_Real aRadius = Draw::Atof (theArgs[5]);
5792 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
5794 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
5795 aDistribution.LowerCase();
5796 if ( aDistribution != "surface" && aDistribution != "volume" )
5798 std::cout << "Error: wrong arguments! See usage:\n";
5799 theDI.PrintHelp (theArgs[0]);
5802 Standard_Boolean isSurface = aDistribution == "surface";
5804 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
5806 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags);
5807 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
5809 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5810 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5811 Standard_Real aDistance = isSurface ?
5812 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
5814 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
5816 Cos (anAlpha) * Cos (aBeta));
5817 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
5819 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5822 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
5823 1.0, 0.5, Quantity_TOC_HLS);
5824 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5829 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
5833 anArrayPoints->SetVertexTexel (anIndexOfPoint, gp_Pnt2d (anAlpha / 2.0 * M_PI,
5834 aBeta / 2.0 * M_PI));
5839 // set array of points in point cloud object
5840 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
5841 aPointCloud->SetPoints (anArrayPoints);
5842 VDisplayAISObject (aName, aPointCloud);
5846 //=======================================================================
5847 //function : VPriority
5848 //purpose : Prints or sets the display priority for an object
5849 //=======================================================================
5851 static int VPriority (Draw_Interpretor& theDI,
5852 Standard_Integer theArgNum,
5853 const char** theArgs)
5855 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5856 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5857 if (aContext.IsNull())
5859 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5863 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
5864 Standard_Integer aPriority = -1;
5865 Standard_Integer aNbArgs = theArgNum;
5866 if (aLastArg.IsIntegerValue())
5868 aPriority = aLastArg.IntegerValue();
5870 if (aPriority < 0 || aPriority > 10)
5872 std::cout << "Error: the specified display priority value '" << aLastArg
5873 << "' is outside the valid range [0..10]" << std::endl;
5879 anUpdateTool.Invalidate();
5884 std::cout << "Error: wrong number of arguments! See usage:\n";
5885 theDI.PrintHelp (theArgs[0]);
5889 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
5891 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
5896 TCollection_AsciiString aName (theArgs[anArgIter]);
5897 Handle(AIS_InteractiveObject) anIObj;
5898 GetMapOfAIS().Find2 (aName, anIObj);
5899 if (anIObj.IsNull())
5901 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
5907 theDI << aContext->DisplayPriority (anIObj) << " ";
5911 aContext->SetDisplayPriority (anIObj, aPriority);
5917 //! Auxiliary class for command vnormals.
5918 class MyShapeWithNormals : public AIS_Shape
5920 DEFINE_STANDARD_RTTI_INLINE(MyShapeWithNormals, AIS_Shape);
5923 Standard_Real NormalLength;
5924 Standard_Integer NbAlongU;
5925 Standard_Integer NbAlongV;
5926 Standard_Boolean ToUseMesh;
5927 Standard_Boolean ToOrient;
5931 //! Main constructor.
5932 MyShapeWithNormals (const TopoDS_Shape& theShape)
5933 : AIS_Shape (theShape),
5937 ToUseMesh (Standard_False),
5938 ToOrient (Standard_False) {}
5942 //! Comnpute presentation.
5943 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
5944 const Handle(Prs3d_Presentation)& thePrs,
5945 const Standard_Integer theMode) Standard_OVERRIDE
5947 AIS_Shape::Compute (thePrsMgr, thePrs, theMode);
5949 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormalMap;
5952 DBRep_DrawableShape::addMeshNormals (aNormalMap, myshape, NormalLength);
5956 DBRep_DrawableShape::addSurfaceNormals (aNormalMap, myshape, NormalLength, NbAlongU, NbAlongV);
5959 Handle(Graphic3d_Group) aPrsGroup = Prs3d_Root::NewGroup (thePrs);
5960 aPrsGroup->SetGroupPrimitivesAspect (myDrawer->ArrowAspect()->Aspect());
5962 const Standard_Real aArrowAngle = myDrawer->ArrowAspect()->Angle();
5963 const Standard_Real aArrowLength = myDrawer->ArrowAspect()->Length();
5964 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormalMap);
5965 aFaceIt.More(); aFaceIt.Next())
5967 const Standard_Boolean toReverse = ToOrient && aFaceIt.Key().Orientation() == TopAbs_REVERSED;
5968 Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (2 * aFaceIt.Value().Size());
5969 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aPntIt (aFaceIt.Value()); aPntIt.More(); aPntIt.Next())
5971 std::pair<gp_Pnt, gp_Pnt> aPair = aPntIt.Value();
5974 const gp_Vec aDir = aPair.first.XYZ() - aPair.second.XYZ();
5975 aPair.second = aPair.first.XYZ() + aDir.XYZ();
5978 aSegments->AddVertex (aPair.first);
5979 aSegments->AddVertex (aPair.second);
5980 Prs3d_Arrow::Draw (aPrsGroup, aPair.second, gp_Vec(aPair.first, aPair.second), aArrowAngle, aArrowLength);
5983 aPrsGroup->AddPrimitiveArray (aSegments);
5989 //=======================================================================
5990 //function : VNormals
5991 //purpose : Displays/Hides normals calculated on shape geometry or retrieved from triangulation
5992 //=======================================================================
5993 static int VNormals (Draw_Interpretor& theDI,
5994 Standard_Integer theArgNum,
5995 const char** theArgs)
5997 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5998 if (aContext.IsNull())
6000 std::cout << "Error: no view available, call 'vinit' before!\n";
6003 else if (theArgNum < 2)
6005 std::cout << "Error: wrong number of arguments! See usage:\n";
6006 theDI.PrintHelp (theArgs[0]);
6010 Standard_Integer anArgIter = 1;
6011 Standard_CString aShapeName = theArgs[anArgIter++];
6012 TopoDS_Shape aShape = DBRep::Get (aShapeName);
6013 Standard_Boolean isOn = Standard_True;
6014 if (aShape.IsNull())
6016 std::cout << "Error: shape with name '" << aShapeName << "' is not found\n";
6020 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6021 Handle(MyShapeWithNormals) aShapePrs;
6022 if (aMap.IsBound2 (aShapeName))
6024 aShapePrs = Handle(MyShapeWithNormals)::DownCast (aMap.Find2 (aShapeName));
6027 Standard_Boolean isUseMesh = Standard_False;
6028 Standard_Real aLength = 10.0;
6029 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
6030 Standard_Boolean isOriented = Standard_False;
6031 for (; anArgIter < theArgNum; ++anArgIter)
6033 TCollection_AsciiString aParam (theArgs[anArgIter]);
6036 && ViewerTest::ParseOnOff (aParam.ToCString(), isOn))
6040 else if (aParam == "-usemesh"
6041 || aParam == "-mesh")
6043 isUseMesh = Standard_True;
6045 else if (aParam == "-length"
6046 || aParam == "-len")
6049 aLength = anArgIter < theArgNum ? Draw::Atof (theArgs[anArgIter]) : 0.0;
6050 if (Abs (aLength) <= gp::Resolution())
6052 std::cout << "Syntax error: length should not be zero\n";
6056 else if (aParam == "-orient"
6057 || aParam == "-oriented")
6059 isOriented = Standard_True;
6060 if (anArgIter + 1 < theArgNum
6061 && ViewerTest::ParseOnOff (theArgs[anArgIter + 1], isOriented))
6066 else if (aParam == "-nbalongu"
6067 || aParam == "-nbu")
6070 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6073 std::cout << "Syntax error: NbAlongU should be >=1\n";
6077 else if (aParam == "-nbalongv"
6078 || aParam == "-nbv")
6081 aNbAlongV = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6084 std::cout << "Syntax error: NbAlongV should be >=1\n";
6088 else if (aParam == "-nbalong"
6089 || aParam == "-nbuv")
6092 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6093 aNbAlongV = aNbAlongU;
6096 std::cout << "Syntax error: NbAlong should be >=1\n";
6102 std::cout << "Syntax error: unknwon argument '" << aParam << "'\n";
6109 if (aShapePrs.IsNull())
6111 aShapePrs = new MyShapeWithNormals (aShape);
6113 aShapePrs->ToUseMesh = isUseMesh;
6114 aShapePrs->ToOrient = isOriented;
6115 aShapePrs->NormalLength = aLength;
6116 aShapePrs->NbAlongU = aNbAlongU;
6117 aShapePrs->NbAlongV = aNbAlongV;
6118 VDisplayAISObject (aShapeName, aShapePrs);
6120 else if (!aShapePrs.IsNull())
6122 VDisplayAISObject (aShapeName, new AIS_Shape (aShape));
6128 //=======================================================================
6129 //function : ObjectsCommands
6131 //=======================================================================
6133 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
6135 const char *group ="AISObjects";
6137 theCommands.Add ("vtrihedron",
6138 "vtrihedron : vtrihedron name"
6139 "\n\t\t: [-dispMode {wireframe|shading} ]"
6140 "\n\t\t: [-origin x y z ]"
6141 "\n\t\t: [-zaxis u v w -xaxis u v w ]"
6142 "\n\t\t: [-drawAxes {X|Y|Z|XY|YZ|XZ|XYZ}]"
6143 "\n\t\t: [-hideLabels {on|off}]"
6144 "\n\t\t: [-hideArrows {on|off}]"
6145 "\n\t\t: [-label {XAxis|YAxis|ZAxis} value]"
6146 "\n\t\t: [-attribute {XAxisLength|YAxisLength|ZAxisLength"
6147 "\n\t\t: |TubeRadiusPercent|ConeRadiusPercent"
6148 "\n\t\t: |ConeLengthPercent|OriginRadiusPercent"
6149 "\n\t\t: |ShadingNumberOfFacettes} value]"
6150 "\n\t\t: [-color {Origin|XAxis|YAxis|ZAxis|XOYAxis|YOZAxis"
6151 "\n\t\t: |XOZAxis|Whole} {r g b | colorName}]"
6152 "\n\t\t: [-textColor {r g b | colorName}]"
6153 "\n\t\t: [-arrowColor {r g b | colorName}]"
6154 "\n\t\t: [-priority {Origin|XAxis|YAxis|ZAxis|XArrow"
6155 "\n\t\t: |YArrow|ZArrow|XOYAxis|YOZAxis"
6156 "\n\t\t: |XOZAxis|Whole} value]"
6158 "\n\t\t: Creates a new *AIS_Trihedron* object or changes parameters of "
6159 "\n\t\t: existing trihedron. If no argument is set,"
6160 "\n\t\t: the default trihedron (0XYZ) is created."
6161 "\n\t\t: -dispMode mode of visualization: wf - wireframe,"
6162 "\n\t\t: sh - shading."
6163 "\n\t\t: Default value is wireframe."
6164 "\n\t\t: -origin allows to set trihedron location."
6165 "\n\t\t: -zaxis/-xaxis allows to set trihedron X and Z"
6166 "\n\t\t: directions. The directions should"
6167 "\n\t\t: be orthogonal. Y direction is calculated."
6168 "\n\t\t: -drawAxes allows to set what axes are drawn in the"
6169 "\n\t\t: trihedron, default state is XYZ"
6170 "\n\t\t: -hideLabels allows to show/hide trihedron labels"
6171 "\n\t\t: -hideArrows allows to show/hide trihedron arrows"
6172 "\n\t\t: -label allows to change default X/Y/Z titles of axes"
6173 "\n\t\t: -attribute sets parameters of trihedron"
6174 "\n\t\t: -color sets color properties of parts of trihedron"
6175 "\n\t\t: -textColor sets color properties of trihedron labels"
6176 "\n\t\t: -arrowColor sets color properties of trihedron arrows"
6177 "\n\t\t: -priority allows to change default selection priority"
6178 "\n\t\t: of trihedron components",
6179 __FILE__,VTrihedron,group);
6181 theCommands.Add("vtri2d",
6183 "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.",
6184 __FILE__,VTrihedron2D ,group);
6186 theCommands.Add("vplanetri",
6188 "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default",
6189 __FILE__,VPlaneTrihedron ,group);
6191 theCommands.Add("vsize",
6192 "vsize : vsize [name(Default=Current)] [size(Default=100)] "
6193 "\n\t\t: Changes the size of a named or selected trihedron."
6194 "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done."
6195 "\n\t\t: If the value is not defined: it is set to 100 by default.",
6196 __FILE__,VSize,group);
6198 theCommands.Add("vaxis",
6199 "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]"
6200 "\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",
6201 __FILE__,VAxisBuilder,group);
6203 theCommands.Add("vaxispara",
6205 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.",
6206 __FILE__,VAxisBuilder,group);
6208 theCommands.Add("vaxisortho",
6210 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.",
6211 __FILE__,VAxisBuilder,group);
6213 theCommands.Add("vpoint",
6214 "vpoint PointName [Xa] [Ya] [Za] "
6215 "\n\t\t: Creates a point from coordinates. If the values are not defined,"
6216 "\n\t\t: a point is created by interactive selection of a vertice or an edge (in the center of the edge).",
6217 __FILE__,VPointBuilder,group);
6219 theCommands.Add("vplane",
6220 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]"
6221 "\n\t\t: Creates a plane from named or interactively selected entities."
6222 "\n\t\t: TypeOfSensitivity:"
6223 "\n\t\t: 0 - Interior"
6224 "\n\t\t: 1 - Boundary",
6225 __FILE__,VPlaneBuilder,group);
6227 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
6228 " vchangeplane <plane_name>"
6229 " [x=center_x y=center_y z=center_z]"
6230 " [dx=dir_x dy=dir_y dz=dir_z]"
6231 " [sx=size_x sy=size_y]"
6233 " - changes parameters of the plane:\n"
6234 " - x y z - center\n"
6235 " - dx dy dz - normal\n"
6236 " - sx sy - plane sizes\n"
6237 " - noupdate - do not update/redisplay the plane in context\n"
6238 " Please enter coordinates in format \"param=value\" in arbitrary order.",
6239 __FILE__, VChangePlane, group);
6241 theCommands.Add("vplanepara",
6242 "vplanepara PlaneName "
6243 "\n\t\t: Creates a plane from interactively selected vertex and face.",
6244 __FILE__,VPlaneBuilder,group);
6246 theCommands.Add("vplaneortho",
6247 "vplaneortho PlaneName "
6248 "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ",
6249 __FILE__,VPlaneBuilder,group);
6251 theCommands.Add("vline",
6252 "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] "
6253 "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ",
6254 __FILE__,VLineBuilder,group);
6256 theCommands.Add("vcircle",
6257 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]"
6258 "\n\t\t: Creates a circle from named or interactively selected entities."
6259 "\n\t\t: Parameter IsFilled is defined as 0 or 1.",
6260 __FILE__,VCircleBuilder,group);
6262 theCommands.Add ("vdrawtext",
6263 "vdrawtext name text"
6264 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6265 "\n\t\t: [-color {R G B|name}=yellow]"
6266 "\n\t\t: [-halign {left|center|right}=left]"
6267 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6268 "\n\t\t: [-angle angle=0]"
6269 "\n\t\t: [-zoom {0|1}=0]"
6270 "\n\t\t: [-height height=16]"
6271 "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]"
6272 "\n\t\t: [-font font=Times]"
6274 "\n\t\t: [-perspos {X Y Z}=0 0 0], where"
6275 "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window"
6276 "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..."
6277 "\n\t\t Z coordinate defines the gap from border of view window (except center position)."
6278 "\n\t\t: [-disptype {blend|decal|shadow|subtitle|dimension|normal}=normal}"
6279 "\n\t\t: [-subcolor {R G B|name}=white]"
6280 "\n\t\t: [-noupdate]"
6281 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]"
6282 "\n\t\t: [-flipping]"
6283 "\n\t\t: Display text label at specified position.",
6284 __FILE__, VDrawText, group);
6286 theCommands.Add("vdrawsphere",
6287 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
6288 __FILE__,VDrawSphere,group);
6290 theCommands.Add ("vlocation",
6293 "\n\t\t: [-copyFrom otherName]"
6294 "\n\t\t: [-translate X Y [Z]]"
6295 "\n\t\t: [-rotate x y z dx dy dz angle]"
6296 "\n\t\t: [-scale [X Y Z] scale]"
6297 "\n\t\t: [-mirror x y z dx dy dz]"
6298 "\n\t\t: [-setLocation X Y [Z]]"
6299 "\n\t\t: [-setRotation QX QY QZ QW]"
6300 "\n\t\t: [-setScale [X Y Z] scale]"
6301 "\n\t\t: Object local transformation management:"
6302 "\n\t\t: -reset reset transformation to identity"
6303 "\n\t\t: -translate translate object"
6304 "\n\t\t: -rotate applies rotation to local transformation"
6305 "\n\t\t: -scale applies scale to local transformation"
6306 "\n\t\t: -mirror applies mirror to local transformation"
6307 "\n\t\t: -setLocation assign object location"
6308 "\n\t\t: -setRotation assign object rotation (quaternion)"
6309 "\n\t\t: -setScale assign object scale factor",
6310 __FILE__, VSetLocation, group);
6311 theCommands.Add ("vsetlocation",
6312 "alias for vlocation",
6313 __FILE__, VSetLocation, group);
6315 theCommands.Add ("vcomputehlr",
6316 "vcomputehlr shapeInput hlrResult [-algoType {algo|polyAlgo}=polyAlgo]"
6317 "\n\t\t: [eyeX eyeY eyeZ dirX dirY dirZ upX upY upZ]"
6318 "\n\t\t: [-showTangentEdges {on|off}=off] [-nbIsolines N=0] [-showHiddenEdges {on|off}=off]"
6319 "\n\t\t: Arguments:"
6320 "\n\t\t: shapeInput - name of the initial shape"
6321 "\n\t\t: hlrResult - result HLR object from initial shape"
6322 "\n\t\t: eye, dir are eye position and look direction"
6323 "\n\t\t: up is the look up direction vector"
6324 "\n\t\t: -algoType HLR algorithm to use"
6325 "\n\t\t: -showTangentEdges include tangent edges"
6326 "\n\t\t: -nbIsolines include isolines"
6327 "\n\t\t: -showHiddenEdges include hidden edges"
6328 "\n\t\t: Use vtop to see projected HLR shape.",
6329 __FILE__, VComputeHLR, group);
6331 theCommands.Add("vdrawparray",
6332 "vdrawparray name TypeOfArray={points|segments|polylines|triangles"
6333 "\n\t\t: |trianglefans|trianglestrips|quads|quadstrips|polygons}"
6334 "\n\t\t: [-deinterleaved|-mutable]"
6335 "\n\t\t: [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [texel={'t' tx ty}]]"
6336 "\n\t\t: [bound= {'b' nbVertices [bound_color={'c' r g b}]]"
6337 "\n\t\t: [edge= {'e' vertexId]"
6338 "\n\t\t: [-shape shapeName] [-patch]"
6339 "\n\t\t: Commands create an Interactive Object for specified Primitive Array definition (Graphic3d_ArrayOfPrimitives)"
6340 "\n\t\t: with the main purpose is covering various combinations by tests",
6341 __FILE__,VDrawPArray,group);
6343 theCommands.Add("vconnect",
6344 "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]"
6345 "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.",
6346 __FILE__, VConnect, group);
6348 theCommands.Add("vconnectto",
6349 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
6350 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6351 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
6352 __FILE__, VConnectTo,group);
6354 theCommands.Add("vdisconnect",
6355 "vdisconnect assembly_name (object_name | object_number | 'all')"
6356 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6357 __FILE__,VDisconnect,group);
6359 theCommands.Add("vaddconnected",
6360 "vaddconnected assembly_name object_name"
6361 "Adds object to assembly.",
6362 __FILE__,VAddConnected,group);
6364 theCommands.Add("vlistconnected",
6365 "vlistconnected assembly_name"
6366 "Lists objects in assembly.",
6367 __FILE__,VListConnected,group);
6370 theCommands.Add("vselmode",
6371 "vselmode [object] selectionMode {on|off}"
6372 "\n\t\t: [{-add|-set|-globalOrLocal}=-globalOrLocal]"
6373 "\n\t\t: Switches selection mode for the specified object or for all objects in context."
6374 "\n\t\t: Selection mode is either an integer number specific to Interactive Object,"
6375 "\n\t\t: or sub-shape type in case of AIS_Shape:"
6376 "\n\t\t: Shape, Vertex, Edge, Wire, Face, Shell, Solid, CompSolid, Compound"
6377 "\n\t\t: The integer mode 0 (Shape in case of AIS_Shape) is reserved for selecting object as whole."
6378 "\n\t\t: Additional options:"
6379 "\n\t\t: -add already activated selection modes will be left activated"
6380 "\n\t\t: -set already activated selection modes will be deactivated"
6381 "\n\t\t: -globalOrLocal (default) if new mode is Global selection mode,"
6382 "\n\t\t: then active local selection modes will be deactivated"
6383 "\n\t\t: and the samthen active local selection modes will be deactivated",
6384 __FILE__, VSetSelectionMode, group);
6386 theCommands.Add("vselnext",
6387 "vselnext : hilight next detected",
6388 __FILE__, VSelectionNext, group);
6390 theCommands.Add("vselprev",
6391 "vselnext : hilight previous detected",
6392 __FILE__, VSelectionPrevious, group);
6394 theCommands.Add("vtriangle",
6395 "vtriangle Name PointName PointName PointName"
6396 "\n\t\t: Creates and displays a filled triangle from named points.",
6397 __FILE__, VTriangle,group);
6399 theCommands.Add("vsegment",
6400 "vsegment Name PointName PointName"
6401 "\n\t\t: Creates and displays a segment from named points.",
6402 __FILE__, VTriangle,group);
6404 theCommands.Add("vobjzlayer",
6405 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6406 __FILE__, VObjZLayer, group);
6408 theCommands.Add("vpolygonoffset",
6409 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6410 __FILE__, VPolygonOffset, group);
6412 theCommands.Add ("vmarkerstest",
6413 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6414 __FILE__, VMarkersTest, group);
6416 theCommands.Add ("text2brep",
6417 "text2brep: name text"
6418 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6419 "\n\t\t: [-halign {left|center|right}=left]"
6420 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6421 "\n\t\t: [-height height=16]"
6422 "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]"
6423 "\n\t\t: [-font font=Courier] [-strict {strict|aliases|any}=any]"
6424 "\n\t\t: [-composite {on|off}=off]"
6425 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]",
6426 __FILE__, TextToBRep, group);
6427 theCommands.Add ("vfont",
6428 "vfont [-add pathToFont [fontName] [regular,bold,italic,boldItalic=undefined] [singleStroke]]"
6429 "\n\t\t: [-strict {any|aliases|strict}] [-find fontName [regular,bold,italic,boldItalic=undefined]] [-verbose {on|off}]",
6430 __FILE__, VFont, group);
6432 theCommands.Add ("vvertexmode",
6433 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6434 "vvertexmode - prints the default vertex draw mode\n"
6435 "vvertexmode name - prints the vertex draw mode of the given object\n"
6436 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6437 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6438 __FILE__, VVertexMode, group);
6440 theCommands.Add ("vpointcloud",
6441 "vpointcloud name shape [-randColor] [-normals] [-noNormals] [-uv]"
6442 "\n\t\t: Create an interactive object for arbitary set of points"
6443 "\n\t\t: from triangulated shape."
6445 "vpointcloud name x y z r npts {surface|volume}\n"
6446 " ... [-randColor] [-normals] [-noNormals] [-uv]"
6447 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6448 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6450 "\n\t\t: Additional options:"
6451 "\n\t\t: -randColor - generate random color per point"
6452 "\n\t\t: -normals - generate normal per point (default)"
6453 "\n\t\t: -noNormals - do not generate normal per point"
6455 __FILE__, VPointCloud, group);
6457 theCommands.Add("vpriority",
6458 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",
6462 theCommands.Add ("vnormals",
6464 "vnormals Shape [{on|off}=on] [-length {10}] [-nbAlongU {1}] [-nbAlongV {1}] [-nbAlong {1}]"
6465 "\n\t\t: [-useMesh] [-oriented {0}1}=0]"
6466 "\n\t\t: Displays/Hides normals calculated on shape geometry or retrieved from triangulation",
6467 __FILE__, VNormals, group);