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>
31 #include <Message.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 <BRepLib_PointCloudShape.hxx>
44 #include <TColStd_MapOfInteger.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_SensitivePoint.hxx>
135 #include <Select3D_SensitivePoly.hxx>
136 #include <BRepAdaptor_Curve.hxx>
137 #include <StdPrs_Curve.hxx>
139 #include <BRepExtrema_ExtPC.hxx>
140 #include <BRepExtrema_ExtPF.hxx>
142 #include <Prs3d_Arrow.hxx>
143 #include <Prs3d_ArrowAspect.hxx>
144 #include <Prs3d_DatumAttribute.hxx>
145 #include <Prs3d_DatumAspect.hxx>
146 #include <Prs3d_Drawer.hxx>
147 #include <Prs3d_VertexDrawMode.hxx>
148 #include <Prs3d_LineAspect.hxx>
149 #include <Prs3d_PointAspect.hxx>
150 #include <Prs3d_Presentation.hxx>
151 #include <Prs3d_TextAspect.hxx>
152 #include <Prs3d_ToolCylinder.hxx>
153 #include <Prs3d_ToolSphere.hxx>
154 #include <Prs3d_ToolTorus.hxx>
156 #include <Image_AlienPixMap.hxx>
157 #include <TColStd_HArray1OfAsciiString.hxx>
158 #include <TColStd_HSequenceOfAsciiString.hxx>
160 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
161 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
162 const Handle(AIS_InteractiveObject)& theAISObj,
163 Standard_Boolean theReplaceIfExists = Standard_True);
164 extern Handle(AIS_InteractiveContext)& TheAISContext();
168 static bool convertToColor (const Handle(TColStd_HSequenceOfAsciiString)& theColorValues,
169 Quantity_Color& theColor)
171 const char* anArgs[3] =
173 theColorValues->Size() >= 1 ? theColorValues->Value (1).ToCString() : "",
174 theColorValues->Size() >= 2 ? theColorValues->Value (2).ToCString() : "",
175 theColorValues->Size() >= 3 ? theColorValues->Value (3).ToCString() : ""
177 return Draw::ParseColor (theColorValues->Size(), anArgs, theColor) != 0;
180 static bool convertToDatumPart (const TCollection_AsciiString& theValue,
181 Prs3d_DatumParts& theDatumPart)
183 TCollection_AsciiString aValue = theValue;
185 if (aValue == "origin") theDatumPart = Prs3d_DatumParts_Origin;
186 else if (aValue == "xaxis") theDatumPart = Prs3d_DatumParts_XAxis;
187 else if (aValue == "yaxis") theDatumPart = Prs3d_DatumParts_YAxis;
188 else if (aValue == "zaxis") theDatumPart = Prs3d_DatumParts_ZAxis;
189 else if (aValue == "xarrow") theDatumPart = Prs3d_DatumParts_XArrow;
190 else if (aValue == "yarrow") theDatumPart = Prs3d_DatumParts_YArrow;
191 else if (aValue == "zarrow") theDatumPart = Prs3d_DatumParts_ZArrow;
192 else if (aValue == "xoyaxis") theDatumPart = Prs3d_DatumParts_XOYAxis;
193 else if (aValue == "yozaxis") theDatumPart = Prs3d_DatumParts_YOZAxis;
194 else if (aValue == "xozaxis") theDatumPart = Prs3d_DatumParts_XOZAxis;
195 else if (aValue == "whole") theDatumPart = Prs3d_DatumParts_None;
203 static void convertToDatumParts (const TCollection_AsciiString& theValue,
204 NCollection_List<Prs3d_DatumParts>& theParts)
206 TCollection_AsciiString aValue = theValue;
207 const Standard_Integer aSplitPos = theValue.Search ("|");
208 Prs3d_DatumParts aPart = Prs3d_DatumParts_None;
211 convertToDatumParts (theValue.SubString (aSplitPos + 1, theValue.Length()), theParts);
212 if (aSplitPos == 1) // first symbol
216 aValue = theValue.SubString (1, aSplitPos - 1);
218 if (convertToDatumPart (aValue, aPart))
220 theParts.Append (aPart);
224 static bool convertToDatumAttribute (const TCollection_AsciiString& theValue,
225 Prs3d_DatumAttribute& theAttribute)
227 TCollection_AsciiString aValue = theValue;
229 if (aValue == "xaxislength") theAttribute = Prs3d_DatumAttribute_XAxisLength;
230 else if (aValue == "yaxislength") theAttribute = Prs3d_DatumAttribute_YAxisLength;
231 else if (aValue == "zaxislength") theAttribute = Prs3d_DatumAttribute_ZAxisLength;
232 else if (aValue == "tuberadiuspercent") theAttribute = Prs3d_DatumAttribute_ShadingTubeRadiusPercent;
233 else if (aValue == "coneradiuspercent") theAttribute = Prs3d_DatumAttribute_ShadingConeRadiusPercent;
234 else if (aValue == "conelengthpercent") theAttribute = Prs3d_DatumAttribute_ShadingConeLengthPercent;
235 else if (aValue == "originradiuspercent") theAttribute = Prs3d_DatumAttribute_ShadingOriginRadiusPercent;
236 else if (aValue == "shadingnumberoffacettes") theAttribute = Prs3d_DatumAttribute_ShadingNumberOfFacettes;
242 static void convertToDatumAttributes (const TCollection_AsciiString& theValue,
243 NCollection_List<Prs3d_DatumAttribute>& theAttributes)
245 TCollection_AsciiString aValue = theValue;
246 const Standard_Integer aSplitPos = theValue.Search ("|");
247 Prs3d_DatumAttribute anAttribute = Prs3d_DatumAttribute_XAxisLength;
250 convertToDatumAttributes (theValue.SubString (aSplitPos + 1, theValue.Length()), theAttributes);
251 if (aSplitPos == 1) // first symbol
255 aValue = theValue.SubString (1, aSplitPos - 1);
257 if (convertToDatumAttribute (aValue, anAttribute))
259 theAttributes.Append (anAttribute);
263 static bool convertToDatumAxes (const TCollection_AsciiString& theValue,
264 Prs3d_DatumAxes& theDatumAxes)
266 TCollection_AsciiString aValue = theValue;
268 if (aValue == "x") theDatumAxes = Prs3d_DatumAxes_XAxis;
269 else if (aValue == "y") theDatumAxes = Prs3d_DatumAxes_YAxis;
270 else if (aValue == "z") theDatumAxes = Prs3d_DatumAxes_ZAxis;
271 else if (aValue == "xy") theDatumAxes = Prs3d_DatumAxes_XYAxes;
272 else if (aValue == "zy") theDatumAxes = Prs3d_DatumAxes_YZAxes;
273 else if (aValue == "xz") theDatumAxes = Prs3d_DatumAxes_XZAxes;
274 else if (aValue == "xyz") theDatumAxes = Prs3d_DatumAxes_XYZAxes;
282 static Standard_Boolean setTrihedronParams (Standard_Integer theArgsNb,
283 const char** theArgVec,
284 Handle(AIS_Trihedron) theTrihedron)
286 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
287 TCollection_AsciiString aParseKey;
288 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
290 TCollection_AsciiString anArg (theArgVec [anArgIt]);
291 if (anArg.Value (1) == '-'
292 && !anArg.IsRealValue (Standard_True))
295 aParseKey.Remove (1);
296 aParseKey.LowerCase();
297 std::string aKey = aParseKey.ToCString();
298 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString());
302 if (aParseKey.IsEmpty())
307 aMapOfArgs (aParseKey)->Append (anArg);
311 if ((aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis"))
312 || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")))
314 Message::SendFail ("Syntax error: -xaxis and -zaxis parameters are to set together");
315 return Standard_False;
318 Handle(TColStd_HSequenceOfAsciiString) aValues;
319 Handle(Geom_Axis2Placement) aComponent = theTrihedron->Component();
320 if (aMapOfArgs.Find ("origin", aValues))
322 aComponent->SetLocation (gp_Pnt (aValues->Value (1).RealValue(),
323 aValues->Value (2).RealValue(),
324 aValues->Value (3).RealValue()));
326 Handle(TColStd_HSequenceOfAsciiString) aXValues, aZValues;
327 if (aMapOfArgs.Find ("xaxis", aXValues) && aMapOfArgs.Find ("zaxis", aZValues))
329 gp_Dir aXDir (aXValues->Value (1).RealValue(),
330 aXValues->Value (2).RealValue(),
331 aXValues->Value (3).RealValue());
333 gp_Dir aZDir (aZValues->Value (1).RealValue(),
334 aZValues->Value (2).RealValue(),
335 aZValues->Value (3).RealValue());
337 if (!aZDir.IsNormal (aXDir, M_PI / 180.0))
339 Message::SendFail ("Syntax error - parameters 'xaxis' and 'zaxis' are not applied as VectorX is not normal to VectorZ");
340 return Standard_False;
343 aComponent->SetAx2 (gp_Ax2 (aComponent->Location(), aZDir, aXDir));
346 if (aMapOfArgs.Find ("dispmode", aValues))
348 TCollection_AsciiString aValue (aValues->Value (1));
349 bool isWireframe = true;
350 if (aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
352 theTrihedron->SetDatumDisplayMode (isWireframe ? Prs3d_DM_WireFrame
356 if (aMapOfArgs.Find ("hidelabels", aValues))
358 Standard_Boolean toHideLabels = Standard_True;
359 if (aValues->Size() == 1)
361 Draw::ParseOnOff (aValues->First().ToCString(), toHideLabels);
363 else if (aValues->Size() != 0)
365 Message::SendFail ("Syntax error: -hidelabels expects parameter 'on' or 'off' after");
366 return Standard_False;
369 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
371 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
373 theTrihedron->Attributes()->DatumAspect()->SetDrawLabels (!toHideLabels);
376 if (aMapOfArgs.Find ("hidearrows", aValues))
378 Standard_Boolean toHideArrows = Standard_True;
379 if (aValues->Size() == 1)
381 Draw::ParseOnOff (aValues->First().ToCString(), toHideArrows);
383 else if (aValues->Size() != 0)
385 Message::SendFail ("Syntax error: -hidearrows expects parameter 'on' or 'off' after");
386 return Standard_False;
389 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
391 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
393 theTrihedron->Attributes()->DatumAspect()->SetDrawArrows (!toHideArrows);
396 if (aMapOfArgs.Find ("color", aValues))
398 NCollection_List<Prs3d_DatumParts> aParts;
399 if (aValues->Size() < 2)
401 Message::SendFail ("Syntax error: -color wrong parameters");
402 return Standard_False;
405 convertToDatumParts (aValues->Value(1), aParts);
406 aValues->Remove (1); // datum part is processed
407 Quantity_Color aColor;
408 if (!convertToColor (aValues, aColor))
410 Message::SendFail ("Syntax error: -color wrong parameters");
411 return Standard_False;
414 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (aParts); anIterator.More(); anIterator.Next())
416 Prs3d_DatumParts aDatumPart = anIterator.Value();
417 if (aDatumPart == Prs3d_DatumParts_None)
419 theTrihedron->SetColor (aColor);
423 theTrihedron->SetDatumPartColor (aDatumPart, aColor);
428 if (aMapOfArgs.Find ("textcolor", aValues))
430 Prs3d_DatumParts aDatumPart = Prs3d_DatumParts_None;
431 if (!aValues->IsEmpty()
432 && convertToDatumPart (aValues->First(), aDatumPart)
433 && aDatumPart >= Prs3d_DatumParts_XAxis
434 && aDatumPart <= Prs3d_DatumParts_ZAxis)
436 aValues->Remove (1); // datum part is processed
439 Quantity_Color aColor;
440 if (!convertToColor (aValues, aColor))
442 Message::SendFail ("Syntax error: -textcolor wrong parameters");
443 return Standard_False;
446 if (aDatumPart != Prs3d_DatumParts_None)
448 theTrihedron->SetTextColor (aDatumPart, aColor);
452 theTrihedron->SetTextColor (aColor);
456 if (aMapOfArgs.Find ("arrowcolor", aValues))
458 Prs3d_DatumParts aDatumPart = Prs3d_DatumParts_None;
459 if (!aValues->IsEmpty()
460 && convertToDatumPart (aValues->First(), aDatumPart)
461 && ((aDatumPart >= Prs3d_DatumParts_XArrow && aDatumPart <= Prs3d_DatumParts_ZArrow)
462 || (aDatumPart >= Prs3d_DatumParts_XAxis && aDatumPart <= Prs3d_DatumParts_ZAxis)))
464 aValues->Remove (1); // datum part is processed
467 Quantity_Color aColor;
468 if (!convertToColor (aValues, aColor))
470 Message::SendFail ("Syntax error: -arrowcolor wrong parameters");
471 return Standard_False;
474 if (aDatumPart != Prs3d_DatumParts_None)
476 Prs3d_DatumParts anArrowPart = Prs3d_DatumAspect::ArrowPartForAxis (aDatumPart);
477 theTrihedron->SetArrowColor (anArrowPart, aColor);
481 theTrihedron->SetArrowColor (aColor);
485 if (aMapOfArgs.Find ("attribute", aValues))
487 NCollection_List<Prs3d_DatumAttribute> anAttributes;
488 if (aValues->Size() != 2)
490 Message::SendFail ("Syntax error: -attribute wrong parameters");
491 return Standard_False;
494 convertToDatumAttributes (aValues->Value (1), anAttributes);
495 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
496 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
497 for (NCollection_List<Prs3d_DatumAttribute>::Iterator anIterator (anAttributes); anIterator.More(); anIterator.Next())
499 theTrihedron->Attributes()->DatumAspect()->SetAttribute (anIterator.Value(), aValues->Value (2).RealValue());
503 if (aMapOfArgs.Find ("priority", aValues))
505 Prs3d_DatumParts aDatumPart;
506 if (aValues->Size() < 2
507 || !convertToDatumPart (aValues->Value (1), aDatumPart))
509 Message::SendFail ("Syntax error: -priority wrong parameters");
510 return Standard_False;
512 theTrihedron->SetSelectionPriority (aDatumPart, aValues->Value (2).IntegerValue());
515 if (aMapOfArgs.Find ("labels", aValues)
516 || aMapOfArgs.Find ("label", aValues))
518 Prs3d_DatumParts aDatumPart = Prs3d_DatumParts_None;
519 if (aValues->Size() >= 2
520 && convertToDatumPart(aValues->Value(1), aDatumPart)
521 && aDatumPart >= Prs3d_DatumParts_XAxis
522 && aDatumPart <= Prs3d_DatumParts_ZAxis) // labels are set to axes only
524 theTrihedron->SetLabel (aDatumPart, aValues->Value (2));
528 Message::SendFail ("Syntax error: -labels wrong parameters");
529 return Standard_False;
533 if (aMapOfArgs.Find ("drawaxes", aValues))
535 Prs3d_DatumAxes aDatumAxes = Prs3d_DatumAxes_XAxis;
536 if (aValues->Size() < 1
537 || !convertToDatumAxes (aValues->Value (1), aDatumAxes))
539 Message::SendFail ("Syntax error: -drawaxes wrong parameters");
540 return Standard_False;
542 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
543 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
544 theTrihedron->Attributes()->DatumAspect()->SetDrawDatumAxes (aDatumAxes);
546 return Standard_True;
549 //! Auxiliary function to parse font aspect style argument
550 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
551 Font_FontAspect& theAspect)
553 if (theArg == "regular"
554 || *theArg.ToCString() == 'r')
556 theAspect = Font_FA_Regular;
557 return Standard_True;
559 else if (theArg == "bolditalic"
560 || theArg == "bold-italic"
561 || theArg == "italic-bold"
562 || theArg == "italicbold")
564 theAspect = Font_FA_BoldItalic;
565 return Standard_True;
567 else if (theArg == "bold"
568 || *theArg.ToCString() == 'b')
570 theAspect = Font_FA_Bold;
571 return Standard_True;
573 else if (theArg == "italic"
574 || *theArg.ToCString() == 'i')
576 theAspect = Font_FA_Italic;
577 return Standard_True;
579 return Standard_False;
582 //! Auxiliary function to parse font strict level argument
583 static Standard_Integer parseFontStrictLevel (const Standard_Integer theArgNb,
584 const char** theArgVec,
585 Font_StrictLevel& theLevel)
589 TCollection_AsciiString anArg (theArgVec[0]);
593 theLevel = Font_StrictLevel_Any;
596 else if (anArg == "aliases")
598 theLevel = Font_StrictLevel_Aliases;
601 else if (anArg == "strict")
603 theLevel = Font_StrictLevel_Strict;
607 theLevel = Font_StrictLevel_Strict;
612 //==============================================================================
613 //function : Vtrihedron 2d
614 //purpose : Create a plane with a 2D trihedron from a faceselection
615 //Draw arg : vtri2d name
616 //==============================================================================
617 static int VTrihedron2D (Draw_Interpretor& /*theDI*/,
618 Standard_Integer theArgsNum,
619 const char** theArgVec)
621 if (ViewerTest::CurrentView().IsNull())
623 Message::SendFail ("Error: no active viewer");
628 Message::SendFail() << "Syntax error: wrong number of arguments.";
632 TopTools_ListOfShape aShapes;
633 ViewerTest::GetSelectedShapes (aShapes);
635 if (aShapes.Extent() != 1)
637 Message::SendFail ("Error: wrong number of selected shapes.");
641 const TopoDS_Shape& aShape = aShapes.First();
643 TopoDS_Face aFace = TopoDS::Face (aShape);
644 TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE);
645 TopoDS_Edge anEdge0 = TopoDS::Edge (aFaceExp.Current());
651 TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() );
652 BRepAdaptor_Curve aCurve0 (anEdge0);
653 BRepAdaptor_Curve aCurve1 (anEdge1);
654 A = aCurve1.Value (0.1);
655 B = aCurve1.Value (0.9);
656 C = aCurve0.Value (0.5);
660 BRepAdaptor_Curve aCurve0 (anEdge0);
661 A = aCurve0.Value (0.1);
662 B = aCurve0.Value (0.9);
663 C = aCurve0.Value (0.5);
666 GC_MakePlane aMkPlane (A,B,C);
668 Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value());
669 TCollection_AsciiString aName (theArgVec[1]);
671 VDisplayAISObject (aName, anAISPlaneTri);
676 //=======================================================================
677 //function : VTrihedron
679 //=======================================================================
680 static int VTrihedron (Draw_Interpretor& ,
681 Standard_Integer theArgsNb,
682 const char** theArgVec)
684 if (ViewerTest::CurrentView().IsNull())
686 Message::SendFail ("Error: no active viewer");
691 Message::SendFail ("Syntax error: the wrong number of input parameters");
695 TCollection_AsciiString aName (theArgVec[1]);
696 gp_Pln aWorkingPlane;
697 Standard_Boolean toUpdate = Standard_True;
699 NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
700 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
702 Handle(AIS_Trihedron) aTrihedron;
703 Handle(AIS_InteractiveObject) anObject;
704 if (GetMapOfAIS().Find2 (aName, anObject))
706 aTrihedron = Handle(AIS_Trihedron)::DownCast (anObject);
707 if (aTrihedron.IsNull())
709 Message::SendFail ("Syntax error: no trihedron with this name");
715 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (gp_Pnt (0.0, 0.0, 0.0),
717 aTrihedron = new AIS_Trihedron (aPlacement);
720 if (!setTrihedronParams (theArgsNb, theArgVec, aTrihedron))
725 // Redisplay a dimension after parameter changing.
726 if (ViewerTest::GetAISContext()->IsDisplayed (aTrihedron))
728 ViewerTest::GetAISContext()->Redisplay (aTrihedron, toUpdate);
732 VDisplayAISObject (theArgVec[1], aTrihedron);
738 //==============================================================================
741 //purpose : Change the size of a named or selected trihedron
742 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
743 // if no value, the value is set at 100 by default
744 //Draw arg : vsize [name] [size]
745 //==============================================================================
746 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
748 if (TheAISContext().IsNull())
750 Message::SendFail ("Error: no active viewer");
754 TCollection_AsciiString aName;
755 Standard_Real aSize = 0.0;
765 aSize = Draw::Atof (argv[1]);
771 aSize = Draw::Atof (argv[2]);
776 di << "Syntax error";
781 NCollection_Sequence<Handle(AIS_Trihedron)> aTrihedrons;
782 if (!aName.IsEmpty())
784 Handle(AIS_InteractiveObject) aShape;
785 if (GetMapOfAIS().Find2 (aName, aShape))
787 if (Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape))
789 aTrihedrons.Append (aTrihedron);
793 di << "Syntax error: " << aName << " is not a trihedron";
798 else if (TheAISContext()->NbSelected() > 0)
800 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS()); it.More(); it.Next())
802 const Handle(AIS_InteractiveObject)& aShape = it.Key1();
804 && TheAISContext()->IsSelected (aShape))
806 if (Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape))
808 aTrihedrons.Append (aTrihedron);
814 for (NCollection_Sequence<Handle(AIS_Trihedron)>::Iterator anObjIter (aTrihedrons); anObjIter.More(); anObjIter.Next())
816 const Handle(AIS_Trihedron)& aTrihedron = anObjIter.Value();
817 Quantity_Color aColor = Quantity_NOC_BLACK;
818 const bool hasColor = aTrihedron->HasColor();
821 aTrihedron->Color (aColor);
824 aTrihedron->SetSize (aSize);
825 if (hasColor) { aTrihedron->SetColor (aColor); }
826 else { aTrihedron->UnsetColor(); }
828 TheAISContext()->Redisplay (aTrihedron, Standard_False);
830 if (!aTrihedrons.IsEmpty())
832 TheAISContext()->UpdateCurrentViewer();
838 //==============================================================================
840 //==============================================================================
841 //function : VPlaneTrihedron
842 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
843 //Draw arg : vplanetri name
844 //==============================================================================
845 #include <AIS_Plane.hxx>
849 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
852 // Verification des arguments
853 if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
855 if (TheAISContext().IsNull())
857 Message::SendFail ("Error: no active viewer");
861 if (TheAISContext()->NbSelected() != 1)
863 Message::SendFail ("Error: Wrong number of selected shapes.");
867 TheAISContext()->InitSelected();
868 Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive();
869 Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest);
872 Message::SendFail ("Error: Selected shape is not a plane.");
876 VDisplayAISObject (argv[1], aPlane);
883 //==============================================================================
884 // Fonction First click 2de click
886 // vaxis vertex vertex
888 // vaxispara edge vertex
889 // vaxisortho edge Vertex
890 // vaxisinter Face Face
891 //==============================================================================
893 //==============================================================================
894 //function : VAxisBuilder
896 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
897 //==============================================================================
898 #include <TopoDS_Edge.hxx>
899 #include <TopoDS_Vertex.hxx>
900 #include <TopExp.hxx>
901 #include <Geom_Line.hxx>
903 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
906 Standard_Boolean HasArg;
907 TCollection_AsciiString name;
910 if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
911 if (argc==8) HasArg=Standard_True;
912 else HasArg=Standard_False;
916 TopTools_ListOfShape aShapes;
917 ViewerTest::GetSelectedShapes (aShapes);
919 // Cas ou il y a des arguments
920 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
922 Standard_Real coord[6];
923 for(Standard_Integer i=0;i<=5;i++){
924 coord[i]=Draw::Atof(argv[2+i]);
926 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
928 gp_Vec myVect (p1,p2);
929 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
930 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
931 GetMapOfAIS().Bind (TheAxis,name);
932 TheAISContext()->Display(TheAxis, Standard_True);
938 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
939 if ( !strcasecmp(argv[0], "vaxis")) {
940 if (aShapes.Extent() != 2 && aShapes.Extent() != 1)
942 Message::SendFail ("Error: Wrong number of selected shapes.");
946 const TopoDS_Shape& aShapeA = aShapes.First();
947 if (aShapeA.ShapeType() == TopAbs_VERTEX)
949 if (aShapes.Extent() != 2)
951 Message::SendFail ("Error: Wrong number of selected shapes.");
955 const TopoDS_Shape& aShapeB = aShapes.Last();
956 if (aShapeB.ShapeType() != TopAbs_VERTEX)
958 Message::SendFail ("Syntax error: You should select two vertices or one edge.");
962 // Construction de l'axe
963 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
964 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
967 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
968 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
969 GetMapOfAIS().Bind (TheAxis,name);
970 TheAISContext()->Display (TheAxis, Standard_True);
974 TopoDS_Edge ed =TopoDS::Edge (aShapeA);
976 TopExp::Vertices(ed,Va,Vb );
977 gp_Pnt A=BRep_Tool::Pnt(Va);
978 gp_Pnt B=BRep_Tool::Pnt(Vb);
981 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
982 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
983 GetMapOfAIS().Bind (TheAxis,name);
984 TheAISContext()->Display (TheAxis, Standard_True);
990 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
991 else if ( !strcasecmp(argv[0], "vaxispara"))
993 if (aShapes.Extent() != 2)
995 Message::SendFail ("Error: Wrong number of selected shapes.");
999 const TopoDS_Shape& aShapeA = aShapes.First();
1000 const TopoDS_Shape& aShapeB = aShapes.Last();
1001 if (!(aShapeA.ShapeType() == TopAbs_EDGE
1002 && aShapeB.ShapeType() == TopAbs_VERTEX))
1004 Message::SendFail ("Syntax error: You should select face and then vertex.");
1008 TopoDS_Edge ed=TopoDS::Edge (aShapeA);
1009 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1010 TopoDS_Vertex Va,Vc;
1011 TopExp::Vertices(ed,Va,Vc );
1012 gp_Pnt A=BRep_Tool::Pnt(Va);
1013 gp_Pnt C=BRep_Tool::Pnt(Vc);
1016 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1017 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1018 GetMapOfAIS().Bind (TheAxis,name);
1019 TheAISContext()->Display (TheAxis, Standard_True);
1023 // Fonction axisortho
1026 if (aShapes.Extent() != 2)
1028 Message::SendFail ("Error: Wrong number of selected shapes.");
1032 const TopoDS_Shape& aShapeA = aShapes.First();
1033 const TopoDS_Shape& aShapeB = aShapes.Last();
1034 if (!(aShapeA.ShapeType() == TopAbs_EDGE
1035 && aShapeB.ShapeType() == TopAbs_VERTEX))
1037 Message::SendFail ("Syntax error: You should select face and then vertex.");
1041 // Construction de l'axe
1042 TopoDS_Edge ed=TopoDS::Edge(aShapeA) ;
1043 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) );
1044 TopoDS_Vertex Va,Vc;
1045 TopExp::Vertices(ed,Va,Vc );
1046 gp_Pnt A=BRep_Tool::Pnt(Va);
1047 gp_Pnt C=BRep_Tool::Pnt(Vc);
1048 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
1051 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1052 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1053 GetMapOfAIS().Bind (TheAxis,name);
1054 TheAISContext()->Display (TheAxis, Standard_True);
1063 //==============================================================================
1064 // Fonction First click Result
1066 // vpoint vertex AIS_Point=Vertex
1067 // edge AIS_Point=Middle of the edge
1068 //==============================================================================
1070 //==============================================================================
1071 //function : VPointBuilder
1073 //==============================================================================
1074 #include <TopoDS_Edge.hxx>
1075 #include <TopoDS_Vertex.hxx>
1076 #include <TopExp.hxx>
1077 #include <AIS_Point.hxx>
1078 #include <Geom_CartesianPoint.hxx>
1080 static int VPointBuilder(Draw_Interpretor& ,
1081 Standard_Integer theArgNb,
1082 const char** theArgVec)
1084 TCollection_AsciiString aName;
1085 gp_Pnt aPnt (RealLast(), 0.0, 0.0);
1086 bool is2d = false, isNoSel = false;
1087 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
1089 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1095 else if (anArg == "-nosel"
1096 || anArg == "-noselection")
1100 else if (aName.IsEmpty())
1102 aName = theArgVec[anArgIter];
1104 else if (aPnt.X() == RealLast()
1105 && anArgIter + 1 < theArgNb
1106 && Draw::ParseReal (theArgVec[anArgIter + 0], aPnt.ChangeCoord().ChangeCoord (1))
1107 && Draw::ParseReal (theArgVec[anArgIter + 1], aPnt.ChangeCoord().ChangeCoord (2)))
1109 if (anArgIter + 2 < theArgNb
1110 && TCollection_AsciiString (theArgVec[anArgIter + 2]) != "-2d"
1111 && Draw::ParseReal (theArgVec[anArgIter + 2], aPnt.ChangeCoord().ChangeCoord (3)))
1122 Message::SendFail() << "Syntax error at argument '" << anArg << "'\n";
1127 if (aPnt.X() == RealLast())
1129 TopTools_ListOfShape aShapes;
1130 ViewerTest::GetSelectedShapes (aShapes);
1131 TopoDS_Shape aShapeA;
1132 if (aShapes.Extent() == 1)
1134 aShapeA = aShapes.First();
1136 switch (!aShapeA.IsNull() ? aShapeA.ShapeType() : TopAbs_SHAPE)
1140 aPnt = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1143 case TopAbs_EDGE: // edge middle point
1145 const TopoDS_Edge& anEdge = TopoDS::Edge (aShapeA);
1146 TopoDS_Vertex aVertPair[2];
1147 TopExp::Vertices (anEdge, aVertPair[0], aVertPair[1]);
1148 const gp_Pnt A = BRep_Tool::Pnt (aVertPair[0]);
1149 const gp_Pnt B = BRep_Tool::Pnt (aVertPair[1]);
1150 aPnt = (A.XYZ() + B.XYZ()) / 2;
1155 Message::SendFail() << "Error: Wrong number of selected shapes.\n"
1156 << "\tYou should select one edge or vertex.";
1164 aPnt.SetY (-aPnt.Y());
1166 Handle(Geom_CartesianPoint ) aGeomPoint = new Geom_CartesianPoint (aPnt);
1167 Handle(AIS_Point) aPointPrs = new AIS_Point (aGeomPoint);
1170 aPointPrs->SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_UPPER));
1171 aPointPrs->SetZLayer (Graphic3d_ZLayerId_TopOSD);
1173 ViewerTest::Display (aName, aPointPrs);
1176 ViewerTest::GetAISContext()->Deactivate (aPointPrs);
1181 //==============================================================================
1182 // Function 1st click 2de click 3de click
1183 // vplane Vertex Vertex Vertex
1187 // vplanepara Face Vertex
1189 // vplaneortho Face Edge
1191 //==============================================================================
1193 //==============================================================================
1194 //function : VPlaneBuilder
1195 //purpose : Build an AIS_Plane from selected entities or Named AIS components
1196 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
1197 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
1198 // [PlaneName] [PointName] [TypeOfSensitivity]
1199 //==============================================================================
1201 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
1202 Standard_Integer argc,
1206 Standard_Boolean hasArg;
1207 TCollection_AsciiString aName;
1210 if (argc<2 || argc>6 )
1212 Message::SendFail ("Syntax error: wrong number of arguments");
1215 if (argc == 6 || argc==5 || argc==4)
1216 hasArg=Standard_True;
1218 hasArg=Standard_False;
1222 // There are some arguments
1225 Handle(AIS_InteractiveObject) aShapeA;
1226 if (!GetMapOfAIS().Find2 (argv[2], aShapeA))
1228 Message::SendFail ("Syntax error: 1st name is not displayed");
1232 // The first argument is an AIS_Point
1233 if (!aShapeA.IsNull()
1234 && aShapeA->Type() == AIS_KindOfInteractive_Datum
1235 && aShapeA->Signature() == 1)
1237 // The second argument must also be an AIS_Point
1238 Handle(AIS_InteractiveObject) aShapeB;
1239 if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1241 Message::SendFail ("Syntax error: 2nd name is not displayed");
1245 // If B is not an AIS_Point
1246 if (aShapeB.IsNull()
1247 || !(aShapeB->Type() == AIS_KindOfInteractive_Datum
1248 && aShapeB->Signature() == 1))
1250 Message::SendFail ("Syntax error: 2nd object is expected to be an AIS_Point");
1254 // The third object is an AIS_Point
1255 Handle(AIS_InteractiveObject) aShapeC;
1256 if (!GetMapOfAIS().Find2(argv[4], aShapeC))
1258 Message::SendFail ("Syntax error: 3d name is not displayed");
1262 // If C is not an AIS_Point
1263 if (aShapeC.IsNull()
1264 || !(aShapeC->Type() == AIS_KindOfInteractive_Datum
1265 && aShapeC->Signature() == 1))
1267 Message::SendFail ("Syntax error: 3d object is expected to be an AIS_Point");
1271 // Treatment of objects A, B, C
1272 // Downcast an AIS_IO to AIS_Point
1273 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast (aShapeA);
1274 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast (aShapeB);
1275 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast (aShapeC);
1277 Handle(Geom_CartesianPoint ) aCartPointA = Handle(Geom_CartesianPoint)::DownCast (anAISPointA->Component());
1278 Handle(Geom_CartesianPoint ) aCartPointB = Handle(Geom_CartesianPoint)::DownCast (anAISPointB->Component());
1279 Handle(Geom_CartesianPoint ) aCartPointC = Handle(Geom_CartesianPoint)::DownCast (anAISPointC->Component());
1281 // Verification that the three points are different
1282 if (Abs(aCartPointB->X()-aCartPointA->X()) <= Precision::Confusion()
1283 && Abs(aCartPointB->Y()-aCartPointA->Y()) <= Precision::Confusion()
1284 && Abs(aCartPointB->Z()-aCartPointA->Z()) <= Precision::Confusion())
1287 Message::SendFail ("Error: same points");
1290 if (Abs(aCartPointC->X()-aCartPointA->X()) <= Precision::Confusion()
1291 && Abs(aCartPointC->Y()-aCartPointA->Y()) <= Precision::Confusion()
1292 && Abs(aCartPointC->Z()-aCartPointA->Z()) <= Precision::Confusion())
1295 Message::SendFail ("Error: same points");
1298 if (Abs(aCartPointC->X()-aCartPointB->X()) <= Precision::Confusion()
1299 && Abs(aCartPointC->Y()-aCartPointB->Y()) <= Precision::Confusion()
1300 && Abs(aCartPointC->Z()-aCartPointB->Z()) <= Precision::Confusion())
1303 Message::SendFail ("Error: same points");
1307 gp_Pnt A = aCartPointA->Pnt();
1308 gp_Pnt B = aCartPointB->Pnt();
1309 gp_Pnt C = aCartPointC->Pnt();
1311 // Construction of AIS_Plane
1312 GC_MakePlane MkPlane (A,B,C);
1313 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1314 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1315 GetMapOfAIS().Bind (anAISPlane, aName);
1318 Standard_Integer aType = Draw::Atoi (argv[5]);
1319 if (aType != 0 && aType != 1)
1321 Message::SendFail("Syntax error: wrong type of sensitivity.\n"
1322 "Should be one of the following values:\n"
1329 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1332 TheAISContext()->Display (anAISPlane, Standard_True);
1334 // The first argument is an AIS_Axis
1335 // Creation of a plane orthogonal to the axis through a point
1336 else if (aShapeA->Type() == AIS_KindOfInteractive_Datum
1337 && aShapeA->Signature() == 2)
1339 // The second argument should be an AIS_Point
1340 Handle(AIS_InteractiveObject) aShapeB;
1341 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1343 Message::SendFail ("Syntax error: 2d name is not displayed");
1346 // If B is not an AIS_Point
1347 if (aShapeB.IsNull()
1348 || !(aShapeB->Type() == AIS_KindOfInteractive_Datum
1349 && aShapeB->Signature() == 1))
1351 Message::SendFail ("Syntax error: 2d object is expected to be an AIS_Point");
1355 // Treatment of objects A and B
1356 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1357 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1359 Handle(Geom_Line ) aGeomLineA = anAISAxisA->Component();
1360 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1362 gp_Ax1 anAxis = aGeomLineA->Position();
1363 Handle(Geom_CartesianPoint) aCartPointB = Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1365 gp_Dir D = anAxis.Direction();
1366 gp_Pnt B = aCartPointB->Pnt();
1368 // Construction of AIS_Plane
1369 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1370 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1371 GetMapOfAIS().Bind (anAISPlane,aName );
1374 Standard_Integer aType = Draw::Atoi (argv[4]);
1375 if (aType != 0 && aType != 1)
1377 Message::SendFail ("Syntax error: wrong type of sensitivity!\n"
1378 "Should be one of the following values:\n"
1385 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1388 TheAISContext()->Display (anAISPlane, Standard_True);
1390 // The first argument is an AIS_Plane
1391 // Creation of a plane parallel to the plane passing through the point
1392 else if (aShapeA->Type() == AIS_KindOfInteractive_Datum
1393 && aShapeA->Signature() == 7)
1395 // The second argument should be an AIS_Point
1396 Handle(AIS_InteractiveObject) aShapeB;
1397 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1399 Message::SendFail ("Syntax error: 2d name is not displayed");
1402 // B should be an AIS_Point
1403 if (aShapeB.IsNull()
1404 || !(aShapeB->Type()==AIS_KindOfInteractive_Datum
1405 && aShapeB->Signature() == 1))
1407 Message::SendFail ("Syntax error: 2d object is expected to be an AIS_Point");
1411 // Treatment of objects A and B
1412 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1413 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1415 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1416 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1418 Handle(Geom_CartesianPoint) aCartPointB = Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1419 gp_Pnt B= aCartPointB->Pnt();
1421 // Construction of an AIS_Plane
1422 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1423 GetMapOfAIS().Bind (anAISPlane, aName);
1426 Standard_Integer aType = Draw::Atoi (argv[4]);
1427 if (aType != 0 && aType != 1)
1429 Message::SendFail ("Syntax error: wrong type of sensitivity!\n"
1430 "Should be one of the following values:\n"
1437 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1440 TheAISContext()->Display (anAISPlane, Standard_True);
1445 Message::SendFail ("Syntax error: 1st object is not an AIS");
1449 // There are no arguments
1452 TopTools_ListOfShape aShapes;
1453 ViewerTest::GetSelectedShapes (aShapes);
1456 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1457 if (!strcasecmp(argv[0], "vplane"))
1459 if (aShapes.Extent() < 1 || aShapes.Extent() > 3)
1461 Message::SendFail() << "Error: Wront number of selected shapes.\n"
1462 << "\tYou should one of variant: face, edge and vertex or three vertices.";
1466 const TopoDS_Shape& aShapeA = aShapes.First();
1467 if (aShapeA.ShapeType() == TopAbs_VERTEX)
1469 if (aShapes.Extent() == 2)
1471 const TopoDS_Shape& aShapeB = aShapes.Last();
1472 if (aShapeB.ShapeType() != TopAbs_EDGE)
1474 Message::SendFail ("Syntax error: Together with vertex should be edge.");
1478 // Verify that the vertex is not on the edge ShapeB
1479 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1480 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1482 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1483 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1485 // The vertex is on the edge
1486 Message::SendFail ("Error: point is on the edge");
1491 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1492 TopoDS_Vertex aVBa, aVBb;
1493 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1494 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1495 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1496 GC_MakePlane MkPlane (A, aBa, aBb);
1497 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1498 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1499 GetMapOfAIS().Bind (anAISPlane, aName);
1500 TheAISContext()->Display (anAISPlane, Standard_True);
1503 else if (aShapes.Extent() == 3)
1505 TopTools_ListOfShape::Iterator anIter (aShapes);
1508 const TopoDS_Shape& aShapeB = anIter.Value();
1511 const TopoDS_Shape& aShapeC = anIter.Value();
1513 if (!(aShapeB.ShapeType() == TopAbs_VERTEX
1514 && aShapeC.ShapeType() == TopAbs_VERTEX))
1516 Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices.");
1520 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1521 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1522 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1523 GC_MakePlane MkPlane(A, B, C);
1524 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1525 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1526 GetMapOfAIS().Bind (anAISPlane, aName);
1527 TheAISContext()->Display (anAISPlane, Standard_True);
1531 Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices.");
1535 else if (aShapeA.ShapeType() == TopAbs_EDGE)
1537 if (aShapes.Extent() != 2)
1539 Message::SendFail ("Error: wrong number of selected shapes.");
1543 const TopoDS_Shape& aShapeB = aShapes.Last();
1544 if (aShapeB.ShapeType() != TopAbs_VERTEX)
1546 Message::SendFail ("Syntax error: Together with edge should be vertex.");
1550 // Check that the vertex aShapeB is not on the edge
1551 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1552 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1554 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1555 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1557 // The vertex is on the edge
1558 Message::SendFail ("Error point is on the edge");
1562 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1563 TopoDS_Vertex aVAa, aVAb;
1564 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1565 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1566 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1567 GC_MakePlane MkPlane (B,Aa,Ab);
1568 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1569 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1570 GetMapOfAIS().Bind (anAISPlane ,aName);
1571 TheAISContext()->Display (anAISPlane, Standard_True);
1573 else if (aShapeA.ShapeType() == TopAbs_FACE)
1575 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1576 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1577 if (aSurface.GetType()==GeomAbs_Plane)
1579 gp_Pln aPlane = aSurface.Plane();
1580 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1581 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1582 GetMapOfAIS().Bind (anAISPlane, aName);
1583 TheAISContext()->Display (anAISPlane, Standard_True);
1587 Message::SendFail ("Error: surface is not Plane");
1593 Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices");
1598 // Function vPlanePara
1599 // ===================
1600 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1601 else if (!strcasecmp(argv[0], "vplanepara"))
1603 if (aShapes.Extent() != 2)
1605 Message::SendFail ("Error: Wrong number of selected shapes.");
1609 const TopoDS_Shape* aShapeA = &aShapes.First();
1610 const TopoDS_Shape* aShapeB = &aShapes.Last();
1611 if (aShapeA->ShapeType() != TopAbs_VERTEX)
1613 std::swap (aShapeA, aShapeB);
1616 if (!(aShapeA->ShapeType() == TopAbs_VERTEX
1617 && aShapeB->ShapeType() == TopAbs_FACE))
1619 Message::SendFail ("Syntax error: you should select face and vertex.");
1623 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA));
1625 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1626 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1627 if (aSurface.GetType() == GeomAbs_Plane)
1629 gp_Pln aPlane = aSurface.Plane();
1630 // Construct a plane parallel to aGeomPlane through A
1631 aPlane.SetLocation(A);
1632 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1633 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1634 GetMapOfAIS().Bind (aAISPlane ,aName);
1635 TheAISContext()->Display (aAISPlane, Standard_True);
1639 Message::SendFail ("Error: Built surface is not a plane.");
1644 // Function vplaneortho
1645 // ====================
1646 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1649 if (aShapes.Extent() != 2)
1651 Message::SendFail ("Error: wrong number of selected shapes.");
1655 const TopoDS_Shape* aShapeA = &aShapes.First();
1656 const TopoDS_Shape* aShapeB = &aShapes.Last();
1658 if (aShapeA->ShapeType() != TopAbs_EDGE)
1660 std::swap (aShapeA, aShapeB);
1663 if (!(aShapeA->ShapeType() == TopAbs_EDGE
1664 && aShapeB->ShapeType() == TopAbs_FACE))
1666 Message::SendFail ("Error: you should select edge and face.");
1670 // Construction of plane
1671 TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA);
1672 TopoDS_Vertex aVAa, aVAb;
1673 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1674 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1675 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1679 // Creation of rotation axis
1680 gp_Ax1 aRotAxis (Aa,Dab);
1682 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1683 // The edge must be parallel to the face
1684 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1685 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1686 // Compare to heights
1687 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1688 >Precision::Confusion())
1690 // the edge is not parallel to the face
1691 Message::SendFail ("Error: the edge is not parallel to the face");
1695 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1696 if (aSurface.GetType()==GeomAbs_Plane)
1698 gp_Pln aPlane = aSurface.Plane();
1699 // It rotates a half turn round the axis of rotation
1700 aPlane.Rotate(aRotAxis , M_PI/2);
1702 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1703 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1704 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1705 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1706 GetMapOfAIS().Bind (anAISPlane, aName);
1707 TheAISContext()->Display (anAISPlane, Standard_True);
1711 Message::SendFail ("Error: surface is not Plane");
1719 //===============================================================================================
1720 //function : VChangePlane
1722 //===============================================================================================
1723 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1725 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1726 if (aContextAIS.IsNull())
1728 Message::SendFail ("Error: no active viewer.");
1732 if (theArgsNb < 3 || theArgsNb > 11)
1734 Message::SendFail ("Syntax error: wrong number of arguments.");
1738 TCollection_AsciiString aName (theArgVec[1]);
1740 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1741 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1744 if ( aPlane.IsNull() )
1746 Message::SendFail() << "Syntax error: there is no interactive plane with the given name '" << aName << "'.";
1750 Standard_Real aCenterX = aPlane->Center().X();
1751 Standard_Real aCenterY = aPlane->Center().Y();
1752 Standard_Real aCenterZ = aPlane->Center().Z();
1754 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1755 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1756 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1758 Standard_Real aSizeX = 0.0;
1759 Standard_Real aSizeY = 0.0;
1760 Standard_Boolean aHasMinSize = aPlane->HasMinimumSize();
1761 Standard_Real aMinSizeY = 0.0;
1762 aPlane->Size (aSizeX, aSizeY);
1763 Standard_Boolean isUpdate = Standard_True;
1765 TCollection_AsciiString aPName, aPValue;
1766 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1768 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1769 TCollection_AsciiString anArgCase = anArg;
1770 anArgCase.UpperCase();
1771 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1774 if (aPName.IsEqual ("X"))
1776 aCenterX = aPValue.RealValue();
1778 else if (aPName.IsEqual ("Y"))
1780 aCenterY = aPValue.RealValue();
1782 else if (aPName.IsEqual ("Z"))
1784 aCenterZ = aPValue.RealValue();
1786 else if (aPName.IsEqual ("DX"))
1788 aDirX = aPValue.RealValue();
1790 else if (aPName.IsEqual ("DY"))
1792 aDirY = aPValue.RealValue();
1794 else if (aPName.IsEqual ("DZ"))
1796 aDirZ = aPValue.RealValue();
1798 else if (aPName.IsEqual ("SX"))
1800 aSizeX = aPValue.RealValue();
1802 else if (aPName.IsEqual ("SY"))
1804 aSizeY = aPValue.RealValue();
1806 else if (aPName.IsEqual ("MINSIZE"))
1808 aHasMinSize = Standard_True;
1809 aMinSizeY = aPValue.RealValue();
1812 else if (anArg.IsEqual ("NOUPDATE"))
1814 isUpdate = Standard_False;
1818 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1819 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1820 aPlane->SetCenter (aCenterPnt);
1821 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1822 aPlane->SetSize (aSizeX, aSizeY);
1826 aPlane->SetMinimumSize (aMinSizeY);
1828 else if (aPlane->HasMinimumSize())
1830 aPlane->UnsetMinimumSize();
1833 aContextAIS->Update (aPlane, isUpdate);
1838 //==============================================================================
1840 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1841 //==============================================================================
1843 //==============================================================================
1844 //function : VLineBuilder
1845 //purpose : Build an AIS_Line
1846 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1847 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1848 //==============================================================================
1849 #include <Geom_CartesianPoint.hxx>
1850 #include <AIS_Line.hxx>
1853 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1855 if (argc == 4) // parameters: AIS_Point AIS_Point
1857 Handle(AIS_InteractiveObject) aShapeA, aShapeB;
1858 GetMapOfAIS().Find2 (argv[2], aShapeA);
1859 GetMapOfAIS().Find2 (argv[3], aShapeB);
1860 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast (aShapeA);
1861 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast (aShapeB);
1862 if (anAISPointA.IsNull()
1863 || anAISPointB.IsNull())
1865 di << "vline error: wrong type of arguments\n";
1869 Handle(Geom_Point) aGeomPointBA = anAISPointA->Component();
1870 Handle(Geom_CartesianPoint) aCartPointA = Handle(Geom_CartesianPoint)::DownCast (aGeomPointBA);
1872 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1873 Handle(Geom_CartesianPoint) aCartPointB = Handle(Geom_CartesianPoint)::DownCast (aGeomPointB);
1875 if (aCartPointB->X() == aCartPointA->X()
1876 && aCartPointB->Y() == aCartPointA->Y()
1877 && aCartPointB->Z() == aCartPointA->Z())
1880 di << "vline error: same points\n";
1884 Handle(AIS_Line) anAISLine = new AIS_Line (aCartPointA, aCartPointB);
1885 GetMapOfAIS().Bind (anAISLine, argv[1]);
1886 TheAISContext()->Display (anAISLine, Standard_True);
1888 else if (argc == 8) // parametres 6 reals
1890 Standard_Real aCoord[6] = {};
1891 for (Standard_Integer i = 0; i <= 2; ++i)
1893 aCoord[i] = Draw::Atof (argv[2 + i]);
1894 aCoord[i + 3] = Draw::Atof (argv[5 + i]);
1897 Handle(Geom_CartesianPoint) aCartPointA = new Geom_CartesianPoint (aCoord[0], aCoord[1], aCoord[2]);
1898 Handle(Geom_CartesianPoint) aCartPointB = new Geom_CartesianPoint (aCoord[3], aCoord[4], aCoord[5]);
1900 Handle(AIS_Line) anAISLine = new AIS_Line (aCartPointA, aCartPointB);
1901 GetMapOfAIS().Bind (anAISLine, argv[1]);
1902 TheAISContext()->Display (anAISLine, Standard_True);
1905 else if (argc == 2) // selection in 3D viewer
1907 TopTools_ListOfShape aShapes;
1908 ViewerTest::GetSelectedShapes (aShapes);
1909 if (aShapes.Extent() != 2)
1911 Message::SendFail ("Error: wrong number of selected shapes.");
1915 const TopoDS_Shape& aShapeA = aShapes.First();
1916 const TopoDS_Shape& aShapeB = aShapes.Last();
1917 if (aShapeA.ShapeType() != TopAbs_VERTEX
1918 || aShapeB.ShapeType() != TopAbs_VERTEX)
1920 Message::SendFail ("Error: you should select two different vertex.");
1924 // Construction de la line
1925 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1926 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
1928 Handle(Geom_CartesianPoint) aCartPointA = new Geom_CartesianPoint (A);
1929 Handle(Geom_CartesianPoint) aCartPointB = new Geom_CartesianPoint (B);
1931 Handle(AIS_Line) anAISLine = new AIS_Line (aCartPointA, aCartPointB);
1932 GetMapOfAIS().Bind (anAISLine, argv[1]);
1933 TheAISContext()->Display (anAISLine, Standard_True);
1937 di << "Syntax error: wrong number of arguments";
1944 //==============================================================================
1945 // class : FilledCircle
1946 // purpose : creates filled circle based on AIS_InteractiveObject
1948 // This class is used to check method Matches() of class
1949 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1950 // because none of AIS classes provides creation of
1951 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1952 // (look method ComputeSelection() )
1953 //==============================================================================
1955 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1957 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1958 gp_Circ aCirc(anAxes, theRadius);
1959 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1963 class FilledCircle : public AIS_InteractiveObject
1967 DEFINE_STANDARD_RTTI_INLINE(FilledCircle, AIS_InteractiveObject);
1969 FilledCircle (const Handle(Geom_Circle)& theCircle,
1970 const Standard_Real theUStart,
1971 const Standard_Real theUEnd);
1973 FilledCircle (const gp_Pnt& theCenter,
1974 const Standard_Real theRadius,
1975 const Standard_Real theUStart,
1976 const Standard_Real theUEnd);
1979 TopoDS_Face ComputeFace();
1981 // Virtual methods implementation
1982 virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
1983 const Handle(Prs3d_Presentation)& thePrs,
1984 const Standard_Integer theMode) Standard_OVERRIDE;
1986 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel,
1987 const Standard_Integer theMode) Standard_OVERRIDE;
1991 Handle(Geom_Circle) myCircle;
1992 Standard_Real myUStart;
1993 Standard_Real myUEnd;
1994 Standard_Boolean myFilledStatus;
1998 FilledCircle::FilledCircle (const Handle(Geom_Circle)& theCircle,
1999 const Standard_Real theUStart,
2000 const Standard_Real theUEnd)
2001 : myCircle (theCircle),
2002 myUStart (theUStart),
2004 myFilledStatus (Standard_True)
2007 FilledCircle::FilledCircle (const gp_Pnt& theCenter,
2008 const Standard_Real theRadius,
2009 const Standard_Real theUStart,
2010 const Standard_Real theUEnd)
2011 : FilledCircle (CreateCircle (theCenter, theRadius), theUStart, theUEnd)
2014 TopoDS_Face FilledCircle::ComputeFace()
2016 // Create edge from myCircle
2017 BRepBuilderAPI_MakeEdge anEdgeMaker (myCircle->Circ(), myUStart, myUEnd);
2018 TopoDS_Edge anEdge = anEdgeMaker.Edge();
2020 // Create wire from anEdge
2021 BRepBuilderAPI_MakeWire aWireMaker;
2022 if (Abs (Abs (myUEnd - myUStart) - 2.0 * M_PI) > gp::Resolution())
2024 TopoDS_Edge anEndCenterEdge = BRepBuilderAPI_MakeEdge (myCircle->Value (myUEnd), myCircle->Location()).Edge();
2025 TopoDS_Edge aStartCenterEdge = BRepBuilderAPI_MakeEdge (myCircle->Location(), myCircle->Value (myUStart)).Edge();
2026 aWireMaker = BRepBuilderAPI_MakeWire (anEdge, anEndCenterEdge, aStartCenterEdge);
2030 aWireMaker = BRepBuilderAPI_MakeWire (anEdge);
2032 TopoDS_Wire aWire = aWireMaker.Wire();
2034 // Create face from aWire
2035 BRepBuilderAPI_MakeFace aFaceMaker (aWire);
2036 TopoDS_Face aFace = aFaceMaker.Face();
2041 void FilledCircle::Compute (const Handle(PrsMgr_PresentationManager)& ,
2042 const Handle(Prs3d_Presentation)& thePrs,
2043 const Standard_Integer theMode)
2047 TopoDS_Face aFace = ComputeFace();
2049 if (aFace.IsNull()) return;
2050 if (theMode != 0) return;
2052 StdPrs_ShadedShape::Add (thePrs, aFace, myDrawer);
2055 void FilledCircle::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection,
2056 const Standard_Integer /*theMode*/)
2058 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2059 Handle(Select3D_SensitiveEntity) aSensitiveCircle;
2061 if (Abs (Abs (myUEnd - myUStart) - 2.0 * M_PI) > gp::Resolution())
2063 aSensitiveCircle = new Select3D_SensitivePoly (anEntityOwner, myCircle->Circ(), myUStart, myUEnd, myFilledStatus);
2067 aSensitiveCircle = new Select3D_SensitiveCircle (anEntityOwner, myCircle->Circ(), myFilledStatus);
2070 theSelection->Add (aSensitiveCircle);
2073 //==============================================================================
2075 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2076 //==============================================================================
2078 //==============================================================================
2079 //function : VCircleBuilder
2080 //purpose : Build an AIS_Circle
2081 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled UStart UEnd
2082 // PointName PointName PointName IsFilled UStart UEnd
2083 //==============================================================================
2085 void DisplayCircle (const Handle(Geom_Circle)& theGeomCircle,
2086 const TCollection_AsciiString& theName,
2087 const Standard_Boolean isFilled,
2088 const Standard_Real theUStart,
2089 const Standard_Real theUEnd)
2091 Handle(AIS_InteractiveObject) aCircle;
2094 aCircle = new FilledCircle (theGeomCircle, theUStart, theUEnd);
2098 aCircle = new AIS_Circle (theGeomCircle, theUStart, theUEnd, Standard_False);
2101 // Check if there is an object with given name
2102 // and remove it from context
2103 if (GetMapOfAIS().IsBound2(theName))
2105 Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2 (theName);
2106 TheAISContext()->Remove (anInterObj, Standard_False);
2107 GetMapOfAIS().UnBind2 (theName);
2110 // Bind the circle to its name
2111 GetMapOfAIS().Bind (aCircle, theName);
2113 // Display the circle
2114 TheAISContext()->Display (aCircle, Standard_True);
2117 static int VCircleBuilder (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2119 if (argc > 8 || argc < 2)
2121 Message::SendFail ("Syntax error: wrong number of arguments");
2125 Standard_Real anUStart = 0, anUEnd = M_PI * 2.0;
2128 anUStart = Draw::Atof (argv[6]) * M_PI / 180.0;
2129 anUEnd = Draw::Atof (argv[7]) * M_PI / 180.0;
2133 anUStart = Draw::Atof (argv[2]) * M_PI / 180.0;
2134 anUEnd = Draw::Atof (argv[3]) * M_PI / 180.0;
2137 if (argc == 6 || argc == 8)
2139 TCollection_AsciiString aName (argv[1]);
2140 Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0;
2142 Handle(AIS_InteractiveObject) aShapeA, aShapeB;
2143 GetMapOfAIS().Find2 (argv[2], aShapeA);
2144 GetMapOfAIS().Find2 (argv[3], aShapeB);
2146 // Arguments: AIS_Point AIS_Point AIS_Point
2147 if (!aShapeA.IsNull()
2148 && !aShapeB.IsNull()
2149 && aShapeA->Type() == AIS_KindOfInteractive_Datum
2150 && aShapeA->Signature() == 1)
2152 Handle(AIS_InteractiveObject) aShapeC;
2153 GetMapOfAIS().Find2 (argv[4], aShapeC);
2154 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast (aShapeA);
2155 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast (aShapeB);
2156 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast (aShapeC);
2157 if (anAISPointA.IsNull()
2158 || anAISPointB.IsNull()
2159 || anAISPointC.IsNull())
2161 Message::SendFail ("Error: arguments are expected to be points");
2165 // Verify that the three points are different
2166 Handle(Geom_CartesianPoint) aCartPointA = Handle(Geom_CartesianPoint)::DownCast (anAISPointA->Component());
2167 Handle(Geom_CartesianPoint) aCartPointB = Handle(Geom_CartesianPoint)::DownCast (anAISPointB->Component());
2168 Handle(Geom_CartesianPoint) aCartPointC = Handle(Geom_CartesianPoint)::DownCast (anAISPointC->Component());
2170 if (Abs(aCartPointA->X() - aCartPointB->X()) <= Precision::Confusion()
2171 && Abs(aCartPointA->Y() - aCartPointB->Y()) <= Precision::Confusion()
2172 && Abs(aCartPointA->Z() - aCartPointB->Z()) <= Precision::Confusion())
2174 Message::SendFail ("Error: Same points");
2178 if (Abs(aCartPointA->X() - aCartPointC->X()) <= Precision::Confusion()
2179 && Abs(aCartPointA->Y() - aCartPointC->Y()) <= Precision::Confusion()
2180 && Abs(aCartPointA->Z() - aCartPointC->Z()) <= Precision::Confusion())
2182 Message::SendFail ("Error: Same points");
2186 if (Abs(aCartPointB->X() - aCartPointC->X()) <= Precision::Confusion()
2187 && Abs(aCartPointB->Y() - aCartPointC->Y()) <= Precision::Confusion()
2188 && Abs(aCartPointB->Z() - aCartPointC->Z()) <= Precision::Confusion())
2190 Message::SendFail ("Error: Same points");
2193 // Construction of the circle
2194 GC_MakeCircle aCir = GC_MakeCircle (aCartPointA->Pnt(), aCartPointB->Pnt(), aCartPointC->Pnt());
2195 Handle (Geom_Circle) aGeomCircle;
2198 aGeomCircle = aCir.Value();
2200 catch (StdFail_NotDone const&)
2202 Message::SendFail ("Error: can't create circle");
2206 DisplayCircle (aGeomCircle, aName, isFilled, anUStart, anUEnd);
2209 // Arguments: AIS_Plane AIS_Point Real
2210 else if (aShapeA->Type() == AIS_KindOfInteractive_Datum
2211 && aShapeA->Signature() == 7)
2213 Handle(AIS_Plane) anAISPlane = Handle(AIS_Plane)::DownCast (aShapeA);
2214 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast (aShapeB);
2215 if (anAISPointB.IsNull())
2217 Message::SendFail ("Error: 2d element is a expected to be a point");
2221 // Check that the radius is >= 0
2222 const Standard_Real anR = Draw::Atof (argv[4]);
2225 Message::SendFail ("Syntax error: the radius must be >=0");
2229 // Recover the normal to the plane
2230 Handle(Geom_Plane) aGeomPlane = anAISPlane->Component();
2231 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
2232 Handle(Geom_CartesianPoint) aCartPointB = Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
2234 gp_Pln aGpPlane = aGeomPlane->Pln();
2235 gp_Ax1 aGpAxe = aGpPlane.Axis();
2236 gp_Dir aDir = aGpAxe.Direction();
2237 gp_Pnt aCenter = aCartPointB->Pnt();
2238 GC_MakeCircle aCir = GC_MakeCircle (aCenter, aDir, anR);
2239 Handle(Geom_Circle) aGeomCircle;
2242 aGeomCircle = aCir.Value();
2244 catch (StdFail_NotDone const&)
2246 Message::SendFail ("Error: can't create circle");
2250 DisplayCircle (aGeomCircle, aName, isFilled, anUStart, anUEnd);
2254 Message::SendFail ("Error: 1st argument has an unexpected type");
2258 else // No arguments: selection in the viewer
2260 // Get the name of the circle
2261 TCollection_AsciiString aName (argv[1]);
2263 TopTools_ListOfShape aShapes;
2264 ViewerTest::GetSelectedShapes (aShapes);
2265 if (aShapes.Extent() != 3 && aShapes.Extent() != 2)
2267 Message::SendFail ("Error: Wrong number of selected shapes.");
2271 const TopoDS_Shape& aShapeA = aShapes.First();
2272 if (aShapeA.ShapeType() == TopAbs_VERTEX)
2274 if (aShapes.Extent() != 3)
2276 Message::SendFail ("Error: wrong number of selected shapes.");
2280 TopTools_ListOfShape::Iterator anIter (aShapes);
2283 const TopoDS_Shape& aShapeB = anIter.Value();
2286 const TopoDS_Shape& aShapeC = anIter.Value();
2289 Standard_Boolean isFilled;
2290 std::cout << "Enter filled status (0 or 1)\n";
2291 std::cin >> isFilled;
2293 // Construction of the circle
2294 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
2295 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2296 gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC));
2298 GC_MakeCircle aCir = GC_MakeCircle (A, B, C);
2299 Handle(Geom_Circle) aGeomCircle;
2302 aGeomCircle = aCir.Value();
2304 catch (StdFail_NotDone const&)
2306 Message::SendFail ("Error: can't create circle");
2310 DisplayCircle (aGeomCircle, aName, isFilled, anUStart, anUEnd);
2312 else if (aShapeA.ShapeType() == TopAbs_FACE)
2314 const TopoDS_Shape& aShapeB = aShapes.Last();
2316 // Recover the radius
2317 Standard_Real aRad = 0.0;
2320 std::cout << " Enter the value of the radius:\n";
2322 } while (aRad <= 0);
2324 // Get filled status
2325 Standard_Boolean isFilled;
2326 std::cout << "Enter filled status (0 or 1)\n";
2327 std::cin >> isFilled;
2329 // Recover the normal to the plane. tag
2330 TopoDS_Face aFace = TopoDS::Face (aShapeA);
2331 BRepAdaptor_Surface aSurface (aFace, Standard_False);
2332 gp_Pln aPlane = aSurface.Plane();
2333 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
2334 gp_Pln aGpPlane = aGeomPlane->Pln();
2335 gp_Ax1 aGpAxe = aGpPlane.Axis();
2336 gp_Dir aDir = aGpAxe.Direction();
2338 // Recover the center
2339 gp_Pnt aCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2341 // Construct the circle
2342 GC_MakeCircle aCir = GC_MakeCircle (aCenter, aDir, aRad);
2343 Handle(Geom_Circle) aGeomCircle;
2346 aGeomCircle = aCir.Value();
2348 catch (StdFail_NotDone const&)
2350 Message::SendFail ("Error: can't create circle");
2354 DisplayCircle (aGeomCircle, aName, isFilled, anUStart, anUEnd);
2358 Message::SendFail ("Error: You should select face and vertex or three vertices.");
2366 //=======================================================================
2367 //function : VDrawText
2369 //=======================================================================
2370 static int VDrawText (Draw_Interpretor& theDI,
2371 Standard_Integer theArgsNb,
2372 const char** theArgVec)
2374 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2377 Message::SendFail ("Syntax error: wrong number of arguments. See usage:");
2378 theDI.PrintHelp (theArgVec[0]);
2381 else if (aContext.IsNull())
2383 Message::SendFail ("Error: no active viewer");
2387 Standard_Integer anArgIt = 1;
2388 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2389 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2390 Handle(AIS_TextLabel) aTextPrs;
2391 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2393 Standard_Boolean isNewPrs = Standard_False;
2394 if (GetMapOfAIS().IsBound2 (aName))
2396 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2399 if (aTextPrs.IsNull())
2401 isNewPrs = Standard_True;
2402 aTextPrs = new AIS_TextLabel();
2405 aTextPrs->SetText (aText);
2407 Handle(Graphic3d_TransformPers) aTrsfPers;
2408 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2410 Standard_Boolean aHasPlane = Standard_False;
2416 Handle(Font_TextFormatter) aTextFormatter;
2417 for (; anArgIt < theArgsNb; ++anArgIt)
2419 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2422 if (anAutoUpdater.parseRedrawMode (aParam))
2426 else if ((aParam == "-pos"
2427 || aParam == "-position")
2428 && anArgIt + 3 < theArgsNb)
2430 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2431 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2432 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2433 aTextPrs->SetPosition (aPos);
2435 else if (aParam == "-color")
2437 Quantity_Color aColor;
2438 Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIt - 1,
2439 theArgVec + anArgIt + 1,
2443 Message::SendFail() << "Syntax error at '" << aParam << "'";
2446 anArgIt += aNbParsed;
2447 aTextPrs->SetColor (aColor);
2449 else if ((aParam == "-halign"
2450 || aParam == "-valign"
2451 || aParam == "-align")
2452 && anArgIt + 1 < theArgsNb)
2454 TCollection_AsciiString aType (theArgVec[++anArgIt]);
2456 if (aType == "left")
2458 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2459 if (aParam == "-valign")
2461 Message::SendFail() << "Syntax error at '" << aParam << "'";
2465 else if (aType == "center")
2467 if (aParam == "-halign"
2468 || aParam == "-align")
2470 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2472 if (aParam == "-valign"
2473 || aParam == "-align")
2475 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2478 else if (aType == "right")
2480 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2481 if (aParam == "-valign")
2483 Message::SendFail() << "Syntax error at '" << aParam << "'";
2487 else if (aType == "top")
2489 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2490 if (aParam == "-halign")
2492 Message::SendFail() << "Syntax error at '" << aParam << "'";
2496 else if (aType == "bottom")
2498 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2499 if (aParam == "-halign")
2501 Message::SendFail() << "Syntax error at '" << aParam << "'";
2505 else if (aType == "topfirstline")
2507 aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2508 if (aParam == "-halign")
2510 Message::SendFail() << "Syntax error at '" << aParam << "'";
2516 Message::SendFail() << "Syntax error at '" << aParam << "'";
2520 else if (aParam == "-angle"
2521 && anArgIt + 1 < theArgsNb)
2523 aTextPrs->SetAngle (Draw::Atof (theArgVec[++anArgIt]) * (M_PI / 180.0));
2525 else if (aParam == "-zoom"
2526 || aParam == "-nozoom"
2527 || aParam == "-zoomable"
2528 || aParam == "-nonzoomable")
2530 const bool isZoomable = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIt);
2531 aTextPrs->SetZoomable (isZoomable);
2533 else if (aParam == "-height"
2534 && anArgIt + 1 < theArgsNb)
2536 aTextPrs->SetHeight (Draw::Atof(theArgVec[++anArgIt]));
2538 else if (aParam == "-wrapping"
2539 && anArgIt + 1 < theArgsNb)
2541 if (aTextFormatter.IsNull())
2543 aTextFormatter = new Font_TextFormatter();
2545 aTextFormatter->SetWrapping ((Standard_ShortReal)Draw::Atof(theArgVec[++anArgIt]));
2547 else if (aParam == "-wordwrapping")
2549 const bool isWordWrapping = Draw::ParseOnOffNoIterator(theArgsNb, theArgVec, anArgIt);
2550 aTextFormatter->SetWordWrapping(isWordWrapping);
2552 else if (aParam == "-aspect"
2553 && anArgIt + 1 < theArgsNb)
2555 TCollection_AsciiString anOption (theArgVec[++anArgIt]);
2556 anOption.LowerCase();
2557 Font_FontAspect aFontAspect = Font_FA_Undefined;
2558 if (!parseFontStyle (anOption, aFontAspect))
2560 Message::SendFail() << "Syntax error: unknown font aspect '" << anOption << "'";
2563 aTextPrs->SetFontAspect (aFontAspect);
2565 else if (aParam == "-font"
2566 && anArgIt + 1 < theArgsNb)
2568 aTextPrs->SetFont (theArgVec[++anArgIt]);
2570 else if (aParam == "-plane"
2571 && anArgIt + 6 < theArgsNb)
2573 aNormal.SetCoord (Draw::Atof (theArgVec[anArgIt + 1]),
2574 Draw::Atof (theArgVec[anArgIt + 2]),
2575 Draw::Atof (theArgVec[anArgIt + 3]));
2576 aDirection.SetCoord (Draw::Atof (theArgVec[anArgIt + 4]),
2577 Draw::Atof (theArgVec[anArgIt + 5]),
2578 Draw::Atof (theArgVec[anArgIt + 6]));
2579 aHasPlane = Standard_True;
2582 else if (aParam == "-flipping"
2583 || aParam == "-noflipping"
2584 || aParam == "-flip"
2585 || aParam == "-noflip")
2587 const bool toFlip = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIt);
2588 aTextPrs->SetFlipping (toFlip);
2590 else if (aParam == "-ownanchor"
2591 || aParam == "-noownanchor")
2593 const bool isOwnAnchor = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIt);
2594 aTextPrs->SetOwnAnchorPoint (isOwnAnchor);
2596 else if ((aParam == "-disptype"
2597 || aParam == "-displaytype")
2598 && anArgIt + 1 < theArgsNb)
2600 TCollection_AsciiString aType (theArgVec[++anArgIt]);
2602 if (aType == "subtitle") { aDisplayType = Aspect_TODT_SUBTITLE; }
2603 else if (aType == "decal") { aDisplayType = Aspect_TODT_DEKALE; }
2604 else if (aType == "blend") { aDisplayType = Aspect_TODT_BLEND; }
2605 else if (aType == "dimension") { aDisplayType = Aspect_TODT_DIMENSION; }
2606 else if (aType == "normal") { aDisplayType = Aspect_TODT_NORMAL; }
2607 else if (aType == "shadow") { aDisplayType = Aspect_TODT_SHADOW; }
2610 Message::SendFail() << "Syntax error: wrong display type '" << aType << "'";
2614 else if (aParam == "-subcolor"
2615 || aParam == "-subtitlecolor")
2617 Quantity_Color aColor;
2618 Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIt - 1,
2619 theArgVec + anArgIt + 1,
2623 Message::SendFail() << "Syntax error at '" << aParam << "'";
2626 anArgIt += aNbParsed;
2627 aTextPrs->SetColorSubTitle (aColor);
2629 else if (aParam == "-2d")
2631 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d);
2633 else if (aParam == "-trsfperspos"
2634 || aParam == "-perspos")
2636 if (anArgIt + 2 >= theArgsNb)
2638 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'.";
2642 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2643 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2644 TCollection_AsciiString aZ = "0";
2645 if (!aX.IsIntegerValue()
2646 || !aY.IsIntegerValue())
2648 Message::SendFail() << "Error: wrong syntax at '" << aParam << "'.";
2651 if (anArgIt + 1 < theArgsNb)
2653 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2654 if (aTemp.IsIntegerValue())
2661 Standard_Integer aCorner = Aspect_TOTP_CENTER;
2662 if (aX.IntegerValue() > 0.0) { aCorner |= Aspect_TOTP_RIGHT; }
2663 else if (aX.IntegerValue() < 0.0) { aCorner |= Aspect_TOTP_LEFT; }
2664 if (aY.IntegerValue() > 0.0) { aCorner |= Aspect_TOTP_TOP; }
2665 else if (aY.IntegerValue() < 0.0) { aCorner |= Aspect_TOTP_BOTTOM; }
2666 aTrsfPers = new Graphic3d_TransformPers (aTrsfPers->Mode(), Aspect_TypeOfTriedronPosition (aCorner), Graphic3d_Vec2i (aZ.IntegerValue()));
2670 Message::SendFail() << "Syntax error: unknown argument '" << aParam << "'";
2675 aTextPrs->SetTextFormatter (aTextFormatter);
2679 aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2682 aTextPrs->SetDisplayType (aDisplayType);
2684 if (!aTrsfPers.IsNull())
2686 aContext->SetTransformPersistence (aTextPrs, aTrsfPers);
2687 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2688 if (aTextPrs->Position().Z() != 0)
2690 aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
2693 else if (!aTextPrs->TransformPersistence().IsNull())
2695 aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
2700 ViewerTest::Display (aName, aTextPrs, Standard_False);
2704 aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
2710 #include <gp_Pnt.hxx>
2711 #include <Graphic3d_ArrayOfPoints.hxx>
2712 #include <Graphic3d_ArrayOfPrimitives.hxx>
2713 #include <Graphic3d_ArrayOfTriangles.hxx>
2714 #include <Poly_Array1OfTriangle.hxx>
2715 #include <Poly_Triangle.hxx>
2716 #include <Poly_Triangulation.hxx>
2717 #include <TColgp_Array1OfPnt.hxx>
2718 #include <TShort_Array1OfShortReal.hxx>
2719 #include <TShort_HArray1OfShortReal.hxx>
2721 #include <AIS_Triangulation.hxx>
2722 #include <StdPrs_ToolTriangulatedShape.hxx>
2723 #include <Poly_Connect.hxx>
2724 #include <TColgp_Array1OfDir.hxx>
2725 #include <Graphic3d_GraphicDriver.hxx>
2727 #include <TColStd_Array1OfInteger.hxx>
2728 #include <TColStd_HArray1OfInteger.hxx>
2729 #include <Prs3d_ShadingAspect.hxx>
2730 #include <Graphic3d_MaterialAspect.hxx>
2731 #include <Graphic3d_AspectFillArea3d.hxx>
2733 #include <BRepPrimAPI_MakeCylinder.hxx>
2734 #include <TopoDS_Shape.hxx>
2735 #include <TopExp_Explorer.hxx>
2736 #include <TopAbs.hxx>
2737 #include <AIS_InteractiveObject.hxx>
2740 //===============================================================================================
2741 //function : CalculationOfSphere
2743 //purpose : Create a Sphere
2744 //===============================================================================================
2746 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2749 double mRadius = Radius;
2750 double mCenter[3] = {X,Y,Z};
2751 int mThetaResolution;
2753 double mStartTheta = 0;//StartTheta;
2754 double mEndTheta = 360;//EndTheta;
2755 double mStartPhi = 0;//StartPhi;
2756 double mEndPhi = 180;//EndPhi;
2757 res = res < 4 ? 4 : res;
2759 mThetaResolution = res;
2760 mPhiResolution = res;
2763 int jStart, jEnd, numOffset;
2764 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2765 double startTheta, endTheta, startPhi, endPhi;
2766 int base, numPoles=0, thetaResolution, phiResolution;
2771 if ( numPieces > mThetaResolution ) {
2772 numPieces = mThetaResolution;
2775 int localThetaResolution = mThetaResolution;
2776 double localStartTheta = mStartTheta;
2777 double localEndTheta = mEndTheta;
2779 while ( localEndTheta < localStartTheta ) {
2780 localEndTheta += 360.0;
2783 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2785 // Change the ivars based on pieces.
2787 start = piece * localThetaResolution / numPieces;
2788 end = (piece+1) * localThetaResolution / numPieces;
2789 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2790 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2791 localThetaResolution = end - start;
2793 // Create north pole if needed
2794 int number_point = 0;
2795 int number_pointArray = 0;
2797 if ( mStartPhi <= 0.0 ) {
2798 number_pointArray++;
2801 if ( mEndPhi >= 180.0 ) {
2802 number_pointArray++;
2806 // Check data, determine increments, and convert to radians
2807 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2808 startTheta *= M_PI / 180.0;
2809 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2810 endTheta *= M_PI / 180.0;
2813 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2814 startPhi *= M_PI / 180.0;
2815 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2816 endPhi *= M_PI / 180.0;
2818 phiResolution = mPhiResolution - numPoles;
2819 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2820 thetaResolution = localThetaResolution;
2821 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2822 ++localThetaResolution;
2824 deltaTheta = (endTheta - startTheta) / thetaResolution;
2826 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2827 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2829 // Create intermediate points
2830 for ( i = 0; i < localThetaResolution; i++ ) {
2831 for ( j = jStart; j < jEnd; j++ ) {
2832 number_pointArray++;
2836 //Generate mesh connectivity
2837 base = phiResolution * localThetaResolution;
2839 int number_triangle = 0 ;
2840 if ( mStartPhi <= 0.0 ) { // around north pole
2841 number_triangle += localThetaResolution;
2844 if ( mEndPhi >= 180.0 ) { // around south pole
2845 number_triangle += localThetaResolution;
2848 // bands in-between poles
2849 for ( i=0; i < localThetaResolution; i++){
2850 for ( j=0; j < (phiResolution-1); j++){
2851 number_triangle +=2;
2855 Handle(Poly_Triangulation) polyTriangulation = new Poly_Triangulation (number_pointArray, number_triangle, false, true);
2857 if ( mStartPhi <= 0.0 ){
2860 x[2] = mCenter[2] + mRadius;
2861 polyTriangulation->SetNode (1, gp_Pnt (x[0],x[1],x[2]));
2864 // Create south pole if needed
2865 if ( mEndPhi >= 180.0 ){
2868 x[2] = mCenter[2] - mRadius;
2869 polyTriangulation->SetNode (2, gp_Pnt (x[0],x[1],x[2]));
2873 for ( i=0; i < localThetaResolution; i++){
2874 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2875 for ( j = jStart; j < jEnd; j++){
2876 phi = startPhi + j*deltaPhi;
2877 radius = mRadius * sin((double)phi);
2878 n[0] = radius * cos((double)theta);
2879 n[1] = radius * sin((double)theta);
2880 n[2] = mRadius * cos((double)phi);
2881 x[0] = n[0] + mCenter[0];
2882 x[1] = n[1] + mCenter[1];
2883 x[2] = n[2] + mCenter[2];
2884 polyTriangulation->SetNode (number_point, gp_Pnt (x[0],x[1],x[2]));
2890 number_triangle = 1;
2891 if ( mStartPhi <= 0.0 ){// around north pole
2892 for (i=0; i < localThetaResolution; i++){
2893 pts[0] = phiResolution*i + numPoles;
2894 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2896 polyTriangulation->SetTriangle (number_triangle, Poly_Triangle (pts[0],pts[1],pts[2]));
2901 if ( mEndPhi >= 180.0 ){ // around south pole
2902 numOffset = phiResolution - 1 + numPoles;
2903 for (i=0; i < localThetaResolution; i++){
2904 pts[0] = phiResolution*i + numOffset;
2905 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2906 pts[1] = numPoles - 1;
2907 polyTriangulation->SetTriangle (number_triangle, Poly_Triangle (pts[0],pts[1],pts[2]));
2912 // bands in-between poles
2914 for (i=0; i < localThetaResolution; i++){
2915 for (j=0; j < (phiResolution-1); j++){
2916 pts[0] = phiResolution*i + j + numPoles;
2917 pts[1] = pts[0] + 1;
2918 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2919 polyTriangulation->SetTriangle (number_triangle, Poly_Triangle (pts[0],pts[1],pts[2]));
2922 pts[2] = pts[1] - 1;
2923 polyTriangulation->SetTriangle (number_triangle, Poly_Triangle (pts[0],pts[1],pts[2]));
2928 Poly_Connect pc (polyTriangulation);
2930 Standard_Integer index[3];
2931 Standard_Real Tol = Precision::Confusion();
2934 for (i = 1; i <= polyTriangulation->NbNodes(); i++)
2936 gp_XYZ eqPlan(0, 0, 0);
2937 for (pc.Initialize (i); pc.More(); pc.Next())
2939 polyTriangulation->Triangle (pc.Value()).Get (index[0], index[1], index[2]);
2940 gp_XYZ v1 (polyTriangulation->Node (index[1]).Coord() - polyTriangulation->Node (index[0]).Coord());
2941 gp_XYZ v2 (polyTriangulation->Node (index[2]).Coord() - polyTriangulation->Node (index[1]).Coord());
2943 Standard_Real mod = vv.Modulus();
2944 if(mod < Tol) continue;
2948 Standard_Real modmax = eqPlan.Modulus();
2950 Nor = gp_Dir(eqPlan);
2952 Nor = gp_Dir(0., 0., 1.);
2954 polyTriangulation->SetNormal (i, Nor.XYZ());
2957 return polyTriangulation;
2960 //===============================================================================================
2961 //function : VDrawSphere
2963 //purpose : Create an AIS shape.
2964 //===============================================================================================
2965 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2968 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2969 if (aContextAIS.IsNull())
2971 Message::SendFail ("Error: no active viewer");
2976 Message::SendFail() << "Syntax error: wrong number of arguments.\n"
2977 << "Use: " << argv[0] << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]";
2981 // read the arguments
2982 TCollection_AsciiString aShapeName (argv[1]);
2983 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2984 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2985 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2986 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2987 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2988 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2989 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
2991 // remove AIS object with given name from map
2992 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2995 std::cout << "Compute Triangulation...\n";
2996 Handle(AIS_Triangulation) aShape
2997 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
3000 const Standard_Integer aNumberPoints = aShape->GetTriangulation()->NbNodes();
3001 const Standard_Integer aNumberTriangles = aShape->GetTriangulation()->NbTriangles();
3003 // stupid initialization of Green color in RGBA space as integer
3004 // probably wrong for big-endian CPUs
3005 const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
3007 // setup colors array per vertex
3008 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
3009 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
3011 aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData()));
3013 aShape->SetColors (aColorArray);
3016 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3017 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3018 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
3019 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
3020 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
3021 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
3022 aTotalSize >>= 20; //MB
3023 aNormalsSize >>= 20;
3025 aTrianglesSize >>= 20;
3026 aPolyConnectSize >>= 20;
3029 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
3030 << "NumberOfTriangles: " << aNumberTriangles << "\n"
3031 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
3032 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
3033 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
3034 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
3037 // Setting material properties, very important for desirable visual result!
3038 Graphic3d_MaterialAspect aMat (Graphic3d_NameOfMaterial_Plastified);
3039 aMat.SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.04f)));
3040 aMat.SetSpecularColor(Quantity_Color (Graphic3d_Vec3 (0.50f)));
3041 Handle(Graphic3d_AspectFillArea3d) anAspect
3042 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3044 Quantity_NOC_YELLOW,
3049 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3050 anAspect->SetDrawEdges (toShowEdges);
3051 aShAsp->SetAspect (anAspect);
3052 aShape->Attributes()->SetShadingAspect (aShAsp);
3054 VDisplayAISObject (aShapeName, aShape);
3058 //=============================================================================
3059 //function : VComputeHLR
3061 //=============================================================================
3063 static int VComputeHLR (Draw_Interpretor& ,
3064 Standard_Integer theArgNb,
3065 const char** theArgVec)
3067 TCollection_AsciiString aShapeName, aHlrName;
3072 bool hasViewDirArg = false;
3073 Prs3d_TypeOfHLR anAlgoType = Prs3d_TOH_PolyAlgo;
3074 bool toShowCNEdges = false, toShowHiddenEdges = false;
3075 int aNbIsolines = 0;
3076 if (Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext())
3079 Handle(V3d_View) aView = ViewerTest::CurrentView();
3080 Standard_Integer aWidth, aHeight;
3081 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3082 Standard_Real aRightX, aRightY, aRightZ;
3083 aView->Window()->Size (aWidth, aHeight);
3085 aView->ConvertWithProj (aWidth, aHeight/2,
3086 aRightX, aRightY, aRightZ,
3087 aDirX, aDirY, aDirZ);
3088 aView->ConvertWithProj (aWidth/2, aHeight/2,
3089 aCentX, aCentY, aCentZ,
3090 aDirX, aDirY, aDirZ);
3092 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3093 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3094 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3095 aProjAx.SetLocation (anEye);
3096 aProjAx.SetDirection (aDir);
3097 aProjAx.SetXDirection (aRight);
3099 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3101 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3102 anArgCase.LowerCase();
3103 if (anArgIter + 1 < theArgNb
3104 && (anArgCase == "-algotype"
3105 || anArgCase == "-algo"
3106 || anArgCase == "-type"))
3108 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
3109 anArgNext.LowerCase();
3110 if (anArgNext == "polyalgo")
3112 anAlgoType = Prs3d_TOH_PolyAlgo;
3114 else if (anArgNext == "algo")
3116 anAlgoType = Prs3d_TOH_Algo;
3120 Message::SendFail() << "Syntax error: unknown algo type '" << anArgNext << "'";
3124 else if (anArgCase == "-showhiddenedges"
3125 || anArgCase == "-hiddenedges"
3126 || anArgCase == "-hidden")
3128 toShowHiddenEdges = true;
3129 if (anArgIter + 1 < theArgNb
3130 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toShowHiddenEdges))
3135 else if (anArgCase == "-showtangentedges"
3136 || anArgCase == "-tangentedges"
3137 || anArgCase == "-tangent")
3139 toShowCNEdges = true;
3140 if (anArgIter + 1 < theArgNb
3141 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toShowCNEdges))
3146 else if (anArgIter + 1 < theArgNb
3147 && (anArgCase == "-nbiso"
3148 || anArgCase == "-nbisolines"))
3150 aNbIsolines = Draw::Atoi (theArgVec[++anArgIter]);
3152 else if (aSh.IsNull())
3154 aSh = DBRep::Get (theArgVec[anArgIter]);
3155 aShapeName = theArgVec[anArgIter];
3158 BRep_Builder aBrepBuilder;
3159 BRepTools::Read (aSh, theArgVec[anArgIter], aBrepBuilder);
3162 Message::SendFail() << "Syntax error: no shape with name " << theArgVec[anArgIter] << " found";
3167 else if (aHlrName.IsEmpty())
3169 aHlrName = theArgVec[anArgIter];
3171 else if (!hasViewDirArg
3172 && anArgIter + 8 < theArgNb)
3174 hasViewDirArg = true;
3176 anEye.SetCoord (Draw::Atof (theArgVec[anArgIter + 0]), Draw::Atof (theArgVec[anArgIter + 1]), Draw::Atof (theArgVec[anArgIter + 2]));
3177 aDir .SetCoord (Draw::Atof (theArgVec[anArgIter + 3]), Draw::Atof (theArgVec[anArgIter + 4]), Draw::Atof (theArgVec[anArgIter + 5]));
3178 anUp .SetCoord (Draw::Atof (theArgVec[anArgIter + 6]), Draw::Atof (theArgVec[anArgIter + 7]), Draw::Atof (theArgVec[anArgIter + 8]));
3179 aProjAx.SetLocation (anEye);
3180 aProjAx.SetDirection (aDir);
3181 aProjAx.SetYDirection (anUp);
3186 Message::SendFail() << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'";
3191 if (aHlrName.IsEmpty() || aSh.IsNull()
3192 || (ViewerTest::GetAISContext().IsNull() && hasViewDirArg))
3194 Message::SendFail ("Syntax error: wrong number of arguments");
3198 HLRAlgo_Projector aProjector (aProjAx);
3199 TopoDS_Shape aVisible[6];
3200 TopoDS_Shape aHidden[6];
3201 if (anAlgoType == Prs3d_TOH_PolyAlgo)
3203 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3204 aPolyAlgo->Projector (aProjector);
3205 aPolyAlgo->Load (aSh);
3206 aPolyAlgo->Update();
3208 HLRBRep_PolyHLRToShape aHLRToShape;
3209 aHLRToShape.Update (aPolyAlgo);
3211 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3212 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); // extract visible outlines
3213 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3216 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3218 if (toShowHiddenEdges)
3220 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3221 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3222 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3225 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3231 Handle(HLRBRep_Algo) aHlrAlgo = new HLRBRep_Algo();
3232 aHlrAlgo->Add (aSh, aNbIsolines);
3233 aHlrAlgo->Projector (aProjector);
3237 HLRBRep_HLRToShape aHLRToShape (aHlrAlgo);
3238 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3239 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound();
3240 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3243 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3245 aVisible[HLRBRep_IsoLine] = aHLRToShape.IsoLineVCompound();
3247 if (toShowHiddenEdges)
3249 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3250 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3251 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3254 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3256 aHidden[HLRBRep_IsoLine] = aHLRToShape.IsoLineHCompound();
3259 //aVisible[HLRBRep_Sharp] = aHLRToShape.CompoundOfEdges (HLRBRep_Sharp, Standard_True, Standard_True);
3260 //aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound3d();
3263 TopoDS_Compound aCompRes, aCompVis, aCompHid;
3264 BRep_Builder aBuilder;
3265 aBuilder.MakeCompound (aCompVis);
3266 aBuilder.MakeCompound (aCompHid);
3267 aBuilder.MakeCompound (aCompRes);
3268 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3270 if (!aVisible[aTypeIter].IsNull())
3272 aBuilder.Add (aCompVis, aVisible[aTypeIter]);
3274 if (!aHidden[aTypeIter].IsNull())
3276 aBuilder.Add (aCompHid, aHidden[aTypeIter]);
3279 aBuilder.Add (aCompRes, aCompVis);
3280 aBuilder.Add (aCompRes, aCompHid);
3282 // create an AIS shape and display it
3283 if (!ViewerTest::GetAISContext().IsNull())
3285 Handle(AIS_ColoredShape) anObject = new AIS_ColoredShape (aCompRes);
3286 if (toShowHiddenEdges)
3288 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect (Quantity_Color (Quantity_NOC_RED), Aspect_TOL_DASH, 1.0f);
3289 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3291 if (!aHidden[aTypeIter].IsNull())
3293 Handle(AIS_ColoredDrawer) aDrawer = anObject->CustomAspects (aHidden[aTypeIter]);
3294 aDrawer->SetLineAspect (aLineAspect);
3295 aDrawer->SetWireAspect (aLineAspect);
3296 aDrawer->SetFreeBoundaryAspect (aLineAspect);
3297 aDrawer->SetUnFreeBoundaryAspect (aLineAspect);
3301 ViewerTest::Display (aHlrName, anObject, true);
3304 DBRep::Set (aHlrName.ToCString(), aCompRes);
3308 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3309 // manipulating and displaying such an array with AIS context
3311 class MyPArrayObject : public AIS_InteractiveObject
3316 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives)& thePArray) : myPArray (thePArray) {}
3318 MyPArrayObject (Graphic3d_TypeOfPrimitiveArray thePrimType,
3319 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3320 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect)
3322 Init (thePrimType, theDesc, theMarkerAspect, Standard_False);
3325 //! Initialize the array from specified description.
3326 Standard_Boolean Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3327 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3328 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3329 Standard_Boolean theToPatch);
3331 DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
3333 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
3335 //! Sets color to this interactive object
3336 //! @param theColor the color to be set
3337 virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
3341 virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
3342 const Handle(Prs3d_Presentation)& thePrs,
3343 const Standard_Integer theMode) Standard_OVERRIDE;
3345 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel,
3346 const Standard_Integer theMode) Standard_OVERRIDE;
3348 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3349 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3350 Standard_Integer &theArgIndex,
3351 Standard_Integer theArgCount,
3352 Standard_Integer theMaxArgs);
3354 //! Sets color for the shading aspect of the drawer used in this interactive object
3355 //! @param theColor the color to be set
3356 void setColorForShadingAspect(const Quantity_Color& theColor);
3358 //! Replaces shading aspect from myDrawer->Link() with the own shading aspect of myDrawer for this interactive object
3359 void replaceShadingAspect();
3363 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3364 Handle(Graphic3d_ArrayOfPrimitives) myPArray;
3368 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager)& ,
3369 const Handle(Prs3d_Presentation)& thePrs,
3370 const Standard_Integer theMode)
3372 if (myPArray.IsNull() || theMode != 0)
3377 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
3378 if (!myMarkerAspect.IsNull())
3380 aGroup->SetGroupPrimitivesAspect (myMarkerAspect);
3384 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
3386 aGroup->AddPrimitiveArray (myPArray);
3389 Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3390 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3391 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3392 Standard_Boolean theToPatch)
3394 myMarkerAspect = theMarkerAspect;
3400 // Parsing array description
3401 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3402 Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None;
3404 const Standard_Integer anArgsCount = theDesc->Length();
3405 TCollection_AsciiString aCommand;
3406 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3408 aCommand = theDesc->Value (anArgIndex);
3409 aCommand.LowerCase();
3411 if (CheckInputCommand ("-deinterleaved", theDesc, anArgIndex, 0, anArgsCount))
3413 anArrayFlags |= Graphic3d_ArrayFlags_AttribsDeinterleaved;
3415 else if (CheckInputCommand ("-mutable", theDesc, anArgIndex, 0, anArgsCount))
3417 anArrayFlags |= Graphic3d_ArrayFlags_AttribsMutable;
3418 anArrayFlags |= Graphic3d_ArrayFlags_IndexesMutable;
3421 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3423 // vertex has a normal or normal with color or texel
3424 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3426 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal;
3429 // vertex has a color
3430 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3432 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor;
3435 // vertex has a texel
3436 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3438 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel;
3444 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3447 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3449 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor;
3455 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3464 if (myPArray.IsNull())
3466 myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
3467 if (myPArray->HasVertexColors())
3469 myDrawer->SetupOwnShadingAspect();
3470 Graphic3d_MaterialAspect aMat (Graphic3d_NameOfMaterial_Plastified);
3471 aMat.SetSpecularColor (Quantity_NOC_BLACK);
3472 aMat.SetEmissiveColor (Quantity_NOC_BLACK);
3473 aMat.SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
3474 aMat.SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
3475 myDrawer->ShadingAspect()->SetMaterial (aMat);
3476 myDrawer->ShadingAspect()->SetColor (Quantity_NOC_WHITE);
3481 if (myPArray->Type() != thePrimType
3482 || aVertexNum > myPArray->VertexNumberAllocated()
3483 || aEdgeNum > myPArray->EdgeNumberAllocated()
3484 || aBoundNum > myPArray->BoundNumberAllocated()
3485 || !myPArray->Attributes()->IsMutable()
3486 || (!myPArray->Indices().IsNull() && !myPArray->Indices()->IsMutable()))
3488 Message::SendFail ("Syntax error: array cannot be patched");
3489 return Standard_False;
3492 myPArray->Attributes()->NbElements = aVertexNum;
3493 if (Handle(Graphic3d_AttribBuffer) anAttribs = Handle(Graphic3d_AttribBuffer)::DownCast (myPArray->Attributes()))
3495 anAttribs->Invalidate (0, aVertexNum - 1);
3497 if (!myPArray->Indices().IsNull())
3499 myPArray->Indices()->NbElements = aEdgeNum;
3501 if (!myPArray->Bounds().IsNull())
3503 myPArray->Bounds()->NbBounds = aBoundNum;
3507 Standard_Integer aVertIndex = 0;
3508 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3510 aCommand = theDesc->Value (anArgIndex);
3511 aCommand.LowerCase();
3512 if (!aCommand.IsAscii()
3513 || aCommand.IsEmpty())
3518 // skip beautifiers (syntax is not actually validated)
3519 if (aCommand == "-deinterleaved"
3520 || aCommand == "-mutable"
3521 || aCommand.Value (1) == '('
3522 || aCommand.Value (1) == ')'
3523 || aCommand.Value (1) == ',')
3528 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3530 const Graphic3d_Vec3 aVert ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3531 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3532 (float )theDesc->Value (anArgIndex - 1).RealValue());
3533 if ((anArrayFlags & Graphic3d_ArrayFlags_AttribsDeinterleaved) != 0
3534 || (anArrayFlags & Graphic3d_ArrayFlags_AttribsMutable) != 0)
3537 myPArray->SetVertice (aVertIndex, aVert.x(), aVert.y(), aVert.z());
3541 aVertIndex = myPArray->AddVertex (aVert);
3544 // vertex has a normal or normal with color or texel
3545 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3547 const Graphic3d_Vec3 aNorm ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3548 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3549 (float )theDesc->Value (anArgIndex - 1).RealValue());
3550 myPArray->SetVertexNormal (aVertIndex, aNorm.x(), aNorm.y(), aNorm.z());
3553 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3555 const Graphic3d_Vec3d aCol (theDesc->Value (anArgIndex - 3).RealValue(),
3556 theDesc->Value (anArgIndex - 2).RealValue(),
3557 theDesc->Value (anArgIndex - 1).RealValue());
3558 myPArray->SetVertexColor (aVertIndex, aCol.r(), aCol.g(), aCol.b());
3560 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3562 const Graphic3d_Vec2 aTex ((float )theDesc->Value (anArgIndex - 2).RealValue(),
3563 (float )theDesc->Value (anArgIndex - 1).RealValue());
3564 myPArray->SetVertexTexel (aVertIndex, aTex.x(), aTex.y());
3568 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3570 Standard_Integer aVertCount = theDesc->Value (anArgIndex - 1).IntegerValue();
3572 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3573 myPArray->AddBound (aVertCount,
3574 theDesc->Value (anArgIndex - 3).RealValue(),
3575 theDesc->Value (anArgIndex - 2).RealValue(),
3576 theDesc->Value (anArgIndex - 1).RealValue());
3579 myPArray->AddBound (aVertCount);
3582 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3584 const Standard_Integer anEdge = theDesc->Value (anArgIndex - 1).IntegerValue();
3585 myPArray->AddEdge (anEdge);
3590 Message::SendFail() << "Syntax error: unknown argument '" << theDesc->Value(anArgIndex) << "'";
3591 return Standard_False;
3594 return Standard_True;
3597 //=======================================================================
3598 // function : SetColor
3600 //=======================================================================
3601 void MyPArrayObject::SetColor (const Quantity_Color& theColor)
3603 AIS_InteractiveObject::SetColor (theColor);
3604 setColorForShadingAspect (theColor);
3607 myMarkerAspect->SetColor (theColor);
3609 SynchronizeAspects();
3612 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3613 const Standard_Integer theMode)
3616 || myPArray.IsNull())
3621 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
3622 if (Handle(Graphic3d_ArrayOfTriangles) aTris = Handle(Graphic3d_ArrayOfTriangles)::DownCast (myPArray))
3624 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3625 aSensitive->InitTriangulation (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3626 theSelection->Add (aSensitive);
3628 else if (Handle(Graphic3d_ArrayOfSegments) aSegs = Handle(Graphic3d_ArrayOfSegments)::DownCast (myPArray))
3630 if (aSegs->EdgeNumber() > 0)
3632 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->EdgeNumber(); aPntIter += 2)
3634 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aSegs->Edge (aPntIter)), aSegs->Vertice (aSegs->Edge (aPntIter + 1)));
3635 aSeg->SetSensitivityFactor (4);
3636 theSelection->Add (aSeg);
3641 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->VertexNumber(); aPntIter += 2)
3643 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aPntIter), aSegs->Vertice (aPntIter + 1));
3644 aSeg->SetSensitivityFactor (4);
3645 theSelection->Add (aSeg);
3651 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3652 aSensitive->SetSensitivityFactor (8);
3653 aSensitive->InitPoints (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3654 theSelection->Add (aSensitive);
3658 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3659 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3660 Standard_Integer &theArgIndex,
3661 Standard_Integer theArgCount,
3662 Standard_Integer theMaxArgs)
3664 // check if there is more elements than expected
3665 if (theArgIndex >= theMaxArgs)
3668 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3669 aStrCommand.LowerCase();
3670 if (aStrCommand.Search(theCommand) != 1 ||
3671 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3674 // go to the first data element
3677 // check data if it can be converted to numeric
3678 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3680 aStrCommand = theArgsArray->Value (theArgIndex);
3681 if (!aStrCommand.IsRealValue (Standard_True))
3688 //=======================================================================
3689 // function : setColorForShadingAspect
3691 //=======================================================================
3692 void MyPArrayObject::setColorForShadingAspect (const Quantity_Color& theColor)
3694 if (myDrawer->SetupOwnShadingAspect())
3696 replaceShadingAspect();
3698 myDrawer->ShadingAspect()->SetColor (theColor);
3701 //=======================================================================
3702 // function : replaceShadingAspect
3704 //=======================================================================
3705 void MyPArrayObject::replaceShadingAspect()
3707 if (!myDrawer->Link())
3711 Graphic3d_MapOfAspectsToAspects anAspectReplacementMap;
3712 anAspectReplacementMap.Bind (myDrawer->Link()->ShadingAspect()->Aspect(), myDrawer->ShadingAspect()->Aspect());
3713 replaceAspects (anAspectReplacementMap);
3716 //=============================================================================
3717 //function : VDrawPArray
3718 //purpose : Draws primitives array from list of vertexes, bounds, edges
3719 //=============================================================================
3721 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3723 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3724 if (aContextAIS.IsNull())
3726 Message::SendFail ("Error: no active Viewer");
3731 Message::SendFail ("Syntax error: wrong number of arguments");
3735 // read the arguments
3736 Standard_Integer anArgIndex = 1;
3737 TCollection_AsciiString aName (argv[anArgIndex++]);
3738 TCollection_AsciiString anArrayType (argv[anArgIndex++]);
3739 anArrayType.LowerCase();
3740 Handle(MyPArrayObject) aPObject;
3741 if (anArrayType == "-shape")
3743 Standard_CString aShapeName = argv[anArgIndex++];
3744 TopoDS_Shape aShape = DBRep::Get (aShapeName);
3745 Handle(Graphic3d_ArrayOfPrimitives) aTris = StdPrs_ShadedShape::FillTriangles (aShape);
3746 if (aShape.IsNull())
3748 Message::SendFail() << "Syntax error: shape '" << aShapeName << "' is not found";
3751 else if (aTris.IsNull())
3753 Message::SendFail() << "Syntax error: shape '" << aShapeName << "' is not triangulated";
3757 aPObject = new MyPArrayObject (aTris);
3758 ViewerTest::Display (aName, aPObject);
3761 else if (anArrayType == "-patch"
3762 || anArrayType == "-modify"
3763 || anArrayType == "-edit")
3767 anArrayType = argv[anArgIndex++];
3768 anArrayType.LowerCase();
3771 if (GetMapOfAIS().IsBound2 (aName))
3773 aPObject = Handle(MyPArrayObject)::DownCast (GetMapOfAIS().Find2 (aName));
3775 if (aPObject.IsNull())
3777 Message::SendFail() << "Syntax error: object '" << aName << "' cannot be found";
3782 Standard_Boolean hasVertex = Standard_False;
3784 Graphic3d_TypeOfPrimitiveArray aPrimType = Graphic3d_TOPA_UNDEFINED;
3785 if (anArrayType == "points")
3787 aPrimType = Graphic3d_TOPA_POINTS;
3789 else if (anArrayType == "segments")
3791 aPrimType = Graphic3d_TOPA_SEGMENTS;
3793 else if (anArrayType == "polylines")
3795 aPrimType = Graphic3d_TOPA_POLYLINES;
3797 else if (anArrayType == "triangles")
3799 aPrimType = Graphic3d_TOPA_TRIANGLES;
3801 else if (anArrayType == "trianglefans")
3803 aPrimType = Graphic3d_TOPA_TRIANGLEFANS;
3805 else if (anArrayType == "trianglestrips")
3807 aPrimType = Graphic3d_TOPA_TRIANGLESTRIPS;
3809 else if (anArrayType == "quads")
3811 aPrimType = Graphic3d_TOPA_QUADRANGLES;
3813 else if (anArrayType == "quadstrips")
3815 aPrimType = Graphic3d_TOPA_QUADRANGLESTRIPS;
3817 else if (anArrayType == "polygons")
3819 aPrimType = Graphic3d_TOPA_POLYGONS;
3821 if (aPrimType == Graphic3d_TOPA_UNDEFINED)
3823 Message::SendFail ("Syntax error: unexpected type of primitives array");
3827 Standard_Integer aLowerArg = anArgIndex;
3828 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 3);
3829 for (; anArgIndex < argc; ++anArgIndex)
3831 TCollection_AsciiString aCommand (argv[anArgIndex]);
3832 aCommand.LowerCase();
3833 if (!aCommand.IsAscii())
3835 di << "Unexpected argument: #" << anArgIndex - 1 << " , "
3836 << "should be an array element: 'v', 'b', 'e' \n";
3840 if (aCommand == "v")
3842 hasVertex = Standard_True;
3845 anArgsArray->SetValue (anArgIndex - aLowerArg, aCommand);
3850 di << "You should pass any verticies in the list of array elements\n";
3854 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3855 if (aPrimType == Graphic3d_TOPA_POINTS)
3857 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3860 // create primitives array object
3861 if (aPObject.IsNull())
3863 // register the object in map
3864 aPObject = new MyPArrayObject (aPrimType, anArgsArray, anAspPoints);
3865 VDisplayAISObject (aName, aPObject);
3869 aPObject->Init (aPrimType, anArgsArray, anAspPoints, Standard_True);
3870 ViewerTest::CurrentView()->Redraw();
3877 //! Auxiliary function for parsing translation vector - either 2D or 3D.
3878 static Standard_Integer parseTranslationVec (Standard_Integer theArgNb,
3879 const char** theArgVec,
3887 TCollection_AsciiString anX (theArgVec[0]);
3888 TCollection_AsciiString anY (theArgVec[1]);
3889 if (!anX.IsRealValue (Standard_True)
3890 || !anY.IsRealValue (Standard_True))
3895 theVec.SetX (anX.RealValue());
3896 theVec.SetY (anY.RealValue());
3899 TCollection_AsciiString anZ (theArgVec[2]);
3900 if (anZ.IsRealValue (Standard_True))
3902 theVec.SetZ (anZ.RealValue());
3910 //=======================================================================
3911 //function : VSetLocation
3912 //purpose : Change location of AIS interactive object
3913 //=======================================================================
3915 static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
3916 Standard_Integer theArgNb,
3917 const char** theArgVec)
3919 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3920 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3921 if (aContext.IsNull())
3923 Message::SendFail ("Error: no active viewer");
3927 Standard_Boolean toPrintInfo = Standard_True;
3928 Handle(AIS_InteractiveObject) anObj;
3929 TCollection_AsciiString aCmdName (theArgVec[0]);
3930 aCmdName.LowerCase();
3931 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3933 TCollection_AsciiString anArg = theArgVec[anArgIter];
3935 if (anUpdateTool.parseRedrawMode (anArg))
3939 else if (anObj.IsNull())
3941 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3942 GetMapOfAIS().Find2 (aName, anObj);
3945 Message::SendFail() << "Error: object '" << aName << "' is not displayed";
3949 else if (anArg == "-reset")
3951 toPrintInfo = Standard_False;
3952 aContext->SetLocation (anObj, gp_Trsf());
3954 else if (anArg == "-copyfrom"
3955 || anArg == "-copy")
3957 if (anArgIter + 1 >= theArgNb)
3959 Message::SendFail() << "Syntax error at '" << anArg << "'";
3963 const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]);
3964 Handle(AIS_InteractiveObject) anObj2;
3965 GetMapOfAIS().Find2 (aName2, anObj2);
3966 if (anObj2.IsNull())
3968 Message::SendFail() << "Error: object '" << aName2 << "' is not displayed";
3973 aContext->SetLocation (anObj, anObj2->LocalTransformation());
3975 else if (anArg == "-rotate"
3976 || anArg == "-prerotate")
3978 toPrintInfo = Standard_False;
3979 if (anArgIter + 7 >= theArgNb)
3981 Message::SendFail() << "Syntax error at '" << anArg << "'";
3986 aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]),
3987 Draw::Atof (theArgVec[anArgIter + 2]),
3988 Draw::Atof (theArgVec[anArgIter + 3])),
3989 gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]),
3990 Draw::Atof (theArgVec[anArgIter + 5]),
3991 Draw::Atof (theArgVec[anArgIter + 6]))),
3992 Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0));
3995 if (anArg == "-prerotate")
3997 aTrsf = anObj->LocalTransformation() * aTrsf;
4001 aTrsf = aTrsf * anObj->LocalTransformation();
4003 aContext->SetLocation (anObj, aTrsf);
4005 else if (anArg == "-translate"
4006 || anArg == "-pretranslate")
4008 toPrintInfo = Standard_False;
4010 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
4011 anArgIter += aNbParsed;
4014 Message::SendFail() << "Syntax error at '" << anArg << "'";
4019 aTrsf.SetTranslationPart (aLocVec);
4020 if (anArg == "-pretranslate")
4022 aTrsf = anObj->LocalTransformation() * aTrsf;
4026 aTrsf = aTrsf * anObj->LocalTransformation();
4028 aContext->SetLocation (anObj, aTrsf);
4030 else if (anArg == "-scale"
4031 || anArg == "-prescale"
4032 || anArg == "-setscale")
4034 toPrintInfo = Standard_False;
4036 Standard_Real aScale = 1.0;
4037 Standard_Boolean toPrintScale = Standard_True;
4038 Standard_Boolean hasScaleLoc = Standard_False;
4039 if (anArgIter + 4 < theArgNb)
4041 TCollection_AsciiString aScaleArgs[4] =
4043 TCollection_AsciiString (theArgVec[anArgIter + 1]),
4044 TCollection_AsciiString (theArgVec[anArgIter + 2]),
4045 TCollection_AsciiString (theArgVec[anArgIter + 3]),
4046 TCollection_AsciiString (theArgVec[anArgIter + 4])
4048 Standard_Integer aScaleArgIter = 0;
4049 for (; aScaleArgIter < 4; ++aScaleArgIter)
4051 if (!aScaleArgs[aScaleArgIter].IsRealValue (Standard_True))
4056 if (aScaleArgIter == 4)
4058 aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue());
4059 aScale = aScaleArgs[3].RealValue();
4061 toPrintScale = Standard_False;
4062 hasScaleLoc = Standard_True;
4064 else if (aScaleArgIter >= 1)
4066 aScale = aScaleArgs[0].RealValue();
4068 toPrintScale = Standard_False;
4071 else if (anArgIter + 1 < theArgNb)
4073 TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]);
4074 if (aScaleArg.IsRealValue (Standard_True))
4076 aScale = aScaleArg.RealValue();
4078 toPrintScale = Standard_False;
4084 if (anArg == "-setscale"
4085 || anArg == "-prescale")
4087 Message::SendFail() << "Syntax error at '" << anArg << "'";
4092 Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor());
4097 if (anArg == "-setscale")
4099 gp_Trsf aTrsf = anObj->LocalTransformation();
4102 aTrsf.SetScale (aScaleLoc, aScale);
4106 aTrsf.SetScaleFactor (aScale);
4108 aContext->SetLocation (anObj, aTrsf);
4115 aTrsf.SetScale (aScaleLoc, aScale);
4119 aTrsf.SetScaleFactor (aScale);
4122 if (anArg == "-prescale")
4124 aTrsf = anObj->LocalTransformation() * aTrsf;
4128 aTrsf = aTrsf * anObj->LocalTransformation();
4130 aContext->SetLocation (anObj, aTrsf);
4133 else if (anArg == "-mirror"
4134 || anArg == "-premirror")
4136 toPrintInfo = Standard_False;
4137 if (anArgIter + 6 >= theArgNb)
4139 Message::SendFail() << "Syntax error at '" << anArg << "'";
4144 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
4145 Draw::Atof(theArgVec[theArgNb - 5]),
4146 Draw::Atof(theArgVec[theArgNb - 4])),
4147 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
4148 Draw::Atof(theArgVec[theArgNb - 2]),
4149 Draw::Atof(theArgVec[theArgNb - 1]))));
4151 if (anArg == "-premirror")
4153 aTrsf = anObj->LocalTransformation() * aTrsf;
4157 aTrsf = aTrsf * anObj->LocalTransformation();
4159 aContext->SetLocation (anObj, aTrsf);
4161 else if (anArg == "-setrotation"
4162 || anArg == "-rotation")
4164 toPrintInfo = Standard_False;
4165 if (anArgIter + 4 < theArgNb)
4167 TCollection_AsciiString aQuatArgs[4] =
4169 TCollection_AsciiString (theArgVec[anArgIter + 1]),
4170 TCollection_AsciiString (theArgVec[anArgIter + 2]),
4171 TCollection_AsciiString (theArgVec[anArgIter + 3]),
4172 TCollection_AsciiString (theArgVec[anArgIter + 4])
4174 Standard_Integer aQuatArgIter = 0;
4175 for (; aQuatArgIter < 4; ++aQuatArgIter)
4177 if (!aQuatArgs[aQuatArgIter].IsRealValue (Standard_True))
4183 if (aQuatArgIter == 4)
4186 const gp_Quaternion aQuat (aQuatArgs[0].RealValue(),
4187 aQuatArgs[1].RealValue(),
4188 aQuatArgs[2].RealValue(),
4189 aQuatArgs[3].RealValue());
4190 gp_Trsf aTrsf = anObj->LocalTransformation();
4191 aTrsf.SetRotationPart (aQuat);
4192 aContext->SetLocation (anObj, aTrsf);
4195 else if (anArg == "-setrotation")
4197 Message::SendFail() << "Syntax error at '" << anArg << "'";
4203 const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation();
4204 Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W());
4207 else if (anArg == "-setlocation"
4208 || anArg == "-location")
4210 toPrintInfo = Standard_False;
4212 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
4213 anArgIter += aNbParsed;
4216 gp_Trsf aTrsf = anObj->LocalTransformation();
4217 aTrsf.SetTranslationPart (aLocVec);
4218 aContext->SetLocation (anObj, aTrsf);
4220 else if (anArg == "-setlocation")
4222 Message::SendFail() << "Syntax error at '" << anArg << "'";
4227 const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart();
4228 Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z());
4231 else if (aCmdName == "vsetlocation")
4233 // compatibility with old syntax
4235 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec);
4238 Message::SendFail() << "Syntax error at '" << anArg << "'";
4241 anArgIter = anArgIter + aNbParsed - 1;
4244 aTrsf.SetTranslationPart (aLocVec);
4245 aContext->SetLocation (anObj, aTrsf);
4246 toPrintInfo = Standard_False;
4250 Message::SendFail() << "Error: unknown argument '" << anArg << "'";
4257 Message::SendFail ("Syntax error - wrong number of arguments");
4260 else if (!toPrintInfo)
4265 const gp_Trsf aTrsf = anObj->LocalTransformation();
4266 const gp_XYZ aLoc = aTrsf.TranslationPart();
4267 const gp_Quaternion aRot = aTrsf.GetRotation();
4269 Sprintf (aText, "Location: %g %g %g\n"
4270 "Rotation: %g %g %g %g\n"
4272 aLoc.X(), aLoc.Y(), aLoc.Z(),
4273 aRot.X(), aRot.Y(), aRot.Z(), aRot.W(),
4274 aTrsf.ScaleFactor());
4279 //! Find displayed object.
4280 static Handle(AIS_InteractiveObject) findConnectedObject (const TCollection_AsciiString& theName)
4282 Handle(AIS_InteractiveObject) aPrs;
4283 if (!GetMapOfAIS().Find2 (theName, aPrs))
4285 return Handle(AIS_InteractiveObject)();
4287 if (Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (aPrs))
4291 else if (Handle(AIS_MultipleConnectedInteractive) aMultiCon = Handle(AIS_MultipleConnectedInteractive)::DownCast (aPrs))
4296 // replace already displayed object with connected one
4297 TheAISContext()->Remove (aPrs, false);
4298 Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive();
4299 if (aPrs->HasDisplayMode())
4301 aConnected->SetDisplayMode (aPrs->DisplayMode());
4303 aConnected->Connect (aPrs, aPrs->LocalTransformationGeom());
4304 if (!aPrs->TransformPersistence().IsNull())
4306 aConnected->SetTransformPersistence (aPrs->TransformPersistence());
4308 ViewerTest::Display (theName, aConnected, false);
4312 //===============================================================================================
4313 //function : VConnect
4314 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4315 //===============================================================================================
4316 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
4317 Standard_Integer argc,
4320 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4321 if (aContext.IsNull())
4323 Message::SendFail ("Error: no active viewer");
4328 Message::SendFail ("Syntax error: expect at least 5 arguments");
4333 Standard_Integer anArgIter = 1;
4334 const TCollection_AsciiString aName (argv[anArgIter++]);
4335 Handle(AIS_MultipleConnectedInteractive) aMultiConObject;
4336 TCollection_AsciiString aColorString (argv[argc-1]);
4337 Quantity_Color aColor;
4338 Standard_Boolean hasColor = Standard_False;
4339 if (aColorString.Search ("color=") != -1)
4341 hasColor = Standard_True;
4342 aColorString.Remove (1, 6);
4343 if (!Quantity_Color::ColorFromName (aColorString.ToCString(), aColor))
4345 Message::SendFail() << "Syntax error at " << aColorString;
4350 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
4351 for (Standard_Integer i = 5; i < aNbShapes; ++i)
4353 TCollection_AsciiString anOriginObjectName (argv[i]);
4354 Handle(AIS_InteractiveObject) anObject;
4355 if (aName.IsEqual (anOriginObjectName))
4357 Message::SendFail ("Syntax error: equal names for connected objects");
4361 anObject = findConnectedObject (anOriginObjectName);
4362 if (anObject.IsNull())
4364 TopoDS_Shape aTDShape = DBRep::Get (anOriginObjectName);
4365 if (aTDShape.IsNull())
4367 Message::SendFail() << "Syntax error: object " << anOriginObjectName << " doesn't exist";
4370 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aTDShape);
4371 Handle(AIS_ConnectedInteractive) aConnectedOrig = new AIS_ConnectedInteractive();
4372 aConnectedOrig->Connect (aShapePrs);
4373 anObject = aConnectedOrig;
4375 aContext->Load (anObject);
4376 anObject->SetColor (aColor);
4379 if (aMultiConObject.IsNull())
4381 aMultiConObject = new AIS_MultipleConnectedInteractive();
4384 aMultiConObject->Connect (anObject);
4386 if (aMultiConObject.IsNull())
4388 Message::SendFail ("Syntax error: can't connect input objects");
4392 // Create transformation
4394 aTrsf.SetTranslationPart (gp_Vec (Draw::Atof (argv[anArgIter + 0]),
4395 Draw::Atof (argv[anArgIter + 1]),
4396 Draw::Atof (argv[anArgIter + 2])));
4397 TopLoc_Location aLocation (aTrsf);
4400 aMultiConObject->SetLocalTransformation (aTrsf);
4402 ViewerTest::Display (aName, aMultiConObject, true);
4406 //===============================================================================================
4407 //function : VConnectTo
4408 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4409 //===============================================================================================
4410 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
4411 Standard_Integer argc,
4414 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4415 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4416 if (aContext.IsNull())
4418 Message::SendFail ("Error: no active viewer");
4421 if (argc != 6 && argc != 7)
4423 Message::SendFail ("Syntax error: expect at least 5 arguments");
4427 Standard_Integer anArgIter = 1;
4428 TCollection_AsciiString aName (argv[anArgIter++]);
4429 Handle(AIS_InteractiveObject) anOriginObject;
4431 TCollection_AsciiString anOriginObjectName(argv[5]);
4432 if (aName.IsEqual (anOriginObjectName))
4434 Message::SendFail ("Syntax error: equal names for connected objects");
4437 anOriginObject = findConnectedObject (anOriginObjectName);
4438 if (anOriginObject.IsNull())
4440 TopoDS_Shape aTDShape = DBRep::Get (anOriginObjectName);
4441 if (aTDShape.IsNull())
4443 Message::SendFail() << "Syntax error: object " << anOriginObjectName << " doesn't exist";
4447 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aTDShape);
4448 Handle(AIS_ConnectedInteractive) aConnectedOrig = new AIS_ConnectedInteractive();
4449 aConnectedOrig->Connect (aShapePrs);
4451 anOriginObject = aConnectedOrig;
4452 GetMapOfAIS().Bind (aConnectedOrig, anOriginObjectName);
4455 // Create transformation
4457 aTrsf.SetTranslationPart (gp_Vec (Draw::Atof (argv[anArgIter + 0]),
4458 Draw::Atof (argv[anArgIter + 1]),
4459 Draw::Atof (argv[anArgIter + 2])));
4462 Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive();
4463 aConnected->Connect (anOriginObject, aTrsf);
4466 TCollection_AsciiString anArg = argv[6];
4468 if (anArg == "-nodisplay")
4470 // bind connected object without displaying it
4471 Handle(AIS_InteractiveObject) anObj;
4472 if (GetMapOfAIS().Find2 (aName, anObj))
4474 TheAISContext()->Remove (anObj, false);
4475 GetMapOfAIS().UnBind2 (aName);
4477 GetMapOfAIS().Bind (aConnected, aName);
4481 if (!anUpdateTool.parseRedrawMode (anArg))
4483 Message::SendFail() << "Syntax error: unknown argument '" << anArg << "'";
4488 ViewerTest::Display (aName, aConnected, false);
4492 //=======================================================================
4493 //function : VDisconnect
4495 //=======================================================================
4496 static Standard_Integer VDisconnect (Draw_Interpretor& di,
4497 Standard_Integer argc,
4500 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4501 if (aContext.IsNull())
4503 Message::SendFail( "Error: no active viewer");
4509 Message::SendFail() << "Syntax error: wrong number of arguments.\nUsage: " << argv[0] << " name object";
4513 TCollection_AsciiString aName (argv[1]);
4514 TCollection_AsciiString anObject (argv[2]);
4515 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
4518 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4519 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4520 if (!aMap.IsBound2 (aName) )
4522 Message::SendFail ("Error: no active viewer");
4526 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4527 if (anAssembly.IsNull())
4529 di << "Not an assembly\n";
4533 Handle(AIS_InteractiveObject) anIObj;
4534 if (!aMap.Find2 (anObject, anIObj))
4536 // try to interpret second argument as child number
4537 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
4539 Standard_Integer aCounter = 1;
4540 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4542 if (aCounter == anObjectNumber)
4544 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4552 Message::SendFail ("Error: no active viewer");
4557 aContext->Disconnect (anAssembly, anIObj);
4558 aContext->UpdateCurrentViewer();
4562 //=======================================================================
4563 //function : VAddConnected
4565 //=======================================================================
4566 static Standard_Integer VAddConnected (Draw_Interpretor& ,
4567 Standard_Integer argc,
4570 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4571 if (aContext.IsNull())
4573 Message::SendFail ("Error: no active viewer");
4579 Message::SendFail ("Syntax error: expect 5 arguments");
4583 const TCollection_AsciiString aName (argv[1]);
4584 const Standard_Real aX = Draw::Atof (argv[2]);
4585 const Standard_Real aY = Draw::Atof (argv[3]);
4586 const Standard_Real aZ = Draw::Atof (argv[4]);
4587 const TCollection_AsciiString anObjectName (argv[5]);
4590 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4591 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4593 Handle(AIS_InteractiveObject) aPrs;
4594 aMap.Find2 (aName, aPrs);
4595 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aPrs);
4596 if (anAssembly.IsNull())
4598 Message::SendFail() << "Syntax error: '" << aName << "' is not an assembly";
4603 Handle(AIS_InteractiveObject) anIObj = findConnectedObject (anObjectName);
4604 if (anIObj.IsNull())
4606 Message::SendFail() << "Syntax error: '" << anObjectName << "' is not displayed";
4611 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4613 anAssembly->Connect (anIObj, aTrsf);
4614 TheAISContext()->Display (anAssembly, Standard_False);
4615 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4616 aContext->UpdateCurrentViewer();
4620 //=======================================================================
4621 //function : VListConnected
4623 //=======================================================================
4624 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4625 Standard_Integer argc,
4628 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4629 if (aContext.IsNull())
4631 Message::SendFail ("Error: no active viewer");
4637 Message::SendFail() << "Syntax error: wrong number of arguments.\nUsage: " << argv[0] << " name";
4641 TCollection_AsciiString aName (argv[1]);
4644 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4645 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4646 if (!aMap.IsBound2 (aName) )
4648 Message::SendFail ("Error: no active viewer");
4652 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4653 if (anAssembly.IsNull())
4655 Message::SendFail ("Syntax error: Not an assembly");
4659 std::cout << "Children of " << aName << ":\n";
4661 Standard_Integer aCounter = 1;
4662 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4664 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4665 if (GetMapOfAIS().IsBound1 (anObj))
4667 TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anObj);
4668 std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4671 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4673 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4674 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4676 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4678 std::cout << std::endl;
4686 //=======================================================================
4689 //=======================================================================
4690 static Standard_Integer VChild (Draw_Interpretor& ,
4691 Standard_Integer theNbArgs,
4692 const char** theArgVec)
4694 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4695 if (aContext.IsNull())
4697 Message::SendFail ("Error: no active viewer");
4702 Handle(AIS_InteractiveObject) aParent;
4703 bool hasActions = false;
4704 int toInheritTrsf = -1;
4705 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4706 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4708 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4710 if (anUpdateTool.parseRedrawMode (anArg))
4714 else if (anArg == "-add")
4719 else if (anArg == "-remove")
4724 else if (anArg == "-inheritparenttrsf"
4725 || anArg == "-inheritparentloc"
4726 || anArg == "-inheritparentlocation"
4727 || anArg == "-inheritparent"
4728 || anArg == "-noinheritparenttrsf"
4729 || anArg == "-noinheritparentloc"
4730 || anArg == "-noinheritparentlocation"
4731 || anArg == "-noinheritparent"
4732 || anArg == "-ignoreparenttrsf"
4733 || anArg == "-ignoreparentloc"
4734 || anArg == "-ignoreparentlocation"
4735 || anArg == "-ignoreparent")
4738 if (anArgIter + 1 < theNbArgs
4739 && Draw::ParseOnOff(theArgVec[anArgIter + 1], aVal))
4743 if (anArg.StartsWith("-no")
4744 || anArg.StartsWith("-ignore"))
4748 toInheritTrsf = aVal ? 1 : 0;
4752 Handle(AIS_InteractiveObject) aChild;
4753 if (!GetMapOfAIS().Find2 (theArgVec[anArgIter], aChild))
4755 Message::SendFail() << "Syntax error: object '" << theArgVec[anArgIter] << "' is not found";
4759 if (aParent.IsNull())
4763 else if (toAdd == -1)
4765 Message::SendFail ("Syntax error: no action specified");
4773 if(toInheritTrsf == 0)
4774 aParent->AddChildWithCurrentTransformation(aChild);
4776 aParent->AddChild (aChild);
4780 if (toInheritTrsf == 0)
4781 aParent->RemoveChildWithRestoreTransformation(aChild);
4783 aParent->RemoveChild (aChild);
4789 Message::SendFail ("Syntax error: not enough arguments");
4795 //=======================================================================
4796 //function : VParent
4798 //=======================================================================
4799 static Standard_Integer VParent(Draw_Interpretor&,
4800 Standard_Integer theNbArgs,
4801 const char** theArgVec)
4803 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4804 if (aContext.IsNull())
4806 Message::SendFail ("Error: no active viewer");
4812 Message::SendFail ("Syntax error: wrong number of arguments");
4816 TCollection_AsciiString aName(theArgVec[1]);
4817 Handle(AIS_InteractiveObject) aParent;
4818 if (!GetMapOfAIS().Find2(theArgVec[1], aParent))
4820 Message::SendFail() << "Syntax error: object '" << theArgVec[1] << "' is not found";
4824 ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
4825 for (Standard_Integer anArgIter = 2; anArgIter < theNbArgs; ++anArgIter)
4827 TCollection_AsciiString anArg(theArgVec[anArgIter]);
4829 if (anArg == "-ignorevisu")
4830 aParent->SetPropagateVisualState(Standard_False);
4835 //===============================================================================================
4836 //function : VSetSelectionMode
4837 //purpose : vselmode
4838 //===============================================================================================
4839 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4840 Standard_Integer theNbArgs,
4841 const char** theArgv)
4844 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4845 if (anAISContext.IsNull())
4847 Message::SendFail ("Error: no active Viewer");
4851 NCollection_Sequence<TCollection_AsciiString> anObjNames;
4852 Standard_Integer aSelectionMode = -1;
4853 Standard_Boolean toTurnOn = Standard_True;
4854 AIS_SelectionModesConcurrency aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4855 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4857 TCollection_AsciiString anArgCase (theArgv[anArgIter]);
4858 anArgCase.LowerCase();
4859 if (anArgCase == "-set"
4860 || anArgCase == "-replace"
4861 || anArgCase == "-single"
4862 || anArgCase == "-exclusive")
4864 aSelModeConcurrency = AIS_SelectionModesConcurrency_Single;
4866 else if (anArgCase == "-add"
4867 || anArgCase == "-combine"
4868 || anArgCase == "-combination"
4869 || anArgCase == "-multiple")
4871 aSelModeConcurrency = AIS_SelectionModesConcurrency_Multiple;
4873 else if (anArgCase == "-globalorlocal"
4874 || anArgCase == "-localorglobal")
4876 aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4880 anObjNames.Append (theArgv[anArgIter]);
4883 if (anObjNames.Size() < 2
4884 || !Draw::ParseOnOff (anObjNames.Last().ToCString(), toTurnOn))
4886 Message::SendFail ("Syntax error: wrong number of arguments");
4889 anObjNames.Remove (anObjNames.Upper());
4891 const TCollection_AsciiString aSelModeString = anObjNames.Last();
4892 anObjNames.Remove (anObjNames.Upper());
4893 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4894 if (aSelModeString.IsIntegerValue())
4896 aSelectionMode = aSelModeString.IntegerValue();
4898 else if (TopAbs::ShapeTypeFromString (aSelModeString.ToCString(), aShapeType))
4900 aSelectionMode = AIS_Shape::SelectionMode (aShapeType);
4904 Message::SendFail() << "Syntax error: unknown selection mode '" << aSelModeString << "'";
4909 AIS_ListOfInteractive aTargetIOs;
4910 for (NCollection_Sequence<TCollection_AsciiString>::Iterator anObjIter (anObjNames); anObjIter.More(); anObjIter.Next())
4912 const TCollection_AsciiString& aNameIO = anObjIter.Value();
4913 Handle(AIS_InteractiveObject) anIO;
4914 GetMapOfAIS().Find2 (aNameIO, anIO);
4917 Message::SendFail() << "Syntax error: undefined presentable object " << aNameIO;
4920 aTargetIOs.Append (anIO);
4922 if (aTargetIOs.IsEmpty())
4924 anAISContext->DisplayedObjects (aTargetIOs);
4927 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4929 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4930 anAISContext->SetSelectionModeActive (anIO, aSelectionMode, toTurnOn, aSelModeConcurrency);
4935 //===============================================================================================
4936 //function : VSelectionNext
4938 //===============================================================================================
4939 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4940 Standard_Integer /*theArgsNb*/,
4941 const char** /*theArgVec*/)
4944 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4945 Handle(V3d_View) aView = ViewerTest::CurrentView();
4947 if (anAISContext.IsNull())
4949 Message::SendFail ("Error: no active viewer");
4953 anAISContext->HilightNextDetected (aView);
4957 //===============================================================================================
4958 //function : VSelectionPrevious
4960 //===============================================================================================
4961 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4962 Standard_Integer /*theArgsNb*/,
4963 const char** /*theArgVec*/)
4966 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4967 Handle(V3d_View) aView = ViewerTest::CurrentView();
4969 if (anAISContext.IsNull())
4971 Message::SendFail ("Error: no active viewer");
4975 anAISContext->HilightPreviousDetected (aView);
4979 //===========================================================================
4980 //function : VTriangle
4981 //Draw arg : vtriangle Name PointName PointName PointName
4982 //purpose : creates and displays Triangle
4983 //===========================================================================
4984 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4985 Standard_Integer argc,
4988 const Standard_Boolean isTri = TCollection_AsciiString (argv[0]) == "vtriangle";
4989 Handle(Graphic3d_ArrayOfPrimitives) aPrims;
4992 aPrims = new Graphic3d_ArrayOfTriangles (3);
4996 aPrims = new Graphic3d_ArrayOfSegments (2);
4999 if (argc != (2 + aPrims->VertexNumberAllocated()))
5001 Message::SendFail ("Syntax error: wrong number of arguments");
5006 for (Standard_Integer aPntIter = 0; aPntIter < aPrims->VertexNumberAllocated(); ++aPntIter)
5008 const TCollection_AsciiString aName (argv[2 + aPntIter]);
5009 if (Handle(AIS_Point) aPntPrs = Handle(AIS_Point)::DownCast (GetMapOfAIS().IsBound2 (aName) ? GetMapOfAIS().Find2 (aName) : NULL))
5011 aPnts[aPntIter] = aPntPrs->Component()->Pnt();
5015 TopoDS_Shape aShape = DBRep::Get (argv[2 + aPntIter]);
5017 || aShape.ShapeType() != TopAbs_VERTEX)
5019 Message::SendFail() << "Syntax error: argument " << aName << " must be a point";
5022 aPnts[aPntIter] = BRep_Tool::Pnt (TopoDS::Vertex (aShape));
5025 for (Standard_Integer aPnt2Iter = 0; aPnt2Iter < aPntIter; ++aPnt2Iter)
5027 if (aPnts[aPnt2Iter].IsEqual (aPnts[aPntIter], Precision::Confusion()))
5029 Message::SendFail ("Syntax error: points should not be equal");
5034 aPrims->AddVertex (aPnts[aPntIter]);
5037 Handle(AIS_InteractiveObject) aPrs = new MyPArrayObject (aPrims);
5040 aPrs->Attributes()->SetupOwnShadingAspect();
5041 aPrs->Attributes()->ShadingAspect()->Aspect()->SetColor (Quantity_NOC_YELLOW);
5043 ViewerTest::Display (argv[1], aPrs);
5047 //===========================================================================
5049 //purpose : creates and displays a torus or torus segment
5050 //===========================================================================
5051 static Standard_Integer VTorus (Draw_Interpretor& /*di*/,
5052 Standard_Integer theNbArgs,
5053 const char** theArgVec)
5055 if (ViewerTest::GetAISContext().IsNull())
5057 Message::SendFail ("Error: no active viewer");
5061 TCollection_AsciiString aName;
5062 Standard_Integer aNbSlices = 100, aNbStacks = 100;
5063 Standard_Real aMajorRad = -1.0, aMinorRad = -1.0;
5064 Standard_Real aPipeAngle = 360.0, aSegAngle1 = 0.0, aSegAngle2 = 360.0;
5065 Standard_Real anAngles[3] = { -1.0, -1.0, -1.0 };
5066 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
5067 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
5069 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5071 if (anUpdateTool.parseRedrawMode (anArg))
5075 else if (anArgIter + 1 < theNbArgs
5076 && (anArg == "-nbslices"
5077 || anArg == "-slices")
5078 && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbSlices))
5082 else if (anArgIter + 1 < theNbArgs
5083 && (anArg == "-nbstacks"
5084 || anArg == "-stacks")
5085 && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbStacks))
5089 else if (anArgIter + 1 < theNbArgs
5090 && (anArg == "-radius"
5091 || anArg == "-majorradius")
5092 && Draw::ParseReal (theArgVec[anArgIter + 1], aMajorRad))
5096 else if (anArgIter + 1 < theNbArgs
5097 && (anArg == "-piperadius"
5098 || anArg == "-minoradius")
5099 && Draw::ParseReal (theArgVec[anArgIter + 1], aMinorRad))
5103 else if (anArgIter + 1 < theNbArgs
5104 && (anArg == "-pipeangle"
5105 || anArg == "-angle")
5106 && Draw::ParseReal (theArgVec[anArgIter + 1], aPipeAngle))
5110 else if (anArgIter + 1 < theNbArgs
5111 && (anArg == "-segmentanglefrom"
5112 || anArg == "-seganglefrom"
5113 || anArg == "-segmentangle1"
5114 || anArg == "-segangle1")
5115 && Draw::ParseReal (theArgVec[anArgIter + 1], aSegAngle1))
5119 else if (anArgIter + 1 < theNbArgs
5120 && (anArg == "-segmentangleto"
5121 || anArg == "-segangleto"
5122 || anArg == "-segmentangle2"
5123 || anArg == "-segangle2")
5124 && Draw::ParseReal (theArgVec[anArgIter + 1], aSegAngle2))
5128 else if (aName.IsEmpty())
5130 aName = theArgVec[anArgIter];
5132 else if (aMajorRad < 0.0
5133 && Draw::ParseReal (theArgVec[anArgIter], aMajorRad))
5137 else if (aMinorRad < 0.0
5138 && Draw::ParseReal (theArgVec[anArgIter], aMinorRad))
5142 else if (anAngles[0] < 0.0
5143 && Draw::ParseReal (theArgVec[anArgIter], anAngles[0]))
5147 else if (anAngles[1] < 0.0
5148 && Draw::ParseReal (theArgVec[anArgIter], anAngles[1]))
5152 else if (anAngles[2] < 0.0
5153 && Draw::ParseReal (theArgVec[anArgIter], anAngles[2]))
5159 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
5164 if (anAngles[2] > 0.0)
5166 aSegAngle1 = anAngles[0];
5167 aSegAngle2 = anAngles[1];
5168 aPipeAngle = anAngles[2];
5170 else if (anAngles[1] > 0.0)
5172 aSegAngle1 = anAngles[0];
5173 aSegAngle2 = anAngles[1];
5175 else if (anAngles[0] > 0.0)
5177 aPipeAngle = anAngles[0];
5180 aSegAngle1 = aSegAngle1 * (M_PI / 180.0);
5181 aSegAngle2 = aSegAngle2 * (M_PI / 180.0);
5182 aPipeAngle = aPipeAngle * (M_PI / 180.0);
5184 if (aMajorRad <= 0 || aMinorRad <= 0 || aNbSlices <= 0 || aNbStacks <= 0
5185 || Abs(aSegAngle2 - aSegAngle1) <= Precision::Angular()
5186 || Abs(aPipeAngle) <= Precision::Angular())
5188 Message::SendFail ("Syntax error: wrong parameters");
5192 Handle(Graphic3d_ArrayOfTriangles) aTriangles = Prs3d_ToolTorus::Create (aMajorRad, aMinorRad, aSegAngle1, aSegAngle2, aPipeAngle, aNbSlices, aNbStacks, gp_Trsf());
5193 Handle(AIS_InteractiveObject) anIO = new MyPArrayObject (aTriangles);
5194 ViewerTest::Display (aName, anIO, false);
5198 //===========================================================================
5199 //function : VCylinder
5200 //purpose : creates and displays a cylinder
5201 //===========================================================================
5202 static Standard_Integer VCylinder (Draw_Interpretor& /*di*/,
5203 Standard_Integer theNbArgs,
5204 const char** theArgVec)
5206 if (ViewerTest::GetAISContext().IsNull())
5208 Message::SendFail ("Error: no active viewer");
5212 TCollection_AsciiString aName;
5213 Standard_Integer aNbSlices = 100, aNbStacks = 1;
5214 Standard_Real aBotRad = -1.0, aTopRad = -1.0, aHeight = -1.0;
5215 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
5216 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
5218 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5220 if (anUpdateTool.parseRedrawMode (anArg))
5224 else if (anArgIter + 1 < theNbArgs
5225 && (anArg == "-nbslices"
5226 || anArg == "-slices")
5227 && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbSlices))
5231 else if (anArgIter + 1 < theNbArgs
5232 && (anArg == "-nbstacks"
5233 || anArg == "-stacks")
5234 && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbStacks))
5238 else if (anArgIter + 1 < theNbArgs
5239 && anArg == "-radius"
5240 && Draw::ParseReal (theArgVec[anArgIter + 1], aBotRad))
5245 else if (anArgIter + 1 < theNbArgs
5246 && anArg == "-bottomradius"
5247 && Draw::ParseReal (theArgVec[anArgIter + 1], aBotRad))
5251 else if (anArgIter + 1 < theNbArgs
5252 && anArg == "-topradius"
5253 && Draw::ParseReal (theArgVec[anArgIter + 1], aTopRad))
5257 else if (anArgIter + 1 < theNbArgs
5258 && anArg == "-height"
5259 && Draw::ParseReal (theArgVec[anArgIter + 1], aHeight))
5263 else if (aName.IsEmpty())
5265 aName = theArgVec[anArgIter];
5267 else if (aBotRad < 0.0
5268 && Draw::ParseReal (theArgVec[anArgIter], aBotRad))
5272 else if (aTopRad < 0.0
5273 && Draw::ParseReal (theArgVec[anArgIter], aTopRad))
5277 else if (aHeight < 0.0
5278 && Draw::ParseReal (theArgVec[anArgIter], aHeight))
5284 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
5289 if (aBotRad < 0 || aTopRad < 0 || aHeight <= 0 || aNbSlices < 3)
5291 Message::SendFail ("Syntax error: wrong parameters");
5295 Handle(Graphic3d_ArrayOfTriangles) aTriangles = Prs3d_ToolCylinder::Create (aBotRad, aTopRad, aHeight, aNbSlices, aNbStacks, gp_Trsf());
5296 Handle(AIS_InteractiveObject) anIO = new MyPArrayObject (aTriangles);
5297 ViewerTest::Display (aName, anIO, false);
5301 //===========================================================================
5302 //function : VSphere
5303 //purpose : creates and displays a sphere
5304 //===========================================================================
5305 static Standard_Integer VSphere (Draw_Interpretor& /*di*/,
5306 Standard_Integer theNbArgs,
5307 const char** theArgVec)
5309 if (ViewerTest::GetAISContext().IsNull())
5311 Message::SendFail ("Error: no active viewer");
5315 TCollection_AsciiString aName;
5316 Standard_Integer aNbSlices = 100, aNbStacks = 100;
5317 Standard_Real aRad = -1.0;
5318 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
5319 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
5321 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5323 if (anUpdateTool.parseRedrawMode (anArg))
5327 else if (anArgIter + 1 < theNbArgs
5328 && (anArg == "-nbslices"
5329 || anArg == "-slices")
5330 && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbSlices))
5334 else if (anArgIter + 1 < theNbArgs
5335 && (anArg == "-nbstacks"
5336 || anArg == "-stacks")
5337 && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbStacks))
5341 else if (anArgIter + 1 < theNbArgs
5342 && anArg == "-radius"
5343 && Draw::ParseReal (theArgVec[anArgIter + 1], aRad))
5347 else if (aName.IsEmpty())
5349 aName = theArgVec[anArgIter];
5352 && Draw::ParseReal (theArgVec[anArgIter], aRad))
5358 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
5363 if (aRad <= 0 || aNbSlices <= 0 || aNbStacks <= 0)
5365 Message::SendFail ("Syntax error: wrong parameters");
5369 Handle(Graphic3d_ArrayOfTriangles) aTriangles = Prs3d_ToolSphere::Create (aRad, aNbSlices, aNbStacks, gp_Trsf());
5370 Handle(AIS_InteractiveObject) anIO = new MyPArrayObject (aTriangles);
5371 ViewerTest::Display (aName, anIO, false);
5375 //=======================================================================
5376 //function : VObjZLayer
5377 //purpose : Set or get z layer id for presentable object
5378 //=======================================================================
5380 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
5381 Standard_Integer argc,
5384 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5385 if (aContext.IsNull())
5387 Message::SendFail ("Error: no active viewer");
5392 TCollection_AsciiString aOperation;
5394 aOperation = TCollection_AsciiString (argv [1]);
5396 // check for correct arguments
5397 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
5398 !(argc == 3 && aOperation.IsEqual ("get")))
5400 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
5401 di << " set - set layer id for interactive object, layerid - z layer id\n";
5402 di << " get - get layer id of interactive object\n";
5403 di << " argument layerid should be passed for set operation only\n";
5408 TCollection_AsciiString aName (argv[2]);
5409 Handle(AIS_InteractiveObject) anInterObj;
5410 GetMapOfAIS().Find2 (aName, anInterObj);
5411 if (anInterObj.IsNull())
5413 Message::SendFail() << "Syntax error: object '" << aName << "' is not displayed";
5417 // process operation
5418 if (aOperation.IsEqual ("set"))
5420 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
5421 aContext->SetZLayer (anInterObj, aLayerId);
5423 else if (aOperation.IsEqual ("get"))
5425 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
5431 //=======================================================================
5432 //function : VPolygonOffset
5433 //purpose : Set or get polygon offset parameters
5434 //=======================================================================
5435 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
5436 Standard_Integer argc,
5439 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5440 if (aContext.IsNull())
5442 Message::SendFail ("Error: no active viewer");
5446 if (argc > 2 && argc != 5)
5448 Message::SendFail() << "Syntax error: wrong number of arguments.\n"
5449 "Usage: " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
5450 "without arguments prints the default values";
5455 Handle(AIS_InteractiveObject) anInterObj;
5458 TCollection_AsciiString aName (argv[1]);
5459 if (!GetMapOfAIS().Find2 (aName, anInterObj)
5460 || anInterObj.IsNull())
5462 Message::SendFail() << "Syntax error: object '" << aName << "' is not displayed";
5467 Standard_Integer aMode;
5468 Standard_ShortReal aFactor, aUnits;
5471 aMode = Draw::Atoi(argv[2]);
5472 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
5473 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
5475 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
5476 aContext->UpdateCurrentViewer();
5481 if (anInterObj->HasPolygonOffsets())
5483 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
5484 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
5485 std::cout << "\tMode: " << aMode << std::endl;
5486 std::cout << "\tFactor: " << aFactor << std::endl;
5487 std::cout << "\tUnits: " << aUnits << std::endl;
5492 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
5496 std::cout << "Default polygon offset parameters:" << std::endl;
5497 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
5498 std::cout << "\tMode: " << aMode << std::endl;
5499 std::cout << "\tFactor: " << aFactor << std::endl;
5500 std::cout << "\tUnits: " << aUnits << std::endl;
5505 // This class is used for testing markers.
5506 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
5511 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
5512 const Standard_Integer& thePointsOnSide,
5513 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
5515 myStartPoint = theStartPoint;
5516 myPointsOnSide = thePointsOnSide;
5517 myMarkerAspect = theMarkerAspect;
5520 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_MarkersArrayObject,AIS_InteractiveObject);
5524 virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
5525 const Handle(Prs3d_Presentation)& thePrs,
5526 const Standard_Integer theMode) Standard_OVERRIDE;
5528 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel,
5529 const Standard_Integer theMode) Standard_OVERRIDE;
5533 gp_XYZ myStartPoint;
5534 Standard_Integer myPointsOnSide;
5535 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
5539 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager)& ,
5540 const Handle(Prs3d_Presentation)& aPresentation,
5541 const Standard_Integer )
5543 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
5544 if (myPointsOnSide == 1)
5546 anArray->AddVertex (myStartPoint);
5550 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5552 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5554 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5556 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5557 anArray->SetVertexColor (anArray->VertexNumber(),
5560 k / myPointsOnSide);
5566 aPresentation->Clear();
5567 if (!myMarkerAspect.IsNull())
5569 aPresentation->CurrentGroup()->SetGroupPrimitivesAspect (myMarkerAspect);
5571 aPresentation->CurrentGroup()->AddPrimitiveArray (anArray);
5574 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5575 const Standard_Integer /*theMode*/)
5577 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
5579 if (myPointsOnSide == 1)
5581 gp_Pnt aPoint (myStartPoint);
5582 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5583 theSelection->Add (aSensetivePoint);
5587 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5589 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5591 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5593 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5594 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5595 theSelection->Add (aSensetivePoint);
5601 //=======================================================================
5602 //function : VMarkersTest
5603 //purpose : Draws an array of markers for testing purposes.
5604 //=======================================================================
5605 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5606 Standard_Integer theArgNb,
5607 const char** theArgVec)
5609 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5610 if (aContext.IsNull())
5612 Message::SendFail ("Error: no active viewer");
5618 Message::SendFail ("Syntax error: wrong number of arguments");
5622 Standard_Integer anArgIter = 1;
5624 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5625 TCollection_AsciiString aFileName;
5626 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5627 Atof (theArgVec[anArgIter + 1]),
5628 Atof (theArgVec[anArgIter + 2]));
5631 Standard_Integer aPointsOnSide = 10;
5632 Standard_Integer aMarkerType = -1;
5633 Standard_Real aScale = 1.0;
5634 for (; anArgIter < theArgNb; ++anArgIter)
5636 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5637 if (anArg.Search ("PointsOnSide=") > -1)
5639 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5641 else if (anArg.Search ("MarkerType=") > -1)
5643 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5645 else if (anArg.Search ("Scale=") > -1)
5647 aScale = anArg.Token ("=", 2).RealValue();
5649 else if (anArg.Search ("FileName=") > -1)
5651 aFileName = anArg.Token ("=", 2);
5655 Message::SendFail() << "Syntax error: wrong argument '" << anArg << "'";
5660 Handle(Graphic3d_AspectMarker3d) anAspect;
5661 Handle(Image_AlienPixMap) anImage;
5662 Quantity_Color aColor (Quantity_NOC_GREEN1);
5663 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5664 && !aFileName.IsEmpty())
5666 anImage = new Image_AlienPixMap();
5667 if (!anImage->Load (aFileName))
5669 Message::SendFail() << "Error: could not load image from file '" << aFileName << "'!";
5672 if (anImage->Format() == Image_Format_Gray)
5674 anImage->SetFormat (Image_Format_Alpha);
5676 else if (anImage->Format() == Image_Format_GrayF)
5678 anImage->SetFormat (Image_Format_AlphaF);
5680 anAspect = new Graphic3d_AspectMarker3d (anImage);
5684 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5687 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5688 VDisplayAISObject (aName, aMarkersArray);
5693 //=======================================================================
5694 //function : TextToBrep
5695 //purpose : Tool for conversion text to occt-shapes
5696 //=======================================================================
5697 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5698 Standard_Integer theArgNb,
5699 const char** theArgVec)
5704 Message::SendFail() << "Error: " << theArgVec[0] << " - invalid syntax";
5708 Standard_Integer anArgIt = 1;
5709 Standard_CString aName = theArgVec[anArgIt++];
5710 Standard_CString aText = theArgVec[anArgIt++];
5712 Font_BRepFont aFont;
5713 TCollection_AsciiString aFontName ("Courier");
5714 Standard_Real aTextHeight = 16.0;
5715 Font_FontAspect aFontAspect = Font_FA_Regular;
5716 Standard_Boolean anIsCompositeCurve = Standard_False;
5717 gp_Ax3 aPenAx3 (gp::XOY());
5718 gp_Dir aNormal (0.0, 0.0, 1.0);
5719 gp_Dir aDirection (1.0, 0.0, 0.0);
5722 Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT;
5723 Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM;
5724 Font_StrictLevel aStrictLevel = Font_StrictLevel_Any;
5725 for (; anArgIt < theArgNb; ++anArgIt)
5727 TCollection_AsciiString aParam (theArgVec[anArgIt]);
5730 if (aParam == "-pos"
5731 || aParam == "-position")
5733 if (anArgIt + 3 >= theArgNb)
5735 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5739 aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt]));
5740 aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt]));
5741 aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt]));
5743 else if (aParam == "-halign")
5745 if (++anArgIt >= theArgNb)
5747 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5751 TCollection_AsciiString aType (theArgVec[anArgIt]);
5753 if (aType == "left")
5755 aHJustification = Graphic3d_HTA_LEFT;
5757 else if (aType == "center")
5759 aHJustification = Graphic3d_HTA_CENTER;
5761 else if (aType == "right")
5763 aHJustification = Graphic3d_HTA_RIGHT;
5767 Message::SendFail() << "Error: wrong syntax at '" << aParam << "'";
5771 else if (aParam == "-valign")
5773 if (++anArgIt >= theArgNb)
5775 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5779 TCollection_AsciiString aType (theArgVec[anArgIt]);
5783 aVJustification = Graphic3d_VTA_TOP;
5785 else if (aType == "center")
5787 aVJustification = Graphic3d_VTA_CENTER;
5789 else if (aType == "bottom")
5791 aVJustification = Graphic3d_VTA_BOTTOM;
5793 else if (aType == "topfirstline")
5795 aVJustification = Graphic3d_VTA_TOPFIRSTLINE;
5799 Message::SendFail() << "Error: wrong syntax at '" << aParam << "'";
5803 else if (aParam == "-height")
5805 if (++anArgIt >= theArgNb)
5807 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5811 aTextHeight = Draw::Atof(theArgVec[anArgIt]);
5813 else if (aParam == "-aspect")
5815 if (++anArgIt >= theArgNb)
5817 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5821 TCollection_AsciiString anOption (theArgVec[anArgIt]);
5822 anOption.LowerCase();
5823 if (!parseFontStyle (anOption, aFontAspect))
5825 Message::SendFail() << "Error: unknown font aspect '" << anOption << "'";
5829 else if (aParam == "-font")
5831 if (++anArgIt >= theArgNb)
5833 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5837 aFontName = theArgVec[anArgIt];
5839 else if (aParam == "-strict")
5841 anArgIt += parseFontStrictLevel (theArgNb - anArgIt - 1,
5842 theArgVec + anArgIt + 1,
5845 else if (aParam == "-composite")
5847 if (++anArgIt >= theArgNb)
5849 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5853 Draw::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve);
5855 else if (aParam == "-plane")
5857 if (anArgIt + 6 >= theArgNb)
5859 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5863 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
5864 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
5865 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
5866 aNormal.SetCoord (aX, aY, aZ);
5868 aX = Draw::Atof (theArgVec[++anArgIt]);
5869 aY = Draw::Atof (theArgVec[++anArgIt]);
5870 aZ = Draw::Atof (theArgVec[++anArgIt]);
5871 aDirection.SetCoord (aX, aY, aZ);
5875 Message::SendFail() << "Warning! Unknown argument '" << aParam << "'";
5879 aFont.SetCompositeCurveMode (anIsCompositeCurve);
5880 if (!aFont.FindAndInit (aFontName.ToCString(), aFontAspect, aTextHeight, aStrictLevel))
5882 Message::SendFail ("Error: unable to load Font");
5886 aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection);
5888 Font_BRepTextBuilder aBuilder;
5889 DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification));
5893 //=======================================================================
5895 //purpose : Font management
5896 //=======================================================================
5897 struct FontComparator
5899 bool operator() (const Handle(Font_SystemFont)& theFontA,
5900 const Handle(Font_SystemFont)& theFontB)
5902 return theFontA->FontKey().IsLess (theFontB->FontKey());
5906 static int VFont (Draw_Interpretor& theDI,
5907 Standard_Integer theArgNb,
5908 const char** theArgVec)
5910 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5911 bool toPrintList = theArgNb < 2, toPrintNames = false;
5912 Font_StrictLevel aStrictLevel = Font_StrictLevel_Any;
5913 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5915 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5916 TCollection_AsciiString anArgCase (anArg);
5917 anArgCase.LowerCase();
5918 if (anArgCase == "-strict")
5920 anArgIter += parseFontStrictLevel (theArgNb - anArgIter - 1,
5921 theArgVec + anArgIter + 1,
5924 else if (anArgCase == "-clear")
5926 aMgr->ClearFontDataBase();
5928 else if (anArgCase == "-init")
5930 aMgr->InitFontDataBase();
5932 else if (anArgCase == "-list")
5936 else if (anArgCase == "-names")
5939 toPrintNames = true;
5941 else if (anArgIter + 1 < theArgNb
5942 && (anArgCase == "-find"
5943 || anArgCase == "-findinfo"
5944 || anArgCase == "-findall"
5945 || anArgCase == "find"))
5947 const TCollection_AsciiString aFontName (theArgVec[++anArgIter]);
5948 Font_FontAspect aFontAspect = Font_FA_Undefined;
5949 if (++anArgIter < theArgNb)
5951 anArgCase = theArgVec[anArgIter];
5952 anArgCase.LowerCase();
5953 if (!parseFontStyle (anArgCase, aFontAspect))
5959 const bool toFindAll = (anArgCase == "-findall");
5960 const bool toPrintInfo = (anArgCase == "-findinfo");
5961 TCollection_AsciiString aResult;
5963 || aFontName.Search ("*") != -1)
5965 const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts();
5966 std::vector<Handle(Font_SystemFont)> aFontsSorted;
5967 aFontsSorted.reserve (aFonts.Size());
5968 for (Font_NListOfSystemFont::Iterator aFontIter (aFonts); aFontIter.More(); aFontIter.Next())
5970 aFontsSorted.push_back (aFontIter.Value());
5972 std::stable_sort (aFontsSorted.begin(), aFontsSorted.end(), FontComparator());
5973 for (std::vector<Handle(Font_SystemFont)>::iterator aFontIter = aFontsSorted.begin(); aFontIter != aFontsSorted.end(); ++aFontIter)
5975 const Handle(Font_SystemFont)& aFont = *aFontIter;
5976 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match -nocase \"") + aFontName + "\" \"" + aFont->FontName() + "\"";
5977 if (theDI.Eval (aCheck.ToCString()) == 0
5978 && *theDI.Result() != '1')
5985 if (!aResult.IsEmpty())
5990 aResult += toPrintInfo ? aFont->ToString() : aFont->FontName();
5997 else if (Handle(Font_SystemFont) aFont = aMgr->FindFont (aFontName, aStrictLevel, aFontAspect))
5999 aResult = toPrintInfo ? aFont->ToString() : aFont->FontName();
6002 if (!aResult.IsEmpty())
6008 Message::SendFail() << "Error: font '" << aFontName << "' is not found";
6011 else if (anArgIter + 1 < theArgNb
6012 && (anArgCase == "-add"
6013 || anArgCase == "add"
6014 || anArgCase == "-register"
6015 || anArgCase == "register"))
6018 Standard_CString aFontPath = theArgVec[anArgIter++];
6019 TCollection_AsciiString aFontName;
6020 Font_FontAspect aFontAspect = Font_FA_Undefined;
6021 Standard_Integer isSingelStroke = -1;
6022 for (; anArgIter < theArgNb; ++anArgIter)
6024 anArgCase = theArgVec[anArgIter];
6025 anArgCase.LowerCase();
6026 if (aFontAspect == Font_FontAspect_UNDEFINED
6027 && parseFontStyle (anArgCase, aFontAspect))
6031 else if (anArgCase == "singlestroke"
6032 || anArgCase == "singleline"
6033 || anArgCase == "oneline")
6037 else if (aFontName.IsEmpty())
6039 aFontName = theArgVec[anArgIter];
6048 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
6051 Message::SendFail() << "Error: font '" << aFontPath << "' is not found!";
6055 if (aFontAspect != Font_FontAspect_UNDEFINED
6056 || !aFontName.IsEmpty())
6058 TCollection_AsciiString aName = aFont->FontName();
6059 if (!aFontName.IsEmpty())
6063 Handle(Font_SystemFont) aFont2 = new Font_SystemFont (aName);
6064 if (aFontAspect != Font_FontAspect_UNDEFINED)
6066 aFont2->SetFontPath (aFontAspect, aFontPath, 0);
6070 for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
6072 aFont2->SetFontPath ((Font_FontAspect )anAspectIter,
6073 aFont->FontPath ((Font_FontAspect )anAspectIter),
6074 aFont->FontFaceId ((Font_FontAspect )anAspectIter));
6079 if (isSingelStroke != -1)
6081 aFont->SetSingleStrokeFont (isSingelStroke == 1);
6084 aMgr->RegisterFont (aFont, Standard_True);
6085 theDI << aFont->ToString();
6087 else if (anArgCase == "-aliases")
6089 TCollection_AsciiString anAliasName;
6090 TColStd_SequenceOfHAsciiString aNames;
6091 if (anArgIter + 1 < theArgNb
6092 && *theArgVec[anArgIter + 1] != '-')
6094 anAliasName = theArgVec[++anArgIter];
6096 if (!anAliasName.IsEmpty())
6098 aMgr->GetFontAliases (aNames, anAliasName);
6102 aMgr->GetAllAliases (aNames);
6104 for (TColStd_SequenceOfHAsciiString::Iterator aNameIter (aNames); aNameIter.More(); aNameIter.Next())
6106 theDI << "{" << aNameIter.Value()->String() << "} ";
6109 else if (anArgIter + 2 < theArgNb
6110 && anArgCase == "-addalias")
6112 TCollection_AsciiString anAliasName(theArgVec[++anArgIter]);
6113 TCollection_AsciiString aFontName (theArgVec[++anArgIter]);
6114 aMgr->AddFontAlias (anAliasName, aFontName);
6116 else if (anArgIter + 2 < theArgNb
6117 && anArgCase == "-removealias")
6119 TCollection_AsciiString anAliasName(theArgVec[++anArgIter]);
6120 TCollection_AsciiString aFontName (theArgVec[++anArgIter]);
6121 aMgr->RemoveFontAlias (anAliasName, aFontName);
6123 else if (anArgIter + 1 < theArgNb
6124 && anArgCase == "-clearalias")
6126 TCollection_AsciiString anAliasName(theArgVec[++anArgIter]);
6127 aMgr->RemoveFontAlias (anAliasName, "");
6129 else if (anArgCase == "-clearaliases")
6131 aMgr->RemoveFontAlias ("", "");
6133 else if (anArgCase == "-verbose"
6134 || anArgCase == "-trace")
6136 bool toEnable = true;
6137 if (anArgIter + 1 < theArgNb
6138 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6142 aMgr->SetTraceAliases (toEnable);
6144 else if (anArgCase == "-unicodefallback"
6145 || anArgCase == "-fallback"
6146 || anArgCase == "-touseunicodesubsetfallback")
6148 bool toEnable = true;
6149 if (anArgIter + 1 < theArgNb
6150 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6154 Font_FontMgr::ToUseUnicodeSubsetFallback() = toEnable;
6158 Message::SendFail() << "Warning! Unknown argument '" << anArg << "'";
6164 // just print the list of available fonts
6165 Standard_Boolean isFirst = Standard_True;
6166 const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts();
6167 std::vector<Handle(Font_SystemFont)> aFontsSorted;
6168 aFontsSorted.reserve (aFonts.Size());
6169 for (Font_NListOfSystemFont::Iterator aFontIter (aFonts); aFontIter.More(); aFontIter.Next())
6171 aFontsSorted.push_back (aFontIter.Value());
6173 std::stable_sort (aFontsSorted.begin(), aFontsSorted.end(), FontComparator());
6174 for (std::vector<Handle(Font_SystemFont)>::iterator aFontIter = aFontsSorted.begin(); aFontIter != aFontsSorted.end(); ++aFontIter)
6176 const Handle(Font_SystemFont)& aFont = *aFontIter;
6184 theDI << "\"" << aFont->FontName() << "\"";
6192 theDI << aFont->ToString();
6194 isFirst = Standard_False;
6202 //=======================================================================
6203 //function : VVertexMode
6204 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
6205 //=======================================================================
6207 static int VVertexMode (Draw_Interpretor& theDI,
6208 Standard_Integer theArgNum,
6209 const char** theArgs)
6211 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6212 if (aContext.IsNull())
6214 Message::SendFail ("Error: no active viewer");
6218 // No arguments --> print the current default vertex draw mode
6221 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
6222 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
6226 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
6227 TCollection_AsciiString aParam (theArgs[1]);
6228 if (aParam == "-set")
6232 Message::SendFail ("Error: '-set' option not followed by the mode and optional object name(s)\n"
6233 "Type 'help vvertexmode' for usage hints");
6237 TCollection_AsciiString aModeStr (theArgs[2]);
6238 Prs3d_VertexDrawMode aNewMode =
6239 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
6240 (aModeStr == "all" ? Prs3d_VDM_All :
6241 Prs3d_VDM_Inherited);
6243 Standard_Boolean aRedrawNeeded = Standard_False;
6244 AIS_ListOfInteractive anObjs;
6246 // No object(s) specified -> use all displayed
6249 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
6250 aContext->DisplayedObjects (anObjs);
6251 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
6252 aRedrawNeeded = Standard_True;
6255 Handle(AIS_InteractiveObject) anObject;
6256 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
6258 TCollection_AsciiString aName (theArgs[aCount]);
6259 if (!GetMapOfAIS().Find2 (aName, anObject))
6261 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
6264 anObjs.Append (anObject);
6267 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
6269 anObject = anIt.Value();
6270 anObject->Attributes()->SetVertexDrawMode (aNewMode);
6271 aContext->Redisplay (anObject, Standard_False);
6272 aRedrawNeeded = Standard_True;
6276 ViewerTest::CurrentView()->Redraw();
6281 Handle(AIS_InteractiveObject) anObject;
6283 || !GetMapOfAIS().Find2 (aParam, anObject))
6285 Message::SendFail ("Syntax error: invalid number of arguments");
6289 // One argument (object name) --> print the current vertex draw mode for the object
6290 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
6291 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
6295 //=======================================================================
6296 //function : VPointCloud
6297 //purpose : Create interactive object for arbitrary set of points.
6298 //=======================================================================
6299 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
6300 Standard_Integer theArgNum,
6301 const char** theArgs)
6305 Message::SendFail ("Syntax error: wrong number of arguments");
6309 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
6310 if (anAISContext.IsNull())
6312 Message::SendFail ("Error: no active view!");
6316 TCollection_AsciiString aName;
6317 TopoDS_Shape aShape;
6319 TCollection_AsciiString aDistribution;
6321 Standard_Real aDistRadius = 0.0;
6322 Standard_Integer aDistNbPoints = 0;
6325 bool toRandColors = false;
6326 bool hasNormals = true, hasUV = false;
6327 bool isDensityPoints = false;
6328 Standard_Real aDensity = 0.0, aDist = 0.0;
6329 Standard_Real aTol = Precision::Confusion();
6330 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
6332 TCollection_AsciiString aFlag (theArgs[anArgIter]);
6334 if (aFlag == "-randcolors"
6335 || aFlag == "-randcolor")
6337 toRandColors = Draw::ParseOnOffIterator (theArgNum, theArgs, anArgIter);
6339 else if (aFlag == "-normals"
6340 || aFlag == "-normal")
6342 hasNormals = Draw::ParseOnOffIterator (theArgNum, theArgs, anArgIter);
6344 else if (aFlag == "-nonormals"
6345 || aFlag == "-nonormal")
6347 hasNormals = !Draw::ParseOnOffIterator (theArgNum, theArgs, anArgIter);
6349 else if (aFlag == "-uv"
6350 || aFlag == "-texels")
6352 hasUV = Draw::ParseOnOffIterator (theArgNum, theArgs, anArgIter);
6354 else if ((aFlag == "-dist"
6355 || aFlag == "-distance")
6356 && anArgIter + 1 < theArgNum
6357 && Draw::ParseReal (theArgs[anArgIter + 1], aDist))
6362 theDI << "Syntax error: -distance value should be >= 0.0";
6365 aDist = Max (aDist, Precision::Confusion());
6367 else if ((aFlag == "-dens"
6368 || aFlag == "-density")
6369 && anArgIter + 1 < theArgNum
6370 && Draw::ParseReal (theArgs[anArgIter + 1], aDensity))
6373 isDensityPoints = Standard_True;
6374 if (aDensity <= 0.0)
6376 theDI << "Syntax error: -density value should be > 0.0";
6380 else if ((aFlag == "-tol"
6381 || aFlag == "-tolerance")
6382 && anArgIter + 1 < theArgNum
6383 && Draw::ParseReal (theArgs[anArgIter + 1], aTol))
6386 if (aTol < Precision::Confusion())
6388 theDI << "Syntax error: -tol value should be >= " << Precision::Confusion();
6392 else if ((aFlag == "-surface"
6393 || aFlag == "-volume")
6394 && anArgIter + 5 < theArgNum)
6396 aDistribution = aFlag;
6397 aDistCenter.SetCoord (Draw::Atof (theArgs[anArgIter + 1]),
6398 Draw::Atof (theArgs[anArgIter + 2]),
6399 Draw::Atof (theArgs[anArgIter + 3]));
6400 aDistRadius = Draw::Atof (theArgs[anArgIter + 4]);
6401 aDistNbPoints = Draw::Atoi (theArgs[anArgIter + 5]);
6404 else if (aName.IsEmpty())
6406 aName = theArgs[anArgIter];
6408 else if (aShape.IsNull())
6410 aShape = DBRep::Get (theArgs[anArgIter]);
6411 if (aShape.IsNull())
6413 theDI << "Syntax error: invalid shape '" << theArgs[anArgIter] << "'";
6419 theDI << "Syntax error at '" << theArgs[anArgIter] << "'";
6424 Graphic3d_ArrayFlags aFlags = Graphic3d_ArrayFlags_None;
6427 aFlags |= Graphic3d_ArrayFlags_VertexNormal;
6431 aFlags |= Graphic3d_ArrayFlags_VertexColor;
6435 aFlags |= Graphic3d_ArrayFlags_VertexTexel;
6438 // generate arbitrary set of points
6439 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
6440 if (!aShape.IsNull())
6442 class PointCloudPntFiller : public BRepLib_PointCloudShape
6445 PointCloudPntFiller (Standard_Real theTol) : BRepLib_PointCloudShape (TopoDS_Shape(), theTol) {}
6446 void SetPointArray (const Handle(Graphic3d_ArrayOfPoints)& thePoints) { myPoints = thePoints; }
6449 virtual void addPoint (const gp_Pnt& thePoint,
6450 const gp_Vec& theNorm,
6451 const gp_Pnt2d& theUV,
6452 const TopoDS_Shape& ) Standard_OVERRIDE
6454 const Standard_Integer aPntIndex = myPoints->AddVertex (thePoint, theUV);
6455 if (theNorm.SquareMagnitude() > gp::Resolution())
6457 myPoints->SetVertexNormal (aPntIndex, theNorm);
6459 if (myPoints->HasVertexColors())
6461 Quantity_Color aColor (360.0 * Standard_Real(aPntIndex) / Standard_Real(myPoints->VertexNumberAllocated()),
6462 1.0, 0.5, Quantity_TOC_HLS);
6463 myPoints->SetVertexColor (aPntIndex, aColor);
6468 Handle(Graphic3d_ArrayOfPoints) myPoints;
6471 PointCloudPntFiller aPoitCloudTool (aTol);
6472 aPoitCloudTool.SetShape (aShape);
6473 aPoitCloudTool.SetDistance (aDist);
6475 Standard_Integer aNbPoints = isDensityPoints
6476 ? aPoitCloudTool.NbPointsByDensity (aDensity)
6477 : aPoitCloudTool.NbPointsByTriangulation();
6478 theDI << "Number of the generated points : " << aNbPoints << "\n";
6479 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags);
6480 aPoitCloudTool.SetPointArray (anArrayPoints);
6481 Standard_Boolean isDone = isDensityPoints
6482 ? aPoitCloudTool.GeneratePointsByDensity (aDensity)
6483 : aPoitCloudTool.GeneratePointsByTriangulation();
6486 Message::SendFail() << "Error: Point cloud was not generated";
6490 else if (!aDistribution.IsEmpty())
6492 const bool isSurface = aDistribution == "-surface";
6494 anArrayPoints = new Graphic3d_ArrayOfPoints (aDistNbPoints, aFlags);
6495 std::mt19937 aRandomGenerator(0);
6496 std::uniform_real_distribution<> anAlphaDistrib(0.0, 2.0 * M_PI);
6497 std::uniform_real_distribution<> aBetaDistrib (0.0, 2.0 * M_PI);
6498 std::uniform_real_distribution<> aRadiusDistrib(0.0, aDistRadius);
6499 for (Standard_Integer aPntIt = 0; aPntIt < aDistNbPoints; ++aPntIt)
6501 Standard_Real anAlpha = anAlphaDistrib(aRandomGenerator);
6502 Standard_Real aBeta = aBetaDistrib (aRandomGenerator);
6503 Standard_Real aDistance = isSurface ? aDistRadius : aRadiusDistrib (aRandomGenerator);
6505 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
6507 Cos (anAlpha) * Cos (aBeta));
6508 gp_Pnt aPoint = aDistCenter.Translated (aDir.XYZ() * aDistance);
6510 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
6513 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aDistNbPoints),
6514 1.0, 0.5, Quantity_TOC_HLS);
6515 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
6520 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
6524 anArrayPoints->SetVertexTexel (anIndexOfPoint, gp_Pnt2d (anAlpha / 2.0 * M_PI,
6525 aBeta / 2.0 * M_PI));
6531 Message::SendFail ("Error: wrong number of arguments");
6535 // set array of points in point cloud object
6536 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
6537 aPointCloud->SetPoints (anArrayPoints);
6538 ViewerTest::Display (aName, aPointCloud);
6542 //=======================================================================
6543 //function : VPriority
6544 //purpose : Prints or sets the display priority for an object
6545 //=======================================================================
6547 static int VPriority (Draw_Interpretor& theDI,
6548 Standard_Integer theArgNum,
6549 const char** theArgs)
6551 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6552 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6553 if (aContext.IsNull())
6555 Message::SendFail ("Error: no active viewer");
6559 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
6560 Standard_Integer aPriority = Graphic3d_DisplayPriority_INVALID;
6561 Standard_Integer aNbArgs = theArgNum;
6562 if (aLastArg.IsIntegerValue())
6564 aPriority = aLastArg.IntegerValue();
6566 if (aPriority < Graphic3d_DisplayPriority_Bottom || aPriority > Graphic3d_DisplayPriority_Topmost)
6568 Message::SendFail() << "Syntax error: the specified display priority value '" << aLastArg
6569 << "' is outside the valid range [" << Graphic3d_DisplayPriority_Bottom << ".." << Graphic3d_DisplayPriority_Topmost << "]";
6575 anUpdateTool.Invalidate();
6580 Message::SendFail ("Syntax error: wrong number of arguments! See usage:");
6581 theDI.PrintHelp (theArgs[0]);
6585 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
6587 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
6592 TCollection_AsciiString aName (theArgs[anArgIter]);
6593 Handle(AIS_InteractiveObject) anIObj;
6594 GetMapOfAIS().Find2 (aName, anIObj);
6595 if (anIObj.IsNull())
6597 Message::SendFail() << "Error: the object '" << theArgs[1] << "' is not displayed";
6601 if (aPriority == Graphic3d_DisplayPriority_INVALID)
6603 theDI << aContext->DisplayPriority (anIObj) << " ";
6607 aContext->SetDisplayPriority (anIObj, (Graphic3d_DisplayPriority )aPriority);
6613 //! Auxiliary class for command vnormals.
6614 class MyShapeWithNormals : public AIS_Shape
6616 DEFINE_STANDARD_RTTI_INLINE(MyShapeWithNormals, AIS_Shape);
6619 Standard_Real NormalLength;
6620 Standard_Integer NbAlongU;
6621 Standard_Integer NbAlongV;
6622 Standard_Boolean ToUseMesh;
6623 Standard_Boolean ToOrient;
6627 //! Main constructor.
6628 MyShapeWithNormals (const TopoDS_Shape& theShape)
6629 : AIS_Shape (theShape),
6633 ToUseMesh (Standard_False),
6634 ToOrient (Standard_False) {}
6638 //! Compute presentation.
6639 virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
6640 const Handle(Prs3d_Presentation)& thePrs,
6641 const Standard_Integer theMode) Standard_OVERRIDE
6643 AIS_Shape::Compute (thePrsMgr, thePrs, theMode);
6645 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormalMap;
6648 DBRep_DrawableShape::addMeshNormals (aNormalMap, myshape, NormalLength);
6652 DBRep_DrawableShape::addSurfaceNormals (aNormalMap, myshape, NormalLength, NbAlongU, NbAlongV);
6655 Handle(Graphic3d_Group) aPrsGroup = thePrs->NewGroup();
6656 aPrsGroup->SetGroupPrimitivesAspect (myDrawer->ArrowAspect()->Aspect());
6658 const Standard_Real aArrowAngle = myDrawer->ArrowAspect()->Angle();
6659 const Standard_Real aArrowLength = myDrawer->ArrowAspect()->Length();
6660 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormalMap);
6661 aFaceIt.More(); aFaceIt.Next())
6663 const Standard_Boolean toReverse = ToOrient && aFaceIt.Key().Orientation() == TopAbs_REVERSED;
6664 Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (2 * aFaceIt.Value().Size());
6665 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aPntIt (aFaceIt.Value()); aPntIt.More(); aPntIt.Next())
6667 std::pair<gp_Pnt, gp_Pnt> aPair = aPntIt.Value();
6670 const gp_Vec aDir = aPair.first.XYZ() - aPair.second.XYZ();
6671 aPair.second = aPair.first.XYZ() + aDir.XYZ();
6674 aSegments->AddVertex (aPair.first);
6675 aSegments->AddVertex (aPair.second);
6676 Prs3d_Arrow::Draw (aPrsGroup, aPair.second, gp_Vec(aPair.first, aPair.second), aArrowAngle, aArrowLength);
6679 aPrsGroup->AddPrimitiveArray (aSegments);
6685 //=======================================================================
6686 //function : VNormals
6687 //purpose : Displays/Hides normals calculated on shape geometry or retrieved from triangulation
6688 //=======================================================================
6689 static int VNormals (Draw_Interpretor& theDI,
6690 Standard_Integer theArgNum,
6691 const char** theArgs)
6693 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6694 if (aContext.IsNull())
6696 Message::SendFail ("Error: no active viewer");
6699 else if (theArgNum < 2)
6701 Message::SendFail ("Syntax error: wrong number of arguments. See usage:");
6702 theDI.PrintHelp (theArgs[0]);
6706 Standard_Integer anArgIter = 1;
6707 Standard_CString aShapeName = theArgs[anArgIter++];
6708 TopoDS_Shape aShape = DBRep::Get (aShapeName);
6709 Standard_Boolean isOn = Standard_True;
6710 if (aShape.IsNull())
6712 Message::SendFail() << "Error: shape with name '" << aShapeName << "' is not found";
6716 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6717 Handle(MyShapeWithNormals) aShapePrs;
6718 if (aMap.IsBound2 (aShapeName))
6720 aShapePrs = Handle(MyShapeWithNormals)::DownCast (aMap.Find2 (aShapeName));
6723 Standard_Boolean isUseMesh = Standard_False;
6724 Standard_Real aLength = 10.0;
6725 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
6726 Standard_Boolean isOriented = Standard_False;
6727 for (; anArgIter < theArgNum; ++anArgIter)
6729 TCollection_AsciiString aParam (theArgs[anArgIter]);
6732 && Draw::ParseOnOff (aParam.ToCString(), isOn))
6736 else if (aParam == "-usemesh"
6737 || aParam == "-mesh")
6739 isUseMesh = Standard_True;
6741 else if (aParam == "-length"
6742 || aParam == "-len")
6745 aLength = anArgIter < theArgNum ? Draw::Atof (theArgs[anArgIter]) : 0.0;
6746 if (Abs (aLength) <= gp::Resolution())
6748 Message::SendFail ("Syntax error: length should not be zero");
6752 else if (aParam == "-orient"
6753 || aParam == "-oriented")
6755 isOriented = Standard_True;
6756 if (anArgIter + 1 < theArgNum
6757 && Draw::ParseOnOff (theArgs[anArgIter + 1], isOriented))
6762 else if (aParam == "-nbalongu"
6763 || aParam == "-nbu")
6766 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6769 Message::SendFail ("Syntax error: NbAlongU should be >=1");
6773 else if (aParam == "-nbalongv"
6774 || aParam == "-nbv")
6777 aNbAlongV = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6780 Message::SendFail ("Syntax error: NbAlongV should be >=1");
6784 else if (aParam == "-nbalong"
6785 || aParam == "-nbuv")
6788 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6789 aNbAlongV = aNbAlongU;
6792 Message::SendFail ("Syntax error: NbAlong should be >=1");
6798 Message::SendFail() << "Syntax error: unknown argument '" << aParam << "'";
6805 if (aShapePrs.IsNull())
6807 aShapePrs = new MyShapeWithNormals (aShape);
6809 aShapePrs->ToUseMesh = isUseMesh;
6810 aShapePrs->ToOrient = isOriented;
6811 aShapePrs->NormalLength = aLength;
6812 aShapePrs->NbAlongU = aNbAlongU;
6813 aShapePrs->NbAlongV = aNbAlongV;
6814 VDisplayAISObject (aShapeName, aShapePrs);
6816 else if (!aShapePrs.IsNull())
6818 VDisplayAISObject (aShapeName, new AIS_Shape (aShape));
6824 //=======================================================================
6825 //function : ObjectsCommands
6827 //=======================================================================
6829 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
6831 const char* aGroup = "AIS Viewer";
6832 const char* aFileName = __FILE__;
6833 auto addCmd = [&](const char* theName, Draw_Interpretor::CommandFunction theFunc, const char* theHelp)
6835 theCommands.Add (theName, theHelp, aFileName, theFunc, aGroup);
6838 addCmd ("vtrihedron", VTrihedron, /* [vtrihedron] */ R"(
6840 [-dispMode {wireframe|shading} ]
6842 [-zaxis u v w -xaxis u v w ]
6843 [-drawAxes {X|Y|Z|XY|YZ|XZ|XYZ}]
6844 [-hideLabels {on|off}]
6845 [-hideArrows {on|off}]
6846 [-label {XAxis|YAxis|ZAxis} value]
6847 [-attribute {XAxisLength|YAxisLength|ZAxisLength
6848 |TubeRadiusPercent|ConeRadiusPercent
6849 |ConeLengthPercent|OriginRadiusPercent
6850 |ShadingNumberOfFacettes} value]
6851 [-color {Origin|XAxis|YAxis|ZAxis|XOYAxis|YOZAxis
6852 |XOZAxis|Whole} {r g b | colorName}]
6853 [-textColor [XAxis|YAxis|ZAxis] {r g b | colorName}]
6854 [-arrowColor [XAxis|YAxis|ZAxis] {r g b | colorName}]
6855 [-priority {Origin|XAxis|YAxis|ZAxis|XArrow
6856 |YArrow|ZArrow|XOYAxis|YOZAxis
6857 |XOZAxis|Whole} value]
6859 Creates/changes *AIS_Trihedron* object.
6860 -dispMode mode of visualization: wf - wireframe,
6862 default value is wireframe;
6863 -origin allows to set trihedron location;
6864 -zaxis/-xaxis allows to set trihedron X and Z directions;
6865 the directions should be orthogonal;
6866 Y direction is calculated;
6867 -drawAxes allows to set what axes are drawn in the
6868 trihedron, default state is XYZ;
6869 -hideLabels allows to show/hide trihedron labels;
6870 -hideArrows allows to show/hide trihedron arrows;
6871 -label allows to change default X/Y/Z titles of axes;
6872 -attribute sets parameters of trihedron;
6873 -color sets color properties of parts of trihedron;
6874 -textColor sets color properties of trihedron labels;
6875 -arrowColor sets color properties of trihedron arrows;
6876 -priority allows to change default selection priority
6877 of trihedron components.
6878 )" /* [vtrihedron] */);
6880 addCmd ("vtri2d", VTrihedron2D, /* [vtri2d] */ R"(
6881 vtri2d Name : Creates a plane with a 2D trihedron from an interactively selected face.
6884 addCmd ("vplanetri", VPlaneTrihedron, /* [vplanetri] */ R"(
6886 Create a plane from a trihedron selection.
6887 If no arguments are set, the default plane is created.
6888 )" /* [vplanetri] */);
6890 addCmd ("vsize", VSize, /* [vsize] */ R"(
6891 vsize [name(Default=Current)] [size(Default=100)]
6892 Changes the size of a named or selected trihedron.
6893 If the name is not defined: it affects the selected trihedrons otherwise nothing is done.
6894 If the value is not defined: it is set to 100 by default.
6897 addCmd ("vaxis", VAxisBuilder, /* [vaxis] */ R"(
6898 vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
6899 Creates an axis. If the values are not defined,
6900 an axis is created by interactive selection of two vertices or one edge.
6903 addCmd ("vaxispara", VAxisBuilder, /* [vaxispara] */ R"(
6905 Creates an axis by interactive selection of an edge and a vertex.
6906 )" /* [vaxispara] */);
6908 addCmd ("vaxisortho", VAxisBuilder, /* [vaxisortho] */ R"(
6910 Creates an axis by interactive selection of an edge and a vertex.
6911 The axis will be orthogonal to the selected edge.
6912 )" /* [vaxisortho] */);
6914 addCmd ("vpoint", VPointBuilder, /* [vpoint] */ R"(
6915 vpoint name [X Y [Z]] [-2d] [-nosel]
6916 Creates a point from coordinates.
6917 If the values are not defined, a point is created from selected vertex or edge (center).
6918 -2d defines on-screen 2D point from top-left window corner;
6919 -nosel creates non-selectable presentation.
6922 addCmd ("vplane", VPlaneBuilder, /* [vplane] */ R"(
6923 vplane PlaneName [AxisName/PlaneName/PointName]
6924 [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]
6925 Creates a plane from named or interactively selected entities. TypeOfSensitivity:
6930 addCmd ("vchangeplane", VChangePlane, /* [vchangeplane] */ R"(
6931 vchangeplane plane_name
6932 [x=center_x y=center_y z=center_z]
6933 [dx=dir_x dy=dir_y dz=dir_z]
6934 [sx=size_x sy=size_y]
6937 Changes parameters of the plane:
6940 - sx sy - plane sizes
6941 - noupdate - do not update/redisplay the plane in context
6942 Please enter coordinates in format "param=value" in arbitrary order.
6943 )" /* [vchangeplane] */);
6945 addCmd ("vplanepara", VPlaneBuilder, /* [vplanepara] */ R"(
6946 vplanepara PlaneName
6947 Creates a plane from interactively selected vertex and face.
6948 )" /* [vplanepara] */);
6950 addCmd ("vplaneortho", VPlaneBuilder, /* [vplaneortho] */ R"(
6951 vplaneortho PlaneName
6952 Creates a plane from interactive selected face and coplanar edge.
6953 )" /* [vplaneortho] */);
6955 addCmd ("vline", VLineBuilder, /* [vline] */ R"(
6956 vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb]
6957 Creates a line from coordinates, named or interactively selected vertices.
6960 addCmd ("vcircle", VCircleBuilder, /* [vcircle] */ R"(
6961 vcircle CircleName [PointName PointName PointName IsFilled] [UStart UEnd]
6962 [PlaneName PointName Radius IsFilled] [UStart UEnd]
6963 Creates a circle from named or interactively selected entities.
6964 Parameter IsFilled is defined as 0 or 1.
6965 )" /* [vcircle] */);
6967 addCmd ("vdrawtext", VDrawText, /* [vdrawtext] */ R"(
6969 [-pos X Y Z]={0 0 0}
6970 [-color {R G B|name}]=yellow
6971 [-halign {left|center|right}]=left
6972 [-valign {top|center|bottom|topfirstline}}]=bottom
6976 [-wrapping width]=40
6977 [-wordwrapping {0|1}]=1
6978 [-aspect {regular|bold|italic|boldItalic}]=regular
6980 [-2d] [-perspos {X Y Z}]={0 0 0}
6981 [-disptype {blend|decal|shadow|subtitle|dimension|normal}}=normal
6982 [-subcolor {R G B|name}]=white
6984 [-plane NormX NormY NormZ DirX DirY DirZ]
6985 [-flipping] [-ownanchor {0|1}]=1
6986 Display text label at specified position.
6987 Within -perspos, X and Y define the coordinate origin in 2d space relative to the view window.
6988 Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc...
6989 Z coordinate defines the gap from border of view window (except center position).
6990 )" /* [vdrawtext] */);
6992 addCmd ("vdrawsphere", VDrawSphere, /* [vdrawsphere] */ R"(
6993 vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]
6994 )" /* [vdrawsphere] */);
6996 addCmd ("vlocation", VSetLocation, /* [vlocation] */ R"(
6998 [-reset] [-copyFrom otherName]
6999 [-translate X Y [Z]] [-rotate x y z dx dy dz angle] [-scale [X Y Z] scale]
7000 [-pretranslate X Y [Z]] [-prerotate x y z dx dy dz angle] [-prescale [X Y Z] scale]
7001 [-mirror x y z dx dy dz] [-premirror x y z dx dy dz]
7002 [-setLocation X Y [Z]] [-setRotation QX QY QZ QW] [-setScale [X Y Z] scale]
7003 Object local transformation management:
7004 -reset resets transformation to identity
7005 -translate applies translation vector
7006 -rotate applies rotation around axis
7007 -scale applies scale factor with optional anchor
7008 -mirror applies mirror transformation
7009 -pretranslate pre-multiplies translation vector
7010 -prerotate pre-multiplies rotation around axis
7011 -prescale pre-multiplies scale transformation
7012 -premirror pre-multiplies mirror transformation
7013 -setLocation overrides translation part
7014 -setRotation overrides rotation part with specified quaternion
7015 -setScale overrides scale factor
7016 )" /* [vlocation] */);
7018 addCmd ("vsetlocation", VSetLocation, /* [vsetlocation] */ R"(
7020 )" /* [vsetlocation] */);
7022 addCmd ("vchild", VChild, /* [vchild] */ R"(
7023 vchild parent [-add] [-remove] [-ignoreParentTrsf {0|1}] child1 [child2] [...]
7024 Command for testing low-level presentation connections.
7025 vconnect command should be used instead.
7028 addCmd ("vparent", VParent, /* [vparent] */ R"(
7029 vparent parent [-ignoreVisu]
7030 Command for testing object properties as parent in the hierarchy.
7031 -ignoreVisu do not propagate the visual state (display/erase/color) to children objects
7032 )" /* [vparent] */);
7034 addCmd ("vcomputehlr", VComputeHLR, /* [vcomputehlr] */ R"(
7035 vcomputehlr shapeInput hlrResult [-algoType {algo|polyAlgo}=polyAlgo]
7036 [eyeX eyeY eyeZ dirX dirY dirZ upX upY upZ]
7037 [-showTangentEdges {on|off}=off] [-nbIsolines N=0] [-showHiddenEdges {on|off}=off]
7039 shapeInput - name of the initial shape
7040 hlrResult - result HLR object from initial shape
7041 eye, dir are eye position and look direction
7042 up is the look up direction vector
7043 -algoType HLR algorithm to use
7044 -showTangentEdges include tangent edges
7045 -nbIsolines include isolines
7046 -showHiddenEdges include hidden edges
7047 Use vtop to see projected HLR shape.
7048 )" /* [vcomputehlr] */);
7050 addCmd ("vdrawparray", VDrawPArray, /* [vdrawparray] */ R"(
7051 vdrawparray name TypeOfArray={points|segments|polylines|triangles
7052 |trianglefans|trianglestrips|quads|quadstrips|polygons}
7053 [-deinterleaved|-mutable]
7054 [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [texel={'t' tx ty}]]
7055 [bound= {'b' nbVertices [bound_color={'c' r g b}]]
7056 [edge= {'e' vertexId]
7057 [-shape shapeName] [-patch]
7058 Commands create an Interactive Object for specified Primitive Array definition
7059 with the main purpose is covering various combinations by tests.
7060 )" /* [vdrawparray] */);
7062 addCmd ("vconnect", VConnect, /* [vconnect] */ R"(
7063 vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
7064 Creates and displays AIS_ConnectedInteractive object from input object and location.
7065 )" /* [vconnect] */);
7067 addCmd ("vconnectto", VConnectTo, /* [vconnectto] */ R"(
7068 vconnectto instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]
7069 Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo).
7070 -nodisplay - only creates interactive object, but not displays it.
7071 )" /* [vconnectto] */);
7073 addCmd ("vdisconnect", VDisconnect, /* [vdisconnect] */ R"(
7074 vdisconnect assembly_name {object_name|object_number|'all'}
7075 Disconnects all objects from assembly or disconnects object by name or number.
7076 Use vlistconnected to enumerate assembly children.
7077 )" /* [vdisconnect] */);
7079 addCmd ("vaddconnected", VAddConnected, /* [vaddconnected] */ R"(
7080 vaddconnected assembly_name object_name
7081 Adds object to assembly.
7082 )" /* [vaddconnected] */);
7084 addCmd ("vlistconnected", VListConnected, /* [vlistconnected] */ R"(
7085 vlistconnected assembly_name
7086 Lists objects in assembly.
7087 )" /* [vlistconnected] */);
7089 addCmd ("vselmode", VSetSelectionMode, /* [vselmode] */ R"(
7090 vselmode [object] selectionMode {on|off}
7091 [{-add|-set|-globalOrLocal}=-globalOrLocal]
7092 Switches selection mode for the specified object or for all objects in context.
7093 Selection mode is either an integer number specific to Interactive Object,
7094 or sub-shape type in case of AIS_Shape:
7095 Shape, Vertex, Edge, Wire, Face, Shell, Solid, CompSolid, Compound
7096 The integer mode 0 (Shape in case of AIS_Shape) is reserved for selecting object as whole.
7098 -add already activated selection modes will be left activated
7099 -set already activated selection modes will be deactivated
7100 -globalOrLocal (default) if new mode is Global selection mode,
7101 then active local selection modes will be deactivated
7102 and the samthen active local selection modes will be deactivated
7103 )" /* [vselmode] */);
7105 addCmd ("vselnext", VSelectionNext, /* [vselnext] */ R"(
7106 vselnext : hilight next detected
7107 )" /* [vselnext] */);
7109 addCmd ("vselprev", VSelectionPrevious, /* [vselprev] */ R"(
7110 vselnext : hilight previous detected
7111 )" /* [vselprev] */);
7113 addCmd ("vtriangle", VTriangle, /* [vtriangle] */ R"(
7114 vtriangle Name PointName PointName PointName
7115 Creates and displays a filled triangle from named points.
7116 )" /* [vtriangle] */);
7118 addCmd ("vsegment", VTriangle, /* [vsegment] */ R"(
7119 vsegment Name PointName PointName
7120 Creates and displays a segment from named points.
7121 )" /* [vsegment] */);
7123 addCmd ("vtorus", VTorus, /* [vtorus] */ R"(
7124 vtorus name [R1 R2 [Angle1=0 Angle2=360] [Angle=360]]
7125 [-radius R1] [-pipeRadius R2]
7126 [-pipeAngle Angle=360] [-segmentAngle1 Angle1=0 -segmentAngle2 Angle2=360]
7127 [-nbSlices Number=100] [-nbStacks Number=100] [-noupdate]
7128 Creates and displays a torus or torus segment.
7129 Parameters of the torus:
7130 - R1 distance from the center of the pipe to the center of the torus
7131 - R2 radius of the pipe
7132 - Angle1 first angle to create a torus ring segment
7133 - Angle2 second angle to create a torus ring segment
7134 - Angle angle to create a torus pipe segment
7137 addCmd ("vcylinder", VCylinder, /* [vcylinder] */ R"(
7138 vcylinder name [R1 R2 Height] [-height H] [-radius R] [-bottomRadius R1 -topRadius R2]
7139 [-nbSlices Number=100] [-noupdate]
7140 Creates and displays a cylinder.
7141 Parameters of the cylinder:
7142 - R1 cylinder bottom radius
7143 - R2 cylinder top radius
7144 - Height cylinder height
7145 )" /* [vcylinder] */);
7147 addCmd ("vsphere", VSphere, /* [vsphere] */ R"(
7148 vsphere name [-radius] R
7149 [-nbSlices Number=100] [-nbStacks Number=100] [-noupdate]
7150 Creates and displays a sphere.
7151 )" /* [vsphere] */);
7153 addCmd ("vobjzlayer", VObjZLayer, /* [vobjzlayer] */ R"(
7154 vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object
7155 )" /* [vobjzlayer] */);
7157 addCmd ("vpolygonoffset", VPolygonOffset, /* [vpolygonoffset] */ R"(
7158 vpolygonoffset [object [mode factor units]]
7159 Sets/gets polygon offset parameters for an object; without arguments prints the default values
7160 )" /* [vpolygonoffset] */);
7162 addCmd ("vmarkerstest", VMarkersTest, /* [vmarkerstest] */ R"(
7163 vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]
7164 )" /* [vmarkerstest] */);
7166 addCmd ("text2brep", TextToBRep, /* [text2brep] */ R"(
7167 text2brep name text"
7169 [-halign {left|center|right}=left]"
7170 [-valign {top|center|bottom|topfirstline}=bottom}]"
7171 [-height height=16]"
7172 [-aspect {regular|bold|italic|boldItalic}=regular]"
7173 [-font font=Courier] [-strict {strict|aliases|any}=any]"
7174 [-composite {on|off}=off]"
7175 [-plane NormX NormY NormZ DirX DirY DirZ]",
7176 )" /* [text2brep] */);
7178 addCmd ("vfont", VFont, /* [vfont] */ R"(
7179 vfont [-add pathToFont [fontName] [regular,bold,italic,boldItalic=undefined] [singleStroke]]
7180 [-strict {any|aliases|strict}] [-find fontName [regular,bold,italic,boldItalic=undefined]]
7182 [-findAll fontNameMask] [-findInfo fontName]
7183 [-unicodeFallback {on|off}]
7184 [-clear] [-init] [-list] [-names]
7185 [-aliases [aliasName]] [-addAlias Alias FontName] [-removeAlias Alias FontName]
7186 [-clearAlias Alias] [-clearAliases]
7187 Work with font registry - register font, list available fonts, find font.
7188 -findAll is same as -find, but can print more than one font when mask is passed.
7189 -findInfo is same as -find, but prints complete font information instead of family name.
7192 addCmd ("vvertexmode", VVertexMode, /* [vvertexmode] */ R"(
7193 vvertexmode [name | -set {isolated|all|inherited} [name1 name2 ...]]
7194 Sets the vertex draw mode for the specified object(s)
7195 or sets default vertex draw mode and updates the mode for all displayed objects.
7196 Prints the default vertex draw mode without -set parameter.
7197 )" /* [vvertexmode] */);
7199 addCmd ("vpointcloud", VPointCloud, /* [vpointcloud] */ R"(
7200 vpointcloud name shape [-randColor {0|1}]=0 [-normals {0|1}]=1 [-uv {0|1}]=0
7201 [-distance Value]=0.0 [-density Value] [-tolerance Value]
7202 Create an interactive object for arbitrary set of points from triangulated shape.
7204 vpointcloud name {-surface|-volume} x y z r npts
7205 [-randColor] [-normals] [-uv]
7206 Create arbitrary set of points (npts) randomly distributed
7207 on spheric surface or within spheric volume (x y z r).
7210 -normals generate or not normal per point
7211 -uv generate UV (texel) coordinates per point
7212 -randColor generate random color per point
7213 -distance distance from shape into the range [0, Value];
7214 -density density of points to generate randomly on surface;
7215 -tolerance cloud generator's tolerance; default value is Precision::Confusion();
7217 )" /* [vpointcloud] */);
7219 addCmd ("vpriority", VPriority, /* [vpriority] */ R"(
7220 vpriority [-noupdate|-update] name [value]
7221 Prints or sets the display priority for an object.
7222 )" /* [vpriority] */);
7224 addCmd ("vnormals", VNormals, /* [vnormals] */ R"(
7225 vnormals Shape [{on|off}=on] [-length {10}] [-nbAlongU {1}] [-nbAlongV {1}] [-nbAlong {1}]
7226 [-useMesh] [-oriented {0}1}=0]
7227 Displays/Hides normals calculated on shape geometry or retrieved from triangulation
7228 )" /* [vnormals] */);