1 // Created on: 1998-11-12
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <ViewerTest.hxx>
19 #include <AIS_PlaneTrihedron.hxx>
21 #include <Quantity_NameOfColor.hxx>
22 #include <Draw_Interpretor.hxx>
24 #include <Draw_Appli.hxx>
26 #include <DBRep_DrawableShape.hxx>
28 #include <Font_BRepFont.hxx>
29 #include <Font_BRepTextBuilder.hxx>
30 #include <Font_FontMgr.hxx>
32 #include <NCollection_List.hxx>
34 #include <OSD_Chronometer.hxx>
35 #include <TCollection_AsciiString.hxx>
36 #include <V3d_Viewer.hxx>
37 #include <V3d_View.hxx>
40 #include <AIS_Shape.hxx>
41 #include <AIS_DisplayMode.hxx>
42 #include <AIS_PointCloud.hxx>
43 #include <TColStd_MapOfInteger.hxx>
44 #include <AIS_MapOfInteractive.hxx>
45 #include <ViewerTest_AutoUpdater.hxx>
46 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
47 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
48 #include <ViewerTest_EventManager.hxx>
50 #include <TopoDS_Solid.hxx>
51 #include <BRepTools.hxx>
52 #include <BRep_Builder.hxx>
53 #include <TopAbs_ShapeEnum.hxx>
56 #include <BRep_Tool.hxx>
57 #include <TopExp_Explorer.hxx>
59 #include <BRepAdaptor_Curve.hxx>
60 #include <BRepAdaptor_Surface.hxx>
64 #include <TopoDS_Vertex.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Face.hxx>
68 #include <Draw_Window.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
70 #include <AIS_ListOfInteractive.hxx>
71 #include <AIS_ColoredShape.hxx>
72 #include <AIS_DisplayMode.hxx>
73 #include <AIS_Shape.hxx>
75 #include <AIS_InteractiveContext.hxx>
76 #include <Geom_Plane.hxx>
78 #include <TCollection_ExtendedString.hxx>
79 #include <TCollection_HAsciiString.hxx>
80 #include <GC_MakePlane.hxx>
81 #include <gp_Circ.hxx>
82 #include <AIS_Axis.hxx>
83 #include <Geom_Axis2Placement.hxx>
84 #include <Geom_Axis1Placement.hxx>
85 #include <AIS_Trihedron.hxx>
86 #include <AIS_Axis.hxx>
87 #include <gp_Trsf.hxx>
88 #include <gp_Quaternion.hxx>
89 #include <TopLoc_Location.hxx>
91 #include <HLRAlgo_Projector.hxx>
92 #include <HLRBRep_Algo.hxx>
93 #include <HLRBRep_PolyAlgo.hxx>
94 #include <HLRBRep_PolyHLRToShape.hxx>
95 #include <HLRBRep_HLRToShape.hxx>
96 #include <Aspect_Window.hxx>
98 #include <Graphic3d_ArrayOfPoints.hxx>
99 #include <Graphic3d_ArrayOfSegments.hxx>
100 #include <Graphic3d_ArrayOfPolylines.hxx>
101 #include <Graphic3d_ArrayOfTriangles.hxx>
102 #include <Graphic3d_ArrayOfTriangleFans.hxx>
103 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
104 #include <Graphic3d_ArrayOfQuadrangles.hxx>
105 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
106 #include <Graphic3d_ArrayOfPolygons.hxx>
107 #include <Graphic3d_AttribBuffer.hxx>
108 #include <Graphic3d_AspectMarker3d.hxx>
109 #include <Graphic3d_Group.hxx>
110 #include <Standard_Real.hxx>
112 #include <AIS_Circle.hxx>
113 #include <BRepBuilderAPI_MakeEdge.hxx>
114 #include <BRepBuilderAPI_MakeFace.hxx>
115 #include <BRepBuilderAPI_MakeWire.hxx>
116 #include <Geom_Circle.hxx>
117 #include <GC_MakeCircle.hxx>
118 #include <Select3D_SensitiveCircle.hxx>
119 #include <SelectMgr_EntityOwner.hxx>
120 #include <SelectMgr_Selection.hxx>
121 #include <StdFail_NotDone.hxx>
122 #include <StdPrs_ShadedShape.hxx>
123 #include <TopoDS_Wire.hxx>
125 #include <AIS_MultipleConnectedInteractive.hxx>
126 #include <AIS_ConnectedInteractive.hxx>
127 #include <AIS_TextLabel.hxx>
128 #include <TopLoc_Location.hxx>
129 #include <TColStd_ListOfInteger.hxx>
130 #include <TColStd_ListIteratorOfListOfInteger.hxx>
132 #include <Select3D_SensitiveSegment.hxx>
133 #include <Select3D_SensitivePrimitiveArray.hxx>
134 #include <Select3D_SensitiveTriangle.hxx>
135 #include <Select3D_SensitiveCurve.hxx>
136 #include <Select3D_SensitivePoint.hxx>
137 #include <BRepAdaptor_Curve.hxx>
138 #include <StdPrs_Curve.hxx>
140 #include <BRepExtrema_ExtPC.hxx>
141 #include <BRepExtrema_ExtPF.hxx>
143 #include <Prs3d_Arrow.hxx>
144 #include <Prs3d_ArrowAspect.hxx>
145 #include <Prs3d_DatumAttribute.hxx>
146 #include <Prs3d_DatumAspect.hxx>
147 #include <Prs3d_Drawer.hxx>
148 #include <Prs3d_VertexDrawMode.hxx>
149 #include <Prs3d_LineAspect.hxx>
150 #include <Prs3d_PointAspect.hxx>
151 #include <Prs3d_Presentation.hxx>
152 #include <Prs3d_TextAspect.hxx>
154 #include <Image_AlienPixMap.hxx>
155 #include <TColStd_HArray1OfAsciiString.hxx>
156 #include <TColStd_HSequenceOfAsciiString.hxx>
158 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
159 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
160 const Handle(AIS_InteractiveObject)& theAISObj,
161 Standard_Boolean theReplaceIfExists = Standard_True);
162 extern Handle(AIS_InteractiveContext)& TheAISContext();
166 static bool convertToColor (const Handle(TColStd_HSequenceOfAsciiString)& theColorValues,
167 Quantity_Color& theColor)
169 const char* anArgs[3] =
171 theColorValues->Size() >= 1 ? theColorValues->Value (1).ToCString() : "",
172 theColorValues->Size() >= 2 ? theColorValues->Value (2).ToCString() : "",
173 theColorValues->Size() >= 3 ? theColorValues->Value (3).ToCString() : ""
175 return ViewerTest::ParseColor (theColorValues->Size(), anArgs, theColor) != 0;
178 static bool convertToDatumPart (const TCollection_AsciiString& theValue,
179 Prs3d_DatumParts& theDatumPart)
181 TCollection_AsciiString aValue = theValue;
183 if (aValue == "origin") theDatumPart = Prs3d_DP_Origin;
184 else if (aValue == "xaxis") theDatumPart = Prs3d_DP_XAxis;
185 else if (aValue == "yaxis") theDatumPart = Prs3d_DP_YAxis;
186 else if (aValue == "zaxis") theDatumPart = Prs3d_DP_ZAxis;
187 else if (aValue == "xarrow") theDatumPart = Prs3d_DP_XArrow;
188 else if (aValue == "yarrow") theDatumPart = Prs3d_DP_YArrow;
189 else if (aValue == "zarrow") theDatumPart = Prs3d_DP_ZArrow;
190 else if (aValue == "xoyaxis") theDatumPart = Prs3d_DP_XOYAxis;
191 else if (aValue == "yozaxis") theDatumPart = Prs3d_DP_YOZAxis;
192 else if (aValue == "xozaxis") theDatumPart = Prs3d_DP_XOZAxis;
193 else if (aValue == "whole") theDatumPart = Prs3d_DP_None;
201 static void convertToDatumParts (const TCollection_AsciiString& theValue,
202 NCollection_List<Prs3d_DatumParts>& theParts)
204 TCollection_AsciiString aValue = theValue;
205 const Standard_Integer aSplitPos = theValue.Search ("|");
206 Prs3d_DatumParts aPart = Prs3d_DP_None;
209 convertToDatumParts (theValue.SubString (aSplitPos + 1, theValue.Length()), theParts);
210 if (aSplitPos == 1) // first symbol
214 aValue = theValue.SubString (1, aSplitPos - 1);
216 if (convertToDatumPart (aValue, aPart))
218 theParts.Append (aPart);
222 static bool convertToDatumAttribute (const TCollection_AsciiString& theValue,
223 Prs3d_DatumAttribute& theAttribute)
225 TCollection_AsciiString aValue = theValue;
227 if (aValue == "xaxislength") theAttribute = Prs3d_DA_XAxisLength;
228 else if (aValue == "yaxislength") theAttribute = Prs3d_DA_YAxisLength;
229 else if (aValue == "zaxislength") theAttribute = Prs3d_DA_ZAxisLength;
230 else if (aValue == "tuberadiuspercent") theAttribute = Prs3d_DP_ShadingTubeRadiusPercent;
231 else if (aValue == "coneradiuspercent") theAttribute = Prs3d_DP_ShadingConeRadiusPercent;
232 else if (aValue == "conelengthpercent") theAttribute = Prs3d_DP_ShadingConeLengthPercent;
233 else if (aValue == "originradiuspercent") theAttribute = Prs3d_DP_ShadingOriginRadiusPercent;
234 else if (aValue == "shadingnumberoffacettes") theAttribute = Prs3d_DP_ShadingNumberOfFacettes;
240 static void convertToDatumAttributes (const TCollection_AsciiString& theValue,
241 NCollection_List<Prs3d_DatumAttribute>& theAttributes)
243 TCollection_AsciiString aValue = theValue;
244 const Standard_Integer aSplitPos = theValue.Search ("|");
245 Prs3d_DatumAttribute anAttribute = Prs3d_DA_XAxisLength;
248 convertToDatumAttributes (theValue.SubString (aSplitPos + 1, theValue.Length()), theAttributes);
249 if (aSplitPos == 1) // first symbol
253 aValue = theValue.SubString (1, aSplitPos - 1);
255 if (convertToDatumAttribute (aValue, anAttribute))
257 theAttributes.Append (anAttribute);
261 static bool convertToDatumAxes (const TCollection_AsciiString& theValue,
262 Prs3d_DatumAxes& theDatumAxes)
264 TCollection_AsciiString aValue = theValue;
266 if (aValue == "x") theDatumAxes = Prs3d_DA_XAxis;
267 else if (aValue == "y") theDatumAxes = Prs3d_DA_YAxis;
268 else if (aValue == "z") theDatumAxes = Prs3d_DA_ZAxis;
269 else if (aValue == "xy") theDatumAxes = Prs3d_DA_XYAxis;
270 else if (aValue == "zy") theDatumAxes = Prs3d_DA_YZAxis;
271 else if (aValue == "xz") theDatumAxes = Prs3d_DA_XZAxis;
272 else if (aValue == "xyz") theDatumAxes = Prs3d_DA_XYZAxis;
280 static Standard_Boolean setTrihedronParams (Standard_Integer theArgsNb,
281 const char** theArgVec,
282 Handle(AIS_Trihedron) theTrihedron)
284 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
285 TCollection_AsciiString aParseKey;
286 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
288 TCollection_AsciiString anArg (theArgVec [anArgIt]);
289 if (anArg.Value (1) == '-'
290 && !anArg.IsRealValue())
293 aParseKey.Remove (1);
294 aParseKey.LowerCase();
295 std::string aKey = aParseKey.ToCString();
296 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString());
300 if (aParseKey.IsEmpty())
305 aMapOfArgs (aParseKey)->Append (anArg);
309 if ((aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis"))
310 || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")))
312 std::cout << "Syntax error: -xaxis and -zaxis parameters are to set together.\n";
313 return Standard_False;
316 Handle(TColStd_HSequenceOfAsciiString) aValues;
317 Handle(Geom_Axis2Placement) aComponent = theTrihedron->Component();
318 if (aMapOfArgs.Find ("origin", aValues))
320 aComponent->SetLocation (gp_Pnt (aValues->Value (1).RealValue(),
321 aValues->Value (2).RealValue(),
322 aValues->Value (3).RealValue()));
324 Handle(TColStd_HSequenceOfAsciiString) aXValues, aZValues;
325 if (aMapOfArgs.Find ("xaxis", aXValues) && aMapOfArgs.Find ("zaxis", aZValues))
327 gp_Dir aXDir (aXValues->Value (1).RealValue(),
328 aXValues->Value (2).RealValue(),
329 aXValues->Value (3).RealValue());
331 gp_Dir aZDir (aZValues->Value (1).RealValue(),
332 aZValues->Value (2).RealValue(),
333 aZValues->Value (3).RealValue());
335 if (!aZDir.IsNormal (aXDir, M_PI / 180.0))
337 std::cout << "Syntax error - parameters 'xaxis' and 'zaxis' are not applied as VectorX is not normal to VectorZ\n";
338 return Standard_False;
341 aComponent->SetAx2 (gp_Ax2 (aComponent->Location(), aZDir, aXDir));
344 if (aMapOfArgs.Find ("dispmode", aValues))
346 TCollection_AsciiString aValue (aValues->Value (1));
347 bool isWireframe = true;
348 if (aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
350 theTrihedron->SetDatumDisplayMode (isWireframe ? Prs3d_DM_WireFrame
354 if (aMapOfArgs.Find ("hidelabels", aValues))
356 Standard_Boolean toHideLabels = Standard_True;
357 if (aValues->Size() == 1)
359 ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideLabels);
361 else if (aValues->Size() != 0)
363 std::cout << "Syntax error: -hidelabels expects parameter 'on' or 'off' after.\n";
364 return Standard_False;
367 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
369 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
371 theTrihedron->Attributes()->DatumAspect()->SetDrawLabels (!toHideLabels);
374 if (aMapOfArgs.Find ("hidearrows", aValues))
376 Standard_Boolean toHideArrows = Standard_True;
377 if (aValues->Size() == 1)
379 ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideArrows);
381 else if (aValues->Size() != 0)
383 std::cout << "Syntax error: -hidearrows expects parameter 'on' or 'off' after.\n";
384 return Standard_False;
387 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
389 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
391 theTrihedron->Attributes()->DatumAspect()->SetDrawArrows (!toHideArrows);
394 if (aMapOfArgs.Find ("color", aValues))
396 NCollection_List<Prs3d_DatumParts> aParts;
397 if (aValues->Size() < 2)
399 std::cout << "Syntax error: -color wrong parameters.\n";
400 return Standard_False;
403 convertToDatumParts (aValues->Value(1), aParts);
404 aValues->Remove (1); // datum part is processed
405 Quantity_Color aColor;
406 if (!convertToColor (aValues, aColor))
408 std::cout << "Syntax error: -color wrong parameters.\n";
409 return Standard_False;
412 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (aParts); anIterator.More(); anIterator.Next())
414 Prs3d_DatumParts aDatumPart = anIterator.Value();
415 if (aDatumPart == Prs3d_DP_None)
417 theTrihedron->SetColor (aColor);
421 theTrihedron->SetDatumPartColor (aDatumPart, aColor);
426 if (aMapOfArgs.Find ("textcolor", aValues))
428 Quantity_Color aColor;
429 if (!convertToColor (aValues, aColor))
431 std::cout << "Syntax error: -textcolor wrong parameters.\n";
432 return Standard_False;
434 theTrihedron->SetTextColor (aColor);
437 if (aMapOfArgs.Find ("arrowcolor", aValues))
439 Quantity_Color aColor;
440 if (!convertToColor (aValues, aColor))
442 std::cout << "Syntax error: -arrowcolor wrong parameters.\n";
443 return Standard_False;
445 theTrihedron->SetArrowColor (aColor);
448 if (aMapOfArgs.Find ("attribute", aValues))
450 NCollection_List<Prs3d_DatumAttribute> anAttributes;
451 if (aValues->Size() != 2)
453 std::cout << "Syntax error: -attribute wrong parameters.\n";
454 return Standard_False;
457 convertToDatumAttributes (aValues->Value (1), anAttributes);
458 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
459 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
460 for (NCollection_List<Prs3d_DatumAttribute>::Iterator anIterator (anAttributes); anIterator.More(); anIterator.Next())
462 theTrihedron->Attributes()->DatumAspect()->SetAttribute (anIterator.Value(), aValues->Value (2).RealValue());
466 if (aMapOfArgs.Find ("priority", aValues))
468 Prs3d_DatumParts aDatumPart;
469 if (aValues->Size() < 2
470 || !convertToDatumPart (aValues->Value (1), aDatumPart))
472 std::cout << "Syntax error: -priority wrong parameters.\n";
473 return Standard_False;
475 theTrihedron->SetSelectionPriority (aDatumPart, aValues->Value (2).IntegerValue());
478 if (aMapOfArgs.Find ("labels", aValues)
479 || aMapOfArgs.Find ("label", aValues))
481 Prs3d_DatumParts aDatumPart = Prs3d_DP_None;
482 if (aValues->Size() >= 2
483 && convertToDatumPart(aValues->Value(1), aDatumPart)
484 && aDatumPart >= Prs3d_DP_XAxis
485 && aDatumPart <= Prs3d_DP_ZAxis) // labels are set to axes only
487 theTrihedron->SetLabel (aDatumPart, aValues->Value (2));
491 std::cout << "Syntax error: -labels wrong parameters.\n";
492 return Standard_False;
496 if (aMapOfArgs.Find ("drawaxes", aValues))
498 Prs3d_DatumAxes aDatumAxes = Prs3d_DA_XAxis;
499 if (aValues->Size() < 1
500 || !convertToDatumAxes (aValues->Value (1), aDatumAxes))
502 std::cout << "Syntax error: -drawaxes wrong parameters.\n";
503 return Standard_False;
505 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
506 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
507 theTrihedron->Attributes()->DatumAspect()->SetDrawDatumAxes (aDatumAxes);
509 return Standard_True;
512 //! Auxiliary function to parse font aspect style argument
513 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
514 Font_FontAspect& theAspect)
516 if (theArg == "regular"
517 || *theArg.ToCString() == 'r')
519 theAspect = Font_FA_Regular;
520 return Standard_True;
522 else if (theArg == "bolditalic"
523 || theArg == "bold-italic"
524 || theArg == "italic-bold"
525 || theArg == "italicbold")
527 theAspect = Font_FA_BoldItalic;
528 return Standard_True;
530 else if (theArg == "bold"
531 || *theArg.ToCString() == 'b')
533 theAspect = Font_FA_Bold;
534 return Standard_True;
536 else if (theArg == "italic"
537 || *theArg.ToCString() == 'i')
539 theAspect = Font_FA_Italic;
540 return Standard_True;
542 return Standard_False;
545 //! Auxiliary function to parse font strict level argument
546 static Standard_Integer parseFontStrictLevel (const Standard_Integer theArgNb,
547 const char** theArgVec,
548 Font_StrictLevel& theLevel)
552 TCollection_AsciiString anArg (theArgVec[0]);
556 theLevel = Font_StrictLevel_Any;
559 else if (anArg == "aliases")
561 theLevel = Font_StrictLevel_Aliases;
564 else if (anArg == "strict")
566 theLevel = Font_StrictLevel_Strict;
570 theLevel = Font_StrictLevel_Strict;
575 //==============================================================================
576 //function : Vtrihedron 2d
577 //purpose : Create a plane with a 2D trihedron from a faceselection
578 //Draw arg : vtri2d name
579 //==============================================================================
580 static int VTrihedron2D (Draw_Interpretor& /*theDI*/,
581 Standard_Integer theArgsNum,
582 const char** theArgVec)
586 std::cerr << theArgVec[0]<< " error.\n";
590 TopTools_ListOfShape aShapes;
591 ViewerTest::GetSelectedShapes (aShapes);
593 if (aShapes.Extent() != 1)
595 std::cerr << "Error: wrong number of selected shapes.\n";
599 const TopoDS_Shape& aShape = aShapes.First();
601 TopoDS_Face aFace = TopoDS::Face (aShape);
602 TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE);
603 TopoDS_Edge anEdge0 = TopoDS::Edge (aFaceExp.Current());
609 TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() );
610 BRepAdaptor_Curve aCurve0 (anEdge0);
611 BRepAdaptor_Curve aCurve1 (anEdge1);
612 A = aCurve1.Value (0.1);
613 B = aCurve1.Value (0.9);
614 C = aCurve0.Value (0.5);
618 BRepAdaptor_Curve aCurve0 (anEdge0);
619 A = aCurve0.Value (0.1);
620 B = aCurve0.Value (0.9);
621 C = aCurve0.Value (0.5);
624 GC_MakePlane aMkPlane (A,B,C);
626 Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value());
627 TCollection_AsciiString aName (theArgVec[1]);
629 VDisplayAISObject (aName, anAISPlaneTri);
634 //=======================================================================
635 //function : VTrihedron
637 //=======================================================================
638 static int VTrihedron (Draw_Interpretor& ,
639 Standard_Integer theArgsNb,
640 const char** theArgVec)
644 std::cout << "Syntax error: the wrong number of input parameters.\n";
648 TCollection_AsciiString aName (theArgVec[1]);
649 gp_Pln aWorkingPlane;
650 Standard_Boolean toUpdate = Standard_True;
652 NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
653 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
655 Handle(AIS_Trihedron) aTrihedron;
656 Handle(AIS_InteractiveObject) anObject;
657 if (GetMapOfAIS().Find2 (aName, anObject))
659 aTrihedron = Handle(AIS_Trihedron)::DownCast (anObject);
660 if (aTrihedron.IsNull())
662 std::cout << "Syntax error: no trihedron with this name.\n";
668 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (gp_Pnt (0.0, 0.0, 0.0),
670 aTrihedron = new AIS_Trihedron (aPlacement);
673 if (!setTrihedronParams (theArgsNb, theArgVec, aTrihedron))
678 // Redisplay a dimension after parameter changing.
679 if (ViewerTest::GetAISContext()->IsDisplayed (aTrihedron))
681 ViewerTest::GetAISContext()->Redisplay (aTrihedron, toUpdate);
685 VDisplayAISObject (theArgVec[1], aTrihedron);
691 //==============================================================================
694 //purpose : Change the size of a named or selected trihedron
695 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
696 // if no value, the value is set at 100 by default
697 //Draw arg : vsize [name] [size]
698 //==============================================================================
700 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
703 // Declaration de booleens
704 Standard_Boolean ThereIsName;
705 Standard_Boolean ThereIsCurrent;
707 Standard_Boolean hascol;
709 Quantity_Color col = Quantity_NOC_BLACK;
711 // Verification des arguments
712 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;}
714 // Verification du nombre d'arguments
715 if (argc==1) {ThereIsName=Standard_False;value=100;}
716 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
717 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
719 // On set le booleen ThereIsCurrent
720 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
721 else {ThereIsCurrent=Standard_False;}
725 //===============================================================
726 // Il n'y a pas de nom mais des objets selectionnes
727 //===============================================================
728 if (!ThereIsName && ThereIsCurrent)
731 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
734 while ( it.More() ) {
736 Handle(AIS_InteractiveObject) aShape = it.Key1();
738 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
741 // On verifie que l'AIS InteraciveObject selectionne est bien
743 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
745 if (aShape->HasColor())
747 hascol = Standard_True;
749 // On recupere la couleur de aShape
754 hascol = Standard_False;
757 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
758 // pour lui appliquer la methode SetSize()
759 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
761 // C'est bien un triedre,on chage sa valeur!
762 aTrihedron->SetSize(value);
764 // On donne la couleur au Trihedron
765 if(hascol) aTrihedron->SetColor(col);
766 else aTrihedron->UnsetColor();
769 // The trihedron hasn't be errased from the map
770 // so you just have to redisplay it
771 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
780 TheAISContext() ->UpdateCurrentViewer();
783 //===============================================================
784 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
785 //===============================================================
789 //===============================================================
790 // Il y a un nom de triedre passe en argument
791 //===============================================================
793 TCollection_AsciiString name=argv[1];
795 // on verifie que ce nom correspond bien a une shape
796 Handle(AIS_InteractiveObject) aShape;
797 if (GetMapOfAIS().Find2(name, aShape))
799 // On verifie que l'AIS InteraciveObject est bien
801 if (!aShape.IsNull() &&
802 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
804 if (aShape->HasColor())
806 hascol=Standard_True;
808 // On recupere la couleur de aShape
813 hascol = Standard_False;
816 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
817 // pour lui appliquer la methode SetSize()
818 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
820 // C'est bien un triedre,on chage sa valeur
821 aTrihedron->SetSize(value);
823 // On donne la couleur au Trihedron
824 if(hascol) aTrihedron->SetColor(col);
825 else aTrihedron->UnsetColor();
827 // The trihedron hasn't be errased from the map
828 // so you just have to redisplay it
829 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
831 TheAISContext() ->UpdateCurrentViewer();
839 //==============================================================================
841 //==============================================================================
842 //function : VPlaneTrihedron
843 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
844 //Draw arg : vplanetri name
845 //==============================================================================
846 #include <AIS_Plane.hxx>
850 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
853 // Verification des arguments
854 if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
856 if (TheAISContext()->NbSelected() != 1)
858 std::cerr << "Error: Wrong number of selected shapes.\n";
862 TheAISContext()->InitSelected();
863 Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive();
864 Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest);
867 std::cerr << "Error: Selected shape is not a plane.\n";
871 VDisplayAISObject (argv[1], aPlane);
878 //==============================================================================
879 // Fonction First click 2de click
881 // vaxis vertex vertex
883 // vaxispara edge vertex
884 // vaxisortho edge Vertex
885 // vaxisinter Face Face
886 //==============================================================================
888 //==============================================================================
889 //function : VAxisBuilder
891 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
892 //==============================================================================
893 #include <TopoDS_Edge.hxx>
894 #include <TopoDS_Vertex.hxx>
895 #include <TopExp.hxx>
896 #include <Geom_Line.hxx>
898 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
901 Standard_Boolean HasArg;
902 TCollection_AsciiString name;
905 if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
906 if (argc==8) HasArg=Standard_True;
907 else HasArg=Standard_False;
911 TopTools_ListOfShape aShapes;
912 ViewerTest::GetSelectedShapes (aShapes);
914 // Cas ou il y a des arguments
915 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
917 Standard_Real coord[6];
918 for(Standard_Integer i=0;i<=5;i++){
919 coord[i]=Draw::Atof(argv[2+i]);
921 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
923 gp_Vec myVect (p1,p2);
924 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
925 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
926 GetMapOfAIS().Bind (TheAxis,name);
927 TheAISContext()->Display(TheAxis, Standard_True);
933 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
934 if ( !strcasecmp(argv[0], "vaxis")) {
935 if (aShapes.Extent() != 2 && aShapes.Extent() != 1)
937 std::cerr << "Error: Wrong number of selected shapes.\n";
941 const TopoDS_Shape& aShapeA = aShapes.First();
942 if (aShapeA.ShapeType() == TopAbs_VERTEX)
944 if (aShapes.Extent() != 2)
946 std::cerr << "Error: Wron number of selected shapes.\n";
950 const TopoDS_Shape& aShapeB = aShapes.Last();
951 if (aShapeB.ShapeType() != TopAbs_VERTEX)
953 std::cerr << "Syntax error: You should select two vertices or one edge.\n";
957 // Construction de l'axe
958 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
959 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
962 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
963 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
964 GetMapOfAIS().Bind (TheAxis,name);
965 TheAISContext()->Display (TheAxis, Standard_True);
969 TopoDS_Edge ed =TopoDS::Edge (aShapeA);
971 TopExp::Vertices(ed,Va,Vb );
972 gp_Pnt A=BRep_Tool::Pnt(Va);
973 gp_Pnt B=BRep_Tool::Pnt(Vb);
976 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
977 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
978 GetMapOfAIS().Bind (TheAxis,name);
979 TheAISContext()->Display (TheAxis, Standard_True);
985 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
986 else if ( !strcasecmp(argv[0], "vaxispara"))
988 if (aShapes.Extent() != 2)
990 std::cerr << "Error: Wrong number of selected shapes.\n";
994 const TopoDS_Shape& aShapeA = aShapes.First();
995 const TopoDS_Shape& aShapeB = aShapes.Last();
996 if (!(aShapeA.ShapeType() == TopAbs_EDGE
997 && aShapeB.ShapeType() == TopAbs_VERTEX))
999 std::cerr << "Syntax error: You should select face and then vertex.\n";
1003 TopoDS_Edge ed=TopoDS::Edge (aShapeA);
1004 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1005 TopoDS_Vertex Va,Vc;
1006 TopExp::Vertices(ed,Va,Vc );
1007 gp_Pnt A=BRep_Tool::Pnt(Va);
1008 gp_Pnt C=BRep_Tool::Pnt(Vc);
1011 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1012 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1013 GetMapOfAIS().Bind (TheAxis,name);
1014 TheAISContext()->Display (TheAxis, Standard_True);
1018 // Fonction axisortho
1021 if (aShapes.Extent() != 2)
1023 std::cerr << "Error: Wrong number of selected shapes.\n";
1027 const TopoDS_Shape& aShapeA = aShapes.First();
1028 const TopoDS_Shape& aShapeB = aShapes.Last();
1029 if (!(aShapeA.ShapeType() == TopAbs_EDGE
1030 && aShapeB.ShapeType() == TopAbs_VERTEX))
1032 std::cerr << "Syntax error: You should select face and then vertex.\n";
1036 // Construction de l'axe
1037 TopoDS_Edge ed=TopoDS::Edge(aShapeA) ;
1038 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) );
1039 TopoDS_Vertex Va,Vc;
1040 TopExp::Vertices(ed,Va,Vc );
1041 gp_Pnt A=BRep_Tool::Pnt(Va);
1042 gp_Pnt C=BRep_Tool::Pnt(Vc);
1043 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
1046 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1047 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1048 GetMapOfAIS().Bind (TheAxis,name);
1049 TheAISContext()->Display (TheAxis, Standard_True);
1058 //==============================================================================
1059 // Fonction First click Result
1061 // vpoint vertex AIS_Point=Vertex
1062 // edge AIS_Point=Middle of the edge
1063 //==============================================================================
1065 //==============================================================================
1066 //function : VPointBuilder
1067 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
1068 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
1069 //==============================================================================
1070 #include <TopoDS_Edge.hxx>
1071 #include <TopoDS_Vertex.hxx>
1072 #include <TopExp.hxx>
1073 #include <AIS_Point.hxx>
1074 #include <Geom_CartesianPoint.hxx>
1076 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1079 Standard_Boolean HasArg;
1080 TCollection_AsciiString name;
1083 if (argc<2 || argc>5 ) {di<<" Syntaxe error\n";return 1;}
1084 if (argc==5) HasArg=Standard_True;
1085 else HasArg=Standard_False;
1089 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
1091 Standard_Real thecoord[3];
1092 for(Standard_Integer i=0;i<=2;i++)
1093 thecoord[i]=Draw::Atof(argv[2+i]);
1094 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
1095 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
1096 GetMapOfAIS().Bind (myAISPoint,name);
1097 TheAISContext()->Display (myAISPoint, Standard_True);
1100 // Il n'a pas d'arguments
1103 TopTools_ListOfShape aShapes;
1104 ViewerTest::GetSelectedShapes (aShapes);
1106 if (aShapes.Extent() != 1)
1108 std::cerr << "Error: Wrong number of selected shapes.\n";
1109 std::cerr << "\tYou should select one edge or vertex.\n";
1113 const TopoDS_Shape& aShapeA = aShapes.First();
1115 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1117 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(aShapeA ) );
1118 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
1119 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
1120 GetMapOfAIS().Bind(myAISPoint,name);
1121 TheAISContext()->Display (myAISPoint, Standard_True);
1125 TopoDS_Edge myEdge=TopoDS::Edge(aShapeA);
1126 TopoDS_Vertex myVertexA,myVertexB;
1127 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
1128 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
1129 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
1130 // M est le milieu de [AB]
1131 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
1132 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
1133 GetMapOfAIS().Bind(myAISPointM,name);
1134 TheAISContext()->Display (myAISPointM, Standard_True);
1142 //==============================================================================
1143 // Function 1st click 2de click 3de click
1144 // vplane Vertex Vertex Vertex
1148 // vplanepara Face Vertex
1150 // vplaneortho Face Edge
1152 //==============================================================================
1154 //==============================================================================
1155 //function : VPlaneBuilder
1156 //purpose : Build an AIS_Plane from selected entities or Named AIS components
1157 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
1158 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
1159 // [PlaneName] [PointName] [TypeOfSensitivity]
1160 //==============================================================================
1162 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
1163 Standard_Integer argc,
1167 Standard_Boolean hasArg;
1168 TCollection_AsciiString aName;
1171 if (argc<2 || argc>6 )
1173 std::cout<<" Syntax error\n";
1176 if (argc == 6 || argc==5 || argc==4)
1177 hasArg=Standard_True;
1179 hasArg=Standard_False;
1183 // There are some arguments
1186 Handle(AIS_InteractiveObject) aShapeA;
1187 if (!GetMapOfAIS().Find2 (argv[2], aShapeA))
1189 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
1193 // The first argument is an AIS_Point
1194 if (!aShapeA.IsNull() &&
1195 aShapeA->Type()==AIS_KOI_Datum &&
1196 aShapeA->Signature()==1)
1198 // The second argument must also be an AIS_Point
1199 Handle(AIS_InteractiveObject) aShapeB;
1200 if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1202 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
1205 // If B is not an AIS_Point
1206 if (aShapeB.IsNull() ||
1207 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1209 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
1212 // The third object is an AIS_Point
1213 Handle(AIS_InteractiveObject) aShapeC;
1214 if (!GetMapOfAIS().Find2(argv[4], aShapeC))
1216 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
1219 // If C is not an AIS_Point
1220 if (aShapeC.IsNull() ||
1221 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
1223 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
1227 // Treatment of objects A, B, C
1228 // Downcast an AIS_IO to AIS_Point
1229 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
1230 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
1231 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
1233 Handle(Geom_CartesianPoint ) aCartPointA =
1234 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
1236 Handle(Geom_CartesianPoint ) aCartPointB =
1237 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
1239 Handle(Geom_CartesianPoint ) aCartPointC =
1240 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
1242 // Verification that the three points are different
1243 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
1244 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1245 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
1248 std::cout<<"vplane error: same points\n";return 1;
1250 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1251 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1252 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1255 std::cout<<"vplane error: same points\n";return 1;
1257 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1258 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1259 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1262 std::cout<<"vplane error: same points\n";return 1;
1265 gp_Pnt A = aCartPointA->Pnt();
1266 gp_Pnt B = aCartPointB->Pnt();
1267 gp_Pnt C = aCartPointC->Pnt();
1269 // Construction of AIS_Plane
1270 GC_MakePlane MkPlane (A,B,C);
1271 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1272 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1273 GetMapOfAIS().Bind (anAISPlane,aName );
1276 Standard_Integer aType = Draw::Atoi (argv[5]);
1277 if (aType != 0 && aType != 1)
1279 std::cout << "vplane error: wrong type of sensitivity!\n"
1280 << "Should be one of the following values:\n"
1288 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1291 TheAISContext()->Display (anAISPlane, Standard_True);
1294 // The first argument is an AIS_Axis
1295 // Creation of a plane orthogonal to the axis through a point
1296 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1297 // The second argument should be an AIS_Point
1298 Handle(AIS_InteractiveObject) aShapeB;
1299 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1301 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1304 // If B is not an AIS_Point
1305 if (aShapeB.IsNull() ||
1306 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1308 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1312 // Treatment of objects A and B
1313 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1314 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1316 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1317 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1319 gp_Ax1 anAxis = aGeomLineA->Position();
1320 Handle(Geom_CartesianPoint) aCartPointB =
1321 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1323 gp_Dir D =anAxis.Direction();
1324 gp_Pnt B = aCartPointB->Pnt();
1326 // Construction of AIS_Plane
1327 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1328 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1329 GetMapOfAIS().Bind (anAISPlane,aName );
1332 Standard_Integer aType = Draw::Atoi (argv[4]);
1333 if (aType != 0 && aType != 1)
1335 std::cout << "vplane error: wrong type of sensitivity!\n"
1336 << "Should be one of the following values:\n"
1344 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1347 TheAISContext()->Display (anAISPlane, Standard_True);
1350 // The first argumnet is an AIS_Plane
1351 // Creation of a plane parallel to the plane passing through the point
1352 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1354 // The second argument should be an AIS_Point
1355 Handle(AIS_InteractiveObject) aShapeB;
1356 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1358 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1361 // B should be an AIS_Point
1362 if (aShapeB.IsNull() ||
1363 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1365 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1369 // Treatment of objects A and B
1370 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1371 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1373 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1374 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1376 Handle(Geom_CartesianPoint) aCartPointB =
1377 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1378 gp_Pnt B= aCartPointB->Pnt();
1380 // Construction of an AIS_Plane
1381 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1382 GetMapOfAIS().Bind (anAISPlane, aName);
1385 Standard_Integer aType = Draw::Atoi (argv[4]);
1386 if (aType != 0 && aType != 1)
1388 std::cout << "vplane error: wrong type of sensitivity!\n"
1389 << "Should be one of the following values:\n"
1397 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1400 TheAISContext()->Display (anAISPlane, Standard_True);
1405 std::cout<<"vplane: error 1st object is not an AIS\n";
1409 // There are no arguments
1412 TopTools_ListOfShape aShapes;
1413 ViewerTest::GetSelectedShapes (aShapes);
1416 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1417 if (!strcasecmp(argv[0], "vplane"))
1419 if (aShapes.Extent() < 1 || aShapes.Extent() > 3)
1421 std::cerr << "Error: Wront number of selected shapes.\n";
1422 std::cerr << "\tYou should one of variant: face, edge and vertex or three vertices.\n";
1426 const TopoDS_Shape& aShapeA = aShapes.First();
1427 if (aShapeA.ShapeType() == TopAbs_VERTEX)
1429 if (aShapes.Extent() == 2)
1431 const TopoDS_Shape& aShapeB = aShapes.Last();
1432 if (aShapeB.ShapeType() != TopAbs_EDGE)
1434 std::cerr << "Syntax error: Together with vertex should be edge.\n";
1438 // Verify that the vertex is not on the edge ShapeB
1439 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1440 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1442 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1443 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1445 // The vertex is on the edge
1446 std::cout<<" vplane: error point is on the edge\n";
1451 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1452 TopoDS_Vertex aVBa, aVBb;
1453 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1454 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1455 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1456 GC_MakePlane MkPlane (A, aBa, aBb);
1457 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1458 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1459 GetMapOfAIS().Bind (anAISPlane, aName);
1460 TheAISContext()->Display (anAISPlane, Standard_True);
1463 else if (aShapes.Extent() == 3)
1465 TopTools_ListOfShape::Iterator anIter (aShapes);
1468 const TopoDS_Shape& aShapeB = anIter.Value();
1471 const TopoDS_Shape& aShapeC = anIter.Value();
1473 if (!(aShapeB.ShapeType() == TopAbs_VERTEX
1474 && aShapeC.ShapeType() == TopAbs_VERTEX))
1476 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1480 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1481 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1482 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1483 GC_MakePlane MkPlane(A, B, C);
1484 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1485 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1486 GetMapOfAIS().Bind (anAISPlane, aName);
1487 TheAISContext()->Display (anAISPlane, Standard_True);
1491 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1495 else if (aShapeA.ShapeType() == TopAbs_EDGE)
1497 if (aShapes.Extent() != 2)
1499 std::cerr << "Error: wrong number of selected shapes.\n";
1503 const TopoDS_Shape& aShapeB = aShapes.Last();
1504 if (aShapeB.ShapeType() != TopAbs_VERTEX)
1506 std::cerr << "Syntax error: Together with edge should be vertex.\n";
1510 // Check that the vertex aShapeB is not on the edge
1511 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1512 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1514 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1515 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1517 // The vertex is on the edge
1518 std::cout<<" vplane: error point is on the edge\n";
1522 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1523 TopoDS_Vertex aVAa, aVAb;
1524 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1525 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1526 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1527 GC_MakePlane MkPlane (B,Aa,Ab);
1528 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1529 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1530 GetMapOfAIS().Bind (anAISPlane ,aName);
1531 TheAISContext()->Display (anAISPlane, Standard_True);
1533 else if (aShapeA.ShapeType() == TopAbs_FACE)
1535 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1536 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1537 if (aSurface.GetType()==GeomAbs_Plane)
1539 gp_Pln aPlane = aSurface.Plane();
1540 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1541 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1542 GetMapOfAIS().Bind (anAISPlane, aName);
1543 TheAISContext()->Display (anAISPlane, Standard_True);
1547 std::cout<<" vplane: error\n";
1553 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1558 // Function vPlanePara
1559 // ===================
1560 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1561 else if (!strcasecmp(argv[0], "vplanepara"))
1563 if (aShapes.Extent() != 2)
1565 std::cerr << "Error: Wrong number of selected shapes.\n";
1569 const TopoDS_Shape* aShapeA = &aShapes.First();
1570 const TopoDS_Shape* aShapeB = &aShapes.Last();
1571 if (aShapeA->ShapeType() != TopAbs_VERTEX)
1573 std::swap (aShapeA, aShapeB);
1576 if (!(aShapeA->ShapeType() == TopAbs_VERTEX
1577 && aShapeB->ShapeType() == TopAbs_FACE))
1579 std::cerr << "Syntax error: you should select face and vertex.\n";
1583 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA));
1585 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1586 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1587 if (aSurface.GetType() == GeomAbs_Plane)
1589 gp_Pln aPlane = aSurface.Plane();
1590 // Construct a plane parallel to aGeomPlane through A
1591 aPlane.SetLocation(A);
1592 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1593 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1594 GetMapOfAIS().Bind (aAISPlane ,aName);
1595 TheAISContext()->Display (aAISPlane, Standard_True);
1599 std::cerr << "Error: Builded surface is not a plane.\n";
1604 // Function vplaneortho
1605 // ====================
1606 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1609 if (aShapes.Extent() != 2)
1611 std::cerr << "Error: wrong number of selected shapes.\n";
1615 const TopoDS_Shape* aShapeA = &aShapes.First();
1616 const TopoDS_Shape* aShapeB = &aShapes.Last();
1618 if (aShapeA->ShapeType() != TopAbs_EDGE)
1620 std::swap (aShapeA, aShapeB);
1623 if (!(aShapeA->ShapeType() == TopAbs_EDGE
1624 && aShapeB->ShapeType() == TopAbs_FACE))
1626 std::cerr << "Error: you should select edge and face.\n";
1630 // Construction of plane
1631 TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA);
1632 TopoDS_Vertex aVAa, aVAb;
1633 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1634 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1635 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1639 // Creation of rotation axis
1640 gp_Ax1 aRotAxis (Aa,Dab);
1642 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1643 // The edge must be parallel to the face
1644 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1645 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1646 // Compare to heights
1647 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1648 >Precision::Confusion())
1650 // the edge is not parallel to the face
1651 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1655 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1656 if (aSurface.GetType()==GeomAbs_Plane)
1658 gp_Pln aPlane = aSurface.Plane();
1659 // It rotates a half turn round the axis of rotation
1660 aPlane.Rotate(aRotAxis , M_PI/2);
1662 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1663 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1664 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1665 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1666 GetMapOfAIS().Bind (anAISPlane, aName);
1667 TheAISContext()->Display (anAISPlane, Standard_True);
1671 std::cout<<" vplaneortho: error\n";
1679 //===============================================================================================
1680 //function : VChangePlane
1682 //===============================================================================================
1683 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1685 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1686 if (aContextAIS.IsNull())
1688 std::cout << theArgVec[0] << "AIS context is not available.\n";
1692 if (theArgsNb < 3 || theArgsNb > 11)
1694 std::cerr << theArgVec[0]
1695 << ": incorrect number of command arguments.\n"
1696 << "Type help for more information.\n";
1700 TCollection_AsciiString aName (theArgVec[1]);
1702 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1703 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1706 if ( aPlane.IsNull() )
1708 std::cout << theArgVec[0]
1709 << ": there is no interactive plane with the given name."
1710 << "Type help for more information.\n";
1714 Standard_Real aCenterX = aPlane->Center().X();
1715 Standard_Real aCenterY = aPlane->Center().Y();
1716 Standard_Real aCenterZ = aPlane->Center().Z();
1718 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1719 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1720 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1722 Standard_Real aSizeX = 0.0;
1723 Standard_Real aSizeY = 0.0;
1724 aPlane->Size (aSizeX, aSizeY);
1725 Standard_Boolean isUpdate = Standard_True;
1727 TCollection_AsciiString aPName, aPValue;
1728 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1730 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1731 TCollection_AsciiString anArgCase = anArg;
1732 anArgCase.UpperCase();
1733 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1736 if (aPName.IsEqual ("X"))
1738 aCenterX = aPValue.RealValue();
1740 else if (aPName.IsEqual ("Y"))
1742 aCenterY = aPValue.RealValue();
1744 else if (aPName.IsEqual ("Z"))
1746 aCenterZ = aPValue.RealValue();
1748 else if (aPName.IsEqual ("DX"))
1750 aDirX = aPValue.RealValue();
1752 else if (aPName.IsEqual ("DY"))
1754 aDirY = aPValue.RealValue();
1756 else if (aPName.IsEqual ("DZ"))
1758 aDirZ = aPValue.RealValue();
1760 else if (aPName.IsEqual ("SX"))
1762 aSizeX = aPValue.RealValue();
1764 else if (aPName.IsEqual ("SY"))
1766 aSizeY = aPValue.RealValue();
1769 else if (anArg.IsEqual ("NOUPDATE"))
1771 isUpdate = Standard_False;
1775 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1776 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1777 aPlane->SetCenter (aCenterPnt);
1778 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1779 aPlane->SetSize (aSizeX, aSizeY);
1781 aContextAIS->Update (aPlane, isUpdate);
1786 //==============================================================================
1788 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1789 //==============================================================================
1791 //==============================================================================
1792 //function : VLineBuilder
1793 //purpose : Build an AIS_Line
1794 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1795 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1796 //==============================================================================
1797 #include <Geom_CartesianPoint.hxx>
1798 #include <AIS_Line.hxx>
1801 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1804 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; }
1806 // On recupere les parametres
1807 Handle(AIS_InteractiveObject) theShapeA;
1808 Handle(AIS_InteractiveObject) theShapeB;
1810 // Parametres: AIS_Point AIS_Point
1811 // ===============================
1813 GetMapOfAIS().Find2 (argv[2], theShapeA);
1814 // On verifie que c'est bien une AIS_Point
1815 if (!theShapeA.IsNull() &&
1816 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1817 // on recupere le deuxieme AIS_Point
1818 GetMapOfAIS().Find2 (argv[3], theShapeB);
1819 if (theShapeB.IsNull() ||
1820 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1822 di <<"vline error: wrong type of 2de argument.\n";
1826 else {di <<"vline error: wrong type of 1st argument.\n";return 1; }
1827 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1828 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1829 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
1831 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1832 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
1833 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1835 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1836 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
1837 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1839 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1841 di<<"vline error: same points\n";return 1;
1843 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1844 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1845 GetMapOfAIS().Bind(theAISLine,argv[1] );
1846 TheAISContext()->Display (theAISLine, Standard_True);
1850 // Parametres 6 Reals
1851 // ==================
1854 // On verifie que les deux points ne sont pas confondus
1856 Standard_Real coord[6];
1857 for(Standard_Integer i=0;i<=2;i++){
1858 coord[i]=Draw::Atof(argv[2+i]);
1859 coord[i+3]=Draw::Atof(argv[5+i]);
1862 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1863 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1865 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1866 GetMapOfAIS().Bind(theAISLine,argv[1] );
1867 TheAISContext()->Display (theAISLine, Standard_True);
1871 // Pas de parametres: Selection dans le viewer.
1872 // ============================================
1876 TopTools_ListOfShape aShapes;
1877 ViewerTest::GetSelectedShapes (aShapes);
1878 if (aShapes.Extent() != 2)
1880 std::cerr << "Error: wrong number of selected shapes.\n";
1884 const TopoDS_Shape& aShapeA = aShapes.First();
1885 const TopoDS_Shape& aShapeB = aShapes.Last();
1887 if (!(aShapeA.ShapeType() == TopAbs_VERTEX
1888 && aShapeB.ShapeType() == TopAbs_VERTEX))
1890 std::cerr << "Error: you should select two different vertex.\n";
1894 // Construction de la line
1895 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1896 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
1898 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1899 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1901 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1902 GetMapOfAIS().Bind(theAISLine,argv[1] );
1903 TheAISContext()->Display (theAISLine, Standard_True);
1909 //==============================================================================
1910 // class : FilledCircle
1911 // purpose : creates filled circle based on AIS_InteractiveObject
1913 // This class is used to check method Matches() of class
1914 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1915 // because none of AIS classes provides creation of
1916 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1917 // (look method ComputeSelection() )
1918 //==============================================================================
1920 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1922 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1923 gp_Circ aCirc(anAxes, theRadius);
1924 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1928 class FilledCircle : public AIS_InteractiveObject
1932 DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject);
1934 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1935 FilledCircle(Handle(Geom_Circle) theCircle);
1938 TopoDS_Face ComputeFace();
1940 // Virtual methods implementation
1941 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1942 const Handle(Prs3d_Presentation)& thePresentation,
1943 const Standard_Integer theMode) Standard_OVERRIDE;
1945 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1946 const Standard_Integer theMode) Standard_OVERRIDE;
1949 Handle(Geom_Circle) myCircle;
1950 Standard_Boolean myFilledStatus;
1955 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1957 myCircle = CreateCircle(theCenter, theRadius);
1958 myFilledStatus = Standard_True;
1961 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1963 myCircle = theCircle;
1964 myFilledStatus = Standard_True;
1967 TopoDS_Face FilledCircle::ComputeFace()
1969 // Create edge from myCircle
1970 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1971 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1973 // Create wire from anEdge
1974 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1975 TopoDS_Wire aWire = aWireMaker.Wire();
1977 // Create face from aWire
1978 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1979 TopoDS_Face aFace = aFaceMaker.Face();
1984 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1985 const Handle(Prs3d_Presentation) &thePresentation,
1986 const Standard_Integer theMode)
1988 thePresentation->Clear();
1990 TopoDS_Face aFace = ComputeFace();
1992 if (aFace.IsNull()) return;
1993 if (theMode != 0) return;
1995 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1998 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
1999 const Standard_Integer /*theMode*/)
2001 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2002 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2003 myCircle, myFilledStatus);
2004 theSelection->Add(aSensitiveCircle);
2007 //==============================================================================
2009 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2010 //==============================================================================
2012 //==============================================================================
2013 //function : VCircleBuilder
2014 //purpose : Build an AIS_Circle
2015 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2016 // PointName PointName PointName IsFilled
2017 //==============================================================================
2019 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2020 TCollection_AsciiString theName,
2021 Standard_Boolean isFilled)
2023 Handle(AIS_InteractiveObject) aCircle;
2026 aCircle = new FilledCircle(theGeomCircle);
2030 aCircle = new AIS_Circle(theGeomCircle);
2031 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2034 // Check if there is an object with given name
2035 // and remove it from context
2036 if (GetMapOfAIS().IsBound2(theName))
2038 Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2(theName);
2039 TheAISContext()->Remove(anInterObj, Standard_False);
2040 GetMapOfAIS().UnBind2(theName);
2043 // Bind the circle to its name
2044 GetMapOfAIS().Bind(aCircle, theName);
2046 // Display the circle
2047 TheAISContext()->Display (aCircle, Standard_True);
2051 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2053 // Verification of the arguments
2054 if (argc>6 || argc<2)
2056 std::cout << "vcircle error: expect 4 arguments.\n";
2057 return 1; // TCL_ERROR
2060 // There are all arguments
2064 TCollection_AsciiString aName(argv[1]);
2065 Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0;
2067 Handle(AIS_InteractiveObject) theShapeA, theShapeB;
2068 GetMapOfAIS().Find2 (argv[2], theShapeA);
2069 GetMapOfAIS().Find2 (argv[3], theShapeB);
2071 // Arguments: AIS_Point AIS_Point AIS_Point
2072 // ========================================
2073 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2074 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2076 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2078 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2079 return 1; // TCL_ERROR
2081 // The third object must be a point
2082 Handle(AIS_InteractiveObject) theShapeC;
2083 GetMapOfAIS().Find2 (argv[4], theShapeC);
2084 if (theShapeC.IsNull() ||
2085 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2087 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2088 return 1; // TCL_ERROR
2091 // Verify that the three points are different
2092 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2093 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2094 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2096 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2097 Handle(Geom_CartesianPoint) myCartPointA =
2098 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2100 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2101 Handle(Geom_CartesianPoint) myCartPointB =
2102 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2104 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2105 Handle(Geom_CartesianPoint) myCartPointC =
2106 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2109 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2110 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2111 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2113 std::cout << "vcircle error: Same points.\n";
2114 return 1; // TCL_ERROR
2117 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2118 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2119 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2121 std::cout << "vcircle error: Same points.\n";
2122 return 1; // TCL_ERROR
2125 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2126 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2127 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2129 std::cout << "vcircle error: Same points.\n";
2130 return 1;// TCL_ERROR
2132 // Construction of the circle
2133 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2134 myCartPointB->Pnt(), myCartPointC->Pnt() );
2135 Handle (Geom_Circle) theGeomCircle;
2138 theGeomCircle = Cir.Value();
2140 catch (StdFail_NotDone const&)
2142 std::cout << "vcircle error: can't create circle\n";
2143 return -1; // TCL_ERROR
2146 DisplayCircle(theGeomCircle, aName, isFilled);
2149 // Arguments: AIS_Plane AIS_Point Real
2150 // ===================================
2151 else if (theShapeA->Type() == AIS_KOI_Datum &&
2152 theShapeA->Signature() == 7 )
2154 if (theShapeB->Type() != AIS_KOI_Datum ||
2155 theShapeB->Signature() != 1 )
2157 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2158 return 1; // TCL_ERROR
2160 // Check that the radius is >= 0
2161 if (Draw::Atof(argv[4]) <= 0 )
2163 std::cout << "vcircle error: the radius must be >=0.\n";
2164 return 1; // TCL_ERROR
2167 // Recover the normal to the plane
2168 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2169 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2171 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2172 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2173 Handle(Geom_CartesianPoint) myCartPointB =
2174 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2176 gp_Pln mygpPlane = myGeomPlane->Pln();
2177 gp_Ax1 thegpAxe = mygpPlane.Axis();
2178 gp_Dir theDir = thegpAxe.Direction();
2179 gp_Pnt theCenter = myCartPointB->Pnt();
2180 Standard_Real TheR = Draw::Atof(argv[4]);
2181 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2182 Handle (Geom_Circle) theGeomCircle;
2185 theGeomCircle = Cir.Value();
2187 catch (StdFail_NotDone const&)
2189 std::cout << "vcircle error: can't create circle\n";
2190 return -1; // TCL_ERROR
2193 DisplayCircle(theGeomCircle, aName, isFilled);
2200 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2201 return 1; // TCL_ERROR
2205 // No arguments: selection in the viewer
2206 // =========================================
2209 // Get the name of the circle
2210 TCollection_AsciiString aName(argv[1]);
2212 TopTools_ListOfShape aShapes;
2213 ViewerTest::GetSelectedShapes (aShapes);
2214 if (aShapes.Extent() != 3 && aShapes.Extent() != 2)
2216 std::cerr << "Error: Wrong number of selected shapes.\n";
2220 const TopoDS_Shape& aShapeA = aShapes.First();
2221 if (aShapeA.ShapeType() == TopAbs_VERTEX )
2223 if (aShapes.Extent() != 3)
2225 std::cerr << "Error: wrong number of selected shapes.\n";
2229 TopTools_ListOfShape::Iterator anIter (aShapes);
2232 const TopoDS_Shape& aShapeB = anIter.Value();
2235 const TopoDS_Shape& aShapeC = anIter.Value();
2238 Standard_Boolean isFilled;
2239 std::cout << "Enter filled status (0 or 1)\n";
2240 std::cin >> isFilled;
2242 // Construction of the circle
2243 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
2244 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2245 gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC));
2247 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2248 Handle (Geom_Circle) theGeomCircle;
2251 theGeomCircle = Cir.Value();
2253 catch (StdFail_NotDone const&)
2255 std::cout << "vcircle error: can't create circle\n";
2256 return -1; // TCL_ERROR
2259 DisplayCircle(theGeomCircle, aName, isFilled);
2262 else if (aShapeA.ShapeType() == TopAbs_FACE)
2264 const TopoDS_Shape& aShapeB = aShapes.Last();
2266 // Recover the radius
2267 Standard_Real theRad;
2270 std::cout << " Enter the value of the radius:\n";
2272 } while (theRad <= 0);
2274 // Get filled status
2275 Standard_Boolean isFilled;
2276 std::cout << "Enter filled status (0 or 1)\n";
2277 std::cin >> isFilled;
2279 // Recover the normal to the plane. tag
2280 TopoDS_Face myFace = TopoDS::Face(aShapeA);
2281 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2282 gp_Pln myPlane = mySurface.Plane();
2283 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2284 gp_Pln mygpPlane = theGeomPlane->Pln();
2285 gp_Ax1 thegpAxe = mygpPlane.Axis();
2286 gp_Dir theDir = thegpAxe.Direction();
2288 // Recover the center
2289 gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2291 // Construct the circle
2292 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2293 Handle (Geom_Circle) theGeomCircle;
2296 theGeomCircle = Cir.Value();
2298 catch (StdFail_NotDone const&)
2300 std::cout << "vcircle error: can't create circle\n";
2301 return -1; // TCL_ERROR
2304 DisplayCircle(theGeomCircle, aName, isFilled);
2308 std::cerr << "Error: You should select face and vertex or three vertices.\n";
2316 //=======================================================================
2317 //function : VDrawText
2319 //=======================================================================
2320 static int VDrawText (Draw_Interpretor& theDI,
2321 Standard_Integer theArgsNb,
2322 const char** theArgVec)
2324 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2327 std::cout << "Error: wrong number of arguments! See usage:\n";
2328 theDI.PrintHelp (theArgVec[0]);
2331 else if (aContext.IsNull())
2333 std::cout << "Error: no active view!\n";
2337 Standard_Integer anArgIt = 1;
2338 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2339 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2340 Handle(AIS_TextLabel) aTextPrs;
2341 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2343 Standard_Boolean isNewPrs = Standard_False;
2344 if (GetMapOfAIS().IsBound2 (aName))
2346 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2349 if (aTextPrs.IsNull())
2351 isNewPrs = Standard_True;
2352 aTextPrs = new AIS_TextLabel();
2353 aTextPrs->SetFont ("Courier");
2356 aTextPrs->SetText (aText);
2358 Handle(Graphic3d_TransformPers) aTrsfPers;
2359 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2361 Standard_Boolean aHasPlane = Standard_False;
2366 for (; anArgIt < theArgsNb; ++anArgIt)
2368 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2371 if (anAutoUpdater.parseRedrawMode (aParam))
2375 else if (aParam == "-pos"
2376 || aParam == "-position")
2378 if (anArgIt + 3 >= theArgsNb)
2380 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2384 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2385 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2386 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2387 aTextPrs->SetPosition (aPos);
2389 else if (aParam == "-color")
2391 Quantity_Color aColor;
2392 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIt - 1,
2393 theArgVec + anArgIt + 1,
2397 std::cout << "Syntax error at '" << aParam << "'\n";
2400 anArgIt += aNbParsed;
2401 aTextPrs->SetColor (aColor);
2403 else if (aParam == "-halign")
2405 if (++anArgIt >= theArgsNb)
2407 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2411 TCollection_AsciiString aType (theArgVec[anArgIt]);
2413 if (aType == "left")
2415 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2417 else if (aType == "center")
2419 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2421 else if (aType == "right")
2423 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2427 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2431 else if (aParam == "-valign")
2433 if (++anArgIt >= theArgsNb)
2435 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2439 TCollection_AsciiString aType (theArgVec[anArgIt]);
2443 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2445 else if (aType == "center")
2447 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2449 else if (aType == "bottom")
2451 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2453 else if (aType == "topfirstline")
2455 aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2459 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2463 else if (aParam == "-angle")
2465 if (++anArgIt >= theArgsNb)
2467 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2471 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2473 else if (aParam == "-zoom")
2475 if (++anArgIt >= theArgsNb)
2477 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2481 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2483 else if (aParam == "-height")
2485 if (++anArgIt >= theArgsNb)
2487 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2491 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2493 else if (aParam == "-aspect")
2495 if (++anArgIt >= theArgsNb)
2497 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2501 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2502 anOption.LowerCase();
2503 Font_FontAspect aFontAspect = Font_FA_Undefined;
2504 if (!parseFontStyle (anOption, aFontAspect))
2506 std::cout << "Error: unknown font aspect '" << anOption << "'.\n";
2509 aTextPrs->SetFontAspect (aFontAspect);
2511 else if (aParam == "-font")
2513 if (++anArgIt >= theArgsNb)
2515 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2519 aTextPrs->SetFont (theArgVec[anArgIt]);
2521 else if (aParam == "-plane")
2523 if (anArgIt + 6 >= theArgsNb)
2525 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2529 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
2530 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
2531 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
2532 aNormal.SetCoord (aX, aY, aZ);
2534 aX = Draw::Atof (theArgVec[++anArgIt]);
2535 aY = Draw::Atof (theArgVec[++anArgIt]);
2536 aZ = Draw::Atof (theArgVec[++anArgIt]);
2537 aDirection.SetCoord (aX, aY, aZ);
2539 aHasPlane = Standard_True;
2541 else if (aParam == "-flipping")
2543 aTextPrs->SetFlipping (Standard_True);
2545 else if (aParam == "-disptype"
2546 || aParam == "-displaytype")
2548 if (++anArgIt >= theArgsNb)
2550 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2553 TCollection_AsciiString aType (theArgVec[anArgIt]);
2555 if (aType == "subtitle")
2556 aDisplayType = Aspect_TODT_SUBTITLE;
2557 else if (aType == "decal")
2558 aDisplayType = Aspect_TODT_DEKALE;
2559 else if (aType == "blend")
2560 aDisplayType = Aspect_TODT_BLEND;
2561 else if (aType == "dimension")
2562 aDisplayType = Aspect_TODT_DIMENSION;
2563 else if (aType == "normal")
2564 aDisplayType = Aspect_TODT_NORMAL;
2565 else if (aType == "shadow")
2566 aDisplayType = Aspect_TODT_SHADOW;
2569 std::cout << "Error: wrong display type '" << aType << "'.\n";
2573 else if (aParam == "-subcolor"
2574 || aParam == "-subtitlecolor")
2576 Quantity_Color aColor;
2577 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIt - 1,
2578 theArgVec + anArgIt + 1,
2582 std::cout << "Syntax error at '" << aParam << "'\n";
2585 anArgIt += aNbParsed;
2586 aTextPrs->SetColorSubTitle (aColor);
2588 else if (aParam == "-2d")
2590 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d);
2592 else if (aParam == "-trsfperspos"
2593 || aParam == "-perspos")
2595 if (anArgIt + 2 >= theArgsNb)
2597 std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2601 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2602 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2603 TCollection_AsciiString aZ = "0";
2604 if (!aX.IsIntegerValue()
2605 || !aY.IsIntegerValue())
2607 std::cerr << "Error: wrong syntax at '" << aParam << "'.\n";
2610 if (anArgIt + 1 < theArgsNb)
2612 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2613 if (aTemp.IsIntegerValue())
2620 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()));
2624 std::cout << "Error: unknown argument '" << aParam << "'\n";
2631 aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2634 aTextPrs->SetDisplayType (aDisplayType);
2636 if (!aTrsfPers.IsNull())
2638 aContext->SetTransformPersistence (aTextPrs, aTrsfPers);
2639 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2640 if (aTextPrs->Position().Z() != 0)
2642 aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
2645 else if (!aTextPrs->TransformPersistence().IsNull())
2647 aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
2652 ViewerTest::Display (aName, aTextPrs, Standard_False);
2656 aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
2662 #include <gp_Pnt.hxx>
2663 #include <Graphic3d_ArrayOfPoints.hxx>
2664 #include <Graphic3d_ArrayOfPrimitives.hxx>
2665 #include <Graphic3d_ArrayOfTriangles.hxx>
2666 #include <Poly_Array1OfTriangle.hxx>
2667 #include <Poly_Triangle.hxx>
2668 #include <Poly_Triangulation.hxx>
2669 #include <TColgp_Array1OfPnt.hxx>
2670 #include <TShort_Array1OfShortReal.hxx>
2671 #include <TShort_HArray1OfShortReal.hxx>
2673 #include <AIS_Triangulation.hxx>
2674 #include <StdPrs_ToolTriangulatedShape.hxx>
2675 #include <Poly_Connect.hxx>
2676 #include <TColgp_Array1OfDir.hxx>
2677 #include <Graphic3d_GraphicDriver.hxx>
2679 #include <TColStd_Array1OfInteger.hxx>
2680 #include <TColStd_HArray1OfInteger.hxx>
2681 #include <Prs3d_ShadingAspect.hxx>
2682 #include <Graphic3d_MaterialAspect.hxx>
2683 #include <Graphic3d_AspectFillArea3d.hxx>
2685 #include <BRepPrimAPI_MakeCylinder.hxx>
2686 #include <TopoDS_Shape.hxx>
2687 #include <TopExp_Explorer.hxx>
2688 #include <TopAbs.hxx>
2689 #include <StdSelect_ShapeTypeFilter.hxx>
2690 #include <AIS_InteractiveObject.hxx>
2693 //===============================================================================================
2694 //function : CalculationOfSphere
2696 //purpose : Create a Sphere
2697 //===============================================================================================
2699 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2702 double mRadius = Radius;
2703 double mCenter[3] = {X,Y,Z};
2704 int mThetaResolution;
2706 double mStartTheta = 0;//StartTheta;
2707 double mEndTheta = 360;//EndTheta;
2708 double mStartPhi = 0;//StartPhi;
2709 double mEndPhi = 180;//EndPhi;
2710 res = res < 4 ? 4 : res;
2712 mThetaResolution = res;
2713 mPhiResolution = res;
2716 int jStart, jEnd, numOffset;
2717 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2718 double startTheta, endTheta, startPhi, endPhi;
2719 int base, numPoles=0, thetaResolution, phiResolution;
2724 if ( numPieces > mThetaResolution ) {
2725 numPieces = mThetaResolution;
2728 int localThetaResolution = mThetaResolution;
2729 double localStartTheta = mStartTheta;
2730 double localEndTheta = mEndTheta;
2732 while ( localEndTheta < localStartTheta ) {
2733 localEndTheta += 360.0;
2736 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2738 // Change the ivars based on pieces.
2740 start = piece * localThetaResolution / numPieces;
2741 end = (piece+1) * localThetaResolution / numPieces;
2742 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2743 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2744 localThetaResolution = end - start;
2746 // Create north pole if needed
2747 int number_point = 0;
2748 int number_pointArray = 0;
2750 if ( mStartPhi <= 0.0 ) {
2751 number_pointArray++;
2754 if ( mEndPhi >= 180.0 ) {
2755 number_pointArray++;
2759 // Check data, determine increments, and convert to radians
2760 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2761 startTheta *= M_PI / 180.0;
2762 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2763 endTheta *= M_PI / 180.0;
2766 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2767 startPhi *= M_PI / 180.0;
2768 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2769 endPhi *= M_PI / 180.0;
2771 phiResolution = mPhiResolution - numPoles;
2772 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2773 thetaResolution = localThetaResolution;
2774 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2775 ++localThetaResolution;
2777 deltaTheta = (endTheta - startTheta) / thetaResolution;
2779 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2780 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2782 // Create intermediate points
2783 for ( i = 0; i < localThetaResolution; i++ ) {
2784 for ( j = jStart; j < jEnd; j++ ) {
2785 number_pointArray++;
2789 //Generate mesh connectivity
2790 base = phiResolution * localThetaResolution;
2792 int number_triangle = 0 ;
2793 if ( mStartPhi <= 0.0 ) { // around north pole
2794 number_triangle += localThetaResolution;
2797 if ( mEndPhi >= 180.0 ) { // around south pole
2798 number_triangle += localThetaResolution;
2801 // bands in-between poles
2802 for ( i=0; i < localThetaResolution; i++){
2803 for ( j=0; j < (phiResolution-1); j++){
2804 number_triangle +=2;
2808 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2809 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2810 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2812 if ( mStartPhi <= 0.0 ){
2815 x[2] = mCenter[2] + mRadius;
2816 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2819 // Create south pole if needed
2820 if ( mEndPhi >= 180.0 ){
2823 x[2] = mCenter[2] - mRadius;
2824 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2828 for ( i=0; i < localThetaResolution; i++){
2829 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2830 for ( j = jStart; j < jEnd; j++){
2831 phi = startPhi + j*deltaPhi;
2832 radius = mRadius * sin((double)phi);
2833 n[0] = radius * cos((double)theta);
2834 n[1] = radius * sin((double)theta);
2835 n[2] = mRadius * cos((double)phi);
2836 x[0] = n[0] + mCenter[0];
2837 x[1] = n[1] + mCenter[1];
2838 x[2] = n[2] + mCenter[2];
2839 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2845 number_triangle = 1;
2846 if ( mStartPhi <= 0.0 ){// around north pole
2847 for (i=0; i < localThetaResolution; i++){
2848 pts[0] = phiResolution*i + numPoles;
2849 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2851 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2856 if ( mEndPhi >= 180.0 ){ // around south pole
2857 numOffset = phiResolution - 1 + numPoles;
2858 for (i=0; i < localThetaResolution; i++){
2859 pts[0] = phiResolution*i + numOffset;
2860 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2861 pts[1] = numPoles - 1;
2862 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2867 // bands in-between poles
2869 for (i=0; i < localThetaResolution; i++){
2870 for (j=0; j < (phiResolution-1); j++){
2871 pts[0] = phiResolution*i + j + numPoles;
2872 pts[1] = pts[0] + 1;
2873 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2874 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2877 pts[2] = pts[1] - 1;
2878 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2883 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2885 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2887 Standard_Integer index[3];
2888 Standard_Real Tol = Precision::Confusion();
2891 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2892 gp_XYZ eqPlan(0, 0, 0);
2893 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2894 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2895 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2896 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2898 Standard_Real mod = vv.Modulus();
2899 if(mod < Tol) continue;
2903 Standard_Real modmax = eqPlan.Modulus();
2906 Nor = gp_Dir(eqPlan);
2908 Nor = gp_Dir(0., 0., 1.);
2910 Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
2911 Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
2912 Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
2913 Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
2917 polyTriangulation->SetNormals(Normals);
2919 return polyTriangulation;
2922 //===============================================================================================
2923 //function : VDrawSphere
2925 //purpose : Create an AIS shape.
2926 //===============================================================================================
2927 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2930 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2931 if (aContextAIS.IsNull())
2933 std::cout << "Call vinit before!\n";
2938 std::cout << "Use: " << argv[0]
2939 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2943 // read the arguments
2944 TCollection_AsciiString aShapeName (argv[1]);
2945 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2946 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2947 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2948 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2949 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2950 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2951 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
2953 // remove AIS object with given name from map
2954 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2957 std::cout << "Compute Triangulation...\n";
2958 Handle(AIS_Triangulation) aShape
2959 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2962 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2963 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2965 // stupid initialization of Green color in RGBA space as integer
2966 // probably wrong for big-endian CPUs
2967 const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
2969 // setup colors array per vertex
2970 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2971 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2973 aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData()));
2975 aShape->SetColors (aColorArray);
2978 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2979 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2980 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2981 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2982 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2983 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2984 aTotalSize >>= 20; //MB
2985 aNormalsSize >>= 20;
2987 aTrianglesSize >>= 20;
2988 aPolyConnectSize >>= 20;
2991 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2992 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2993 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2994 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2995 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2996 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2999 // Setting material properties, very important for desirable visual result!
3000 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
3001 aMat.SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.04f)));
3002 aMat.SetSpecularColor(Quantity_Color (Graphic3d_Vec3 (0.50f)));
3003 Handle(Graphic3d_AspectFillArea3d) anAspect
3004 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3006 Quantity_NOC_YELLOW,
3011 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3012 anAspect->SetDrawEdges (toShowEdges);
3013 aShAsp->SetAspect (anAspect);
3014 aShape->Attributes()->SetShadingAspect (aShAsp);
3016 VDisplayAISObject (aShapeName, aShape);
3020 //=============================================================================
3021 //function : VComputeHLR
3023 //=============================================================================
3025 static int VComputeHLR (Draw_Interpretor& ,
3026 Standard_Integer theArgNb,
3027 const char** theArgVec)
3029 TCollection_AsciiString aShapeName, aHlrName;
3034 bool hasViewDirArg = false;
3035 Prs3d_TypeOfHLR anAlgoType = Prs3d_TOH_PolyAlgo;
3036 bool toShowCNEdges = false, toShowHiddenEdges = false;
3037 int aNbIsolines = 0;
3038 if (Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext())
3041 Handle(V3d_View) aView = ViewerTest::CurrentView();
3042 Standard_Integer aWidth, aHeight;
3043 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3044 Standard_Real aRightX, aRightY, aRightZ;
3045 aView->Window()->Size (aWidth, aHeight);
3047 aView->ConvertWithProj (aWidth, aHeight/2,
3048 aRightX, aRightY, aRightZ,
3049 aDirX, aDirY, aDirZ);
3050 aView->ConvertWithProj (aWidth/2, aHeight/2,
3051 aCentX, aCentY, aCentZ,
3052 aDirX, aDirY, aDirZ);
3054 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3055 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3056 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3057 aProjAx.SetLocation (anEye);
3058 aProjAx.SetDirection (aDir);
3059 aProjAx.SetXDirection (aRight);
3061 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3063 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3064 anArgCase.LowerCase();
3065 if (anArgIter + 1 < theArgNb
3066 && (anArgCase == "-algotype"
3067 || anArgCase == "-algo"
3068 || anArgCase == "-type"))
3070 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
3071 anArgNext.LowerCase();
3072 if (anArgNext == "polyalgo")
3074 anAlgoType = Prs3d_TOH_PolyAlgo;
3076 else if (anArgNext == "algo")
3078 anAlgoType = Prs3d_TOH_Algo;
3082 std::cout << "Syntax error: unknown algo type '" << anArgNext << "'\n";
3086 else if (anArgCase == "-showhiddenedges"
3087 || anArgCase == "-hiddenedges"
3088 || anArgCase == "-hidden")
3090 toShowHiddenEdges = true;
3091 if (anArgIter + 1 < theArgNb
3092 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowHiddenEdges))
3097 else if (anArgCase == "-showtangentedges"
3098 || anArgCase == "-tangentedges"
3099 || anArgCase == "-tangent")
3101 toShowCNEdges = true;
3102 if (anArgIter + 1 < theArgNb
3103 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowCNEdges))
3108 else if (anArgIter + 1 < theArgNb
3109 && (anArgCase == "-nbiso"
3110 || anArgCase == "-nbisolines"))
3112 aNbIsolines = Draw::Atoi (theArgVec[++anArgIter]);
3114 else if (aSh.IsNull())
3116 aSh = DBRep::Get (theArgVec[anArgIter]);
3117 aShapeName = theArgVec[anArgIter];
3120 BRep_Builder aBrepBuilder;
3121 BRepTools::Read (aSh, theArgVec[anArgIter], aBrepBuilder);
3124 std::cout << "Syntax error: no shape with name " << theArgVec[anArgIter] << " found\n";
3129 else if (aHlrName.IsEmpty())
3131 aHlrName = theArgVec[anArgIter];
3133 else if (!hasViewDirArg
3134 && anArgIter + 8 < theArgNb)
3136 hasViewDirArg = true;
3138 anEye.SetCoord (Draw::Atof (theArgVec[anArgIter + 0]), Draw::Atof (theArgVec[anArgIter + 1]), Draw::Atof (theArgVec[anArgIter + 2]));
3139 aDir .SetCoord (Draw::Atof (theArgVec[anArgIter + 3]), Draw::Atof (theArgVec[anArgIter + 4]), Draw::Atof (theArgVec[anArgIter + 5]));
3140 anUp .SetCoord (Draw::Atof (theArgVec[anArgIter + 6]), Draw::Atof (theArgVec[anArgIter + 7]), Draw::Atof (theArgVec[anArgIter + 8]));
3141 aProjAx.SetLocation (anEye);
3142 aProjAx.SetDirection (aDir);
3143 aProjAx.SetYDirection (anUp);
3148 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n";
3153 if (aHlrName.IsEmpty() || aSh.IsNull()
3154 || (ViewerTest::GetAISContext().IsNull() && hasViewDirArg))
3156 std::cout << "Syntax error: wrong number of arguments\n";
3160 HLRAlgo_Projector aProjector (aProjAx);
3161 TopoDS_Shape aVisible[6];
3162 TopoDS_Shape aHidden[6];
3163 if (anAlgoType == Prs3d_TOH_PolyAlgo)
3165 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3166 aPolyAlgo->Projector (aProjector);
3167 aPolyAlgo->Load (aSh);
3168 aPolyAlgo->Update();
3170 HLRBRep_PolyHLRToShape aHLRToShape;
3171 aHLRToShape.Update (aPolyAlgo);
3173 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3174 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); // extract visible outlines
3175 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3178 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3180 if (toShowHiddenEdges)
3182 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3183 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3184 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3187 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3193 Handle(HLRBRep_Algo) aHlrAlgo = new HLRBRep_Algo();
3194 aHlrAlgo->Add (aSh, aNbIsolines);
3195 aHlrAlgo->Projector (aProjector);
3199 HLRBRep_HLRToShape aHLRToShape (aHlrAlgo);
3200 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3201 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound();
3202 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3205 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3207 aVisible[HLRBRep_IsoLine] = aHLRToShape.IsoLineVCompound();
3209 if (toShowHiddenEdges)
3211 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3212 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3213 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3216 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3218 aHidden[HLRBRep_IsoLine] = aHLRToShape.IsoLineHCompound();
3221 //aVisible[HLRBRep_Sharp] = aHLRToShape.CompoundOfEdges (HLRBRep_Sharp, Standard_True, Standard_True);
3222 //aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound3d();
3225 TopoDS_Compound aCompRes, aCompVis, aCompHid;
3226 BRep_Builder aBuilder;
3227 aBuilder.MakeCompound (aCompVis);
3228 aBuilder.MakeCompound (aCompHid);
3229 aBuilder.MakeCompound (aCompRes);
3230 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3232 if (!aVisible[aTypeIter].IsNull())
3234 aBuilder.Add (aCompVis, aVisible[aTypeIter]);
3236 if (!aHidden[aTypeIter].IsNull())
3238 aBuilder.Add (aCompHid, aHidden[aTypeIter]);
3241 aBuilder.Add (aCompRes, aCompVis);
3242 aBuilder.Add (aCompRes, aCompHid);
3244 // create an AIS shape and display it
3245 if (!ViewerTest::GetAISContext().IsNull())
3247 Handle(AIS_ColoredShape) anObject = new AIS_ColoredShape (aCompRes);
3248 if (toShowHiddenEdges)
3250 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect (Quantity_Color (Quantity_NOC_RED), Aspect_TOL_DASH, 1.0f);
3251 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3253 if (!aHidden[aTypeIter].IsNull())
3255 Handle(AIS_ColoredDrawer) aDrawer = anObject->CustomAspects (aHidden[aTypeIter]);
3256 aDrawer->SetLineAspect (aLineAspect);
3257 aDrawer->SetWireAspect (aLineAspect);
3258 aDrawer->SetFreeBoundaryAspect (aLineAspect);
3259 aDrawer->SetUnFreeBoundaryAspect (aLineAspect);
3263 ViewerTest::Display (aHlrName, anObject, true);
3266 DBRep::Set (aHlrName.ToCString(), aCompRes);
3270 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3271 // manipulating and displaying such an array with AIS context
3273 class MyPArrayObject : public AIS_InteractiveObject
3278 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives)& thePArray) : myPArray (thePArray) {}
3280 MyPArrayObject (Graphic3d_TypeOfPrimitiveArray thePrimType,
3281 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3282 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect)
3284 Init (thePrimType, theDesc, theMarkerAspect, Standard_False);
3287 //! Initialize the array from specified description.
3288 Standard_Boolean Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3289 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3290 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3291 Standard_Boolean theToPatch);
3293 DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
3295 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
3297 //! Sets color to this interactive object
3298 //! @param theColor the color to be set
3299 virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
3303 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3304 const Handle(Prs3d_Presentation)& aPresentation,
3305 const Standard_Integer aMode) Standard_OVERRIDE;
3307 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3308 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
3310 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3311 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3312 Standard_Integer &theArgIndex,
3313 Standard_Integer theArgCount,
3314 Standard_Integer theMaxArgs);
3316 //! Sets color for the shading aspect of the drawer used in this interactive object
3317 //! @param theColor the color to be set
3318 void setColorForShadingAspect(const Quantity_Color& theColor);
3320 //! Replaces shading aspect from myDrawer->Link() with the own shading aspect of myDrawer for this interactive object
3321 void replaceShadingAspect();
3325 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3326 Handle(Graphic3d_ArrayOfPrimitives) myPArray;
3330 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3331 const Handle(Prs3d_Presentation)& thePrs,
3332 const Standard_Integer theMode)
3334 if (myPArray.IsNull() || theMode != 0)
3339 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
3340 if (!myMarkerAspect.IsNull())
3342 aGroup->SetGroupPrimitivesAspect (myMarkerAspect);
3346 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
3348 aGroup->AddPrimitiveArray (myPArray);
3351 Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3352 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3353 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3354 Standard_Boolean theToPatch)
3356 myMarkerAspect = theMarkerAspect;
3362 // Parsing array description
3363 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3364 Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None;
3366 const Standard_Integer anArgsCount = theDesc->Length();
3367 TCollection_AsciiString aCommand;
3368 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3370 aCommand = theDesc->Value (anArgIndex);
3371 aCommand.LowerCase();
3373 if (CheckInputCommand ("-deinterleaved", theDesc, anArgIndex, 0, anArgsCount))
3375 anArrayFlags |= Graphic3d_ArrayFlags_AttribsDeinterleaved;
3377 else if (CheckInputCommand ("-mutable", theDesc, anArgIndex, 0, anArgsCount))
3379 anArrayFlags |= Graphic3d_ArrayFlags_AttribsMutable;
3380 anArrayFlags |= Graphic3d_ArrayFlags_IndexesMutable;
3383 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3385 // vertex has a normal or normal with color or texel
3386 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3388 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal;
3391 // vertex has a color
3392 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3394 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor;
3397 // vertex has a texel
3398 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3400 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel;
3406 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3409 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3411 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor;
3417 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3426 if (myPArray.IsNull())
3428 myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
3432 if (myPArray->Type() != thePrimType
3433 || aVertexNum > myPArray->VertexNumberAllocated()
3434 || aEdgeNum > myPArray->EdgeNumberAllocated()
3435 || aBoundNum > myPArray->BoundNumberAllocated()
3436 || !myPArray->Attributes()->IsMutable()
3437 || (!myPArray->Indices().IsNull() && !myPArray->Indices()->IsMutable()))
3439 std::cout << "Syntax error: array cannot be patched\n";
3440 return Standard_False;
3443 myPArray->Attributes()->NbElements = aVertexNum;
3444 if (Handle(Graphic3d_AttribBuffer) anAttribs = Handle(Graphic3d_AttribBuffer)::DownCast (myPArray->Attributes()))
3446 anAttribs->Invalidate (0, aVertexNum - 1);
3448 if (!myPArray->Indices().IsNull())
3450 myPArray->Indices()->NbElements = aEdgeNum;
3452 if (!myPArray->Bounds().IsNull())
3454 myPArray->Bounds()->NbBounds = aBoundNum;
3458 Standard_Integer aVertIndex = 0;
3459 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3461 aCommand = theDesc->Value (anArgIndex);
3462 aCommand.LowerCase();
3463 if (!aCommand.IsAscii()
3464 || aCommand.IsEmpty())
3469 // skip beautifiers (syntax is not actually validated)
3470 if (aCommand == "-deinterleaved"
3471 || aCommand == "-mutable"
3472 || aCommand.Value (1) == '('
3473 || aCommand.Value (1) == ')'
3474 || aCommand.Value (1) == ',')
3479 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3481 const Graphic3d_Vec3 aVert ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3482 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3483 (float )theDesc->Value (anArgIndex - 1).RealValue());
3484 if ((anArrayFlags & Graphic3d_ArrayFlags_AttribsDeinterleaved) != 0
3485 || (anArrayFlags & Graphic3d_ArrayFlags_AttribsMutable) != 0)
3488 myPArray->SetVertice (aVertIndex, aVert.x(), aVert.y(), aVert.z());
3492 aVertIndex = myPArray->AddVertex (aVert);
3495 // vertex has a normal or normal with color or texel
3496 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3498 const Graphic3d_Vec3 aNorm ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3499 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3500 (float )theDesc->Value (anArgIndex - 1).RealValue());
3501 myPArray->SetVertexNormal (aVertIndex, aNorm.x(), aNorm.y(), aNorm.z());
3504 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3506 const Graphic3d_Vec3d aCol (theDesc->Value (anArgIndex - 3).RealValue(),
3507 theDesc->Value (anArgIndex - 2).RealValue(),
3508 theDesc->Value (anArgIndex - 1).RealValue());
3509 myPArray->SetVertexColor (aVertIndex, aCol.r(), aCol.g(), aCol.b());
3511 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3513 const Graphic3d_Vec2 aTex ((float )theDesc->Value (anArgIndex - 2).RealValue(),
3514 (float )theDesc->Value (anArgIndex - 1).RealValue());
3515 myPArray->SetVertexTexel (aVertIndex, aTex.x(), aTex.y());
3519 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3521 Standard_Integer aVertCount = theDesc->Value (anArgIndex - 1).IntegerValue();
3523 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3524 myPArray->AddBound (aVertCount,
3525 theDesc->Value (anArgIndex - 3).RealValue(),
3526 theDesc->Value (anArgIndex - 2).RealValue(),
3527 theDesc->Value (anArgIndex - 1).RealValue());
3530 myPArray->AddBound (aVertCount);
3533 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3535 const Standard_Integer anEdge = theDesc->Value (anArgIndex - 1).IntegerValue();
3536 myPArray->AddEdge (anEdge);
3541 std::cout << "Syntax error: unknown argument '" << theDesc->Value(anArgIndex) << "'\n";
3542 return Standard_False;
3545 return Standard_True;
3548 //=======================================================================
3549 // function : SetColor
3551 //=======================================================================
3552 void MyPArrayObject::SetColor (const Quantity_Color& theColor)
3554 AIS_InteractiveObject::SetColor (theColor);
3555 setColorForShadingAspect (theColor);
3558 myMarkerAspect->SetColor (theColor);
3560 SynchronizeAspects();
3563 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3564 const Standard_Integer theMode)
3567 || myPArray.IsNull())
3572 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
3573 if (Handle(Graphic3d_ArrayOfTriangles) aTris = Handle(Graphic3d_ArrayOfTriangles)::DownCast (myPArray))
3575 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3576 aSensitive->InitTriangulation (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3577 theSelection->Add (aSensitive);
3579 else if (Handle(Graphic3d_ArrayOfSegments) aSegs = Handle(Graphic3d_ArrayOfSegments)::DownCast (myPArray))
3581 if (aSegs->EdgeNumber() > 0)
3583 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->EdgeNumber(); aPntIter += 2)
3585 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aSegs->Edge (aPntIter)), aSegs->Vertice (aSegs->Edge (aPntIter + 1)));
3586 aSeg->SetSensitivityFactor (4);
3587 theSelection->Add (aSeg);
3592 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->VertexNumber(); aPntIter += 2)
3594 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aPntIter), aSegs->Vertice (aPntIter + 1));
3595 aSeg->SetSensitivityFactor (4);
3596 theSelection->Add (aSeg);
3602 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3603 aSensitive->SetSensitivityFactor (8);
3604 aSensitive->InitPoints (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3605 theSelection->Add (aSensitive);
3609 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3610 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3611 Standard_Integer &theArgIndex,
3612 Standard_Integer theArgCount,
3613 Standard_Integer theMaxArgs)
3615 // check if there is more elements than expected
3616 if (theArgIndex >= theMaxArgs)
3619 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3620 aStrCommand.LowerCase();
3621 if (aStrCommand.Search(theCommand) != 1 ||
3622 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3625 // go to the first data element
3628 // check data if it can be converted to numeric
3629 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3631 aStrCommand = theArgsArray->Value (theArgIndex);
3632 if (!aStrCommand.IsRealValue())
3639 //=======================================================================
3640 // function : setColorForShadingAspect
3642 //=======================================================================
3643 void MyPArrayObject::setColorForShadingAspect (const Quantity_Color& theColor)
3645 if (myDrawer->SetupOwnShadingAspect())
3647 replaceShadingAspect();
3649 myDrawer->ShadingAspect()->SetColor (theColor);
3652 //=======================================================================
3653 // function : replaceShadingAspect
3655 //=======================================================================
3656 void MyPArrayObject::replaceShadingAspect()
3658 if (!myDrawer->Link())
3662 Graphic3d_MapOfAspectsToAspects anAspectReplacementMap;
3663 anAspectReplacementMap.Bind (myDrawer->Link()->ShadingAspect()->Aspect(), myDrawer->ShadingAspect()->Aspect());
3664 replaceAspects (anAspectReplacementMap);
3667 //=============================================================================
3668 //function : VDrawPArray
3669 //purpose : Draws primitives array from list of vertexes, bounds, edges
3670 //=============================================================================
3672 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3674 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3675 if (aContextAIS.IsNull())
3677 std::cout << "Error: no active Viewer\n";
3682 std::cout << "Syntax error: wrong number of arguments\n";
3686 // read the arguments
3687 Standard_Integer anArgIndex = 1;
3688 TCollection_AsciiString aName (argv[anArgIndex++]);
3689 TCollection_AsciiString anArrayType (argv[anArgIndex++]);
3690 anArrayType.LowerCase();
3691 Handle(MyPArrayObject) aPObject;
3692 if (anArrayType == "-shape")
3694 Standard_CString aShapeName = argv[anArgIndex++];
3695 TopoDS_Shape aShape = DBRep::Get (aShapeName);
3696 Handle(Graphic3d_ArrayOfPrimitives) aTris = StdPrs_ShadedShape::FillTriangles (aShape);
3697 if (aShape.IsNull())
3699 std::cout << "Syntax error: shape '" << aShapeName << "' is not found\n";
3702 else if (aTris.IsNull())
3704 std::cout << "Syntax error: shape '" << aShapeName << "' is not triangulated\n";
3708 aPObject = new MyPArrayObject (aTris);
3709 ViewerTest::Display (aName, aPObject);
3712 else if (anArrayType == "-patch"
3713 || anArrayType == "-modify"
3714 || anArrayType == "-edit")
3718 anArrayType = argv[anArgIndex++];
3719 anArrayType.LowerCase();
3722 if (GetMapOfAIS().IsBound2 (aName))
3724 aPObject = Handle(MyPArrayObject)::DownCast (GetMapOfAIS().Find2 (aName));
3726 if (aPObject.IsNull())
3728 std::cout << "Syntax error: object '" << aName << "' cannot be found\n";
3733 Standard_Boolean hasVertex = Standard_False;
3735 Graphic3d_TypeOfPrimitiveArray aPrimType = Graphic3d_TOPA_UNDEFINED;
3736 if (anArrayType == "points")
3738 aPrimType = Graphic3d_TOPA_POINTS;
3740 else if (anArrayType == "segments")
3742 aPrimType = Graphic3d_TOPA_SEGMENTS;
3744 else if (anArrayType == "polylines")
3746 aPrimType = Graphic3d_TOPA_POLYLINES;
3748 else if (anArrayType == "triangles")
3750 aPrimType = Graphic3d_TOPA_TRIANGLES;
3752 else if (anArrayType == "trianglefans")
3754 aPrimType = Graphic3d_TOPA_TRIANGLEFANS;
3756 else if (anArrayType == "trianglestrips")
3758 aPrimType = Graphic3d_TOPA_TRIANGLESTRIPS;
3760 else if (anArrayType == "quads")
3762 aPrimType = Graphic3d_TOPA_QUADRANGLES;
3764 else if (anArrayType == "quadstrips")
3766 aPrimType = Graphic3d_TOPA_QUADRANGLESTRIPS;
3768 else if (anArrayType == "polygons")
3770 aPrimType = Graphic3d_TOPA_POLYGONS;
3772 if (aPrimType == Graphic3d_TOPA_UNDEFINED)
3774 std::cout << "Syntax error: unexpected type of primitives array\n";
3778 Standard_Integer aLowerArg = anArgIndex;
3779 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 3);
3780 for (; anArgIndex < argc; ++anArgIndex)
3782 TCollection_AsciiString aCommand (argv[anArgIndex]);
3783 aCommand.LowerCase();
3784 if (!aCommand.IsAscii())
3786 di << "Unexpected argument: #" << anArgIndex - 1 << " , "
3787 << "should be an array element: 'v', 'b', 'e' \n";
3791 if (aCommand == "v")
3793 hasVertex = Standard_True;
3796 anArgsArray->SetValue (anArgIndex - aLowerArg, aCommand);
3801 di << "You should pass any verticies in the list of array elements\n";
3805 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3806 if (aPrimType == Graphic3d_TOPA_POINTS)
3808 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3811 // create primitives array object
3812 if (aPObject.IsNull())
3814 // register the object in map
3815 aPObject = new MyPArrayObject (aPrimType, anArgsArray, anAspPoints);
3816 VDisplayAISObject (aName, aPObject);
3820 aPObject->Init (aPrimType, anArgsArray, anAspPoints, Standard_True);
3821 ViewerTest::CurrentView()->Redraw();
3828 //! Auxiliary function for parsing translation vector - either 2D or 3D.
3829 static Standard_Integer parseTranslationVec (Standard_Integer theArgNb,
3830 const char** theArgVec,
3838 TCollection_AsciiString anX (theArgVec[0]);
3839 TCollection_AsciiString anY (theArgVec[1]);
3840 if (!anX.IsRealValue()
3841 || !anY.IsRealValue())
3846 theVec.SetX (anX.RealValue());
3847 theVec.SetY (anY.RealValue());
3850 TCollection_AsciiString anZ (theArgVec[2]);
3851 if (anZ.IsRealValue())
3853 theVec.SetZ (anZ.RealValue());
3861 //=======================================================================
3862 //function : VSetLocation
3863 //purpose : Change location of AIS interactive object
3864 //=======================================================================
3866 static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
3867 Standard_Integer theArgNb,
3868 const char** theArgVec)
3870 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3871 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3872 if (aContext.IsNull())
3874 std::cout << "Error: no active view!\n";
3878 Standard_Boolean toPrintInfo = Standard_True;
3879 Handle(AIS_InteractiveObject) anObj;
3880 TCollection_AsciiString aCmdName (theArgVec[0]);
3881 aCmdName.LowerCase();
3882 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3884 TCollection_AsciiString anArg = theArgVec[anArgIter];
3886 if (anUpdateTool.parseRedrawMode (anArg))
3890 else if (anObj.IsNull())
3892 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3893 GetMapOfAIS().Find2 (aName, anObj);
3896 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3900 else if (anArg == "-reset")
3902 toPrintInfo = Standard_False;
3903 aContext->SetLocation (anObj, gp_Trsf());
3905 else if (anArg == "-copyfrom"
3906 || anArg == "-copy")
3908 if (anArgIter + 1 >= theArgNb)
3910 std::cout << "Syntax error at '" << anArg << "'\n";
3914 const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]);
3915 Handle(AIS_InteractiveObject) anObj2;
3916 GetMapOfAIS().Find2 (aName2, anObj2);
3917 if (anObj2.IsNull())
3919 std::cout << "Error: object '" << aName2 << "' is not displayed!\n";
3924 aContext->SetLocation (anObj, anObj2->LocalTransformation());
3926 else if (anArg == "-rotate")
3928 toPrintInfo = Standard_False;
3929 if (anArgIter + 7 >= theArgNb)
3931 std::cout << "Syntax error at '" << anArg << "'\n";
3936 aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]),
3937 Draw::Atof (theArgVec[anArgIter + 2]),
3938 Draw::Atof (theArgVec[anArgIter + 3])),
3939 gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]),
3940 Draw::Atof (theArgVec[anArgIter + 5]),
3941 Draw::Atof (theArgVec[anArgIter + 6]))),
3942 Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0));
3945 aTrsf = anObj->LocalTransformation() * aTrsf;
3946 aContext->SetLocation (anObj, aTrsf);
3948 else if (anArg == "-translate")
3950 toPrintInfo = Standard_False;
3952 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
3953 anArgIter += aNbParsed;
3956 std::cout << "Syntax error at '" << anArg << "'\n";
3961 aTrsf.SetTranslationPart (aLocVec);
3962 aTrsf = anObj->LocalTransformation() * aTrsf;
3963 aContext->SetLocation (anObj, aTrsf);
3965 else if (anArg == "-scale"
3966 || anArg == "-setscale")
3968 toPrintInfo = Standard_False;
3970 Standard_Real aScale = 1.0;
3971 Standard_Boolean toPrintScale = Standard_True;
3972 Standard_Boolean hasScaleLoc = Standard_False;
3973 if (anArgIter + 4 < theArgNb)
3975 TCollection_AsciiString aScaleArgs[4] =
3977 TCollection_AsciiString (theArgVec[anArgIter + 1]),
3978 TCollection_AsciiString (theArgVec[anArgIter + 2]),
3979 TCollection_AsciiString (theArgVec[anArgIter + 3]),
3980 TCollection_AsciiString (theArgVec[anArgIter + 4])
3982 Standard_Integer aScaleArgIter = 0;
3983 for (; aScaleArgIter < 4; ++aScaleArgIter)
3985 if (!aScaleArgs[aScaleArgIter].IsRealValue())
3990 if (aScaleArgIter == 4)
3992 aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue());
3993 aScale = aScaleArgs[3].RealValue();
3995 toPrintScale = Standard_False;
3996 hasScaleLoc = Standard_True;
3998 else if (aScaleArgIter >= 1)
4000 aScale = aScaleArgs[0].RealValue();
4002 toPrintScale = Standard_False;
4005 else if (anArgIter + 1 < theArgNb)
4007 TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]);
4008 if (aScaleArg.IsRealValue())
4010 aScale = aScaleArg.RealValue();
4012 toPrintScale = Standard_False;
4018 if (anArg == "-setscale")
4020 std::cout << "Syntax error at '" << anArg << "'\n";
4025 Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor());
4030 if (anArg == "-setscale")
4032 gp_Trsf aTrsf = anObj->LocalTransformation();
4035 aTrsf.SetScale (aScaleLoc, aScale);
4039 aTrsf.SetScaleFactor (aScale);
4041 aContext->SetLocation (anObj, aTrsf);
4048 aTrsf.SetScale (aScaleLoc, aScale);
4049 aTrsf = anObj->LocalTransformation() * aTrsf;
4053 aTrsf = anObj->LocalTransformation();
4054 aTrsf.SetScaleFactor (aTrsf.ScaleFactor() * aScale);
4056 aContext->SetLocation (anObj, aTrsf);
4059 else if (anArg == "-mirror")
4061 toPrintInfo = Standard_False;
4062 if (anArgIter + 6 >= theArgNb)
4064 std::cout << "Syntax error at '" << anArg << "'\n";
4069 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
4070 Draw::Atof(theArgVec[theArgNb - 5]),
4071 Draw::Atof(theArgVec[theArgNb - 4])),
4072 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
4073 Draw::Atof(theArgVec[theArgNb - 2]),
4074 Draw::Atof(theArgVec[theArgNb - 1]))));
4076 aTrsf = anObj->LocalTransformation() * aTrsf;
4077 aContext->SetLocation (anObj, aTrsf);
4079 else if (anArg == "-setrotation"
4080 || anArg == "-rotation")
4082 toPrintInfo = Standard_False;
4083 if (anArgIter + 4 < theArgNb)
4085 TCollection_AsciiString aQuatArgs[4] =
4087 TCollection_AsciiString (theArgVec[anArgIter + 1]),
4088 TCollection_AsciiString (theArgVec[anArgIter + 2]),
4089 TCollection_AsciiString (theArgVec[anArgIter + 3]),
4090 TCollection_AsciiString (theArgVec[anArgIter + 4])
4092 Standard_Integer aQuatArgIter = 0;
4093 for (; aQuatArgIter < 4; ++aQuatArgIter)
4095 if (!aQuatArgs[aQuatArgIter].IsRealValue())
4101 if (aQuatArgIter == 4)
4104 const gp_Quaternion aQuat (aQuatArgs[0].RealValue(),
4105 aQuatArgs[1].RealValue(),
4106 aQuatArgs[2].RealValue(),
4107 aQuatArgs[3].RealValue());
4108 gp_Trsf aTrsf = anObj->LocalTransformation();
4109 aTrsf.SetRotation (aQuat);
4110 aContext->SetLocation (anObj, aTrsf);
4113 else if (anArg == "-setrotation")
4115 std::cout << "Syntax error at '" << anArg << "'\n";
4121 const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation();
4122 Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W());
4125 else if (anArg == "-setlocation"
4126 || anArg == "-location")
4128 toPrintInfo = Standard_False;
4130 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
4131 anArgIter += aNbParsed;
4134 gp_Trsf aTrsf = anObj->LocalTransformation();
4135 aTrsf.SetTranslationPart (aLocVec);
4136 aContext->SetLocation (anObj, aTrsf);
4138 else if (anArg == "-setlocation")
4140 std::cout << "Syntax error at '" << anArg << "'\n";
4145 const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart();
4146 Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z());
4149 else if (aCmdName == "vsetlocation")
4151 // compatibility with old syntax
4153 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec);
4156 std::cout << "Syntax error at '" << anArg << "'\n";
4159 anArgIter = anArgIter + aNbParsed - 1;
4162 aTrsf.SetTranslationPart (aLocVec);
4163 aContext->SetLocation (anObj, aTrsf);
4164 toPrintInfo = Standard_False;
4168 std::cout << "Error: unknown argument '" << anArg << "'\n";
4175 std::cout << "Syntax error - wrong number of arguments\n";
4178 else if (!toPrintInfo)
4183 const gp_Trsf aTrsf = anObj->LocalTransformation();
4184 const gp_XYZ aLoc = aTrsf.TranslationPart();
4185 const gp_Quaternion aRot = aTrsf.GetRotation();
4187 Sprintf (aText, "Location: %g %g %g\n"
4188 "Rotation: %g %g %g %g\n"
4190 aLoc.X(), aLoc.Y(), aLoc.Z(),
4191 aRot.X(), aRot.Y(), aRot.Z(), aRot.W(),
4192 aTrsf.ScaleFactor());
4197 //! Find displayed object.
4198 static Handle(AIS_InteractiveObject) findConnectedObject (const TCollection_AsciiString& theName)
4200 Handle(AIS_InteractiveObject) aPrs;
4201 if (!GetMapOfAIS().Find2 (theName, aPrs))
4203 return Handle(AIS_InteractiveObject)();
4205 if (Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (aPrs))
4209 else if (Handle(AIS_MultipleConnectedInteractive) aMultiCon = Handle(AIS_MultipleConnectedInteractive)::DownCast (aPrs))
4214 // replace already displayed object with connected one
4215 TheAISContext()->Remove (aPrs, false);
4216 Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive();
4217 if (aPrs->HasDisplayMode())
4219 aConnected->SetDisplayMode (aPrs->DisplayMode());
4221 aConnected->Connect (aPrs, aPrs->LocalTransformationGeom());
4222 ViewerTest::Display (theName, aConnected, false);
4226 //===============================================================================================
4227 //function : VConnect
4228 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4229 //===============================================================================================
4230 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
4231 Standard_Integer argc,
4234 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4235 if (aContext.IsNull())
4237 std::cout << "Error: no active view.\n";
4242 std::cout << "Syntax error: expect at least 5 arguments\n";
4247 Standard_Integer anArgIter = 1;
4248 const TCollection_AsciiString aName (argv[anArgIter++]);
4249 Handle(AIS_MultipleConnectedInteractive) aMultiConObject;
4250 TCollection_AsciiString aColorString (argv[argc-1]);
4251 Standard_CString aColorName = "";
4252 Standard_Boolean hasColor = Standard_False;
4253 if (aColorString.Search ("color=") != -1)
4255 hasColor = Standard_True;
4256 aColorString.Remove (1, 6);
4257 aColorName = aColorString.ToCString();
4260 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
4261 for (Standard_Integer i = 5; i < aNbShapes; ++i)
4263 TCollection_AsciiString anOriginObjectName (argv[i]);
4264 Handle(AIS_InteractiveObject) anObject;
4265 if (aName.IsEqual (anOriginObjectName))
4267 std::cout << "Syntax error: equal names for connected objects\n";
4271 anObject = findConnectedObject (anOriginObjectName);
4272 if (anObject.IsNull())
4274 TopoDS_Shape aTDShape = DBRep::Get (anOriginObjectName);
4275 if (aTDShape.IsNull())
4277 std::cout << "Syntax error: object " << anOriginObjectName << " doesn't exist\n";
4280 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aTDShape);
4281 Handle(AIS_ConnectedInteractive) aConnectedOrig = new AIS_ConnectedInteractive();
4282 aConnectedOrig->Connect (aShapePrs);
4283 anObject = aConnectedOrig;
4285 aContext->Load (anObject);
4286 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
4289 if (aMultiConObject.IsNull())
4291 aMultiConObject = new AIS_MultipleConnectedInteractive();
4294 aMultiConObject->Connect (anObject);
4296 if (aMultiConObject.IsNull())
4298 std::cout << "Syntax error: can't connect input objects\n";
4302 // Create transformation
4304 aTrsf.SetTranslationPart (gp_Vec (Draw::Atof (argv[anArgIter + 0]),
4305 Draw::Atof (argv[anArgIter + 1]),
4306 Draw::Atof (argv[anArgIter + 2])));
4307 TopLoc_Location aLocation (aTrsf);
4310 aMultiConObject->SetLocalTransformation (aTrsf);
4312 ViewerTest::Display (aName, aMultiConObject, true);
4316 //===============================================================================================
4317 //function : VConnectTo
4318 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4319 //===============================================================================================
4320 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
4321 Standard_Integer argc,
4324 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4325 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4326 if (aContext.IsNull())
4328 std::cout << "Error: no active view.\n";
4331 if (argc != 6 && argc != 7)
4333 std::cout << "Syntax error: expect at least 5 arguments\n";
4337 Standard_Integer anArgIter = 1;
4338 TCollection_AsciiString aName (argv[anArgIter++]);
4339 Handle(AIS_InteractiveObject) anOriginObject;
4341 TCollection_AsciiString anOriginObjectName(argv[5]);
4342 if (aName.IsEqual (anOriginObjectName))
4344 std::cout << "Syntax error: equal names for connected objects\n";
4347 anOriginObject = findConnectedObject (anOriginObjectName);
4348 if (anOriginObject.IsNull())
4350 TopoDS_Shape aTDShape = DBRep::Get (anOriginObjectName);
4351 if (aTDShape.IsNull())
4353 std::cout << "Syntax error: object " << anOriginObjectName << " doesn't exist\n";
4357 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aTDShape);
4358 Handle(AIS_ConnectedInteractive) aConnectedOrig = new AIS_ConnectedInteractive();
4359 aConnectedOrig->Connect (aShapePrs);
4361 anOriginObject = aConnectedOrig;
4362 GetMapOfAIS().Bind (aConnectedOrig, anOriginObjectName);
4365 // Create transformation
4367 aTrsf.SetTranslationPart (gp_Vec (Draw::Atof (argv[anArgIter + 0]),
4368 Draw::Atof (argv[anArgIter + 1]),
4369 Draw::Atof (argv[anArgIter + 2])));
4372 Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive();
4373 aConnected->Connect (anOriginObject, aTrsf);
4376 TCollection_AsciiString anArg = argv[6];
4378 if (anArg == "-nodisplay")
4380 // bind connected object without displaying it
4381 Handle(AIS_InteractiveObject) anObj;
4382 if (GetMapOfAIS().Find2 (aName, anObj))
4384 TheAISContext()->Remove (anObj, false);
4385 GetMapOfAIS().UnBind2 (aName);
4387 GetMapOfAIS().Bind (aConnected, aName);
4391 if (!anUpdateTool.parseRedrawMode (anArg))
4393 std::cout << "Syntax error: unknown argument '" << anArg << "'.\n";
4398 ViewerTest::Display (aName, aConnected, false);
4402 //=======================================================================
4403 //function : VDisconnect
4405 //=======================================================================
4406 static Standard_Integer VDisconnect (Draw_Interpretor& di,
4407 Standard_Integer argc,
4410 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4411 if (aContext.IsNull())
4413 std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4419 std::cout << "ERROR : Usage : " << argv[0] << " name object\n";
4423 TCollection_AsciiString aName (argv[1]);
4424 TCollection_AsciiString anObject (argv[2]);
4425 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
4428 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4429 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4430 if (!aMap.IsBound2 (aName) )
4432 std::cout << "Use 'vdisplay' before\n";
4436 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4437 if (anAssembly.IsNull())
4439 di << "Not an assembly\n";
4443 Handle(AIS_InteractiveObject) anIObj;
4444 if (!aMap.Find2 (anObject, anIObj))
4446 // try to interpret second argument as child number
4447 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
4449 Standard_Integer aCounter = 1;
4450 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4452 if (aCounter == anObjectNumber)
4454 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4462 std::cout << "Use 'vdisplay' before\n";
4467 aContext->Disconnect (anAssembly, anIObj);
4468 aContext->UpdateCurrentViewer();
4472 //=======================================================================
4473 //function : VAddConnected
4475 //=======================================================================
4476 static Standard_Integer VAddConnected (Draw_Interpretor& ,
4477 Standard_Integer argc,
4480 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4481 if (aContext.IsNull())
4483 std::cout << "Error: no active view\n";
4489 std::cout << "Syntax error: expect 5 arguments\n";
4493 const TCollection_AsciiString aName (argv[1]);
4494 const Standard_Real aX = Draw::Atof (argv[2]);
4495 const Standard_Real aY = Draw::Atof (argv[3]);
4496 const Standard_Real aZ = Draw::Atof (argv[4]);
4497 const TCollection_AsciiString anObjectName (argv[5]);
4500 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4501 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4503 Handle(AIS_InteractiveObject) aPrs;
4504 aMap.Find2 (aName, aPrs);
4505 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aPrs);
4506 if (anAssembly.IsNull())
4508 std::cout << "Syntax error: '" << aName << "' is not an assembly\n";
4513 Handle(AIS_InteractiveObject) anIObj = findConnectedObject (anObjectName);
4514 if (anIObj.IsNull())
4516 std::cout << "Syntax error: '" << anObjectName << "' is not displayed\n";
4521 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4523 anAssembly->Connect (anIObj, aTrsf);
4524 TheAISContext()->Display (anAssembly, Standard_False);
4525 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4526 aContext->UpdateCurrentViewer();
4530 //=======================================================================
4531 //function : VListConnected
4533 //=======================================================================
4534 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4535 Standard_Integer argc,
4538 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4539 if (aContext.IsNull())
4541 std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4547 std::cout << "ERROR : Usage : " << argv[0] << " name\n";
4551 TCollection_AsciiString aName (argv[1]);
4554 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4555 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4556 if (!aMap.IsBound2 (aName) )
4558 std::cout << "Use 'vdisplay' before\n";
4562 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4563 if (anAssembly.IsNull())
4565 std::cout << "Not an assembly\n";
4569 std::cout << "Children of " << aName << ":\n";
4571 Standard_Integer aCounter = 1;
4572 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4574 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4575 if (GetMapOfAIS().IsBound1 (anObj))
4577 TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anObj);
4578 std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4581 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4583 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4584 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4586 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4588 std::cout << std::endl;
4596 //=======================================================================
4599 //=======================================================================
4600 static Standard_Integer VChild (Draw_Interpretor& ,
4601 Standard_Integer theNbArgs,
4602 const char** theArgVec)
4604 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4605 if (aContext.IsNull())
4607 std::cout << "Error: no active view\n";
4612 Handle(AIS_InteractiveObject) aParent;
4613 bool hasActions = false;
4614 int toInheritTrsf = -1;
4615 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4616 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4618 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4620 if (anUpdateTool.parseRedrawMode (anArg))
4624 else if (anArg == "-add")
4629 else if (anArg == "-remove")
4634 else if (anArg == "-inheritparenttrsf"
4635 || anArg == "-inheritparentloc"
4636 || anArg == "-inheritparentlocation"
4637 || anArg == "-inheritparent"
4638 || anArg == "-noinheritparenttrsf"
4639 || anArg == "-noinheritparentloc"
4640 || anArg == "-noinheritparentlocation"
4641 || anArg == "-noinheritparent"
4642 || anArg == "-ignoreparenttrsf"
4643 || anArg == "-ignoreparentloc"
4644 || anArg == "-ignoreparentlocation"
4645 || anArg == "-ignoreparent")
4648 if (anArgIter + 1 < theNbArgs
4649 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], aVal))
4653 if (anArg.StartsWith("-no")
4654 || anArg.StartsWith("-ignore"))
4658 toInheritTrsf = aVal ? 1 : 0;
4662 Handle(AIS_InteractiveObject) aChild;
4663 if (!GetMapOfAIS().Find2 (theArgVec[anArgIter], aChild))
4665 std::cout << "Syntax error: object '" << theArgVec[anArgIter] << "' is not found\n";
4669 if (aParent.IsNull())
4673 else if (toAdd == -1)
4675 std::cout << "Syntax error: no action specified\n";
4683 if(toInheritTrsf == 0)
4684 aParent->AddChildWithCurrentTransformation(aChild);
4686 aParent->AddChild (aChild);
4690 if (toInheritTrsf == 0)
4691 aParent->RemoveChildWithRestoreTransformation(aChild);
4693 aParent->RemoveChild (aChild);
4699 std::cout << "Syntax error: not enough arguments\n";
4705 //=======================================================================
4706 //function : VParent
4708 //=======================================================================
4709 static Standard_Integer VParent(Draw_Interpretor&,
4710 Standard_Integer theNbArgs,
4711 const char** theArgVec)
4713 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4714 if (aContext.IsNull())
4716 std::cout << "Error: no active view\n";
4722 std::cout << theArgVec[0] << " error: expect at least 2 arguments\n";
4726 TCollection_AsciiString aName(theArgVec[1]);
4727 Handle(AIS_InteractiveObject) aParent;
4728 if (!GetMapOfAIS().Find2(theArgVec[1], aParent))
4730 std::cout << "Syntax error: object '" << theArgVec[1] << "' is not found\n";
4734 ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
4735 for (Standard_Integer anArgIter = 2; anArgIter < theNbArgs; ++anArgIter)
4737 TCollection_AsciiString anArg(theArgVec[anArgIter]);
4739 if (anArg == "-ignorevisu")
4740 aParent->SetPropagateVisualState(Standard_False);
4745 //===============================================================================================
4746 //function : VSetSelectionMode
4747 //purpose : vselmode
4748 //===============================================================================================
4749 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4750 Standard_Integer theNbArgs,
4751 const char** theArgv)
4754 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4755 if (anAISContext.IsNull())
4757 std::cout << "Error: no active Viewer\n";
4761 NCollection_Sequence<TCollection_AsciiString> anObjNames;
4762 Standard_Integer aSelectionMode = -1;
4763 Standard_Boolean toTurnOn = Standard_True;
4764 AIS_SelectionModesConcurrency aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4765 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4767 TCollection_AsciiString anArgCase (theArgv[anArgIter]);
4768 anArgCase.LowerCase();
4769 if (anArgCase == "-set"
4770 || anArgCase == "-replace"
4771 || anArgCase == "-single"
4772 || anArgCase == "-exclusive")
4774 aSelModeConcurrency = AIS_SelectionModesConcurrency_Single;
4776 else if (anArgCase == "-add"
4777 || anArgCase == "-combine"
4778 || anArgCase == "-combination"
4779 || anArgCase == "-multiple")
4781 aSelModeConcurrency = AIS_SelectionModesConcurrency_Multiple;
4783 else if (anArgCase == "-globalorlocal"
4784 || anArgCase == "-localorglobal")
4786 aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4790 anObjNames.Append (theArgv[anArgIter]);
4793 if (anObjNames.Size() < 2
4794 || !ViewerTest::ParseOnOff (anObjNames.Last().ToCString(), toTurnOn))
4796 std::cout << "Syntax error: wrong number of arguments\n";
4799 anObjNames.Remove (anObjNames.Upper());
4801 const TCollection_AsciiString aSelModeString = anObjNames.Last();
4802 anObjNames.Remove (anObjNames.Upper());
4803 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4804 if (aSelModeString.IsIntegerValue())
4806 aSelectionMode = aSelModeString.IntegerValue();
4808 else if (TopAbs::ShapeTypeFromString (aSelModeString.ToCString(), aShapeType))
4810 aSelectionMode = AIS_Shape::SelectionMode (aShapeType);
4814 std::cout << "Syntax error: unknown selection mode '" << aSelModeString << "'\n";
4819 AIS_ListOfInteractive aTargetIOs;
4820 for (NCollection_Sequence<TCollection_AsciiString>::Iterator anObjIter (anObjNames); anObjIter.More(); anObjIter.Next())
4822 const TCollection_AsciiString& aNameIO = anObjIter.Value();
4823 Handle(AIS_InteractiveObject) anIO;
4824 GetMapOfAIS().Find2 (aNameIO, anIO);
4827 std::cout << "Syntax error: undefined presentable object " << aNameIO << "\n";
4830 aTargetIOs.Append (anIO);
4832 if (aTargetIOs.IsEmpty())
4834 anAISContext->DisplayedObjects (aTargetIOs);
4837 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4839 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4840 anAISContext->SetSelectionModeActive (anIO, aSelectionMode, toTurnOn, aSelModeConcurrency);
4845 //===============================================================================================
4846 //function : VSelectionNext
4848 //===============================================================================================
4849 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4850 Standard_Integer /*theArgsNb*/,
4851 const char** /*theArgVec*/)
4854 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4855 Handle(V3d_View) aView = ViewerTest::CurrentView();
4857 if (anAISContext.IsNull())
4859 std::cerr << "Call vinit before!" << std::endl;
4863 anAISContext->HilightNextDetected (aView);
4867 //===============================================================================================
4868 //function : VSelectionPrevious
4870 //===============================================================================================
4871 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4872 Standard_Integer /*theArgsNb*/,
4873 const char** /*theArgVec*/)
4876 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4877 Handle(V3d_View) aView = ViewerTest::CurrentView();
4879 if (anAISContext.IsNull())
4881 std::cerr << "Call vinit before!" << std::endl;
4885 anAISContext->HilightPreviousDetected (aView);
4889 //===========================================================================
4890 //function : VTriangle
4891 //Draw arg : vtriangle Name PointName PointName PointName
4892 //purpose : creates and displays Triangle
4893 //===========================================================================
4894 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4895 Standard_Integer argc,
4898 const Standard_Boolean isTri = TCollection_AsciiString (argv[0]) == "vtriangle";
4899 Handle(Graphic3d_ArrayOfPrimitives) aPrims;
4902 aPrims = new Graphic3d_ArrayOfTriangles (3);
4906 aPrims = new Graphic3d_ArrayOfSegments (2);
4909 if (argc != (2 + aPrims->VertexNumberAllocated()))
4911 std::cout << "Syntax error: wrong number of arguments\n";
4916 for (Standard_Integer aPntIter = 0; aPntIter < aPrims->VertexNumberAllocated(); ++aPntIter)
4918 const TCollection_AsciiString aName (argv[2 + aPntIter]);
4919 if (Handle(AIS_Point) aPntPrs = Handle(AIS_Point)::DownCast (GetMapOfAIS().IsBound2 (aName) ? GetMapOfAIS().Find2 (aName) : NULL))
4921 aPnts[aPntIter] = aPntPrs->Component()->Pnt();
4925 TopoDS_Shape aShape = DBRep::Get (argv[2 + aPntIter]);
4927 || aShape.ShapeType() != TopAbs_VERTEX)
4929 std::cout << "Syntax error: argument " << aName << " must be a point\n";
4932 aPnts[aPntIter] = BRep_Tool::Pnt (TopoDS::Vertex (aShape));
4935 for (Standard_Integer aPnt2Iter = 0; aPnt2Iter < aPntIter; ++aPnt2Iter)
4937 if (aPnts[aPnt2Iter].IsEqual (aPnts[aPntIter], Precision::Confusion()))
4939 std::cout << "Syntax error: points should not be equal\n";
4944 aPrims->AddVertex (aPnts[aPntIter]);
4947 Handle(AIS_InteractiveObject) aPrs = new MyPArrayObject (aPrims);
4950 aPrs->Attributes()->SetupOwnShadingAspect();
4951 aPrs->Attributes()->ShadingAspect()->Aspect()->SetColor (aPrs->Attributes()->LineAspect()->Aspect()->Color());
4953 ViewerTest::Display (argv[1], aPrs);
4957 //=======================================================================
4958 //function : VObjZLayer
4959 //purpose : Set or get z layer id for presentable object
4960 //=======================================================================
4962 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4963 Standard_Integer argc,
4966 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4967 if (aContext.IsNull())
4969 di << argv[0] << "Call 'vinit' before!\n";
4974 TCollection_AsciiString aOperation;
4976 aOperation = TCollection_AsciiString (argv [1]);
4978 // check for correct arguments
4979 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4980 !(argc == 3 && aOperation.IsEqual ("get")))
4982 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4983 di << " set - set layer id for interactive object, layerid - z layer id\n";
4984 di << " get - get layer id of interactive object\n";
4985 di << " argument layerid should be passed for set operation only\n";
4990 TCollection_AsciiString aName (argv[2]);
4991 Handle(AIS_InteractiveObject) anInterObj;
4992 GetMapOfAIS().Find2 (aName, anInterObj);
4993 if (anInterObj.IsNull())
4995 std::cout << "Syntax error: object '" << aName << "' is not displayed\n";
4999 // process operation
5000 if (aOperation.IsEqual ("set"))
5002 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
5003 aContext->SetZLayer (anInterObj, aLayerId);
5005 else if (aOperation.IsEqual ("get"))
5007 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
5013 //=======================================================================
5014 //function : VPolygonOffset
5015 //purpose : Set or get polygon offset parameters
5016 //=======================================================================
5017 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
5018 Standard_Integer argc,
5021 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5022 if (aContext.IsNull())
5024 std::cout << argv[0] << " Call 'vinit' before!\n";
5028 if (argc > 2 && argc != 5)
5030 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
5031 "without arguments prints the default values" << std::endl;
5036 Handle(AIS_InteractiveObject) anInterObj;
5039 TCollection_AsciiString aName (argv[1]);
5040 if (!GetMapOfAIS().Find2 (aName, anInterObj)
5041 || anInterObj.IsNull())
5043 std::cout << "Syntax error: object '" << aName << "' is not displayed\n";
5048 Standard_Integer aMode;
5049 Standard_ShortReal aFactor, aUnits;
5052 aMode = Draw::Atoi(argv[2]);
5053 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
5054 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
5056 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
5057 aContext->UpdateCurrentViewer();
5062 if (anInterObj->HasPolygonOffsets())
5064 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
5065 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
5066 std::cout << "\tMode: " << aMode << std::endl;
5067 std::cout << "\tFactor: " << aFactor << std::endl;
5068 std::cout << "\tUnits: " << aUnits << std::endl;
5073 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
5077 std::cout << "Default polygon offset parameters:" << std::endl;
5078 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
5079 std::cout << "\tMode: " << aMode << std::endl;
5080 std::cout << "\tFactor: " << aFactor << std::endl;
5081 std::cout << "\tUnits: " << aUnits << std::endl;
5086 // This class is used for testing markers.
5087 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
5092 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
5093 const Standard_Integer& thePointsOnSide,
5094 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
5096 myStartPoint = theStartPoint;
5097 myPointsOnSide = thePointsOnSide;
5098 myMarkerAspect = theMarkerAspect;
5101 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_MarkersArrayObject,AIS_InteractiveObject);
5105 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
5106 const Handle(Prs3d_Presentation)& aPresentation,
5107 const Standard_Integer aMode) Standard_OVERRIDE;
5109 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5110 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
5114 gp_XYZ myStartPoint;
5115 Standard_Integer myPointsOnSide;
5116 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
5120 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
5121 const Handle(Prs3d_Presentation)& aPresentation,
5122 const Standard_Integer /*aMode*/)
5124 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
5125 if (myPointsOnSide == 1)
5127 anArray->AddVertex (myStartPoint);
5131 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5133 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5135 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5137 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5138 anArray->SetVertexColor (anArray->VertexNumber(),
5141 k / myPointsOnSide);
5147 aPresentation->Clear();
5148 if (!myMarkerAspect.IsNull())
5150 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
5152 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
5155 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5156 const Standard_Integer /*theMode*/)
5158 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
5160 if (myPointsOnSide == 1)
5162 gp_Pnt aPoint (myStartPoint);
5163 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5164 theSelection->Add (aSensetivePoint);
5168 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5170 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5172 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5174 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5175 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5176 theSelection->Add (aSensetivePoint);
5182 //=======================================================================
5183 //function : VMarkersTest
5184 //purpose : Draws an array of markers for testing purposes.
5185 //=======================================================================
5186 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5187 Standard_Integer theArgNb,
5188 const char** theArgVec)
5190 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5191 if (aContext.IsNull())
5193 std::cerr << "Call 'vinit' before!\n";
5199 std::cerr << "Usage :\n " << theArgVec[0]
5200 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5204 Standard_Integer anArgIter = 1;
5206 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5207 TCollection_AsciiString aFileName;
5208 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5209 Atof (theArgVec[anArgIter + 1]),
5210 Atof (theArgVec[anArgIter + 2]));
5213 Standard_Integer aPointsOnSide = 10;
5214 Standard_Integer aMarkerType = -1;
5215 Standard_Real aScale = 1.0;
5216 for (; anArgIter < theArgNb; ++anArgIter)
5218 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5219 if (anArg.Search ("PointsOnSide=") > -1)
5221 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5223 else if (anArg.Search ("MarkerType=") > -1)
5225 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5227 else if (anArg.Search ("Scale=") > -1)
5229 aScale = anArg.Token ("=", 2).RealValue();
5231 else if (anArg.Search ("FileName=") > -1)
5233 aFileName = anArg.Token ("=", 2);
5237 std::cerr << "Wrong argument: " << anArg << "\n";
5242 Handle(Graphic3d_AspectMarker3d) anAspect;
5243 Handle(Image_AlienPixMap) anImage;
5244 Quantity_Color aColor (Quantity_NOC_GREEN1);
5245 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5246 && !aFileName.IsEmpty())
5248 anImage = new Image_AlienPixMap();
5249 if (!anImage->Load (aFileName))
5251 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5254 if (anImage->Format() == Image_Format_Gray)
5256 anImage->SetFormat (Image_Format_Alpha);
5258 else if (anImage->Format() == Image_Format_GrayF)
5260 anImage->SetFormat (Image_Format_AlphaF);
5262 anAspect = new Graphic3d_AspectMarker3d (anImage);
5266 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5269 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5270 VDisplayAISObject (aName, aMarkersArray);
5275 //=======================================================================
5276 //function : TextToBrep
5277 //purpose : Tool for conversion text to occt-shapes
5278 //=======================================================================
5279 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5280 Standard_Integer theArgNb,
5281 const char** theArgVec)
5286 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5290 Standard_Integer anArgIt = 1;
5291 Standard_CString aName = theArgVec[anArgIt++];
5292 Standard_CString aText = theArgVec[anArgIt++];
5294 Font_BRepFont aFont;
5295 TCollection_AsciiString aFontName ("Courier");
5296 Standard_Real aTextHeight = 16.0;
5297 Font_FontAspect aFontAspect = Font_FA_Regular;
5298 Standard_Boolean anIsCompositeCurve = Standard_False;
5299 gp_Ax3 aPenAx3 (gp::XOY());
5300 gp_Dir aNormal (0.0, 0.0, 1.0);
5301 gp_Dir aDirection (1.0, 0.0, 0.0);
5304 Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT;
5305 Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM;
5306 Font_StrictLevel aStrictLevel = Font_StrictLevel_Any;
5307 for (; anArgIt < theArgNb; ++anArgIt)
5309 TCollection_AsciiString aParam (theArgVec[anArgIt]);
5312 if (aParam == "-pos"
5313 || aParam == "-position")
5315 if (anArgIt + 3 >= theArgNb)
5317 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5321 aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt]));
5322 aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt]));
5323 aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt]));
5325 else if (aParam == "-halign")
5327 if (++anArgIt >= theArgNb)
5329 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5333 TCollection_AsciiString aType (theArgVec[anArgIt]);
5335 if (aType == "left")
5337 aHJustification = Graphic3d_HTA_LEFT;
5339 else if (aType == "center")
5341 aHJustification = Graphic3d_HTA_CENTER;
5343 else if (aType == "right")
5345 aHJustification = Graphic3d_HTA_RIGHT;
5349 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5353 else if (aParam == "-valign")
5355 if (++anArgIt >= theArgNb)
5357 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5361 TCollection_AsciiString aType (theArgVec[anArgIt]);
5365 aVJustification = Graphic3d_VTA_TOP;
5367 else if (aType == "center")
5369 aVJustification = Graphic3d_VTA_CENTER;
5371 else if (aType == "bottom")
5373 aVJustification = Graphic3d_VTA_BOTTOM;
5375 else if (aType == "topfirstline")
5377 aVJustification = Graphic3d_VTA_TOPFIRSTLINE;
5381 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5385 else if (aParam == "-height")
5387 if (++anArgIt >= theArgNb)
5389 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5393 aTextHeight = Draw::Atof(theArgVec[anArgIt]);
5395 else if (aParam == "-aspect")
5397 if (++anArgIt >= theArgNb)
5399 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5403 TCollection_AsciiString anOption (theArgVec[anArgIt]);
5404 anOption.LowerCase();
5405 if (!parseFontStyle (anOption, aFontAspect))
5407 std::cout << "Error: unknown font aspect '" << anOption << "'.\n";
5411 else if (aParam == "-font")
5413 if (++anArgIt >= theArgNb)
5415 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5419 aFontName = theArgVec[anArgIt];
5421 else if (aParam == "-strict")
5423 anArgIt += parseFontStrictLevel (theArgNb - anArgIt - 1,
5424 theArgVec + anArgIt + 1,
5427 else if (aParam == "-composite")
5429 if (++anArgIt >= theArgNb)
5431 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5435 ViewerTest::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve);
5437 else if (aParam == "-plane")
5439 if (anArgIt + 6 >= theArgNb)
5441 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5445 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
5446 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
5447 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
5448 aNormal.SetCoord (aX, aY, aZ);
5450 aX = Draw::Atof (theArgVec[++anArgIt]);
5451 aY = Draw::Atof (theArgVec[++anArgIt]);
5452 aZ = Draw::Atof (theArgVec[++anArgIt]);
5453 aDirection.SetCoord (aX, aY, aZ);
5457 std::cerr << "Warning! Unknown argument '" << aParam << "'\n";
5461 aFont.SetCompositeCurveMode (anIsCompositeCurve);
5462 if (!aFont.FindAndInit (aFontName.ToCString(), aFontAspect, aTextHeight, aStrictLevel))
5464 std::cout << "Error: unable to load Font\n";
5468 aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection);
5470 Font_BRepTextBuilder aBuilder;
5471 DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification));
5475 //=======================================================================
5477 //purpose : Font management
5478 //=======================================================================
5479 struct FontComparator
5481 bool operator() (const Handle(Font_SystemFont)& theFontA,
5482 const Handle(Font_SystemFont)& theFontB)
5484 return theFontA->FontKey().IsLess (theFontB->FontKey());
5488 static int VFont (Draw_Interpretor& theDI,
5489 Standard_Integer theArgNb,
5490 const char** theArgVec)
5492 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5495 // just print the list of available fonts
5496 Standard_Boolean isFirst = Standard_True;
5497 const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts();
5498 std::vector<Handle(Font_SystemFont)> aFontsSorted;
5499 aFontsSorted.reserve (aFonts.Size());
5500 for (Font_NListOfSystemFont::Iterator aFontIter (aFonts); aFontIter.More(); aFontIter.Next())
5502 aFontsSorted.push_back (aFontIter.Value());
5504 std::stable_sort (aFontsSorted.begin(), aFontsSorted.end(), FontComparator());
5505 for (std::vector<Handle(Font_SystemFont)>::iterator aFontIter = aFontsSorted.begin(); aFontIter != aFontsSorted.end(); ++aFontIter)
5507 const Handle(Font_SystemFont)& aFont = *aFontIter;
5513 theDI << aFont->ToString();
5514 isFirst = Standard_False;
5519 Font_StrictLevel aStrictLevel = Font_StrictLevel_Any;
5520 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5522 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5523 TCollection_AsciiString anArgCase (anArg);
5524 anArgCase.LowerCase();
5525 if (anArgCase == "-strict")
5527 anArgIter += parseFontStrictLevel (theArgNb - anArgIter - 1,
5528 theArgVec + anArgIter + 1,
5531 else if (anArgCase == "-clear")
5533 aMgr->ClearFontDataBase();
5535 else if (anArgCase == "-init")
5537 aMgr->InitFontDataBase();
5539 else if (anArgIter + 1 < theArgNb
5540 && (anArgCase == "-find"
5541 || anArgCase == "find"))
5543 Standard_CString aFontName = theArgVec[++anArgIter];
5544 Font_FontAspect aFontAspect = Font_FA_Undefined;
5545 if (++anArgIter < theArgNb)
5547 anArgCase = theArgVec[anArgIter];
5548 anArgCase.LowerCase();
5549 if (!parseFontStyle (anArgCase, aFontAspect))
5555 if (Handle(Font_SystemFont) aFont = aMgr->FindFont (aFontName, aStrictLevel, aFontAspect))
5557 theDI << aFont->ToString();
5561 std::cout << "Error: font '" << aFontName << "' is not found!\n";
5564 else if (anArgIter + 1 < theArgNb
5565 && (anArgCase == "-add"
5566 || anArgCase == "add"
5567 || anArgCase == "-register"
5568 || anArgCase == "register"))
5571 Standard_CString aFontPath = theArgVec[anArgIter++];
5572 TCollection_AsciiString aFontName;
5573 Font_FontAspect aFontAspect = Font_FA_Undefined;
5574 Standard_Integer isSingelStroke = -1;
5575 for (; anArgIter < theArgNb; ++anArgIter)
5577 anArgCase = theArgVec[anArgIter];
5578 anArgCase.LowerCase();
5579 if (aFontAspect == Font_FontAspect_UNDEFINED
5580 && parseFontStyle (anArgCase, aFontAspect))
5584 else if (anArgCase == "singlestroke"
5585 || anArgCase == "singleline"
5586 || anArgCase == "oneline")
5590 else if (aFontName.IsEmpty())
5592 aFontName = theArgVec[anArgIter];
5601 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5604 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5608 if (aFontAspect != Font_FontAspect_UNDEFINED
5609 || !aFontName.IsEmpty())
5611 TCollection_AsciiString aName = aFont->FontName();
5612 if (!aFontName.IsEmpty())
5616 Handle(Font_SystemFont) aFont2 = new Font_SystemFont (aName);
5617 if (aFontAspect != Font_FontAspect_UNDEFINED)
5619 aFont2->SetFontPath (aFontAspect, aFontPath);
5623 for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
5625 aFont2->SetFontPath ((Font_FontAspect )anAspectIter, aFont->FontPath ((Font_FontAspect )anAspectIter));
5630 if (isSingelStroke != -1)
5632 aFont->SetSingleStrokeFont (isSingelStroke == 1);
5635 aMgr->RegisterFont (aFont, Standard_True);
5636 theDI << aFont->ToString();
5638 else if (anArgCase == "-verbose"
5639 || anArgCase == "-trace")
5641 bool toEnable = true;
5642 if (anArgIter + 1 < theArgNb
5643 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
5647 aMgr->SetTraceAliases (toEnable);
5649 else if (anArgCase == "-unicodefallback"
5650 || anArgCase == "-fallback"
5651 || anArgCase == "-touseunicodesubsetfallback")
5653 bool toEnable = true;
5654 if (anArgIter + 1 < theArgNb
5655 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
5659 Font_FontMgr::ToUseUnicodeSubsetFallback() = toEnable;
5663 std::cerr << "Warning! Unknown argument '" << anArg << "'\n";
5670 //=======================================================================
5671 //function : VVertexMode
5672 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
5673 //=======================================================================
5675 static int VVertexMode (Draw_Interpretor& theDI,
5676 Standard_Integer theArgNum,
5677 const char** theArgs)
5679 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5680 if (aContext.IsNull())
5682 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5686 // No arguments --> print the current default vertex draw mode
5689 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5690 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5694 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5695 TCollection_AsciiString aParam (theArgs[1]);
5696 if (aParam == "-set")
5700 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5701 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5705 TCollection_AsciiString aModeStr (theArgs[2]);
5706 Prs3d_VertexDrawMode aNewMode =
5707 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5708 (aModeStr == "all" ? Prs3d_VDM_All :
5709 Prs3d_VDM_Inherited);
5711 Standard_Boolean aRedrawNeeded = Standard_False;
5712 AIS_ListOfInteractive anObjs;
5714 // No object(s) specified -> use all displayed
5717 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5718 aContext->DisplayedObjects (anObjs);
5719 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5720 aRedrawNeeded = Standard_True;
5723 Handle(AIS_InteractiveObject) anObject;
5724 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5726 TCollection_AsciiString aName (theArgs[aCount]);
5727 if (!GetMapOfAIS().Find2 (aName, anObject))
5729 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5732 anObjs.Append (anObject);
5735 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5737 anObject = anIt.Value();
5738 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5739 aContext->Redisplay (anObject, Standard_False);
5740 aRedrawNeeded = Standard_True;
5744 ViewerTest::CurrentView()->Redraw();
5749 Handle(AIS_InteractiveObject) anObject;
5751 || !GetMapOfAIS().Find2 (aParam, anObject))
5753 std::cout << "Error: invalid number of arguments" << std::endl;
5757 // One argument (object name) --> print the current vertex draw mode for the object
5758 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5759 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5763 //=======================================================================
5764 //function : VPointCloud
5765 //purpose : Create interactive object for arbitary set of points.
5766 //=======================================================================
5767 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5768 Standard_Integer theArgNum,
5769 const char** theArgs)
5771 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5772 if (anAISContext.IsNull())
5774 std::cerr << "Error: no active view!\n";
5778 // command to execute
5781 CloudForShape, // generate point cloud for shape
5782 CloudSphere, // generate point cloud for generic sphere
5786 // count number of non-optional command arguments
5787 Command aCmd = Unknow;
5788 Standard_Integer aCmdArgs = 0;
5789 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5791 Standard_CString anArg = theArgs[anArgIter];
5792 TCollection_AsciiString aFlag (anArg);
5794 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5801 case 2 : aCmd = CloudForShape; break;
5802 case 7 : aCmd = CloudSphere; break;
5804 std::cout << "Error: wrong number of arguments! See usage:\n";
5805 theDI.PrintHelp (theArgs[0]);
5810 Standard_Boolean toRandColors = Standard_False;
5811 Standard_Boolean hasNormals = Standard_True;
5812 Standard_Boolean isSetArgNorm = Standard_False;
5813 Standard_Boolean hasUV = Standard_False;
5814 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5816 Standard_CString anArg = theArgs[anArgIter];
5817 TCollection_AsciiString aFlag (anArg);
5819 if (aFlag == "-randcolors"
5820 || aFlag == "-randcolor")
5822 if (isSetArgNorm && hasNormals)
5824 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5827 toRandColors = Standard_True;
5828 hasNormals = Standard_False;
5830 else if (aFlag == "-normals"
5831 || aFlag == "-normal")
5835 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5838 isSetArgNorm = Standard_True;
5839 hasNormals = Standard_True;
5841 else if (aFlag == "-nonormals"
5842 || aFlag == "-nonormal")
5844 isSetArgNorm = Standard_True;
5845 hasNormals = Standard_False;
5847 else if (aFlag == "-uv"
5848 || aFlag == "-texels")
5850 hasUV = Standard_True;
5854 Standard_CString aName = theArgs[1];
5855 Graphic3d_ArrayFlags aFlags = Graphic3d_ArrayFlags_None;
5858 aFlags |= Graphic3d_ArrayFlags_VertexNormal;
5862 aFlags |= Graphic3d_ArrayFlags_VertexColor;
5866 aFlags |= Graphic3d_ArrayFlags_VertexTexel;
5869 // generate arbitrary set of points
5870 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
5871 if (aCmd == CloudForShape)
5873 Standard_CString aShapeName = theArgs[2];
5874 TopoDS_Shape aShape = DBRep::Get (aShapeName);
5876 if (aShape.IsNull())
5878 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
5882 // calculate number of points
5883 TopLoc_Location aLocation;
5884 Standard_Integer aNbPoints = 0;
5885 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5887 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5888 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5889 if (!aTriangulation.IsNull())
5891 aNbPoints += aTriangulation->NbNodes();
5896 std::cout << "Error: shape should be triangulated!\n";
5900 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags);
5901 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5903 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5904 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5905 if (aTriangulation.IsNull())
5910 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
5911 const gp_Trsf& aTrsf = aLocation.Transformation();
5913 // extract normals from nodes
5914 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
5917 Poly_Connect aPolyConnect (aTriangulation);
5918 StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
5921 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
5923 gp_Pnt aPoint = aNodes (aNodeIter);
5924 if (!aLocation.IsIdentity())
5926 aPoint.Transform (aTrsf);
5929 aNormals (aNodeIter).Transform (aTrsf);
5933 // add vertex into array of points
5934 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5937 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
5938 1.0, 0.5, Quantity_TOC_HLS);
5939 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5944 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
5947 && aTriangulation->HasUVNodes())
5949 anArrayPoints->SetVertexTexel (anIndexOfPoint, aTriangulation->UVNode (aNodeIter));
5954 else if (aCmd == CloudSphere)
5956 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
5957 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
5958 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
5959 Standard_Real aRadius = Draw::Atof (theArgs[5]);
5960 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
5962 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
5963 aDistribution.LowerCase();
5964 if ( aDistribution != "surface" && aDistribution != "volume" )
5966 std::cout << "Error: wrong arguments! See usage:\n";
5967 theDI.PrintHelp (theArgs[0]);
5970 Standard_Boolean isSurface = aDistribution == "surface";
5972 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
5974 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags);
5975 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
5977 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5978 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5979 Standard_Real aDistance = isSurface ?
5980 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
5982 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
5984 Cos (anAlpha) * Cos (aBeta));
5985 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
5987 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5990 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
5991 1.0, 0.5, Quantity_TOC_HLS);
5992 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5997 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
6001 anArrayPoints->SetVertexTexel (anIndexOfPoint, gp_Pnt2d (anAlpha / 2.0 * M_PI,
6002 aBeta / 2.0 * M_PI));
6007 // set array of points in point cloud object
6008 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
6009 aPointCloud->SetPoints (anArrayPoints);
6010 VDisplayAISObject (aName, aPointCloud);
6014 //=======================================================================
6015 //function : VPriority
6016 //purpose : Prints or sets the display priority for an object
6017 //=======================================================================
6019 static int VPriority (Draw_Interpretor& theDI,
6020 Standard_Integer theArgNum,
6021 const char** theArgs)
6023 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6024 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6025 if (aContext.IsNull())
6027 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
6031 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
6032 Standard_Integer aPriority = -1;
6033 Standard_Integer aNbArgs = theArgNum;
6034 if (aLastArg.IsIntegerValue())
6036 aPriority = aLastArg.IntegerValue();
6038 if (aPriority < 0 || aPriority > 10)
6040 std::cout << "Error: the specified display priority value '" << aLastArg
6041 << "' is outside the valid range [0..10]" << std::endl;
6047 anUpdateTool.Invalidate();
6052 std::cout << "Error: wrong number of arguments! See usage:\n";
6053 theDI.PrintHelp (theArgs[0]);
6057 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
6059 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
6064 TCollection_AsciiString aName (theArgs[anArgIter]);
6065 Handle(AIS_InteractiveObject) anIObj;
6066 GetMapOfAIS().Find2 (aName, anIObj);
6067 if (anIObj.IsNull())
6069 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
6075 theDI << aContext->DisplayPriority (anIObj) << " ";
6079 aContext->SetDisplayPriority (anIObj, aPriority);
6085 //! Auxiliary class for command vnormals.
6086 class MyShapeWithNormals : public AIS_Shape
6088 DEFINE_STANDARD_RTTI_INLINE(MyShapeWithNormals, AIS_Shape);
6091 Standard_Real NormalLength;
6092 Standard_Integer NbAlongU;
6093 Standard_Integer NbAlongV;
6094 Standard_Boolean ToUseMesh;
6095 Standard_Boolean ToOrient;
6099 //! Main constructor.
6100 MyShapeWithNormals (const TopoDS_Shape& theShape)
6101 : AIS_Shape (theShape),
6105 ToUseMesh (Standard_False),
6106 ToOrient (Standard_False) {}
6110 //! Comnpute presentation.
6111 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
6112 const Handle(Prs3d_Presentation)& thePrs,
6113 const Standard_Integer theMode) Standard_OVERRIDE
6115 AIS_Shape::Compute (thePrsMgr, thePrs, theMode);
6117 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormalMap;
6120 DBRep_DrawableShape::addMeshNormals (aNormalMap, myshape, NormalLength);
6124 DBRep_DrawableShape::addSurfaceNormals (aNormalMap, myshape, NormalLength, NbAlongU, NbAlongV);
6127 Handle(Graphic3d_Group) aPrsGroup = Prs3d_Root::NewGroup (thePrs);
6128 aPrsGroup->SetGroupPrimitivesAspect (myDrawer->ArrowAspect()->Aspect());
6130 const Standard_Real aArrowAngle = myDrawer->ArrowAspect()->Angle();
6131 const Standard_Real aArrowLength = myDrawer->ArrowAspect()->Length();
6132 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormalMap);
6133 aFaceIt.More(); aFaceIt.Next())
6135 const Standard_Boolean toReverse = ToOrient && aFaceIt.Key().Orientation() == TopAbs_REVERSED;
6136 Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (2 * aFaceIt.Value().Size());
6137 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aPntIt (aFaceIt.Value()); aPntIt.More(); aPntIt.Next())
6139 std::pair<gp_Pnt, gp_Pnt> aPair = aPntIt.Value();
6142 const gp_Vec aDir = aPair.first.XYZ() - aPair.second.XYZ();
6143 aPair.second = aPair.first.XYZ() + aDir.XYZ();
6146 aSegments->AddVertex (aPair.first);
6147 aSegments->AddVertex (aPair.second);
6148 Prs3d_Arrow::Draw (aPrsGroup, aPair.second, gp_Vec(aPair.first, aPair.second), aArrowAngle, aArrowLength);
6151 aPrsGroup->AddPrimitiveArray (aSegments);
6157 //=======================================================================
6158 //function : VNormals
6159 //purpose : Displays/Hides normals calculated on shape geometry or retrieved from triangulation
6160 //=======================================================================
6161 static int VNormals (Draw_Interpretor& theDI,
6162 Standard_Integer theArgNum,
6163 const char** theArgs)
6165 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6166 if (aContext.IsNull())
6168 std::cout << "Error: no view available, call 'vinit' before!\n";
6171 else if (theArgNum < 2)
6173 std::cout << "Error: wrong number of arguments! See usage:\n";
6174 theDI.PrintHelp (theArgs[0]);
6178 Standard_Integer anArgIter = 1;
6179 Standard_CString aShapeName = theArgs[anArgIter++];
6180 TopoDS_Shape aShape = DBRep::Get (aShapeName);
6181 Standard_Boolean isOn = Standard_True;
6182 if (aShape.IsNull())
6184 std::cout << "Error: shape with name '" << aShapeName << "' is not found\n";
6188 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6189 Handle(MyShapeWithNormals) aShapePrs;
6190 if (aMap.IsBound2 (aShapeName))
6192 aShapePrs = Handle(MyShapeWithNormals)::DownCast (aMap.Find2 (aShapeName));
6195 Standard_Boolean isUseMesh = Standard_False;
6196 Standard_Real aLength = 10.0;
6197 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
6198 Standard_Boolean isOriented = Standard_False;
6199 for (; anArgIter < theArgNum; ++anArgIter)
6201 TCollection_AsciiString aParam (theArgs[anArgIter]);
6204 && ViewerTest::ParseOnOff (aParam.ToCString(), isOn))
6208 else if (aParam == "-usemesh"
6209 || aParam == "-mesh")
6211 isUseMesh = Standard_True;
6213 else if (aParam == "-length"
6214 || aParam == "-len")
6217 aLength = anArgIter < theArgNum ? Draw::Atof (theArgs[anArgIter]) : 0.0;
6218 if (Abs (aLength) <= gp::Resolution())
6220 std::cout << "Syntax error: length should not be zero\n";
6224 else if (aParam == "-orient"
6225 || aParam == "-oriented")
6227 isOriented = Standard_True;
6228 if (anArgIter + 1 < theArgNum
6229 && ViewerTest::ParseOnOff (theArgs[anArgIter + 1], isOriented))
6234 else if (aParam == "-nbalongu"
6235 || aParam == "-nbu")
6238 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6241 std::cout << "Syntax error: NbAlongU should be >=1\n";
6245 else if (aParam == "-nbalongv"
6246 || aParam == "-nbv")
6249 aNbAlongV = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6252 std::cout << "Syntax error: NbAlongV should be >=1\n";
6256 else if (aParam == "-nbalong"
6257 || aParam == "-nbuv")
6260 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6261 aNbAlongV = aNbAlongU;
6264 std::cout << "Syntax error: NbAlong should be >=1\n";
6270 std::cout << "Syntax error: unknwon argument '" << aParam << "'\n";
6277 if (aShapePrs.IsNull())
6279 aShapePrs = new MyShapeWithNormals (aShape);
6281 aShapePrs->ToUseMesh = isUseMesh;
6282 aShapePrs->ToOrient = isOriented;
6283 aShapePrs->NormalLength = aLength;
6284 aShapePrs->NbAlongU = aNbAlongU;
6285 aShapePrs->NbAlongV = aNbAlongV;
6286 VDisplayAISObject (aShapeName, aShapePrs);
6288 else if (!aShapePrs.IsNull())
6290 VDisplayAISObject (aShapeName, new AIS_Shape (aShape));
6296 //=======================================================================
6297 //function : ObjectsCommands
6299 //=======================================================================
6301 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
6303 const char *group ="AISObjects";
6305 theCommands.Add ("vtrihedron",
6306 "vtrihedron : vtrihedron name"
6307 "\n\t\t: [-dispMode {wireframe|shading} ]"
6308 "\n\t\t: [-origin x y z ]"
6309 "\n\t\t: [-zaxis u v w -xaxis u v w ]"
6310 "\n\t\t: [-drawAxes {X|Y|Z|XY|YZ|XZ|XYZ}]"
6311 "\n\t\t: [-hideLabels {on|off}]"
6312 "\n\t\t: [-hideArrows {on|off}]"
6313 "\n\t\t: [-label {XAxis|YAxis|ZAxis} value]"
6314 "\n\t\t: [-attribute {XAxisLength|YAxisLength|ZAxisLength"
6315 "\n\t\t: |TubeRadiusPercent|ConeRadiusPercent"
6316 "\n\t\t: |ConeLengthPercent|OriginRadiusPercent"
6317 "\n\t\t: |ShadingNumberOfFacettes} value]"
6318 "\n\t\t: [-color {Origin|XAxis|YAxis|ZAxis|XOYAxis|YOZAxis"
6319 "\n\t\t: |XOZAxis|Whole} {r g b | colorName}]"
6320 "\n\t\t: [-textColor {r g b | colorName}]"
6321 "\n\t\t: [-arrowColor {r g b | colorName}]"
6322 "\n\t\t: [-priority {Origin|XAxis|YAxis|ZAxis|XArrow"
6323 "\n\t\t: |YArrow|ZArrow|XOYAxis|YOZAxis"
6324 "\n\t\t: |XOZAxis|Whole} value]"
6326 "\n\t\t: Creates a new *AIS_Trihedron* object or changes parameters of "
6327 "\n\t\t: existing trihedron. If no argument is set,"
6328 "\n\t\t: the default trihedron (0XYZ) is created."
6329 "\n\t\t: -dispMode mode of visualization: wf - wireframe,"
6330 "\n\t\t: sh - shading."
6331 "\n\t\t: Default value is wireframe."
6332 "\n\t\t: -origin allows to set trihedron location."
6333 "\n\t\t: -zaxis/-xaxis allows to set trihedron X and Z"
6334 "\n\t\t: directions. The directions should"
6335 "\n\t\t: be orthogonal. Y direction is calculated."
6336 "\n\t\t: -drawAxes allows to set what axes are drawn in the"
6337 "\n\t\t: trihedron, default state is XYZ"
6338 "\n\t\t: -hideLabels allows to show/hide trihedron labels"
6339 "\n\t\t: -hideArrows allows to show/hide trihedron arrows"
6340 "\n\t\t: -label allows to change default X/Y/Z titles of axes"
6341 "\n\t\t: -attribute sets parameters of trihedron"
6342 "\n\t\t: -color sets color properties of parts of trihedron"
6343 "\n\t\t: -textColor sets color properties of trihedron labels"
6344 "\n\t\t: -arrowColor sets color properties of trihedron arrows"
6345 "\n\t\t: -priority allows to change default selection priority"
6346 "\n\t\t: of trihedron components",
6347 __FILE__,VTrihedron,group);
6349 theCommands.Add("vtri2d",
6351 "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.",
6352 __FILE__,VTrihedron2D ,group);
6354 theCommands.Add("vplanetri",
6356 "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default",
6357 __FILE__,VPlaneTrihedron ,group);
6359 theCommands.Add("vsize",
6360 "vsize : vsize [name(Default=Current)] [size(Default=100)] "
6361 "\n\t\t: Changes the size of a named or selected trihedron."
6362 "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done."
6363 "\n\t\t: If the value is not defined: it is set to 100 by default.",
6364 __FILE__,VSize,group);
6366 theCommands.Add("vaxis",
6367 "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]"
6368 "\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",
6369 __FILE__,VAxisBuilder,group);
6371 theCommands.Add("vaxispara",
6373 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.",
6374 __FILE__,VAxisBuilder,group);
6376 theCommands.Add("vaxisortho",
6378 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.",
6379 __FILE__,VAxisBuilder,group);
6381 theCommands.Add("vpoint",
6382 "vpoint PointName [Xa] [Ya] [Za] "
6383 "\n\t\t: Creates a point from coordinates. If the values are not defined,"
6384 "\n\t\t: a point is created by interactive selection of a vertice or an edge (in the center of the edge).",
6385 __FILE__,VPointBuilder,group);
6387 theCommands.Add("vplane",
6388 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]"
6389 "\n\t\t: Creates a plane from named or interactively selected entities."
6390 "\n\t\t: TypeOfSensitivity:"
6391 "\n\t\t: 0 - Interior"
6392 "\n\t\t: 1 - Boundary",
6393 __FILE__,VPlaneBuilder,group);
6395 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
6396 " vchangeplane <plane_name>"
6397 " [x=center_x y=center_y z=center_z]"
6398 " [dx=dir_x dy=dir_y dz=dir_z]"
6399 " [sx=size_x sy=size_y]"
6401 " - changes parameters of the plane:\n"
6402 " - x y z - center\n"
6403 " - dx dy dz - normal\n"
6404 " - sx sy - plane sizes\n"
6405 " - noupdate - do not update/redisplay the plane in context\n"
6406 " Please enter coordinates in format \"param=value\" in arbitrary order.",
6407 __FILE__, VChangePlane, group);
6409 theCommands.Add("vplanepara",
6410 "vplanepara PlaneName "
6411 "\n\t\t: Creates a plane from interactively selected vertex and face.",
6412 __FILE__,VPlaneBuilder,group);
6414 theCommands.Add("vplaneortho",
6415 "vplaneortho PlaneName "
6416 "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ",
6417 __FILE__,VPlaneBuilder,group);
6419 theCommands.Add("vline",
6420 "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] "
6421 "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ",
6422 __FILE__,VLineBuilder,group);
6424 theCommands.Add("vcircle",
6425 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]"
6426 "\n\t\t: Creates a circle from named or interactively selected entities."
6427 "\n\t\t: Parameter IsFilled is defined as 0 or 1.",
6428 __FILE__,VCircleBuilder,group);
6430 theCommands.Add ("vdrawtext",
6431 "vdrawtext name text"
6432 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6433 "\n\t\t: [-color {R G B|name}=yellow]"
6434 "\n\t\t: [-halign {left|center|right}=left]"
6435 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6436 "\n\t\t: [-angle angle=0]"
6437 "\n\t\t: [-zoom {0|1}=0]"
6438 "\n\t\t: [-height height=16]"
6439 "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]"
6440 "\n\t\t: [-font font=Times]"
6442 "\n\t\t: [-perspos {X Y Z}=0 0 0], where"
6443 "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window"
6444 "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..."
6445 "\n\t\t Z coordinate defines the gap from border of view window (except center position)."
6446 "\n\t\t: [-disptype {blend|decal|shadow|subtitle|dimension|normal}=normal}"
6447 "\n\t\t: [-subcolor {R G B|name}=white]"
6448 "\n\t\t: [-noupdate]"
6449 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]"
6450 "\n\t\t: [-flipping]"
6451 "\n\t\t: Display text label at specified position.",
6452 __FILE__, VDrawText, group);
6454 theCommands.Add("vdrawsphere",
6455 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
6456 __FILE__,VDrawSphere,group);
6458 theCommands.Add ("vlocation",
6461 "\n\t\t: [-copyFrom otherName]"
6462 "\n\t\t: [-translate X Y [Z]]"
6463 "\n\t\t: [-rotate x y z dx dy dz angle]"
6464 "\n\t\t: [-scale [X Y Z] scale]"
6465 "\n\t\t: [-mirror x y z dx dy dz]"
6466 "\n\t\t: [-setLocation X Y [Z]]"
6467 "\n\t\t: [-setRotation QX QY QZ QW]"
6468 "\n\t\t: [-setScale [X Y Z] scale]"
6469 "\n\t\t: [-inheritParentTrsf {on|off}]"
6470 "\n\t\t: Object local transformation management:"
6471 "\n\t\t: -reset reset transformation to identity"
6472 "\n\t\t: -translate translate object"
6473 "\n\t\t: -rotate applies rotation to local transformation"
6474 "\n\t\t: -scale applies scale to local transformation"
6475 "\n\t\t: -mirror applies mirror to local transformation"
6476 "\n\t\t: -setLocation assign object location"
6477 "\n\t\t: -setRotation assign object rotation (quaternion)"
6478 "\n\t\t: -setScale assign object scale factor"
6479 "\n\t\t: -inheritParentTrsf option to inherit parent"
6480 "\n\t\t: transformation or not (ON by default)",
6481 __FILE__, VSetLocation, group);
6482 theCommands.Add ("vsetlocation",
6483 "alias for vlocation",
6484 __FILE__, VSetLocation, group);
6485 theCommands.Add ("vchild",
6486 "vchild parent [-add] [-remove] [-ignoreParentTrsf {0|1}] child1 [child2] [...]"
6487 "\n\t\t: Command for testing low-level presentation connections."
6488 "\n\t\t: vconnect command should be used instead.",
6489 __FILE__, VChild, group);
6490 theCommands.Add("vparent",
6491 "vparent parent [-ignoreVisu]"
6492 "\n\t\t: Command for testing object properties as parent in the hierarchy."
6493 "\n\t\t: Arguments:"
6494 "\n\t\t: -ignoreVisu do not propagate the visual state (display/erase/color) to children objects",
6495 __FILE__, VParent, group);
6496 theCommands.Add ("vcomputehlr",
6497 "vcomputehlr shapeInput hlrResult [-algoType {algo|polyAlgo}=polyAlgo]"
6498 "\n\t\t: [eyeX eyeY eyeZ dirX dirY dirZ upX upY upZ]"
6499 "\n\t\t: [-showTangentEdges {on|off}=off] [-nbIsolines N=0] [-showHiddenEdges {on|off}=off]"
6500 "\n\t\t: Arguments:"
6501 "\n\t\t: shapeInput - name of the initial shape"
6502 "\n\t\t: hlrResult - result HLR object from initial shape"
6503 "\n\t\t: eye, dir are eye position and look direction"
6504 "\n\t\t: up is the look up direction vector"
6505 "\n\t\t: -algoType HLR algorithm to use"
6506 "\n\t\t: -showTangentEdges include tangent edges"
6507 "\n\t\t: -nbIsolines include isolines"
6508 "\n\t\t: -showHiddenEdges include hidden edges"
6509 "\n\t\t: Use vtop to see projected HLR shape.",
6510 __FILE__, VComputeHLR, group);
6512 theCommands.Add("vdrawparray",
6513 "vdrawparray name TypeOfArray={points|segments|polylines|triangles"
6514 "\n\t\t: |trianglefans|trianglestrips|quads|quadstrips|polygons}"
6515 "\n\t\t: [-deinterleaved|-mutable]"
6516 "\n\t\t: [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [texel={'t' tx ty}]]"
6517 "\n\t\t: [bound= {'b' nbVertices [bound_color={'c' r g b}]]"
6518 "\n\t\t: [edge= {'e' vertexId]"
6519 "\n\t\t: [-shape shapeName] [-patch]"
6520 "\n\t\t: Commands create an Interactive Object for specified Primitive Array definition (Graphic3d_ArrayOfPrimitives)"
6521 "\n\t\t: with the main purpose is covering various combinations by tests",
6522 __FILE__,VDrawPArray,group);
6524 theCommands.Add("vconnect",
6525 "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]"
6526 "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.",
6527 __FILE__, VConnect, group);
6529 theCommands.Add("vconnectto",
6530 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
6531 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6532 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
6533 __FILE__, VConnectTo,group);
6535 theCommands.Add("vdisconnect",
6536 "vdisconnect assembly_name (object_name | object_number | 'all')"
6537 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6538 __FILE__,VDisconnect,group);
6540 theCommands.Add("vaddconnected",
6541 "vaddconnected assembly_name object_name"
6542 "Adds object to assembly.",
6543 __FILE__,VAddConnected,group);
6545 theCommands.Add("vlistconnected",
6546 "vlistconnected assembly_name"
6547 "Lists objects in assembly.",
6548 __FILE__,VListConnected,group);
6551 theCommands.Add("vselmode",
6552 "vselmode [object] selectionMode {on|off}"
6553 "\n\t\t: [{-add|-set|-globalOrLocal}=-globalOrLocal]"
6554 "\n\t\t: Switches selection mode for the specified object or for all objects in context."
6555 "\n\t\t: Selection mode is either an integer number specific to Interactive Object,"
6556 "\n\t\t: or sub-shape type in case of AIS_Shape:"
6557 "\n\t\t: Shape, Vertex, Edge, Wire, Face, Shell, Solid, CompSolid, Compound"
6558 "\n\t\t: The integer mode 0 (Shape in case of AIS_Shape) is reserved for selecting object as whole."
6559 "\n\t\t: Additional options:"
6560 "\n\t\t: -add already activated selection modes will be left activated"
6561 "\n\t\t: -set already activated selection modes will be deactivated"
6562 "\n\t\t: -globalOrLocal (default) if new mode is Global selection mode,"
6563 "\n\t\t: then active local selection modes will be deactivated"
6564 "\n\t\t: and the samthen active local selection modes will be deactivated",
6565 __FILE__, VSetSelectionMode, group);
6567 theCommands.Add("vselnext",
6568 "vselnext : hilight next detected",
6569 __FILE__, VSelectionNext, group);
6571 theCommands.Add("vselprev",
6572 "vselnext : hilight previous detected",
6573 __FILE__, VSelectionPrevious, group);
6575 theCommands.Add("vtriangle",
6576 "vtriangle Name PointName PointName PointName"
6577 "\n\t\t: Creates and displays a filled triangle from named points.",
6578 __FILE__, VTriangle,group);
6580 theCommands.Add("vsegment",
6581 "vsegment Name PointName PointName"
6582 "\n\t\t: Creates and displays a segment from named points.",
6583 __FILE__, VTriangle,group);
6585 theCommands.Add("vobjzlayer",
6586 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6587 __FILE__, VObjZLayer, group);
6589 theCommands.Add("vpolygonoffset",
6590 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6591 __FILE__, VPolygonOffset, group);
6593 theCommands.Add ("vmarkerstest",
6594 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6595 __FILE__, VMarkersTest, group);
6597 theCommands.Add ("text2brep",
6598 "text2brep: name text"
6599 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6600 "\n\t\t: [-halign {left|center|right}=left]"
6601 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6602 "\n\t\t: [-height height=16]"
6603 "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]"
6604 "\n\t\t: [-font font=Courier] [-strict {strict|aliases|any}=any]"
6605 "\n\t\t: [-composite {on|off}=off]"
6606 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]",
6607 __FILE__, TextToBRep, group);
6608 theCommands.Add ("vfont",
6609 "vfont [-add pathToFont [fontName] [regular,bold,italic,boldItalic=undefined] [singleStroke]]"
6610 "\n\t\t: [-strict {any|aliases|strict}] [-find fontName [regular,bold,italic,boldItalic=undefined]] [-verbose {on|off}]"
6611 "\n\t\t: [-unicodeFallback {on|off}]"
6612 "\n\t\t: [-clear] [-init]",
6613 __FILE__, VFont, group);
6615 theCommands.Add ("vvertexmode",
6616 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6617 "vvertexmode - prints the default vertex draw mode\n"
6618 "vvertexmode name - prints the vertex draw mode of the given object\n"
6619 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6620 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6621 __FILE__, VVertexMode, group);
6623 theCommands.Add ("vpointcloud",
6624 "vpointcloud name shape [-randColor] [-normals] [-noNormals] [-uv]"
6625 "\n\t\t: Create an interactive object for arbitary set of points"
6626 "\n\t\t: from triangulated shape."
6628 "vpointcloud name x y z r npts {surface|volume}\n"
6629 " ... [-randColor] [-normals] [-noNormals] [-uv]"
6630 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6631 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6633 "\n\t\t: Additional options:"
6634 "\n\t\t: -randColor - generate random color per point"
6635 "\n\t\t: -normals - generate normal per point (default)"
6636 "\n\t\t: -noNormals - do not generate normal per point"
6638 __FILE__, VPointCloud, group);
6640 theCommands.Add("vpriority",
6641 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",
6645 theCommands.Add ("vnormals",
6647 "vnormals Shape [{on|off}=on] [-length {10}] [-nbAlongU {1}] [-nbAlongV {1}] [-nbAlong {1}]"
6648 "\n\t\t: [-useMesh] [-oriented {0}1}=0]"
6649 "\n\t\t: Displays/Hides normals calculated on shape geometry or retrieved from triangulation",
6650 __FILE__, VNormals, group);