1 // Created on: 1998-11-12
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <ViewerTest.hxx>
19 #include <AIS_PlaneTrihedron.hxx>
21 #include <Quantity_NameOfColor.hxx>
22 #include <Draw_Interpretor.hxx>
24 #include <Draw_Appli.hxx>
26 #include <DBRep_DrawableShape.hxx>
28 #include <Font_BRepFont.hxx>
29 #include <Font_BRepTextBuilder.hxx>
30 #include <Font_FontMgr.hxx>
32 #include <NCollection_List.hxx>
34 #include <OSD_Chronometer.hxx>
35 #include <TCollection_AsciiString.hxx>
36 #include <V3d_Viewer.hxx>
37 #include <V3d_View.hxx>
40 #include <AIS_Shape.hxx>
41 #include <AIS_DisplayMode.hxx>
42 #include <AIS_PointCloud.hxx>
43 #include <TColStd_MapOfInteger.hxx>
44 #include <AIS_MapOfInteractive.hxx>
45 #include <ViewerTest_AutoUpdater.hxx>
46 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
47 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
48 #include <ViewerTest_EventManager.hxx>
50 #include <TopoDS_Solid.hxx>
51 #include <BRepTools.hxx>
52 #include <BRep_Builder.hxx>
53 #include <TopAbs_ShapeEnum.hxx>
56 #include <BRep_Tool.hxx>
57 #include <TopExp_Explorer.hxx>
59 #include <BRepAdaptor_Curve.hxx>
60 #include <BRepAdaptor_Surface.hxx>
64 #include <TopoDS_Vertex.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Face.hxx>
68 #include <Draw_Window.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
70 #include <AIS_ListOfInteractive.hxx>
71 #include <AIS_ColoredShape.hxx>
72 #include <AIS_DisplayMode.hxx>
73 #include <AIS_Shape.hxx>
75 #include <AIS_InteractiveContext.hxx>
76 #include <Geom_Plane.hxx>
78 #include <TCollection_ExtendedString.hxx>
79 #include <TCollection_HAsciiString.hxx>
80 #include <GC_MakePlane.hxx>
81 #include <gp_Circ.hxx>
82 #include <AIS_Axis.hxx>
83 #include <Geom_Axis2Placement.hxx>
84 #include <Geom_Axis1Placement.hxx>
85 #include <AIS_Trihedron.hxx>
86 #include <AIS_Axis.hxx>
87 #include <gp_Trsf.hxx>
88 #include <gp_Quaternion.hxx>
89 #include <TopLoc_Location.hxx>
91 #include <HLRAlgo_Projector.hxx>
92 #include <HLRBRep_Algo.hxx>
93 #include <HLRBRep_PolyAlgo.hxx>
94 #include <HLRBRep_PolyHLRToShape.hxx>
95 #include <HLRBRep_HLRToShape.hxx>
96 #include <Aspect_Window.hxx>
98 #include <Graphic3d_ArrayOfPoints.hxx>
99 #include <Graphic3d_ArrayOfSegments.hxx>
100 #include <Graphic3d_ArrayOfPolylines.hxx>
101 #include <Graphic3d_ArrayOfTriangles.hxx>
102 #include <Graphic3d_ArrayOfTriangleFans.hxx>
103 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
104 #include <Graphic3d_ArrayOfQuadrangles.hxx>
105 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
106 #include <Graphic3d_ArrayOfPolygons.hxx>
107 #include <Graphic3d_AttribBuffer.hxx>
108 #include <Graphic3d_AspectMarker3d.hxx>
109 #include <Graphic3d_Group.hxx>
110 #include <Standard_Real.hxx>
112 #include <AIS_Circle.hxx>
113 #include <BRepBuilderAPI_MakeEdge.hxx>
114 #include <BRepBuilderAPI_MakeFace.hxx>
115 #include <BRepBuilderAPI_MakeWire.hxx>
116 #include <Geom_Circle.hxx>
117 #include <GC_MakeCircle.hxx>
118 #include <Select3D_SensitiveCircle.hxx>
119 #include <SelectMgr_EntityOwner.hxx>
120 #include <SelectMgr_Selection.hxx>
121 #include <StdFail_NotDone.hxx>
122 #include <StdPrs_ShadedShape.hxx>
123 #include <TopoDS_Wire.hxx>
125 #include <AIS_MultipleConnectedInteractive.hxx>
126 #include <AIS_ConnectedInteractive.hxx>
127 #include <AIS_TextLabel.hxx>
128 #include <TopLoc_Location.hxx>
129 #include <TColStd_ListOfInteger.hxx>
130 #include <TColStd_ListIteratorOfListOfInteger.hxx>
132 #include <Select3D_SensitiveSegment.hxx>
133 #include <Select3D_SensitivePrimitiveArray.hxx>
134 #include <Select3D_SensitiveTriangle.hxx>
135 #include <Select3D_SensitiveCurve.hxx>
136 #include <Select3D_SensitivePoint.hxx>
137 #include <BRepAdaptor_Curve.hxx>
138 #include <StdPrs_Curve.hxx>
140 #include <BRepExtrema_ExtPC.hxx>
141 #include <BRepExtrema_ExtPF.hxx>
143 #include <Prs3d_Arrow.hxx>
144 #include <Prs3d_ArrowAspect.hxx>
145 #include <Prs3d_DatumAttribute.hxx>
146 #include <Prs3d_DatumAspect.hxx>
147 #include <Prs3d_Drawer.hxx>
148 #include <Prs3d_VertexDrawMode.hxx>
149 #include <Prs3d_LineAspect.hxx>
150 #include <Prs3d_PointAspect.hxx>
151 #include <Prs3d_Presentation.hxx>
152 #include <Prs3d_TextAspect.hxx>
154 #include <Image_AlienPixMap.hxx>
155 #include <TColStd_HArray1OfAsciiString.hxx>
156 #include <TColStd_HSequenceOfAsciiString.hxx>
158 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
159 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
160 const Handle(AIS_InteractiveObject)& theAISObj,
161 Standard_Boolean theReplaceIfExists = Standard_True);
162 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
163 extern Handle(AIS_InteractiveContext)& TheAISContext();
167 static bool convertToColor (const Handle(TColStd_HSequenceOfAsciiString)& theColorValues,
168 Quantity_Color& theColor)
170 const char* anArgs[3] =
172 theColorValues->Size() >= 1 ? theColorValues->Value (1).ToCString() : "",
173 theColorValues->Size() >= 2 ? theColorValues->Value (2).ToCString() : "",
174 theColorValues->Size() >= 3 ? theColorValues->Value (3).ToCString() : ""
176 return ViewerTest::ParseColor (theColorValues->Size(), anArgs, theColor) != 0;
179 static bool convertToDatumPart (const TCollection_AsciiString& theValue,
180 Prs3d_DatumParts& theDatumPart)
182 TCollection_AsciiString aValue = theValue;
184 if (aValue == "origin") theDatumPart = Prs3d_DP_Origin;
185 else if (aValue == "xaxis") theDatumPart = Prs3d_DP_XAxis;
186 else if (aValue == "yaxis") theDatumPart = Prs3d_DP_YAxis;
187 else if (aValue == "zaxis") theDatumPart = Prs3d_DP_ZAxis;
188 else if (aValue == "xarrow") theDatumPart = Prs3d_DP_XArrow;
189 else if (aValue == "yarrow") theDatumPart = Prs3d_DP_YArrow;
190 else if (aValue == "zarrow") theDatumPart = Prs3d_DP_ZArrow;
191 else if (aValue == "xoyaxis") theDatumPart = Prs3d_DP_XOYAxis;
192 else if (aValue == "yozaxis") theDatumPart = Prs3d_DP_YOZAxis;
193 else if (aValue == "xozaxis") theDatumPart = Prs3d_DP_XOZAxis;
194 else if (aValue == "whole") theDatumPart = Prs3d_DP_None;
202 static void convertToDatumParts (const TCollection_AsciiString& theValue,
203 NCollection_List<Prs3d_DatumParts>& theParts)
205 TCollection_AsciiString aValue = theValue;
206 const Standard_Integer aSplitPos = theValue.Search ("|");
207 Prs3d_DatumParts aPart = Prs3d_DP_None;
210 convertToDatumParts (theValue.SubString (aSplitPos + 1, theValue.Length()), theParts);
211 if (aSplitPos == 1) // first symbol
215 aValue = theValue.SubString (1, aSplitPos - 1);
217 if (convertToDatumPart (aValue, aPart))
219 theParts.Append (aPart);
223 static bool convertToDatumAttribute (const TCollection_AsciiString& theValue,
224 Prs3d_DatumAttribute& theAttribute)
226 TCollection_AsciiString aValue = theValue;
228 if (aValue == "xaxislength") theAttribute = Prs3d_DA_XAxisLength;
229 else if (aValue == "yaxislength") theAttribute = Prs3d_DA_YAxisLength;
230 else if (aValue == "zaxislength") theAttribute = Prs3d_DA_ZAxisLength;
231 else if (aValue == "tuberadiuspercent") theAttribute = Prs3d_DP_ShadingTubeRadiusPercent;
232 else if (aValue == "coneradiuspercent") theAttribute = Prs3d_DP_ShadingConeRadiusPercent;
233 else if (aValue == "conelengthpercent") theAttribute = Prs3d_DP_ShadingConeLengthPercent;
234 else if (aValue == "originradiuspercent") theAttribute = Prs3d_DP_ShadingOriginRadiusPercent;
235 else if (aValue == "shadingnumberoffacettes") theAttribute = Prs3d_DP_ShadingNumberOfFacettes;
241 static void convertToDatumAttributes (const TCollection_AsciiString& theValue,
242 NCollection_List<Prs3d_DatumAttribute>& theAttributes)
244 TCollection_AsciiString aValue = theValue;
245 const Standard_Integer aSplitPos = theValue.Search ("|");
246 Prs3d_DatumAttribute anAttribute = Prs3d_DA_XAxisLength;
249 convertToDatumAttributes (theValue.SubString (aSplitPos + 1, theValue.Length()), theAttributes);
250 if (aSplitPos == 1) // first symbol
254 aValue = theValue.SubString (1, aSplitPos - 1);
256 if (convertToDatumAttribute (aValue, anAttribute))
258 theAttributes.Append (anAttribute);
262 static bool convertToDatumAxes (const TCollection_AsciiString& theValue,
263 Prs3d_DatumAxes& theDatumAxes)
265 TCollection_AsciiString aValue = theValue;
267 if (aValue == "x") theDatumAxes = Prs3d_DA_XAxis;
268 else if (aValue == "y") theDatumAxes = Prs3d_DA_YAxis;
269 else if (aValue == "z") theDatumAxes = Prs3d_DA_ZAxis;
270 else if (aValue == "xy") theDatumAxes = Prs3d_DA_XYAxis;
271 else if (aValue == "zy") theDatumAxes = Prs3d_DA_YZAxis;
272 else if (aValue == "xz") theDatumAxes = Prs3d_DA_XZAxis;
273 else if (aValue == "xyz") theDatumAxes = Prs3d_DA_XYZAxis;
281 static Standard_Boolean setTrihedronParams (Standard_Integer theArgsNb,
282 const char** theArgVec,
283 Handle(AIS_Trihedron) theTrihedron)
285 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
286 TCollection_AsciiString aParseKey;
287 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
289 TCollection_AsciiString anArg (theArgVec [anArgIt]);
290 if (anArg.Value (1) == '-'
291 && !anArg.IsRealValue())
294 aParseKey.Remove (1);
295 aParseKey.LowerCase();
296 std::string aKey = aParseKey.ToCString();
297 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString());
301 if (aParseKey.IsEmpty())
306 aMapOfArgs (aParseKey)->Append (anArg);
310 if ((aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis"))
311 || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")))
313 std::cout << "Syntax error: -xaxis and -zaxis parameters are to set together.\n";
314 return Standard_False;
317 Handle(TColStd_HSequenceOfAsciiString) aValues;
318 Handle(Geom_Axis2Placement) aComponent = theTrihedron->Component();
319 if (aMapOfArgs.Find ("origin", aValues))
321 aComponent->SetLocation (gp_Pnt (aValues->Value (1).RealValue(),
322 aValues->Value (2).RealValue(),
323 aValues->Value (3).RealValue()));
325 Handle(TColStd_HSequenceOfAsciiString) aXValues, aZValues;
326 if (aMapOfArgs.Find ("xaxis", aXValues) && aMapOfArgs.Find ("zaxis", aZValues))
328 gp_Dir aXDir (aXValues->Value (1).RealValue(),
329 aXValues->Value (2).RealValue(),
330 aXValues->Value (3).RealValue());
332 gp_Dir aZDir (aZValues->Value (1).RealValue(),
333 aZValues->Value (2).RealValue(),
334 aZValues->Value (3).RealValue());
336 if (!aZDir.IsNormal (aXDir, M_PI / 180.0))
338 std::cout << "Syntax error - parameters 'xaxis' and 'zaxis' are not applied as VectorX is not normal to VectorZ\n";
339 return Standard_False;
342 aComponent->SetAx2 (gp_Ax2 (aComponent->Location(), aZDir, aXDir));
345 if (aMapOfArgs.Find ("dispmode", aValues))
347 TCollection_AsciiString aValue (aValues->Value (1));
348 bool isWireframe = true;
349 if (aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
351 theTrihedron->SetDatumDisplayMode (isWireframe ? Prs3d_DM_WireFrame
355 if (aMapOfArgs.Find ("hidelabels", aValues))
357 Standard_Boolean toHideLabels = Standard_True;
358 if (aValues->Size() == 1)
360 ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideLabels);
362 else if (aValues->Size() != 0)
364 std::cout << "Syntax error: -hidelabels expects parameter 'on' or 'off' after.\n";
365 return Standard_False;
368 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
370 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
372 theTrihedron->Attributes()->DatumAspect()->SetDrawLabels (!toHideLabels);
375 if (aMapOfArgs.Find ("hidearrows", aValues))
377 Standard_Boolean toHideArrows = Standard_True;
378 if (aValues->Size() == 1)
380 ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideArrows);
382 else if (aValues->Size() != 0)
384 std::cout << "Syntax error: -hidearrows expects parameter 'on' or 'off' after.\n";
385 return Standard_False;
388 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
390 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
392 theTrihedron->Attributes()->DatumAspect()->SetDrawArrows (!toHideArrows);
395 if (aMapOfArgs.Find ("color", aValues))
397 NCollection_List<Prs3d_DatumParts> aParts;
398 if (aValues->Size() < 2)
400 std::cout << "Syntax error: -color wrong parameters.\n";
401 return Standard_False;
404 convertToDatumParts (aValues->Value(1), aParts);
405 aValues->Remove (1); // datum part is processed
406 Quantity_Color aColor;
407 if (!convertToColor (aValues, aColor))
409 std::cout << "Syntax error: -color wrong parameters.\n";
410 return Standard_False;
413 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (aParts); anIterator.More(); anIterator.Next())
415 Prs3d_DatumParts aDatumPart = anIterator.Value();
416 if (aDatumPart == Prs3d_DP_None)
418 theTrihedron->SetColor (aColor);
422 theTrihedron->SetDatumPartColor (aDatumPart, aColor);
427 if (aMapOfArgs.Find ("textcolor", aValues))
429 Quantity_Color aColor;
430 if (!convertToColor (aValues, aColor))
432 std::cout << "Syntax error: -textcolor wrong parameters.\n";
433 return Standard_False;
435 theTrihedron->SetTextColor (aColor);
438 if (aMapOfArgs.Find ("arrowcolor", aValues))
440 Quantity_Color aColor;
441 if (!convertToColor (aValues, aColor))
443 std::cout << "Syntax error: -arrowcolor wrong parameters.\n";
444 return Standard_False;
446 theTrihedron->SetArrowColor (aColor);
449 if (aMapOfArgs.Find ("attribute", aValues))
451 NCollection_List<Prs3d_DatumAttribute> anAttributes;
452 if (aValues->Size() != 2)
454 std::cout << "Syntax error: -attribute wrong parameters.\n";
455 return Standard_False;
458 convertToDatumAttributes (aValues->Value (1), anAttributes);
459 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
460 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
461 for (NCollection_List<Prs3d_DatumAttribute>::Iterator anIterator (anAttributes); anIterator.More(); anIterator.Next())
463 theTrihedron->Attributes()->DatumAspect()->SetAttribute (anIterator.Value(), aValues->Value (2).RealValue());
467 if (aMapOfArgs.Find ("priority", aValues))
469 Prs3d_DatumParts aDatumPart;
470 if (aValues->Size() < 2
471 || !convertToDatumPart (aValues->Value (1), aDatumPart))
473 std::cout << "Syntax error: -priority wrong parameters.\n";
474 return Standard_False;
476 theTrihedron->SetSelectionPriority (aDatumPart, aValues->Value (2).IntegerValue());
479 if (aMapOfArgs.Find ("labels", aValues)
480 || aMapOfArgs.Find ("label", aValues))
482 Prs3d_DatumParts aDatumPart = Prs3d_DP_None;
483 if (aValues->Size() >= 2
484 && convertToDatumPart(aValues->Value(1), aDatumPart)
485 && aDatumPart >= Prs3d_DP_XAxis
486 && aDatumPart <= Prs3d_DP_ZAxis) // labels are set to axes only
488 theTrihedron->SetLabel (aDatumPart, aValues->Value (2));
492 std::cout << "Syntax error: -labels wrong parameters.\n";
493 return Standard_False;
497 if (aMapOfArgs.Find ("drawaxes", aValues))
499 Prs3d_DatumAxes aDatumAxes = Prs3d_DA_XAxis;
500 if (aValues->Size() < 1
501 || !convertToDatumAxes (aValues->Value (1), aDatumAxes))
503 std::cout << "Syntax error: -drawaxes wrong parameters.\n";
504 return Standard_False;
506 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
507 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
508 theTrihedron->Attributes()->DatumAspect()->SetDrawDatumAxes (aDatumAxes);
510 return Standard_True;
513 //! Auxiliary function to parse font aspect style argument
514 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
515 Font_FontAspect& theAspect)
517 if (theArg == "regular"
518 || *theArg.ToCString() == 'r')
520 theAspect = Font_FA_Regular;
521 return Standard_True;
523 else if (theArg == "bolditalic"
524 || theArg == "bold-italic"
525 || theArg == "italic-bold"
526 || theArg == "italicbold")
528 theAspect = Font_FA_BoldItalic;
529 return Standard_True;
531 else if (theArg == "bold"
532 || *theArg.ToCString() == 'b')
534 theAspect = Font_FA_Bold;
535 return Standard_True;
537 else if (theArg == "italic"
538 || *theArg.ToCString() == 'i')
540 theAspect = Font_FA_Italic;
541 return Standard_True;
543 return Standard_False;
547 //==============================================================================
548 //function : Vtrihedron 2d
549 //purpose : Create a plane with a 2D trihedron from a faceselection
550 //Draw arg : vtri2d name
551 //==============================================================================
552 static int VTrihedron2D (Draw_Interpretor& /*theDI*/,
553 Standard_Integer theArgsNum,
554 const char** theArgVec)
558 std::cerr << theArgVec[0]<< " error.\n";
562 TopTools_ListOfShape aShapes;
563 ViewerTest::GetSelectedShapes (aShapes);
565 if (aShapes.Extent() != 1)
567 std::cerr << "Error: wrong number of selected shapes.\n";
571 const TopoDS_Shape& aShape = aShapes.First();
573 TopoDS_Face aFace = TopoDS::Face (aShape);
574 TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE);
575 TopoDS_Edge anEdge0 = TopoDS::Edge (aFaceExp.Current());
581 TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() );
582 BRepAdaptor_Curve aCurve0 (anEdge0);
583 BRepAdaptor_Curve aCurve1 (anEdge1);
584 A = aCurve1.Value (0.1);
585 B = aCurve1.Value (0.9);
586 C = aCurve0.Value (0.5);
590 BRepAdaptor_Curve aCurve0 (anEdge0);
591 A = aCurve0.Value (0.1);
592 B = aCurve0.Value (0.9);
593 C = aCurve0.Value (0.5);
596 GC_MakePlane aMkPlane (A,B,C);
598 Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value());
599 TCollection_AsciiString aName (theArgVec[1]);
601 VDisplayAISObject (aName, anAISPlaneTri);
606 //=======================================================================
607 //function : VTrihedron
609 //=======================================================================
610 static int VTrihedron (Draw_Interpretor& ,
611 Standard_Integer theArgsNb,
612 const char** theArgVec)
616 std::cout << "Syntax error: the wrong number of input parameters.\n";
620 TCollection_AsciiString aName (theArgVec[1]);
621 gp_Pln aWorkingPlane;
622 Standard_Boolean toUpdate = Standard_True;
624 NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
625 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
627 Handle(AIS_Trihedron) aTrihedron;
628 Handle(AIS_InteractiveObject) anObject;
629 if (GetMapOfAIS().Find2 (aName, anObject))
631 aTrihedron = Handle(AIS_Trihedron)::DownCast (anObject);
632 if (aTrihedron.IsNull())
634 std::cout << "Syntax error: no trihedron with this name.\n";
640 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (gp_Pnt (0.0, 0.0, 0.0),
642 aTrihedron = new AIS_Trihedron (aPlacement);
645 if (!setTrihedronParams (theArgsNb, theArgVec, aTrihedron))
650 // Redisplay a dimension after parameter changing.
651 if (ViewerTest::GetAISContext()->IsDisplayed (aTrihedron))
653 ViewerTest::GetAISContext()->Redisplay (aTrihedron, toUpdate);
657 VDisplayAISObject (theArgVec[1], aTrihedron);
663 //==============================================================================
666 //purpose : Change the size of a named or selected trihedron
667 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
668 // if no value, the value is set at 100 by default
669 //Draw arg : vsize [name] [size]
670 //==============================================================================
672 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
675 // Declaration de booleens
676 Standard_Boolean ThereIsName;
677 Standard_Boolean ThereIsCurrent;
679 Standard_Boolean hascol;
681 Quantity_Color col = Quantity_NOC_BLACK;
683 // Verification des arguments
684 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;}
686 // Verification du nombre d'arguments
687 if (argc==1) {ThereIsName=Standard_False;value=100;}
688 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
689 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
691 // On set le booleen ThereIsCurrent
692 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
693 else {ThereIsCurrent=Standard_False;}
697 //===============================================================
698 // Il n'y a pas de nom mais des objets selectionnes
699 //===============================================================
700 if (!ThereIsName && ThereIsCurrent)
703 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
706 while ( it.More() ) {
708 Handle(AIS_InteractiveObject) aShape = it.Key1();
710 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
713 // On verifie que l'AIS InteraciveObject selectionne est bien
715 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
717 if (aShape->HasColor())
719 hascol = Standard_True;
721 // On recupere la couleur de aShape
726 hascol = Standard_False;
729 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
730 // pour lui appliquer la methode SetSize()
731 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
733 // C'est bien un triedre,on chage sa valeur!
734 aTrihedron->SetSize(value);
736 // On donne la couleur au Trihedron
737 if(hascol) aTrihedron->SetColor(col);
738 else aTrihedron->UnsetColor();
741 // The trihedron hasn't be errased from the map
742 // so you just have to redisplay it
743 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
752 TheAISContext() ->UpdateCurrentViewer();
755 //===============================================================
756 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
757 //===============================================================
761 //===============================================================
762 // Il y a un nom de triedre passe en argument
763 //===============================================================
765 TCollection_AsciiString name=argv[1];
767 // on verifie que ce nom correspond bien a une shape
768 Handle(AIS_InteractiveObject) aShape;
769 if (GetMapOfAIS().Find2(name, aShape))
771 // On verifie que l'AIS InteraciveObject est bien
773 if (!aShape.IsNull() &&
774 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
776 if (aShape->HasColor())
778 hascol=Standard_True;
780 // On recupere la couleur de aShape
785 hascol = Standard_False;
788 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
789 // pour lui appliquer la methode SetSize()
790 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
792 // C'est bien un triedre,on chage sa valeur
793 aTrihedron->SetSize(value);
795 // On donne la couleur au Trihedron
796 if(hascol) aTrihedron->SetColor(col);
797 else aTrihedron->UnsetColor();
799 // The trihedron hasn't be errased from the map
800 // so you just have to redisplay it
801 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
803 TheAISContext() ->UpdateCurrentViewer();
811 //==============================================================================
813 //==============================================================================
814 //function : VPlaneTrihedron
815 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
816 //Draw arg : vplanetri name
817 //==============================================================================
818 #include <AIS_Plane.hxx>
822 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
825 // Verification des arguments
826 if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
828 if (TheAISContext()->NbSelected() != 1)
830 std::cerr << "Error: Wrong number of selected shapes.\n";
834 TheAISContext()->InitSelected();
835 Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive();
836 Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest);
839 std::cerr << "Error: Selected shape is not a plane.\n";
843 VDisplayAISObject (argv[1], aPlane);
850 //==============================================================================
851 // Fonction First click 2de click
853 // vaxis vertex vertex
855 // vaxispara edge vertex
856 // vaxisortho edge Vertex
857 // vaxisinter Face Face
858 //==============================================================================
860 //==============================================================================
861 //function : VAxisBuilder
863 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
864 //==============================================================================
865 #include <TopoDS_Edge.hxx>
866 #include <TopoDS_Vertex.hxx>
867 #include <TopExp.hxx>
868 #include <Geom_Line.hxx>
870 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
873 Standard_Boolean HasArg;
874 TCollection_AsciiString name;
877 if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
878 if (argc==8) HasArg=Standard_True;
879 else HasArg=Standard_False;
883 TopTools_ListOfShape aShapes;
884 ViewerTest::GetSelectedShapes (aShapes);
886 // Cas ou il y a des arguments
887 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
889 Standard_Real coord[6];
890 for(Standard_Integer i=0;i<=5;i++){
891 coord[i]=Draw::Atof(argv[2+i]);
893 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
895 gp_Vec myVect (p1,p2);
896 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
897 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
898 GetMapOfAIS().Bind (TheAxis,name);
899 TheAISContext()->Display(TheAxis, Standard_True);
905 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
906 if ( !strcasecmp(argv[0], "vaxis")) {
907 if (aShapes.Extent() != 2 && aShapes.Extent() != 1)
909 std::cerr << "Error: Wrong number of selected shapes.\n";
913 const TopoDS_Shape& aShapeA = aShapes.First();
914 if (aShapeA.ShapeType() == TopAbs_VERTEX)
916 if (aShapes.Extent() != 2)
918 std::cerr << "Error: Wron number of selected shapes.\n";
922 const TopoDS_Shape& aShapeB = aShapes.Last();
923 if (aShapeB.ShapeType() != TopAbs_VERTEX)
925 std::cerr << "Syntax error: You should select two vertices or one edge.\n";
929 // Construction de l'axe
930 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
931 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
934 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
935 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
936 GetMapOfAIS().Bind (TheAxis,name);
937 TheAISContext()->Display (TheAxis, Standard_True);
941 TopoDS_Edge ed =TopoDS::Edge (aShapeA);
943 TopExp::Vertices(ed,Va,Vb );
944 gp_Pnt A=BRep_Tool::Pnt(Va);
945 gp_Pnt B=BRep_Tool::Pnt(Vb);
948 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
949 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
950 GetMapOfAIS().Bind (TheAxis,name);
951 TheAISContext()->Display (TheAxis, Standard_True);
957 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
958 else if ( !strcasecmp(argv[0], "vaxispara"))
960 if (aShapes.Extent() != 2)
962 std::cerr << "Error: Wrong number of selected shapes.\n";
966 const TopoDS_Shape& aShapeA = aShapes.First();
967 const TopoDS_Shape& aShapeB = aShapes.Last();
968 if (!(aShapeA.ShapeType() == TopAbs_EDGE
969 && aShapeB.ShapeType() == TopAbs_VERTEX))
971 std::cerr << "Syntax error: You should select face and then vertex.\n";
975 TopoDS_Edge ed=TopoDS::Edge (aShapeA);
976 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
978 TopExp::Vertices(ed,Va,Vc );
979 gp_Pnt A=BRep_Tool::Pnt(Va);
980 gp_Pnt C=BRep_Tool::Pnt(Vc);
983 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
984 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
985 GetMapOfAIS().Bind (TheAxis,name);
986 TheAISContext()->Display (TheAxis, Standard_True);
990 // Fonction axisortho
993 if (aShapes.Extent() != 2)
995 std::cerr << "Error: Wrong number of selected shapes.\n";
999 const TopoDS_Shape& aShapeA = aShapes.First();
1000 const TopoDS_Shape& aShapeB = aShapes.Last();
1001 if (!(aShapeA.ShapeType() == TopAbs_EDGE
1002 && aShapeB.ShapeType() == TopAbs_VERTEX))
1004 std::cerr << "Syntax error: You should select face and then vertex.\n";
1008 // Construction de l'axe
1009 TopoDS_Edge ed=TopoDS::Edge(aShapeA) ;
1010 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) );
1011 TopoDS_Vertex Va,Vc;
1012 TopExp::Vertices(ed,Va,Vc );
1013 gp_Pnt A=BRep_Tool::Pnt(Va);
1014 gp_Pnt C=BRep_Tool::Pnt(Vc);
1015 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
1018 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1019 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1020 GetMapOfAIS().Bind (TheAxis,name);
1021 TheAISContext()->Display (TheAxis, Standard_True);
1030 //==============================================================================
1031 // Fonction First click Result
1033 // vpoint vertex AIS_Point=Vertex
1034 // edge AIS_Point=Middle of the edge
1035 //==============================================================================
1037 //==============================================================================
1038 //function : VPointBuilder
1039 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
1040 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
1041 //==============================================================================
1042 #include <TopoDS_Edge.hxx>
1043 #include <TopoDS_Vertex.hxx>
1044 #include <TopExp.hxx>
1045 #include <AIS_Point.hxx>
1046 #include <Geom_CartesianPoint.hxx>
1048 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1051 Standard_Boolean HasArg;
1052 TCollection_AsciiString name;
1055 if (argc<2 || argc>5 ) {di<<" Syntaxe error\n";return 1;}
1056 if (argc==5) HasArg=Standard_True;
1057 else HasArg=Standard_False;
1061 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
1063 Standard_Real thecoord[3];
1064 for(Standard_Integer i=0;i<=2;i++)
1065 thecoord[i]=Draw::Atof(argv[2+i]);
1066 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
1067 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
1068 GetMapOfAIS().Bind (myAISPoint,name);
1069 TheAISContext()->Display (myAISPoint, Standard_True);
1072 // Il n'a pas d'arguments
1075 TopTools_ListOfShape aShapes;
1076 ViewerTest::GetSelectedShapes (aShapes);
1078 if (aShapes.Extent() != 1)
1080 std::cerr << "Error: Wrong number of selected shapes.\n";
1081 std::cerr << "\tYou should select one edge or vertex.\n";
1085 const TopoDS_Shape& aShapeA = aShapes.First();
1087 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1089 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(aShapeA ) );
1090 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
1091 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
1092 GetMapOfAIS().Bind(myAISPoint,name);
1093 TheAISContext()->Display (myAISPoint, Standard_True);
1097 TopoDS_Edge myEdge=TopoDS::Edge(aShapeA);
1098 TopoDS_Vertex myVertexA,myVertexB;
1099 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
1100 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
1101 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
1102 // M est le milieu de [AB]
1103 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
1104 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
1105 GetMapOfAIS().Bind(myAISPointM,name);
1106 TheAISContext()->Display (myAISPointM, Standard_True);
1114 //==============================================================================
1115 // Function 1st click 2de click 3de click
1116 // vplane Vertex Vertex Vertex
1120 // vplanepara Face Vertex
1122 // vplaneortho Face Edge
1124 //==============================================================================
1126 //==============================================================================
1127 //function : VPlaneBuilder
1128 //purpose : Build an AIS_Plane from selected entities or Named AIS components
1129 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
1130 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
1131 // [PlaneName] [PointName] [TypeOfSensitivity]
1132 //==============================================================================
1134 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
1135 Standard_Integer argc,
1139 Standard_Boolean hasArg;
1140 TCollection_AsciiString aName;
1143 if (argc<2 || argc>6 )
1145 std::cout<<" Syntax error\n";
1148 if (argc == 6 || argc==5 || argc==4)
1149 hasArg=Standard_True;
1151 hasArg=Standard_False;
1155 // There are some arguments
1158 Handle(AIS_InteractiveObject) aShapeA;
1159 if (!GetMapOfAIS().Find2 (argv[2], aShapeA))
1161 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
1165 // The first argument is an AIS_Point
1166 if (!aShapeA.IsNull() &&
1167 aShapeA->Type()==AIS_KOI_Datum &&
1168 aShapeA->Signature()==1)
1170 // The second argument must also be an AIS_Point
1171 Handle(AIS_InteractiveObject) aShapeB;
1172 if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1174 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
1177 // If B is not an AIS_Point
1178 if (aShapeB.IsNull() ||
1179 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1181 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
1184 // The third object is an AIS_Point
1185 Handle(AIS_InteractiveObject) aShapeC;
1186 if (!GetMapOfAIS().Find2(argv[4], aShapeC))
1188 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
1191 // If C is not an AIS_Point
1192 if (aShapeC.IsNull() ||
1193 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
1195 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
1199 // Treatment of objects A, B, C
1200 // Downcast an AIS_IO to AIS_Point
1201 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
1202 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
1203 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
1205 Handle(Geom_CartesianPoint ) aCartPointA =
1206 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
1208 Handle(Geom_CartesianPoint ) aCartPointB =
1209 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
1211 Handle(Geom_CartesianPoint ) aCartPointC =
1212 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
1214 // Verification that the three points are different
1215 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
1216 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1217 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
1220 std::cout<<"vplane error: same points\n";return 1;
1222 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1223 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1224 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1227 std::cout<<"vplane error: same points\n";return 1;
1229 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1230 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1231 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1234 std::cout<<"vplane error: same points\n";return 1;
1237 gp_Pnt A = aCartPointA->Pnt();
1238 gp_Pnt B = aCartPointB->Pnt();
1239 gp_Pnt C = aCartPointC->Pnt();
1241 // Construction of AIS_Plane
1242 GC_MakePlane MkPlane (A,B,C);
1243 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1244 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1245 GetMapOfAIS().Bind (anAISPlane,aName );
1248 Standard_Integer aType = Draw::Atoi (argv[5]);
1249 if (aType != 0 && aType != 1)
1251 std::cout << "vplane error: wrong type of sensitivity!\n"
1252 << "Should be one of the following values:\n"
1260 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1263 TheAISContext()->Display (anAISPlane, Standard_True);
1266 // The first argument is an AIS_Axis
1267 // Creation of a plane orthogonal to the axis through a point
1268 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1269 // The second argument should be an AIS_Point
1270 Handle(AIS_InteractiveObject) aShapeB;
1271 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1273 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1276 // If B is not an AIS_Point
1277 if (aShapeB.IsNull() ||
1278 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1280 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1284 // Treatment of objects A and B
1285 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1286 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1288 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1289 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1291 gp_Ax1 anAxis = aGeomLineA->Position();
1292 Handle(Geom_CartesianPoint) aCartPointB =
1293 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1295 gp_Dir D =anAxis.Direction();
1296 gp_Pnt B = aCartPointB->Pnt();
1298 // Construction of AIS_Plane
1299 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1300 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1301 GetMapOfAIS().Bind (anAISPlane,aName );
1304 Standard_Integer aType = Draw::Atoi (argv[4]);
1305 if (aType != 0 && aType != 1)
1307 std::cout << "vplane error: wrong type of sensitivity!\n"
1308 << "Should be one of the following values:\n"
1316 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1319 TheAISContext()->Display (anAISPlane, Standard_True);
1322 // The first argumnet is an AIS_Plane
1323 // Creation of a plane parallel to the plane passing through the point
1324 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1326 // The second argument should be an AIS_Point
1327 Handle(AIS_InteractiveObject) aShapeB;
1328 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1330 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1333 // B should be an AIS_Point
1334 if (aShapeB.IsNull() ||
1335 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1337 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1341 // Treatment of objects A and B
1342 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1343 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1345 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1346 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1348 Handle(Geom_CartesianPoint) aCartPointB =
1349 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1350 gp_Pnt B= aCartPointB->Pnt();
1352 // Construction of an AIS_Plane
1353 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1354 GetMapOfAIS().Bind (anAISPlane, aName);
1357 Standard_Integer aType = Draw::Atoi (argv[4]);
1358 if (aType != 0 && aType != 1)
1360 std::cout << "vplane error: wrong type of sensitivity!\n"
1361 << "Should be one of the following values:\n"
1369 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1372 TheAISContext()->Display (anAISPlane, Standard_True);
1377 std::cout<<"vplane: error 1st object is not an AIS\n";
1381 // There are no arguments
1384 TopTools_ListOfShape aShapes;
1385 ViewerTest::GetSelectedShapes (aShapes);
1388 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1389 if (!strcasecmp(argv[0], "vplane"))
1391 if (aShapes.Extent() < 1 || aShapes.Extent() > 3)
1393 std::cerr << "Error: Wront number of selected shapes.\n";
1394 std::cerr << "\tYou should one of variant: face, edge and vertex or three vertices.\n";
1398 const TopoDS_Shape& aShapeA = aShapes.First();
1399 if (aShapeA.ShapeType() == TopAbs_VERTEX)
1401 if (aShapes.Extent() == 2)
1403 const TopoDS_Shape& aShapeB = aShapes.Last();
1404 if (aShapeB.ShapeType() != TopAbs_EDGE)
1406 std::cerr << "Syntax error: Together with vertex should be edge.\n";
1410 // Verify that the vertex is not on the edge ShapeB
1411 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1412 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1414 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1415 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1417 // The vertex is on the edge
1418 std::cout<<" vplane: error point is on the edge\n";
1423 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1424 TopoDS_Vertex aVBa, aVBb;
1425 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1426 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1427 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1428 GC_MakePlane MkPlane (A, aBa, aBb);
1429 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1430 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1431 GetMapOfAIS().Bind (anAISPlane, aName);
1432 TheAISContext()->Display (anAISPlane, Standard_True);
1435 else if (aShapes.Extent() == 3)
1437 TopTools_ListOfShape::Iterator anIter (aShapes);
1440 const TopoDS_Shape& aShapeB = anIter.Value();
1443 const TopoDS_Shape& aShapeC = anIter.Value();
1445 if (!(aShapeB.ShapeType() == TopAbs_VERTEX
1446 && aShapeC.ShapeType() == TopAbs_VERTEX))
1448 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1452 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1453 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1454 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1455 GC_MakePlane MkPlane(A, B, C);
1456 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1457 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1458 GetMapOfAIS().Bind (anAISPlane, aName);
1459 TheAISContext()->Display (anAISPlane, Standard_True);
1463 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1467 else if (aShapeA.ShapeType() == TopAbs_EDGE)
1469 if (aShapes.Extent() != 2)
1471 std::cerr << "Error: wrong number of selected shapes.\n";
1475 const TopoDS_Shape& aShapeB = aShapes.Last();
1476 if (aShapeB.ShapeType() != TopAbs_VERTEX)
1478 std::cerr << "Syntax error: Together with edge should be vertex.\n";
1482 // Check that the vertex aShapeB is not on the edge
1483 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1484 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1486 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1487 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1489 // The vertex is on the edge
1490 std::cout<<" vplane: error point is on the edge\n";
1494 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1495 TopoDS_Vertex aVAa, aVAb;
1496 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1497 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1498 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1499 GC_MakePlane MkPlane (B,Aa,Ab);
1500 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1501 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1502 GetMapOfAIS().Bind (anAISPlane ,aName);
1503 TheAISContext()->Display (anAISPlane, Standard_True);
1505 else if (aShapeA.ShapeType() == TopAbs_FACE)
1507 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1508 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1509 if (aSurface.GetType()==GeomAbs_Plane)
1511 gp_Pln aPlane = aSurface.Plane();
1512 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1513 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1514 GetMapOfAIS().Bind (anAISPlane, aName);
1515 TheAISContext()->Display (anAISPlane, Standard_True);
1519 std::cout<<" vplane: error\n";
1525 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1530 // Function vPlanePara
1531 // ===================
1532 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1533 else if (!strcasecmp(argv[0], "vplanepara"))
1535 if (aShapes.Extent() != 2)
1537 std::cerr << "Error: Wrong number of selected shapes.\n";
1541 const TopoDS_Shape* aShapeA = &aShapes.First();
1542 const TopoDS_Shape* aShapeB = &aShapes.Last();
1543 if (aShapeA->ShapeType() != TopAbs_VERTEX)
1545 std::swap (aShapeA, aShapeB);
1548 if (!(aShapeA->ShapeType() == TopAbs_VERTEX
1549 && aShapeB->ShapeType() == TopAbs_FACE))
1551 std::cerr << "Syntax error: you should select face and vertex.\n";
1555 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA));
1557 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1558 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1559 if (aSurface.GetType() == GeomAbs_Plane)
1561 gp_Pln aPlane = aSurface.Plane();
1562 // Construct a plane parallel to aGeomPlane through A
1563 aPlane.SetLocation(A);
1564 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1565 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1566 GetMapOfAIS().Bind (aAISPlane ,aName);
1567 TheAISContext()->Display (aAISPlane, Standard_True);
1571 std::cerr << "Error: Builded surface is not a plane.\n";
1576 // Function vplaneortho
1577 // ====================
1578 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1581 if (aShapes.Extent() != 2)
1583 std::cerr << "Error: wrong number of selected shapes.\n";
1587 const TopoDS_Shape* aShapeA = &aShapes.First();
1588 const TopoDS_Shape* aShapeB = &aShapes.Last();
1590 if (aShapeA->ShapeType() != TopAbs_EDGE)
1592 std::swap (aShapeA, aShapeB);
1595 if (!(aShapeA->ShapeType() == TopAbs_EDGE
1596 && aShapeB->ShapeType() == TopAbs_FACE))
1598 std::cerr << "Error: you should select edge and face.\n";
1602 // Construction of plane
1603 TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA);
1604 TopoDS_Vertex aVAa, aVAb;
1605 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1606 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1607 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1611 // Creation of rotation axis
1612 gp_Ax1 aRotAxis (Aa,Dab);
1614 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1615 // The edge must be parallel to the face
1616 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1617 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1618 // Compare to heights
1619 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1620 >Precision::Confusion())
1622 // the edge is not parallel to the face
1623 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1627 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1628 if (aSurface.GetType()==GeomAbs_Plane)
1630 gp_Pln aPlane = aSurface.Plane();
1631 // It rotates a half turn round the axis of rotation
1632 aPlane.Rotate(aRotAxis , M_PI/2);
1634 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1635 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1636 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1637 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1638 GetMapOfAIS().Bind (anAISPlane, aName);
1639 TheAISContext()->Display (anAISPlane, Standard_True);
1643 std::cout<<" vplaneortho: error\n";
1651 //===============================================================================================
1652 //function : VChangePlane
1654 //===============================================================================================
1655 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1657 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1658 if (aContextAIS.IsNull())
1660 std::cout << theArgVec[0] << "AIS context is not available.\n";
1664 if (theArgsNb < 3 || theArgsNb > 11)
1666 std::cerr << theArgVec[0]
1667 << ": incorrect number of command arguments.\n"
1668 << "Type help for more information.\n";
1672 TCollection_AsciiString aName (theArgVec[1]);
1674 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1675 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1678 if ( aPlane.IsNull() )
1680 std::cout << theArgVec[0]
1681 << ": there is no interactive plane with the given name."
1682 << "Type help for more information.\n";
1686 Standard_Real aCenterX = aPlane->Center().X();
1687 Standard_Real aCenterY = aPlane->Center().Y();
1688 Standard_Real aCenterZ = aPlane->Center().Z();
1690 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1691 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1692 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1694 Standard_Real aSizeX = 0.0;
1695 Standard_Real aSizeY = 0.0;
1696 aPlane->Size (aSizeX, aSizeY);
1697 Standard_Boolean isUpdate = Standard_True;
1699 TCollection_AsciiString aPName, aPValue;
1700 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1702 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1703 TCollection_AsciiString anArgCase = anArg;
1704 anArgCase.UpperCase();
1705 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1708 if (aPName.IsEqual ("X"))
1710 aCenterX = aPValue.RealValue();
1712 else if (aPName.IsEqual ("Y"))
1714 aCenterY = aPValue.RealValue();
1716 else if (aPName.IsEqual ("Z"))
1718 aCenterZ = aPValue.RealValue();
1720 else if (aPName.IsEqual ("DX"))
1722 aDirX = aPValue.RealValue();
1724 else if (aPName.IsEqual ("DY"))
1726 aDirY = aPValue.RealValue();
1728 else if (aPName.IsEqual ("DZ"))
1730 aDirZ = aPValue.RealValue();
1732 else if (aPName.IsEqual ("SX"))
1734 aSizeX = aPValue.RealValue();
1736 else if (aPName.IsEqual ("SY"))
1738 aSizeY = aPValue.RealValue();
1741 else if (anArg.IsEqual ("NOUPDATE"))
1743 isUpdate = Standard_False;
1747 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1748 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1749 aPlane->SetCenter (aCenterPnt);
1750 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1751 aPlane->SetSize (aSizeX, aSizeY);
1753 aContextAIS->Update (aPlane, isUpdate);
1758 //==============================================================================
1760 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1761 //==============================================================================
1763 //==============================================================================
1764 //function : VLineBuilder
1765 //purpose : Build an AIS_Line
1766 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1767 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1768 //==============================================================================
1769 #include <Geom_CartesianPoint.hxx>
1770 #include <AIS_Line.hxx>
1773 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1776 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; }
1778 // On recupere les parametres
1779 Handle(AIS_InteractiveObject) theShapeA;
1780 Handle(AIS_InteractiveObject) theShapeB;
1782 // Parametres: AIS_Point AIS_Point
1783 // ===============================
1785 GetMapOfAIS().Find2 (argv[2], theShapeA);
1786 // On verifie que c'est bien une AIS_Point
1787 if (!theShapeA.IsNull() &&
1788 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1789 // on recupere le deuxieme AIS_Point
1790 GetMapOfAIS().Find2 (argv[3], theShapeB);
1791 if (theShapeB.IsNull() ||
1792 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1794 di <<"vline error: wrong type of 2de argument.\n";
1798 else {di <<"vline error: wrong type of 1st argument.\n";return 1; }
1799 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1800 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1801 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
1803 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1804 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
1805 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1807 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1808 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
1809 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1811 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1813 di<<"vline error: same points\n";return 1;
1815 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1816 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1817 GetMapOfAIS().Bind(theAISLine,argv[1] );
1818 TheAISContext()->Display (theAISLine, Standard_True);
1822 // Parametres 6 Reals
1823 // ==================
1826 // On verifie que les deux points ne sont pas confondus
1828 Standard_Real coord[6];
1829 for(Standard_Integer i=0;i<=2;i++){
1830 coord[i]=Draw::Atof(argv[2+i]);
1831 coord[i+3]=Draw::Atof(argv[5+i]);
1834 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1835 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1837 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1838 GetMapOfAIS().Bind(theAISLine,argv[1] );
1839 TheAISContext()->Display (theAISLine, Standard_True);
1843 // Pas de parametres: Selection dans le viewer.
1844 // ============================================
1848 TopTools_ListOfShape aShapes;
1849 ViewerTest::GetSelectedShapes (aShapes);
1850 if (aShapes.Extent() != 2)
1852 std::cerr << "Error: wrong number of selected shapes.\n";
1856 const TopoDS_Shape& aShapeA = aShapes.First();
1857 const TopoDS_Shape& aShapeB = aShapes.Last();
1859 if (!(aShapeA.ShapeType() == TopAbs_VERTEX
1860 && aShapeB.ShapeType() == TopAbs_VERTEX))
1862 std::cerr << "Error: you should select two different vertex.\n";
1866 // Construction de la line
1867 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1868 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
1870 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1871 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1873 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1874 GetMapOfAIS().Bind(theAISLine,argv[1] );
1875 TheAISContext()->Display (theAISLine, Standard_True);
1881 //==============================================================================
1882 // class : FilledCircle
1883 // purpose : creates filled circle based on AIS_InteractiveObject
1885 // This class is used to check method Matches() of class
1886 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1887 // because none of AIS classes provides creation of
1888 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1889 // (look method ComputeSelection() )
1890 //==============================================================================
1892 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1894 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1895 gp_Circ aCirc(anAxes, theRadius);
1896 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1900 class FilledCircle : public AIS_InteractiveObject
1904 DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject);
1906 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1907 FilledCircle(Handle(Geom_Circle) theCircle);
1910 TopoDS_Face ComputeFace();
1912 // Virtual methods implementation
1913 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1914 const Handle(Prs3d_Presentation)& thePresentation,
1915 const Standard_Integer theMode) Standard_OVERRIDE;
1917 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1918 const Standard_Integer theMode) Standard_OVERRIDE;
1921 Handle(Geom_Circle) myCircle;
1922 Standard_Boolean myFilledStatus;
1927 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1929 myCircle = CreateCircle(theCenter, theRadius);
1930 myFilledStatus = Standard_True;
1933 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1935 myCircle = theCircle;
1936 myFilledStatus = Standard_True;
1939 TopoDS_Face FilledCircle::ComputeFace()
1941 // Create edge from myCircle
1942 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1943 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1945 // Create wire from anEdge
1946 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1947 TopoDS_Wire aWire = aWireMaker.Wire();
1949 // Create face from aWire
1950 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1951 TopoDS_Face aFace = aFaceMaker.Face();
1956 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1957 const Handle(Prs3d_Presentation) &thePresentation,
1958 const Standard_Integer theMode)
1960 thePresentation->Clear();
1962 TopoDS_Face aFace = ComputeFace();
1964 if (aFace.IsNull()) return;
1965 if (theMode != 0) return;
1967 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1970 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
1971 const Standard_Integer /*theMode*/)
1973 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
1974 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
1975 myCircle, myFilledStatus);
1976 theSelection->Add(aSensitiveCircle);
1979 //==============================================================================
1981 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
1982 //==============================================================================
1984 //==============================================================================
1985 //function : VCircleBuilder
1986 //purpose : Build an AIS_Circle
1987 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
1988 // PointName PointName PointName IsFilled
1989 //==============================================================================
1991 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
1992 TCollection_AsciiString theName,
1993 Standard_Boolean isFilled)
1995 Handle(AIS_InteractiveObject) aCircle;
1998 aCircle = new FilledCircle(theGeomCircle);
2002 aCircle = new AIS_Circle(theGeomCircle);
2003 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2006 // Check if there is an object with given name
2007 // and remove it from context
2008 if (GetMapOfAIS().IsBound2(theName))
2010 Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2(theName);
2011 TheAISContext()->Remove(anInterObj, Standard_False);
2012 GetMapOfAIS().UnBind2(theName);
2015 // Bind the circle to its name
2016 GetMapOfAIS().Bind(aCircle, theName);
2018 // Display the circle
2019 TheAISContext()->Display (aCircle, Standard_True);
2023 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2025 // Verification of the arguments
2026 if (argc>6 || argc<2)
2028 std::cout << "vcircle error: expect 4 arguments.\n";
2029 return 1; // TCL_ERROR
2032 // There are all arguments
2036 TCollection_AsciiString aName(argv[1]);
2037 Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0;
2039 Handle(AIS_InteractiveObject) theShapeA, theShapeB;
2040 GetMapOfAIS().Find2 (argv[2], theShapeA);
2041 GetMapOfAIS().Find2 (argv[3], theShapeB);
2043 // Arguments: AIS_Point AIS_Point AIS_Point
2044 // ========================================
2045 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2046 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2048 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2050 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2051 return 1; // TCL_ERROR
2053 // The third object must be a point
2054 Handle(AIS_InteractiveObject) theShapeC;
2055 GetMapOfAIS().Find2 (argv[4], theShapeC);
2056 if (theShapeC.IsNull() ||
2057 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2059 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2060 return 1; // TCL_ERROR
2063 // Verify that the three points are different
2064 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2065 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2066 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2068 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2069 Handle(Geom_CartesianPoint) myCartPointA =
2070 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2072 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2073 Handle(Geom_CartesianPoint) myCartPointB =
2074 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2076 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2077 Handle(Geom_CartesianPoint) myCartPointC =
2078 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2081 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2082 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2083 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2085 std::cout << "vcircle error: Same points.\n";
2086 return 1; // TCL_ERROR
2089 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2090 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2091 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2093 std::cout << "vcircle error: Same points.\n";
2094 return 1; // TCL_ERROR
2097 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2098 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2099 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2101 std::cout << "vcircle error: Same points.\n";
2102 return 1;// TCL_ERROR
2104 // Construction of the circle
2105 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2106 myCartPointB->Pnt(), myCartPointC->Pnt() );
2107 Handle (Geom_Circle) theGeomCircle;
2110 theGeomCircle = Cir.Value();
2112 catch (StdFail_NotDone)
2114 std::cout << "vcircle error: can't create circle\n";
2115 return -1; // TCL_ERROR
2118 DisplayCircle(theGeomCircle, aName, isFilled);
2121 // Arguments: AIS_Plane AIS_Point Real
2122 // ===================================
2123 else if (theShapeA->Type() == AIS_KOI_Datum &&
2124 theShapeA->Signature() == 7 )
2126 if (theShapeB->Type() != AIS_KOI_Datum ||
2127 theShapeB->Signature() != 1 )
2129 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2130 return 1; // TCL_ERROR
2132 // Check that the radius is >= 0
2133 if (Draw::Atof(argv[4]) <= 0 )
2135 std::cout << "vcircle error: the radius must be >=0.\n";
2136 return 1; // TCL_ERROR
2139 // Recover the normal to the plane
2140 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2141 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2143 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2144 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2145 Handle(Geom_CartesianPoint) myCartPointB =
2146 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2148 gp_Pln mygpPlane = myGeomPlane->Pln();
2149 gp_Ax1 thegpAxe = mygpPlane.Axis();
2150 gp_Dir theDir = thegpAxe.Direction();
2151 gp_Pnt theCenter = myCartPointB->Pnt();
2152 Standard_Real TheR = Draw::Atof(argv[4]);
2153 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2154 Handle (Geom_Circle) theGeomCircle;
2157 theGeomCircle = Cir.Value();
2159 catch (StdFail_NotDone)
2161 std::cout << "vcircle error: can't create circle\n";
2162 return -1; // TCL_ERROR
2165 DisplayCircle(theGeomCircle, aName, isFilled);
2172 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2173 return 1; // TCL_ERROR
2177 // No arguments: selection in the viewer
2178 // =========================================
2181 // Get the name of the circle
2182 TCollection_AsciiString aName(argv[1]);
2184 TopTools_ListOfShape aShapes;
2185 ViewerTest::GetSelectedShapes (aShapes);
2186 if (aShapes.Extent() != 3 && aShapes.Extent() != 2)
2188 std::cerr << "Error: Wrong number of selected shapes.\n";
2192 const TopoDS_Shape& aShapeA = aShapes.First();
2193 if (aShapeA.ShapeType() == TopAbs_VERTEX )
2195 if (aShapes.Extent() != 3)
2197 std::cerr << "Error: wrong number of selected shapes.\n";
2201 TopTools_ListOfShape::Iterator anIter (aShapes);
2204 const TopoDS_Shape& aShapeB = anIter.Value();
2207 const TopoDS_Shape& aShapeC = anIter.Value();
2210 Standard_Boolean isFilled;
2211 std::cout << "Enter filled status (0 or 1)\n";
2214 // Construction of the circle
2215 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
2216 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2217 gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC));
2219 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2220 Handle (Geom_Circle) theGeomCircle;
2223 theGeomCircle = Cir.Value();
2225 catch (StdFail_NotDone)
2227 std::cout << "vcircle error: can't create circle\n";
2228 return -1; // TCL_ERROR
2231 DisplayCircle(theGeomCircle, aName, isFilled);
2234 else if (aShapeA.ShapeType() == TopAbs_FACE)
2236 const TopoDS_Shape& aShapeB = aShapes.Last();
2238 // Recover the radius
2239 Standard_Real theRad;
2242 std::cout << " Enter the value of the radius:\n";
2244 } while (theRad <= 0);
2246 // Get filled status
2247 Standard_Boolean isFilled;
2248 std::cout << "Enter filled status (0 or 1)\n";
2251 // Recover the normal to the plane. tag
2252 TopoDS_Face myFace = TopoDS::Face(aShapeA);
2253 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2254 gp_Pln myPlane = mySurface.Plane();
2255 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2256 gp_Pln mygpPlane = theGeomPlane->Pln();
2257 gp_Ax1 thegpAxe = mygpPlane.Axis();
2258 gp_Dir theDir = thegpAxe.Direction();
2260 // Recover the center
2261 gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2263 // Construct the circle
2264 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2265 Handle (Geom_Circle) theGeomCircle;
2268 theGeomCircle = Cir.Value();
2270 catch (StdFail_NotDone)
2272 std::cout << "vcircle error: can't create circle\n";
2273 return -1; // TCL_ERROR
2276 DisplayCircle(theGeomCircle, aName, isFilled);
2280 std::cerr << "Error: You should select face and vertex or three vertices.\n";
2288 //=======================================================================
2289 //function : VDrawText
2291 //=======================================================================
2292 static int VDrawText (Draw_Interpretor& theDI,
2293 Standard_Integer theArgsNb,
2294 const char** theArgVec)
2296 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2299 std::cout << "Error: wrong number of arguments! See usage:\n";
2300 theDI.PrintHelp (theArgVec[0]);
2303 else if (aContext.IsNull())
2305 std::cout << "Error: no active view!\n";
2309 Standard_Integer anArgIt = 1;
2310 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2311 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2312 Handle(AIS_TextLabel) aTextPrs;
2313 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2315 Standard_Boolean isNewPrs = Standard_False;
2316 if (GetMapOfAIS().IsBound2 (aName))
2318 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2321 if (aTextPrs.IsNull())
2323 isNewPrs = Standard_True;
2324 aTextPrs = new AIS_TextLabel();
2325 aTextPrs->SetFont ("Courier");
2328 aTextPrs->SetText (aText);
2330 Handle(Graphic3d_TransformPers) aTrsfPers;
2331 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2333 Standard_Boolean aHasPlane = Standard_False;
2338 for (; anArgIt < theArgsNb; ++anArgIt)
2340 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2343 if (anAutoUpdater.parseRedrawMode (aParam))
2347 else if (aParam == "-pos"
2348 || aParam == "-position")
2350 if (anArgIt + 3 >= theArgsNb)
2352 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2356 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2357 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2358 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2359 aTextPrs->SetPosition (aPos);
2361 else if (aParam == "-color")
2363 if (anArgIt + 1 >= theArgsNb)
2365 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2369 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2370 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2371 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2374 aTextPrs->SetColor (aNameOfColor);
2377 else if (anArgIt + 3 >= theArgsNb)
2379 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2383 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2384 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2385 if (!aColor.IsRealValue()
2386 || !aGreen.IsRealValue()
2387 || !aBlue.IsRealValue())
2389 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2393 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2397 aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2400 else if (aParam == "-halign")
2402 if (++anArgIt >= theArgsNb)
2404 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2408 TCollection_AsciiString aType (theArgVec[anArgIt]);
2410 if (aType == "left")
2412 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2414 else if (aType == "center")
2416 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2418 else if (aType == "right")
2420 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2424 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2428 else if (aParam == "-valign")
2430 if (++anArgIt >= theArgsNb)
2432 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2436 TCollection_AsciiString aType (theArgVec[anArgIt]);
2440 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2442 else if (aType == "center")
2444 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2446 else if (aType == "bottom")
2448 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2450 else if (aType == "topfirstline")
2452 aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2456 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2460 else if (aParam == "-angle")
2462 if (++anArgIt >= theArgsNb)
2464 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2468 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2470 else if (aParam == "-zoom")
2472 if (++anArgIt >= theArgsNb)
2474 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2478 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2480 else if (aParam == "-height")
2482 if (++anArgIt >= theArgsNb)
2484 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2488 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2490 else if (aParam == "-aspect")
2492 if (++anArgIt >= theArgsNb)
2494 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2498 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2499 anOption.LowerCase();
2500 Font_FontAspect aFontAspect = Font_FA_Undefined;
2501 if (!parseFontStyle (anOption, aFontAspect))
2503 std::cout << "Error: unknown font aspect '" << anOption << "'.\n";
2506 aTextPrs->SetFontAspect (aFontAspect);
2508 else if (aParam == "-font")
2510 if (++anArgIt >= theArgsNb)
2512 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2516 aTextPrs->SetFont (theArgVec[anArgIt]);
2518 else if (aParam == "-plane")
2520 if (anArgIt + 6 >= theArgsNb)
2522 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2526 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
2527 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
2528 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
2529 aNormal.SetCoord (aX, aY, aZ);
2531 aX = Draw::Atof (theArgVec[++anArgIt]);
2532 aY = Draw::Atof (theArgVec[++anArgIt]);
2533 aZ = Draw::Atof (theArgVec[++anArgIt]);
2534 aDirection.SetCoord (aX, aY, aZ);
2536 aHasPlane = Standard_True;
2538 else if (aParam == "-flipping")
2540 aTextPrs->SetFlipping (Standard_True);
2542 else if (aParam == "-disptype"
2543 || aParam == "-displaytype")
2545 if (++anArgIt >= theArgsNb)
2547 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2550 TCollection_AsciiString aType (theArgVec[anArgIt]);
2552 if (aType == "subtitle")
2553 aDisplayType = Aspect_TODT_SUBTITLE;
2554 else if (aType == "decal")
2555 aDisplayType = Aspect_TODT_DEKALE;
2556 else if (aType == "blend")
2557 aDisplayType = Aspect_TODT_BLEND;
2558 else if (aType == "dimension")
2559 aDisplayType = Aspect_TODT_DIMENSION;
2560 else if (aType == "normal")
2561 aDisplayType = Aspect_TODT_NORMAL;
2562 else if (aType == "shadow")
2563 aDisplayType = Aspect_TODT_SHADOW;
2566 std::cout << "Error: wrong display type '" << aType << "'.\n";
2570 else if (aParam == "-subcolor"
2571 || aParam == "-subtitlecolor")
2573 if (anArgIt + 1 >= theArgsNb)
2575 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2579 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2580 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2581 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2584 aTextPrs->SetColorSubTitle (aNameOfColor);
2587 else if (anArgIt + 3 >= theArgsNb)
2589 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2593 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2594 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2595 if (!aColor.IsRealValue()
2596 || !aGreen.IsRealValue()
2597 || !aBlue.IsRealValue())
2599 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2603 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2607 aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2610 else if (aParam == "-2d")
2612 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d);
2614 else if (aParam == "-trsfperspos"
2615 || aParam == "-perspos")
2617 if (anArgIt + 2 >= theArgsNb)
2619 std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2623 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2624 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2625 TCollection_AsciiString aZ = "0";
2626 if (!aX.IsIntegerValue()
2627 || !aY.IsIntegerValue())
2629 std::cerr << "Error: wrong syntax at '" << aParam << "'.\n";
2632 if (anArgIt + 1 < theArgsNb)
2634 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2635 if (aTemp.IsIntegerValue())
2642 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()));
2646 std::cout << "Error: unknown argument '" << aParam << "'\n";
2653 aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2656 aTextPrs->SetDisplayType (aDisplayType);
2658 if (!aTrsfPers.IsNull())
2660 aContext->SetTransformPersistence (aTextPrs, aTrsfPers);
2661 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2662 if (aTextPrs->Position().Z() != 0)
2664 aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
2667 else if (!aTextPrs->TransformPersistence().IsNull())
2669 aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
2674 ViewerTest::Display (aName, aTextPrs, Standard_False);
2678 aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
2684 #include <gp_Pnt.hxx>
2685 #include <Graphic3d_ArrayOfPoints.hxx>
2686 #include <Graphic3d_ArrayOfPrimitives.hxx>
2687 #include <Graphic3d_ArrayOfTriangles.hxx>
2688 #include <Poly_Array1OfTriangle.hxx>
2689 #include <Poly_Triangle.hxx>
2690 #include <Poly_Triangulation.hxx>
2691 #include <TColgp_Array1OfPnt.hxx>
2692 #include <TShort_Array1OfShortReal.hxx>
2693 #include <TShort_HArray1OfShortReal.hxx>
2695 #include <AIS_Triangulation.hxx>
2696 #include <StdPrs_ToolTriangulatedShape.hxx>
2697 #include <Poly_Connect.hxx>
2698 #include <TColgp_Array1OfDir.hxx>
2699 #include <Graphic3d_GraphicDriver.hxx>
2701 #include <TColStd_Array1OfInteger.hxx>
2702 #include <TColStd_HArray1OfInteger.hxx>
2703 #include <Prs3d_ShadingAspect.hxx>
2704 #include <Graphic3d_MaterialAspect.hxx>
2705 #include <Graphic3d_AspectFillArea3d.hxx>
2707 #include <BRepPrimAPI_MakeCylinder.hxx>
2708 #include <TopoDS_Shape.hxx>
2709 #include <TopExp_Explorer.hxx>
2710 #include <TopAbs.hxx>
2711 #include <StdSelect_ShapeTypeFilter.hxx>
2712 #include <AIS_InteractiveObject.hxx>
2715 //===============================================================================================
2716 //function : CalculationOfSphere
2718 //purpose : Create a Sphere
2719 //===============================================================================================
2721 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2724 double mRadius = Radius;
2725 double mCenter[3] = {X,Y,Z};
2726 int mThetaResolution;
2728 double mStartTheta = 0;//StartTheta;
2729 double mEndTheta = 360;//EndTheta;
2730 double mStartPhi = 0;//StartPhi;
2731 double mEndPhi = 180;//EndPhi;
2732 res = res < 4 ? 4 : res;
2734 mThetaResolution = res;
2735 mPhiResolution = res;
2738 int jStart, jEnd, numOffset;
2739 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2740 double startTheta, endTheta, startPhi, endPhi;
2741 int base, numPoles=0, thetaResolution, phiResolution;
2746 if ( numPieces > mThetaResolution ) {
2747 numPieces = mThetaResolution;
2750 int localThetaResolution = mThetaResolution;
2751 double localStartTheta = mStartTheta;
2752 double localEndTheta = mEndTheta;
2754 while ( localEndTheta < localStartTheta ) {
2755 localEndTheta += 360.0;
2758 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2760 // Change the ivars based on pieces.
2762 start = piece * localThetaResolution / numPieces;
2763 end = (piece+1) * localThetaResolution / numPieces;
2764 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2765 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2766 localThetaResolution = end - start;
2768 // Create north pole if needed
2769 int number_point = 0;
2770 int number_pointArray = 0;
2772 if ( mStartPhi <= 0.0 ) {
2773 number_pointArray++;
2776 if ( mEndPhi >= 180.0 ) {
2777 number_pointArray++;
2781 // Check data, determine increments, and convert to radians
2782 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2783 startTheta *= M_PI / 180.0;
2784 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2785 endTheta *= M_PI / 180.0;
2788 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2789 startPhi *= M_PI / 180.0;
2790 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2791 endPhi *= M_PI / 180.0;
2793 phiResolution = mPhiResolution - numPoles;
2794 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2795 thetaResolution = localThetaResolution;
2796 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2797 ++localThetaResolution;
2799 deltaTheta = (endTheta - startTheta) / thetaResolution;
2801 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2802 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2804 // Create intermediate points
2805 for ( i = 0; i < localThetaResolution; i++ ) {
2806 for ( j = jStart; j < jEnd; j++ ) {
2807 number_pointArray++;
2811 //Generate mesh connectivity
2812 base = phiResolution * localThetaResolution;
2814 int number_triangle = 0 ;
2815 if ( mStartPhi <= 0.0 ) { // around north pole
2816 number_triangle += localThetaResolution;
2819 if ( mEndPhi >= 180.0 ) { // around south pole
2820 number_triangle += localThetaResolution;
2823 // bands in-between poles
2824 for ( i=0; i < localThetaResolution; i++){
2825 for ( j=0; j < (phiResolution-1); j++){
2826 number_triangle +=2;
2830 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2831 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2832 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2834 if ( mStartPhi <= 0.0 ){
2837 x[2] = mCenter[2] + mRadius;
2838 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2841 // Create south pole if needed
2842 if ( mEndPhi >= 180.0 ){
2845 x[2] = mCenter[2] - mRadius;
2846 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2850 for ( i=0; i < localThetaResolution; i++){
2851 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2852 for ( j = jStart; j < jEnd; j++){
2853 phi = startPhi + j*deltaPhi;
2854 radius = mRadius * sin((double)phi);
2855 n[0] = radius * cos((double)theta);
2856 n[1] = radius * sin((double)theta);
2857 n[2] = mRadius * cos((double)phi);
2858 x[0] = n[0] + mCenter[0];
2859 x[1] = n[1] + mCenter[1];
2860 x[2] = n[2] + mCenter[2];
2861 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2867 number_triangle = 1;
2868 if ( mStartPhi <= 0.0 ){// around north pole
2869 for (i=0; i < localThetaResolution; i++){
2870 pts[0] = phiResolution*i + numPoles;
2871 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2873 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2878 if ( mEndPhi >= 180.0 ){ // around south pole
2879 numOffset = phiResolution - 1 + numPoles;
2880 for (i=0; i < localThetaResolution; i++){
2881 pts[0] = phiResolution*i + numOffset;
2882 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2883 pts[1] = numPoles - 1;
2884 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2889 // bands in-between poles
2891 for (i=0; i < localThetaResolution; i++){
2892 for (j=0; j < (phiResolution-1); j++){
2893 pts[0] = phiResolution*i + j + numPoles;
2894 pts[1] = pts[0] + 1;
2895 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2896 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2899 pts[2] = pts[1] - 1;
2900 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2905 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2907 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2909 Standard_Integer index[3];
2910 Standard_Real Tol = Precision::Confusion();
2913 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2914 gp_XYZ eqPlan(0, 0, 0);
2915 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2916 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2917 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2918 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2920 Standard_Real mod = vv.Modulus();
2921 if(mod < Tol) continue;
2925 Standard_Real modmax = eqPlan.Modulus();
2928 Nor = gp_Dir(eqPlan);
2930 Nor = gp_Dir(0., 0., 1.);
2932 Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
2933 Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
2934 Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
2935 Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
2939 polyTriangulation->SetNormals(Normals);
2941 return polyTriangulation;
2944 //===============================================================================================
2945 //function : VDrawSphere
2947 //purpose : Create an AIS shape.
2948 //===============================================================================================
2949 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2952 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2953 if (aContextAIS.IsNull())
2955 std::cout << "Call vinit before!\n";
2960 std::cout << "Use: " << argv[0]
2961 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2965 // read the arguments
2966 TCollection_AsciiString aShapeName (argv[1]);
2967 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2968 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2969 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2970 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2971 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2972 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2973 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
2975 // remove AIS object with given name from map
2976 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2979 std::cout << "Compute Triangulation...\n";
2980 Handle(AIS_Triangulation) aShape
2981 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2984 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2985 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2987 // stupid initialization of Green color in RGBA space as integer
2988 // probably wrong for big-endian CPUs
2989 const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
2991 // setup colors array per vertex
2992 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2993 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2995 aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData()));
2997 aShape->SetColors (aColorArray);
3000 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3001 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3002 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
3003 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
3004 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
3005 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
3006 aTotalSize >>= 20; //MB
3007 aNormalsSize >>= 20;
3009 aTrianglesSize >>= 20;
3010 aPolyConnectSize >>= 20;
3013 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
3014 << "NumberOfTriangles: " << aNumberTriangles << "\n"
3015 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
3016 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
3017 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
3018 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
3021 // Setting material properties, very important for desirable visual result!
3022 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
3023 aMat.SetAmbient (0.2f);
3024 aMat.SetSpecular (0.5f);
3025 Handle(Graphic3d_AspectFillArea3d) anAspect
3026 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3028 Quantity_NOC_YELLOW,
3033 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3034 anAspect->SetDrawEdges (toShowEdges);
3035 aShAsp->SetAspect (anAspect);
3036 aShape->Attributes()->SetShadingAspect (aShAsp);
3038 VDisplayAISObject (aShapeName, aShape);
3042 //=============================================================================
3043 //function : VComputeHLR
3045 //=============================================================================
3047 static int VComputeHLR (Draw_Interpretor& ,
3048 Standard_Integer theArgNb,
3049 const char** theArgVec)
3051 TCollection_AsciiString aShapeName, aHlrName;
3056 bool hasViewDirArg = false;
3057 Prs3d_TypeOfHLR anAlgoType = Prs3d_TOH_PolyAlgo;
3058 bool toShowTangentEdges = false, toShowHiddenEdges = false;
3059 int aNbIsolines = 0;
3060 if (Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext())
3063 Handle(V3d_View) aView = ViewerTest::CurrentView();
3064 Standard_Integer aWidth, aHeight;
3065 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3066 Standard_Real aRightX, aRightY, aRightZ;
3067 aView->Window()->Size (aWidth, aHeight);
3069 aView->ConvertWithProj (aWidth, aHeight/2,
3070 aRightX, aRightY, aRightZ,
3071 aDirX, aDirY, aDirZ);
3072 aView->ConvertWithProj (aWidth/2, aHeight/2,
3073 aCentX, aCentY, aCentZ,
3074 aDirX, aDirY, aDirZ);
3076 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3077 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3078 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3079 aProjAx.SetLocation (anEye);
3080 aProjAx.SetDirection (aDir);
3081 aProjAx.SetXDirection (aRight);
3083 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3085 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3086 anArgCase.LowerCase();
3087 if (anArgIter + 1 < theArgNb
3088 && (anArgCase == "-algotype"
3089 || anArgCase == "-algo"
3090 || anArgCase == "-type"))
3092 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
3093 anArgNext.LowerCase();
3094 if (anArgNext == "polyalgo")
3096 anAlgoType = Prs3d_TOH_PolyAlgo;
3098 else if (anArgNext == "algo")
3100 anAlgoType = Prs3d_TOH_Algo;
3104 std::cout << "Syntax error: unknown algo type '" << anArgNext << "'\n";
3108 else if (anArgCase == "-showhiddenedges"
3109 || anArgCase == "-hiddenedges"
3110 || anArgCase == "-hidden")
3112 toShowHiddenEdges = true;
3113 if (anArgIter + 1 < theArgNb
3114 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowHiddenEdges))
3119 else if (anArgCase == "-showtangentedges"
3120 || anArgCase == "-tangentedges"
3121 || anArgCase == "-tangent")
3123 toShowTangentEdges = true;
3124 if (anArgIter + 1 < theArgNb
3125 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowTangentEdges))
3130 else if (anArgIter + 1 < theArgNb
3131 && (anArgCase == "-nbiso"
3132 || anArgCase == "-nbisolines"))
3134 aNbIsolines = Draw::Atoi (theArgVec[++anArgIter]);
3136 else if (aSh.IsNull())
3138 aSh = DBRep::Get (theArgVec[anArgIter]);
3139 aShapeName = theArgVec[anArgIter];
3142 BRep_Builder aBrepBuilder;
3143 BRepTools::Read (aSh, theArgVec[anArgIter], aBrepBuilder);
3146 std::cout << "Syntax error: no shape with name " << theArgVec[anArgIter] << " found\n";
3151 else if (aHlrName.IsEmpty())
3153 aHlrName = theArgVec[anArgIter];
3155 else if (!hasViewDirArg
3156 && anArgIter + 8 < theArgNb)
3158 hasViewDirArg = true;
3160 anEye.SetCoord (Draw::Atof (theArgVec[anArgIter + 0]), Draw::Atof (theArgVec[anArgIter + 1]), Draw::Atof (theArgVec[anArgIter + 2]));
3161 aDir .SetCoord (Draw::Atof (theArgVec[anArgIter + 3]), Draw::Atof (theArgVec[anArgIter + 4]), Draw::Atof (theArgVec[anArgIter + 5]));
3162 anUp .SetCoord (Draw::Atof (theArgVec[anArgIter + 6]), Draw::Atof (theArgVec[anArgIter + 7]), Draw::Atof (theArgVec[anArgIter + 8]));
3163 aProjAx.SetLocation (anEye);
3164 aProjAx.SetDirection (aDir);
3165 aProjAx.SetYDirection (anUp);
3170 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n";
3175 if (aHlrName.IsEmpty() || aSh.IsNull()
3176 || (ViewerTest::GetAISContext().IsNull() && hasViewDirArg))
3178 std::cout << "Syntax error: wrong number of arguments\n";
3182 HLRAlgo_Projector aProjector (aProjAx);
3183 TopoDS_Shape aVisible[6];
3184 TopoDS_Shape aHidden[6];
3185 if (anAlgoType == Prs3d_TOH_PolyAlgo)
3187 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3188 aPolyAlgo->Projector (aProjector);
3189 aPolyAlgo->Load (aSh);
3190 aPolyAlgo->Update();
3192 HLRBRep_PolyHLRToShape aHLRToShape;
3193 aHLRToShape.Update (aPolyAlgo);
3195 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3196 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); // extract visible outlines
3197 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3198 if (toShowTangentEdges)
3200 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3202 if (toShowHiddenEdges)
3204 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3205 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3206 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3207 if (toShowTangentEdges)
3209 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3215 Handle(HLRBRep_Algo) aHlrAlgo = new HLRBRep_Algo();
3216 aHlrAlgo->Add (aSh, aNbIsolines);
3217 aHlrAlgo->Projector (aProjector);
3221 HLRBRep_HLRToShape aHLRToShape (aHlrAlgo);
3222 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3223 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound();
3224 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3225 if (toShowTangentEdges)
3227 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3229 aVisible[HLRBRep_IsoLine] = aHLRToShape.IsoLineVCompound();
3231 if (toShowHiddenEdges)
3233 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3234 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3235 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3236 if (toShowTangentEdges)
3238 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3240 aHidden[HLRBRep_IsoLine] = aHLRToShape.IsoLineHCompound();
3243 //aVisible[HLRBRep_Sharp] = aHLRToShape.CompoundOfEdges (HLRBRep_Sharp, Standard_True, Standard_True);
3244 //aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound3d();
3247 TopoDS_Compound aCompRes, aCompVis, aCompHid;
3248 BRep_Builder aBuilder;
3249 aBuilder.MakeCompound (aCompVis);
3250 aBuilder.MakeCompound (aCompHid);
3251 aBuilder.MakeCompound (aCompRes);
3252 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3254 if (!aVisible[aTypeIter].IsNull())
3256 aBuilder.Add (aCompVis, aVisible[aTypeIter]);
3258 if (!aHidden[aTypeIter].IsNull())
3260 aBuilder.Add (aCompHid, aHidden[aTypeIter]);
3263 aBuilder.Add (aCompRes, aCompVis);
3264 aBuilder.Add (aCompRes, aCompHid);
3266 // create an AIS shape and display it
3267 if (!ViewerTest::GetAISContext().IsNull())
3269 Handle(AIS_ColoredShape) anObject = new AIS_ColoredShape (aCompRes);
3270 if (toShowHiddenEdges)
3272 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect (Quantity_Color (Quantity_NOC_RED), Aspect_TOL_DASH, 1.0f);
3273 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3275 if (!aHidden[aTypeIter].IsNull())
3277 Handle(AIS_ColoredDrawer) aDrawer = anObject->CustomAspects (aHidden[aTypeIter]);
3278 aDrawer->SetLineAspect (aLineAspect);
3279 aDrawer->SetWireAspect (aLineAspect);
3280 aDrawer->SetFreeBoundaryAspect (aLineAspect);
3281 aDrawer->SetUnFreeBoundaryAspect (aLineAspect);
3285 ViewerTest::Display (aHlrName, anObject, true);
3288 DBRep::Set (aHlrName.ToCString(), aCompRes);
3292 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3293 // manipulating and displaying such an array with AIS context
3295 class MyPArrayObject : public AIS_InteractiveObject
3300 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives)& thePArray) : myPArray (thePArray) {}
3302 MyPArrayObject (Graphic3d_TypeOfPrimitiveArray thePrimType,
3303 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3304 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect)
3306 Init (thePrimType, theDesc, theMarkerAspect, Standard_False);
3309 //! Initialize the array from specified description.
3310 Standard_Boolean Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3311 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3312 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3313 Standard_Boolean theToPatch);
3315 DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
3317 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
3321 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3322 const Handle(Prs3d_Presentation)& aPresentation,
3323 const Standard_Integer aMode) Standard_OVERRIDE;
3325 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3326 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
3328 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3329 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3330 Standard_Integer &theArgIndex,
3331 Standard_Integer theArgCount,
3332 Standard_Integer theMaxArgs);
3336 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3337 Handle(Graphic3d_ArrayOfPrimitives) myPArray;
3341 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3342 const Handle(Prs3d_Presentation)& thePrs,
3343 const Standard_Integer theMode)
3345 if (myPArray.IsNull() || theMode != 0)
3350 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
3351 if (!myMarkerAspect.IsNull())
3353 aGroup->SetGroupPrimitivesAspect (myMarkerAspect);
3357 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
3359 aGroup->AddPrimitiveArray (myPArray);
3362 Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3363 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3364 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3365 Standard_Boolean theToPatch)
3367 myMarkerAspect = theMarkerAspect;
3373 // Parsing array description
3374 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3375 Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None;
3377 const Standard_Integer anArgsCount = theDesc->Length();
3378 TCollection_AsciiString aCommand;
3379 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3381 aCommand = theDesc->Value (anArgIndex);
3382 aCommand.LowerCase();
3384 if (CheckInputCommand ("-deinterleaved", theDesc, anArgIndex, 0, anArgsCount))
3386 anArrayFlags |= Graphic3d_ArrayFlags_AttribsDeinterleaved;
3388 else if (CheckInputCommand ("-mutable", theDesc, anArgIndex, 0, anArgsCount))
3390 anArrayFlags |= Graphic3d_ArrayFlags_AttribsMutable;
3391 anArrayFlags |= Graphic3d_ArrayFlags_IndexesMutable;
3394 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3396 // vertex has a normal or normal with color or texel
3397 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3399 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal;
3402 // vertex has a color
3403 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3405 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor;
3408 // vertex has a texel
3409 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3411 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel;
3417 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3420 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3422 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor;
3428 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3437 if (myPArray.IsNull())
3439 myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
3443 if (myPArray->Type() != thePrimType
3444 || aVertexNum > myPArray->VertexNumberAllocated()
3445 || aEdgeNum > myPArray->EdgeNumberAllocated()
3446 || aBoundNum > myPArray->BoundNumberAllocated()
3447 || !myPArray->Attributes()->IsMutable()
3448 || (!myPArray->Indices().IsNull() && !myPArray->Indices()->IsMutable()))
3450 std::cout << "Syntax error: array cannot be patched\n";
3451 return Standard_False;
3454 myPArray->Attributes()->NbElements = aVertexNum;
3455 if (Handle(Graphic3d_AttribBuffer) anAttribs = Handle(Graphic3d_AttribBuffer)::DownCast (myPArray->Attributes()))
3457 anAttribs->Invalidate (0, aVertexNum - 1);
3459 if (!myPArray->Indices().IsNull())
3461 myPArray->Indices()->NbElements = aEdgeNum;
3463 if (!myPArray->Bounds().IsNull())
3465 myPArray->Bounds()->NbBounds = aBoundNum;
3469 Standard_Integer aVertIndex = 0;
3470 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3472 aCommand = theDesc->Value (anArgIndex);
3473 aCommand.LowerCase();
3474 if (!aCommand.IsAscii()
3475 || aCommand.IsEmpty())
3480 // skip beautifiers (syntax is not actually validated)
3481 if (aCommand == "-deinterleaved"
3482 || aCommand == "-mutable"
3483 || aCommand.Value (1) == '('
3484 || aCommand.Value (1) == ')'
3485 || aCommand.Value (1) == ',')
3490 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3492 const Graphic3d_Vec3 aVert ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3493 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3494 (float )theDesc->Value (anArgIndex - 1).RealValue());
3495 if ((anArrayFlags & Graphic3d_ArrayFlags_AttribsDeinterleaved) != 0
3496 || (anArrayFlags & Graphic3d_ArrayFlags_AttribsMutable) != 0)
3499 myPArray->SetVertice (aVertIndex, aVert.x(), aVert.y(), aVert.z());
3503 aVertIndex = myPArray->AddVertex (aVert);
3506 // vertex has a normal or normal with color or texel
3507 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3509 const Graphic3d_Vec3 aNorm ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3510 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3511 (float )theDesc->Value (anArgIndex - 1).RealValue());
3512 myPArray->SetVertexNormal (aVertIndex, aNorm.x(), aNorm.y(), aNorm.z());
3515 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3517 const Graphic3d_Vec3d aCol (theDesc->Value (anArgIndex - 3).RealValue(),
3518 theDesc->Value (anArgIndex - 2).RealValue(),
3519 theDesc->Value (anArgIndex - 1).RealValue());
3520 myPArray->SetVertexColor (aVertIndex, aCol.r(), aCol.g(), aCol.b());
3522 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3524 const Graphic3d_Vec2 aTex ((float )theDesc->Value (anArgIndex - 2).RealValue(),
3525 (float )theDesc->Value (anArgIndex - 1).RealValue());
3526 myPArray->SetVertexTexel (aVertIndex, aTex.x(), aTex.y());
3530 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3532 Standard_Integer aVertCount = theDesc->Value (anArgIndex - 1).IntegerValue();
3534 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3535 myPArray->AddBound (aVertCount,
3536 theDesc->Value (anArgIndex - 3).RealValue(),
3537 theDesc->Value (anArgIndex - 2).RealValue(),
3538 theDesc->Value (anArgIndex - 1).RealValue());
3541 myPArray->AddBound (aVertCount);
3544 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3546 const Standard_Integer anEdge = theDesc->Value (anArgIndex - 1).IntegerValue();
3547 myPArray->AddEdge (anEdge);
3552 std::cout << "Syntax error: unknown argument '" << theDesc->Value(anArgIndex) << "'\n";
3553 return Standard_False;
3556 return Standard_True;
3559 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3560 const Standard_Integer theMode)
3563 || myPArray.IsNull())
3568 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
3569 if (Handle(Graphic3d_ArrayOfTriangles) aTris = Handle(Graphic3d_ArrayOfTriangles)::DownCast (myPArray))
3571 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3572 aSensitive->InitTriangulation (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3573 theSelection->Add (aSensitive);
3575 else if (Handle(Graphic3d_ArrayOfSegments) aSegs = Handle(Graphic3d_ArrayOfSegments)::DownCast (myPArray))
3577 if (aSegs->EdgeNumber() > 0)
3579 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->EdgeNumber(); aPntIter += 2)
3581 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aSegs->Edge (aPntIter)), aSegs->Vertice (aSegs->Edge (aPntIter + 1)));
3582 aSeg->SetSensitivityFactor (4);
3583 theSelection->Add (aSeg);
3588 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->VertexNumber(); aPntIter += 2)
3590 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aPntIter), aSegs->Vertice (aPntIter + 1));
3591 aSeg->SetSensitivityFactor (4);
3592 theSelection->Add (aSeg);
3598 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3599 aSensitive->SetSensitivityFactor (8);
3600 aSensitive->InitPoints (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3601 theSelection->Add (aSensitive);
3605 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3606 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3607 Standard_Integer &theArgIndex,
3608 Standard_Integer theArgCount,
3609 Standard_Integer theMaxArgs)
3611 // check if there is more elements than expected
3612 if (theArgIndex >= theMaxArgs)
3615 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3616 aStrCommand.LowerCase();
3617 if (aStrCommand.Search(theCommand) != 1 ||
3618 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3621 // go to the first data element
3624 // check data if it can be converted to numeric
3625 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3627 aStrCommand = theArgsArray->Value (theArgIndex);
3628 if (!aStrCommand.IsRealValue())
3635 //=============================================================================
3636 //function : VDrawPArray
3637 //purpose : Draws primitives array from list of vertexes, bounds, edges
3638 //=============================================================================
3640 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3642 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3643 if (aContextAIS.IsNull())
3645 std::cout << "Error: no active Viewer\n";
3650 std::cout << "Syntax error: wrong number of arguments\n";
3654 // read the arguments
3655 Standard_Integer anArgIndex = 1;
3656 TCollection_AsciiString aName (argv[anArgIndex++]);
3657 TCollection_AsciiString anArrayType (argv[anArgIndex++]);
3658 anArrayType.LowerCase();
3659 Handle(MyPArrayObject) aPObject;
3660 if (anArrayType == "-shape")
3662 Standard_CString aShapeName = argv[anArgIndex++];
3663 TopoDS_Shape aShape = DBRep::Get (aShapeName);
3664 Handle(Graphic3d_ArrayOfPrimitives) aTris = StdPrs_ShadedShape::FillTriangles (aShape);
3665 if (aShape.IsNull())
3667 std::cout << "Syntax error: shape '" << aShapeName << "' is not found\n";
3670 else if (aTris.IsNull())
3672 std::cout << "Syntax error: shape '" << aShapeName << "' is not triangulated\n";
3676 aPObject = new MyPArrayObject (aTris);
3677 ViewerTest::Display (aName, aPObject);
3680 else if (anArrayType == "-patch"
3681 || anArrayType == "-modify"
3682 || anArrayType == "-edit")
3686 anArrayType = argv[anArgIndex++];
3687 anArrayType.LowerCase();
3690 if (GetMapOfAIS().IsBound2 (aName))
3692 aPObject = Handle(MyPArrayObject)::DownCast (GetMapOfAIS().Find2 (aName));
3694 if (aPObject.IsNull())
3696 std::cout << "Syntax error: object '" << aName << "' cannot be found\n";
3701 Standard_Boolean hasVertex = Standard_False;
3703 Graphic3d_TypeOfPrimitiveArray aPrimType = Graphic3d_TOPA_UNDEFINED;
3704 if (anArrayType == "points")
3706 aPrimType = Graphic3d_TOPA_POINTS;
3708 else if (anArrayType == "segments")
3710 aPrimType = Graphic3d_TOPA_SEGMENTS;
3712 else if (anArrayType == "polylines")
3714 aPrimType = Graphic3d_TOPA_POLYLINES;
3716 else if (anArrayType == "triangles")
3718 aPrimType = Graphic3d_TOPA_TRIANGLES;
3720 else if (anArrayType == "trianglefans")
3722 aPrimType = Graphic3d_TOPA_TRIANGLEFANS;
3724 else if (anArrayType == "trianglestrips")
3726 aPrimType = Graphic3d_TOPA_TRIANGLESTRIPS;
3728 else if (anArrayType == "quads")
3730 aPrimType = Graphic3d_TOPA_QUADRANGLES;
3732 else if (anArrayType == "quadstrips")
3734 aPrimType = Graphic3d_TOPA_QUADRANGLESTRIPS;
3736 else if (anArrayType == "polygons")
3738 aPrimType = Graphic3d_TOPA_POLYGONS;
3740 if (aPrimType == Graphic3d_TOPA_UNDEFINED)
3742 std::cout << "Syntax error: unexpected type of primitives array\n";
3746 Standard_Integer aLowerArg = anArgIndex;
3747 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 3);
3748 for (; anArgIndex < argc; ++anArgIndex)
3750 TCollection_AsciiString aCommand (argv[anArgIndex]);
3751 aCommand.LowerCase();
3752 if (!aCommand.IsAscii())
3754 di << "Unexpected argument: #" << anArgIndex - 1 << " , "
3755 << "should be an array element: 'v', 'b', 'e' \n";
3759 if (aCommand == "v")
3761 hasVertex = Standard_True;
3764 anArgsArray->SetValue (anArgIndex - aLowerArg, aCommand);
3769 di << "You should pass any verticies in the list of array elements\n";
3773 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3774 if (aPrimType == Graphic3d_TOPA_POINTS)
3776 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3779 // create primitives array object
3780 if (aPObject.IsNull())
3782 // register the object in map
3783 aPObject = new MyPArrayObject (aPrimType, anArgsArray, anAspPoints);
3784 VDisplayAISObject (aName, aPObject);
3788 aPObject->Init (aPrimType, anArgsArray, anAspPoints, Standard_True);
3789 ViewerTest::CurrentView()->Redraw();
3796 //! Auxiliary function for parsing translation vector - either 2D or 3D.
3797 static Standard_Integer parseTranslationVec (Standard_Integer theArgNb,
3798 const char** theArgVec,
3806 TCollection_AsciiString anX (theArgVec[0]);
3807 TCollection_AsciiString anY (theArgVec[1]);
3808 if (!anX.IsRealValue()
3809 || !anY.IsRealValue())
3814 theVec.SetX (anX.RealValue());
3815 theVec.SetY (anY.RealValue());
3818 TCollection_AsciiString anZ (theArgVec[2]);
3819 if (anZ.IsRealValue())
3821 theVec.SetZ (anZ.RealValue());
3829 //=======================================================================
3830 //function : VSetLocation
3831 //purpose : Change location of AIS interactive object
3832 //=======================================================================
3834 static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
3835 Standard_Integer theArgNb,
3836 const char** theArgVec)
3838 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3839 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3840 if (aContext.IsNull())
3842 std::cout << "Error: no active view!\n";
3846 Standard_Boolean toPrintInfo = Standard_True;
3847 Handle(AIS_InteractiveObject) anObj;
3848 TCollection_AsciiString aCmdName (theArgVec[0]);
3849 aCmdName.LowerCase();
3850 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3852 TCollection_AsciiString anArg = theArgVec[anArgIter];
3854 if (anUpdateTool.parseRedrawMode (anArg))
3858 else if (anObj.IsNull())
3860 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3861 GetMapOfAIS().Find2 (aName, anObj);
3864 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3868 else if (anArg == "-reset")
3870 toPrintInfo = Standard_False;
3871 aContext->SetLocation (anObj, gp_Trsf());
3873 else if (anArg == "-copyfrom"
3874 || anArg == "-copy")
3876 if (anArgIter + 1 >= theArgNb)
3878 std::cout << "Syntax error at '" << anArg << "'\n";
3882 const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]);
3883 Handle(AIS_InteractiveObject) anObj2;
3884 GetMapOfAIS().Find2 (aName2, anObj2);
3885 if (anObj2.IsNull())
3887 std::cout << "Error: object '" << aName2 << "' is not displayed!\n";
3892 aContext->SetLocation (anObj, anObj2->LocalTransformation());
3894 else if (anArg == "-rotate")
3896 toPrintInfo = Standard_False;
3897 if (anArgIter + 7 >= theArgNb)
3899 std::cout << "Syntax error at '" << anArg << "'\n";
3904 aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]),
3905 Draw::Atof (theArgVec[anArgIter + 2]),
3906 Draw::Atof (theArgVec[anArgIter + 3])),
3907 gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]),
3908 Draw::Atof (theArgVec[anArgIter + 5]),
3909 Draw::Atof (theArgVec[anArgIter + 6]))),
3910 Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0));
3913 aTrsf = anObj->LocalTransformation() * aTrsf;
3914 aContext->SetLocation (anObj, aTrsf);
3916 else if (anArg == "-translate")
3918 toPrintInfo = Standard_False;
3920 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
3921 anArgIter += aNbParsed;
3924 std::cout << "Syntax error at '" << anArg << "'\n";
3929 aTrsf.SetTranslationPart (aLocVec);
3930 aTrsf = anObj->LocalTransformation() * aTrsf;
3931 aContext->SetLocation (anObj, aTrsf);
3933 else if (anArg == "-scale"
3934 || anArg == "-setscale")
3936 toPrintInfo = Standard_False;
3938 Standard_Real aScale = 1.0;
3939 Standard_Boolean toPrintScale = Standard_True;
3940 Standard_Boolean hasScaleLoc = Standard_False;
3941 if (anArgIter + 4 < theArgNb)
3943 TCollection_AsciiString aScaleArgs[4] =
3945 TCollection_AsciiString (theArgVec[anArgIter + 1]),
3946 TCollection_AsciiString (theArgVec[anArgIter + 2]),
3947 TCollection_AsciiString (theArgVec[anArgIter + 3]),
3948 TCollection_AsciiString (theArgVec[anArgIter + 4])
3950 Standard_Integer aScaleArgIter = 0;
3951 for (; aScaleArgIter < 4; ++aScaleArgIter)
3953 if (!aScaleArgs[aScaleArgIter].IsRealValue())
3958 if (aScaleArgIter == 4)
3960 aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue());
3961 aScale = aScaleArgs[3].RealValue();
3963 toPrintScale = Standard_False;
3964 hasScaleLoc = Standard_True;
3966 else if (aScaleArgIter >= 1)
3968 aScale = aScaleArgs[0].RealValue();
3970 toPrintScale = Standard_False;
3973 else if (anArgIter + 1 < theArgNb)
3975 TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]);
3976 if (aScaleArg.IsRealValue())
3978 aScale = aScaleArg.RealValue();
3980 toPrintScale = Standard_False;
3986 if (anArg == "-setscale")
3988 std::cout << "Syntax error at '" << anArg << "'\n";
3993 Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor());
3998 if (anArg == "-setscale")
4000 gp_Trsf aTrsf = anObj->LocalTransformation();
4003 aTrsf.SetScale (aScaleLoc, aScale);
4007 aTrsf.SetScaleFactor (aScale);
4009 aContext->SetLocation (anObj, aTrsf);
4016 aTrsf.SetScale (aScaleLoc, aScale);
4017 aTrsf = anObj->LocalTransformation() * aTrsf;
4021 aTrsf = anObj->LocalTransformation();
4022 aTrsf.SetScaleFactor (aTrsf.ScaleFactor() * aScale);
4024 aContext->SetLocation (anObj, aTrsf);
4027 else if (anArg == "-mirror")
4029 toPrintInfo = Standard_False;
4030 if (anArgIter + 6 >= theArgNb)
4032 std::cout << "Syntax error at '" << anArg << "'\n";
4037 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
4038 Draw::Atof(theArgVec[theArgNb - 5]),
4039 Draw::Atof(theArgVec[theArgNb - 4])),
4040 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
4041 Draw::Atof(theArgVec[theArgNb - 2]),
4042 Draw::Atof(theArgVec[theArgNb - 1]))));
4044 aTrsf = anObj->LocalTransformation() * aTrsf;
4045 aContext->SetLocation (anObj, aTrsf);
4047 else if (anArg == "-setrotation"
4048 || anArg == "-rotation")
4050 toPrintInfo = Standard_False;
4051 if (anArgIter + 4 < theArgNb)
4053 TCollection_AsciiString aQuatArgs[4] =
4055 TCollection_AsciiString (theArgVec[anArgIter + 1]),
4056 TCollection_AsciiString (theArgVec[anArgIter + 2]),
4057 TCollection_AsciiString (theArgVec[anArgIter + 3]),
4058 TCollection_AsciiString (theArgVec[anArgIter + 4])
4060 Standard_Integer aQuatArgIter = 0;
4061 for (; aQuatArgIter < 4; ++aQuatArgIter)
4063 if (!aQuatArgs[aQuatArgIter].IsRealValue())
4069 if (aQuatArgIter == 4)
4072 const gp_Quaternion aQuat (aQuatArgs[0].RealValue(),
4073 aQuatArgs[1].RealValue(),
4074 aQuatArgs[2].RealValue(),
4075 aQuatArgs[3].RealValue());
4076 gp_Trsf aTrsf = anObj->LocalTransformation();
4077 aTrsf.SetRotation (aQuat);
4078 aContext->SetLocation (anObj, aTrsf);
4081 else if (anArg == "-setrotation")
4083 std::cout << "Syntax error at '" << anArg << "'\n";
4089 const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation();
4090 Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W());
4093 else if (anArg == "-setlocation"
4094 || anArg == "-location")
4096 toPrintInfo = Standard_False;
4098 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
4099 anArgIter += aNbParsed;
4102 gp_Trsf aTrsf = anObj->LocalTransformation();
4103 aTrsf.SetTranslationPart (aLocVec);
4104 aContext->SetLocation (anObj, aTrsf);
4106 else if (anArg == "-setlocation")
4108 std::cout << "Syntax error at '" << anArg << "'\n";
4113 const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart();
4114 Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z());
4117 else if (aCmdName == "vsetlocation")
4119 // compatibility with old syntax
4121 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec);
4124 std::cout << "Syntax error at '" << anArg << "'\n";
4127 anArgIter = anArgIter + aNbParsed - 1;
4130 aTrsf.SetTranslationPart (aLocVec);
4131 aContext->SetLocation (anObj, aTrsf);
4132 toPrintInfo = Standard_False;
4136 std::cout << "Error: unknown argument '" << anArg << "'\n";
4143 std::cout << "Syntax error - wrong number of arguments\n";
4146 else if (!toPrintInfo)
4151 const gp_Trsf aTrsf = anObj->LocalTransformation();
4152 const gp_XYZ aLoc = aTrsf.TranslationPart();
4153 const gp_Quaternion aRot = aTrsf.GetRotation();
4155 Sprintf (aText, "Location: %g %g %g\n"
4156 "Rotation: %g %g %g %g\n"
4158 aLoc.X(), aLoc.Y(), aLoc.Z(),
4159 aRot.X(), aRot.Y(), aRot.Z(), aRot.W(),
4160 aTrsf.ScaleFactor());
4165 //===============================================================================================
4166 //function : VConnect
4167 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4168 //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
4169 //===============================================================================================
4171 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
4172 Standard_Integer argc,
4176 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4177 if (aContext.IsNull())
4179 std::cout << "vconnect error : call vinit before\n";
4180 return 1; // TCL_ERROR
4185 std::cout << "vconnect error: expect at least 5 arguments\n";
4186 return 1; // TCL_ERROR
4190 Standard_Integer anArgIter = 1;
4191 TCollection_AsciiString aName (argv[anArgIter++]);
4192 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
4193 TCollection_AsciiString aColorString (argv[argc-1]);
4194 Standard_CString aColorName = "";
4195 Standard_Boolean hasColor = Standard_False;
4196 if (aColorString.Search ("color=") != -1)
4198 hasColor = Standard_True;
4199 aColorString.Remove (1, 6);
4200 aColorName = aColorString.ToCString();
4202 Handle(AIS_InteractiveObject) anObject;
4204 // AIS_MultipleConnectedInteractive
4205 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
4206 for (Standard_Integer i = 5; i < aNbShapes; ++i)
4208 TCollection_AsciiString anOriginObjectName (argv[i]);
4209 if (aName.IsEqual (anOriginObjectName))
4211 std::cout << "vconnect error: equal names for connected objects\n";
4214 if (GetMapOfAIS().Find2 (anOriginObjectName, anObject))
4216 if (anObject.IsNull())
4218 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4224 Standard_CString aOriginName = anOriginObjectName.ToCString();
4225 TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4226 if (aTDShape.IsNull())
4228 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4231 anObject = new AIS_Shape (aTDShape);
4232 aContext->Load (anObject);
4233 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
4236 if (anOriginObject.IsNull())
4238 anOriginObject = new AIS_MultipleConnectedInteractive();
4241 anOriginObject->Connect (anObject);
4243 if (anOriginObject.IsNull())
4245 std::cout << "vconect error : can't connect input objects\n";
4246 return 1; // TCL_ERROR
4249 // Get location data
4250 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4251 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4252 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4254 // Create transformation
4255 gp_Vec aTranslation (aXo, aYo, aZo);
4258 aTrsf.SetTranslationPart (aTranslation);
4259 TopLoc_Location aLocation (aTrsf);
4261 anOriginObject->SetLocalTransformation (aTrsf);
4263 // Check if there is another object with given name
4264 // and remove it from context
4265 Handle(AIS_InteractiveObject) anObj;
4266 if (GetMapOfAIS().Find2 (aName, anObj))
4268 TheAISContext()->Remove(anObj, Standard_False);
4269 GetMapOfAIS().UnBind2(aName);
4272 // Bind connected object to its name
4273 GetMapOfAIS().Bind (anOriginObject, aName);
4275 // Display connected object
4276 TheAISContext()->Display (anOriginObject, Standard_True);
4281 //===============================================================================================
4282 //function : VConnectTo
4283 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4284 //Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
4285 //===============================================================================================
4287 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
4288 Standard_Integer argc,
4292 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4293 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4294 if (aContext.IsNull())
4296 std::cout << "vconnect error : call vinit before\n";
4297 return 1; // TCL_ERROR
4300 if (argc != 6 && argc != 7)
4302 std::cout << "vconnect error: expect at least 5 arguments\n";
4303 return 1; // TCL_ERROR
4307 Standard_Integer anArgIter = 1;
4308 TCollection_AsciiString aName (argv[anArgIter++]);
4309 Handle(AIS_InteractiveObject) anOriginObject;
4311 TCollection_AsciiString anOriginObjectName(argv[5]);
4312 if (aName.IsEqual (anOriginObjectName))
4314 std::cout << "vconnect error: equal names for connected objects\n";
4315 return 1; // TCL_ERROR
4317 if (GetMapOfAIS().Find2 (anOriginObjectName, anOriginObject))
4319 if (anOriginObject.IsNull())
4321 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4322 return 1; // TCL_ERROR
4327 Standard_CString aOriginName = anOriginObjectName.ToCString();
4328 TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4329 if (aTDShape.IsNull())
4331 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4332 return 1; // TCL_ERROR
4334 anOriginObject = new AIS_Shape (aTDShape);
4335 GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
4338 // Get location data
4339 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4340 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4341 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4343 // Create transformation
4344 gp_Vec aTranslation (aXo, aYo, aZo);
4347 aTrsf.SetTranslationPart (aTranslation);
4349 Handle(AIS_ConnectedInteractive) aConnected;
4351 aConnected = new AIS_ConnectedInteractive();
4353 aConnected->Connect (anOriginObject, aTrsf);
4355 // Check if there is another object with given name
4356 // and remove it from context
4357 Handle(AIS_InteractiveObject) anObj;
4358 if (GetMapOfAIS().Find2 (aName, anObj))
4360 TheAISContext()->Remove (anObj, Standard_False);
4361 GetMapOfAIS().UnBind2(aName);
4364 // Bind connected object to its name
4365 GetMapOfAIS().Bind (aConnected, aName);
4369 TCollection_AsciiString anArg = argv[6];
4371 if (anArg == "-nodisplay")
4374 if (!anUpdateTool.parseRedrawMode (anArg))
4376 std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
4380 // Display connected object
4381 TheAISContext()->Display (aConnected, Standard_False);
4386 //=======================================================================
4387 //function : VDisconnect
4389 //=======================================================================
4390 static Standard_Integer VDisconnect (Draw_Interpretor& di,
4391 Standard_Integer argc,
4394 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4395 if (aContext.IsNull())
4397 std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4403 std::cout << "ERROR : Usage : " << argv[0] << " name object\n";
4407 TCollection_AsciiString aName (argv[1]);
4408 TCollection_AsciiString anObject (argv[2]);
4409 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
4412 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4413 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4414 if (!aMap.IsBound2 (aName) )
4416 std::cout << "Use 'vdisplay' before\n";
4420 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4421 if (anAssembly.IsNull())
4423 di << "Not an assembly\n";
4427 Handle(AIS_InteractiveObject) anIObj;
4428 if (!aMap.Find2 (anObject, anIObj))
4430 // try to interpret second argument as child number
4431 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
4433 Standard_Integer aCounter = 1;
4434 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4436 if (aCounter == anObjectNumber)
4438 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4446 std::cout << "Use 'vdisplay' before\n";
4451 aContext->Disconnect (anAssembly, anIObj);
4452 aContext->UpdateCurrentViewer();
4456 //=======================================================================
4457 //function : VAddConnected
4459 //=======================================================================
4460 static Standard_Integer VAddConnected (Draw_Interpretor& di,
4461 Standard_Integer argc,
4464 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4465 if (aContext.IsNull())
4467 std::cout << argv[0] << "error : use 'vinit' command before \n";
4473 std::cout << argv[0] << " error: expect 5 arguments\n";
4477 TCollection_AsciiString aName (argv[1]);
4478 TCollection_AsciiString anObject (argv[5]);
4479 Standard_Real aX = Draw::Atof (argv[2]);
4480 Standard_Real aY = Draw::Atof (argv[3]);
4481 Standard_Real aZ = Draw::Atof (argv[4]);
4484 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4485 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4486 if (!aMap.IsBound2 (aName) )
4488 std::cout << "Use 'vdisplay' before\n";
4492 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4493 if (anAssembly.IsNull())
4495 di << "Not an assembly\n";
4499 Handle(AIS_InteractiveObject) anIObj;
4500 if (!aMap.Find2 (anObject, anIObj))
4502 std::cout << "Use 'vdisplay' before\n";
4507 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4509 anAssembly->Connect (anIObj, aTrsf);
4510 TheAISContext()->Display (anAssembly, Standard_False);
4511 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4512 aContext->UpdateCurrentViewer();
4517 //=======================================================================
4518 //function : VListConnected
4520 //=======================================================================
4521 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4522 Standard_Integer argc,
4525 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4526 if (aContext.IsNull())
4528 std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4534 std::cout << "ERROR : Usage : " << argv[0] << " name\n";
4538 TCollection_AsciiString aName (argv[1]);
4541 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4542 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4543 if (!aMap.IsBound2 (aName) )
4545 std::cout << "Use 'vdisplay' before\n";
4549 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4550 if (anAssembly.IsNull())
4552 std::cout << "Not an assembly\n";
4556 std::cout << "Children of " << aName << ":\n";
4558 Standard_Integer aCounter = 1;
4559 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4561 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4562 if (GetMapOfAIS().IsBound1 (anObj))
4564 TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anObj);
4565 std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4568 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4570 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4571 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4573 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4575 std::cout << std::endl;
4583 //===============================================================================================
4584 //function : VSetSelectionMode
4585 //purpose : vselmode
4586 //===============================================================================================
4587 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4588 Standard_Integer theNbArgs,
4589 const char** theArgv)
4592 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4593 if (anAISContext.IsNull())
4595 std::cout << "Error: no active Viewer\n";
4599 NCollection_Sequence<TCollection_AsciiString> anObjNames;
4600 Standard_Integer aSelectionMode = -1;
4601 Standard_Boolean toTurnOn = Standard_True;
4602 AIS_SelectionModesConcurrency aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4603 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4605 TCollection_AsciiString anArgCase (theArgv[anArgIter]);
4606 anArgCase.LowerCase();
4607 if (anArgCase == "-set"
4608 || anArgCase == "-replace"
4609 || anArgCase == "-single"
4610 || anArgCase == "-exclusive")
4612 aSelModeConcurrency = AIS_SelectionModesConcurrency_Single;
4614 else if (anArgCase == "-add"
4615 || anArgCase == "-combine"
4616 || anArgCase == "-combination"
4617 || anArgCase == "-multiple")
4619 aSelModeConcurrency = AIS_SelectionModesConcurrency_Multiple;
4621 else if (anArgCase == "-globalorlocal"
4622 || anArgCase == "-localorglobal")
4624 aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4628 anObjNames.Append (theArgv[anArgIter]);
4631 if (anObjNames.Size() < 2
4632 || !ViewerTest::ParseOnOff (anObjNames.Last().ToCString(), toTurnOn))
4634 std::cout << "Syntax error: wrong number of arguments\n";
4637 anObjNames.Remove (anObjNames.Upper());
4639 const TCollection_AsciiString aSelModeString = anObjNames.Last();
4640 anObjNames.Remove (anObjNames.Upper());
4641 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4642 if (aSelModeString.IsIntegerValue())
4644 aSelectionMode = aSelModeString.IntegerValue();
4646 else if (TopAbs::ShapeTypeFromString (aSelModeString.ToCString(), aShapeType))
4648 aSelectionMode = AIS_Shape::SelectionMode (aShapeType);
4652 std::cout << "Syntax error: unknown selection mode '" << aSelModeString << "'\n";
4657 AIS_ListOfInteractive aTargetIOs;
4658 for (NCollection_Sequence<TCollection_AsciiString>::Iterator anObjIter (anObjNames); anObjIter.More(); anObjIter.Next())
4660 const TCollection_AsciiString& aNameIO = anObjIter.Value();
4661 Handle(AIS_InteractiveObject) anIO;
4662 GetMapOfAIS().Find2 (aNameIO, anIO);
4665 std::cout << "Syntax error: undefined presentable object " << aNameIO << "\n";
4668 aTargetIOs.Append (anIO);
4670 if (aTargetIOs.IsEmpty())
4672 anAISContext->DisplayedObjects (aTargetIOs);
4675 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4677 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4678 anAISContext->SetSelectionModeActive (anIO, aSelectionMode, toTurnOn, aSelModeConcurrency);
4683 //===============================================================================================
4684 //function : VSelectionNext
4686 //===============================================================================================
4687 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4688 Standard_Integer /*theArgsNb*/,
4689 const char** /*theArgVec*/)
4692 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4693 Handle(V3d_View) aView = ViewerTest::CurrentView();
4695 if (anAISContext.IsNull())
4697 std::cerr << "Call vinit before!" << std::endl;
4701 anAISContext->HilightNextDetected (aView);
4705 //===============================================================================================
4706 //function : VSelectionPrevious
4708 //===============================================================================================
4709 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4710 Standard_Integer /*theArgsNb*/,
4711 const char** /*theArgVec*/)
4714 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4715 Handle(V3d_View) aView = ViewerTest::CurrentView();
4717 if (anAISContext.IsNull())
4719 std::cerr << "Call vinit before!" << std::endl;
4723 anAISContext->HilightPreviousDetected (aView);
4727 //===========================================================================
4728 //function : VTriangle
4729 //Draw arg : vtriangle Name PointName PointName PointName
4730 //purpose : creates and displays Triangle
4731 //===========================================================================
4732 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4733 Standard_Integer argc,
4736 const Standard_Boolean isTri = TCollection_AsciiString (argv[0]) == "vtriangle";
4737 Handle(Graphic3d_ArrayOfPrimitives) aPrims;
4740 aPrims = new Graphic3d_ArrayOfTriangles (3);
4744 aPrims = new Graphic3d_ArrayOfSegments (2);
4747 if (argc != (2 + aPrims->VertexNumberAllocated()))
4749 std::cout << "Syntax error: wrong number of arguments\n";
4754 for (Standard_Integer aPntIter = 0; aPntIter < aPrims->VertexNumberAllocated(); ++aPntIter)
4756 const TCollection_AsciiString aName (argv[2 + aPntIter]);
4757 if (Handle(AIS_Point) aPntPrs = Handle(AIS_Point)::DownCast (GetMapOfAIS().IsBound2 (aName) ? GetMapOfAIS().Find2 (aName) : NULL))
4759 aPnts[aPntIter] = aPntPrs->Component()->Pnt();
4763 TopoDS_Shape aShape = DBRep::Get (argv[2 + aPntIter]);
4765 || aShape.ShapeType() != TopAbs_VERTEX)
4767 std::cout << "Syntax error: argument " << aName << " must be a point\n";
4770 aPnts[aPntIter] = BRep_Tool::Pnt (TopoDS::Vertex (aShape));
4773 for (Standard_Integer aPnt2Iter = 0; aPnt2Iter < aPntIter; ++aPnt2Iter)
4775 if (aPnts[aPnt2Iter].IsEqual (aPnts[aPntIter], Precision::Confusion()))
4777 std::cout << "Syntax error: points should not be equal\n";
4782 aPrims->AddVertex (aPnts[aPntIter]);
4785 Handle(AIS_InteractiveObject) aPrs = new MyPArrayObject (aPrims);
4788 aPrs->Attributes()->SetupOwnShadingAspect();
4789 aPrs->Attributes()->ShadingAspect()->Aspect()->SetColor (aPrs->Attributes()->LineAspect()->Aspect()->Color());
4791 ViewerTest::Display (argv[1], aPrs);
4795 //=======================================================================
4796 //function : VObjZLayer
4797 //purpose : Set or get z layer id for presentable object
4798 //=======================================================================
4800 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4801 Standard_Integer argc,
4804 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4805 if (aContext.IsNull())
4807 di << argv[0] << "Call 'vinit' before!\n";
4812 TCollection_AsciiString aOperation;
4814 aOperation = TCollection_AsciiString (argv [1]);
4816 // check for correct arguments
4817 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4818 !(argc == 3 && aOperation.IsEqual ("get")))
4820 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4821 di << " set - set layer id for interactive object, layerid - z layer id\n";
4822 di << " get - get layer id of interactive object\n";
4823 di << " argument layerid should be passed for set operation only\n";
4828 TCollection_AsciiString aName (argv[2]);
4829 Handle(AIS_InteractiveObject) anInterObj;
4830 GetMapOfAIS().Find2 (aName, anInterObj);
4831 if (anInterObj.IsNull())
4833 std::cout << "Syntax error: object '" << aName << "' is not displayed\n";
4837 // process operation
4838 if (aOperation.IsEqual ("set"))
4840 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
4841 aContext->SetZLayer (anInterObj, aLayerId);
4843 else if (aOperation.IsEqual ("get"))
4845 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4851 //=======================================================================
4852 //function : VPolygonOffset
4853 //purpose : Set or get polygon offset parameters
4854 //=======================================================================
4855 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
4856 Standard_Integer argc,
4859 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4860 if (aContext.IsNull())
4862 std::cout << argv[0] << " Call 'vinit' before!\n";
4866 if (argc > 2 && argc != 5)
4868 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4869 "without arguments prints the default values" << std::endl;
4874 Handle(AIS_InteractiveObject) anInterObj;
4877 TCollection_AsciiString aName (argv[1]);
4878 if (!GetMapOfAIS().Find2 (aName, anInterObj)
4879 || anInterObj.IsNull())
4881 std::cout << "Syntax error: object '" << aName << "' is not displayed\n";
4886 Standard_Integer aMode;
4887 Standard_ShortReal aFactor, aUnits;
4890 aMode = Draw::Atoi(argv[2]);
4891 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4892 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
4894 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4895 aContext->UpdateCurrentViewer();
4900 if (anInterObj->HasPolygonOffsets())
4902 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4903 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4904 std::cout << "\tMode: " << aMode << std::endl;
4905 std::cout << "\tFactor: " << aFactor << std::endl;
4906 std::cout << "\tUnits: " << aUnits << std::endl;
4911 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4915 std::cout << "Default polygon offset parameters:" << std::endl;
4916 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4917 std::cout << "\tMode: " << aMode << std::endl;
4918 std::cout << "\tFactor: " << aFactor << std::endl;
4919 std::cout << "\tUnits: " << aUnits << std::endl;
4924 // This class is used for testing markers.
4925 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
4930 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
4931 const Standard_Integer& thePointsOnSide,
4932 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
4934 myStartPoint = theStartPoint;
4935 myPointsOnSide = thePointsOnSide;
4936 myMarkerAspect = theMarkerAspect;
4939 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_MarkersArrayObject,AIS_InteractiveObject);
4943 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
4944 const Handle(Prs3d_Presentation)& aPresentation,
4945 const Standard_Integer aMode) Standard_OVERRIDE;
4947 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4948 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
4952 gp_XYZ myStartPoint;
4953 Standard_Integer myPointsOnSide;
4954 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
4958 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
4959 const Handle(Prs3d_Presentation)& aPresentation,
4960 const Standard_Integer /*aMode*/)
4962 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
4963 if (myPointsOnSide == 1)
4965 anArray->AddVertex (myStartPoint);
4969 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4971 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4973 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4975 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4976 anArray->SetVertexColor (anArray->VertexNumber(),
4979 k / myPointsOnSide);
4985 aPresentation->Clear();
4986 if (!myMarkerAspect.IsNull())
4988 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
4990 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
4993 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4994 const Standard_Integer /*theMode*/)
4996 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
4998 if (myPointsOnSide == 1)
5000 gp_Pnt aPoint (myStartPoint);
5001 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5002 theSelection->Add (aSensetivePoint);
5006 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5008 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5010 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5012 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5013 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5014 theSelection->Add (aSensetivePoint);
5020 //=======================================================================
5021 //function : VMarkersTest
5022 //purpose : Draws an array of markers for testing purposes.
5023 //=======================================================================
5024 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5025 Standard_Integer theArgNb,
5026 const char** theArgVec)
5028 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5029 if (aContext.IsNull())
5031 std::cerr << "Call 'vinit' before!\n";
5037 std::cerr << "Usage :\n " << theArgVec[0]
5038 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5042 Standard_Integer anArgIter = 1;
5044 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5045 TCollection_AsciiString aFileName;
5046 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5047 Atof (theArgVec[anArgIter + 1]),
5048 Atof (theArgVec[anArgIter + 2]));
5051 Standard_Integer aPointsOnSide = 10;
5052 Standard_Integer aMarkerType = -1;
5053 Standard_Real aScale = 1.0;
5054 for (; anArgIter < theArgNb; ++anArgIter)
5056 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5057 if (anArg.Search ("PointsOnSide=") > -1)
5059 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5061 else if (anArg.Search ("MarkerType=") > -1)
5063 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5065 else if (anArg.Search ("Scale=") > -1)
5067 aScale = anArg.Token ("=", 2).RealValue();
5069 else if (anArg.Search ("FileName=") > -1)
5071 aFileName = anArg.Token ("=", 2);
5075 std::cerr << "Wrong argument: " << anArg << "\n";
5080 Handle(Graphic3d_AspectMarker3d) anAspect;
5081 Handle(Image_AlienPixMap) anImage;
5082 Quantity_Color aColor (Quantity_NOC_GREEN1);
5083 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5084 && !aFileName.IsEmpty())
5086 anImage = new Image_AlienPixMap();
5087 if (!anImage->Load (aFileName))
5089 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5092 if (anImage->Format() == Image_Format_Gray)
5094 anImage->SetFormat (Image_Format_Alpha);
5096 else if (anImage->Format() == Image_Format_GrayF)
5098 anImage->SetFormat (Image_Format_AlphaF);
5100 anAspect = new Graphic3d_AspectMarker3d (anImage);
5104 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5107 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5108 VDisplayAISObject (aName, aMarkersArray);
5113 //=======================================================================
5114 //function : TextToBrep
5115 //purpose : Tool for conversion text to occt-shapes
5116 //=======================================================================
5117 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5118 Standard_Integer theArgNb,
5119 const char** theArgVec)
5124 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5128 Standard_Integer anArgIt = 1;
5129 Standard_CString aName = theArgVec[anArgIt++];
5130 Standard_CString aText = theArgVec[anArgIt++];
5132 Font_BRepFont aFont;
5133 TCollection_AsciiString aFontName ("Courier");
5134 Standard_Real aTextHeight = 16.0;
5135 Font_FontAspect aFontAspect = Font_FA_Regular;
5136 Standard_Boolean anIsCompositeCurve = Standard_False;
5137 gp_Ax3 aPenAx3 (gp::XOY());
5138 gp_Dir aNormal (0.0, 0.0, 1.0);
5139 gp_Dir aDirection (1.0, 0.0, 0.0);
5142 Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT;
5143 Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM;
5145 for (; anArgIt < theArgNb; ++anArgIt)
5147 TCollection_AsciiString aParam (theArgVec[anArgIt]);
5150 if (aParam == "-pos"
5151 || aParam == "-position")
5153 if (anArgIt + 3 >= theArgNb)
5155 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5159 aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt]));
5160 aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt]));
5161 aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt]));
5163 else if (aParam == "-halign")
5165 if (++anArgIt >= theArgNb)
5167 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5171 TCollection_AsciiString aType (theArgVec[anArgIt]);
5173 if (aType == "left")
5175 aHJustification = Graphic3d_HTA_LEFT;
5177 else if (aType == "center")
5179 aHJustification = Graphic3d_HTA_CENTER;
5181 else if (aType == "right")
5183 aHJustification = Graphic3d_HTA_RIGHT;
5187 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5191 else if (aParam == "-valign")
5193 if (++anArgIt >= theArgNb)
5195 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5199 TCollection_AsciiString aType (theArgVec[anArgIt]);
5203 aVJustification = Graphic3d_VTA_TOP;
5205 else if (aType == "center")
5207 aVJustification = Graphic3d_VTA_CENTER;
5209 else if (aType == "bottom")
5211 aVJustification = Graphic3d_VTA_BOTTOM;
5213 else if (aType == "topfirstline")
5215 aVJustification = Graphic3d_VTA_TOPFIRSTLINE;
5219 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5223 else if (aParam == "-height")
5225 if (++anArgIt >= theArgNb)
5227 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5231 aTextHeight = Draw::Atof(theArgVec[anArgIt]);
5233 else if (aParam == "-aspect")
5235 if (++anArgIt >= theArgNb)
5237 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5241 TCollection_AsciiString anOption (theArgVec[anArgIt]);
5242 anOption.LowerCase();
5243 if (!parseFontStyle (anOption, aFontAspect))
5245 std::cout << "Error: unknown font aspect '" << anOption << "'.\n";
5249 else if (aParam == "-font")
5251 if (++anArgIt >= theArgNb)
5253 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5257 aFontName = theArgVec[anArgIt];
5259 else if (aParam == "-composite")
5261 if (++anArgIt >= theArgNb)
5263 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5267 ViewerTest::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve);
5269 else if (aParam == "-plane")
5271 if (anArgIt + 6 >= theArgNb)
5273 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5277 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
5278 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
5279 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
5280 aNormal.SetCoord (aX, aY, aZ);
5282 aX = Draw::Atof (theArgVec[++anArgIt]);
5283 aY = Draw::Atof (theArgVec[++anArgIt]);
5284 aZ = Draw::Atof (theArgVec[++anArgIt]);
5285 aDirection.SetCoord (aX, aY, aZ);
5289 std::cerr << "Warning! Unknown argument '" << aParam << "'\n";
5293 aFont.SetCompositeCurveMode (anIsCompositeCurve);
5294 if (!aFont.Init (aFontName.ToCString(), aFontAspect, aTextHeight))
5296 std::cerr << "Font initialization error\n";
5300 aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection);
5302 Font_BRepTextBuilder aBuilder;
5303 DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification));
5307 //=======================================================================
5309 //purpose : Font management
5310 //=======================================================================
5312 static int VFont (Draw_Interpretor& theDI,
5313 Standard_Integer theArgNb,
5314 const char** theArgVec)
5316 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5319 // just print the list of available fonts
5320 Standard_Boolean isFirst = Standard_True;
5321 const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts();
5322 for (Font_NListOfSystemFont::Iterator anIter (aFonts); anIter.More(); anIter.Next())
5324 const Handle(Font_SystemFont)& aFont = anIter.Value();
5330 theDI << aFont->ToString();
5331 isFirst = Standard_False;
5336 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5338 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5339 TCollection_AsciiString anArgCase (anArg);
5340 anArgCase.LowerCase();
5341 if (anArgIter + 1 < theArgNb
5342 && (anArgCase == "-find"
5343 || anArgCase == "find"))
5345 Standard_CString aFontName = theArgVec[++anArgIter];
5346 Font_FontAspect aFontAspect = Font_FA_Undefined;
5347 if (++anArgIter < theArgNb)
5349 anArgCase = theArgVec[anArgIter];
5350 anArgCase.LowerCase();
5351 if (!parseFontStyle (anArgCase, aFontAspect))
5357 if (Handle(Font_SystemFont) aFont = aMgr->FindFont (aFontName, aFontAspect))
5359 theDI << aFont->ToString();
5363 std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5366 else if (anArgIter + 1 < theArgNb
5367 && (anArgCase == "-add"
5368 || anArgCase == "add"
5369 || anArgCase == "-register"
5370 || anArgCase == "register"))
5373 Standard_CString aFontPath = theArgVec[anArgIter++];
5374 TCollection_AsciiString aFontName;
5375 Font_FontAspect aFontAspect = Font_FA_Undefined;
5376 Standard_Integer isSingelStroke = -1;
5377 for (; anArgIter < theArgNb; ++anArgIter)
5379 anArgCase = theArgVec[anArgIter];
5380 anArgCase.LowerCase();
5381 if (aFontAspect == Font_FontAspect_UNDEFINED
5382 && parseFontStyle (anArgCase, aFontAspect))
5386 else if (anArgCase == "singlestroke"
5387 || anArgCase == "singleline"
5388 || anArgCase == "oneline")
5392 else if (aFontName.IsEmpty())
5394 aFontName = theArgVec[anArgIter];
5403 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5406 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5410 if (aFontAspect != Font_FontAspect_UNDEFINED
5411 || !aFontName.IsEmpty())
5413 TCollection_AsciiString aName = aFont->FontName();
5414 if (!aFontName.IsEmpty())
5418 Handle(Font_SystemFont) aFont2 = new Font_SystemFont (aName);
5419 if (aFontAspect != Font_FontAspect_UNDEFINED)
5421 aFont2->SetFontPath (aFontAspect, aFontPath);
5425 for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
5427 aFont2->SetFontPath ((Font_FontAspect )anAspectIter, aFont->FontPath ((Font_FontAspect )anAspectIter));
5432 if (isSingelStroke != -1)
5434 aFont->SetSingleStrokeFont (isSingelStroke == 1);
5437 aMgr->RegisterFont (aFont, Standard_True);
5438 theDI << aFont->ToString();
5440 else if (anArgCase == "-verbose"
5441 || anArgCase == "-trace")
5443 bool toEnable = true;
5444 if (anArgIter + 1 < theArgNb
5445 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
5449 aMgr->SetTraceAliases (toEnable);
5453 std::cerr << "Warning! Unknown argument '" << anArg << "'\n";
5460 //=======================================================================
5461 //function : VVertexMode
5462 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
5463 //=======================================================================
5465 static int VVertexMode (Draw_Interpretor& theDI,
5466 Standard_Integer theArgNum,
5467 const char** theArgs)
5469 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5470 if (aContext.IsNull())
5472 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5476 // No arguments --> print the current default vertex draw mode
5479 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5480 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5484 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5485 TCollection_AsciiString aParam (theArgs[1]);
5486 if (aParam == "-set")
5490 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5491 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5495 TCollection_AsciiString aModeStr (theArgs[2]);
5496 Prs3d_VertexDrawMode aNewMode =
5497 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5498 (aModeStr == "all" ? Prs3d_VDM_All :
5499 Prs3d_VDM_Inherited);
5501 Standard_Boolean aRedrawNeeded = Standard_False;
5502 AIS_ListOfInteractive anObjs;
5504 // No object(s) specified -> use all displayed
5507 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5508 aContext->DisplayedObjects (anObjs);
5509 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5510 aRedrawNeeded = Standard_True;
5513 Handle(AIS_InteractiveObject) anObject;
5514 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5516 TCollection_AsciiString aName (theArgs[aCount]);
5517 if (!GetMapOfAIS().Find2 (aName, anObject))
5519 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5522 anObjs.Append (anObject);
5525 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5527 anObject = anIt.Value();
5528 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5529 aContext->Redisplay (anObject, Standard_False);
5530 aRedrawNeeded = Standard_True;
5534 ViewerTest::CurrentView()->Redraw();
5539 Handle(AIS_InteractiveObject) anObject;
5541 || !GetMapOfAIS().Find2 (aParam, anObject))
5543 std::cout << "Error: invalid number of arguments" << std::endl;
5547 // One argument (object name) --> print the current vertex draw mode for the object
5548 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5549 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5553 //=======================================================================
5554 //function : VPointCloud
5555 //purpose : Create interactive object for arbitary set of points.
5556 //=======================================================================
5557 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5558 Standard_Integer theArgNum,
5559 const char** theArgs)
5561 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5562 if (anAISContext.IsNull())
5564 std::cerr << "Error: no active view!\n";
5568 // command to execute
5571 CloudForShape, // generate point cloud for shape
5572 CloudSphere, // generate point cloud for generic sphere
5576 // count number of non-optional command arguments
5577 Command aCmd = Unknow;
5578 Standard_Integer aCmdArgs = 0;
5579 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5581 Standard_CString anArg = theArgs[anArgIter];
5582 TCollection_AsciiString aFlag (anArg);
5584 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5591 case 2 : aCmd = CloudForShape; break;
5592 case 7 : aCmd = CloudSphere; break;
5594 std::cout << "Error: wrong number of arguments! See usage:\n";
5595 theDI.PrintHelp (theArgs[0]);
5600 Standard_Boolean toRandColors = Standard_False;
5601 Standard_Boolean hasNormals = Standard_True;
5602 Standard_Boolean isSetArgNorm = Standard_False;
5603 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5605 Standard_CString anArg = theArgs[anArgIter];
5606 TCollection_AsciiString aFlag (anArg);
5608 if (aFlag == "-randcolors"
5609 || aFlag == "-randcolor")
5611 if (isSetArgNorm && hasNormals)
5613 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5616 toRandColors = Standard_True;
5617 hasNormals = Standard_False;
5619 else if (aFlag == "-normals"
5620 || aFlag == "-normal")
5624 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5627 isSetArgNorm = Standard_True;
5628 hasNormals = Standard_True;
5630 else if (aFlag == "-nonormals"
5631 || aFlag == "-nonormal")
5633 isSetArgNorm = Standard_True;
5634 hasNormals = Standard_False;
5638 Standard_CString aName = theArgs[1];
5640 // generate arbitrary set of points
5641 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
5642 if (aCmd == CloudForShape)
5644 Standard_CString aShapeName = theArgs[2];
5645 TopoDS_Shape aShape = DBRep::Get (aShapeName);
5647 if (aShape.IsNull())
5649 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
5653 // calculate number of points
5654 TopLoc_Location aLocation;
5655 Standard_Integer aNbPoints = 0;
5656 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5658 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5659 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5660 if (!aTriangulation.IsNull())
5662 aNbPoints += aTriangulation->NbNodes();
5667 std::cout << "Error: shape should be triangulated!\n";
5671 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5672 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5674 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5675 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5676 if (aTriangulation.IsNull())
5681 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
5682 const gp_Trsf& aTrsf = aLocation.Transformation();
5684 // extract normals from nodes
5685 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
5688 Poly_Connect aPolyConnect (aTriangulation);
5689 StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
5692 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
5694 gp_Pnt aPoint = aNodes (aNodeIter);
5695 if (!aLocation.IsIdentity())
5697 aPoint.Transform (aTrsf);
5700 aNormals (aNodeIter).Transform (aTrsf);
5704 // add vertex into array of points
5705 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5708 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
5709 1.0, 0.5, Quantity_TOC_HLS);
5710 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5715 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
5720 else if (aCmd == CloudSphere)
5722 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
5723 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
5724 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
5725 Standard_Real aRadius = Draw::Atof (theArgs[5]);
5726 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
5728 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
5729 aDistribution.LowerCase();
5730 if ( aDistribution != "surface" && aDistribution != "volume" )
5732 std::cout << "Error: wrong arguments! See usage:\n";
5733 theDI.PrintHelp (theArgs[0]);
5736 Standard_Boolean isSurface = aDistribution == "surface";
5738 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
5740 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5741 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
5743 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5744 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5745 Standard_Real aDistance = isSurface ?
5746 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
5748 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
5750 Cos (anAlpha) * Cos (aBeta));
5751 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
5753 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5756 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
5757 1.0, 0.5, Quantity_TOC_HLS);
5758 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5763 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
5768 // set array of points in point cloud object
5769 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
5770 aPointCloud->SetPoints (anArrayPoints);
5771 VDisplayAISObject (aName, aPointCloud);
5775 //=======================================================================
5776 //function : VPriority
5777 //purpose : Prints or sets the display priority for an object
5778 //=======================================================================
5780 static int VPriority (Draw_Interpretor& theDI,
5781 Standard_Integer theArgNum,
5782 const char** theArgs)
5784 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5785 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5786 if (aContext.IsNull())
5788 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5792 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
5793 Standard_Integer aPriority = -1;
5794 Standard_Integer aNbArgs = theArgNum;
5795 if (aLastArg.IsIntegerValue())
5797 aPriority = aLastArg.IntegerValue();
5799 if (aPriority < 0 || aPriority > 10)
5801 std::cout << "Error: the specified display priority value '" << aLastArg
5802 << "' is outside the valid range [0..10]" << std::endl;
5808 anUpdateTool.Invalidate();
5813 std::cout << "Error: wrong number of arguments! See usage:\n";
5814 theDI.PrintHelp (theArgs[0]);
5818 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
5820 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
5825 TCollection_AsciiString aName (theArgs[anArgIter]);
5826 Handle(AIS_InteractiveObject) anIObj;
5827 GetMapOfAIS().Find2 (aName, anIObj);
5828 if (anIObj.IsNull())
5830 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
5836 theDI << aContext->DisplayPriority (anIObj) << " ";
5840 aContext->SetDisplayPriority (anIObj, aPriority);
5846 //! Auxiliary class for command vnormals.
5847 class MyShapeWithNormals : public AIS_Shape
5849 DEFINE_STANDARD_RTTI_INLINE(MyShapeWithNormals, AIS_Shape);
5852 Standard_Real NormalLength;
5853 Standard_Integer NbAlongU;
5854 Standard_Integer NbAlongV;
5855 Standard_Boolean ToUseMesh;
5856 Standard_Boolean ToOrient;
5860 //! Main constructor.
5861 MyShapeWithNormals (const TopoDS_Shape& theShape)
5862 : AIS_Shape (theShape),
5866 ToUseMesh (Standard_False),
5867 ToOrient (Standard_False) {}
5871 //! Comnpute presentation.
5872 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
5873 const Handle(Prs3d_Presentation)& thePrs,
5874 const Standard_Integer theMode) Standard_OVERRIDE
5876 AIS_Shape::Compute (thePrsMgr, thePrs, theMode);
5878 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormalMap;
5881 DBRep_DrawableShape::addMeshNormals (aNormalMap, myshape, NormalLength);
5885 DBRep_DrawableShape::addSurfaceNormals (aNormalMap, myshape, NormalLength, NbAlongU, NbAlongV);
5888 Handle(Graphic3d_Group) aPrsGroup = Prs3d_Root::NewGroup (thePrs);
5889 aPrsGroup->SetGroupPrimitivesAspect (myDrawer->ArrowAspect()->Aspect());
5891 const Standard_Real aArrowAngle = myDrawer->ArrowAspect()->Angle();
5892 const Standard_Real aArrowLength = myDrawer->ArrowAspect()->Length();
5893 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormalMap);
5894 aFaceIt.More(); aFaceIt.Next())
5896 const Standard_Boolean toReverse = ToOrient && aFaceIt.Key().Orientation() == TopAbs_REVERSED;
5897 Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (2 * aFaceIt.Value().Size());
5898 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aPntIt (aFaceIt.Value()); aPntIt.More(); aPntIt.Next())
5900 std::pair<gp_Pnt, gp_Pnt> aPair = aPntIt.Value();
5903 const gp_Vec aDir = aPair.first.XYZ() - aPair.second.XYZ();
5904 aPair.second = aPair.first.XYZ() + aDir.XYZ();
5907 aSegments->AddVertex (aPair.first);
5908 aSegments->AddVertex (aPair.second);
5909 Prs3d_Arrow::Draw (aPrsGroup, aPair.second, gp_Vec(aPair.first, aPair.second), aArrowAngle, aArrowLength);
5912 aPrsGroup->AddPrimitiveArray (aSegments);
5918 //=======================================================================
5919 //function : VNormals
5920 //purpose : Displays/Hides normals calculated on shape geometry or retrieved from triangulation
5921 //=======================================================================
5922 static int VNormals (Draw_Interpretor& theDI,
5923 Standard_Integer theArgNum,
5924 const char** theArgs)
5926 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5927 if (aContext.IsNull())
5929 std::cout << "Error: no view available, call 'vinit' before!\n";
5932 else if (theArgNum < 2)
5934 std::cout << "Error: wrong number of arguments! See usage:\n";
5935 theDI.PrintHelp (theArgs[0]);
5939 Standard_Integer anArgIter = 1;
5940 Standard_CString aShapeName = theArgs[anArgIter++];
5941 TopoDS_Shape aShape = DBRep::Get (aShapeName);
5942 Standard_Boolean isOn = Standard_True;
5943 if (aShape.IsNull())
5945 std::cout << "Error: shape with name '" << aShapeName << "' is not found\n";
5949 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5950 Handle(MyShapeWithNormals) aShapePrs;
5951 if (aMap.IsBound2 (aShapeName))
5953 aShapePrs = Handle(MyShapeWithNormals)::DownCast (aMap.Find2 (aShapeName));
5956 Standard_Boolean isUseMesh = Standard_False;
5957 Standard_Real aLength = 10.0;
5958 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
5959 Standard_Boolean isOriented = Standard_False;
5960 for (; anArgIter < theArgNum; ++anArgIter)
5962 TCollection_AsciiString aParam (theArgs[anArgIter]);
5965 && ViewerTest::ParseOnOff (aParam.ToCString(), isOn))
5969 else if (aParam == "-usemesh"
5970 || aParam == "-mesh")
5972 isUseMesh = Standard_True;
5974 else if (aParam == "-length"
5975 || aParam == "-len")
5978 aLength = anArgIter < theArgNum ? Draw::Atof (theArgs[anArgIter]) : 0.0;
5979 if (Abs (aLength) <= gp::Resolution())
5981 std::cout << "Syntax error: length should not be zero\n";
5985 else if (aParam == "-orient"
5986 || aParam == "-oriented")
5988 isOriented = Standard_True;
5989 if (anArgIter + 1 < theArgNum
5990 && ViewerTest::ParseOnOff (theArgs[anArgIter + 1], isOriented))
5995 else if (aParam == "-nbalongu"
5996 || aParam == "-nbu")
5999 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6002 std::cout << "Syntax error: NbAlongU should be >=1\n";
6006 else if (aParam == "-nbalongv"
6007 || aParam == "-nbv")
6010 aNbAlongV = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6013 std::cout << "Syntax error: NbAlongV should be >=1\n";
6017 else if (aParam == "-nbalong"
6018 || aParam == "-nbuv")
6021 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6022 aNbAlongV = aNbAlongU;
6025 std::cout << "Syntax error: NbAlong should be >=1\n";
6031 std::cout << "Syntax error: unknwon argument '" << aParam << "'\n";
6038 if (aShapePrs.IsNull())
6040 aShapePrs = new MyShapeWithNormals (aShape);
6042 aShapePrs->ToUseMesh = isUseMesh;
6043 aShapePrs->ToOrient = isOriented;
6044 aShapePrs->NormalLength = aLength;
6045 aShapePrs->NbAlongU = aNbAlongU;
6046 aShapePrs->NbAlongV = aNbAlongV;
6047 VDisplayAISObject (aShapeName, aShapePrs);
6049 else if (!aShapePrs.IsNull())
6051 VDisplayAISObject (aShapeName, new AIS_Shape (aShape));
6057 //=======================================================================
6058 //function : ObjectsCommands
6060 //=======================================================================
6062 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
6064 const char *group ="AISObjects";
6066 theCommands.Add ("vtrihedron",
6067 "vtrihedron : vtrihedron name"
6068 "\n\t\t: [-dispMode {wireframe|shading} ]"
6069 "\n\t\t: [-origin x y z ]"
6070 "\n\t\t: [-zaxis u v w -xaxis u v w ]"
6071 "\n\t\t: [-drawAxes {X|Y|Z|XY|YZ|XZ|XYZ}]"
6072 "\n\t\t: [-hideLabels {on|off}]"
6073 "\n\t\t: [-hideArrows {on|off}]"
6074 "\n\t\t: [-label {XAxis|YAxis|ZAxis} value]"
6075 "\n\t\t: [-attribute {XAxisLength|YAxisLength|ZAxisLength"
6076 "\n\t\t: |TubeRadiusPercent|ConeRadiusPercent"
6077 "\n\t\t: |ConeLengthPercent|OriginRadiusPercent"
6078 "\n\t\t: |ShadingNumberOfFacettes} value]"
6079 "\n\t\t: [-color {Origin|XAxis|YAxis|ZAxis|XOYAxis|YOZAxis"
6080 "\n\t\t: |XOZAxis|Whole} {r g b | colorName}]"
6081 "\n\t\t: [-textColor {r g b | colorName}]"
6082 "\n\t\t: [-arrowColor {r g b | colorName}]"
6083 "\n\t\t: [-priority {Origin|XAxis|YAxis|ZAxis|XArrow"
6084 "\n\t\t: |YArrow|ZArrow|XOYAxis|YOZAxis"
6085 "\n\t\t: |XOZAxis|Whole} value]"
6087 "\n\t\t: Creates a new *AIS_Trihedron* object or changes parameters of "
6088 "\n\t\t: existing trihedron. If no argument is set,"
6089 "\n\t\t: the default trihedron (0XYZ) is created."
6090 "\n\t\t: -dispMode mode of visualization: wf - wireframe,"
6091 "\n\t\t: sh - shading."
6092 "\n\t\t: Default value is wireframe."
6093 "\n\t\t: -origin allows to set trihedron location."
6094 "\n\t\t: -zaxis/-xaxis allows to set trihedron X and Z"
6095 "\n\t\t: directions. The directions should"
6096 "\n\t\t: be orthogonal. Y direction is calculated."
6097 "\n\t\t: -drawAxes allows to set what axes are drawn in the"
6098 "\n\t\t: trihedron, default state is XYZ"
6099 "\n\t\t: -hideLabels allows to show/hide trihedron labels"
6100 "\n\t\t: -hideArrows allows to show/hide trihedron arrows"
6101 "\n\t\t: -label allows to change default X/Y/Z titles of axes"
6102 "\n\t\t: -attribute sets parameters of trihedron"
6103 "\n\t\t: -color sets color properties of parts of trihedron"
6104 "\n\t\t: -textColor sets color properties of trihedron labels"
6105 "\n\t\t: -arrowColor sets color properties of trihedron arrows"
6106 "\n\t\t: -priority allows to change default selection priority"
6107 "\n\t\t: of trihedron components",
6108 __FILE__,VTrihedron,group);
6110 theCommands.Add("vtri2d",
6112 "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.",
6113 __FILE__,VTrihedron2D ,group);
6115 theCommands.Add("vplanetri",
6117 "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default",
6118 __FILE__,VPlaneTrihedron ,group);
6120 theCommands.Add("vsize",
6121 "vsize : vsize [name(Default=Current)] [size(Default=100)] "
6122 "\n\t\t: Changes the size of a named or selected trihedron."
6123 "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done."
6124 "\n\t\t: If the value is not defined: it is set to 100 by default.",
6125 __FILE__,VSize,group);
6127 theCommands.Add("vaxis",
6128 "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]"
6129 "\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",
6130 __FILE__,VAxisBuilder,group);
6132 theCommands.Add("vaxispara",
6134 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.",
6135 __FILE__,VAxisBuilder,group);
6137 theCommands.Add("vaxisortho",
6139 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.",
6140 __FILE__,VAxisBuilder,group);
6142 theCommands.Add("vpoint",
6143 "vpoint PointName [Xa] [Ya] [Za] "
6144 "\n\t\t: Creates a point from coordinates. If the values are not defined,"
6145 "\n\t\t: a point is created by interactive selection of a vertice or an edge (in the center of the edge).",
6146 __FILE__,VPointBuilder,group);
6148 theCommands.Add("vplane",
6149 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]"
6150 "\n\t\t: Creates a plane from named or interactively selected entities."
6151 "\n\t\t: TypeOfSensitivity:"
6152 "\n\t\t: 0 - Interior"
6153 "\n\t\t: 1 - Boundary",
6154 __FILE__,VPlaneBuilder,group);
6156 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
6157 " vchangeplane <plane_name>"
6158 " [x=center_x y=center_y z=center_z]"
6159 " [dx=dir_x dy=dir_y dz=dir_z]"
6160 " [sx=size_x sy=size_y]"
6162 " - changes parameters of the plane:\n"
6163 " - x y z - center\n"
6164 " - dx dy dz - normal\n"
6165 " - sx sy - plane sizes\n"
6166 " - noupdate - do not update/redisplay the plane in context\n"
6167 " Please enter coordinates in format \"param=value\" in arbitrary order.",
6168 __FILE__, VChangePlane, group);
6170 theCommands.Add("vplanepara",
6171 "vplanepara PlaneName "
6172 "\n\t\t: Creates a plane from interactively selected vertex and face.",
6173 __FILE__,VPlaneBuilder,group);
6175 theCommands.Add("vplaneortho",
6176 "vplaneortho PlaneName "
6177 "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ",
6178 __FILE__,VPlaneBuilder,group);
6180 theCommands.Add("vline",
6181 "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] "
6182 "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ",
6183 __FILE__,VLineBuilder,group);
6185 theCommands.Add("vcircle",
6186 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]"
6187 "\n\t\t: Creates a circle from named or interactively selected entities."
6188 "\n\t\t: Parameter IsFilled is defined as 0 or 1.",
6189 __FILE__,VCircleBuilder,group);
6191 theCommands.Add ("vdrawtext",
6192 "vdrawtext name text"
6193 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6194 "\n\t\t: [-color {R G B|name}=yellow]"
6195 "\n\t\t: [-halign {left|center|right}=left]"
6196 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6197 "\n\t\t: [-angle angle=0]"
6198 "\n\t\t: [-zoom {0|1}=0]"
6199 "\n\t\t: [-height height=16]"
6200 "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]"
6201 "\n\t\t: [-font font=Times]"
6203 "\n\t\t: [-perspos {X Y Z}=0 0 0], where"
6204 "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window"
6205 "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..."
6206 "\n\t\t Z coordinate defines the gap from border of view window (except center position)."
6207 "\n\t\t: [-disptype {blend|decal|shadow|subtitle|dimension|normal}=normal}"
6208 "\n\t\t: [-subcolor {R G B|name}=white]"
6209 "\n\t\t: [-noupdate]"
6210 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]"
6211 "\n\t\t: [-flipping]"
6212 "\n\t\t: Display text label at specified position.",
6213 __FILE__, VDrawText, group);
6215 theCommands.Add("vdrawsphere",
6216 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
6217 __FILE__,VDrawSphere,group);
6219 theCommands.Add ("vlocation",
6222 "\n\t\t: [-copyFrom otherName]"
6223 "\n\t\t: [-translate X Y [Z]]"
6224 "\n\t\t: [-rotate x y z dx dy dz angle]"
6225 "\n\t\t: [-scale [X Y Z] scale]"
6226 "\n\t\t: [-mirror x y z dx dy dz]"
6227 "\n\t\t: [-setLocation X Y [Z]]"
6228 "\n\t\t: [-setRotation QX QY QZ QW]"
6229 "\n\t\t: [-setScale [X Y Z] scale]"
6230 "\n\t\t: Object local transformation management:"
6231 "\n\t\t: -reset reset transformation to identity"
6232 "\n\t\t: -translate translate object"
6233 "\n\t\t: -rotate applies rotation to local transformation"
6234 "\n\t\t: -scale applies scale to local transformation"
6235 "\n\t\t: -mirror applies mirror to local transformation"
6236 "\n\t\t: -setLocation assign object location"
6237 "\n\t\t: -setRotation assign object rotation (quaternion)"
6238 "\n\t\t: -setScale assign object scale factor",
6239 __FILE__, VSetLocation, group);
6240 theCommands.Add ("vsetlocation",
6241 "alias for vlocation",
6242 __FILE__, VSetLocation, group);
6244 theCommands.Add ("vcomputehlr",
6245 "vcomputehlr shapeInput hlrResult [-algoType {algo|polyAlgo}=polyAlgo]"
6246 "\n\t\t: [eyeX eyeY eyeZ dirX dirY dirZ upX upY upZ]"
6247 "\n\t\t: [-showTangentEdges {on|off}=off] [-nbIsolines N=0] [-showHiddenEdges {on|off}=off]"
6248 "\n\t\t: Arguments:"
6249 "\n\t\t: shapeInput - name of the initial shape"
6250 "\n\t\t: hlrResult - result HLR object from initial shape"
6251 "\n\t\t: eye, dir are eye position and look direction"
6252 "\n\t\t: up is the look up direction vector"
6253 "\n\t\t: -algoType HLR algorithm to use"
6254 "\n\t\t: -showTangentEdges include tangent edges"
6255 "\n\t\t: -nbIsolines include isolines"
6256 "\n\t\t: -showHiddenEdges include hidden edges"
6257 "\n\t\t: Use vtop to see projected HLR shape.",
6258 __FILE__, VComputeHLR, group);
6260 theCommands.Add("vdrawparray",
6261 "vdrawparray name TypeOfArray={points|segments|polylines|triangles"
6262 "\n\t\t: |trianglefans|trianglestrips|quads|quadstrips|polygons}"
6263 "\n\t\t: [-deinterleaved|-mutable]"
6264 "\n\t\t: [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [texel={'t' tx ty}]]"
6265 "\n\t\t: [bound= {'b' nbVertices [bound_color={'c' r g b}]]"
6266 "\n\t\t: [edge= {'e' vertexId]"
6267 "\n\t\t: [-shape shapeName] [-patch]"
6268 "\n\t\t: Commands create an Interactive Object for specified Primitive Array definition (Graphic3d_ArrayOfPrimitives)"
6269 "\n\t\t: with the main purpose is covering various combinations by tests",
6270 __FILE__,VDrawPArray,group);
6272 theCommands.Add("vconnect",
6273 "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]"
6274 "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.",
6275 __FILE__, VConnect, group);
6277 theCommands.Add("vconnectto",
6278 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
6279 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6280 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
6281 __FILE__, VConnectTo,group);
6283 theCommands.Add("vdisconnect",
6284 "vdisconnect assembly_name (object_name | object_number | 'all')"
6285 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6286 __FILE__,VDisconnect,group);
6288 theCommands.Add("vaddconnected",
6289 "vaddconnected assembly_name object_name"
6290 "Adds object to assembly.",
6291 __FILE__,VAddConnected,group);
6293 theCommands.Add("vlistconnected",
6294 "vlistconnected assembly_name"
6295 "Lists objects in assembly.",
6296 __FILE__,VListConnected,group);
6299 theCommands.Add("vselmode",
6300 "vselmode [object] selectionMode {on|off}"
6301 "\n\t\t: [{-add|-set|-globalOrLocal}=-globalOrLocal]"
6302 "\n\t\t: Switches selection mode for the specified object or for all objects in context."
6303 "\n\t\t: Selection mode is either an integer number specific to Interactive Object,"
6304 "\n\t\t: or sub-shape type in case of AIS_Shape:"
6305 "\n\t\t: Shape, Vertex, Edge, Wire, Face, Shell, Solid, CompSolid, Compound"
6306 "\n\t\t: The integer mode 0 (Shape in case of AIS_Shape) is reserved for selecting object as whole."
6307 "\n\t\t: Additional options:"
6308 "\n\t\t: -add already activated selection modes will be left activated"
6309 "\n\t\t: -set already activated selection modes will be deactivated"
6310 "\n\t\t: -globalOrLocal (default) if new mode is Global selection mode,"
6311 "\n\t\t: then active local selection modes will be deactivated"
6312 "\n\t\t: and the samthen active local selection modes will be deactivated",
6313 __FILE__, VSetSelectionMode, group);
6315 theCommands.Add("vselnext",
6316 "vselnext : hilight next detected",
6317 __FILE__, VSelectionNext, group);
6319 theCommands.Add("vselprev",
6320 "vselnext : hilight previous detected",
6321 __FILE__, VSelectionPrevious, group);
6323 theCommands.Add("vtriangle",
6324 "vtriangle Name PointName PointName PointName"
6325 "\n\t\t: Creates and displays a filled triangle from named points.",
6326 __FILE__, VTriangle,group);
6328 theCommands.Add("vsegment",
6329 "vsegment Name PointName PointName"
6330 "\n\t\t: Creates and displays a segment from named points.",
6331 __FILE__, VTriangle,group);
6333 theCommands.Add("vobjzlayer",
6334 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6335 __FILE__, VObjZLayer, group);
6337 theCommands.Add("vpolygonoffset",
6338 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6339 __FILE__, VPolygonOffset, group);
6341 theCommands.Add ("vmarkerstest",
6342 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6343 __FILE__, VMarkersTest, group);
6345 theCommands.Add ("text2brep",
6346 "text2brep: name text"
6347 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6348 "\n\t\t: [-halign {left|center|right}=left]"
6349 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6350 "\n\t\t: [-height height=16]"
6351 "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]"
6352 "\n\t\t: [-font font=Courier]"
6353 "\n\t\t: [-composite {on|off}=off]"
6354 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]",
6355 __FILE__, TextToBRep, group);
6356 theCommands.Add ("vfont",
6357 "vfont [-add pathToFont [fontName] [regular,bold,italic,boldItalic=undefined] [singleStroke]]"
6358 "\n\t\t: [-find fontName [regular,bold,italic,boldItalic=undefined]] [-verbose {on|off}]",
6359 __FILE__, VFont, group);
6361 theCommands.Add ("vvertexmode",
6362 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6363 "vvertexmode - prints the default vertex draw mode\n"
6364 "vvertexmode name - prints the vertex draw mode of the given object\n"
6365 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6366 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6367 __FILE__, VVertexMode, group);
6369 theCommands.Add ("vpointcloud",
6370 "vpointcloud name shape [-randColor] [-normals] [-noNormals]"
6371 "\n\t\t: Create an interactive object for arbitary set of points"
6372 "\n\t\t: from triangulated shape."
6374 "vpointcloud name x y z r npts {surface|volume}\n"
6375 " ... [-randColor] [-normals] [-noNormals]"
6376 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6377 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6379 "\n\t\t: Additional options:"
6380 "\n\t\t: -randColor - generate random color per point"
6381 "\n\t\t: -normals - generate normal per point (default)"
6382 "\n\t\t: -noNormals - do not generate normal per point"
6384 __FILE__, VPointCloud, group);
6386 theCommands.Add("vpriority",
6387 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",
6391 theCommands.Add ("vnormals",
6393 "vnormals Shape [{on|off}=on] [-length {10}] [-nbAlongU {1}] [-nbAlongV {1}] [-nbAlong {1}]"
6394 "\n\t\t: [-useMesh] [-oriented {0}1}=0]"
6395 "\n\t\t: Displays/Hides normals calculated on shape geometry or retrieved from triangulation",
6396 __FILE__, VNormals, group);