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 <TColStd_MapOfInteger.hxx>
44 #include <AIS_MapOfInteractive.hxx>
45 #include <ViewerTest_AutoUpdater.hxx>
46 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
47 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
48 #include <ViewerTest_EventManager.hxx>
50 #include <TopoDS_Solid.hxx>
51 #include <BRepTools.hxx>
52 #include <BRep_Builder.hxx>
53 #include <TopAbs_ShapeEnum.hxx>
56 #include <BRep_Tool.hxx>
57 #include <TopExp_Explorer.hxx>
59 #include <BRepAdaptor_Curve.hxx>
60 #include <BRepAdaptor_Surface.hxx>
64 #include <TopoDS_Vertex.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Face.hxx>
68 #include <Draw_Window.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
70 #include <AIS_ListOfInteractive.hxx>
71 #include <AIS_ColoredShape.hxx>
72 #include <AIS_DisplayMode.hxx>
73 #include <AIS_Shape.hxx>
75 #include <AIS_InteractiveContext.hxx>
76 #include <Geom_Plane.hxx>
78 #include <TCollection_ExtendedString.hxx>
79 #include <TCollection_HAsciiString.hxx>
80 #include <GC_MakePlane.hxx>
81 #include <gp_Circ.hxx>
82 #include <AIS_Axis.hxx>
83 #include <Geom_Axis2Placement.hxx>
84 #include <Geom_Axis1Placement.hxx>
85 #include <AIS_Trihedron.hxx>
86 #include <AIS_Axis.hxx>
87 #include <gp_Trsf.hxx>
88 #include <gp_Quaternion.hxx>
89 #include <TopLoc_Location.hxx>
91 #include <HLRAlgo_Projector.hxx>
92 #include <HLRBRep_Algo.hxx>
93 #include <HLRBRep_PolyAlgo.hxx>
94 #include <HLRBRep_PolyHLRToShape.hxx>
95 #include <HLRBRep_HLRToShape.hxx>
96 #include <Aspect_Window.hxx>
98 #include <Graphic3d_ArrayOfPoints.hxx>
99 #include <Graphic3d_ArrayOfSegments.hxx>
100 #include <Graphic3d_ArrayOfPolylines.hxx>
101 #include <Graphic3d_ArrayOfTriangles.hxx>
102 #include <Graphic3d_ArrayOfTriangleFans.hxx>
103 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
104 #include <Graphic3d_ArrayOfQuadrangles.hxx>
105 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
106 #include <Graphic3d_ArrayOfPolygons.hxx>
107 #include <Graphic3d_AttribBuffer.hxx>
108 #include <Graphic3d_AspectMarker3d.hxx>
109 #include <Graphic3d_Group.hxx>
110 #include <Standard_Real.hxx>
112 #include <AIS_Circle.hxx>
113 #include <BRepBuilderAPI_MakeEdge.hxx>
114 #include <BRepBuilderAPI_MakeFace.hxx>
115 #include <BRepBuilderAPI_MakeWire.hxx>
116 #include <Geom_Circle.hxx>
117 #include <GC_MakeCircle.hxx>
118 #include <Select3D_SensitiveCircle.hxx>
119 #include <SelectMgr_EntityOwner.hxx>
120 #include <SelectMgr_Selection.hxx>
121 #include <StdFail_NotDone.hxx>
122 #include <StdPrs_ShadedShape.hxx>
123 #include <TopoDS_Wire.hxx>
125 #include <AIS_MultipleConnectedInteractive.hxx>
126 #include <AIS_ConnectedInteractive.hxx>
127 #include <AIS_TextLabel.hxx>
128 #include <TopLoc_Location.hxx>
129 #include <TColStd_ListOfInteger.hxx>
130 #include <TColStd_ListIteratorOfListOfInteger.hxx>
132 #include <Select3D_SensitiveSegment.hxx>
133 #include <Select3D_SensitivePrimitiveArray.hxx>
134 #include <Select3D_SensitivePoint.hxx>
135 #include <BRepAdaptor_Curve.hxx>
136 #include <StdPrs_Curve.hxx>
138 #include <BRepExtrema_ExtPC.hxx>
139 #include <BRepExtrema_ExtPF.hxx>
141 #include <Prs3d_Arrow.hxx>
142 #include <Prs3d_ArrowAspect.hxx>
143 #include <Prs3d_DatumAttribute.hxx>
144 #include <Prs3d_DatumAspect.hxx>
145 #include <Prs3d_Drawer.hxx>
146 #include <Prs3d_VertexDrawMode.hxx>
147 #include <Prs3d_LineAspect.hxx>
148 #include <Prs3d_PointAspect.hxx>
149 #include <Prs3d_Presentation.hxx>
150 #include <Prs3d_TextAspect.hxx>
152 #include <Image_AlienPixMap.hxx>
153 #include <TColStd_HArray1OfAsciiString.hxx>
154 #include <TColStd_HSequenceOfAsciiString.hxx>
156 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
157 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
158 const Handle(AIS_InteractiveObject)& theAISObj,
159 Standard_Boolean theReplaceIfExists = Standard_True);
160 extern Handle(AIS_InteractiveContext)& TheAISContext();
164 static bool convertToColor (const Handle(TColStd_HSequenceOfAsciiString)& theColorValues,
165 Quantity_Color& theColor)
167 const char* anArgs[3] =
169 theColorValues->Size() >= 1 ? theColorValues->Value (1).ToCString() : "",
170 theColorValues->Size() >= 2 ? theColorValues->Value (2).ToCString() : "",
171 theColorValues->Size() >= 3 ? theColorValues->Value (3).ToCString() : ""
173 return Draw::ParseColor (theColorValues->Size(), anArgs, theColor) != 0;
176 static bool convertToDatumPart (const TCollection_AsciiString& theValue,
177 Prs3d_DatumParts& theDatumPart)
179 TCollection_AsciiString aValue = theValue;
181 if (aValue == "origin") theDatumPart = Prs3d_DP_Origin;
182 else if (aValue == "xaxis") theDatumPart = Prs3d_DP_XAxis;
183 else if (aValue == "yaxis") theDatumPart = Prs3d_DP_YAxis;
184 else if (aValue == "zaxis") theDatumPart = Prs3d_DP_ZAxis;
185 else if (aValue == "xarrow") theDatumPart = Prs3d_DP_XArrow;
186 else if (aValue == "yarrow") theDatumPart = Prs3d_DP_YArrow;
187 else if (aValue == "zarrow") theDatumPart = Prs3d_DP_ZArrow;
188 else if (aValue == "xoyaxis") theDatumPart = Prs3d_DP_XOYAxis;
189 else if (aValue == "yozaxis") theDatumPart = Prs3d_DP_YOZAxis;
190 else if (aValue == "xozaxis") theDatumPart = Prs3d_DP_XOZAxis;
191 else if (aValue == "whole") theDatumPart = Prs3d_DP_None;
199 static void convertToDatumParts (const TCollection_AsciiString& theValue,
200 NCollection_List<Prs3d_DatumParts>& theParts)
202 TCollection_AsciiString aValue = theValue;
203 const Standard_Integer aSplitPos = theValue.Search ("|");
204 Prs3d_DatumParts aPart = Prs3d_DP_None;
207 convertToDatumParts (theValue.SubString (aSplitPos + 1, theValue.Length()), theParts);
208 if (aSplitPos == 1) // first symbol
212 aValue = theValue.SubString (1, aSplitPos - 1);
214 if (convertToDatumPart (aValue, aPart))
216 theParts.Append (aPart);
220 static bool convertToDatumAttribute (const TCollection_AsciiString& theValue,
221 Prs3d_DatumAttribute& theAttribute)
223 TCollection_AsciiString aValue = theValue;
225 if (aValue == "xaxislength") theAttribute = Prs3d_DA_XAxisLength;
226 else if (aValue == "yaxislength") theAttribute = Prs3d_DA_YAxisLength;
227 else if (aValue == "zaxislength") theAttribute = Prs3d_DA_ZAxisLength;
228 else if (aValue == "tuberadiuspercent") theAttribute = Prs3d_DP_ShadingTubeRadiusPercent;
229 else if (aValue == "coneradiuspercent") theAttribute = Prs3d_DP_ShadingConeRadiusPercent;
230 else if (aValue == "conelengthpercent") theAttribute = Prs3d_DP_ShadingConeLengthPercent;
231 else if (aValue == "originradiuspercent") theAttribute = Prs3d_DP_ShadingOriginRadiusPercent;
232 else if (aValue == "shadingnumberoffacettes") theAttribute = Prs3d_DP_ShadingNumberOfFacettes;
238 static void convertToDatumAttributes (const TCollection_AsciiString& theValue,
239 NCollection_List<Prs3d_DatumAttribute>& theAttributes)
241 TCollection_AsciiString aValue = theValue;
242 const Standard_Integer aSplitPos = theValue.Search ("|");
243 Prs3d_DatumAttribute anAttribute = Prs3d_DA_XAxisLength;
246 convertToDatumAttributes (theValue.SubString (aSplitPos + 1, theValue.Length()), theAttributes);
247 if (aSplitPos == 1) // first symbol
251 aValue = theValue.SubString (1, aSplitPos - 1);
253 if (convertToDatumAttribute (aValue, anAttribute))
255 theAttributes.Append (anAttribute);
259 static bool convertToDatumAxes (const TCollection_AsciiString& theValue,
260 Prs3d_DatumAxes& theDatumAxes)
262 TCollection_AsciiString aValue = theValue;
264 if (aValue == "x") theDatumAxes = Prs3d_DA_XAxis;
265 else if (aValue == "y") theDatumAxes = Prs3d_DA_YAxis;
266 else if (aValue == "z") theDatumAxes = Prs3d_DA_ZAxis;
267 else if (aValue == "xy") theDatumAxes = Prs3d_DA_XYAxis;
268 else if (aValue == "zy") theDatumAxes = Prs3d_DA_YZAxis;
269 else if (aValue == "xz") theDatumAxes = Prs3d_DA_XZAxis;
270 else if (aValue == "xyz") theDatumAxes = Prs3d_DA_XYZAxis;
278 static Standard_Boolean setTrihedronParams (Standard_Integer theArgsNb,
279 const char** theArgVec,
280 Handle(AIS_Trihedron) theTrihedron)
282 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
283 TCollection_AsciiString aParseKey;
284 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
286 TCollection_AsciiString anArg (theArgVec [anArgIt]);
287 if (anArg.Value (1) == '-'
288 && !anArg.IsRealValue())
291 aParseKey.Remove (1);
292 aParseKey.LowerCase();
293 std::string aKey = aParseKey.ToCString();
294 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString());
298 if (aParseKey.IsEmpty())
303 aMapOfArgs (aParseKey)->Append (anArg);
307 if ((aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis"))
308 || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")))
310 Message::SendFail ("Syntax error: -xaxis and -zaxis parameters are to set together");
311 return Standard_False;
314 Handle(TColStd_HSequenceOfAsciiString) aValues;
315 Handle(Geom_Axis2Placement) aComponent = theTrihedron->Component();
316 if (aMapOfArgs.Find ("origin", aValues))
318 aComponent->SetLocation (gp_Pnt (aValues->Value (1).RealValue(),
319 aValues->Value (2).RealValue(),
320 aValues->Value (3).RealValue()));
322 Handle(TColStd_HSequenceOfAsciiString) aXValues, aZValues;
323 if (aMapOfArgs.Find ("xaxis", aXValues) && aMapOfArgs.Find ("zaxis", aZValues))
325 gp_Dir aXDir (aXValues->Value (1).RealValue(),
326 aXValues->Value (2).RealValue(),
327 aXValues->Value (3).RealValue());
329 gp_Dir aZDir (aZValues->Value (1).RealValue(),
330 aZValues->Value (2).RealValue(),
331 aZValues->Value (3).RealValue());
333 if (!aZDir.IsNormal (aXDir, M_PI / 180.0))
335 Message::SendFail ("Syntax error - parameters 'xaxis' and 'zaxis' are not applied as VectorX is not normal to VectorZ");
336 return Standard_False;
339 aComponent->SetAx2 (gp_Ax2 (aComponent->Location(), aZDir, aXDir));
342 if (aMapOfArgs.Find ("dispmode", aValues))
344 TCollection_AsciiString aValue (aValues->Value (1));
345 bool isWireframe = true;
346 if (aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
348 theTrihedron->SetDatumDisplayMode (isWireframe ? Prs3d_DM_WireFrame
352 if (aMapOfArgs.Find ("hidelabels", aValues))
354 Standard_Boolean toHideLabels = Standard_True;
355 if (aValues->Size() == 1)
357 Draw::ParseOnOff (aValues->First().ToCString(), toHideLabels);
359 else if (aValues->Size() != 0)
361 Message::SendFail ("Syntax error: -hidelabels expects parameter 'on' or 'off' after");
362 return Standard_False;
365 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
367 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
369 theTrihedron->Attributes()->DatumAspect()->SetDrawLabels (!toHideLabels);
372 if (aMapOfArgs.Find ("hidearrows", aValues))
374 Standard_Boolean toHideArrows = Standard_True;
375 if (aValues->Size() == 1)
377 Draw::ParseOnOff (aValues->First().ToCString(), toHideArrows);
379 else if (aValues->Size() != 0)
381 Message::SendFail ("Syntax error: -hidearrows expects parameter 'on' or 'off' after");
382 return Standard_False;
385 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
387 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
389 theTrihedron->Attributes()->DatumAspect()->SetDrawArrows (!toHideArrows);
392 if (aMapOfArgs.Find ("color", aValues))
394 NCollection_List<Prs3d_DatumParts> aParts;
395 if (aValues->Size() < 2)
397 Message::SendFail ("Syntax error: -color wrong parameters");
398 return Standard_False;
401 convertToDatumParts (aValues->Value(1), aParts);
402 aValues->Remove (1); // datum part is processed
403 Quantity_Color aColor;
404 if (!convertToColor (aValues, aColor))
406 Message::SendFail ("Syntax error: -color wrong parameters");
407 return Standard_False;
410 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (aParts); anIterator.More(); anIterator.Next())
412 Prs3d_DatumParts aDatumPart = anIterator.Value();
413 if (aDatumPart == Prs3d_DP_None)
415 theTrihedron->SetColor (aColor);
419 theTrihedron->SetDatumPartColor (aDatumPart, aColor);
424 if (aMapOfArgs.Find ("textcolor", aValues))
426 Quantity_Color aColor;
427 if (!convertToColor (aValues, aColor))
429 Message::SendFail ("Syntax error: -textcolor wrong parameters");
430 return Standard_False;
432 theTrihedron->SetTextColor (aColor);
435 if (aMapOfArgs.Find ("arrowcolor", aValues))
437 Quantity_Color aColor;
438 if (!convertToColor (aValues, aColor))
440 Message::SendFail ("Syntax error: -arrowcolor wrong parameters");
441 return Standard_False;
443 theTrihedron->SetArrowColor (aColor);
446 if (aMapOfArgs.Find ("attribute", aValues))
448 NCollection_List<Prs3d_DatumAttribute> anAttributes;
449 if (aValues->Size() != 2)
451 Message::SendFail ("Syntax error: -attribute wrong parameters");
452 return Standard_False;
455 convertToDatumAttributes (aValues->Value (1), anAttributes);
456 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
457 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
458 for (NCollection_List<Prs3d_DatumAttribute>::Iterator anIterator (anAttributes); anIterator.More(); anIterator.Next())
460 theTrihedron->Attributes()->DatumAspect()->SetAttribute (anIterator.Value(), aValues->Value (2).RealValue());
464 if (aMapOfArgs.Find ("priority", aValues))
466 Prs3d_DatumParts aDatumPart;
467 if (aValues->Size() < 2
468 || !convertToDatumPart (aValues->Value (1), aDatumPart))
470 Message::SendFail ("Syntax error: -priority wrong parameters");
471 return Standard_False;
473 theTrihedron->SetSelectionPriority (aDatumPart, aValues->Value (2).IntegerValue());
476 if (aMapOfArgs.Find ("labels", aValues)
477 || aMapOfArgs.Find ("label", aValues))
479 Prs3d_DatumParts aDatumPart = Prs3d_DP_None;
480 if (aValues->Size() >= 2
481 && convertToDatumPart(aValues->Value(1), aDatumPart)
482 && aDatumPart >= Prs3d_DP_XAxis
483 && aDatumPart <= Prs3d_DP_ZAxis) // labels are set to axes only
485 theTrihedron->SetLabel (aDatumPart, aValues->Value (2));
489 Message::SendFail ("Syntax error: -labels wrong parameters");
490 return Standard_False;
494 if (aMapOfArgs.Find ("drawaxes", aValues))
496 Prs3d_DatumAxes aDatumAxes = Prs3d_DA_XAxis;
497 if (aValues->Size() < 1
498 || !convertToDatumAxes (aValues->Value (1), aDatumAxes))
500 Message::SendFail ("Syntax error: -drawaxes wrong parameters");
501 return Standard_False;
503 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
504 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
505 theTrihedron->Attributes()->DatumAspect()->SetDrawDatumAxes (aDatumAxes);
507 return Standard_True;
510 //! Auxiliary function to parse font aspect style argument
511 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
512 Font_FontAspect& theAspect)
514 if (theArg == "regular"
515 || *theArg.ToCString() == 'r')
517 theAspect = Font_FA_Regular;
518 return Standard_True;
520 else if (theArg == "bolditalic"
521 || theArg == "bold-italic"
522 || theArg == "italic-bold"
523 || theArg == "italicbold")
525 theAspect = Font_FA_BoldItalic;
526 return Standard_True;
528 else if (theArg == "bold"
529 || *theArg.ToCString() == 'b')
531 theAspect = Font_FA_Bold;
532 return Standard_True;
534 else if (theArg == "italic"
535 || *theArg.ToCString() == 'i')
537 theAspect = Font_FA_Italic;
538 return Standard_True;
540 return Standard_False;
543 //! Auxiliary function to parse font strict level argument
544 static Standard_Integer parseFontStrictLevel (const Standard_Integer theArgNb,
545 const char** theArgVec,
546 Font_StrictLevel& theLevel)
550 TCollection_AsciiString anArg (theArgVec[0]);
554 theLevel = Font_StrictLevel_Any;
557 else if (anArg == "aliases")
559 theLevel = Font_StrictLevel_Aliases;
562 else if (anArg == "strict")
564 theLevel = Font_StrictLevel_Strict;
568 theLevel = Font_StrictLevel_Strict;
573 //==============================================================================
574 //function : Vtrihedron 2d
575 //purpose : Create a plane with a 2D trihedron from a faceselection
576 //Draw arg : vtri2d name
577 //==============================================================================
578 static int VTrihedron2D (Draw_Interpretor& /*theDI*/,
579 Standard_Integer theArgsNum,
580 const char** theArgVec)
584 Message::SendFail() << "Syntax error: wrong number of arguments.";
588 TopTools_ListOfShape aShapes;
589 ViewerTest::GetSelectedShapes (aShapes);
591 if (aShapes.Extent() != 1)
593 Message::SendFail ("Error: wrong number of selected shapes.");
597 const TopoDS_Shape& aShape = aShapes.First();
599 TopoDS_Face aFace = TopoDS::Face (aShape);
600 TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE);
601 TopoDS_Edge anEdge0 = TopoDS::Edge (aFaceExp.Current());
607 TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() );
608 BRepAdaptor_Curve aCurve0 (anEdge0);
609 BRepAdaptor_Curve aCurve1 (anEdge1);
610 A = aCurve1.Value (0.1);
611 B = aCurve1.Value (0.9);
612 C = aCurve0.Value (0.5);
616 BRepAdaptor_Curve aCurve0 (anEdge0);
617 A = aCurve0.Value (0.1);
618 B = aCurve0.Value (0.9);
619 C = aCurve0.Value (0.5);
622 GC_MakePlane aMkPlane (A,B,C);
624 Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value());
625 TCollection_AsciiString aName (theArgVec[1]);
627 VDisplayAISObject (aName, anAISPlaneTri);
632 //=======================================================================
633 //function : VTrihedron
635 //=======================================================================
636 static int VTrihedron (Draw_Interpretor& ,
637 Standard_Integer theArgsNb,
638 const char** theArgVec)
642 Message::SendFail ("Syntax error: the wrong number of input parameters");
646 TCollection_AsciiString aName (theArgVec[1]);
647 gp_Pln aWorkingPlane;
648 Standard_Boolean toUpdate = Standard_True;
650 NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
651 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
653 Handle(AIS_Trihedron) aTrihedron;
654 Handle(AIS_InteractiveObject) anObject;
655 if (GetMapOfAIS().Find2 (aName, anObject))
657 aTrihedron = Handle(AIS_Trihedron)::DownCast (anObject);
658 if (aTrihedron.IsNull())
660 Message::SendFail ("Syntax error: no trihedron with this name");
666 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (gp_Pnt (0.0, 0.0, 0.0),
668 aTrihedron = new AIS_Trihedron (aPlacement);
671 if (!setTrihedronParams (theArgsNb, theArgVec, aTrihedron))
676 // Redisplay a dimension after parameter changing.
677 if (ViewerTest::GetAISContext()->IsDisplayed (aTrihedron))
679 ViewerTest::GetAISContext()->Redisplay (aTrihedron, toUpdate);
683 VDisplayAISObject (theArgVec[1], aTrihedron);
689 //==============================================================================
692 //purpose : Change the size of a named or selected trihedron
693 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
694 // if no value, the value is set at 100 by default
695 //Draw arg : vsize [name] [size]
696 //==============================================================================
698 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
701 // Declaration de booleens
702 Standard_Boolean ThereIsName;
703 Standard_Boolean ThereIsCurrent;
705 Standard_Boolean hascol;
707 Quantity_Color col = Quantity_NOC_BLACK;
709 // Verification des arguments
710 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;}
712 // Verification du nombre d'arguments
713 if (argc==1) {ThereIsName=Standard_False;value=100;}
714 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
715 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
717 // On set le booleen ThereIsCurrent
718 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
719 else {ThereIsCurrent=Standard_False;}
723 //===============================================================
724 // Il n'y a pas de nom mais des objets selectionnes
725 //===============================================================
726 if (!ThereIsName && ThereIsCurrent)
729 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
732 while ( it.More() ) {
734 Handle(AIS_InteractiveObject) aShape = it.Key1();
736 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
739 // On verifie que l'AIS InteraciveObject selectionne est bien
741 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
743 if (aShape->HasColor())
745 hascol = Standard_True;
747 // On recupere la couleur de aShape
752 hascol = Standard_False;
755 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
756 // pour lui appliquer la methode SetSize()
757 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
759 // C'est bien un triedre,on chage sa valeur!
760 aTrihedron->SetSize(value);
762 // On donne la couleur au Trihedron
763 if(hascol) aTrihedron->SetColor(col);
764 else aTrihedron->UnsetColor();
767 // The trihedron hasn't be errased from the map
768 // so you just have to redisplay it
769 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
778 TheAISContext() ->UpdateCurrentViewer();
781 //===============================================================
782 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
783 //===============================================================
787 //===============================================================
788 // Il y a un nom de triedre passe en argument
789 //===============================================================
791 TCollection_AsciiString name=argv[1];
793 // on verifie que ce nom correspond bien a une shape
794 Handle(AIS_InteractiveObject) aShape;
795 if (GetMapOfAIS().Find2(name, aShape))
797 // On verifie que l'AIS InteraciveObject est bien
799 if (!aShape.IsNull() &&
800 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
802 if (aShape->HasColor())
804 hascol=Standard_True;
806 // On recupere la couleur de aShape
811 hascol = Standard_False;
814 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
815 // pour lui appliquer la methode SetSize()
816 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
818 // C'est bien un triedre,on chage sa valeur
819 aTrihedron->SetSize(value);
821 // On donne la couleur au Trihedron
822 if(hascol) aTrihedron->SetColor(col);
823 else aTrihedron->UnsetColor();
825 // The trihedron hasn't be errased from the map
826 // so you just have to redisplay it
827 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
829 TheAISContext() ->UpdateCurrentViewer();
837 //==============================================================================
839 //==============================================================================
840 //function : VPlaneTrihedron
841 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
842 //Draw arg : vplanetri name
843 //==============================================================================
844 #include <AIS_Plane.hxx>
848 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
851 // Verification des arguments
852 if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
854 if (TheAISContext()->NbSelected() != 1)
856 Message::SendFail ("Error: Wrong number of selected shapes.");
860 TheAISContext()->InitSelected();
861 Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive();
862 Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest);
865 Message::SendFail ("Error: Selected shape is not a plane.");
869 VDisplayAISObject (argv[1], aPlane);
876 //==============================================================================
877 // Fonction First click 2de click
879 // vaxis vertex vertex
881 // vaxispara edge vertex
882 // vaxisortho edge Vertex
883 // vaxisinter Face Face
884 //==============================================================================
886 //==============================================================================
887 //function : VAxisBuilder
889 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
890 //==============================================================================
891 #include <TopoDS_Edge.hxx>
892 #include <TopoDS_Vertex.hxx>
893 #include <TopExp.hxx>
894 #include <Geom_Line.hxx>
896 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
899 Standard_Boolean HasArg;
900 TCollection_AsciiString name;
903 if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
904 if (argc==8) HasArg=Standard_True;
905 else HasArg=Standard_False;
909 TopTools_ListOfShape aShapes;
910 ViewerTest::GetSelectedShapes (aShapes);
912 // Cas ou il y a des arguments
913 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
915 Standard_Real coord[6];
916 for(Standard_Integer i=0;i<=5;i++){
917 coord[i]=Draw::Atof(argv[2+i]);
919 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
921 gp_Vec myVect (p1,p2);
922 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
923 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
924 GetMapOfAIS().Bind (TheAxis,name);
925 TheAISContext()->Display(TheAxis, Standard_True);
931 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
932 if ( !strcasecmp(argv[0], "vaxis")) {
933 if (aShapes.Extent() != 2 && aShapes.Extent() != 1)
935 Message::SendFail ("Error: Wrong number of selected shapes.");
939 const TopoDS_Shape& aShapeA = aShapes.First();
940 if (aShapeA.ShapeType() == TopAbs_VERTEX)
942 if (aShapes.Extent() != 2)
944 Message::SendFail ("Error: Wrong number of selected shapes.");
948 const TopoDS_Shape& aShapeB = aShapes.Last();
949 if (aShapeB.ShapeType() != TopAbs_VERTEX)
951 Message::SendFail ("Syntax error: You should select two vertices or one edge.");
955 // Construction de l'axe
956 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
957 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
960 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
961 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
962 GetMapOfAIS().Bind (TheAxis,name);
963 TheAISContext()->Display (TheAxis, Standard_True);
967 TopoDS_Edge ed =TopoDS::Edge (aShapeA);
969 TopExp::Vertices(ed,Va,Vb );
970 gp_Pnt A=BRep_Tool::Pnt(Va);
971 gp_Pnt B=BRep_Tool::Pnt(Vb);
974 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
975 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
976 GetMapOfAIS().Bind (TheAxis,name);
977 TheAISContext()->Display (TheAxis, Standard_True);
983 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
984 else if ( !strcasecmp(argv[0], "vaxispara"))
986 if (aShapes.Extent() != 2)
988 Message::SendFail ("Error: Wrong number of selected shapes.");
992 const TopoDS_Shape& aShapeA = aShapes.First();
993 const TopoDS_Shape& aShapeB = aShapes.Last();
994 if (!(aShapeA.ShapeType() == TopAbs_EDGE
995 && aShapeB.ShapeType() == TopAbs_VERTEX))
997 Message::SendFail ("Syntax error: You should select face and then vertex.");
1001 TopoDS_Edge ed=TopoDS::Edge (aShapeA);
1002 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1003 TopoDS_Vertex Va,Vc;
1004 TopExp::Vertices(ed,Va,Vc );
1005 gp_Pnt A=BRep_Tool::Pnt(Va);
1006 gp_Pnt C=BRep_Tool::Pnt(Vc);
1009 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1010 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1011 GetMapOfAIS().Bind (TheAxis,name);
1012 TheAISContext()->Display (TheAxis, Standard_True);
1016 // Fonction axisortho
1019 if (aShapes.Extent() != 2)
1021 Message::SendFail ("Error: Wrong number of selected shapes.");
1025 const TopoDS_Shape& aShapeA = aShapes.First();
1026 const TopoDS_Shape& aShapeB = aShapes.Last();
1027 if (!(aShapeA.ShapeType() == TopAbs_EDGE
1028 && aShapeB.ShapeType() == TopAbs_VERTEX))
1030 Message::SendFail ("Syntax error: You should select face and then vertex.");
1034 // Construction de l'axe
1035 TopoDS_Edge ed=TopoDS::Edge(aShapeA) ;
1036 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) );
1037 TopoDS_Vertex Va,Vc;
1038 TopExp::Vertices(ed,Va,Vc );
1039 gp_Pnt A=BRep_Tool::Pnt(Va);
1040 gp_Pnt C=BRep_Tool::Pnt(Vc);
1041 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
1044 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1045 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1046 GetMapOfAIS().Bind (TheAxis,name);
1047 TheAISContext()->Display (TheAxis, Standard_True);
1056 //==============================================================================
1057 // Fonction First click Result
1059 // vpoint vertex AIS_Point=Vertex
1060 // edge AIS_Point=Middle of the edge
1061 //==============================================================================
1063 //==============================================================================
1064 //function : VPointBuilder
1066 //==============================================================================
1067 #include <TopoDS_Edge.hxx>
1068 #include <TopoDS_Vertex.hxx>
1069 #include <TopExp.hxx>
1070 #include <AIS_Point.hxx>
1071 #include <Geom_CartesianPoint.hxx>
1073 static int VPointBuilder(Draw_Interpretor& ,
1074 Standard_Integer theArgNb,
1075 const char** theArgVec)
1077 TCollection_AsciiString aName;
1078 gp_Pnt aPnt (RealLast(), 0.0, 0.0);
1079 bool is2d = false, isNoSel = false;
1080 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
1082 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1088 else if (anArg == "-nosel"
1089 || anArg == "-noselection")
1093 else if (aName.IsEmpty())
1095 aName = theArgVec[anArgIter];
1097 else if (aPnt.X() == RealLast()
1098 && anArgIter + 1 < theArgNb
1099 && Draw::ParseReal (theArgVec[anArgIter + 0], aPnt.ChangeCoord().ChangeCoord (1))
1100 && Draw::ParseReal (theArgVec[anArgIter + 1], aPnt.ChangeCoord().ChangeCoord (2)))
1102 if (anArgIter + 2 < theArgNb
1103 && TCollection_AsciiString (theArgVec[anArgIter + 2]) != "-2d"
1104 && Draw::ParseReal (theArgVec[anArgIter + 2], aPnt.ChangeCoord().ChangeCoord (3)))
1115 Message::SendFail() << "Syntax error at argument '" << anArg << "'\n";
1120 if (aPnt.X() == RealLast())
1122 TopTools_ListOfShape aShapes;
1123 ViewerTest::GetSelectedShapes (aShapes);
1124 TopoDS_Shape aShapeA;
1125 if (aShapes.Extent() == 1)
1127 aShapeA = aShapes.First();
1129 switch (!aShapeA.IsNull() ? aShapeA.ShapeType() : TopAbs_SHAPE)
1133 aPnt = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1136 case TopAbs_EDGE: // edge middle point
1138 const TopoDS_Edge& anEdge = TopoDS::Edge (aShapeA);
1139 TopoDS_Vertex aVertPair[2];
1140 TopExp::Vertices (anEdge, aVertPair[0], aVertPair[1]);
1141 const gp_Pnt A = BRep_Tool::Pnt (aVertPair[0]);
1142 const gp_Pnt B = BRep_Tool::Pnt (aVertPair[1]);
1143 aPnt = (A.XYZ() + B.XYZ()) / 2;
1148 Message::SendFail() << "Error: Wrong number of selected shapes.\n"
1149 << "\tYou should select one edge or vertex.";
1157 aPnt.SetY (-aPnt.Y());
1159 Handle(Geom_CartesianPoint ) aGeomPoint = new Geom_CartesianPoint (aPnt);
1160 Handle(AIS_Point) aPointPrs = new AIS_Point (aGeomPoint);
1163 aPointPrs->SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_UPPER));
1164 aPointPrs->SetZLayer (Graphic3d_ZLayerId_TopOSD);
1166 ViewerTest::Display (aName, aPointPrs);
1169 ViewerTest::GetAISContext()->Deactivate (aPointPrs);
1174 //==============================================================================
1175 // Function 1st click 2de click 3de click
1176 // vplane Vertex Vertex Vertex
1180 // vplanepara Face Vertex
1182 // vplaneortho Face Edge
1184 //==============================================================================
1186 //==============================================================================
1187 //function : VPlaneBuilder
1188 //purpose : Build an AIS_Plane from selected entities or Named AIS components
1189 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
1190 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
1191 // [PlaneName] [PointName] [TypeOfSensitivity]
1192 //==============================================================================
1194 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
1195 Standard_Integer argc,
1199 Standard_Boolean hasArg;
1200 TCollection_AsciiString aName;
1203 if (argc<2 || argc>6 )
1205 Message::SendFail ("Syntax error: wrong number of arguments");
1208 if (argc == 6 || argc==5 || argc==4)
1209 hasArg=Standard_True;
1211 hasArg=Standard_False;
1215 // There are some arguments
1218 Handle(AIS_InteractiveObject) aShapeA;
1219 if (!GetMapOfAIS().Find2 (argv[2], aShapeA))
1221 Message::SendFail ("Syntax error: 1st name is not displayed");
1225 // The first argument is an AIS_Point
1226 if (!aShapeA.IsNull() &&
1227 aShapeA->Type()==AIS_KOI_Datum &&
1228 aShapeA->Signature()==1)
1230 // The second argument must also be an AIS_Point
1231 Handle(AIS_InteractiveObject) aShapeB;
1232 if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1234 Message::SendFail ("Syntax error: 2nd name is not displayed");
1237 // If B is not an AIS_Point
1238 if (aShapeB.IsNull() ||
1239 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1241 Message::SendFail ("Syntax error: 2nd object is expected to be an AIS_Point");
1244 // The third object is an AIS_Point
1245 Handle(AIS_InteractiveObject) aShapeC;
1246 if (!GetMapOfAIS().Find2(argv[4], aShapeC))
1248 Message::SendFail ("Syntax error: 3d name is not displayed");
1251 // If C is not an AIS_Point
1252 if (aShapeC.IsNull() ||
1253 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
1255 Message::SendFail ("Syntax error: 3d object is expected to be an AIS_Point");
1259 // Treatment of objects A, B, C
1260 // Downcast an AIS_IO to AIS_Point
1261 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
1262 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
1263 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
1265 Handle(Geom_CartesianPoint ) aCartPointA =
1266 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
1268 Handle(Geom_CartesianPoint ) aCartPointB =
1269 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
1271 Handle(Geom_CartesianPoint ) aCartPointC =
1272 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
1274 // Verification that the three points are different
1275 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
1276 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1277 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
1280 Message::SendFail ("Error: same points");
1283 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1284 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1285 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1288 Message::SendFail ("Error: same points");
1291 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1292 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1293 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1296 Message::SendFail ("Error: same points");
1300 gp_Pnt A = aCartPointA->Pnt();
1301 gp_Pnt B = aCartPointB->Pnt();
1302 gp_Pnt C = aCartPointC->Pnt();
1304 // Construction of AIS_Plane
1305 GC_MakePlane MkPlane (A,B,C);
1306 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1307 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1308 GetMapOfAIS().Bind (anAISPlane,aName );
1311 Standard_Integer aType = Draw::Atoi (argv[5]);
1312 if (aType != 0 && aType != 1)
1314 Message::SendFail("Syntax error: wrong type of sensitivity.\n"
1315 "Should be one of the following values:\n"
1322 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1325 TheAISContext()->Display (anAISPlane, Standard_True);
1328 // The first argument is an AIS_Axis
1329 // Creation of a plane orthogonal to the axis through a point
1330 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1331 // The second argument should be an AIS_Point
1332 Handle(AIS_InteractiveObject) aShapeB;
1333 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1335 Message::SendFail ("Syntax error: 2d name is not displayed");
1338 // If B is not an AIS_Point
1339 if (aShapeB.IsNull() ||
1340 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1342 Message::SendFail ("Syntax error: 2d object is expected to be an AIS_Point");
1346 // Treatment of objects A and B
1347 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1348 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1350 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1351 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1353 gp_Ax1 anAxis = aGeomLineA->Position();
1354 Handle(Geom_CartesianPoint) aCartPointB =
1355 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1357 gp_Dir D =anAxis.Direction();
1358 gp_Pnt B = aCartPointB->Pnt();
1360 // Construction of AIS_Plane
1361 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1362 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1363 GetMapOfAIS().Bind (anAISPlane,aName );
1366 Standard_Integer aType = Draw::Atoi (argv[4]);
1367 if (aType != 0 && aType != 1)
1369 Message::SendFail ("Syntax error: wrong type of sensitivity!\n"
1370 "Should be one of the following values:\n"
1377 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1380 TheAISContext()->Display (anAISPlane, Standard_True);
1383 // The first argumnet is an AIS_Plane
1384 // Creation of a plane parallel to the plane passing through the point
1385 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1387 // The second argument should be an AIS_Point
1388 Handle(AIS_InteractiveObject) aShapeB;
1389 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1391 Message::SendFail ("Syntax error: 2d name is not displayed");
1394 // B should be an AIS_Point
1395 if (aShapeB.IsNull() ||
1396 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1398 Message::SendFail ("Syntax error: 2d object is expected to be an AIS_Point");
1402 // Treatment of objects A and B
1403 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1404 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1406 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1407 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1409 Handle(Geom_CartesianPoint) aCartPointB =
1410 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1411 gp_Pnt B= aCartPointB->Pnt();
1413 // Construction of an AIS_Plane
1414 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1415 GetMapOfAIS().Bind (anAISPlane, aName);
1418 Standard_Integer aType = Draw::Atoi (argv[4]);
1419 if (aType != 0 && aType != 1)
1421 Message::SendFail ("Syntax error: wrong type of sensitivity!\n"
1422 "Should be one of the following values:\n"
1429 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1432 TheAISContext()->Display (anAISPlane, Standard_True);
1437 Message::SendFail ("Syntax error: 1st object is not an AIS");
1441 // There are no arguments
1444 TopTools_ListOfShape aShapes;
1445 ViewerTest::GetSelectedShapes (aShapes);
1448 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1449 if (!strcasecmp(argv[0], "vplane"))
1451 if (aShapes.Extent() < 1 || aShapes.Extent() > 3)
1453 Message::SendFail() << "Error: Wront number of selected shapes.\n"
1454 << "\tYou should one of variant: face, edge and vertex or three vertices.";
1458 const TopoDS_Shape& aShapeA = aShapes.First();
1459 if (aShapeA.ShapeType() == TopAbs_VERTEX)
1461 if (aShapes.Extent() == 2)
1463 const TopoDS_Shape& aShapeB = aShapes.Last();
1464 if (aShapeB.ShapeType() != TopAbs_EDGE)
1466 Message::SendFail ("Syntax error: Together with vertex should be edge.");
1470 // Verify that the vertex is not on the edge ShapeB
1471 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1472 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1474 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1475 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1477 // The vertex is on the edge
1478 Message::SendFail ("Error: point is on the edge");
1483 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1484 TopoDS_Vertex aVBa, aVBb;
1485 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1486 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1487 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1488 GC_MakePlane MkPlane (A, aBa, aBb);
1489 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1490 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1491 GetMapOfAIS().Bind (anAISPlane, aName);
1492 TheAISContext()->Display (anAISPlane, Standard_True);
1495 else if (aShapes.Extent() == 3)
1497 TopTools_ListOfShape::Iterator anIter (aShapes);
1500 const TopoDS_Shape& aShapeB = anIter.Value();
1503 const TopoDS_Shape& aShapeC = anIter.Value();
1505 if (!(aShapeB.ShapeType() == TopAbs_VERTEX
1506 && aShapeC.ShapeType() == TopAbs_VERTEX))
1508 Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices.");
1512 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1513 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1514 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1515 GC_MakePlane MkPlane(A, B, C);
1516 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1517 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1518 GetMapOfAIS().Bind (anAISPlane, aName);
1519 TheAISContext()->Display (anAISPlane, Standard_True);
1523 Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices.");
1527 else if (aShapeA.ShapeType() == TopAbs_EDGE)
1529 if (aShapes.Extent() != 2)
1531 Message::SendFail ("Error: wrong number of selected shapes.");
1535 const TopoDS_Shape& aShapeB = aShapes.Last();
1536 if (aShapeB.ShapeType() != TopAbs_VERTEX)
1538 Message::SendFail ("Syntax error: Together with edge should be vertex.");
1542 // Check that the vertex aShapeB is not on the edge
1543 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1544 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1546 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1547 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1549 // The vertex is on the edge
1550 Message::SendFail ("Error point is on the edge");
1554 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1555 TopoDS_Vertex aVAa, aVAb;
1556 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1557 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1558 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1559 GC_MakePlane MkPlane (B,Aa,Ab);
1560 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1561 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1562 GetMapOfAIS().Bind (anAISPlane ,aName);
1563 TheAISContext()->Display (anAISPlane, Standard_True);
1565 else if (aShapeA.ShapeType() == TopAbs_FACE)
1567 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1568 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1569 if (aSurface.GetType()==GeomAbs_Plane)
1571 gp_Pln aPlane = aSurface.Plane();
1572 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1573 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1574 GetMapOfAIS().Bind (anAISPlane, aName);
1575 TheAISContext()->Display (anAISPlane, Standard_True);
1579 Message::SendFail ("Error: surface is not Plane");
1585 Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices");
1590 // Function vPlanePara
1591 // ===================
1592 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1593 else if (!strcasecmp(argv[0], "vplanepara"))
1595 if (aShapes.Extent() != 2)
1597 Message::SendFail ("Error: Wrong number of selected shapes.");
1601 const TopoDS_Shape* aShapeA = &aShapes.First();
1602 const TopoDS_Shape* aShapeB = &aShapes.Last();
1603 if (aShapeA->ShapeType() != TopAbs_VERTEX)
1605 std::swap (aShapeA, aShapeB);
1608 if (!(aShapeA->ShapeType() == TopAbs_VERTEX
1609 && aShapeB->ShapeType() == TopAbs_FACE))
1611 Message::SendFail ("Syntax error: you should select face and vertex.");
1615 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA));
1617 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1618 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1619 if (aSurface.GetType() == GeomAbs_Plane)
1621 gp_Pln aPlane = aSurface.Plane();
1622 // Construct a plane parallel to aGeomPlane through A
1623 aPlane.SetLocation(A);
1624 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1625 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1626 GetMapOfAIS().Bind (aAISPlane ,aName);
1627 TheAISContext()->Display (aAISPlane, Standard_True);
1631 Message::SendFail ("Error: Builded surface is not a plane.");
1636 // Function vplaneortho
1637 // ====================
1638 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1641 if (aShapes.Extent() != 2)
1643 Message::SendFail ("Error: wrong number of selected shapes.");
1647 const TopoDS_Shape* aShapeA = &aShapes.First();
1648 const TopoDS_Shape* aShapeB = &aShapes.Last();
1650 if (aShapeA->ShapeType() != TopAbs_EDGE)
1652 std::swap (aShapeA, aShapeB);
1655 if (!(aShapeA->ShapeType() == TopAbs_EDGE
1656 && aShapeB->ShapeType() == TopAbs_FACE))
1658 Message::SendFail ("Error: you should select edge and face.");
1662 // Construction of plane
1663 TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA);
1664 TopoDS_Vertex aVAa, aVAb;
1665 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1666 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1667 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1671 // Creation of rotation axis
1672 gp_Ax1 aRotAxis (Aa,Dab);
1674 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1675 // The edge must be parallel to the face
1676 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1677 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1678 // Compare to heights
1679 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1680 >Precision::Confusion())
1682 // the edge is not parallel to the face
1683 Message::SendFail ("Error: the edge is not parallel to the face");
1687 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1688 if (aSurface.GetType()==GeomAbs_Plane)
1690 gp_Pln aPlane = aSurface.Plane();
1691 // It rotates a half turn round the axis of rotation
1692 aPlane.Rotate(aRotAxis , M_PI/2);
1694 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1695 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1696 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1697 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1698 GetMapOfAIS().Bind (anAISPlane, aName);
1699 TheAISContext()->Display (anAISPlane, Standard_True);
1703 Message::SendFail ("Error: surface is not Plane");
1711 //===============================================================================================
1712 //function : VChangePlane
1714 //===============================================================================================
1715 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1717 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1718 if (aContextAIS.IsNull())
1720 Message::SendFail ("Error: no active viewer.");
1724 if (theArgsNb < 3 || theArgsNb > 11)
1726 Message::SendFail ("Syntax error: wrong number of arguments.");
1730 TCollection_AsciiString aName (theArgVec[1]);
1732 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1733 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1736 if ( aPlane.IsNull() )
1738 Message::SendFail() << "Syntax error: there is no interactive plane with the given name '" << aName << "'.";
1742 Standard_Real aCenterX = aPlane->Center().X();
1743 Standard_Real aCenterY = aPlane->Center().Y();
1744 Standard_Real aCenterZ = aPlane->Center().Z();
1746 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1747 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1748 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1750 Standard_Real aSizeX = 0.0;
1751 Standard_Real aSizeY = 0.0;
1752 aPlane->Size (aSizeX, aSizeY);
1753 Standard_Boolean isUpdate = Standard_True;
1755 TCollection_AsciiString aPName, aPValue;
1756 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1758 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1759 TCollection_AsciiString anArgCase = anArg;
1760 anArgCase.UpperCase();
1761 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1764 if (aPName.IsEqual ("X"))
1766 aCenterX = aPValue.RealValue();
1768 else if (aPName.IsEqual ("Y"))
1770 aCenterY = aPValue.RealValue();
1772 else if (aPName.IsEqual ("Z"))
1774 aCenterZ = aPValue.RealValue();
1776 else if (aPName.IsEqual ("DX"))
1778 aDirX = aPValue.RealValue();
1780 else if (aPName.IsEqual ("DY"))
1782 aDirY = aPValue.RealValue();
1784 else if (aPName.IsEqual ("DZ"))
1786 aDirZ = aPValue.RealValue();
1788 else if (aPName.IsEqual ("SX"))
1790 aSizeX = aPValue.RealValue();
1792 else if (aPName.IsEqual ("SY"))
1794 aSizeY = aPValue.RealValue();
1797 else if (anArg.IsEqual ("NOUPDATE"))
1799 isUpdate = Standard_False;
1803 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1804 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1805 aPlane->SetCenter (aCenterPnt);
1806 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1807 aPlane->SetSize (aSizeX, aSizeY);
1809 aContextAIS->Update (aPlane, isUpdate);
1814 //==============================================================================
1816 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1817 //==============================================================================
1819 //==============================================================================
1820 //function : VLineBuilder
1821 //purpose : Build an AIS_Line
1822 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1823 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1824 //==============================================================================
1825 #include <Geom_CartesianPoint.hxx>
1826 #include <AIS_Line.hxx>
1829 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1832 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; }
1834 // On recupere les parametres
1835 Handle(AIS_InteractiveObject) theShapeA;
1836 Handle(AIS_InteractiveObject) theShapeB;
1838 // Parametres: AIS_Point AIS_Point
1839 // ===============================
1841 GetMapOfAIS().Find2 (argv[2], theShapeA);
1842 // On verifie que c'est bien une AIS_Point
1843 if (!theShapeA.IsNull() &&
1844 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1845 // on recupere le deuxieme AIS_Point
1846 GetMapOfAIS().Find2 (argv[3], theShapeB);
1847 if (theShapeB.IsNull() ||
1848 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1850 di <<"vline error: wrong type of 2de argument.\n";
1854 else {di <<"vline error: wrong type of 1st argument.\n";return 1; }
1855 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1856 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1857 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
1859 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1860 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
1861 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1863 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1864 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
1865 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1867 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1869 di<<"vline error: same points\n";return 1;
1871 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1872 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1873 GetMapOfAIS().Bind(theAISLine,argv[1] );
1874 TheAISContext()->Display (theAISLine, Standard_True);
1878 // Parametres 6 Reals
1879 // ==================
1882 // On verifie que les deux points ne sont pas confondus
1884 Standard_Real coord[6];
1885 for(Standard_Integer i=0;i<=2;i++){
1886 coord[i]=Draw::Atof(argv[2+i]);
1887 coord[i+3]=Draw::Atof(argv[5+i]);
1890 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1891 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1893 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1894 GetMapOfAIS().Bind(theAISLine,argv[1] );
1895 TheAISContext()->Display (theAISLine, Standard_True);
1899 // Pas de parametres: Selection dans le viewer.
1900 // ============================================
1904 TopTools_ListOfShape aShapes;
1905 ViewerTest::GetSelectedShapes (aShapes);
1906 if (aShapes.Extent() != 2)
1908 Message::SendFail ("Error: wrong number of selected shapes.");
1912 const TopoDS_Shape& aShapeA = aShapes.First();
1913 const TopoDS_Shape& aShapeB = aShapes.Last();
1915 if (!(aShapeA.ShapeType() == TopAbs_VERTEX
1916 && aShapeB.ShapeType() == TopAbs_VERTEX))
1918 Message::SendFail ("Error: you should select two different vertex.");
1922 // Construction de la line
1923 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1924 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
1926 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1927 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1929 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1930 GetMapOfAIS().Bind(theAISLine,argv[1] );
1931 TheAISContext()->Display (theAISLine, Standard_True);
1937 //==============================================================================
1938 // class : FilledCircle
1939 // purpose : creates filled circle based on AIS_InteractiveObject
1941 // This class is used to check method Matches() of class
1942 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1943 // because none of AIS classes provides creation of
1944 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1945 // (look method ComputeSelection() )
1946 //==============================================================================
1948 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1950 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1951 gp_Circ aCirc(anAxes, theRadius);
1952 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1956 class FilledCircle : public AIS_InteractiveObject
1960 DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject);
1962 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1963 FilledCircle(Handle(Geom_Circle) theCircle);
1966 TopoDS_Face ComputeFace();
1968 // Virtual methods implementation
1969 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1970 const Handle(Prs3d_Presentation)& thePresentation,
1971 const Standard_Integer theMode) Standard_OVERRIDE;
1973 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1974 const Standard_Integer theMode) Standard_OVERRIDE;
1977 Handle(Geom_Circle) myCircle;
1978 Standard_Boolean myFilledStatus;
1983 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1985 myCircle = CreateCircle(theCenter, theRadius);
1986 myFilledStatus = Standard_True;
1989 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1991 myCircle = theCircle;
1992 myFilledStatus = Standard_True;
1995 TopoDS_Face FilledCircle::ComputeFace()
1997 // Create edge from myCircle
1998 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1999 TopoDS_Edge anEdge = anEdgeMaker.Edge();
2001 // Create wire from anEdge
2002 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
2003 TopoDS_Wire aWire = aWireMaker.Wire();
2005 // Create face from aWire
2006 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
2007 TopoDS_Face aFace = aFaceMaker.Face();
2012 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
2013 const Handle(Prs3d_Presentation) &thePresentation,
2014 const Standard_Integer theMode)
2016 thePresentation->Clear();
2018 TopoDS_Face aFace = ComputeFace();
2020 if (aFace.IsNull()) return;
2021 if (theMode != 0) return;
2023 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2026 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
2027 const Standard_Integer /*theMode*/)
2029 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2030 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle (anEntityOwner, myCircle->Circ(), myFilledStatus);
2031 theSelection->Add(aSensitiveCircle);
2034 //==============================================================================
2036 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2037 //==============================================================================
2039 //==============================================================================
2040 //function : VCircleBuilder
2041 //purpose : Build an AIS_Circle
2042 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2043 // PointName PointName PointName IsFilled
2044 //==============================================================================
2046 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2047 TCollection_AsciiString theName,
2048 Standard_Boolean isFilled)
2050 Handle(AIS_InteractiveObject) aCircle;
2053 aCircle = new FilledCircle(theGeomCircle);
2057 aCircle = new AIS_Circle(theGeomCircle);
2058 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2061 // Check if there is an object with given name
2062 // and remove it from context
2063 if (GetMapOfAIS().IsBound2(theName))
2065 Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2(theName);
2066 TheAISContext()->Remove(anInterObj, Standard_False);
2067 GetMapOfAIS().UnBind2(theName);
2070 // Bind the circle to its name
2071 GetMapOfAIS().Bind(aCircle, theName);
2073 // Display the circle
2074 TheAISContext()->Display (aCircle, Standard_True);
2078 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2080 // Verification of the arguments
2081 if (argc>6 || argc<2)
2083 Message::SendFail ("Syntax error: wrong number of arguments");
2087 // There are all arguments
2091 TCollection_AsciiString aName(argv[1]);
2092 Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0;
2094 Handle(AIS_InteractiveObject) theShapeA, theShapeB;
2095 GetMapOfAIS().Find2 (argv[2], theShapeA);
2096 GetMapOfAIS().Find2 (argv[3], theShapeB);
2098 // Arguments: AIS_Point AIS_Point AIS_Point
2099 // ========================================
2100 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2101 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2103 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2105 Message::SendFail ("Error: 2d argument is unexpected to be a point");
2108 // The third object must be a point
2109 Handle(AIS_InteractiveObject) theShapeC;
2110 GetMapOfAIS().Find2 (argv[4], theShapeC);
2111 if (theShapeC.IsNull() ||
2112 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2114 Message::SendFail ("Error: 3d argument is unexpected to be a point");
2118 // Verify that the three points are different
2119 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2120 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2121 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2123 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2124 Handle(Geom_CartesianPoint) myCartPointA =
2125 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2127 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2128 Handle(Geom_CartesianPoint) myCartPointB =
2129 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2131 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2132 Handle(Geom_CartesianPoint) myCartPointC =
2133 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2136 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2137 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2138 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2140 Message::SendFail ("Error: Same points");
2144 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2145 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2146 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2148 Message::SendFail ("Error: Same points");
2152 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2153 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2154 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2156 Message::SendFail ("Error: Same points");
2159 // Construction of the circle
2160 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2161 myCartPointB->Pnt(), myCartPointC->Pnt() );
2162 Handle (Geom_Circle) theGeomCircle;
2165 theGeomCircle = Cir.Value();
2167 catch (StdFail_NotDone const&)
2169 Message::SendFail ("Error: can't create circle");
2173 DisplayCircle(theGeomCircle, aName, isFilled);
2176 // Arguments: AIS_Plane AIS_Point Real
2177 // ===================================
2178 else if (theShapeA->Type() == AIS_KOI_Datum &&
2179 theShapeA->Signature() == 7 )
2181 if (theShapeB->Type() != AIS_KOI_Datum ||
2182 theShapeB->Signature() != 1 )
2184 Message::SendFail ("Error: 2d element is a unexpected to be a point");
2187 // Check that the radius is >= 0
2188 if (Draw::Atof(argv[4]) <= 0 )
2190 Message::SendFail ("Syntax error: the radius must be >=0");
2194 // Recover the normal to the plane
2195 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2196 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2198 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2199 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2200 Handle(Geom_CartesianPoint) myCartPointB =
2201 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2203 gp_Pln mygpPlane = myGeomPlane->Pln();
2204 gp_Ax1 thegpAxe = mygpPlane.Axis();
2205 gp_Dir theDir = thegpAxe.Direction();
2206 gp_Pnt theCenter = myCartPointB->Pnt();
2207 Standard_Real TheR = Draw::Atof(argv[4]);
2208 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2209 Handle (Geom_Circle) theGeomCircle;
2212 theGeomCircle = Cir.Value();
2214 catch (StdFail_NotDone const&)
2216 Message::SendFail ("Error: can't create circle");
2220 DisplayCircle(theGeomCircle, aName, isFilled);
2227 Message::SendFail ("Error: 1st argument has an unexpected type");
2232 // No arguments: selection in the viewer
2233 // =========================================
2236 // Get the name of the circle
2237 TCollection_AsciiString aName(argv[1]);
2239 TopTools_ListOfShape aShapes;
2240 ViewerTest::GetSelectedShapes (aShapes);
2241 if (aShapes.Extent() != 3 && aShapes.Extent() != 2)
2243 Message::SendFail ("Error: Wrong number of selected shapes.");
2247 const TopoDS_Shape& aShapeA = aShapes.First();
2248 if (aShapeA.ShapeType() == TopAbs_VERTEX )
2250 if (aShapes.Extent() != 3)
2252 Message::SendFail ("Error: wrong number of selected shapes.");
2256 TopTools_ListOfShape::Iterator anIter (aShapes);
2259 const TopoDS_Shape& aShapeB = anIter.Value();
2262 const TopoDS_Shape& aShapeC = anIter.Value();
2265 Standard_Boolean isFilled;
2266 std::cout << "Enter filled status (0 or 1)\n";
2267 std::cin >> isFilled;
2269 // Construction of the circle
2270 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
2271 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2272 gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC));
2274 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2275 Handle (Geom_Circle) theGeomCircle;
2278 theGeomCircle = Cir.Value();
2280 catch (StdFail_NotDone const&)
2282 Message::SendFail ("Error: can't create circle");
2286 DisplayCircle(theGeomCircle, aName, isFilled);
2289 else if (aShapeA.ShapeType() == TopAbs_FACE)
2291 const TopoDS_Shape& aShapeB = aShapes.Last();
2293 // Recover the radius
2294 Standard_Real theRad;
2297 std::cout << " Enter the value of the radius:\n";
2299 } while (theRad <= 0);
2301 // Get filled status
2302 Standard_Boolean isFilled;
2303 std::cout << "Enter filled status (0 or 1)\n";
2304 std::cin >> isFilled;
2306 // Recover the normal to the plane. tag
2307 TopoDS_Face myFace = TopoDS::Face(aShapeA);
2308 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2309 gp_Pln myPlane = mySurface.Plane();
2310 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2311 gp_Pln mygpPlane = theGeomPlane->Pln();
2312 gp_Ax1 thegpAxe = mygpPlane.Axis();
2313 gp_Dir theDir = thegpAxe.Direction();
2315 // Recover the center
2316 gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2318 // Construct the circle
2319 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2320 Handle (Geom_Circle) theGeomCircle;
2323 theGeomCircle = Cir.Value();
2325 catch (StdFail_NotDone const&)
2327 Message::SendFail ("Error: can't create circle");
2331 DisplayCircle(theGeomCircle, aName, isFilled);
2335 Message::SendFail ("Error: You should select face and vertex or three vertices.");
2343 //=======================================================================
2344 //function : VDrawText
2346 //=======================================================================
2347 static int VDrawText (Draw_Interpretor& theDI,
2348 Standard_Integer theArgsNb,
2349 const char** theArgVec)
2351 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2354 Message::SendFail ("Syntax error: wrong number of arguments. See usage:");
2355 theDI.PrintHelp (theArgVec[0]);
2358 else if (aContext.IsNull())
2360 Message::SendFail ("Error: no active viewer");
2364 Standard_Integer anArgIt = 1;
2365 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2366 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2367 Handle(AIS_TextLabel) aTextPrs;
2368 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2370 Standard_Boolean isNewPrs = Standard_False;
2371 if (GetMapOfAIS().IsBound2 (aName))
2373 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2376 if (aTextPrs.IsNull())
2378 isNewPrs = Standard_True;
2379 aTextPrs = new AIS_TextLabel();
2380 aTextPrs->SetFont ("Courier");
2383 aTextPrs->SetText (aText);
2385 Handle(Graphic3d_TransformPers) aTrsfPers;
2386 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2388 Standard_Boolean aHasPlane = Standard_False;
2394 Handle(Font_TextFormatter) aTextFormatter;
2395 for (; anArgIt < theArgsNb; ++anArgIt)
2397 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2400 if (anAutoUpdater.parseRedrawMode (aParam))
2404 else if (aParam == "-pos"
2405 || aParam == "-position")
2407 if (anArgIt + 3 >= theArgsNb)
2409 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
2413 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2414 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2415 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2416 aTextPrs->SetPosition (aPos);
2418 else if (aParam == "-color")
2420 Quantity_Color aColor;
2421 Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIt - 1,
2422 theArgVec + anArgIt + 1,
2426 Message::SendFail() << "Syntax error at '" << aParam << "'";
2429 anArgIt += aNbParsed;
2430 aTextPrs->SetColor (aColor);
2432 else if (aParam == "-halign")
2434 if (++anArgIt >= theArgsNb)
2436 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'";
2440 TCollection_AsciiString aType (theArgVec[anArgIt]);
2442 if (aType == "left")
2444 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2446 else if (aType == "center")
2448 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2450 else if (aType == "right")
2452 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2456 Message::SendFail() << "Syntax error at '" << aParam << "'";
2460 else if (aParam == "-valign")
2462 if (++anArgIt >= theArgsNb)
2464 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
2468 TCollection_AsciiString aType (theArgVec[anArgIt]);
2472 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2474 else if (aType == "center")
2476 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2478 else if (aType == "bottom")
2480 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2482 else if (aType == "topfirstline")
2484 aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2488 Message::SendFail() << "Syntax error at '" << aParam << "'";
2492 else if (aParam == "-angle")
2494 if (++anArgIt >= theArgsNb)
2496 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
2500 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2502 else if (aParam == "-zoom")
2504 if (++anArgIt >= theArgsNb)
2506 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
2510 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2512 else if (aParam == "-height")
2514 if (++anArgIt >= theArgsNb)
2516 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
2520 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2522 else if (aParam == "-wrapping")
2524 if (++anArgIt >= theArgsNb)
2526 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
2530 if (aTextFormatter.IsNull())
2532 aTextFormatter = new Font_TextFormatter();
2534 aTextFormatter->SetWrapping ((Standard_ShortReal)Draw::Atof(theArgVec[anArgIt]));
2536 else if (aParam == "-aspect")
2538 if (++anArgIt >= theArgsNb)
2540 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
2544 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2545 anOption.LowerCase();
2546 Font_FontAspect aFontAspect = Font_FA_Undefined;
2547 if (!parseFontStyle (anOption, aFontAspect))
2549 Message::SendFail() << "Syntax error: unknown font aspect '" << anOption << "'";
2552 aTextPrs->SetFontAspect (aFontAspect);
2554 else if (aParam == "-font")
2556 if (++anArgIt >= theArgsNb)
2558 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
2562 aTextPrs->SetFont (theArgVec[anArgIt]);
2564 else if (aParam == "-plane")
2566 if (anArgIt + 6 >= theArgsNb)
2568 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
2572 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
2573 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
2574 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
2575 aNormal.SetCoord (aX, aY, aZ);
2577 aX = Draw::Atof (theArgVec[++anArgIt]);
2578 aY = Draw::Atof (theArgVec[++anArgIt]);
2579 aZ = Draw::Atof (theArgVec[++anArgIt]);
2580 aDirection.SetCoord (aX, aY, aZ);
2582 aHasPlane = Standard_True;
2584 else if (aParam == "-flipping")
2586 aTextPrs->SetFlipping (Standard_True);
2588 else if (aParam == "-ownanchor")
2590 if (++anArgIt >= theArgsNb)
2592 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2595 aTextPrs->SetOwnAnchorPoint (Draw::Atoi (theArgVec[anArgIt]) == 1);
2597 else if (aParam == "-disptype"
2598 || aParam == "-displaytype")
2600 if (++anArgIt >= theArgsNb)
2602 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
2605 TCollection_AsciiString aType (theArgVec[anArgIt]);
2607 if (aType == "subtitle")
2608 aDisplayType = Aspect_TODT_SUBTITLE;
2609 else if (aType == "decal")
2610 aDisplayType = Aspect_TODT_DEKALE;
2611 else if (aType == "blend")
2612 aDisplayType = Aspect_TODT_BLEND;
2613 else if (aType == "dimension")
2614 aDisplayType = Aspect_TODT_DIMENSION;
2615 else if (aType == "normal")
2616 aDisplayType = Aspect_TODT_NORMAL;
2617 else if (aType == "shadow")
2618 aDisplayType = Aspect_TODT_SHADOW;
2621 Message::SendFail() << "Syntax error: wrong display type '" << aType << "'";
2625 else if (aParam == "-subcolor"
2626 || aParam == "-subtitlecolor")
2628 Quantity_Color aColor;
2629 Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIt - 1,
2630 theArgVec + anArgIt + 1,
2634 Message::SendFail() << "Syntax error at '" << aParam << "'";
2637 anArgIt += aNbParsed;
2638 aTextPrs->SetColorSubTitle (aColor);
2640 else if (aParam == "-2d")
2642 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d);
2644 else if (aParam == "-trsfperspos"
2645 || aParam == "-perspos")
2647 if (anArgIt + 2 >= theArgsNb)
2649 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'.";
2653 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2654 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2655 TCollection_AsciiString aZ = "0";
2656 if (!aX.IsIntegerValue()
2657 || !aY.IsIntegerValue())
2659 Message::SendFail() << "Error: wrong syntax at '" << aParam << "'.";
2662 if (anArgIt + 1 < theArgsNb)
2664 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2665 if (aTemp.IsIntegerValue())
2672 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()));
2676 Message::SendFail() << "Syntax error: unknown argument '" << aParam << "'";
2681 aTextPrs->SetTextFormatter (aTextFormatter);
2685 aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2688 aTextPrs->SetDisplayType (aDisplayType);
2690 if (!aTrsfPers.IsNull())
2692 aContext->SetTransformPersistence (aTextPrs, aTrsfPers);
2693 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2694 if (aTextPrs->Position().Z() != 0)
2696 aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
2699 else if (!aTextPrs->TransformPersistence().IsNull())
2701 aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
2706 ViewerTest::Display (aName, aTextPrs, Standard_False);
2710 aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
2716 #include <gp_Pnt.hxx>
2717 #include <Graphic3d_ArrayOfPoints.hxx>
2718 #include <Graphic3d_ArrayOfPrimitives.hxx>
2719 #include <Graphic3d_ArrayOfTriangles.hxx>
2720 #include <Poly_Array1OfTriangle.hxx>
2721 #include <Poly_Triangle.hxx>
2722 #include <Poly_Triangulation.hxx>
2723 #include <TColgp_Array1OfPnt.hxx>
2724 #include <TShort_Array1OfShortReal.hxx>
2725 #include <TShort_HArray1OfShortReal.hxx>
2727 #include <AIS_Triangulation.hxx>
2728 #include <StdPrs_ToolTriangulatedShape.hxx>
2729 #include <Poly_Connect.hxx>
2730 #include <TColgp_Array1OfDir.hxx>
2731 #include <Graphic3d_GraphicDriver.hxx>
2733 #include <TColStd_Array1OfInteger.hxx>
2734 #include <TColStd_HArray1OfInteger.hxx>
2735 #include <Prs3d_ShadingAspect.hxx>
2736 #include <Graphic3d_MaterialAspect.hxx>
2737 #include <Graphic3d_AspectFillArea3d.hxx>
2739 #include <BRepPrimAPI_MakeCylinder.hxx>
2740 #include <TopoDS_Shape.hxx>
2741 #include <TopExp_Explorer.hxx>
2742 #include <TopAbs.hxx>
2743 #include <AIS_InteractiveObject.hxx>
2746 //===============================================================================================
2747 //function : CalculationOfSphere
2749 //purpose : Create a Sphere
2750 //===============================================================================================
2752 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2755 double mRadius = Radius;
2756 double mCenter[3] = {X,Y,Z};
2757 int mThetaResolution;
2759 double mStartTheta = 0;//StartTheta;
2760 double mEndTheta = 360;//EndTheta;
2761 double mStartPhi = 0;//StartPhi;
2762 double mEndPhi = 180;//EndPhi;
2763 res = res < 4 ? 4 : res;
2765 mThetaResolution = res;
2766 mPhiResolution = res;
2769 int jStart, jEnd, numOffset;
2770 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2771 double startTheta, endTheta, startPhi, endPhi;
2772 int base, numPoles=0, thetaResolution, phiResolution;
2777 if ( numPieces > mThetaResolution ) {
2778 numPieces = mThetaResolution;
2781 int localThetaResolution = mThetaResolution;
2782 double localStartTheta = mStartTheta;
2783 double localEndTheta = mEndTheta;
2785 while ( localEndTheta < localStartTheta ) {
2786 localEndTheta += 360.0;
2789 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2791 // Change the ivars based on pieces.
2793 start = piece * localThetaResolution / numPieces;
2794 end = (piece+1) * localThetaResolution / numPieces;
2795 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2796 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2797 localThetaResolution = end - start;
2799 // Create north pole if needed
2800 int number_point = 0;
2801 int number_pointArray = 0;
2803 if ( mStartPhi <= 0.0 ) {
2804 number_pointArray++;
2807 if ( mEndPhi >= 180.0 ) {
2808 number_pointArray++;
2812 // Check data, determine increments, and convert to radians
2813 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2814 startTheta *= M_PI / 180.0;
2815 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2816 endTheta *= M_PI / 180.0;
2819 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2820 startPhi *= M_PI / 180.0;
2821 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2822 endPhi *= M_PI / 180.0;
2824 phiResolution = mPhiResolution - numPoles;
2825 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2826 thetaResolution = localThetaResolution;
2827 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2828 ++localThetaResolution;
2830 deltaTheta = (endTheta - startTheta) / thetaResolution;
2832 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2833 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2835 // Create intermediate points
2836 for ( i = 0; i < localThetaResolution; i++ ) {
2837 for ( j = jStart; j < jEnd; j++ ) {
2838 number_pointArray++;
2842 //Generate mesh connectivity
2843 base = phiResolution * localThetaResolution;
2845 int number_triangle = 0 ;
2846 if ( mStartPhi <= 0.0 ) { // around north pole
2847 number_triangle += localThetaResolution;
2850 if ( mEndPhi >= 180.0 ) { // around south pole
2851 number_triangle += localThetaResolution;
2854 // bands in-between poles
2855 for ( i=0; i < localThetaResolution; i++){
2856 for ( j=0; j < (phiResolution-1); j++){
2857 number_triangle +=2;
2861 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2862 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2863 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2865 if ( mStartPhi <= 0.0 ){
2868 x[2] = mCenter[2] + mRadius;
2869 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2872 // Create south pole if needed
2873 if ( mEndPhi >= 180.0 ){
2876 x[2] = mCenter[2] - mRadius;
2877 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2881 for ( i=0; i < localThetaResolution; i++){
2882 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2883 for ( j = jStart; j < jEnd; j++){
2884 phi = startPhi + j*deltaPhi;
2885 radius = mRadius * sin((double)phi);
2886 n[0] = radius * cos((double)theta);
2887 n[1] = radius * sin((double)theta);
2888 n[2] = mRadius * cos((double)phi);
2889 x[0] = n[0] + mCenter[0];
2890 x[1] = n[1] + mCenter[1];
2891 x[2] = n[2] + mCenter[2];
2892 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2898 number_triangle = 1;
2899 if ( mStartPhi <= 0.0 ){// around north pole
2900 for (i=0; i < localThetaResolution; i++){
2901 pts[0] = phiResolution*i + numPoles;
2902 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2904 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2909 if ( mEndPhi >= 180.0 ){ // around south pole
2910 numOffset = phiResolution - 1 + numPoles;
2911 for (i=0; i < localThetaResolution; i++){
2912 pts[0] = phiResolution*i + numOffset;
2913 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2914 pts[1] = numPoles - 1;
2915 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2920 // bands in-between poles
2922 for (i=0; i < localThetaResolution; i++){
2923 for (j=0; j < (phiResolution-1); j++){
2924 pts[0] = phiResolution*i + j + numPoles;
2925 pts[1] = pts[0] + 1;
2926 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2927 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2930 pts[2] = pts[1] - 1;
2931 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2936 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2938 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2940 Standard_Integer index[3];
2941 Standard_Real Tol = Precision::Confusion();
2944 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2945 gp_XYZ eqPlan(0, 0, 0);
2946 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2947 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2948 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2949 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2951 Standard_Real mod = vv.Modulus();
2952 if(mod < Tol) continue;
2956 Standard_Real modmax = eqPlan.Modulus();
2959 Nor = gp_Dir(eqPlan);
2961 Nor = gp_Dir(0., 0., 1.);
2963 Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
2964 Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
2965 Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
2966 Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
2970 polyTriangulation->SetNormals(Normals);
2972 return polyTriangulation;
2975 //===============================================================================================
2976 //function : VDrawSphere
2978 //purpose : Create an AIS shape.
2979 //===============================================================================================
2980 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2983 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2984 if (aContextAIS.IsNull())
2986 Message::SendFail ("Error: no active viewer");
2991 Message::SendFail() << "Syntax error: wrong number of arguments.\n"
2992 << "Use: " << argv[0] << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]";
2996 // read the arguments
2997 TCollection_AsciiString aShapeName (argv[1]);
2998 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2999 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
3000 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
3001 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
3002 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
3003 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
3004 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
3006 // remove AIS object with given name from map
3007 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
3010 std::cout << "Compute Triangulation...\n";
3011 Handle(AIS_Triangulation) aShape
3012 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
3015 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
3016 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
3018 // stupid initialization of Green color in RGBA space as integer
3019 // probably wrong for big-endian CPUs
3020 const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
3022 // setup colors array per vertex
3023 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
3024 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
3026 aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData()));
3028 aShape->SetColors (aColorArray);
3031 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3032 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3033 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
3034 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
3035 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
3036 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
3037 aTotalSize >>= 20; //MB
3038 aNormalsSize >>= 20;
3040 aTrianglesSize >>= 20;
3041 aPolyConnectSize >>= 20;
3044 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
3045 << "NumberOfTriangles: " << aNumberTriangles << "\n"
3046 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
3047 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
3048 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
3049 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
3052 // Setting material properties, very important for desirable visual result!
3053 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
3054 aMat.SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.04f)));
3055 aMat.SetSpecularColor(Quantity_Color (Graphic3d_Vec3 (0.50f)));
3056 Handle(Graphic3d_AspectFillArea3d) anAspect
3057 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3059 Quantity_NOC_YELLOW,
3064 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3065 anAspect->SetDrawEdges (toShowEdges);
3066 aShAsp->SetAspect (anAspect);
3067 aShape->Attributes()->SetShadingAspect (aShAsp);
3069 VDisplayAISObject (aShapeName, aShape);
3073 //=============================================================================
3074 //function : VComputeHLR
3076 //=============================================================================
3078 static int VComputeHLR (Draw_Interpretor& ,
3079 Standard_Integer theArgNb,
3080 const char** theArgVec)
3082 TCollection_AsciiString aShapeName, aHlrName;
3087 bool hasViewDirArg = false;
3088 Prs3d_TypeOfHLR anAlgoType = Prs3d_TOH_PolyAlgo;
3089 bool toShowCNEdges = false, toShowHiddenEdges = false;
3090 int aNbIsolines = 0;
3091 if (Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext())
3094 Handle(V3d_View) aView = ViewerTest::CurrentView();
3095 Standard_Integer aWidth, aHeight;
3096 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3097 Standard_Real aRightX, aRightY, aRightZ;
3098 aView->Window()->Size (aWidth, aHeight);
3100 aView->ConvertWithProj (aWidth, aHeight/2,
3101 aRightX, aRightY, aRightZ,
3102 aDirX, aDirY, aDirZ);
3103 aView->ConvertWithProj (aWidth/2, aHeight/2,
3104 aCentX, aCentY, aCentZ,
3105 aDirX, aDirY, aDirZ);
3107 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3108 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3109 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3110 aProjAx.SetLocation (anEye);
3111 aProjAx.SetDirection (aDir);
3112 aProjAx.SetXDirection (aRight);
3114 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3116 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3117 anArgCase.LowerCase();
3118 if (anArgIter + 1 < theArgNb
3119 && (anArgCase == "-algotype"
3120 || anArgCase == "-algo"
3121 || anArgCase == "-type"))
3123 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
3124 anArgNext.LowerCase();
3125 if (anArgNext == "polyalgo")
3127 anAlgoType = Prs3d_TOH_PolyAlgo;
3129 else if (anArgNext == "algo")
3131 anAlgoType = Prs3d_TOH_Algo;
3135 Message::SendFail() << "Syntax error: unknown algo type '" << anArgNext << "'";
3139 else if (anArgCase == "-showhiddenedges"
3140 || anArgCase == "-hiddenedges"
3141 || anArgCase == "-hidden")
3143 toShowHiddenEdges = true;
3144 if (anArgIter + 1 < theArgNb
3145 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toShowHiddenEdges))
3150 else if (anArgCase == "-showtangentedges"
3151 || anArgCase == "-tangentedges"
3152 || anArgCase == "-tangent")
3154 toShowCNEdges = true;
3155 if (anArgIter + 1 < theArgNb
3156 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toShowCNEdges))
3161 else if (anArgIter + 1 < theArgNb
3162 && (anArgCase == "-nbiso"
3163 || anArgCase == "-nbisolines"))
3165 aNbIsolines = Draw::Atoi (theArgVec[++anArgIter]);
3167 else if (aSh.IsNull())
3169 aSh = DBRep::Get (theArgVec[anArgIter]);
3170 aShapeName = theArgVec[anArgIter];
3173 BRep_Builder aBrepBuilder;
3174 BRepTools::Read (aSh, theArgVec[anArgIter], aBrepBuilder);
3177 Message::SendFail() << "Syntax error: no shape with name " << theArgVec[anArgIter] << " found";
3182 else if (aHlrName.IsEmpty())
3184 aHlrName = theArgVec[anArgIter];
3186 else if (!hasViewDirArg
3187 && anArgIter + 8 < theArgNb)
3189 hasViewDirArg = true;
3191 anEye.SetCoord (Draw::Atof (theArgVec[anArgIter + 0]), Draw::Atof (theArgVec[anArgIter + 1]), Draw::Atof (theArgVec[anArgIter + 2]));
3192 aDir .SetCoord (Draw::Atof (theArgVec[anArgIter + 3]), Draw::Atof (theArgVec[anArgIter + 4]), Draw::Atof (theArgVec[anArgIter + 5]));
3193 anUp .SetCoord (Draw::Atof (theArgVec[anArgIter + 6]), Draw::Atof (theArgVec[anArgIter + 7]), Draw::Atof (theArgVec[anArgIter + 8]));
3194 aProjAx.SetLocation (anEye);
3195 aProjAx.SetDirection (aDir);
3196 aProjAx.SetYDirection (anUp);
3201 Message::SendFail() << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'";
3206 if (aHlrName.IsEmpty() || aSh.IsNull()
3207 || (ViewerTest::GetAISContext().IsNull() && hasViewDirArg))
3209 Message::SendFail ("Syntax error: wrong number of arguments");
3213 HLRAlgo_Projector aProjector (aProjAx);
3214 TopoDS_Shape aVisible[6];
3215 TopoDS_Shape aHidden[6];
3216 if (anAlgoType == Prs3d_TOH_PolyAlgo)
3218 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3219 aPolyAlgo->Projector (aProjector);
3220 aPolyAlgo->Load (aSh);
3221 aPolyAlgo->Update();
3223 HLRBRep_PolyHLRToShape aHLRToShape;
3224 aHLRToShape.Update (aPolyAlgo);
3226 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3227 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); // extract visible outlines
3228 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3231 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3233 if (toShowHiddenEdges)
3235 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3236 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3237 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3240 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3246 Handle(HLRBRep_Algo) aHlrAlgo = new HLRBRep_Algo();
3247 aHlrAlgo->Add (aSh, aNbIsolines);
3248 aHlrAlgo->Projector (aProjector);
3252 HLRBRep_HLRToShape aHLRToShape (aHlrAlgo);
3253 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3254 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound();
3255 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3258 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3260 aVisible[HLRBRep_IsoLine] = aHLRToShape.IsoLineVCompound();
3262 if (toShowHiddenEdges)
3264 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3265 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3266 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3269 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3271 aHidden[HLRBRep_IsoLine] = aHLRToShape.IsoLineHCompound();
3274 //aVisible[HLRBRep_Sharp] = aHLRToShape.CompoundOfEdges (HLRBRep_Sharp, Standard_True, Standard_True);
3275 //aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound3d();
3278 TopoDS_Compound aCompRes, aCompVis, aCompHid;
3279 BRep_Builder aBuilder;
3280 aBuilder.MakeCompound (aCompVis);
3281 aBuilder.MakeCompound (aCompHid);
3282 aBuilder.MakeCompound (aCompRes);
3283 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3285 if (!aVisible[aTypeIter].IsNull())
3287 aBuilder.Add (aCompVis, aVisible[aTypeIter]);
3289 if (!aHidden[aTypeIter].IsNull())
3291 aBuilder.Add (aCompHid, aHidden[aTypeIter]);
3294 aBuilder.Add (aCompRes, aCompVis);
3295 aBuilder.Add (aCompRes, aCompHid);
3297 // create an AIS shape and display it
3298 if (!ViewerTest::GetAISContext().IsNull())
3300 Handle(AIS_ColoredShape) anObject = new AIS_ColoredShape (aCompRes);
3301 if (toShowHiddenEdges)
3303 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect (Quantity_Color (Quantity_NOC_RED), Aspect_TOL_DASH, 1.0f);
3304 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3306 if (!aHidden[aTypeIter].IsNull())
3308 Handle(AIS_ColoredDrawer) aDrawer = anObject->CustomAspects (aHidden[aTypeIter]);
3309 aDrawer->SetLineAspect (aLineAspect);
3310 aDrawer->SetWireAspect (aLineAspect);
3311 aDrawer->SetFreeBoundaryAspect (aLineAspect);
3312 aDrawer->SetUnFreeBoundaryAspect (aLineAspect);
3316 ViewerTest::Display (aHlrName, anObject, true);
3319 DBRep::Set (aHlrName.ToCString(), aCompRes);
3323 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3324 // manipulating and displaying such an array with AIS context
3326 class MyPArrayObject : public AIS_InteractiveObject
3331 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives)& thePArray) : myPArray (thePArray) {}
3333 MyPArrayObject (Graphic3d_TypeOfPrimitiveArray thePrimType,
3334 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3335 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect)
3337 Init (thePrimType, theDesc, theMarkerAspect, Standard_False);
3340 //! Initialize the array from specified description.
3341 Standard_Boolean Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3342 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3343 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3344 Standard_Boolean theToPatch);
3346 DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
3348 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
3350 //! Sets color to this interactive object
3351 //! @param theColor the color to be set
3352 virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
3356 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3357 const Handle(Prs3d_Presentation)& aPresentation,
3358 const Standard_Integer aMode) Standard_OVERRIDE;
3360 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3361 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
3363 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3364 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3365 Standard_Integer &theArgIndex,
3366 Standard_Integer theArgCount,
3367 Standard_Integer theMaxArgs);
3369 //! Sets color for the shading aspect of the drawer used in this interactive object
3370 //! @param theColor the color to be set
3371 void setColorForShadingAspect(const Quantity_Color& theColor);
3373 //! Replaces shading aspect from myDrawer->Link() with the own shading aspect of myDrawer for this interactive object
3374 void replaceShadingAspect();
3378 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3379 Handle(Graphic3d_ArrayOfPrimitives) myPArray;
3383 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3384 const Handle(Prs3d_Presentation)& thePrs,
3385 const Standard_Integer theMode)
3387 if (myPArray.IsNull() || theMode != 0)
3392 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
3393 if (!myMarkerAspect.IsNull())
3395 aGroup->SetGroupPrimitivesAspect (myMarkerAspect);
3399 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
3401 aGroup->AddPrimitiveArray (myPArray);
3404 Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3405 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3406 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3407 Standard_Boolean theToPatch)
3409 myMarkerAspect = theMarkerAspect;
3415 // Parsing array description
3416 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3417 Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None;
3419 const Standard_Integer anArgsCount = theDesc->Length();
3420 TCollection_AsciiString aCommand;
3421 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3423 aCommand = theDesc->Value (anArgIndex);
3424 aCommand.LowerCase();
3426 if (CheckInputCommand ("-deinterleaved", theDesc, anArgIndex, 0, anArgsCount))
3428 anArrayFlags |= Graphic3d_ArrayFlags_AttribsDeinterleaved;
3430 else if (CheckInputCommand ("-mutable", theDesc, anArgIndex, 0, anArgsCount))
3432 anArrayFlags |= Graphic3d_ArrayFlags_AttribsMutable;
3433 anArrayFlags |= Graphic3d_ArrayFlags_IndexesMutable;
3436 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3438 // vertex has a normal or normal with color or texel
3439 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3441 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal;
3444 // vertex has a color
3445 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3447 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor;
3450 // vertex has a texel
3451 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3453 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel;
3459 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3462 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3464 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor;
3470 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3479 if (myPArray.IsNull())
3481 myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
3485 if (myPArray->Type() != thePrimType
3486 || aVertexNum > myPArray->VertexNumberAllocated()
3487 || aEdgeNum > myPArray->EdgeNumberAllocated()
3488 || aBoundNum > myPArray->BoundNumberAllocated()
3489 || !myPArray->Attributes()->IsMutable()
3490 || (!myPArray->Indices().IsNull() && !myPArray->Indices()->IsMutable()))
3492 Message::SendFail ("Syntax error: array cannot be patched");
3493 return Standard_False;
3496 myPArray->Attributes()->NbElements = aVertexNum;
3497 if (Handle(Graphic3d_AttribBuffer) anAttribs = Handle(Graphic3d_AttribBuffer)::DownCast (myPArray->Attributes()))
3499 anAttribs->Invalidate (0, aVertexNum - 1);
3501 if (!myPArray->Indices().IsNull())
3503 myPArray->Indices()->NbElements = aEdgeNum;
3505 if (!myPArray->Bounds().IsNull())
3507 myPArray->Bounds()->NbBounds = aBoundNum;
3511 Standard_Integer aVertIndex = 0;
3512 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3514 aCommand = theDesc->Value (anArgIndex);
3515 aCommand.LowerCase();
3516 if (!aCommand.IsAscii()
3517 || aCommand.IsEmpty())
3522 // skip beautifiers (syntax is not actually validated)
3523 if (aCommand == "-deinterleaved"
3524 || aCommand == "-mutable"
3525 || aCommand.Value (1) == '('
3526 || aCommand.Value (1) == ')'
3527 || aCommand.Value (1) == ',')
3532 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3534 const Graphic3d_Vec3 aVert ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3535 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3536 (float )theDesc->Value (anArgIndex - 1).RealValue());
3537 if ((anArrayFlags & Graphic3d_ArrayFlags_AttribsDeinterleaved) != 0
3538 || (anArrayFlags & Graphic3d_ArrayFlags_AttribsMutable) != 0)
3541 myPArray->SetVertice (aVertIndex, aVert.x(), aVert.y(), aVert.z());
3545 aVertIndex = myPArray->AddVertex (aVert);
3548 // vertex has a normal or normal with color or texel
3549 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3551 const Graphic3d_Vec3 aNorm ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3552 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3553 (float )theDesc->Value (anArgIndex - 1).RealValue());
3554 myPArray->SetVertexNormal (aVertIndex, aNorm.x(), aNorm.y(), aNorm.z());
3557 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3559 const Graphic3d_Vec3d aCol (theDesc->Value (anArgIndex - 3).RealValue(),
3560 theDesc->Value (anArgIndex - 2).RealValue(),
3561 theDesc->Value (anArgIndex - 1).RealValue());
3562 myPArray->SetVertexColor (aVertIndex, aCol.r(), aCol.g(), aCol.b());
3564 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3566 const Graphic3d_Vec2 aTex ((float )theDesc->Value (anArgIndex - 2).RealValue(),
3567 (float )theDesc->Value (anArgIndex - 1).RealValue());
3568 myPArray->SetVertexTexel (aVertIndex, aTex.x(), aTex.y());
3572 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3574 Standard_Integer aVertCount = theDesc->Value (anArgIndex - 1).IntegerValue();
3576 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3577 myPArray->AddBound (aVertCount,
3578 theDesc->Value (anArgIndex - 3).RealValue(),
3579 theDesc->Value (anArgIndex - 2).RealValue(),
3580 theDesc->Value (anArgIndex - 1).RealValue());
3583 myPArray->AddBound (aVertCount);
3586 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3588 const Standard_Integer anEdge = theDesc->Value (anArgIndex - 1).IntegerValue();
3589 myPArray->AddEdge (anEdge);
3594 Message::SendFail() << "Syntax error: unknown argument '" << theDesc->Value(anArgIndex) << "'";
3595 return Standard_False;
3598 return Standard_True;
3601 //=======================================================================
3602 // function : SetColor
3604 //=======================================================================
3605 void MyPArrayObject::SetColor (const Quantity_Color& theColor)
3607 AIS_InteractiveObject::SetColor (theColor);
3608 setColorForShadingAspect (theColor);
3611 myMarkerAspect->SetColor (theColor);
3613 SynchronizeAspects();
3616 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3617 const Standard_Integer theMode)
3620 || myPArray.IsNull())
3625 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
3626 if (Handle(Graphic3d_ArrayOfTriangles) aTris = Handle(Graphic3d_ArrayOfTriangles)::DownCast (myPArray))
3628 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3629 aSensitive->InitTriangulation (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3630 theSelection->Add (aSensitive);
3632 else if (Handle(Graphic3d_ArrayOfSegments) aSegs = Handle(Graphic3d_ArrayOfSegments)::DownCast (myPArray))
3634 if (aSegs->EdgeNumber() > 0)
3636 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->EdgeNumber(); aPntIter += 2)
3638 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aSegs->Edge (aPntIter)), aSegs->Vertice (aSegs->Edge (aPntIter + 1)));
3639 aSeg->SetSensitivityFactor (4);
3640 theSelection->Add (aSeg);
3645 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->VertexNumber(); aPntIter += 2)
3647 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aPntIter), aSegs->Vertice (aPntIter + 1));
3648 aSeg->SetSensitivityFactor (4);
3649 theSelection->Add (aSeg);
3655 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3656 aSensitive->SetSensitivityFactor (8);
3657 aSensitive->InitPoints (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3658 theSelection->Add (aSensitive);
3662 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3663 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3664 Standard_Integer &theArgIndex,
3665 Standard_Integer theArgCount,
3666 Standard_Integer theMaxArgs)
3668 // check if there is more elements than expected
3669 if (theArgIndex >= theMaxArgs)
3672 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3673 aStrCommand.LowerCase();
3674 if (aStrCommand.Search(theCommand) != 1 ||
3675 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3678 // go to the first data element
3681 // check data if it can be converted to numeric
3682 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3684 aStrCommand = theArgsArray->Value (theArgIndex);
3685 if (!aStrCommand.IsRealValue())
3692 //=======================================================================
3693 // function : setColorForShadingAspect
3695 //=======================================================================
3696 void MyPArrayObject::setColorForShadingAspect (const Quantity_Color& theColor)
3698 if (myDrawer->SetupOwnShadingAspect())
3700 replaceShadingAspect();
3702 myDrawer->ShadingAspect()->SetColor (theColor);
3705 //=======================================================================
3706 // function : replaceShadingAspect
3708 //=======================================================================
3709 void MyPArrayObject::replaceShadingAspect()
3711 if (!myDrawer->Link())
3715 Graphic3d_MapOfAspectsToAspects anAspectReplacementMap;
3716 anAspectReplacementMap.Bind (myDrawer->Link()->ShadingAspect()->Aspect(), myDrawer->ShadingAspect()->Aspect());
3717 replaceAspects (anAspectReplacementMap);
3720 //=============================================================================
3721 //function : VDrawPArray
3722 //purpose : Draws primitives array from list of vertexes, bounds, edges
3723 //=============================================================================
3725 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3727 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3728 if (aContextAIS.IsNull())
3730 Message::SendFail ("Error: no active Viewer");
3735 Message::SendFail ("Syntax error: wrong number of arguments");
3739 // read the arguments
3740 Standard_Integer anArgIndex = 1;
3741 TCollection_AsciiString aName (argv[anArgIndex++]);
3742 TCollection_AsciiString anArrayType (argv[anArgIndex++]);
3743 anArrayType.LowerCase();
3744 Handle(MyPArrayObject) aPObject;
3745 if (anArrayType == "-shape")
3747 Standard_CString aShapeName = argv[anArgIndex++];
3748 TopoDS_Shape aShape = DBRep::Get (aShapeName);
3749 Handle(Graphic3d_ArrayOfPrimitives) aTris = StdPrs_ShadedShape::FillTriangles (aShape);
3750 if (aShape.IsNull())
3752 Message::SendFail() << "Syntax error: shape '" << aShapeName << "' is not found";
3755 else if (aTris.IsNull())
3757 Message::SendFail() << "Syntax error: shape '" << aShapeName << "' is not triangulated";
3761 aPObject = new MyPArrayObject (aTris);
3762 ViewerTest::Display (aName, aPObject);
3765 else if (anArrayType == "-patch"
3766 || anArrayType == "-modify"
3767 || anArrayType == "-edit")
3771 anArrayType = argv[anArgIndex++];
3772 anArrayType.LowerCase();
3775 if (GetMapOfAIS().IsBound2 (aName))
3777 aPObject = Handle(MyPArrayObject)::DownCast (GetMapOfAIS().Find2 (aName));
3779 if (aPObject.IsNull())
3781 Message::SendFail() << "Syntax error: object '" << aName << "' cannot be found";
3786 Standard_Boolean hasVertex = Standard_False;
3788 Graphic3d_TypeOfPrimitiveArray aPrimType = Graphic3d_TOPA_UNDEFINED;
3789 if (anArrayType == "points")
3791 aPrimType = Graphic3d_TOPA_POINTS;
3793 else if (anArrayType == "segments")
3795 aPrimType = Graphic3d_TOPA_SEGMENTS;
3797 else if (anArrayType == "polylines")
3799 aPrimType = Graphic3d_TOPA_POLYLINES;
3801 else if (anArrayType == "triangles")
3803 aPrimType = Graphic3d_TOPA_TRIANGLES;
3805 else if (anArrayType == "trianglefans")
3807 aPrimType = Graphic3d_TOPA_TRIANGLEFANS;
3809 else if (anArrayType == "trianglestrips")
3811 aPrimType = Graphic3d_TOPA_TRIANGLESTRIPS;
3813 else if (anArrayType == "quads")
3815 aPrimType = Graphic3d_TOPA_QUADRANGLES;
3817 else if (anArrayType == "quadstrips")
3819 aPrimType = Graphic3d_TOPA_QUADRANGLESTRIPS;
3821 else if (anArrayType == "polygons")
3823 aPrimType = Graphic3d_TOPA_POLYGONS;
3825 if (aPrimType == Graphic3d_TOPA_UNDEFINED)
3827 Message::SendFail ("Syntax error: unexpected type of primitives array");
3831 Standard_Integer aLowerArg = anArgIndex;
3832 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 3);
3833 for (; anArgIndex < argc; ++anArgIndex)
3835 TCollection_AsciiString aCommand (argv[anArgIndex]);
3836 aCommand.LowerCase();
3837 if (!aCommand.IsAscii())
3839 di << "Unexpected argument: #" << anArgIndex - 1 << " , "
3840 << "should be an array element: 'v', 'b', 'e' \n";
3844 if (aCommand == "v")
3846 hasVertex = Standard_True;
3849 anArgsArray->SetValue (anArgIndex - aLowerArg, aCommand);
3854 di << "You should pass any verticies in the list of array elements\n";
3858 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3859 if (aPrimType == Graphic3d_TOPA_POINTS)
3861 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3864 // create primitives array object
3865 if (aPObject.IsNull())
3867 // register the object in map
3868 aPObject = new MyPArrayObject (aPrimType, anArgsArray, anAspPoints);
3869 VDisplayAISObject (aName, aPObject);
3873 aPObject->Init (aPrimType, anArgsArray, anAspPoints, Standard_True);
3874 ViewerTest::CurrentView()->Redraw();
3881 //! Auxiliary function for parsing translation vector - either 2D or 3D.
3882 static Standard_Integer parseTranslationVec (Standard_Integer theArgNb,
3883 const char** theArgVec,
3891 TCollection_AsciiString anX (theArgVec[0]);
3892 TCollection_AsciiString anY (theArgVec[1]);
3893 if (!anX.IsRealValue()
3894 || !anY.IsRealValue())
3899 theVec.SetX (anX.RealValue());
3900 theVec.SetY (anY.RealValue());
3903 TCollection_AsciiString anZ (theArgVec[2]);
3904 if (anZ.IsRealValue())
3906 theVec.SetZ (anZ.RealValue());
3914 //=======================================================================
3915 //function : VSetLocation
3916 //purpose : Change location of AIS interactive object
3917 //=======================================================================
3919 static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
3920 Standard_Integer theArgNb,
3921 const char** theArgVec)
3923 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3924 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3925 if (aContext.IsNull())
3927 Message::SendFail ("Error: no active viewer");
3931 Standard_Boolean toPrintInfo = Standard_True;
3932 Handle(AIS_InteractiveObject) anObj;
3933 TCollection_AsciiString aCmdName (theArgVec[0]);
3934 aCmdName.LowerCase();
3935 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3937 TCollection_AsciiString anArg = theArgVec[anArgIter];
3939 if (anUpdateTool.parseRedrawMode (anArg))
3943 else if (anObj.IsNull())
3945 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3946 GetMapOfAIS().Find2 (aName, anObj);
3949 Message::SendFail() << "Error: object '" << aName << "' is not displayed";
3953 else if (anArg == "-reset")
3955 toPrintInfo = Standard_False;
3956 aContext->SetLocation (anObj, gp_Trsf());
3958 else if (anArg == "-copyfrom"
3959 || anArg == "-copy")
3961 if (anArgIter + 1 >= theArgNb)
3963 Message::SendFail() << "Syntax error at '" << anArg << "'";
3967 const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]);
3968 Handle(AIS_InteractiveObject) anObj2;
3969 GetMapOfAIS().Find2 (aName2, anObj2);
3970 if (anObj2.IsNull())
3972 Message::SendFail() << "Error: object '" << aName2 << "' is not displayed";
3977 aContext->SetLocation (anObj, anObj2->LocalTransformation());
3979 else if (anArg == "-rotate"
3980 || anArg == "-prerotate")
3982 toPrintInfo = Standard_False;
3983 if (anArgIter + 7 >= theArgNb)
3985 Message::SendFail() << "Syntax error at '" << anArg << "'";
3990 aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]),
3991 Draw::Atof (theArgVec[anArgIter + 2]),
3992 Draw::Atof (theArgVec[anArgIter + 3])),
3993 gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]),
3994 Draw::Atof (theArgVec[anArgIter + 5]),
3995 Draw::Atof (theArgVec[anArgIter + 6]))),
3996 Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0));
3999 if (anArg == "-prerotate")
4001 aTrsf = anObj->LocalTransformation() * aTrsf;
4005 aTrsf = aTrsf * anObj->LocalTransformation();
4007 aContext->SetLocation (anObj, aTrsf);
4009 else if (anArg == "-translate"
4010 || anArg == "-pretranslate")
4012 toPrintInfo = Standard_False;
4014 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
4015 anArgIter += aNbParsed;
4018 Message::SendFail() << "Syntax error at '" << anArg << "'";
4023 aTrsf.SetTranslationPart (aLocVec);
4024 if (anArg == "-pretranslate")
4026 aTrsf = anObj->LocalTransformation() * aTrsf;
4030 aTrsf = aTrsf * anObj->LocalTransformation();
4032 aContext->SetLocation (anObj, aTrsf);
4034 else if (anArg == "-scale"
4035 || anArg == "-prescale"
4036 || anArg == "-setscale")
4038 toPrintInfo = Standard_False;
4040 Standard_Real aScale = 1.0;
4041 Standard_Boolean toPrintScale = Standard_True;
4042 Standard_Boolean hasScaleLoc = Standard_False;
4043 if (anArgIter + 4 < theArgNb)
4045 TCollection_AsciiString aScaleArgs[4] =
4047 TCollection_AsciiString (theArgVec[anArgIter + 1]),
4048 TCollection_AsciiString (theArgVec[anArgIter + 2]),
4049 TCollection_AsciiString (theArgVec[anArgIter + 3]),
4050 TCollection_AsciiString (theArgVec[anArgIter + 4])
4052 Standard_Integer aScaleArgIter = 0;
4053 for (; aScaleArgIter < 4; ++aScaleArgIter)
4055 if (!aScaleArgs[aScaleArgIter].IsRealValue())
4060 if (aScaleArgIter == 4)
4062 aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue());
4063 aScale = aScaleArgs[3].RealValue();
4065 toPrintScale = Standard_False;
4066 hasScaleLoc = Standard_True;
4068 else if (aScaleArgIter >= 1)
4070 aScale = aScaleArgs[0].RealValue();
4072 toPrintScale = Standard_False;
4075 else if (anArgIter + 1 < theArgNb)
4077 TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]);
4078 if (aScaleArg.IsRealValue())
4080 aScale = aScaleArg.RealValue();
4082 toPrintScale = Standard_False;
4088 if (anArg == "-setscale"
4089 || anArg == "-prescale")
4091 Message::SendFail() << "Syntax error at '" << anArg << "'";
4096 Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor());
4101 if (anArg == "-setscale")
4103 gp_Trsf aTrsf = anObj->LocalTransformation();
4106 aTrsf.SetScale (aScaleLoc, aScale);
4110 aTrsf.SetScaleFactor (aScale);
4112 aContext->SetLocation (anObj, aTrsf);
4119 aTrsf.SetScale (aScaleLoc, aScale);
4123 aTrsf.SetScaleFactor (aScale);
4126 if (anArg == "-prescale")
4128 aTrsf = anObj->LocalTransformation() * aTrsf;
4132 aTrsf = aTrsf * anObj->LocalTransformation();
4134 aContext->SetLocation (anObj, aTrsf);
4137 else if (anArg == "-mirror"
4138 || anArg == "-premirror")
4140 toPrintInfo = Standard_False;
4141 if (anArgIter + 6 >= theArgNb)
4143 Message::SendFail() << "Syntax error at '" << anArg << "'";
4148 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
4149 Draw::Atof(theArgVec[theArgNb - 5]),
4150 Draw::Atof(theArgVec[theArgNb - 4])),
4151 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
4152 Draw::Atof(theArgVec[theArgNb - 2]),
4153 Draw::Atof(theArgVec[theArgNb - 1]))));
4155 if (anArg == "-premirror")
4157 aTrsf = anObj->LocalTransformation() * aTrsf;
4161 aTrsf = aTrsf * anObj->LocalTransformation();
4163 aContext->SetLocation (anObj, aTrsf);
4165 else if (anArg == "-setrotation"
4166 || anArg == "-rotation")
4168 toPrintInfo = Standard_False;
4169 if (anArgIter + 4 < theArgNb)
4171 TCollection_AsciiString aQuatArgs[4] =
4173 TCollection_AsciiString (theArgVec[anArgIter + 1]),
4174 TCollection_AsciiString (theArgVec[anArgIter + 2]),
4175 TCollection_AsciiString (theArgVec[anArgIter + 3]),
4176 TCollection_AsciiString (theArgVec[anArgIter + 4])
4178 Standard_Integer aQuatArgIter = 0;
4179 for (; aQuatArgIter < 4; ++aQuatArgIter)
4181 if (!aQuatArgs[aQuatArgIter].IsRealValue())
4187 if (aQuatArgIter == 4)
4190 const gp_Quaternion aQuat (aQuatArgs[0].RealValue(),
4191 aQuatArgs[1].RealValue(),
4192 aQuatArgs[2].RealValue(),
4193 aQuatArgs[3].RealValue());
4194 gp_Trsf aTrsf = anObj->LocalTransformation();
4195 aTrsf.SetRotationPart (aQuat);
4196 aContext->SetLocation (anObj, aTrsf);
4199 else if (anArg == "-setrotation")
4201 Message::SendFail() << "Syntax error at '" << anArg << "'";
4207 const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation();
4208 Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W());
4211 else if (anArg == "-setlocation"
4212 || anArg == "-location")
4214 toPrintInfo = Standard_False;
4216 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
4217 anArgIter += aNbParsed;
4220 gp_Trsf aTrsf = anObj->LocalTransformation();
4221 aTrsf.SetTranslationPart (aLocVec);
4222 aContext->SetLocation (anObj, aTrsf);
4224 else if (anArg == "-setlocation")
4226 Message::SendFail() << "Syntax error at '" << anArg << "'";
4231 const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart();
4232 Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z());
4235 else if (aCmdName == "vsetlocation")
4237 // compatibility with old syntax
4239 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec);
4242 Message::SendFail() << "Syntax error at '" << anArg << "'";
4245 anArgIter = anArgIter + aNbParsed - 1;
4248 aTrsf.SetTranslationPart (aLocVec);
4249 aContext->SetLocation (anObj, aTrsf);
4250 toPrintInfo = Standard_False;
4254 Message::SendFail() << "Error: unknown argument '" << anArg << "'";
4261 Message::SendFail ("Syntax error - wrong number of arguments");
4264 else if (!toPrintInfo)
4269 const gp_Trsf aTrsf = anObj->LocalTransformation();
4270 const gp_XYZ aLoc = aTrsf.TranslationPart();
4271 const gp_Quaternion aRot = aTrsf.GetRotation();
4273 Sprintf (aText, "Location: %g %g %g\n"
4274 "Rotation: %g %g %g %g\n"
4276 aLoc.X(), aLoc.Y(), aLoc.Z(),
4277 aRot.X(), aRot.Y(), aRot.Z(), aRot.W(),
4278 aTrsf.ScaleFactor());
4283 //! Find displayed object.
4284 static Handle(AIS_InteractiveObject) findConnectedObject (const TCollection_AsciiString& theName)
4286 Handle(AIS_InteractiveObject) aPrs;
4287 if (!GetMapOfAIS().Find2 (theName, aPrs))
4289 return Handle(AIS_InteractiveObject)();
4291 if (Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (aPrs))
4295 else if (Handle(AIS_MultipleConnectedInteractive) aMultiCon = Handle(AIS_MultipleConnectedInteractive)::DownCast (aPrs))
4300 // replace already displayed object with connected one
4301 TheAISContext()->Remove (aPrs, false);
4302 Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive();
4303 if (aPrs->HasDisplayMode())
4305 aConnected->SetDisplayMode (aPrs->DisplayMode());
4307 aConnected->Connect (aPrs, aPrs->LocalTransformationGeom());
4308 if (!aPrs->TransformPersistence().IsNull())
4310 aConnected->SetTransformPersistence (aPrs->TransformPersistence());
4312 ViewerTest::Display (theName, aConnected, false);
4316 //===============================================================================================
4317 //function : VConnect
4318 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4319 //===============================================================================================
4320 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
4321 Standard_Integer argc,
4324 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4325 if (aContext.IsNull())
4327 Message::SendFail ("Error: no active viewer");
4332 Message::SendFail ("Syntax error: expect at least 5 arguments");
4337 Standard_Integer anArgIter = 1;
4338 const TCollection_AsciiString aName (argv[anArgIter++]);
4339 Handle(AIS_MultipleConnectedInteractive) aMultiConObject;
4340 TCollection_AsciiString aColorString (argv[argc-1]);
4341 Quantity_Color aColor;
4342 Standard_Boolean hasColor = Standard_False;
4343 if (aColorString.Search ("color=") != -1)
4345 hasColor = Standard_True;
4346 aColorString.Remove (1, 6);
4347 if (!Quantity_Color::ColorFromName (aColorString.ToCString(), aColor))
4349 Message::SendFail() << "Syntax error at " << aColorString;
4354 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
4355 for (Standard_Integer i = 5; i < aNbShapes; ++i)
4357 TCollection_AsciiString anOriginObjectName (argv[i]);
4358 Handle(AIS_InteractiveObject) anObject;
4359 if (aName.IsEqual (anOriginObjectName))
4361 Message::SendFail ("Syntax error: equal names for connected objects");
4365 anObject = findConnectedObject (anOriginObjectName);
4366 if (anObject.IsNull())
4368 TopoDS_Shape aTDShape = DBRep::Get (anOriginObjectName);
4369 if (aTDShape.IsNull())
4371 Message::SendFail() << "Syntax error: object " << anOriginObjectName << " doesn't exist";
4374 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aTDShape);
4375 Handle(AIS_ConnectedInteractive) aConnectedOrig = new AIS_ConnectedInteractive();
4376 aConnectedOrig->Connect (aShapePrs);
4377 anObject = aConnectedOrig;
4379 aContext->Load (anObject);
4380 anObject->SetColor (aColor);
4383 if (aMultiConObject.IsNull())
4385 aMultiConObject = new AIS_MultipleConnectedInteractive();
4388 aMultiConObject->Connect (anObject);
4390 if (aMultiConObject.IsNull())
4392 Message::SendFail ("Syntax error: can't connect input objects");
4396 // Create transformation
4398 aTrsf.SetTranslationPart (gp_Vec (Draw::Atof (argv[anArgIter + 0]),
4399 Draw::Atof (argv[anArgIter + 1]),
4400 Draw::Atof (argv[anArgIter + 2])));
4401 TopLoc_Location aLocation (aTrsf);
4404 aMultiConObject->SetLocalTransformation (aTrsf);
4406 ViewerTest::Display (aName, aMultiConObject, true);
4410 //===============================================================================================
4411 //function : VConnectTo
4412 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4413 //===============================================================================================
4414 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
4415 Standard_Integer argc,
4418 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4419 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4420 if (aContext.IsNull())
4422 Message::SendFail ("Error: no active viewer");
4425 if (argc != 6 && argc != 7)
4427 Message::SendFail ("Syntax error: expect at least 5 arguments");
4431 Standard_Integer anArgIter = 1;
4432 TCollection_AsciiString aName (argv[anArgIter++]);
4433 Handle(AIS_InteractiveObject) anOriginObject;
4435 TCollection_AsciiString anOriginObjectName(argv[5]);
4436 if (aName.IsEqual (anOriginObjectName))
4438 Message::SendFail ("Syntax error: equal names for connected objects");
4441 anOriginObject = findConnectedObject (anOriginObjectName);
4442 if (anOriginObject.IsNull())
4444 TopoDS_Shape aTDShape = DBRep::Get (anOriginObjectName);
4445 if (aTDShape.IsNull())
4447 Message::SendFail() << "Syntax error: object " << anOriginObjectName << " doesn't exist";
4451 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aTDShape);
4452 Handle(AIS_ConnectedInteractive) aConnectedOrig = new AIS_ConnectedInteractive();
4453 aConnectedOrig->Connect (aShapePrs);
4455 anOriginObject = aConnectedOrig;
4456 GetMapOfAIS().Bind (aConnectedOrig, anOriginObjectName);
4459 // Create transformation
4461 aTrsf.SetTranslationPart (gp_Vec (Draw::Atof (argv[anArgIter + 0]),
4462 Draw::Atof (argv[anArgIter + 1]),
4463 Draw::Atof (argv[anArgIter + 2])));
4466 Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive();
4467 aConnected->Connect (anOriginObject, aTrsf);
4470 TCollection_AsciiString anArg = argv[6];
4472 if (anArg == "-nodisplay")
4474 // bind connected object without displaying it
4475 Handle(AIS_InteractiveObject) anObj;
4476 if (GetMapOfAIS().Find2 (aName, anObj))
4478 TheAISContext()->Remove (anObj, false);
4479 GetMapOfAIS().UnBind2 (aName);
4481 GetMapOfAIS().Bind (aConnected, aName);
4485 if (!anUpdateTool.parseRedrawMode (anArg))
4487 Message::SendFail() << "Syntax error: unknown argument '" << anArg << "'";
4492 ViewerTest::Display (aName, aConnected, false);
4496 //=======================================================================
4497 //function : VDisconnect
4499 //=======================================================================
4500 static Standard_Integer VDisconnect (Draw_Interpretor& di,
4501 Standard_Integer argc,
4504 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4505 if (aContext.IsNull())
4507 Message::SendFail( "Error: no active viewer");
4513 Message::SendFail() << "Syntax error: wrong number of arguments.\nUsage: " << argv[0] << " name object";
4517 TCollection_AsciiString aName (argv[1]);
4518 TCollection_AsciiString anObject (argv[2]);
4519 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
4522 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4523 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4524 if (!aMap.IsBound2 (aName) )
4526 Message::SendFail ("Error: no active viewer");
4530 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4531 if (anAssembly.IsNull())
4533 di << "Not an assembly\n";
4537 Handle(AIS_InteractiveObject) anIObj;
4538 if (!aMap.Find2 (anObject, anIObj))
4540 // try to interpret second argument as child number
4541 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
4543 Standard_Integer aCounter = 1;
4544 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4546 if (aCounter == anObjectNumber)
4548 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4556 Message::SendFail ("Error: no active viewer");
4561 aContext->Disconnect (anAssembly, anIObj);
4562 aContext->UpdateCurrentViewer();
4566 //=======================================================================
4567 //function : VAddConnected
4569 //=======================================================================
4570 static Standard_Integer VAddConnected (Draw_Interpretor& ,
4571 Standard_Integer argc,
4574 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4575 if (aContext.IsNull())
4577 Message::SendFail ("Error: no active viewer");
4583 Message::SendFail ("Syntax error: expect 5 arguments");
4587 const TCollection_AsciiString aName (argv[1]);
4588 const Standard_Real aX = Draw::Atof (argv[2]);
4589 const Standard_Real aY = Draw::Atof (argv[3]);
4590 const Standard_Real aZ = Draw::Atof (argv[4]);
4591 const TCollection_AsciiString anObjectName (argv[5]);
4594 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4595 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4597 Handle(AIS_InteractiveObject) aPrs;
4598 aMap.Find2 (aName, aPrs);
4599 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aPrs);
4600 if (anAssembly.IsNull())
4602 Message::SendFail() << "Syntax error: '" << aName << "' is not an assembly";
4607 Handle(AIS_InteractiveObject) anIObj = findConnectedObject (anObjectName);
4608 if (anIObj.IsNull())
4610 Message::SendFail() << "Syntax error: '" << anObjectName << "' is not displayed";
4615 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4617 anAssembly->Connect (anIObj, aTrsf);
4618 TheAISContext()->Display (anAssembly, Standard_False);
4619 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4620 aContext->UpdateCurrentViewer();
4624 //=======================================================================
4625 //function : VListConnected
4627 //=======================================================================
4628 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4629 Standard_Integer argc,
4632 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4633 if (aContext.IsNull())
4635 Message::SendFail ("Error: no active viewer");
4641 Message::SendFail() << "Syntax error: wrong number of arguments.\nUsage: " << argv[0] << " name";
4645 TCollection_AsciiString aName (argv[1]);
4648 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4649 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4650 if (!aMap.IsBound2 (aName) )
4652 Message::SendFail ("Error: no active viewer");
4656 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4657 if (anAssembly.IsNull())
4659 Message::SendFail ("Syntax error: Not an assembly");
4663 std::cout << "Children of " << aName << ":\n";
4665 Standard_Integer aCounter = 1;
4666 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4668 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4669 if (GetMapOfAIS().IsBound1 (anObj))
4671 TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anObj);
4672 std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4675 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4677 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4678 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4680 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4682 std::cout << std::endl;
4690 //=======================================================================
4693 //=======================================================================
4694 static Standard_Integer VChild (Draw_Interpretor& ,
4695 Standard_Integer theNbArgs,
4696 const char** theArgVec)
4698 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4699 if (aContext.IsNull())
4701 Message::SendFail ("Error: no active viewer");
4706 Handle(AIS_InteractiveObject) aParent;
4707 bool hasActions = false;
4708 int toInheritTrsf = -1;
4709 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4710 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4712 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4714 if (anUpdateTool.parseRedrawMode (anArg))
4718 else if (anArg == "-add")
4723 else if (anArg == "-remove")
4728 else if (anArg == "-inheritparenttrsf"
4729 || anArg == "-inheritparentloc"
4730 || anArg == "-inheritparentlocation"
4731 || anArg == "-inheritparent"
4732 || anArg == "-noinheritparenttrsf"
4733 || anArg == "-noinheritparentloc"
4734 || anArg == "-noinheritparentlocation"
4735 || anArg == "-noinheritparent"
4736 || anArg == "-ignoreparenttrsf"
4737 || anArg == "-ignoreparentloc"
4738 || anArg == "-ignoreparentlocation"
4739 || anArg == "-ignoreparent")
4742 if (anArgIter + 1 < theNbArgs
4743 && Draw::ParseOnOff(theArgVec[anArgIter + 1], aVal))
4747 if (anArg.StartsWith("-no")
4748 || anArg.StartsWith("-ignore"))
4752 toInheritTrsf = aVal ? 1 : 0;
4756 Handle(AIS_InteractiveObject) aChild;
4757 if (!GetMapOfAIS().Find2 (theArgVec[anArgIter], aChild))
4759 Message::SendFail() << "Syntax error: object '" << theArgVec[anArgIter] << "' is not found";
4763 if (aParent.IsNull())
4767 else if (toAdd == -1)
4769 Message::SendFail ("Syntax error: no action specified");
4777 if(toInheritTrsf == 0)
4778 aParent->AddChildWithCurrentTransformation(aChild);
4780 aParent->AddChild (aChild);
4784 if (toInheritTrsf == 0)
4785 aParent->RemoveChildWithRestoreTransformation(aChild);
4787 aParent->RemoveChild (aChild);
4793 Message::SendFail ("Syntax error: not enough arguments");
4799 //=======================================================================
4800 //function : VParent
4802 //=======================================================================
4803 static Standard_Integer VParent(Draw_Interpretor&,
4804 Standard_Integer theNbArgs,
4805 const char** theArgVec)
4807 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4808 if (aContext.IsNull())
4810 Message::SendFail ("Error: no active viewer");
4816 Message::SendFail ("Syntax error: wrong number of arguments");
4820 TCollection_AsciiString aName(theArgVec[1]);
4821 Handle(AIS_InteractiveObject) aParent;
4822 if (!GetMapOfAIS().Find2(theArgVec[1], aParent))
4824 Message::SendFail() << "Syntax error: object '" << theArgVec[1] << "' is not found";
4828 ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
4829 for (Standard_Integer anArgIter = 2; anArgIter < theNbArgs; ++anArgIter)
4831 TCollection_AsciiString anArg(theArgVec[anArgIter]);
4833 if (anArg == "-ignorevisu")
4834 aParent->SetPropagateVisualState(Standard_False);
4839 //===============================================================================================
4840 //function : VSetSelectionMode
4841 //purpose : vselmode
4842 //===============================================================================================
4843 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4844 Standard_Integer theNbArgs,
4845 const char** theArgv)
4848 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4849 if (anAISContext.IsNull())
4851 Message::SendFail ("Error: no active Viewer");
4855 NCollection_Sequence<TCollection_AsciiString> anObjNames;
4856 Standard_Integer aSelectionMode = -1;
4857 Standard_Boolean toTurnOn = Standard_True;
4858 AIS_SelectionModesConcurrency aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4859 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4861 TCollection_AsciiString anArgCase (theArgv[anArgIter]);
4862 anArgCase.LowerCase();
4863 if (anArgCase == "-set"
4864 || anArgCase == "-replace"
4865 || anArgCase == "-single"
4866 || anArgCase == "-exclusive")
4868 aSelModeConcurrency = AIS_SelectionModesConcurrency_Single;
4870 else if (anArgCase == "-add"
4871 || anArgCase == "-combine"
4872 || anArgCase == "-combination"
4873 || anArgCase == "-multiple")
4875 aSelModeConcurrency = AIS_SelectionModesConcurrency_Multiple;
4877 else if (anArgCase == "-globalorlocal"
4878 || anArgCase == "-localorglobal")
4880 aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4884 anObjNames.Append (theArgv[anArgIter]);
4887 if (anObjNames.Size() < 2
4888 || !Draw::ParseOnOff (anObjNames.Last().ToCString(), toTurnOn))
4890 Message::SendFail ("Syntax error: wrong number of arguments");
4893 anObjNames.Remove (anObjNames.Upper());
4895 const TCollection_AsciiString aSelModeString = anObjNames.Last();
4896 anObjNames.Remove (anObjNames.Upper());
4897 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4898 if (aSelModeString.IsIntegerValue())
4900 aSelectionMode = aSelModeString.IntegerValue();
4902 else if (TopAbs::ShapeTypeFromString (aSelModeString.ToCString(), aShapeType))
4904 aSelectionMode = AIS_Shape::SelectionMode (aShapeType);
4908 Message::SendFail() << "Syntax error: unknown selection mode '" << aSelModeString << "'";
4913 AIS_ListOfInteractive aTargetIOs;
4914 for (NCollection_Sequence<TCollection_AsciiString>::Iterator anObjIter (anObjNames); anObjIter.More(); anObjIter.Next())
4916 const TCollection_AsciiString& aNameIO = anObjIter.Value();
4917 Handle(AIS_InteractiveObject) anIO;
4918 GetMapOfAIS().Find2 (aNameIO, anIO);
4921 Message::SendFail() << "Syntax error: undefined presentable object " << aNameIO;
4924 aTargetIOs.Append (anIO);
4926 if (aTargetIOs.IsEmpty())
4928 anAISContext->DisplayedObjects (aTargetIOs);
4931 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4933 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4934 anAISContext->SetSelectionModeActive (anIO, aSelectionMode, toTurnOn, aSelModeConcurrency);
4939 //===============================================================================================
4940 //function : VSelectionNext
4942 //===============================================================================================
4943 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4944 Standard_Integer /*theArgsNb*/,
4945 const char** /*theArgVec*/)
4948 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4949 Handle(V3d_View) aView = ViewerTest::CurrentView();
4951 if (anAISContext.IsNull())
4953 Message::SendFail ("Error: no active viewer");
4957 anAISContext->HilightNextDetected (aView);
4961 //===============================================================================================
4962 //function : VSelectionPrevious
4964 //===============================================================================================
4965 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4966 Standard_Integer /*theArgsNb*/,
4967 const char** /*theArgVec*/)
4970 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4971 Handle(V3d_View) aView = ViewerTest::CurrentView();
4973 if (anAISContext.IsNull())
4975 Message::SendFail ("Error: no active viewer");
4979 anAISContext->HilightPreviousDetected (aView);
4983 //===========================================================================
4984 //function : VTriangle
4985 //Draw arg : vtriangle Name PointName PointName PointName
4986 //purpose : creates and displays Triangle
4987 //===========================================================================
4988 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4989 Standard_Integer argc,
4992 const Standard_Boolean isTri = TCollection_AsciiString (argv[0]) == "vtriangle";
4993 Handle(Graphic3d_ArrayOfPrimitives) aPrims;
4996 aPrims = new Graphic3d_ArrayOfTriangles (3);
5000 aPrims = new Graphic3d_ArrayOfSegments (2);
5003 if (argc != (2 + aPrims->VertexNumberAllocated()))
5005 Message::SendFail ("Syntax error: wrong number of arguments");
5010 for (Standard_Integer aPntIter = 0; aPntIter < aPrims->VertexNumberAllocated(); ++aPntIter)
5012 const TCollection_AsciiString aName (argv[2 + aPntIter]);
5013 if (Handle(AIS_Point) aPntPrs = Handle(AIS_Point)::DownCast (GetMapOfAIS().IsBound2 (aName) ? GetMapOfAIS().Find2 (aName) : NULL))
5015 aPnts[aPntIter] = aPntPrs->Component()->Pnt();
5019 TopoDS_Shape aShape = DBRep::Get (argv[2 + aPntIter]);
5021 || aShape.ShapeType() != TopAbs_VERTEX)
5023 Message::SendFail() << "Syntax error: argument " << aName << " must be a point";
5026 aPnts[aPntIter] = BRep_Tool::Pnt (TopoDS::Vertex (aShape));
5029 for (Standard_Integer aPnt2Iter = 0; aPnt2Iter < aPntIter; ++aPnt2Iter)
5031 if (aPnts[aPnt2Iter].IsEqual (aPnts[aPntIter], Precision::Confusion()))
5033 Message::SendFail ("Syntax error: points should not be equal");
5038 aPrims->AddVertex (aPnts[aPntIter]);
5041 Handle(AIS_InteractiveObject) aPrs = new MyPArrayObject (aPrims);
5044 aPrs->Attributes()->SetupOwnShadingAspect();
5045 aPrs->Attributes()->ShadingAspect()->Aspect()->SetColor (aPrs->Attributes()->LineAspect()->Aspect()->Color());
5047 ViewerTest::Display (argv[1], aPrs);
5051 //=======================================================================
5052 //function : VObjZLayer
5053 //purpose : Set or get z layer id for presentable object
5054 //=======================================================================
5056 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
5057 Standard_Integer argc,
5060 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5061 if (aContext.IsNull())
5063 Message::SendFail ("Error: no active viewer");
5068 TCollection_AsciiString aOperation;
5070 aOperation = TCollection_AsciiString (argv [1]);
5072 // check for correct arguments
5073 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
5074 !(argc == 3 && aOperation.IsEqual ("get")))
5076 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
5077 di << " set - set layer id for interactive object, layerid - z layer id\n";
5078 di << " get - get layer id of interactive object\n";
5079 di << " argument layerid should be passed for set operation only\n";
5084 TCollection_AsciiString aName (argv[2]);
5085 Handle(AIS_InteractiveObject) anInterObj;
5086 GetMapOfAIS().Find2 (aName, anInterObj);
5087 if (anInterObj.IsNull())
5089 Message::SendFail() << "Syntax error: object '" << aName << "' is not displayed";
5093 // process operation
5094 if (aOperation.IsEqual ("set"))
5096 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
5097 aContext->SetZLayer (anInterObj, aLayerId);
5099 else if (aOperation.IsEqual ("get"))
5101 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
5107 //=======================================================================
5108 //function : VPolygonOffset
5109 //purpose : Set or get polygon offset parameters
5110 //=======================================================================
5111 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
5112 Standard_Integer argc,
5115 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5116 if (aContext.IsNull())
5118 Message::SendFail ("Error: no active viewer");
5122 if (argc > 2 && argc != 5)
5124 Message::SendFail() << "Syntax error: wrong number of arguments.\n"
5125 "Usage: " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
5126 "without arguments prints the default values";
5131 Handle(AIS_InteractiveObject) anInterObj;
5134 TCollection_AsciiString aName (argv[1]);
5135 if (!GetMapOfAIS().Find2 (aName, anInterObj)
5136 || anInterObj.IsNull())
5138 Message::SendFail() << "Syntax error: object '" << aName << "' is not displayed";
5143 Standard_Integer aMode;
5144 Standard_ShortReal aFactor, aUnits;
5147 aMode = Draw::Atoi(argv[2]);
5148 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
5149 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
5151 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
5152 aContext->UpdateCurrentViewer();
5157 if (anInterObj->HasPolygonOffsets())
5159 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
5160 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
5161 std::cout << "\tMode: " << aMode << std::endl;
5162 std::cout << "\tFactor: " << aFactor << std::endl;
5163 std::cout << "\tUnits: " << aUnits << std::endl;
5168 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
5172 std::cout << "Default polygon offset parameters:" << std::endl;
5173 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
5174 std::cout << "\tMode: " << aMode << std::endl;
5175 std::cout << "\tFactor: " << aFactor << std::endl;
5176 std::cout << "\tUnits: " << aUnits << std::endl;
5181 // This class is used for testing markers.
5182 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
5187 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
5188 const Standard_Integer& thePointsOnSide,
5189 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
5191 myStartPoint = theStartPoint;
5192 myPointsOnSide = thePointsOnSide;
5193 myMarkerAspect = theMarkerAspect;
5196 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_MarkersArrayObject,AIS_InteractiveObject);
5200 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
5201 const Handle(Prs3d_Presentation)& aPresentation,
5202 const Standard_Integer aMode) Standard_OVERRIDE;
5204 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5205 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
5209 gp_XYZ myStartPoint;
5210 Standard_Integer myPointsOnSide;
5211 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
5215 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
5216 const Handle(Prs3d_Presentation)& aPresentation,
5217 const Standard_Integer /*aMode*/)
5219 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
5220 if (myPointsOnSide == 1)
5222 anArray->AddVertex (myStartPoint);
5226 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5228 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5230 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5232 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5233 anArray->SetVertexColor (anArray->VertexNumber(),
5236 k / myPointsOnSide);
5242 aPresentation->Clear();
5243 if (!myMarkerAspect.IsNull())
5245 aPresentation->CurrentGroup()->SetGroupPrimitivesAspect (myMarkerAspect);
5247 aPresentation->CurrentGroup()->AddPrimitiveArray (anArray);
5250 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5251 const Standard_Integer /*theMode*/)
5253 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
5255 if (myPointsOnSide == 1)
5257 gp_Pnt aPoint (myStartPoint);
5258 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5259 theSelection->Add (aSensetivePoint);
5263 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5265 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5267 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5269 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5270 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5271 theSelection->Add (aSensetivePoint);
5277 //=======================================================================
5278 //function : VMarkersTest
5279 //purpose : Draws an array of markers for testing purposes.
5280 //=======================================================================
5281 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5282 Standard_Integer theArgNb,
5283 const char** theArgVec)
5285 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5286 if (aContext.IsNull())
5288 Message::SendFail ("Error: no active viewer");
5294 Message::SendFail ("Syntax error: wrong number of arguments");
5298 Standard_Integer anArgIter = 1;
5300 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5301 TCollection_AsciiString aFileName;
5302 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5303 Atof (theArgVec[anArgIter + 1]),
5304 Atof (theArgVec[anArgIter + 2]));
5307 Standard_Integer aPointsOnSide = 10;
5308 Standard_Integer aMarkerType = -1;
5309 Standard_Real aScale = 1.0;
5310 for (; anArgIter < theArgNb; ++anArgIter)
5312 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5313 if (anArg.Search ("PointsOnSide=") > -1)
5315 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5317 else if (anArg.Search ("MarkerType=") > -1)
5319 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5321 else if (anArg.Search ("Scale=") > -1)
5323 aScale = anArg.Token ("=", 2).RealValue();
5325 else if (anArg.Search ("FileName=") > -1)
5327 aFileName = anArg.Token ("=", 2);
5331 Message::SendFail() << "Syntax error: wrong argument '" << anArg << "'";
5336 Handle(Graphic3d_AspectMarker3d) anAspect;
5337 Handle(Image_AlienPixMap) anImage;
5338 Quantity_Color aColor (Quantity_NOC_GREEN1);
5339 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5340 && !aFileName.IsEmpty())
5342 anImage = new Image_AlienPixMap();
5343 if (!anImage->Load (aFileName))
5345 Message::SendFail() << "Error: could not load image from file '" << aFileName << "'!";
5348 if (anImage->Format() == Image_Format_Gray)
5350 anImage->SetFormat (Image_Format_Alpha);
5352 else if (anImage->Format() == Image_Format_GrayF)
5354 anImage->SetFormat (Image_Format_AlphaF);
5356 anAspect = new Graphic3d_AspectMarker3d (anImage);
5360 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5363 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5364 VDisplayAISObject (aName, aMarkersArray);
5369 //=======================================================================
5370 //function : TextToBrep
5371 //purpose : Tool for conversion text to occt-shapes
5372 //=======================================================================
5373 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5374 Standard_Integer theArgNb,
5375 const char** theArgVec)
5380 Message::SendFail() << "Error: " << theArgVec[0] << " - invalid syntax";
5384 Standard_Integer anArgIt = 1;
5385 Standard_CString aName = theArgVec[anArgIt++];
5386 Standard_CString aText = theArgVec[anArgIt++];
5388 Font_BRepFont aFont;
5389 TCollection_AsciiString aFontName ("Courier");
5390 Standard_Real aTextHeight = 16.0;
5391 Font_FontAspect aFontAspect = Font_FA_Regular;
5392 Standard_Boolean anIsCompositeCurve = Standard_False;
5393 gp_Ax3 aPenAx3 (gp::XOY());
5394 gp_Dir aNormal (0.0, 0.0, 1.0);
5395 gp_Dir aDirection (1.0, 0.0, 0.0);
5398 Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT;
5399 Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM;
5400 Font_StrictLevel aStrictLevel = Font_StrictLevel_Any;
5401 for (; anArgIt < theArgNb; ++anArgIt)
5403 TCollection_AsciiString aParam (theArgVec[anArgIt]);
5406 if (aParam == "-pos"
5407 || aParam == "-position")
5409 if (anArgIt + 3 >= theArgNb)
5411 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5415 aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt]));
5416 aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt]));
5417 aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt]));
5419 else if (aParam == "-halign")
5421 if (++anArgIt >= theArgNb)
5423 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5427 TCollection_AsciiString aType (theArgVec[anArgIt]);
5429 if (aType == "left")
5431 aHJustification = Graphic3d_HTA_LEFT;
5433 else if (aType == "center")
5435 aHJustification = Graphic3d_HTA_CENTER;
5437 else if (aType == "right")
5439 aHJustification = Graphic3d_HTA_RIGHT;
5443 Message::SendFail() << "Error: wrong syntax at '" << aParam << "'";
5447 else if (aParam == "-valign")
5449 if (++anArgIt >= theArgNb)
5451 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5455 TCollection_AsciiString aType (theArgVec[anArgIt]);
5459 aVJustification = Graphic3d_VTA_TOP;
5461 else if (aType == "center")
5463 aVJustification = Graphic3d_VTA_CENTER;
5465 else if (aType == "bottom")
5467 aVJustification = Graphic3d_VTA_BOTTOM;
5469 else if (aType == "topfirstline")
5471 aVJustification = Graphic3d_VTA_TOPFIRSTLINE;
5475 Message::SendFail() << "Error: wrong syntax at '" << aParam << "'";
5479 else if (aParam == "-height")
5481 if (++anArgIt >= theArgNb)
5483 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5487 aTextHeight = Draw::Atof(theArgVec[anArgIt]);
5489 else if (aParam == "-aspect")
5491 if (++anArgIt >= theArgNb)
5493 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5497 TCollection_AsciiString anOption (theArgVec[anArgIt]);
5498 anOption.LowerCase();
5499 if (!parseFontStyle (anOption, aFontAspect))
5501 Message::SendFail() << "Error: unknown font aspect '" << anOption << "'";
5505 else if (aParam == "-font")
5507 if (++anArgIt >= theArgNb)
5509 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5513 aFontName = theArgVec[anArgIt];
5515 else if (aParam == "-strict")
5517 anArgIt += parseFontStrictLevel (theArgNb - anArgIt - 1,
5518 theArgVec + anArgIt + 1,
5521 else if (aParam == "-composite")
5523 if (++anArgIt >= theArgNb)
5525 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5529 Draw::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve);
5531 else if (aParam == "-plane")
5533 if (anArgIt + 6 >= theArgNb)
5535 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
5539 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
5540 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
5541 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
5542 aNormal.SetCoord (aX, aY, aZ);
5544 aX = Draw::Atof (theArgVec[++anArgIt]);
5545 aY = Draw::Atof (theArgVec[++anArgIt]);
5546 aZ = Draw::Atof (theArgVec[++anArgIt]);
5547 aDirection.SetCoord (aX, aY, aZ);
5551 Message::SendFail() << "Warning! Unknown argument '" << aParam << "'";
5555 aFont.SetCompositeCurveMode (anIsCompositeCurve);
5556 if (!aFont.FindAndInit (aFontName.ToCString(), aFontAspect, aTextHeight, aStrictLevel))
5558 Message::SendFail ("Error: unable to load Font");
5562 aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection);
5564 Font_BRepTextBuilder aBuilder;
5565 DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification));
5569 //=======================================================================
5571 //purpose : Font management
5572 //=======================================================================
5573 struct FontComparator
5575 bool operator() (const Handle(Font_SystemFont)& theFontA,
5576 const Handle(Font_SystemFont)& theFontB)
5578 return theFontA->FontKey().IsLess (theFontB->FontKey());
5582 static int VFont (Draw_Interpretor& theDI,
5583 Standard_Integer theArgNb,
5584 const char** theArgVec)
5586 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5587 bool toPrintList = theArgNb < 2, toPrintNames = false;
5588 Font_StrictLevel aStrictLevel = Font_StrictLevel_Any;
5589 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5591 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5592 TCollection_AsciiString anArgCase (anArg);
5593 anArgCase.LowerCase();
5594 if (anArgCase == "-strict")
5596 anArgIter += parseFontStrictLevel (theArgNb - anArgIter - 1,
5597 theArgVec + anArgIter + 1,
5600 else if (anArgCase == "-clear")
5602 aMgr->ClearFontDataBase();
5604 else if (anArgCase == "-init")
5606 aMgr->InitFontDataBase();
5608 else if (anArgCase == "-list")
5612 else if (anArgCase == "-names")
5615 toPrintNames = true;
5617 else if (anArgIter + 1 < theArgNb
5618 && (anArgCase == "-find"
5619 || anArgCase == "-findinfo"
5620 || anArgCase == "-findall"
5621 || anArgCase == "find"))
5623 const TCollection_AsciiString aFontName (theArgVec[++anArgIter]);
5624 Font_FontAspect aFontAspect = Font_FA_Undefined;
5625 if (++anArgIter < theArgNb)
5627 anArgCase = theArgVec[anArgIter];
5628 anArgCase.LowerCase();
5629 if (!parseFontStyle (anArgCase, aFontAspect))
5635 const bool toFindAll = (anArgCase == "-findall");
5636 const bool toPrintInfo = (anArgCase == "-findinfo");
5637 TCollection_AsciiString aResult;
5639 || aFontName.Search ("*") != -1)
5641 const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts();
5642 std::vector<Handle(Font_SystemFont)> aFontsSorted;
5643 aFontsSorted.reserve (aFonts.Size());
5644 for (Font_NListOfSystemFont::Iterator aFontIter (aFonts); aFontIter.More(); aFontIter.Next())
5646 aFontsSorted.push_back (aFontIter.Value());
5648 std::stable_sort (aFontsSorted.begin(), aFontsSorted.end(), FontComparator());
5649 for (std::vector<Handle(Font_SystemFont)>::iterator aFontIter = aFontsSorted.begin(); aFontIter != aFontsSorted.end(); ++aFontIter)
5651 const Handle(Font_SystemFont)& aFont = *aFontIter;
5652 const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match -nocase \"") + aFontName + "\" \"" + aFont->FontName() + "\"";
5653 if (theDI.Eval (aCheck.ToCString()) == 0
5654 && *theDI.Result() != '1')
5661 if (!aResult.IsEmpty())
5666 aResult += toPrintInfo ? aFont->ToString() : aFont->FontName();
5673 else if (Handle(Font_SystemFont) aFont = aMgr->FindFont (aFontName, aStrictLevel, aFontAspect))
5675 aResult = toPrintInfo ? aFont->ToString() : aFont->FontName();
5678 if (!aResult.IsEmpty())
5684 Message::SendFail() << "Error: font '" << aFontName << "' is not found";
5687 else if (anArgIter + 1 < theArgNb
5688 && (anArgCase == "-add"
5689 || anArgCase == "add"
5690 || anArgCase == "-register"
5691 || anArgCase == "register"))
5694 Standard_CString aFontPath = theArgVec[anArgIter++];
5695 TCollection_AsciiString aFontName;
5696 Font_FontAspect aFontAspect = Font_FA_Undefined;
5697 Standard_Integer isSingelStroke = -1;
5698 for (; anArgIter < theArgNb; ++anArgIter)
5700 anArgCase = theArgVec[anArgIter];
5701 anArgCase.LowerCase();
5702 if (aFontAspect == Font_FontAspect_UNDEFINED
5703 && parseFontStyle (anArgCase, aFontAspect))
5707 else if (anArgCase == "singlestroke"
5708 || anArgCase == "singleline"
5709 || anArgCase == "oneline")
5713 else if (aFontName.IsEmpty())
5715 aFontName = theArgVec[anArgIter];
5724 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5727 Message::SendFail() << "Error: font '" << aFontPath << "' is not found!";
5731 if (aFontAspect != Font_FontAspect_UNDEFINED
5732 || !aFontName.IsEmpty())
5734 TCollection_AsciiString aName = aFont->FontName();
5735 if (!aFontName.IsEmpty())
5739 Handle(Font_SystemFont) aFont2 = new Font_SystemFont (aName);
5740 if (aFontAspect != Font_FontAspect_UNDEFINED)
5742 aFont2->SetFontPath (aFontAspect, aFontPath, 0);
5746 for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
5748 aFont2->SetFontPath ((Font_FontAspect )anAspectIter,
5749 aFont->FontPath ((Font_FontAspect )anAspectIter),
5750 aFont->FontFaceId ((Font_FontAspect )anAspectIter));
5755 if (isSingelStroke != -1)
5757 aFont->SetSingleStrokeFont (isSingelStroke == 1);
5760 aMgr->RegisterFont (aFont, Standard_True);
5761 theDI << aFont->ToString();
5763 else if (anArgCase == "-aliases")
5765 TCollection_AsciiString anAliasName;
5766 TColStd_SequenceOfHAsciiString aNames;
5767 if (anArgIter + 1 < theArgNb
5768 && *theArgVec[anArgIter + 1] != '-')
5770 anAliasName = theArgVec[++anArgIter];
5772 if (!anAliasName.IsEmpty())
5774 aMgr->GetFontAliases (aNames, anAliasName);
5778 aMgr->GetAllAliases (aNames);
5780 for (TColStd_SequenceOfHAsciiString::Iterator aNameIter (aNames); aNameIter.More(); aNameIter.Next())
5782 theDI << "{" << aNameIter.Value()->String() << "} ";
5785 else if (anArgIter + 2 < theArgNb
5786 && anArgCase == "-addalias")
5788 TCollection_AsciiString anAliasName(theArgVec[++anArgIter]);
5789 TCollection_AsciiString aFontName (theArgVec[++anArgIter]);
5790 aMgr->AddFontAlias (anAliasName, aFontName);
5792 else if (anArgIter + 2 < theArgNb
5793 && anArgCase == "-removealias")
5795 TCollection_AsciiString anAliasName(theArgVec[++anArgIter]);
5796 TCollection_AsciiString aFontName (theArgVec[++anArgIter]);
5797 aMgr->RemoveFontAlias (anAliasName, aFontName);
5799 else if (anArgIter + 1 < theArgNb
5800 && anArgCase == "-clearalias")
5802 TCollection_AsciiString anAliasName(theArgVec[++anArgIter]);
5803 aMgr->RemoveFontAlias (anAliasName, "");
5805 else if (anArgCase == "-clearaliases")
5807 aMgr->RemoveFontAlias ("", "");
5809 else if (anArgCase == "-verbose"
5810 || anArgCase == "-trace")
5812 bool toEnable = true;
5813 if (anArgIter + 1 < theArgNb
5814 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
5818 aMgr->SetTraceAliases (toEnable);
5820 else if (anArgCase == "-unicodefallback"
5821 || anArgCase == "-fallback"
5822 || anArgCase == "-touseunicodesubsetfallback")
5824 bool toEnable = true;
5825 if (anArgIter + 1 < theArgNb
5826 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
5830 Font_FontMgr::ToUseUnicodeSubsetFallback() = toEnable;
5834 Message::SendFail() << "Warning! Unknown argument '" << anArg << "'";
5840 // just print the list of available fonts
5841 Standard_Boolean isFirst = Standard_True;
5842 const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts();
5843 std::vector<Handle(Font_SystemFont)> aFontsSorted;
5844 aFontsSorted.reserve (aFonts.Size());
5845 for (Font_NListOfSystemFont::Iterator aFontIter (aFonts); aFontIter.More(); aFontIter.Next())
5847 aFontsSorted.push_back (aFontIter.Value());
5849 std::stable_sort (aFontsSorted.begin(), aFontsSorted.end(), FontComparator());
5850 for (std::vector<Handle(Font_SystemFont)>::iterator aFontIter = aFontsSorted.begin(); aFontIter != aFontsSorted.end(); ++aFontIter)
5852 const Handle(Font_SystemFont)& aFont = *aFontIter;
5860 theDI << "\"" << aFont->FontName() << "\"";
5868 theDI << aFont->ToString();
5870 isFirst = Standard_False;
5878 //=======================================================================
5879 //function : VVertexMode
5880 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
5881 //=======================================================================
5883 static int VVertexMode (Draw_Interpretor& theDI,
5884 Standard_Integer theArgNum,
5885 const char** theArgs)
5887 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5888 if (aContext.IsNull())
5890 Message::SendFail ("Error: no active viewer");
5894 // No arguments --> print the current default vertex draw mode
5897 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5898 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5902 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5903 TCollection_AsciiString aParam (theArgs[1]);
5904 if (aParam == "-set")
5908 Message::SendFail ("Error: '-set' option not followed by the mode and optional object name(s)\n"
5909 "Type 'help vvertexmode' for usage hints");
5913 TCollection_AsciiString aModeStr (theArgs[2]);
5914 Prs3d_VertexDrawMode aNewMode =
5915 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5916 (aModeStr == "all" ? Prs3d_VDM_All :
5917 Prs3d_VDM_Inherited);
5919 Standard_Boolean aRedrawNeeded = Standard_False;
5920 AIS_ListOfInteractive anObjs;
5922 // No object(s) specified -> use all displayed
5925 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5926 aContext->DisplayedObjects (anObjs);
5927 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5928 aRedrawNeeded = Standard_True;
5931 Handle(AIS_InteractiveObject) anObject;
5932 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5934 TCollection_AsciiString aName (theArgs[aCount]);
5935 if (!GetMapOfAIS().Find2 (aName, anObject))
5937 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5940 anObjs.Append (anObject);
5943 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5945 anObject = anIt.Value();
5946 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5947 aContext->Redisplay (anObject, Standard_False);
5948 aRedrawNeeded = Standard_True;
5952 ViewerTest::CurrentView()->Redraw();
5957 Handle(AIS_InteractiveObject) anObject;
5959 || !GetMapOfAIS().Find2 (aParam, anObject))
5961 Message::SendFail ("Syntax error: invalid number of arguments");
5965 // One argument (object name) --> print the current vertex draw mode for the object
5966 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5967 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5971 //=======================================================================
5972 //function : VPointCloud
5973 //purpose : Create interactive object for arbitary set of points.
5974 //=======================================================================
5975 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5976 Standard_Integer theArgNum,
5977 const char** theArgs)
5979 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5980 if (anAISContext.IsNull())
5982 Message::SendFail ("Error: no active view!");
5986 // command to execute
5989 CloudForShape, // generate point cloud for shape
5990 CloudSphere, // generate point cloud for generic sphere
5994 // count number of non-optional command arguments
5995 Command aCmd = Unknow;
5996 Standard_Integer aCmdArgs = 0;
5997 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5999 Standard_CString anArg = theArgs[anArgIter];
6000 TCollection_AsciiString aFlag (anArg);
6002 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
6009 case 2 : aCmd = CloudForShape; break;
6010 case 7 : aCmd = CloudSphere; break;
6012 Message::SendFail ("Syntax error: wrong number of arguments! See usage:");
6013 theDI.PrintHelp (theArgs[0]);
6018 Standard_Boolean toRandColors = Standard_False;
6019 Standard_Boolean hasNormals = Standard_True;
6020 Standard_Boolean isSetArgNorm = Standard_False;
6021 Standard_Boolean hasUV = Standard_False;
6022 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
6024 Standard_CString anArg = theArgs[anArgIter];
6025 TCollection_AsciiString aFlag (anArg);
6027 if (aFlag == "-randcolors"
6028 || aFlag == "-randcolor")
6030 if (isSetArgNorm && hasNormals)
6032 Message::SendFail ("Syntax error: normals can not be enabled with colors at the same time");
6035 toRandColors = Standard_True;
6036 hasNormals = Standard_False;
6038 else if (aFlag == "-normals"
6039 || aFlag == "-normal")
6043 Message::SendFail ("Syntax error: normals can not be enabled with colors at the same time");
6046 isSetArgNorm = Standard_True;
6047 hasNormals = Standard_True;
6049 else if (aFlag == "-nonormals"
6050 || aFlag == "-nonormal")
6052 isSetArgNorm = Standard_True;
6053 hasNormals = Standard_False;
6055 else if (aFlag == "-uv"
6056 || aFlag == "-texels")
6058 hasUV = Standard_True;
6062 Standard_CString aName = theArgs[1];
6063 Graphic3d_ArrayFlags aFlags = Graphic3d_ArrayFlags_None;
6066 aFlags |= Graphic3d_ArrayFlags_VertexNormal;
6070 aFlags |= Graphic3d_ArrayFlags_VertexColor;
6074 aFlags |= Graphic3d_ArrayFlags_VertexTexel;
6077 // generate arbitrary set of points
6078 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
6079 if (aCmd == CloudForShape)
6081 Standard_CString aShapeName = theArgs[2];
6082 TopoDS_Shape aShape = DBRep::Get (aShapeName);
6084 if (aShape.IsNull())
6086 Message::SendFail() << "Error: no shape with name '" << aShapeName << "' found";
6090 // calculate number of points
6091 TopLoc_Location aLocation;
6092 Standard_Integer aNbPoints = 0;
6093 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
6095 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
6096 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
6097 if (!aTriangulation.IsNull())
6099 aNbPoints += aTriangulation->NbNodes();
6104 Message::SendFail ("Error: shape should be triangulated");
6108 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags);
6109 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
6111 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
6112 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
6113 if (aTriangulation.IsNull())
6118 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
6119 const gp_Trsf& aTrsf = aLocation.Transformation();
6121 // extract normals from nodes
6122 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
6125 Poly_Connect aPolyConnect (aTriangulation);
6126 StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
6129 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
6131 gp_Pnt aPoint = aNodes (aNodeIter);
6132 if (!aLocation.IsIdentity())
6134 aPoint.Transform (aTrsf);
6137 aNormals (aNodeIter).Transform (aTrsf);
6141 // add vertex into array of points
6142 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
6145 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
6146 1.0, 0.5, Quantity_TOC_HLS);
6147 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
6152 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
6155 && aTriangulation->HasUVNodes())
6157 anArrayPoints->SetVertexTexel (anIndexOfPoint, aTriangulation->UVNode (aNodeIter));
6162 else if (aCmd == CloudSphere)
6164 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
6165 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
6166 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
6167 Standard_Real aRadius = Draw::Atof (theArgs[5]);
6168 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
6170 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
6171 aDistribution.LowerCase();
6172 if ( aDistribution != "surface" && aDistribution != "volume" )
6174 Message::SendFail ("Syntax error: wrong arguments. See usage:");
6175 theDI.PrintHelp (theArgs[0]);
6178 Standard_Boolean isSurface = aDistribution == "surface";
6180 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
6182 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags);
6183 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
6185 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
6186 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
6187 Standard_Real aDistance = isSurface ?
6188 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
6190 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
6192 Cos (anAlpha) * Cos (aBeta));
6193 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
6195 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
6198 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
6199 1.0, 0.5, Quantity_TOC_HLS);
6200 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
6205 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
6209 anArrayPoints->SetVertexTexel (anIndexOfPoint, gp_Pnt2d (anAlpha / 2.0 * M_PI,
6210 aBeta / 2.0 * M_PI));
6215 // set array of points in point cloud object
6216 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
6217 aPointCloud->SetPoints (anArrayPoints);
6218 VDisplayAISObject (aName, aPointCloud);
6222 //=======================================================================
6223 //function : VPriority
6224 //purpose : Prints or sets the display priority for an object
6225 //=======================================================================
6227 static int VPriority (Draw_Interpretor& theDI,
6228 Standard_Integer theArgNum,
6229 const char** theArgs)
6231 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6232 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6233 if (aContext.IsNull())
6235 Message::SendFail ("Error: no active viewer");
6239 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
6240 Standard_Integer aPriority = -1;
6241 Standard_Integer aNbArgs = theArgNum;
6242 if (aLastArg.IsIntegerValue())
6244 aPriority = aLastArg.IntegerValue();
6246 if (aPriority < 0 || aPriority > 10)
6248 Message::SendFail() << "Syntax error: the specified display priority value '" << aLastArg
6249 << "' is outside the valid range [0..10]";
6255 anUpdateTool.Invalidate();
6260 Message::SendFail ("Syntax error: wrong number of arguments! See usage:");
6261 theDI.PrintHelp (theArgs[0]);
6265 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
6267 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
6272 TCollection_AsciiString aName (theArgs[anArgIter]);
6273 Handle(AIS_InteractiveObject) anIObj;
6274 GetMapOfAIS().Find2 (aName, anIObj);
6275 if (anIObj.IsNull())
6277 Message::SendFail() << "Error: the object '" << theArgs[1] << "' is not displayed";
6283 theDI << aContext->DisplayPriority (anIObj) << " ";
6287 aContext->SetDisplayPriority (anIObj, aPriority);
6293 //! Auxiliary class for command vnormals.
6294 class MyShapeWithNormals : public AIS_Shape
6296 DEFINE_STANDARD_RTTI_INLINE(MyShapeWithNormals, AIS_Shape);
6299 Standard_Real NormalLength;
6300 Standard_Integer NbAlongU;
6301 Standard_Integer NbAlongV;
6302 Standard_Boolean ToUseMesh;
6303 Standard_Boolean ToOrient;
6307 //! Main constructor.
6308 MyShapeWithNormals (const TopoDS_Shape& theShape)
6309 : AIS_Shape (theShape),
6313 ToUseMesh (Standard_False),
6314 ToOrient (Standard_False) {}
6318 //! Comnpute presentation.
6319 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
6320 const Handle(Prs3d_Presentation)& thePrs,
6321 const Standard_Integer theMode) Standard_OVERRIDE
6323 AIS_Shape::Compute (thePrsMgr, thePrs, theMode);
6325 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormalMap;
6328 DBRep_DrawableShape::addMeshNormals (aNormalMap, myshape, NormalLength);
6332 DBRep_DrawableShape::addSurfaceNormals (aNormalMap, myshape, NormalLength, NbAlongU, NbAlongV);
6335 Handle(Graphic3d_Group) aPrsGroup = thePrs->NewGroup();
6336 aPrsGroup->SetGroupPrimitivesAspect (myDrawer->ArrowAspect()->Aspect());
6338 const Standard_Real aArrowAngle = myDrawer->ArrowAspect()->Angle();
6339 const Standard_Real aArrowLength = myDrawer->ArrowAspect()->Length();
6340 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormalMap);
6341 aFaceIt.More(); aFaceIt.Next())
6343 const Standard_Boolean toReverse = ToOrient && aFaceIt.Key().Orientation() == TopAbs_REVERSED;
6344 Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (2 * aFaceIt.Value().Size());
6345 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aPntIt (aFaceIt.Value()); aPntIt.More(); aPntIt.Next())
6347 std::pair<gp_Pnt, gp_Pnt> aPair = aPntIt.Value();
6350 const gp_Vec aDir = aPair.first.XYZ() - aPair.second.XYZ();
6351 aPair.second = aPair.first.XYZ() + aDir.XYZ();
6354 aSegments->AddVertex (aPair.first);
6355 aSegments->AddVertex (aPair.second);
6356 Prs3d_Arrow::Draw (aPrsGroup, aPair.second, gp_Vec(aPair.first, aPair.second), aArrowAngle, aArrowLength);
6359 aPrsGroup->AddPrimitiveArray (aSegments);
6365 //=======================================================================
6366 //function : VNormals
6367 //purpose : Displays/Hides normals calculated on shape geometry or retrieved from triangulation
6368 //=======================================================================
6369 static int VNormals (Draw_Interpretor& theDI,
6370 Standard_Integer theArgNum,
6371 const char** theArgs)
6373 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6374 if (aContext.IsNull())
6376 Message::SendFail ("Error: no active viewer");
6379 else if (theArgNum < 2)
6381 Message::SendFail ("Syntax error: wrong number of arguments. See usage:");
6382 theDI.PrintHelp (theArgs[0]);
6386 Standard_Integer anArgIter = 1;
6387 Standard_CString aShapeName = theArgs[anArgIter++];
6388 TopoDS_Shape aShape = DBRep::Get (aShapeName);
6389 Standard_Boolean isOn = Standard_True;
6390 if (aShape.IsNull())
6392 Message::SendFail() << "Error: shape with name '" << aShapeName << "' is not found";
6396 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6397 Handle(MyShapeWithNormals) aShapePrs;
6398 if (aMap.IsBound2 (aShapeName))
6400 aShapePrs = Handle(MyShapeWithNormals)::DownCast (aMap.Find2 (aShapeName));
6403 Standard_Boolean isUseMesh = Standard_False;
6404 Standard_Real aLength = 10.0;
6405 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
6406 Standard_Boolean isOriented = Standard_False;
6407 for (; anArgIter < theArgNum; ++anArgIter)
6409 TCollection_AsciiString aParam (theArgs[anArgIter]);
6412 && Draw::ParseOnOff (aParam.ToCString(), isOn))
6416 else if (aParam == "-usemesh"
6417 || aParam == "-mesh")
6419 isUseMesh = Standard_True;
6421 else if (aParam == "-length"
6422 || aParam == "-len")
6425 aLength = anArgIter < theArgNum ? Draw::Atof (theArgs[anArgIter]) : 0.0;
6426 if (Abs (aLength) <= gp::Resolution())
6428 Message::SendFail ("Syntax error: length should not be zero");
6432 else if (aParam == "-orient"
6433 || aParam == "-oriented")
6435 isOriented = Standard_True;
6436 if (anArgIter + 1 < theArgNum
6437 && Draw::ParseOnOff (theArgs[anArgIter + 1], isOriented))
6442 else if (aParam == "-nbalongu"
6443 || aParam == "-nbu")
6446 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6449 Message::SendFail ("Syntax error: NbAlongU should be >=1");
6453 else if (aParam == "-nbalongv"
6454 || aParam == "-nbv")
6457 aNbAlongV = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6460 Message::SendFail ("Syntax error: NbAlongV should be >=1");
6464 else if (aParam == "-nbalong"
6465 || aParam == "-nbuv")
6468 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6469 aNbAlongV = aNbAlongU;
6472 Message::SendFail ("Syntax error: NbAlong should be >=1");
6478 Message::SendFail() << "Syntax error: unknown argument '" << aParam << "'";
6485 if (aShapePrs.IsNull())
6487 aShapePrs = new MyShapeWithNormals (aShape);
6489 aShapePrs->ToUseMesh = isUseMesh;
6490 aShapePrs->ToOrient = isOriented;
6491 aShapePrs->NormalLength = aLength;
6492 aShapePrs->NbAlongU = aNbAlongU;
6493 aShapePrs->NbAlongV = aNbAlongV;
6494 VDisplayAISObject (aShapeName, aShapePrs);
6496 else if (!aShapePrs.IsNull())
6498 VDisplayAISObject (aShapeName, new AIS_Shape (aShape));
6504 //=======================================================================
6505 //function : ObjectsCommands
6507 //=======================================================================
6509 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
6511 const char *group ="AISObjects";
6513 theCommands.Add ("vtrihedron",
6514 "vtrihedron : vtrihedron name"
6515 "\n\t\t: [-dispMode {wireframe|shading} ]"
6516 "\n\t\t: [-origin x y z ]"
6517 "\n\t\t: [-zaxis u v w -xaxis u v w ]"
6518 "\n\t\t: [-drawAxes {X|Y|Z|XY|YZ|XZ|XYZ}]"
6519 "\n\t\t: [-hideLabels {on|off}]"
6520 "\n\t\t: [-hideArrows {on|off}]"
6521 "\n\t\t: [-label {XAxis|YAxis|ZAxis} value]"
6522 "\n\t\t: [-attribute {XAxisLength|YAxisLength|ZAxisLength"
6523 "\n\t\t: |TubeRadiusPercent|ConeRadiusPercent"
6524 "\n\t\t: |ConeLengthPercent|OriginRadiusPercent"
6525 "\n\t\t: |ShadingNumberOfFacettes} value]"
6526 "\n\t\t: [-color {Origin|XAxis|YAxis|ZAxis|XOYAxis|YOZAxis"
6527 "\n\t\t: |XOZAxis|Whole} {r g b | colorName}]"
6528 "\n\t\t: [-textColor {r g b | colorName}]"
6529 "\n\t\t: [-arrowColor {r g b | colorName}]"
6530 "\n\t\t: [-priority {Origin|XAxis|YAxis|ZAxis|XArrow"
6531 "\n\t\t: |YArrow|ZArrow|XOYAxis|YOZAxis"
6532 "\n\t\t: |XOZAxis|Whole} value]"
6534 "\n\t\t: Creates a new *AIS_Trihedron* object or changes parameters of "
6535 "\n\t\t: existing trihedron. If no argument is set,"
6536 "\n\t\t: the default trihedron (0XYZ) is created."
6537 "\n\t\t: -dispMode mode of visualization: wf - wireframe,"
6538 "\n\t\t: sh - shading."
6539 "\n\t\t: Default value is wireframe."
6540 "\n\t\t: -origin allows to set trihedron location."
6541 "\n\t\t: -zaxis/-xaxis allows to set trihedron X and Z"
6542 "\n\t\t: directions. The directions should"
6543 "\n\t\t: be orthogonal. Y direction is calculated."
6544 "\n\t\t: -drawAxes allows to set what axes are drawn in the"
6545 "\n\t\t: trihedron, default state is XYZ"
6546 "\n\t\t: -hideLabels allows to show/hide trihedron labels"
6547 "\n\t\t: -hideArrows allows to show/hide trihedron arrows"
6548 "\n\t\t: -label allows to change default X/Y/Z titles of axes"
6549 "\n\t\t: -attribute sets parameters of trihedron"
6550 "\n\t\t: -color sets color properties of parts of trihedron"
6551 "\n\t\t: -textColor sets color properties of trihedron labels"
6552 "\n\t\t: -arrowColor sets color properties of trihedron arrows"
6553 "\n\t\t: -priority allows to change default selection priority"
6554 "\n\t\t: of trihedron components",
6555 __FILE__,VTrihedron,group);
6557 theCommands.Add("vtri2d",
6559 "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.",
6560 __FILE__,VTrihedron2D ,group);
6562 theCommands.Add("vplanetri",
6564 "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default",
6565 __FILE__,VPlaneTrihedron ,group);
6567 theCommands.Add("vsize",
6568 "vsize : vsize [name(Default=Current)] [size(Default=100)] "
6569 "\n\t\t: Changes the size of a named or selected trihedron."
6570 "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done."
6571 "\n\t\t: If the value is not defined: it is set to 100 by default.",
6572 __FILE__,VSize,group);
6574 theCommands.Add("vaxis",
6575 "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]"
6576 "\n\t\t: Creates an axis. If the values are not defined, an axis is created by interactive selection of two vertices or one edge",
6577 __FILE__,VAxisBuilder,group);
6579 theCommands.Add("vaxispara",
6581 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.",
6582 __FILE__,VAxisBuilder,group);
6584 theCommands.Add("vaxisortho",
6586 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.",
6587 __FILE__,VAxisBuilder,group);
6589 theCommands.Add("vpoint",
6590 "vpoint name [X Y [Z]] [-2d] [-nosel]"
6591 "\n\t\t: Creates a point from coordinates."
6592 "\n\t\t: If the values are not defined, a point is created from selected vertex or edge (center)."
6593 "\n\t\t: -2d defines on-screen 2D point from top-left window corner"
6594 "\n\t\t: -nosel creates non-selectable presentation",
6595 __FILE__,VPointBuilder,group);
6597 theCommands.Add("vplane",
6598 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]"
6599 "\n\t\t: Creates a plane from named or interactively selected entities."
6600 "\n\t\t: TypeOfSensitivity:"
6601 "\n\t\t: 0 - Interior"
6602 "\n\t\t: 1 - Boundary",
6603 __FILE__,VPlaneBuilder,group);
6605 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
6606 " vchangeplane <plane_name>"
6607 " [x=center_x y=center_y z=center_z]"
6608 " [dx=dir_x dy=dir_y dz=dir_z]"
6609 " [sx=size_x sy=size_y]"
6611 " - changes parameters of the plane:\n"
6612 " - x y z - center\n"
6613 " - dx dy dz - normal\n"
6614 " - sx sy - plane sizes\n"
6615 " - noupdate - do not update/redisplay the plane in context\n"
6616 " Please enter coordinates in format \"param=value\" in arbitrary order.",
6617 __FILE__, VChangePlane, group);
6619 theCommands.Add("vplanepara",
6620 "vplanepara PlaneName "
6621 "\n\t\t: Creates a plane from interactively selected vertex and face.",
6622 __FILE__,VPlaneBuilder,group);
6624 theCommands.Add("vplaneortho",
6625 "vplaneortho PlaneName "
6626 "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ",
6627 __FILE__,VPlaneBuilder,group);
6629 theCommands.Add("vline",
6630 "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] "
6631 "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ",
6632 __FILE__,VLineBuilder,group);
6634 theCommands.Add("vcircle",
6635 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]"
6636 "\n\t\t: Creates a circle from named or interactively selected entities."
6637 "\n\t\t: Parameter IsFilled is defined as 0 or 1.",
6638 __FILE__,VCircleBuilder,group);
6640 theCommands.Add ("vdrawtext",
6641 "vdrawtext name text"
6642 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6643 "\n\t\t: [-color {R G B|name}=yellow]"
6644 "\n\t\t: [-halign {left|center|right}=left]"
6645 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6646 "\n\t\t: [-angle angle=0]"
6647 "\n\t\t: [-zoom {0|1}=0]"
6648 "\n\t\t: [-height height=16]"
6649 "\n\t\t: [-wrapping width=40]"
6650 "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]"
6651 "\n\t\t: [-font font=Times]"
6653 "\n\t\t: [-perspos {X Y Z}=0 0 0], where"
6654 "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window"
6655 "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..."
6656 "\n\t\t Z coordinate defines the gap from border of view window (except center position)."
6657 "\n\t\t: [-disptype {blend|decal|shadow|subtitle|dimension|normal}=normal}"
6658 "\n\t\t: [-subcolor {R G B|name}=white]"
6659 "\n\t\t: [-noupdate]"
6660 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]"
6661 "\n\t\t: [-flipping]"
6662 "\n\t\t: [-ownanchor {0|1}=1]"
6663 "\n\t\t: Display text label at specified position.",
6664 __FILE__, VDrawText, group);
6666 theCommands.Add("vdrawsphere",
6667 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
6668 __FILE__,VDrawSphere,group);
6670 theCommands.Add ("vlocation",
6672 "\n\t\t: [-reset] [-copyFrom otherName]"
6673 "\n\t\t: [-translate X Y [Z]] [-rotate x y z dx dy dz angle] [-scale [X Y Z] scale]"
6674 "\n\t\t: [-pretranslate X Y [Z]] [-prerotate x y z dx dy dz angle] [-prescale [X Y Z] scale]"
6675 "\n\t\t: [-mirror x y z dx dy dz] [-premirror x y z dx dy dz]"
6676 "\n\t\t: [-setLocation X Y [Z]] [-setRotation QX QY QZ QW] [-setScale [X Y Z] scale]"
6677 "\n\t\t: Object local transformation management:"
6678 "\n\t\t: -reset resets transformation to identity"
6679 "\n\t\t: -translate applies translation vector"
6680 "\n\t\t: -rotate applies rotation around axis"
6681 "\n\t\t: -scale applies scale factor with optional anchor"
6682 "\n\t\t: -mirror applies mirror transformation"
6683 "\n\t\t: -pretranslate pre-multiplies translation vector"
6684 "\n\t\t: -prerotate pre-multiplies rotation around axis"
6685 "\n\t\t: -prescale pre-multiplies scale transformation"
6686 "\n\t\t: -premirror pre-multiplies mirror transformation"
6687 "\n\t\t: -setLocation overrides translation part"
6688 "\n\t\t: -setRotation overrides rotation part with specified quaternion"
6689 "\n\t\t: -setScale overrides scale factor",
6690 __FILE__, VSetLocation, group);
6691 theCommands.Add ("vsetlocation",
6692 "alias for vlocation",
6693 __FILE__, VSetLocation, group);
6694 theCommands.Add ("vchild",
6695 "vchild parent [-add] [-remove] [-ignoreParentTrsf {0|1}] child1 [child2] [...]"
6696 "\n\t\t: Command for testing low-level presentation connections."
6697 "\n\t\t: vconnect command should be used instead.",
6698 __FILE__, VChild, group);
6699 theCommands.Add("vparent",
6700 "vparent parent [-ignoreVisu]"
6701 "\n\t\t: Command for testing object properties as parent in the hierarchy."
6702 "\n\t\t: Arguments:"
6703 "\n\t\t: -ignoreVisu do not propagate the visual state (display/erase/color) to children objects",
6704 __FILE__, VParent, group);
6705 theCommands.Add ("vcomputehlr",
6706 "vcomputehlr shapeInput hlrResult [-algoType {algo|polyAlgo}=polyAlgo]"
6707 "\n\t\t: [eyeX eyeY eyeZ dirX dirY dirZ upX upY upZ]"
6708 "\n\t\t: [-showTangentEdges {on|off}=off] [-nbIsolines N=0] [-showHiddenEdges {on|off}=off]"
6709 "\n\t\t: Arguments:"
6710 "\n\t\t: shapeInput - name of the initial shape"
6711 "\n\t\t: hlrResult - result HLR object from initial shape"
6712 "\n\t\t: eye, dir are eye position and look direction"
6713 "\n\t\t: up is the look up direction vector"
6714 "\n\t\t: -algoType HLR algorithm to use"
6715 "\n\t\t: -showTangentEdges include tangent edges"
6716 "\n\t\t: -nbIsolines include isolines"
6717 "\n\t\t: -showHiddenEdges include hidden edges"
6718 "\n\t\t: Use vtop to see projected HLR shape.",
6719 __FILE__, VComputeHLR, group);
6721 theCommands.Add("vdrawparray",
6722 "vdrawparray name TypeOfArray={points|segments|polylines|triangles"
6723 "\n\t\t: |trianglefans|trianglestrips|quads|quadstrips|polygons}"
6724 "\n\t\t: [-deinterleaved|-mutable]"
6725 "\n\t\t: [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [texel={'t' tx ty}]]"
6726 "\n\t\t: [bound= {'b' nbVertices [bound_color={'c' r g b}]]"
6727 "\n\t\t: [edge= {'e' vertexId]"
6728 "\n\t\t: [-shape shapeName] [-patch]"
6729 "\n\t\t: Commands create an Interactive Object for specified Primitive Array definition (Graphic3d_ArrayOfPrimitives)"
6730 "\n\t\t: with the main purpose is covering various combinations by tests",
6731 __FILE__,VDrawPArray,group);
6733 theCommands.Add("vconnect",
6734 "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]"
6735 "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.",
6736 __FILE__, VConnect, group);
6738 theCommands.Add("vconnectto",
6739 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
6740 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6741 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
6742 __FILE__, VConnectTo,group);
6744 theCommands.Add("vdisconnect",
6745 "vdisconnect assembly_name (object_name | object_number | 'all')"
6746 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6747 __FILE__,VDisconnect,group);
6749 theCommands.Add("vaddconnected",
6750 "vaddconnected assembly_name object_name"
6751 "Adds object to assembly.",
6752 __FILE__,VAddConnected,group);
6754 theCommands.Add("vlistconnected",
6755 "vlistconnected assembly_name"
6756 "Lists objects in assembly.",
6757 __FILE__,VListConnected,group);
6760 theCommands.Add("vselmode",
6761 "vselmode [object] selectionMode {on|off}"
6762 "\n\t\t: [{-add|-set|-globalOrLocal}=-globalOrLocal]"
6763 "\n\t\t: Switches selection mode for the specified object or for all objects in context."
6764 "\n\t\t: Selection mode is either an integer number specific to Interactive Object,"
6765 "\n\t\t: or sub-shape type in case of AIS_Shape:"
6766 "\n\t\t: Shape, Vertex, Edge, Wire, Face, Shell, Solid, CompSolid, Compound"
6767 "\n\t\t: The integer mode 0 (Shape in case of AIS_Shape) is reserved for selecting object as whole."
6768 "\n\t\t: Additional options:"
6769 "\n\t\t: -add already activated selection modes will be left activated"
6770 "\n\t\t: -set already activated selection modes will be deactivated"
6771 "\n\t\t: -globalOrLocal (default) if new mode is Global selection mode,"
6772 "\n\t\t: then active local selection modes will be deactivated"
6773 "\n\t\t: and the samthen active local selection modes will be deactivated",
6774 __FILE__, VSetSelectionMode, group);
6776 theCommands.Add("vselnext",
6777 "vselnext : hilight next detected",
6778 __FILE__, VSelectionNext, group);
6780 theCommands.Add("vselprev",
6781 "vselnext : hilight previous detected",
6782 __FILE__, VSelectionPrevious, group);
6784 theCommands.Add("vtriangle",
6785 "vtriangle Name PointName PointName PointName"
6786 "\n\t\t: Creates and displays a filled triangle from named points.",
6787 __FILE__, VTriangle,group);
6789 theCommands.Add("vsegment",
6790 "vsegment Name PointName PointName"
6791 "\n\t\t: Creates and displays a segment from named points.",
6792 __FILE__, VTriangle,group);
6794 theCommands.Add("vobjzlayer",
6795 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6796 __FILE__, VObjZLayer, group);
6798 theCommands.Add("vpolygonoffset",
6799 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6800 __FILE__, VPolygonOffset, group);
6802 theCommands.Add ("vmarkerstest",
6803 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6804 __FILE__, VMarkersTest, group);
6806 theCommands.Add ("text2brep",
6807 "text2brep: name text"
6808 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6809 "\n\t\t: [-halign {left|center|right}=left]"
6810 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6811 "\n\t\t: [-height height=16]"
6812 "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]"
6813 "\n\t\t: [-font font=Courier] [-strict {strict|aliases|any}=any]"
6814 "\n\t\t: [-composite {on|off}=off]"
6815 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]",
6816 __FILE__, TextToBRep, group);
6817 theCommands.Add ("vfont",
6818 "vfont [-add pathToFont [fontName] [regular,bold,italic,boldItalic=undefined] [singleStroke]]"
6819 "\n\t\t: [-strict {any|aliases|strict}] [-find fontName [regular,bold,italic,boldItalic=undefined]] [-verbose {on|off}]"
6820 "\n\t\t: [-findAll fontNameMask] [-findInfo fontName]"
6821 "\n\t\t: [-unicodeFallback {on|off}]"
6822 "\n\t\t: [-clear] [-init] [-list] [-names]"
6823 "\n\t\t: [-aliases [aliasName]] [-addAlias Alias FontName] [-removeAlias Alias FontName] [-clearAlias Alias] [-clearAliases]"
6824 "\n\t\t: Work with font registry - register font, list available fonts, find font."
6825 "\n\t\t: -findAll is same as -find, but can print more than one font when mask is passed."
6826 "\n\t\t: -findInfo is same as -find, but prints complete font information instead of family name.",
6827 __FILE__, VFont, group);
6829 theCommands.Add ("vvertexmode",
6830 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6831 "vvertexmode - prints the default vertex draw mode\n"
6832 "vvertexmode name - prints the vertex draw mode of the given object\n"
6833 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6834 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6835 __FILE__, VVertexMode, group);
6837 theCommands.Add ("vpointcloud",
6838 "vpointcloud name shape [-randColor] [-normals] [-noNormals] [-uv]"
6839 "\n\t\t: Create an interactive object for arbitary set of points"
6840 "\n\t\t: from triangulated shape."
6842 "vpointcloud name x y z r npts {surface|volume}\n"
6843 " ... [-randColor] [-normals] [-noNormals] [-uv]"
6844 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6845 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6847 "\n\t\t: Additional options:"
6848 "\n\t\t: -randColor - generate random color per point"
6849 "\n\t\t: -normals - generate normal per point (default)"
6850 "\n\t\t: -noNormals - do not generate normal per point"
6852 __FILE__, VPointCloud, group);
6854 theCommands.Add("vpriority",
6855 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",
6859 theCommands.Add ("vnormals",
6861 "vnormals Shape [{on|off}=on] [-length {10}] [-nbAlongU {1}] [-nbAlongV {1}] [-nbAlong {1}]"
6862 "\n\t\t: [-useMesh] [-oriented {0}1}=0]"
6863 "\n\t\t: Displays/Hides normals calculated on shape geometry or retrieved from triangulation",
6864 __FILE__, VNormals, group);