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->SetXDirection(aXDir);
343 aComponent->SetDirection (aZDir);
346 if (aMapOfArgs.Find ("dispmode", aValues))
348 TCollection_AsciiString aValue (aValues->Value (1));
349 bool isWireframe = true;
350 if (aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
352 theTrihedron->SetDatumDisplayMode (isWireframe ? Prs3d_DM_WireFrame
356 if (aMapOfArgs.Find ("hidelabels", aValues))
358 Standard_Boolean toHideLabels = Standard_True;
359 if (aValues->Size() == 1)
361 ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideLabels);
363 else if (aValues->Size() != 0)
365 std::cout << "Syntax error: -hidelabels expects parameter 'on' or 'off' after.\n";
366 return Standard_False;
369 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
371 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
373 theTrihedron->Attributes()->DatumAspect()->SetDrawLabels (!toHideLabels);
376 if (aMapOfArgs.Find ("hidearrows", aValues))
378 Standard_Boolean toHideArrows = Standard_True;
379 if (aValues->Size() == 1)
381 ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideArrows);
383 else if (aValues->Size() != 0)
385 std::cout << "Syntax error: -hidearrows expects parameter 'on' or 'off' after.\n";
386 return Standard_False;
389 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
391 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
393 theTrihedron->Attributes()->DatumAspect()->SetDrawArrows (!toHideArrows);
396 if (aMapOfArgs.Find ("color", aValues))
398 NCollection_List<Prs3d_DatumParts> aParts;
399 if (aValues->Size() < 2)
401 std::cout << "Syntax error: -color wrong parameters.\n";
402 return Standard_False;
405 convertToDatumParts (aValues->Value(1), aParts);
406 aValues->Remove (1); // datum part is processed
407 Quantity_Color aColor;
408 if (!convertToColor (aValues, aColor))
410 std::cout << "Syntax error: -color wrong parameters.\n";
411 return Standard_False;
414 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (aParts); anIterator.More(); anIterator.Next())
416 Prs3d_DatumParts aDatumPart = anIterator.Value();
417 if (aDatumPart == Prs3d_DP_None)
419 theTrihedron->SetColor (aColor);
423 theTrihedron->SetDatumPartColor (aDatumPart, aColor);
428 if (aMapOfArgs.Find ("textcolor", aValues))
430 Quantity_Color aColor;
431 if (!convertToColor (aValues, aColor))
433 std::cout << "Syntax error: -textcolor wrong parameters.\n";
434 return Standard_False;
436 theTrihedron->SetTextColor (aColor);
439 if (aMapOfArgs.Find ("arrowcolor", aValues))
441 Quantity_Color aColor;
442 if (!convertToColor (aValues, aColor))
444 std::cout << "Syntax error: -arrowcolor wrong parameters.\n";
445 return Standard_False;
447 theTrihedron->SetArrowColor (aColor);
450 if (aMapOfArgs.Find ("attribute", aValues))
452 NCollection_List<Prs3d_DatumAttribute> anAttributes;
453 if (aValues->Size() != 2)
455 std::cout << "Syntax error: -attribute wrong parameters.\n";
456 return Standard_False;
459 convertToDatumAttributes (aValues->Value (1), anAttributes);
460 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
461 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
462 for (NCollection_List<Prs3d_DatumAttribute>::Iterator anIterator (anAttributes); anIterator.More(); anIterator.Next())
464 theTrihedron->Attributes()->DatumAspect()->SetAttribute (anIterator.Value(), aValues->Value (2).RealValue());
468 if (aMapOfArgs.Find ("priority", aValues))
470 Prs3d_DatumParts aDatumPart;
471 if (aValues->Size() < 2
472 || !convertToDatumPart (aValues->Value (1), aDatumPart))
474 std::cout << "Syntax error: -priority wrong parameters.\n";
475 return Standard_False;
477 theTrihedron->SetSelectionPriority (aDatumPart, aValues->Value (2).IntegerValue());
480 if (aMapOfArgs.Find ("labels", 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;
514 //==============================================================================
515 //function : Vtrihedron 2d
516 //purpose : Create a plane with a 2D trihedron from a faceselection
517 //Draw arg : vtri2d name
518 //==============================================================================
519 static int VTrihedron2D (Draw_Interpretor& /*theDI*/,
520 Standard_Integer theArgsNum,
521 const char** theArgVec)
525 std::cerr << theArgVec[0]<< " error.\n";
529 TopTools_ListOfShape aShapes;
530 ViewerTest::GetSelectedShapes (aShapes);
532 if (aShapes.Extent() != 1)
534 std::cerr << "Error: wrong number of selected shapes.\n";
538 const TopoDS_Shape& aShape = aShapes.First();
540 TopoDS_Face aFace = TopoDS::Face (aShape);
541 TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE);
542 TopoDS_Edge anEdge0 = TopoDS::Edge (aFaceExp.Current());
548 TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() );
549 BRepAdaptor_Curve aCurve0 (anEdge0);
550 BRepAdaptor_Curve aCurve1 (anEdge1);
551 A = aCurve1.Value (0.1);
552 B = aCurve1.Value (0.9);
553 C = aCurve0.Value (0.5);
557 BRepAdaptor_Curve aCurve0 (anEdge0);
558 A = aCurve0.Value (0.1);
559 B = aCurve0.Value (0.9);
560 C = aCurve0.Value (0.5);
563 GC_MakePlane aMkPlane (A,B,C);
565 Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value());
566 TCollection_AsciiString aName (theArgVec[1]);
568 VDisplayAISObject (aName, anAISPlaneTri);
573 //=======================================================================
574 //function : VTrihedron
576 //=======================================================================
577 static int VTrihedron (Draw_Interpretor& ,
578 Standard_Integer theArgsNb,
579 const char** theArgVec)
583 std::cout << "Syntax error: the wrong number of input parameters.\n";
587 TCollection_AsciiString aName (theArgVec[1]);
588 gp_Pln aWorkingPlane;
589 Standard_Boolean toUpdate = Standard_True;
591 NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
592 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
594 Handle(AIS_Trihedron) aTrihedron;
595 Handle(AIS_InteractiveObject) anObject;
596 if (GetMapOfAIS().Find2 (aName, anObject))
598 aTrihedron = Handle(AIS_Trihedron)::DownCast (anObject);
599 if (aTrihedron.IsNull())
601 std::cout << "Syntax error: no trihedron with this name.\n";
607 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (gp_Pnt (0.0, 0.0, 0.0),
609 aTrihedron = new AIS_Trihedron (aPlacement);
612 if (!setTrihedronParams (theArgsNb, theArgVec, aTrihedron))
617 // Redisplay a dimension after parameter changing.
618 if (ViewerTest::GetAISContext()->IsDisplayed (aTrihedron))
620 ViewerTest::GetAISContext()->Redisplay (aTrihedron, toUpdate);
624 VDisplayAISObject (theArgVec[1], aTrihedron);
630 //==============================================================================
633 //purpose : Change the size of a named or selected trihedron
634 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
635 // if no value, the value is set at 100 by default
636 //Draw arg : vsize [name] [size]
637 //==============================================================================
639 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
642 // Declaration de booleens
643 Standard_Boolean ThereIsName;
644 Standard_Boolean ThereIsCurrent;
646 Standard_Boolean hascol;
648 Quantity_Color col = Quantity_NOC_BLACK;
650 // Verification des arguments
651 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;}
653 // Verification du nombre d'arguments
654 if (argc==1) {ThereIsName=Standard_False;value=100;}
655 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
656 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
658 // On set le booleen ThereIsCurrent
659 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
660 else {ThereIsCurrent=Standard_False;}
664 //===============================================================
665 // Il n'y a pas de nom mais des objets selectionnes
666 //===============================================================
667 if (!ThereIsName && ThereIsCurrent)
670 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
673 while ( it.More() ) {
675 Handle(AIS_InteractiveObject) aShape = it.Key1();
677 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
680 // On verifie que l'AIS InteraciveObject selectionne est bien
682 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
684 if (aShape->HasColor())
686 hascol = Standard_True;
688 // On recupere la couleur de aShape
693 hascol = Standard_False;
696 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
697 // pour lui appliquer la methode SetSize()
698 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
700 // C'est bien un triedre,on chage sa valeur!
701 aTrihedron->SetSize(value);
703 // On donne la couleur au Trihedron
704 if(hascol) aTrihedron->SetColor(col);
705 else aTrihedron->UnsetColor();
708 // The trihedron hasn't be errased from the map
709 // so you just have to redisplay it
710 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
719 TheAISContext() ->UpdateCurrentViewer();
722 //===============================================================
723 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
724 //===============================================================
728 //===============================================================
729 // Il y a un nom de triedre passe en argument
730 //===============================================================
732 TCollection_AsciiString name=argv[1];
734 // on verifie que ce nom correspond bien a une shape
735 Handle(AIS_InteractiveObject) aShape;
736 if (GetMapOfAIS().Find2(name, aShape))
738 // On verifie que l'AIS InteraciveObject est bien
740 if (!aShape.IsNull() &&
741 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
743 if (aShape->HasColor())
745 hascol=Standard_True;
747 // On recupere la couleur de aShape
752 hascol = Standard_False;
755 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
756 // pour lui appliquer la methode SetSize()
757 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
759 // C'est bien un triedre,on chage sa valeur
760 aTrihedron->SetSize(value);
762 // On donne la couleur au Trihedron
763 if(hascol) aTrihedron->SetColor(col);
764 else aTrihedron->UnsetColor();
766 // The trihedron hasn't be errased from the map
767 // so you just have to redisplay it
768 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
770 TheAISContext() ->UpdateCurrentViewer();
778 //==============================================================================
780 //==============================================================================
781 //function : VPlaneTrihedron
782 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
783 //Draw arg : vplanetri name
784 //==============================================================================
785 #include <AIS_Plane.hxx>
789 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
792 // Verification des arguments
793 if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
795 if (TheAISContext()->NbSelected() != 1)
797 std::cerr << "Error: Wrong number of selected shapes.\n";
801 TheAISContext()->InitSelected();
802 Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive();
803 Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest);
806 std::cerr << "Error: Selected shape is not a plane.\n";
810 VDisplayAISObject (argv[1], aPlane);
817 //==============================================================================
818 // Fonction First click 2de click
820 // vaxis vertex vertex
822 // vaxispara edge vertex
823 // vaxisortho edge Vertex
824 // vaxisinter Face Face
825 //==============================================================================
827 //==============================================================================
828 //function : VAxisBuilder
830 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
831 //==============================================================================
832 #include <TopoDS_Edge.hxx>
833 #include <TopoDS_Vertex.hxx>
834 #include <TopExp.hxx>
835 #include <Geom_Line.hxx>
837 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
840 Standard_Boolean HasArg;
841 TCollection_AsciiString name;
844 if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
845 if (argc==8) HasArg=Standard_True;
846 else HasArg=Standard_False;
850 TopTools_ListOfShape aShapes;
851 ViewerTest::GetSelectedShapes (aShapes);
853 // Cas ou il y a des arguments
854 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
856 Standard_Real coord[6];
857 for(Standard_Integer i=0;i<=5;i++){
858 coord[i]=Draw::Atof(argv[2+i]);
860 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
862 gp_Vec myVect (p1,p2);
863 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
864 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
865 GetMapOfAIS().Bind (TheAxis,name);
866 TheAISContext()->Display(TheAxis, Standard_True);
872 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
873 if ( !strcasecmp(argv[0], "vaxis")) {
874 if (aShapes.Extent() != 2 && aShapes.Extent() != 1)
876 std::cerr << "Error: Wrong number of selected shapes.\n";
880 const TopoDS_Shape& aShapeA = aShapes.First();
881 if (aShapeA.ShapeType() == TopAbs_VERTEX)
883 if (aShapes.Extent() != 2)
885 std::cerr << "Error: Wron number of selected shapes.\n";
889 const TopoDS_Shape& aShapeB = aShapes.Last();
890 if (aShapeB.ShapeType() != TopAbs_VERTEX)
892 std::cerr << "Syntax error: You should select two vertices or one edge.\n";
896 // Construction de l'axe
897 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
898 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
901 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
902 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
903 GetMapOfAIS().Bind (TheAxis,name);
904 TheAISContext()->Display (TheAxis, Standard_True);
908 TopoDS_Edge ed =TopoDS::Edge (aShapeA);
910 TopExp::Vertices(ed,Va,Vb );
911 gp_Pnt A=BRep_Tool::Pnt(Va);
912 gp_Pnt B=BRep_Tool::Pnt(Vb);
915 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
916 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
917 GetMapOfAIS().Bind (TheAxis,name);
918 TheAISContext()->Display (TheAxis, Standard_True);
924 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
925 else if ( !strcasecmp(argv[0], "vaxispara"))
927 if (aShapes.Extent() != 2)
929 std::cerr << "Error: Wrong number of selected shapes.\n";
933 const TopoDS_Shape& aShapeA = aShapes.First();
934 const TopoDS_Shape& aShapeB = aShapes.Last();
935 if (!(aShapeA.ShapeType() == TopAbs_EDGE
936 && aShapeB.ShapeType() == TopAbs_VERTEX))
938 std::cerr << "Syntax error: You should select face and then vertex.\n";
942 TopoDS_Edge ed=TopoDS::Edge (aShapeA);
943 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
945 TopExp::Vertices(ed,Va,Vc );
946 gp_Pnt A=BRep_Tool::Pnt(Va);
947 gp_Pnt C=BRep_Tool::Pnt(Vc);
950 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
951 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
952 GetMapOfAIS().Bind (TheAxis,name);
953 TheAISContext()->Display (TheAxis, Standard_True);
957 // Fonction axisortho
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 // Construction de l'axe
976 TopoDS_Edge ed=TopoDS::Edge(aShapeA) ;
977 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) );
979 TopExp::Vertices(ed,Va,Vc );
980 gp_Pnt A=BRep_Tool::Pnt(Va);
981 gp_Pnt C=BRep_Tool::Pnt(Vc);
982 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
985 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
986 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
987 GetMapOfAIS().Bind (TheAxis,name);
988 TheAISContext()->Display (TheAxis, Standard_True);
997 //==============================================================================
998 // Fonction First click Result
1000 // vpoint vertex AIS_Point=Vertex
1001 // edge AIS_Point=Middle of the edge
1002 //==============================================================================
1004 //==============================================================================
1005 //function : VPointBuilder
1006 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
1007 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
1008 //==============================================================================
1009 #include <TopoDS_Edge.hxx>
1010 #include <TopoDS_Vertex.hxx>
1011 #include <TopExp.hxx>
1012 #include <AIS_Point.hxx>
1013 #include <Geom_CartesianPoint.hxx>
1015 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1018 Standard_Boolean HasArg;
1019 TCollection_AsciiString name;
1022 if (argc<2 || argc>5 ) {di<<" Syntaxe error\n";return 1;}
1023 if (argc==5) HasArg=Standard_True;
1024 else HasArg=Standard_False;
1028 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
1030 Standard_Real thecoord[3];
1031 for(Standard_Integer i=0;i<=2;i++)
1032 thecoord[i]=Draw::Atof(argv[2+i]);
1033 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
1034 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
1035 GetMapOfAIS().Bind (myAISPoint,name);
1036 TheAISContext()->Display (myAISPoint, Standard_True);
1039 // Il n'a pas d'arguments
1042 TopTools_ListOfShape aShapes;
1043 ViewerTest::GetSelectedShapes (aShapes);
1045 if (aShapes.Extent() != 1)
1047 std::cerr << "Error: Wrong number of selected shapes.\n";
1048 std::cerr << "\tYou should select one edge or vertex.\n";
1052 const TopoDS_Shape& aShapeA = aShapes.First();
1054 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1056 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(aShapeA ) );
1057 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
1058 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
1059 GetMapOfAIS().Bind(myAISPoint,name);
1060 TheAISContext()->Display (myAISPoint, Standard_True);
1064 TopoDS_Edge myEdge=TopoDS::Edge(aShapeA);
1065 TopoDS_Vertex myVertexA,myVertexB;
1066 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
1067 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
1068 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
1069 // M est le milieu de [AB]
1070 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
1071 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
1072 GetMapOfAIS().Bind(myAISPointM,name);
1073 TheAISContext()->Display (myAISPointM, Standard_True);
1081 //==============================================================================
1082 // Function 1st click 2de click 3de click
1083 // vplane Vertex Vertex Vertex
1087 // vplanepara Face Vertex
1089 // vplaneortho Face Edge
1091 //==============================================================================
1093 //==============================================================================
1094 //function : VPlaneBuilder
1095 //purpose : Build an AIS_Plane from selected entities or Named AIS components
1096 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
1097 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
1098 // [PlaneName] [PointName] [TypeOfSensitivity]
1099 //==============================================================================
1101 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
1102 Standard_Integer argc,
1106 Standard_Boolean hasArg;
1107 TCollection_AsciiString aName;
1110 if (argc<2 || argc>6 )
1112 std::cout<<" Syntax error\n";
1115 if (argc == 6 || argc==5 || argc==4)
1116 hasArg=Standard_True;
1118 hasArg=Standard_False;
1122 // There are some arguments
1125 Handle(AIS_InteractiveObject) aShapeA;
1126 if (!GetMapOfAIS().Find2 (argv[2], aShapeA))
1128 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
1132 // The first argument is an AIS_Point
1133 if (!aShapeA.IsNull() &&
1134 aShapeA->Type()==AIS_KOI_Datum &&
1135 aShapeA->Signature()==1)
1137 // The second argument must also be an AIS_Point
1138 Handle(AIS_InteractiveObject) aShapeB;
1139 if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1141 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
1144 // If B is not an AIS_Point
1145 if (aShapeB.IsNull() ||
1146 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1148 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
1151 // The third object is an AIS_Point
1152 Handle(AIS_InteractiveObject) aShapeC;
1153 if (!GetMapOfAIS().Find2(argv[4], aShapeC))
1155 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
1158 // If C is not an AIS_Point
1159 if (aShapeC.IsNull() ||
1160 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
1162 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
1166 // Treatment of objects A, B, C
1167 // Downcast an AIS_IO to AIS_Point
1168 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
1169 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
1170 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
1172 Handle(Geom_CartesianPoint ) aCartPointA =
1173 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
1175 Handle(Geom_CartesianPoint ) aCartPointB =
1176 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
1178 Handle(Geom_CartesianPoint ) aCartPointC =
1179 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
1181 // Verification that the three points are different
1182 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
1183 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1184 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
1187 std::cout<<"vplane error: same points\n";return 1;
1189 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1190 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1191 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1194 std::cout<<"vplane error: same points\n";return 1;
1196 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1197 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1198 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1201 std::cout<<"vplane error: same points\n";return 1;
1204 gp_Pnt A = aCartPointA->Pnt();
1205 gp_Pnt B = aCartPointB->Pnt();
1206 gp_Pnt C = aCartPointC->Pnt();
1208 // Construction of AIS_Plane
1209 GC_MakePlane MkPlane (A,B,C);
1210 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1211 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1212 GetMapOfAIS().Bind (anAISPlane,aName );
1215 Standard_Integer aType = Draw::Atoi (argv[5]);
1216 if (aType != 0 && aType != 1)
1218 std::cout << "vplane error: wrong type of sensitivity!\n"
1219 << "Should be one of the following values:\n"
1227 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1230 TheAISContext()->Display (anAISPlane, Standard_True);
1233 // The first argument is an AIS_Axis
1234 // Creation of a plane orthogonal to the axis through a point
1235 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1236 // The second argument should be an AIS_Point
1237 Handle(AIS_InteractiveObject) aShapeB;
1238 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1240 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1243 // If B is not an AIS_Point
1244 if (aShapeB.IsNull() ||
1245 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1247 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1251 // Treatment of objects A and B
1252 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1253 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1255 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1256 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1258 gp_Ax1 anAxis = aGeomLineA->Position();
1259 Handle(Geom_CartesianPoint) aCartPointB =
1260 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1262 gp_Dir D =anAxis.Direction();
1263 gp_Pnt B = aCartPointB->Pnt();
1265 // Construction of AIS_Plane
1266 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1267 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1268 GetMapOfAIS().Bind (anAISPlane,aName );
1271 Standard_Integer aType = Draw::Atoi (argv[4]);
1272 if (aType != 0 && aType != 1)
1274 std::cout << "vplane error: wrong type of sensitivity!\n"
1275 << "Should be one of the following values:\n"
1283 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1286 TheAISContext()->Display (anAISPlane, Standard_True);
1289 // The first argumnet is an AIS_Plane
1290 // Creation of a plane parallel to the plane passing through the point
1291 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1293 // The second argument should be an AIS_Point
1294 Handle(AIS_InteractiveObject) aShapeB;
1295 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1297 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1300 // B should be an AIS_Point
1301 if (aShapeB.IsNull() ||
1302 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1304 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1308 // Treatment of objects A and B
1309 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1310 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1312 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1313 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1315 Handle(Geom_CartesianPoint) aCartPointB =
1316 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1317 gp_Pnt B= aCartPointB->Pnt();
1319 // Construction of an AIS_Plane
1320 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1321 GetMapOfAIS().Bind (anAISPlane, aName);
1324 Standard_Integer aType = Draw::Atoi (argv[4]);
1325 if (aType != 0 && aType != 1)
1327 std::cout << "vplane error: wrong type of sensitivity!\n"
1328 << "Should be one of the following values:\n"
1336 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1339 TheAISContext()->Display (anAISPlane, Standard_True);
1344 std::cout<<"vplane: error 1st object is not an AIS\n";
1348 // There are no arguments
1351 TopTools_ListOfShape aShapes;
1352 ViewerTest::GetSelectedShapes (aShapes);
1355 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1356 if (!strcasecmp(argv[0], "vplane"))
1358 if (aShapes.Extent() < 1 || aShapes.Extent() > 3)
1360 std::cerr << "Error: Wront number of selected shapes.\n";
1361 std::cerr << "\tYou should one of variant: face, edge and vertex or three vertices.\n";
1365 const TopoDS_Shape& aShapeA = aShapes.First();
1366 if (aShapeA.ShapeType() == TopAbs_VERTEX)
1368 if (aShapes.Extent() == 2)
1370 const TopoDS_Shape& aShapeB = aShapes.Last();
1371 if (aShapeB.ShapeType() != TopAbs_EDGE)
1373 std::cerr << "Syntax error: Together with vertex should be edge.\n";
1377 // Verify that the vertex is not on the edge ShapeB
1378 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1379 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1381 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1382 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1384 // The vertex is on the edge
1385 std::cout<<" vplane: error point is on the edge\n";
1390 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1391 TopoDS_Vertex aVBa, aVBb;
1392 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1393 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1394 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1395 GC_MakePlane MkPlane (A, aBa, aBb);
1396 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1397 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1398 GetMapOfAIS().Bind (anAISPlane, aName);
1399 TheAISContext()->Display (anAISPlane, Standard_True);
1402 else if (aShapes.Extent() == 3)
1404 TopTools_ListOfShape::Iterator anIter (aShapes);
1407 const TopoDS_Shape& aShapeB = anIter.Value();
1410 const TopoDS_Shape& aShapeC = anIter.Value();
1412 if (!(aShapeB.ShapeType() == TopAbs_VERTEX
1413 && aShapeC.ShapeType() == TopAbs_VERTEX))
1415 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1419 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1420 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1421 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1422 GC_MakePlane MkPlane(A, B, C);
1423 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1424 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1425 GetMapOfAIS().Bind (anAISPlane, aName);
1426 TheAISContext()->Display (anAISPlane, Standard_True);
1430 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1434 else if (aShapeA.ShapeType() == TopAbs_EDGE)
1436 if (aShapes.Extent() != 2)
1438 std::cerr << "Error: wrong number of selected shapes.\n";
1442 const TopoDS_Shape& aShapeB = aShapes.Last();
1443 if (aShapeB.ShapeType() != TopAbs_VERTEX)
1445 std::cerr << "Syntax error: Together with edge should be vertex.\n";
1449 // Check that the vertex aShapeB is not on the edge
1450 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1451 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1453 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1454 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1456 // The vertex is on the edge
1457 std::cout<<" vplane: error point is on the edge\n";
1461 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1462 TopoDS_Vertex aVAa, aVAb;
1463 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1464 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1465 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1466 GC_MakePlane MkPlane (B,Aa,Ab);
1467 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1468 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1469 GetMapOfAIS().Bind (anAISPlane ,aName);
1470 TheAISContext()->Display (anAISPlane, Standard_True);
1472 else if (aShapeA.ShapeType() == TopAbs_FACE)
1474 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1475 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1476 if (aSurface.GetType()==GeomAbs_Plane)
1478 gp_Pln aPlane = aSurface.Plane();
1479 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1480 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1481 GetMapOfAIS().Bind (anAISPlane, aName);
1482 TheAISContext()->Display (anAISPlane, Standard_True);
1486 std::cout<<" vplane: error\n";
1492 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1497 // Function vPlanePara
1498 // ===================
1499 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1500 else if (!strcasecmp(argv[0], "vplanepara"))
1502 if (aShapes.Extent() != 2)
1504 std::cerr << "Error: Wrong number of selected shapes.\n";
1508 const TopoDS_Shape* aShapeA = &aShapes.First();
1509 const TopoDS_Shape* aShapeB = &aShapes.Last();
1510 if (aShapeA->ShapeType() != TopAbs_VERTEX)
1512 std::swap (aShapeA, aShapeB);
1515 if (!(aShapeA->ShapeType() == TopAbs_VERTEX
1516 && aShapeB->ShapeType() == TopAbs_FACE))
1518 std::cerr << "Syntax error: you should select face and vertex.\n";
1522 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA));
1524 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1525 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1526 if (aSurface.GetType() == GeomAbs_Plane)
1528 gp_Pln aPlane = aSurface.Plane();
1529 // Construct a plane parallel to aGeomPlane through A
1530 aPlane.SetLocation(A);
1531 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1532 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1533 GetMapOfAIS().Bind (aAISPlane ,aName);
1534 TheAISContext()->Display (aAISPlane, Standard_True);
1538 std::cerr << "Error: Builded surface is not a plane.\n";
1543 // Function vplaneortho
1544 // ====================
1545 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1548 if (aShapes.Extent() != 2)
1550 std::cerr << "Error: wrong number of selected shapes.\n";
1554 const TopoDS_Shape* aShapeA = &aShapes.First();
1555 const TopoDS_Shape* aShapeB = &aShapes.Last();
1557 if (aShapeA->ShapeType() != TopAbs_EDGE)
1559 std::swap (aShapeA, aShapeB);
1562 if (!(aShapeA->ShapeType() == TopAbs_EDGE
1563 && aShapeB->ShapeType() == TopAbs_FACE))
1565 std::cerr << "Error: you should select edge and face.\n";
1569 // Construction of plane
1570 TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA);
1571 TopoDS_Vertex aVAa, aVAb;
1572 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1573 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1574 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1578 // Creation of rotation axis
1579 gp_Ax1 aRotAxis (Aa,Dab);
1581 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1582 // The edge must be parallel to the face
1583 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1584 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1585 // Compare to heights
1586 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1587 >Precision::Confusion())
1589 // the edge is not parallel to the face
1590 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1594 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1595 if (aSurface.GetType()==GeomAbs_Plane)
1597 gp_Pln aPlane = aSurface.Plane();
1598 // It rotates a half turn round the axis of rotation
1599 aPlane.Rotate(aRotAxis , M_PI/2);
1601 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1602 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1603 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1604 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1605 GetMapOfAIS().Bind (anAISPlane, aName);
1606 TheAISContext()->Display (anAISPlane, Standard_True);
1610 std::cout<<" vplaneortho: error\n";
1618 //===============================================================================================
1619 //function : VChangePlane
1621 //===============================================================================================
1622 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1624 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1625 if (aContextAIS.IsNull())
1627 std::cout << theArgVec[0] << "AIS context is not available.\n";
1631 if (theArgsNb < 3 || theArgsNb > 11)
1633 std::cerr << theArgVec[0]
1634 << ": incorrect number of command arguments.\n"
1635 << "Type help for more information.\n";
1639 TCollection_AsciiString aName (theArgVec[1]);
1641 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1642 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1645 if ( aPlane.IsNull() )
1647 std::cout << theArgVec[0]
1648 << ": there is no interactive plane with the given name."
1649 << "Type help for more information.\n";
1653 Standard_Real aCenterX = aPlane->Center().X();
1654 Standard_Real aCenterY = aPlane->Center().Y();
1655 Standard_Real aCenterZ = aPlane->Center().Z();
1657 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1658 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1659 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1661 Standard_Real aSizeX = 0.0;
1662 Standard_Real aSizeY = 0.0;
1663 aPlane->Size (aSizeX, aSizeY);
1664 Standard_Boolean isUpdate = Standard_True;
1666 TCollection_AsciiString aPName, aPValue;
1667 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1669 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1670 TCollection_AsciiString anArgCase = anArg;
1671 anArgCase.UpperCase();
1672 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1675 if (aPName.IsEqual ("X"))
1677 aCenterX = aPValue.RealValue();
1679 else if (aPName.IsEqual ("Y"))
1681 aCenterY = aPValue.RealValue();
1683 else if (aPName.IsEqual ("Z"))
1685 aCenterZ = aPValue.RealValue();
1687 else if (aPName.IsEqual ("DX"))
1689 aDirX = aPValue.RealValue();
1691 else if (aPName.IsEqual ("DY"))
1693 aDirY = aPValue.RealValue();
1695 else if (aPName.IsEqual ("DZ"))
1697 aDirZ = aPValue.RealValue();
1699 else if (aPName.IsEqual ("SX"))
1701 aSizeX = aPValue.RealValue();
1703 else if (aPName.IsEqual ("SY"))
1705 aSizeY = aPValue.RealValue();
1708 else if (anArg.IsEqual ("NOUPDATE"))
1710 isUpdate = Standard_False;
1714 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1715 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1716 aPlane->SetCenter (aCenterPnt);
1717 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1718 aPlane->SetSize (aSizeX, aSizeY);
1720 aContextAIS->Update (aPlane, isUpdate);
1725 //==============================================================================
1727 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1728 //==============================================================================
1730 //==============================================================================
1731 //function : VLineBuilder
1732 //purpose : Build an AIS_Line
1733 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1734 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1735 //==============================================================================
1736 #include <Geom_CartesianPoint.hxx>
1737 #include <AIS_Line.hxx>
1740 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1743 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; }
1745 // On recupere les parametres
1746 Handle(AIS_InteractiveObject) theShapeA;
1747 Handle(AIS_InteractiveObject) theShapeB;
1749 // Parametres: AIS_Point AIS_Point
1750 // ===============================
1752 GetMapOfAIS().Find2 (argv[2], theShapeA);
1753 // On verifie que c'est bien une AIS_Point
1754 if (!theShapeA.IsNull() &&
1755 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1756 // on recupere le deuxieme AIS_Point
1757 GetMapOfAIS().Find2 (argv[3], theShapeB);
1758 if (theShapeB.IsNull() ||
1759 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1761 di <<"vline error: wrong type of 2de argument.\n";
1765 else {di <<"vline error: wrong type of 1st argument.\n";return 1; }
1766 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1767 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1768 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
1770 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1771 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
1772 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1774 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1775 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
1776 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1778 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1780 di<<"vline error: same points\n";return 1;
1782 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1783 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1784 GetMapOfAIS().Bind(theAISLine,argv[1] );
1785 TheAISContext()->Display (theAISLine, Standard_True);
1789 // Parametres 6 Reals
1790 // ==================
1793 // On verifie que les deux points ne sont pas confondus
1795 Standard_Real coord[6];
1796 for(Standard_Integer i=0;i<=2;i++){
1797 coord[i]=Draw::Atof(argv[2+i]);
1798 coord[i+3]=Draw::Atof(argv[5+i]);
1801 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1802 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1804 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1805 GetMapOfAIS().Bind(theAISLine,argv[1] );
1806 TheAISContext()->Display (theAISLine, Standard_True);
1810 // Pas de parametres: Selection dans le viewer.
1811 // ============================================
1815 TopTools_ListOfShape aShapes;
1816 ViewerTest::GetSelectedShapes (aShapes);
1817 if (aShapes.Extent() != 2)
1819 std::cerr << "Error: wrong number of selected shapes.\n";
1823 const TopoDS_Shape& aShapeA = aShapes.First();
1824 const TopoDS_Shape& aShapeB = aShapes.Last();
1826 if (!(aShapeA.ShapeType() == TopAbs_VERTEX
1827 && aShapeB.ShapeType() == TopAbs_VERTEX))
1829 std::cerr << "Error: you should select two different vertex.\n";
1833 // Construction de la line
1834 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1835 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
1837 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1838 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1840 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1841 GetMapOfAIS().Bind(theAISLine,argv[1] );
1842 TheAISContext()->Display (theAISLine, Standard_True);
1848 //==============================================================================
1849 // class : FilledCircle
1850 // purpose : creates filled circle based on AIS_InteractiveObject
1852 // This class is used to check method Matches() of class
1853 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1854 // because none of AIS classes provides creation of
1855 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1856 // (look method ComputeSelection() )
1857 //==============================================================================
1859 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1861 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1862 gp_Circ aCirc(anAxes, theRadius);
1863 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1867 class FilledCircle : public AIS_InteractiveObject
1871 DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject);
1873 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1874 FilledCircle(Handle(Geom_Circle) theCircle);
1877 TopoDS_Face ComputeFace();
1879 // Virtual methods implementation
1880 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1881 const Handle(Prs3d_Presentation)& thePresentation,
1882 const Standard_Integer theMode) Standard_OVERRIDE;
1884 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1885 const Standard_Integer theMode) Standard_OVERRIDE;
1888 Handle(Geom_Circle) myCircle;
1889 Standard_Boolean myFilledStatus;
1894 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1896 myCircle = CreateCircle(theCenter, theRadius);
1897 myFilledStatus = Standard_True;
1900 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1902 myCircle = theCircle;
1903 myFilledStatus = Standard_True;
1906 TopoDS_Face FilledCircle::ComputeFace()
1908 // Create edge from myCircle
1909 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1910 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1912 // Create wire from anEdge
1913 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1914 TopoDS_Wire aWire = aWireMaker.Wire();
1916 // Create face from aWire
1917 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1918 TopoDS_Face aFace = aFaceMaker.Face();
1923 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1924 const Handle(Prs3d_Presentation) &thePresentation,
1925 const Standard_Integer theMode)
1927 thePresentation->Clear();
1929 TopoDS_Face aFace = ComputeFace();
1931 if (aFace.IsNull()) return;
1932 if (theMode != 0) return;
1934 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1937 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
1938 const Standard_Integer /*theMode*/)
1940 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
1941 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
1942 myCircle, myFilledStatus);
1943 theSelection->Add(aSensitiveCircle);
1946 //==============================================================================
1948 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
1949 //==============================================================================
1951 //==============================================================================
1952 //function : VCircleBuilder
1953 //purpose : Build an AIS_Circle
1954 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
1955 // PointName PointName PointName IsFilled
1956 //==============================================================================
1958 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
1959 TCollection_AsciiString theName,
1960 Standard_Boolean isFilled)
1962 Handle(AIS_InteractiveObject) aCircle;
1965 aCircle = new FilledCircle(theGeomCircle);
1969 aCircle = new AIS_Circle(theGeomCircle);
1970 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
1973 // Check if there is an object with given name
1974 // and remove it from context
1975 if (GetMapOfAIS().IsBound2(theName))
1977 Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2(theName);
1978 TheAISContext()->Remove(anInterObj, Standard_False);
1979 GetMapOfAIS().UnBind2(theName);
1982 // Bind the circle to its name
1983 GetMapOfAIS().Bind(aCircle, theName);
1985 // Display the circle
1986 TheAISContext()->Display (aCircle, Standard_True);
1990 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
1992 // Verification of the arguments
1993 if (argc>6 || argc<2)
1995 std::cout << "vcircle error: expect 4 arguments.\n";
1996 return 1; // TCL_ERROR
1999 // There are all arguments
2003 TCollection_AsciiString aName(argv[1]);
2004 Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0;
2006 Handle(AIS_InteractiveObject) theShapeA, theShapeB;
2007 GetMapOfAIS().Find2 (argv[2], theShapeA);
2008 GetMapOfAIS().Find2 (argv[3], theShapeB);
2010 // Arguments: AIS_Point AIS_Point AIS_Point
2011 // ========================================
2012 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2013 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2015 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2017 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2018 return 1; // TCL_ERROR
2020 // The third object must be a point
2021 Handle(AIS_InteractiveObject) theShapeC;
2022 GetMapOfAIS().Find2 (argv[4], theShapeC);
2023 if (theShapeC.IsNull() ||
2024 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2026 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2027 return 1; // TCL_ERROR
2030 // Verify that the three points are different
2031 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2032 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2033 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2035 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2036 Handle(Geom_CartesianPoint) myCartPointA =
2037 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2039 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2040 Handle(Geom_CartesianPoint) myCartPointB =
2041 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2043 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2044 Handle(Geom_CartesianPoint) myCartPointC =
2045 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2048 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2049 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2050 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2052 std::cout << "vcircle error: Same points.\n";
2053 return 1; // TCL_ERROR
2056 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2057 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2058 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2060 std::cout << "vcircle error: Same points.\n";
2061 return 1; // TCL_ERROR
2064 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2065 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2066 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2068 std::cout << "vcircle error: Same points.\n";
2069 return 1;// TCL_ERROR
2071 // Construction of the circle
2072 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2073 myCartPointB->Pnt(), myCartPointC->Pnt() );
2074 Handle (Geom_Circle) theGeomCircle;
2077 theGeomCircle = Cir.Value();
2079 catch (StdFail_NotDone)
2081 std::cout << "vcircle error: can't create circle\n";
2082 return -1; // TCL_ERROR
2085 DisplayCircle(theGeomCircle, aName, isFilled);
2088 // Arguments: AIS_Plane AIS_Point Real
2089 // ===================================
2090 else if (theShapeA->Type() == AIS_KOI_Datum &&
2091 theShapeA->Signature() == 7 )
2093 if (theShapeB->Type() != AIS_KOI_Datum ||
2094 theShapeB->Signature() != 1 )
2096 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2097 return 1; // TCL_ERROR
2099 // Check that the radius is >= 0
2100 if (Draw::Atof(argv[4]) <= 0 )
2102 std::cout << "vcircle error: the radius must be >=0.\n";
2103 return 1; // TCL_ERROR
2106 // Recover the normal to the plane
2107 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2108 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2110 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2111 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2112 Handle(Geom_CartesianPoint) myCartPointB =
2113 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2115 gp_Pln mygpPlane = myGeomPlane->Pln();
2116 gp_Ax1 thegpAxe = mygpPlane.Axis();
2117 gp_Dir theDir = thegpAxe.Direction();
2118 gp_Pnt theCenter = myCartPointB->Pnt();
2119 Standard_Real TheR = Draw::Atof(argv[4]);
2120 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2121 Handle (Geom_Circle) theGeomCircle;
2124 theGeomCircle = Cir.Value();
2126 catch (StdFail_NotDone)
2128 std::cout << "vcircle error: can't create circle\n";
2129 return -1; // TCL_ERROR
2132 DisplayCircle(theGeomCircle, aName, isFilled);
2139 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2140 return 1; // TCL_ERROR
2144 // No arguments: selection in the viewer
2145 // =========================================
2148 // Get the name of the circle
2149 TCollection_AsciiString aName(argv[1]);
2151 TopTools_ListOfShape aShapes;
2152 ViewerTest::GetSelectedShapes (aShapes);
2153 if (aShapes.Extent() != 3 && aShapes.Extent() != 2)
2155 std::cerr << "Error: Wrong number of selected shapes.\n";
2159 const TopoDS_Shape& aShapeA = aShapes.First();
2160 if (aShapeA.ShapeType() == TopAbs_VERTEX )
2162 if (aShapes.Extent() != 3)
2164 std::cerr << "Error: wrong number of selected shapes.\n";
2168 TopTools_ListOfShape::Iterator anIter (aShapes);
2171 const TopoDS_Shape& aShapeB = anIter.Value();
2174 const TopoDS_Shape& aShapeC = anIter.Value();
2177 Standard_Boolean isFilled;
2178 std::cout << "Enter filled status (0 or 1)\n";
2181 // Construction of the circle
2182 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
2183 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2184 gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC));
2186 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2187 Handle (Geom_Circle) theGeomCircle;
2190 theGeomCircle = Cir.Value();
2192 catch (StdFail_NotDone)
2194 std::cout << "vcircle error: can't create circle\n";
2195 return -1; // TCL_ERROR
2198 DisplayCircle(theGeomCircle, aName, isFilled);
2201 else if (aShapeA.ShapeType() == TopAbs_FACE)
2203 const TopoDS_Shape& aShapeB = aShapes.Last();
2205 // Recover the radius
2206 Standard_Real theRad;
2209 std::cout << " Enter the value of the radius:\n";
2211 } while (theRad <= 0);
2213 // Get filled status
2214 Standard_Boolean isFilled;
2215 std::cout << "Enter filled status (0 or 1)\n";
2218 // Recover the normal to the plane. tag
2219 TopoDS_Face myFace = TopoDS::Face(aShapeA);
2220 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2221 gp_Pln myPlane = mySurface.Plane();
2222 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2223 gp_Pln mygpPlane = theGeomPlane->Pln();
2224 gp_Ax1 thegpAxe = mygpPlane.Axis();
2225 gp_Dir theDir = thegpAxe.Direction();
2227 // Recover the center
2228 gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2230 // Construct the circle
2231 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2232 Handle (Geom_Circle) theGeomCircle;
2235 theGeomCircle = Cir.Value();
2237 catch (StdFail_NotDone)
2239 std::cout << "vcircle error: can't create circle\n";
2240 return -1; // TCL_ERROR
2243 DisplayCircle(theGeomCircle, aName, isFilled);
2247 std::cerr << "Error: You should select face and vertex or three vertices.\n";
2255 //=======================================================================
2256 //function : VDrawText
2258 //=======================================================================
2259 static int VDrawText (Draw_Interpretor& theDI,
2260 Standard_Integer theArgsNb,
2261 const char** theArgVec)
2263 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2266 std::cout << "Error: wrong number of arguments! See usage:\n";
2267 theDI.PrintHelp (theArgVec[0]);
2270 else if (aContext.IsNull())
2272 std::cout << "Error: no active view!\n";
2276 Standard_Integer anArgIt = 1;
2277 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2278 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2279 Handle(AIS_TextLabel) aTextPrs;
2280 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2282 Standard_Boolean isNewPrs = Standard_False;
2283 if (GetMapOfAIS().IsBound2 (aName))
2285 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2288 if (aTextPrs.IsNull())
2290 isNewPrs = Standard_True;
2291 aTextPrs = new AIS_TextLabel();
2292 aTextPrs->SetFont ("Courier");
2295 aTextPrs->SetText (aText);
2297 Handle(Graphic3d_TransformPers) aTrsfPers;
2298 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2300 Standard_Boolean aHasPlane = Standard_False;
2305 for (; anArgIt < theArgsNb; ++anArgIt)
2307 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2310 if (anAutoUpdater.parseRedrawMode (aParam))
2314 else if (aParam == "-pos"
2315 || aParam == "-position")
2317 if (anArgIt + 3 >= theArgsNb)
2319 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2323 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2324 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2325 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2326 aTextPrs->SetPosition (aPos);
2328 else if (aParam == "-color")
2330 if (anArgIt + 1 >= theArgsNb)
2332 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2336 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2337 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2338 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2341 aTextPrs->SetColor (aNameOfColor);
2344 else if (anArgIt + 3 >= theArgsNb)
2346 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2350 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2351 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2352 if (!aColor.IsRealValue()
2353 || !aGreen.IsRealValue()
2354 || !aBlue.IsRealValue())
2356 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2360 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2364 aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2367 else if (aParam == "-halign")
2369 if (++anArgIt >= theArgsNb)
2371 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2375 TCollection_AsciiString aType (theArgVec[anArgIt]);
2377 if (aType == "left")
2379 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2381 else if (aType == "center")
2383 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2385 else if (aType == "right")
2387 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2391 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2395 else if (aParam == "-valign")
2397 if (++anArgIt >= theArgsNb)
2399 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2403 TCollection_AsciiString aType (theArgVec[anArgIt]);
2407 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2409 else if (aType == "center")
2411 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2413 else if (aType == "bottom")
2415 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2417 else if (aType == "topfirstline")
2419 aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2423 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2427 else if (aParam == "-angle")
2429 if (++anArgIt >= theArgsNb)
2431 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2435 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2437 else if (aParam == "-zoom")
2439 if (++anArgIt >= theArgsNb)
2441 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2445 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2447 else if (aParam == "-height")
2449 if (++anArgIt >= theArgsNb)
2451 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2455 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2457 else if (aParam == "-aspect")
2459 if (++anArgIt >= theArgsNb)
2461 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2465 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2466 anOption.LowerCase();
2467 if (anOption.IsEqual ("regular"))
2469 aTextPrs->SetFontAspect (Font_FA_Regular);
2471 else if (anOption.IsEqual ("bold"))
2473 aTextPrs->SetFontAspect (Font_FA_Bold);
2475 else if (anOption.IsEqual ("italic"))
2477 aTextPrs->SetFontAspect (Font_FA_Italic);
2479 else if (anOption.IsEqual ("bolditalic"))
2481 aTextPrs->SetFontAspect (Font_FA_BoldItalic);
2484 else if (aParam == "-font")
2486 if (++anArgIt >= theArgsNb)
2488 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2492 aTextPrs->SetFont (theArgVec[anArgIt]);
2494 else if (aParam == "-plane")
2496 if (anArgIt + 6 >= theArgsNb)
2498 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2502 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
2503 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
2504 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
2505 aNormal.SetCoord (aX, aY, aZ);
2507 aX = Draw::Atof (theArgVec[++anArgIt]);
2508 aY = Draw::Atof (theArgVec[++anArgIt]);
2509 aZ = Draw::Atof (theArgVec[++anArgIt]);
2510 aDirection.SetCoord (aX, aY, aZ);
2512 aHasPlane = Standard_True;
2514 else if (aParam == "-flipping")
2516 aTextPrs->SetFlipping (Standard_True);
2518 else if (aParam == "-disptype"
2519 || aParam == "-displaytype")
2521 if (++anArgIt >= theArgsNb)
2523 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2526 TCollection_AsciiString aType (theArgVec[anArgIt]);
2528 if (aType == "subtitle")
2529 aDisplayType = Aspect_TODT_SUBTITLE;
2530 else if (aType == "decal")
2531 aDisplayType = Aspect_TODT_DEKALE;
2532 else if (aType == "blend")
2533 aDisplayType = Aspect_TODT_BLEND;
2534 else if (aType == "dimension")
2535 aDisplayType = Aspect_TODT_DIMENSION;
2536 else if (aType == "normal")
2537 aDisplayType = Aspect_TODT_NORMAL;
2538 else if (aType == "shadow")
2539 aDisplayType = Aspect_TODT_SHADOW;
2542 std::cout << "Error: wrong display type '" << aType << "'.\n";
2546 else if (aParam == "-subcolor"
2547 || aParam == "-subtitlecolor")
2549 if (anArgIt + 1 >= theArgsNb)
2551 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2555 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2556 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2557 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2560 aTextPrs->SetColorSubTitle (aNameOfColor);
2563 else if (anArgIt + 3 >= theArgsNb)
2565 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2569 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2570 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2571 if (!aColor.IsRealValue()
2572 || !aGreen.IsRealValue()
2573 || !aBlue.IsRealValue())
2575 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2579 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2583 aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2586 else if (aParam == "-2d")
2588 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d);
2590 else if (aParam == "-trsfperspos"
2591 || aParam == "-perspos")
2593 if (anArgIt + 2 >= theArgsNb)
2595 std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2599 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2600 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2601 TCollection_AsciiString aZ = "0";
2602 if (!aX.IsIntegerValue()
2603 || !aY.IsIntegerValue())
2605 std::cerr << "Error: wrong syntax at '" << aParam << "'.\n";
2608 if (anArgIt + 1 < theArgsNb)
2610 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2611 if (aTemp.IsIntegerValue())
2618 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()));
2622 std::cout << "Error: unknown argument '" << aParam << "'\n";
2629 aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2632 aTextPrs->SetDisplayType (aDisplayType);
2634 if (!aTrsfPers.IsNull())
2636 aContext->SetTransformPersistence (aTextPrs, aTrsfPers);
2637 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2638 if (aTextPrs->Position().Z() != 0)
2640 aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
2643 else if (!aTextPrs->TransformPersistence().IsNull())
2645 aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
2650 ViewerTest::Display (aName, aTextPrs, Standard_False);
2654 aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
2660 #include <gp_Pnt.hxx>
2661 #include <Graphic3d_ArrayOfPoints.hxx>
2662 #include <Graphic3d_ArrayOfPrimitives.hxx>
2663 #include <Graphic3d_ArrayOfTriangles.hxx>
2664 #include <Poly_Array1OfTriangle.hxx>
2665 #include <Poly_Triangle.hxx>
2666 #include <Poly_Triangulation.hxx>
2667 #include <TColgp_Array1OfPnt.hxx>
2668 #include <TShort_Array1OfShortReal.hxx>
2669 #include <TShort_HArray1OfShortReal.hxx>
2671 #include <AIS_Triangulation.hxx>
2672 #include <StdPrs_ToolTriangulatedShape.hxx>
2673 #include <Poly_Connect.hxx>
2674 #include <TColgp_Array1OfDir.hxx>
2675 #include <Graphic3d_GraphicDriver.hxx>
2677 #include <TColStd_Array1OfInteger.hxx>
2678 #include <TColStd_HArray1OfInteger.hxx>
2679 #include <Prs3d_ShadingAspect.hxx>
2680 #include <Graphic3d_MaterialAspect.hxx>
2681 #include <Graphic3d_AspectFillArea3d.hxx>
2683 #include <BRepPrimAPI_MakeCylinder.hxx>
2684 #include <TopoDS_Shape.hxx>
2685 #include <TopExp_Explorer.hxx>
2686 #include <TopAbs.hxx>
2687 #include <StdSelect_ShapeTypeFilter.hxx>
2688 #include <AIS_InteractiveObject.hxx>
2691 //===============================================================================================
2692 //function : CalculationOfSphere
2694 //purpose : Create a Sphere
2695 //===============================================================================================
2697 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2700 double mRadius = Radius;
2701 double mCenter[3] = {X,Y,Z};
2702 int mThetaResolution;
2704 double mStartTheta = 0;//StartTheta;
2705 double mEndTheta = 360;//EndTheta;
2706 double mStartPhi = 0;//StartPhi;
2707 double mEndPhi = 180;//EndPhi;
2708 res = res < 4 ? 4 : res;
2710 mThetaResolution = res;
2711 mPhiResolution = res;
2714 int jStart, jEnd, numOffset;
2715 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2716 double startTheta, endTheta, startPhi, endPhi;
2717 int base, numPoles=0, thetaResolution, phiResolution;
2722 if ( numPieces > mThetaResolution ) {
2723 numPieces = mThetaResolution;
2726 int localThetaResolution = mThetaResolution;
2727 double localStartTheta = mStartTheta;
2728 double localEndTheta = mEndTheta;
2730 while ( localEndTheta < localStartTheta ) {
2731 localEndTheta += 360.0;
2734 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2736 // Change the ivars based on pieces.
2738 start = piece * localThetaResolution / numPieces;
2739 end = (piece+1) * localThetaResolution / numPieces;
2740 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2741 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2742 localThetaResolution = end - start;
2744 // Create north pole if needed
2745 int number_point = 0;
2746 int number_pointArray = 0;
2748 if ( mStartPhi <= 0.0 ) {
2749 number_pointArray++;
2752 if ( mEndPhi >= 180.0 ) {
2753 number_pointArray++;
2757 // Check data, determine increments, and convert to radians
2758 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2759 startTheta *= M_PI / 180.0;
2760 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2761 endTheta *= M_PI / 180.0;
2764 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2765 startPhi *= M_PI / 180.0;
2766 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2767 endPhi *= M_PI / 180.0;
2769 phiResolution = mPhiResolution - numPoles;
2770 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2771 thetaResolution = localThetaResolution;
2772 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2773 ++localThetaResolution;
2775 deltaTheta = (endTheta - startTheta) / thetaResolution;
2777 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2778 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2780 // Create intermediate points
2781 for ( i = 0; i < localThetaResolution; i++ ) {
2782 for ( j = jStart; j < jEnd; j++ ) {
2783 number_pointArray++;
2787 //Generate mesh connectivity
2788 base = phiResolution * localThetaResolution;
2790 int number_triangle = 0 ;
2791 if ( mStartPhi <= 0.0 ) { // around north pole
2792 number_triangle += localThetaResolution;
2795 if ( mEndPhi >= 180.0 ) { // around south pole
2796 number_triangle += localThetaResolution;
2799 // bands in-between poles
2800 for ( i=0; i < localThetaResolution; i++){
2801 for ( j=0; j < (phiResolution-1); j++){
2802 number_triangle +=2;
2806 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2807 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2808 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2810 if ( mStartPhi <= 0.0 ){
2813 x[2] = mCenter[2] + mRadius;
2814 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2817 // Create south pole if needed
2818 if ( mEndPhi >= 180.0 ){
2821 x[2] = mCenter[2] - mRadius;
2822 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2826 for ( i=0; i < localThetaResolution; i++){
2827 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2828 for ( j = jStart; j < jEnd; j++){
2829 phi = startPhi + j*deltaPhi;
2830 radius = mRadius * sin((double)phi);
2831 n[0] = radius * cos((double)theta);
2832 n[1] = radius * sin((double)theta);
2833 n[2] = mRadius * cos((double)phi);
2834 x[0] = n[0] + mCenter[0];
2835 x[1] = n[1] + mCenter[1];
2836 x[2] = n[2] + mCenter[2];
2837 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2843 number_triangle = 1;
2844 if ( mStartPhi <= 0.0 ){// around north pole
2845 for (i=0; i < localThetaResolution; i++){
2846 pts[0] = phiResolution*i + numPoles;
2847 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2849 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2854 if ( mEndPhi >= 180.0 ){ // around south pole
2855 numOffset = phiResolution - 1 + numPoles;
2856 for (i=0; i < localThetaResolution; i++){
2857 pts[0] = phiResolution*i + numOffset;
2858 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2859 pts[1] = numPoles - 1;
2860 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2865 // bands in-between poles
2867 for (i=0; i < localThetaResolution; i++){
2868 for (j=0; j < (phiResolution-1); j++){
2869 pts[0] = phiResolution*i + j + numPoles;
2870 pts[1] = pts[0] + 1;
2871 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2872 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2875 pts[2] = pts[1] - 1;
2876 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2881 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2883 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2885 Standard_Integer index[3];
2886 Standard_Real Tol = Precision::Confusion();
2889 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2890 gp_XYZ eqPlan(0, 0, 0);
2891 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2892 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2893 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2894 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2896 Standard_Real mod = vv.Modulus();
2897 if(mod < Tol) continue;
2901 Standard_Real modmax = eqPlan.Modulus();
2904 Nor = gp_Dir(eqPlan);
2906 Nor = gp_Dir(0., 0., 1.);
2908 Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
2909 Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
2910 Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
2911 Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
2915 polyTriangulation->SetNormals(Normals);
2917 return polyTriangulation;
2920 //===============================================================================================
2921 //function : VDrawSphere
2923 //purpose : Create an AIS shape.
2924 //===============================================================================================
2925 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2928 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2929 if (aContextAIS.IsNull())
2931 std::cout << "Call vinit before!\n";
2936 std::cout << "Use: " << argv[0]
2937 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2941 // read the arguments
2942 TCollection_AsciiString aShapeName (argv[1]);
2943 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2944 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2945 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2946 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2947 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2948 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2949 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
2951 // remove AIS object with given name from map
2952 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2955 std::cout << "Compute Triangulation...\n";
2956 Handle(AIS_Triangulation) aShape
2957 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2960 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2961 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2963 // stupid initialization of Green color in RGBA space as integer
2964 // probably wrong for big-endian CPUs
2965 const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
2967 // setup colors array per vertex
2968 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2969 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2971 aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData()));
2973 aShape->SetColors (aColorArray);
2976 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2977 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2978 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2979 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2980 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2981 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2982 aTotalSize >>= 20; //MB
2983 aNormalsSize >>= 20;
2985 aTrianglesSize >>= 20;
2986 aPolyConnectSize >>= 20;
2989 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2990 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2991 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2992 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2993 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2994 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2997 // Setting material properties, very important for desirable visual result!
2998 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2999 aMat.SetAmbient (0.2f);
3000 aMat.SetSpecular (0.5f);
3001 Handle(Graphic3d_AspectFillArea3d) anAspect
3002 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3004 Quantity_NOC_YELLOW,
3009 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3012 anAspect->SetEdgeOn();
3016 anAspect->SetEdgeOff();
3018 aShAsp->SetAspect (anAspect);
3019 aShape->Attributes()->SetShadingAspect (aShAsp);
3021 VDisplayAISObject (aShapeName, aShape);
3025 //=============================================================================
3026 //function : VComputeHLR
3028 //=============================================================================
3030 static int VComputeHLR (Draw_Interpretor& ,
3031 Standard_Integer theArgNb,
3032 const char** theArgVec)
3034 TCollection_AsciiString aShapeName, aHlrName;
3039 bool hasViewDirArg = false;
3040 Prs3d_TypeOfHLR anAlgoType = Prs3d_TOH_PolyAlgo;
3041 bool toShowTangentEdges = false, toShowHiddenEdges = false;
3042 int aNbIsolines = 0;
3043 if (Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext())
3046 Handle(V3d_View) aView = ViewerTest::CurrentView();
3047 Standard_Integer aWidth, aHeight;
3048 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3049 Standard_Real aRightX, aRightY, aRightZ;
3050 aView->Window()->Size (aWidth, aHeight);
3052 aView->ConvertWithProj (aWidth, aHeight/2,
3053 aRightX, aRightY, aRightZ,
3054 aDirX, aDirY, aDirZ);
3055 aView->ConvertWithProj (aWidth/2, aHeight/2,
3056 aCentX, aCentY, aCentZ,
3057 aDirX, aDirY, aDirZ);
3059 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3060 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3061 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3062 aProjAx.SetLocation (anEye);
3063 aProjAx.SetDirection (aDir);
3064 aProjAx.SetXDirection (aRight);
3066 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3068 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3069 anArgCase.LowerCase();
3070 if (anArgIter + 1 < theArgNb
3071 && (anArgCase == "-algotype"
3072 || anArgCase == "-algo"
3073 || anArgCase == "-type"))
3075 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
3076 anArgNext.LowerCase();
3077 if (anArgNext == "polyalgo")
3079 anAlgoType = Prs3d_TOH_PolyAlgo;
3081 else if (anArgNext == "algo")
3083 anAlgoType = Prs3d_TOH_Algo;
3087 std::cout << "Syntax error: unknown algo type '" << anArgNext << "'\n";
3091 else if (anArgCase == "-showhiddenedges"
3092 || anArgCase == "-hiddenedges"
3093 || anArgCase == "-hidden")
3095 toShowHiddenEdges = true;
3096 if (anArgIter + 1 < theArgNb
3097 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowHiddenEdges))
3102 else if (anArgCase == "-showtangentedges"
3103 || anArgCase == "-tangentedges"
3104 || anArgCase == "-tangent")
3106 toShowTangentEdges = true;
3107 if (anArgIter + 1 < theArgNb
3108 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowTangentEdges))
3113 else if (anArgIter + 1 < theArgNb
3114 && (anArgCase == "-nbiso"
3115 || anArgCase == "-nbisolines"))
3117 aNbIsolines = Draw::Atoi (theArgVec[++anArgIter]);
3119 else if (aSh.IsNull())
3121 aSh = DBRep::Get (theArgVec[anArgIter]);
3122 aShapeName = theArgVec[anArgIter];
3125 BRep_Builder aBrepBuilder;
3126 BRepTools::Read (aSh, theArgVec[anArgIter], aBrepBuilder);
3129 std::cout << "Syntax error: no shape with name " << theArgVec[anArgIter] << " found\n";
3134 else if (aHlrName.IsEmpty())
3136 aHlrName = theArgVec[anArgIter];
3138 else if (!hasViewDirArg
3139 && anArgIter + 8 < theArgNb)
3141 hasViewDirArg = true;
3143 anEye.SetCoord (Draw::Atof (theArgVec[anArgIter + 0]), Draw::Atof (theArgVec[anArgIter + 1]), Draw::Atof (theArgVec[anArgIter + 2]));
3144 aDir .SetCoord (Draw::Atof (theArgVec[anArgIter + 3]), Draw::Atof (theArgVec[anArgIter + 4]), Draw::Atof (theArgVec[anArgIter + 5]));
3145 anUp .SetCoord (Draw::Atof (theArgVec[anArgIter + 6]), Draw::Atof (theArgVec[anArgIter + 7]), Draw::Atof (theArgVec[anArgIter + 8]));
3146 aProjAx.SetLocation (anEye);
3147 aProjAx.SetDirection (aDir);
3148 aProjAx.SetYDirection (anUp);
3153 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n";
3158 if (aHlrName.IsEmpty() || aSh.IsNull()
3159 || (ViewerTest::GetAISContext().IsNull() && hasViewDirArg))
3161 std::cout << "Syntax error: wrong number of arguments\n";
3165 HLRAlgo_Projector aProjector (aProjAx);
3166 TopoDS_Shape aVisible[6];
3167 TopoDS_Shape aHidden[6];
3168 if (anAlgoType == Prs3d_TOH_PolyAlgo)
3170 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3171 aPolyAlgo->Projector (aProjector);
3172 aPolyAlgo->Load (aSh);
3173 aPolyAlgo->Update();
3175 HLRBRep_PolyHLRToShape aHLRToShape;
3176 aHLRToShape.Update (aPolyAlgo);
3178 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3179 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); // extract visible outlines
3180 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3181 if (toShowTangentEdges)
3183 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3185 if (toShowHiddenEdges)
3187 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3188 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3189 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3190 if (toShowTangentEdges)
3192 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3198 Handle(HLRBRep_Algo) aHlrAlgo = new HLRBRep_Algo();
3199 aHlrAlgo->Add (aSh, aNbIsolines);
3200 aHlrAlgo->Projector (aProjector);
3204 HLRBRep_HLRToShape aHLRToShape (aHlrAlgo);
3205 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3206 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound();
3207 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3208 if (toShowTangentEdges)
3210 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3212 aVisible[HLRBRep_IsoLine] = aHLRToShape.IsoLineVCompound();
3214 if (toShowHiddenEdges)
3216 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3217 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3218 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3219 if (toShowTangentEdges)
3221 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3223 aHidden[HLRBRep_IsoLine] = aHLRToShape.IsoLineHCompound();
3226 //aVisible[HLRBRep_Sharp] = aHLRToShape.CompoundOfEdges (HLRBRep_Sharp, Standard_True, Standard_True);
3227 //aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound3d();
3230 TopoDS_Compound aCompRes, aCompVis, aCompHid;
3231 BRep_Builder aBuilder;
3232 aBuilder.MakeCompound (aCompVis);
3233 aBuilder.MakeCompound (aCompHid);
3234 aBuilder.MakeCompound (aCompRes);
3235 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3237 if (!aVisible[aTypeIter].IsNull())
3239 aBuilder.Add (aCompVis, aVisible[aTypeIter]);
3241 if (!aHidden[aTypeIter].IsNull())
3243 aBuilder.Add (aCompHid, aHidden[aTypeIter]);
3246 aBuilder.Add (aCompRes, aCompVis);
3247 aBuilder.Add (aCompRes, aCompHid);
3249 // create an AIS shape and display it
3250 if (!ViewerTest::GetAISContext().IsNull())
3252 Handle(AIS_ColoredShape) anObject = new AIS_ColoredShape (aCompRes);
3253 if (toShowHiddenEdges)
3255 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect (Quantity_Color (Quantity_NOC_RED), Aspect_TOL_DASH, 1.0f);
3256 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3258 if (!aHidden[aTypeIter].IsNull())
3260 Handle(AIS_ColoredDrawer) aDrawer = anObject->CustomAspects (aHidden[aTypeIter]);
3261 aDrawer->SetLineAspect (aLineAspect);
3262 aDrawer->SetWireAspect (aLineAspect);
3263 aDrawer->SetFreeBoundaryAspect (aLineAspect);
3264 aDrawer->SetUnFreeBoundaryAspect (aLineAspect);
3268 ViewerTest::Display (aHlrName, anObject, true);
3271 DBRep::Set (aHlrName.ToCString(), aCompRes);
3275 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3276 // manipulating and displaying such an array with AIS context
3278 class MyPArrayObject : public AIS_InteractiveObject
3283 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives)& thePArray) : myPArray (thePArray) {}
3285 MyPArrayObject (Graphic3d_TypeOfPrimitiveArray thePrimType,
3286 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3287 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect)
3289 Init (thePrimType, theDesc, theMarkerAspect, Standard_False);
3292 //! Initialize the array from specified description.
3293 Standard_Boolean Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3294 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3295 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3296 Standard_Boolean theToPatch);
3298 DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
3300 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
3304 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3305 const Handle(Prs3d_Presentation)& aPresentation,
3306 const Standard_Integer aMode) Standard_OVERRIDE;
3308 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3309 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
3311 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3312 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3313 Standard_Integer &theArgIndex,
3314 Standard_Integer theArgCount,
3315 Standard_Integer theMaxArgs);
3319 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3320 Handle(Graphic3d_ArrayOfPrimitives) myPArray;
3324 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3325 const Handle(Prs3d_Presentation)& thePrs,
3326 const Standard_Integer theMode)
3328 if (myPArray.IsNull() || theMode != 0)
3333 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
3334 if (!myMarkerAspect.IsNull())
3336 aGroup->SetGroupPrimitivesAspect (myMarkerAspect);
3338 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
3339 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
3340 aGroup->AddPrimitiveArray (myPArray);
3343 Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimType,
3344 const Handle(TColStd_HArray1OfAsciiString)& theDesc,
3345 const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect,
3346 Standard_Boolean theToPatch)
3348 myMarkerAspect = theMarkerAspect;
3354 // Parsing array description
3355 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3356 Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None;
3358 const Standard_Integer anArgsCount = theDesc->Length();
3359 TCollection_AsciiString aCommand;
3360 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3362 aCommand = theDesc->Value (anArgIndex);
3363 aCommand.LowerCase();
3365 if (CheckInputCommand ("-deinterleaved", theDesc, anArgIndex, 0, anArgsCount))
3367 anArrayFlags |= Graphic3d_ArrayFlags_AttribsDeinterleaved;
3369 else if (CheckInputCommand ("-mutable", theDesc, anArgIndex, 0, anArgsCount))
3371 anArrayFlags |= Graphic3d_ArrayFlags_AttribsMutable;
3372 anArrayFlags |= Graphic3d_ArrayFlags_IndexesMutable;
3375 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3377 // vertex has a normal or normal with color or texel
3378 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3380 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal;
3383 // vertex has a color
3384 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3386 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor;
3389 // vertex has a texel
3390 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3392 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel;
3398 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3401 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3403 anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor;
3409 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3418 if (myPArray.IsNull())
3420 myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
3424 if (myPArray->Type() != thePrimType
3425 || aVertexNum > myPArray->VertexNumberAllocated()
3426 || aEdgeNum > myPArray->EdgeNumberAllocated()
3427 || aBoundNum > myPArray->BoundNumberAllocated()
3428 || !myPArray->Attributes()->IsMutable()
3429 || (!myPArray->Indices().IsNull() && !myPArray->Indices()->IsMutable()))
3431 std::cout << "Syntax error: array cannot be patched\n";
3432 return Standard_False;
3435 myPArray->Attributes()->NbElements = aVertexNum;
3436 if (Handle(Graphic3d_AttribBuffer) anAttribs = Handle(Graphic3d_AttribBuffer)::DownCast (myPArray->Attributes()))
3438 anAttribs->Invalidate (0, aVertexNum - 1);
3440 if (!myPArray->Indices().IsNull())
3442 myPArray->Indices()->NbElements = aEdgeNum;
3444 if (!myPArray->Bounds().IsNull())
3446 myPArray->Bounds()->NbBounds = aBoundNum;
3450 Standard_Integer aVertIndex = 0;
3451 for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); )
3453 aCommand = theDesc->Value (anArgIndex);
3454 aCommand.LowerCase();
3455 if (!aCommand.IsAscii()
3456 || aCommand.IsEmpty())
3461 // skip beautifiers (syntax is not actually validated)
3462 if (aCommand == "-deinterleaved"
3463 || aCommand == "-mutable"
3464 || aCommand.Value (1) == '('
3465 || aCommand.Value (1) == ')'
3466 || aCommand.Value (1) == ',')
3471 else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount))
3473 const Graphic3d_Vec3 aVert ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3474 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3475 (float )theDesc->Value (anArgIndex - 1).RealValue());
3476 if ((anArrayFlags & Graphic3d_ArrayFlags_AttribsDeinterleaved) != 0
3477 || (anArrayFlags & Graphic3d_ArrayFlags_AttribsMutable) != 0)
3480 myPArray->SetVertice (aVertIndex, aVert.x(), aVert.y(), aVert.z());
3484 aVertIndex = myPArray->AddVertex (aVert);
3487 // vertex has a normal or normal with color or texel
3488 if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount))
3490 const Graphic3d_Vec3 aNorm ((float )theDesc->Value (anArgIndex - 3).RealValue(),
3491 (float )theDesc->Value (anArgIndex - 2).RealValue(),
3492 (float )theDesc->Value (anArgIndex - 1).RealValue());
3493 myPArray->SetVertexNormal (aVertIndex, aNorm.x(), aNorm.y(), aNorm.z());
3496 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3498 const Graphic3d_Vec3d aCol (theDesc->Value (anArgIndex - 3).RealValue(),
3499 theDesc->Value (anArgIndex - 2).RealValue(),
3500 theDesc->Value (anArgIndex - 1).RealValue());
3501 myPArray->SetVertexColor (aVertIndex, aCol.r(), aCol.g(), aCol.b());
3503 if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
3505 const Graphic3d_Vec2 aTex ((float )theDesc->Value (anArgIndex - 2).RealValue(),
3506 (float )theDesc->Value (anArgIndex - 1).RealValue());
3507 myPArray->SetVertexTexel (aVertIndex, aTex.x(), aTex.y());
3511 else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount))
3513 Standard_Integer aVertCount = theDesc->Value (anArgIndex - 1).IntegerValue();
3515 if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount))
3516 myPArray->AddBound (aVertCount,
3517 theDesc->Value (anArgIndex - 3).RealValue(),
3518 theDesc->Value (anArgIndex - 2).RealValue(),
3519 theDesc->Value (anArgIndex - 1).RealValue());
3522 myPArray->AddBound (aVertCount);
3525 else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount))
3527 const Standard_Integer anEdge = theDesc->Value (anArgIndex - 1).IntegerValue();
3528 myPArray->AddEdge (anEdge);
3533 std::cout << "Syntax error: unknown argument '" << theDesc->Value(anArgIndex) << "'\n";
3534 return Standard_False;
3537 return Standard_True;
3540 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3541 const Standard_Integer theMode)
3544 || myPArray.IsNull())
3549 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
3550 if (Handle(Graphic3d_ArrayOfTriangles) aTris = Handle(Graphic3d_ArrayOfTriangles)::DownCast (myPArray))
3552 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3553 aSensitive->InitTriangulation (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3554 theSelection->Add (aSensitive);
3556 else if (Handle(Graphic3d_ArrayOfSegments) aSegs = Handle(Graphic3d_ArrayOfSegments)::DownCast (myPArray))
3558 if (aSegs->EdgeNumber() > 0)
3560 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->EdgeNumber(); aPntIter += 2)
3562 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aSegs->Edge (aPntIter)), aSegs->Vertice (aSegs->Edge (aPntIter + 1)));
3563 aSeg->SetSensitivityFactor (4);
3564 theSelection->Add (aSeg);
3569 for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->VertexNumber(); aPntIter += 2)
3571 Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aPntIter), aSegs->Vertice (aPntIter + 1));
3572 aSeg->SetSensitivityFactor (4);
3573 theSelection->Add (aSeg);
3579 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
3580 aSensitive->SetSensitivityFactor (8);
3581 aSensitive->InitPoints (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true);
3582 theSelection->Add (aSensitive);
3586 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3587 const Handle(TColStd_HArray1OfAsciiString)& theArgsArray,
3588 Standard_Integer &theArgIndex,
3589 Standard_Integer theArgCount,
3590 Standard_Integer theMaxArgs)
3592 // check if there is more elements than expected
3593 if (theArgIndex >= theMaxArgs)
3596 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3597 aStrCommand.LowerCase();
3598 if (aStrCommand.Search(theCommand) != 1 ||
3599 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3602 // go to the first data element
3605 // check data if it can be converted to numeric
3606 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3608 aStrCommand = theArgsArray->Value (theArgIndex);
3609 if (!aStrCommand.IsRealValue())
3616 //=============================================================================
3617 //function : VDrawPArray
3618 //purpose : Draws primitives array from list of vertexes, bounds, edges
3619 //=============================================================================
3621 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3623 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3624 if (aContextAIS.IsNull())
3626 std::cout << "Error: no active Viewer\n";
3631 std::cout << "Syntax error: wrong number of arguments\n";
3635 // read the arguments
3636 Standard_Integer anArgIndex = 1;
3637 TCollection_AsciiString aName (argv[anArgIndex++]);
3638 TCollection_AsciiString anArrayType (argv[anArgIndex++]);
3639 anArrayType.LowerCase();
3640 Handle(MyPArrayObject) aPObject;
3641 if (anArrayType == "-shape")
3643 Standard_CString aShapeName = argv[anArgIndex++];
3644 TopoDS_Shape aShape = DBRep::Get (aShapeName);
3645 Handle(Graphic3d_ArrayOfPrimitives) aTris = StdPrs_ShadedShape::FillTriangles (aShape);
3646 if (aShape.IsNull())
3648 std::cout << "Syntax error: shape '" << aShapeName << "' is not found\n";
3651 else if (aTris.IsNull())
3653 std::cout << "Syntax error: shape '" << aShapeName << "' is not triangulated\n";
3657 aPObject = new MyPArrayObject (aTris);
3658 ViewerTest::Display (aName, aPObject);
3661 else if (anArrayType == "-patch"
3662 || anArrayType == "-modify"
3663 || anArrayType == "-edit")
3667 anArrayType = argv[anArgIndex++];
3668 anArrayType.LowerCase();
3671 if (GetMapOfAIS().IsBound2 (aName))
3673 aPObject = Handle(MyPArrayObject)::DownCast (GetMapOfAIS().Find2 (aName));
3675 if (aPObject.IsNull())
3677 std::cout << "Syntax error: object '" << aName << "' cannot be found\n";
3682 Standard_Boolean hasVertex = Standard_False;
3684 Graphic3d_TypeOfPrimitiveArray aPrimType = Graphic3d_TOPA_UNDEFINED;
3685 if (anArrayType == "points")
3687 aPrimType = Graphic3d_TOPA_POINTS;
3689 else if (anArrayType == "segments")
3691 aPrimType = Graphic3d_TOPA_SEGMENTS;
3693 else if (anArrayType == "polylines")
3695 aPrimType = Graphic3d_TOPA_POLYLINES;
3697 else if (anArrayType == "triangles")
3699 aPrimType = Graphic3d_TOPA_TRIANGLES;
3701 else if (anArrayType == "trianglefans")
3703 aPrimType = Graphic3d_TOPA_TRIANGLEFANS;
3705 else if (anArrayType == "trianglestrips")
3707 aPrimType = Graphic3d_TOPA_TRIANGLESTRIPS;
3709 else if (anArrayType == "quads")
3711 aPrimType = Graphic3d_TOPA_QUADRANGLES;
3713 else if (anArrayType == "quadstrips")
3715 aPrimType = Graphic3d_TOPA_QUADRANGLESTRIPS;
3717 else if (anArrayType == "polygons")
3719 aPrimType = Graphic3d_TOPA_POLYGONS;
3721 if (aPrimType == Graphic3d_TOPA_UNDEFINED)
3723 std::cout << "Syntax error: unexpected type of primitives array\n";
3727 Standard_Integer aLowerArg = anArgIndex;
3728 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 3);
3729 for (; anArgIndex < argc; ++anArgIndex)
3731 TCollection_AsciiString aCommand (argv[anArgIndex]);
3732 aCommand.LowerCase();
3733 if (!aCommand.IsAscii())
3735 di << "Unexpected argument: #" << anArgIndex - 1 << " , "
3736 << "should be an array element: 'v', 'b', 'e' \n";
3740 if (aCommand == "v")
3742 hasVertex = Standard_True;
3745 anArgsArray->SetValue (anArgIndex - aLowerArg, aCommand);
3750 di << "You should pass any verticies in the list of array elements\n";
3754 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3755 if (aPrimType == Graphic3d_TOPA_POINTS)
3757 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3760 // create primitives array object
3761 if (aPObject.IsNull())
3763 // register the object in map
3764 aPObject = new MyPArrayObject (aPrimType, anArgsArray, anAspPoints);
3765 VDisplayAISObject (aName, aPObject);
3769 aPObject->Init (aPrimType, anArgsArray, anAspPoints, Standard_True);
3770 ViewerTest::CurrentView()->Redraw();
3777 //! Auxiliary function for parsing translation vector - either 2D or 3D.
3778 static Standard_Integer parseTranslationVec (Standard_Integer theArgNb,
3779 const char** theArgVec,
3787 TCollection_AsciiString anX (theArgVec[0]);
3788 TCollection_AsciiString anY (theArgVec[1]);
3789 if (!anX.IsRealValue()
3790 || !anY.IsRealValue())
3795 theVec.SetX (anX.RealValue());
3796 theVec.SetY (anY.RealValue());
3799 TCollection_AsciiString anZ (theArgVec[2]);
3800 if (anZ.IsRealValue())
3802 theVec.SetZ (anZ.RealValue());
3810 //=======================================================================
3811 //function : VSetLocation
3812 //purpose : Change location of AIS interactive object
3813 //=======================================================================
3815 static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
3816 Standard_Integer theArgNb,
3817 const char** theArgVec)
3819 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3820 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3821 if (aContext.IsNull())
3823 std::cout << "Error: no active view!\n";
3827 Standard_Boolean toPrintInfo = Standard_True;
3828 Handle(AIS_InteractiveObject) anObj;
3829 TCollection_AsciiString aCmdName (theArgVec[0]);
3830 aCmdName.LowerCase();
3831 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3833 TCollection_AsciiString anArg = theArgVec[anArgIter];
3835 if (anUpdateTool.parseRedrawMode (anArg))
3839 else if (anObj.IsNull())
3841 const TCollection_AsciiString aName (theArgVec[anArgIter]);
3842 GetMapOfAIS().Find2 (aName, anObj);
3845 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3849 else if (anArg == "-reset")
3851 toPrintInfo = Standard_False;
3852 aContext->SetLocation (anObj, gp_Trsf());
3854 else if (anArg == "-copyfrom"
3855 || anArg == "-copy")
3857 if (anArgIter + 1 >= theArgNb)
3859 std::cout << "Syntax error at '" << anArg << "'\n";
3863 const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]);
3864 Handle(AIS_InteractiveObject) anObj2;
3865 GetMapOfAIS().Find2 (aName2, anObj2);
3866 if (anObj2.IsNull())
3868 std::cout << "Error: object '" << aName2 << "' is not displayed!\n";
3873 aContext->SetLocation (anObj, anObj2->LocalTransformation());
3875 else if (anArg == "-rotate")
3877 toPrintInfo = Standard_False;
3878 if (anArgIter + 7 >= theArgNb)
3880 std::cout << "Syntax error at '" << anArg << "'\n";
3885 aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]),
3886 Draw::Atof (theArgVec[anArgIter + 2]),
3887 Draw::Atof (theArgVec[anArgIter + 3])),
3888 gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]),
3889 Draw::Atof (theArgVec[anArgIter + 5]),
3890 Draw::Atof (theArgVec[anArgIter + 6]))),
3891 Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0));
3894 aTrsf = anObj->LocalTransformation() * aTrsf;
3895 aContext->SetLocation (anObj, aTrsf);
3897 else if (anArg == "-translate")
3899 toPrintInfo = Standard_False;
3901 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
3902 anArgIter += aNbParsed;
3905 std::cout << "Syntax error at '" << anArg << "'\n";
3910 aTrsf.SetTranslationPart (aLocVec);
3911 aTrsf = anObj->LocalTransformation() * aTrsf;
3912 aContext->SetLocation (anObj, aTrsf);
3914 else if (anArg == "-scale"
3915 || anArg == "-setscale")
3917 toPrintInfo = Standard_False;
3919 Standard_Real aScale = 1.0;
3920 Standard_Boolean toPrintScale = Standard_True;
3921 Standard_Boolean hasScaleLoc = Standard_False;
3922 if (anArgIter + 4 < theArgNb)
3924 TCollection_AsciiString aScaleArgs[4] =
3926 TCollection_AsciiString (theArgVec[anArgIter + 1]),
3927 TCollection_AsciiString (theArgVec[anArgIter + 2]),
3928 TCollection_AsciiString (theArgVec[anArgIter + 3]),
3929 TCollection_AsciiString (theArgVec[anArgIter + 4])
3931 Standard_Integer aScaleArgIter = 0;
3932 for (; aScaleArgIter < 4; ++aScaleArgIter)
3934 if (!aScaleArgs[aScaleArgIter].IsRealValue())
3939 if (aScaleArgIter == 4)
3941 aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue());
3942 aScale = aScaleArgs[3].RealValue();
3944 toPrintScale = Standard_False;
3945 hasScaleLoc = Standard_True;
3947 else if (aScaleArgIter >= 1)
3949 aScale = aScaleArgs[0].RealValue();
3951 toPrintScale = Standard_False;
3954 else if (anArgIter + 1 < theArgNb)
3956 TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]);
3957 if (aScaleArg.IsRealValue())
3959 aScale = aScaleArg.RealValue();
3961 toPrintScale = Standard_False;
3967 if (anArg == "-setscale")
3969 std::cout << "Syntax error at '" << anArg << "'\n";
3974 Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor());
3979 if (anArg == "-setscale")
3981 gp_Trsf aTrsf = anObj->LocalTransformation();
3984 aTrsf.SetScale (aScaleLoc, aScale);
3988 aTrsf.SetScaleFactor (aScale);
3990 aContext->SetLocation (anObj, aTrsf);
3997 aTrsf.SetScale (aScaleLoc, aScale);
3998 aTrsf = anObj->LocalTransformation() * aTrsf;
4002 aTrsf = anObj->LocalTransformation();
4003 aTrsf.SetScaleFactor (aTrsf.ScaleFactor() * aScale);
4005 aContext->SetLocation (anObj, aTrsf);
4008 else if (anArg == "-mirror")
4010 toPrintInfo = Standard_False;
4011 if (anArgIter + 6 >= theArgNb)
4013 std::cout << "Syntax error at '" << anArg << "'\n";
4018 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
4019 Draw::Atof(theArgVec[theArgNb - 5]),
4020 Draw::Atof(theArgVec[theArgNb - 4])),
4021 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
4022 Draw::Atof(theArgVec[theArgNb - 2]),
4023 Draw::Atof(theArgVec[theArgNb - 1]))));
4025 aTrsf = anObj->LocalTransformation() * aTrsf;
4026 aContext->SetLocation (anObj, aTrsf);
4028 else if (anArg == "-setrotation"
4029 || anArg == "-rotation")
4031 toPrintInfo = Standard_False;
4032 if (anArgIter + 4 < theArgNb)
4034 TCollection_AsciiString aQuatArgs[4] =
4036 TCollection_AsciiString (theArgVec[anArgIter + 1]),
4037 TCollection_AsciiString (theArgVec[anArgIter + 2]),
4038 TCollection_AsciiString (theArgVec[anArgIter + 3]),
4039 TCollection_AsciiString (theArgVec[anArgIter + 4])
4041 Standard_Integer aQuatArgIter = 0;
4042 for (; aQuatArgIter < 4; ++aQuatArgIter)
4044 if (!aQuatArgs[aQuatArgIter].IsRealValue())
4050 if (aQuatArgIter == 4)
4053 const gp_Quaternion aQuat (aQuatArgs[0].RealValue(),
4054 aQuatArgs[1].RealValue(),
4055 aQuatArgs[2].RealValue(),
4056 aQuatArgs[3].RealValue());
4057 gp_Trsf aTrsf = anObj->LocalTransformation();
4058 aTrsf.SetRotation (aQuat);
4059 aContext->SetLocation (anObj, aTrsf);
4062 else if (anArg == "-setrotation")
4064 std::cout << "Syntax error at '" << anArg << "'\n";
4070 const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation();
4071 Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W());
4074 else if (anArg == "-setlocation"
4075 || anArg == "-location")
4077 toPrintInfo = Standard_False;
4079 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
4080 anArgIter += aNbParsed;
4083 gp_Trsf aTrsf = anObj->LocalTransformation();
4084 aTrsf.SetTranslationPart (aLocVec);
4085 aContext->SetLocation (anObj, aTrsf);
4087 else if (anArg == "-setlocation")
4089 std::cout << "Syntax error at '" << anArg << "'\n";
4094 const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart();
4095 Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z());
4098 else if (aCmdName == "vsetlocation")
4100 // compatibility with old syntax
4102 Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec);
4105 std::cout << "Syntax error at '" << anArg << "'\n";
4108 anArgIter = anArgIter + aNbParsed - 1;
4111 aTrsf.SetTranslationPart (aLocVec);
4112 aContext->SetLocation (anObj, aTrsf);
4113 toPrintInfo = Standard_False;
4117 std::cout << "Error: unknown argument '" << anArg << "'\n";
4124 std::cout << "Syntax error - wrong number of arguments\n";
4127 else if (!toPrintInfo)
4132 const gp_Trsf aTrsf = anObj->LocalTransformation();
4133 const gp_XYZ aLoc = aTrsf.TranslationPart();
4134 const gp_Quaternion aRot = aTrsf.GetRotation();
4136 Sprintf (aText, "Location: %g %g %g\n"
4137 "Rotation: %g %g %g %g\n"
4139 aLoc.X(), aLoc.Y(), aLoc.Z(),
4140 aRot.X(), aRot.Y(), aRot.Z(), aRot.W(),
4141 aTrsf.ScaleFactor());
4146 //===============================================================================================
4147 //function : VConnect
4148 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4149 //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
4150 //===============================================================================================
4152 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
4153 Standard_Integer argc,
4157 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4158 if (aContext.IsNull())
4160 std::cout << "vconnect error : call vinit before\n";
4161 return 1; // TCL_ERROR
4166 std::cout << "vconnect error: expect at least 5 arguments\n";
4167 return 1; // TCL_ERROR
4171 Standard_Integer anArgIter = 1;
4172 TCollection_AsciiString aName (argv[anArgIter++]);
4173 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
4174 TCollection_AsciiString aColorString (argv[argc-1]);
4175 Standard_CString aColorName = "";
4176 Standard_Boolean hasColor = Standard_False;
4177 if (aColorString.Search ("color=") != -1)
4179 hasColor = Standard_True;
4180 aColorString.Remove (1, 6);
4181 aColorName = aColorString.ToCString();
4183 Handle(AIS_InteractiveObject) anObject;
4185 // AIS_MultipleConnectedInteractive
4186 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
4187 for (Standard_Integer i = 5; i < aNbShapes; ++i)
4189 TCollection_AsciiString anOriginObjectName (argv[i]);
4190 if (aName.IsEqual (anOriginObjectName))
4192 std::cout << "vconnect error: equal names for connected objects\n";
4195 if (GetMapOfAIS().Find2 (anOriginObjectName, anObject))
4197 if (anObject.IsNull())
4199 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4205 Standard_CString aOriginName = anOriginObjectName.ToCString();
4206 TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4207 if (aTDShape.IsNull())
4209 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4212 anObject = new AIS_Shape (aTDShape);
4213 aContext->Load (anObject);
4214 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
4217 if (anOriginObject.IsNull())
4219 anOriginObject = new AIS_MultipleConnectedInteractive();
4222 anOriginObject->Connect (anObject);
4224 if (anOriginObject.IsNull())
4226 std::cout << "vconect error : can't connect input objects\n";
4227 return 1; // TCL_ERROR
4230 // Get location data
4231 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4232 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4233 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4235 // Create transformation
4236 gp_Vec aTranslation (aXo, aYo, aZo);
4239 aTrsf.SetTranslationPart (aTranslation);
4240 TopLoc_Location aLocation (aTrsf);
4242 anOriginObject->SetLocalTransformation (aTrsf);
4244 // Check if there is another object with given name
4245 // and remove it from context
4246 Handle(AIS_InteractiveObject) anObj;
4247 if (GetMapOfAIS().Find2 (aName, anObj))
4249 TheAISContext()->Remove(anObj, Standard_False);
4250 GetMapOfAIS().UnBind2(aName);
4253 // Bind connected object to its name
4254 GetMapOfAIS().Bind (anOriginObject, aName);
4256 // Display connected object
4257 TheAISContext()->Display (anOriginObject, Standard_True);
4262 //===============================================================================================
4263 //function : VConnectTo
4264 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4265 //Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
4266 //===============================================================================================
4268 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
4269 Standard_Integer argc,
4273 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4274 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4275 if (aContext.IsNull())
4277 std::cout << "vconnect error : call vinit before\n";
4278 return 1; // TCL_ERROR
4281 if (argc != 6 && argc != 7)
4283 std::cout << "vconnect error: expect at least 5 arguments\n";
4284 return 1; // TCL_ERROR
4288 Standard_Integer anArgIter = 1;
4289 TCollection_AsciiString aName (argv[anArgIter++]);
4290 Handle(AIS_InteractiveObject) anOriginObject;
4292 TCollection_AsciiString anOriginObjectName(argv[5]);
4293 if (aName.IsEqual (anOriginObjectName))
4295 std::cout << "vconnect error: equal names for connected objects\n";
4296 return 1; // TCL_ERROR
4298 if (GetMapOfAIS().Find2 (anOriginObjectName, anOriginObject))
4300 if (anOriginObject.IsNull())
4302 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4303 return 1; // TCL_ERROR
4308 Standard_CString aOriginName = anOriginObjectName.ToCString();
4309 TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4310 if (aTDShape.IsNull())
4312 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4313 return 1; // TCL_ERROR
4315 anOriginObject = new AIS_Shape (aTDShape);
4316 GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
4319 // Get location data
4320 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4321 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4322 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4324 // Create transformation
4325 gp_Vec aTranslation (aXo, aYo, aZo);
4328 aTrsf.SetTranslationPart (aTranslation);
4330 Handle(AIS_ConnectedInteractive) aConnected;
4332 aConnected = new AIS_ConnectedInteractive();
4334 aConnected->Connect (anOriginObject, aTrsf);
4336 // Check if there is another object with given name
4337 // and remove it from context
4338 Handle(AIS_InteractiveObject) anObj;
4339 if (GetMapOfAIS().Find2 (aName, anObj))
4341 TheAISContext()->Remove (anObj, Standard_False);
4342 GetMapOfAIS().UnBind2(aName);
4345 // Bind connected object to its name
4346 GetMapOfAIS().Bind (aConnected, aName);
4350 TCollection_AsciiString anArg = argv[6];
4352 if (anArg == "-nodisplay")
4355 if (!anUpdateTool.parseRedrawMode (anArg))
4357 std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
4361 // Display connected object
4362 TheAISContext()->Display (aConnected, Standard_False);
4367 //=======================================================================
4368 //function : VDisconnect
4370 //=======================================================================
4371 static Standard_Integer VDisconnect (Draw_Interpretor& di,
4372 Standard_Integer argc,
4375 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4376 if (aContext.IsNull())
4378 std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4384 std::cout << "ERROR : Usage : " << argv[0] << " name object\n";
4388 TCollection_AsciiString aName (argv[1]);
4389 TCollection_AsciiString anObject (argv[2]);
4390 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
4393 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4394 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4395 if (!aMap.IsBound2 (aName) )
4397 std::cout << "Use 'vdisplay' before\n";
4401 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4402 if (anAssembly.IsNull())
4404 di << "Not an assembly\n";
4408 Handle(AIS_InteractiveObject) anIObj;
4409 if (!aMap.Find2 (anObject, anIObj))
4411 // try to interpret second argument as child number
4412 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
4414 Standard_Integer aCounter = 1;
4415 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4417 if (aCounter == anObjectNumber)
4419 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4427 std::cout << "Use 'vdisplay' before\n";
4432 aContext->Disconnect (anAssembly, anIObj);
4433 aContext->UpdateCurrentViewer();
4437 //=======================================================================
4438 //function : VAddConnected
4440 //=======================================================================
4441 static Standard_Integer VAddConnected (Draw_Interpretor& di,
4442 Standard_Integer argc,
4445 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4446 if (aContext.IsNull())
4448 std::cout << argv[0] << "error : use 'vinit' command before \n";
4454 std::cout << argv[0] << " error: expect 5 arguments\n";
4458 TCollection_AsciiString aName (argv[1]);
4459 TCollection_AsciiString anObject (argv[5]);
4460 Standard_Real aX = Draw::Atof (argv[2]);
4461 Standard_Real aY = Draw::Atof (argv[3]);
4462 Standard_Real aZ = Draw::Atof (argv[4]);
4465 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4466 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4467 if (!aMap.IsBound2 (aName) )
4469 std::cout << "Use 'vdisplay' before\n";
4473 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4474 if (anAssembly.IsNull())
4476 di << "Not an assembly\n";
4480 Handle(AIS_InteractiveObject) anIObj;
4481 if (!aMap.Find2 (anObject, anIObj))
4483 std::cout << "Use 'vdisplay' before\n";
4488 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4490 anAssembly->Connect (anIObj, aTrsf);
4491 TheAISContext()->Display (anAssembly, Standard_False);
4492 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4493 aContext->UpdateCurrentViewer();
4498 //=======================================================================
4499 //function : VListConnected
4501 //=======================================================================
4502 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4503 Standard_Integer argc,
4506 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4507 if (aContext.IsNull())
4509 std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4515 std::cout << "ERROR : Usage : " << argv[0] << " name\n";
4519 TCollection_AsciiString aName (argv[1]);
4522 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4523 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4524 if (!aMap.IsBound2 (aName) )
4526 std::cout << "Use 'vdisplay' before\n";
4530 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4531 if (anAssembly.IsNull())
4533 std::cout << "Not an assembly\n";
4537 std::cout << "Children of " << aName << ":\n";
4539 Standard_Integer aCounter = 1;
4540 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4542 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4543 if (GetMapOfAIS().IsBound1 (anObj))
4545 TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anObj);
4546 std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4549 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4551 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4552 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4554 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4556 std::cout << std::endl;
4564 //===============================================================================================
4565 //function : VSetSelectionMode
4566 //purpose : vselmode
4567 //===============================================================================================
4568 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4569 Standard_Integer theNbArgs,
4570 const char** theArgv)
4573 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4574 if (anAISContext.IsNull())
4576 std::cout << "Error: no active Viewer\n";
4580 NCollection_Sequence<TCollection_AsciiString> anObjNames;
4581 Standard_Integer aSelectionMode = -1;
4582 Standard_Boolean toTurnOn = Standard_True;
4583 AIS_SelectionModesConcurrency aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4584 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
4586 TCollection_AsciiString anArgCase (theArgv[anArgIter]);
4587 anArgCase.LowerCase();
4588 if (anArgCase == "-set"
4589 || anArgCase == "-replace"
4590 || anArgCase == "-single"
4591 || anArgCase == "-exclusive")
4593 aSelModeConcurrency = AIS_SelectionModesConcurrency_Single;
4595 else if (anArgCase == "-add"
4596 || anArgCase == "-combine"
4597 || anArgCase == "-combination"
4598 || anArgCase == "-multiple")
4600 aSelModeConcurrency = AIS_SelectionModesConcurrency_Multiple;
4602 else if (anArgCase == "-globalorlocal"
4603 || anArgCase == "-localorglobal")
4605 aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal;
4609 anObjNames.Append (theArgv[anArgIter]);
4612 if (anObjNames.Size() < 2
4613 || !ViewerTest::ParseOnOff (anObjNames.Last().ToCString(), toTurnOn))
4615 std::cout << "Syntax error: wrong number of arguments\n";
4618 anObjNames.Remove (anObjNames.Upper());
4620 const TCollection_AsciiString aSelModeString = anObjNames.Last();
4621 anObjNames.Remove (anObjNames.Upper());
4622 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
4623 if (aSelModeString.IsIntegerValue())
4625 aSelectionMode = aSelModeString.IntegerValue();
4627 else if (TopAbs::ShapeTypeFromString (aSelModeString.ToCString(), aShapeType))
4629 aSelectionMode = AIS_Shape::SelectionMode (aShapeType);
4633 std::cout << "Syntax error: unknown selection mode '" << aSelModeString << "'\n";
4638 AIS_ListOfInteractive aTargetIOs;
4639 for (NCollection_Sequence<TCollection_AsciiString>::Iterator anObjIter (anObjNames); anObjIter.More(); anObjIter.Next())
4641 const TCollection_AsciiString& aNameIO = anObjIter.Value();
4642 Handle(AIS_InteractiveObject) anIO;
4643 GetMapOfAIS().Find2 (aNameIO, anIO);
4646 std::cout << "Syntax error: undefined presentable object " << aNameIO << "\n";
4649 aTargetIOs.Append (anIO);
4651 if (aTargetIOs.IsEmpty())
4653 anAISContext->DisplayedObjects (aTargetIOs);
4656 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4658 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4659 anAISContext->SetSelectionModeActive (anIO, aSelectionMode, toTurnOn, aSelModeConcurrency);
4664 //===============================================================================================
4665 //function : VSelectionNext
4667 //===============================================================================================
4668 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4669 Standard_Integer /*theArgsNb*/,
4670 const char** /*theArgVec*/)
4673 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4674 Handle(V3d_View) aView = ViewerTest::CurrentView();
4676 if (anAISContext.IsNull())
4678 std::cerr << "Call vinit before!" << std::endl;
4682 anAISContext->HilightNextDetected (aView);
4686 //===============================================================================================
4687 //function : VSelectionPrevious
4689 //===============================================================================================
4690 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4691 Standard_Integer /*theArgsNb*/,
4692 const char** /*theArgVec*/)
4695 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4696 Handle(V3d_View) aView = ViewerTest::CurrentView();
4698 if (anAISContext.IsNull())
4700 std::cerr << "Call vinit before!" << std::endl;
4704 anAISContext->HilightPreviousDetected (aView);
4708 //===========================================================================
4709 //function : VTriangle
4710 //Draw arg : vtriangle Name PointName PointName PointName
4711 //purpose : creates and displays Triangle
4712 //===========================================================================
4713 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4714 Standard_Integer argc,
4717 const Standard_Boolean isTri = TCollection_AsciiString (argv[0]) == "vtriangle";
4718 Handle(Graphic3d_ArrayOfPrimitives) aPrims;
4721 aPrims = new Graphic3d_ArrayOfTriangles (3);
4725 aPrims = new Graphic3d_ArrayOfSegments (2);
4728 if (argc != (2 + aPrims->VertexNumberAllocated()))
4730 std::cout << "Syntax error: wrong number of arguments\n";
4735 for (Standard_Integer aPntIter = 0; aPntIter < aPrims->VertexNumberAllocated(); ++aPntIter)
4737 const TCollection_AsciiString aName (argv[2 + aPntIter]);
4738 if (Handle(AIS_Point) aPntPrs = Handle(AIS_Point)::DownCast (GetMapOfAIS().IsBound2 (aName) ? GetMapOfAIS().Find2 (aName) : NULL))
4740 aPnts[aPntIter] = aPntPrs->Component()->Pnt();
4744 TopoDS_Shape aShape = DBRep::Get (argv[2 + aPntIter]);
4746 || aShape.ShapeType() != TopAbs_VERTEX)
4748 std::cout << "Syntax error: argument " << aName << " must be a point\n";
4751 aPnts[aPntIter] = BRep_Tool::Pnt (TopoDS::Vertex (aShape));
4754 for (Standard_Integer aPnt2Iter = 0; aPnt2Iter < aPntIter; ++aPnt2Iter)
4756 if (aPnts[aPnt2Iter].IsEqual (aPnts[aPntIter], Precision::Confusion()))
4758 std::cout << "Syntax error: points should not be equal\n";
4763 aPrims->AddVertex (aPnts[aPntIter]);
4766 ViewerTest::Display (argv[1], new MyPArrayObject (aPrims));
4770 //=======================================================================
4771 //function : VObjZLayer
4772 //purpose : Set or get z layer id for presentable object
4773 //=======================================================================
4775 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4776 Standard_Integer argc,
4779 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4780 if (aContext.IsNull())
4782 di << argv[0] << "Call 'vinit' before!\n";
4787 TCollection_AsciiString aOperation;
4789 aOperation = TCollection_AsciiString (argv [1]);
4791 // check for correct arguments
4792 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4793 !(argc == 3 && aOperation.IsEqual ("get")))
4795 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4796 di << " set - set layer id for interactive object, layerid - z layer id\n";
4797 di << " get - get layer id of interactive object\n";
4798 di << " argument layerid should be passed for set operation only\n";
4803 TCollection_AsciiString aName (argv[2]);
4804 Handle(AIS_InteractiveObject) anInterObj;
4805 GetMapOfAIS().Find2 (aName, anInterObj);
4806 if (anInterObj.IsNull())
4808 std::cout << "Syntax error: object '" << aName << "' is not displayed\n";
4812 // process operation
4813 if (aOperation.IsEqual ("set"))
4815 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
4816 aContext->SetZLayer (anInterObj, aLayerId);
4818 else if (aOperation.IsEqual ("get"))
4820 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4826 //=======================================================================
4827 //function : VPolygonOffset
4828 //purpose : Set or get polygon offset parameters
4829 //=======================================================================
4830 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
4831 Standard_Integer argc,
4834 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4835 if (aContext.IsNull())
4837 std::cout << argv[0] << " Call 'vinit' before!\n";
4841 if (argc > 2 && argc != 5)
4843 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4844 "without arguments prints the default values" << std::endl;
4849 Handle(AIS_InteractiveObject) anInterObj;
4852 TCollection_AsciiString aName (argv[1]);
4853 if (!GetMapOfAIS().Find2 (aName, anInterObj)
4854 || anInterObj.IsNull())
4856 std::cout << "Syntax error: object '" << aName << "' is not displayed\n";
4861 Standard_Integer aMode;
4862 Standard_ShortReal aFactor, aUnits;
4865 aMode = Draw::Atoi(argv[2]);
4866 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4867 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
4869 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4870 aContext->UpdateCurrentViewer();
4875 if (anInterObj->HasPolygonOffsets())
4877 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4878 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4879 std::cout << "\tMode: " << aMode << std::endl;
4880 std::cout << "\tFactor: " << aFactor << std::endl;
4881 std::cout << "\tUnits: " << aUnits << std::endl;
4886 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4890 std::cout << "Default polygon offset parameters:" << std::endl;
4891 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4892 std::cout << "\tMode: " << aMode << std::endl;
4893 std::cout << "\tFactor: " << aFactor << std::endl;
4894 std::cout << "\tUnits: " << aUnits << std::endl;
4899 //=======================================================================
4900 //function : VShowFaceBoundaries
4901 //purpose : Set face boundaries drawing on/off for ais object
4902 //=======================================================================
4903 static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
4904 Standard_Integer argc,
4907 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
4908 if (aContext.IsNull ())
4910 std::cout << argv[0] << " Call 'vinit' before!\n";
4914 if ((argc != 3 && argc < 6) || argc > 8)
4916 std::cout << "Usage :\n " << argv[0]
4917 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
4918 << " ObjectName - name of AIS interactive object. \n"
4919 << " if ObjectName = \"\", then set as default\n"
4920 << " settings for all newly displayed objects\n"
4921 << " isOn - flag indicating whether the boundaries\n"
4922 << " should be turned on or off (can be set\n"
4923 << " to 0 (off) or 1 (on)).\n"
4924 << " R, G, B - red, green and blue components of boundary\n"
4925 << " color in range (0 - 255).\n"
4926 << " (default is (0, 0, 0)\n"
4927 << " LineWidth - line width\n"
4928 << " (default is 1)\n"
4929 << " LineStyle - line fill style :\n"
4934 << " (default is solid)";
4938 TCollection_AsciiString aName (argv[1]);
4940 Standard_Real aRed = 0.0;
4941 Standard_Real aGreen = 0.0;
4942 Standard_Real aBlue = 0.0;
4943 Standard_Real aWidth = 1.0;
4944 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4947 Handle(AIS_InteractiveObject) anInterObj;
4949 // if name is empty - apply attributes for default aspect
4950 if (!aName.IsEmpty ())
4952 if (!GetMapOfAIS().Find2 (aName, anInterObj)
4953 || anInterObj.IsNull())
4955 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
4960 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
4961 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
4963 // turn boundaries on/off
4964 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
4965 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
4967 // set boundary line color
4971 aRed = Draw::Atof (argv[3])/255.;
4972 aGreen = Draw::Atof (argv[4])/255.;
4973 aBlue = Draw::Atof (argv[5])/255.;
4979 aWidth = (Standard_Real)Draw::Atof (argv[6]);
4982 // select appropriate line type
4985 if (!ViewerTest::ParseLineType (argv[7], aLineType))
4987 std::cout << "Syntax error: unknown line type '" << argv[7] << "'\n";
4992 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
4994 Handle(Prs3d_LineAspect) aBoundaryAspect =
4995 new Prs3d_LineAspect (aColor, aLineType, aWidth);
4997 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
4999 TheAISContext()->Redisplay (anInterObj, Standard_True);
5004 // This class is used for testing markers.
5006 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
5011 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
5012 const Standard_Integer& thePointsOnSide,
5013 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
5015 myStartPoint = theStartPoint;
5016 myPointsOnSide = thePointsOnSide;
5017 myMarkerAspect = theMarkerAspect;
5020 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_MarkersArrayObject,AIS_InteractiveObject);
5024 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
5025 const Handle(Prs3d_Presentation)& aPresentation,
5026 const Standard_Integer aMode) Standard_OVERRIDE;
5028 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5029 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
5033 gp_XYZ myStartPoint;
5034 Standard_Integer myPointsOnSide;
5035 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
5039 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
5040 const Handle(Prs3d_Presentation)& aPresentation,
5041 const Standard_Integer /*aMode*/)
5043 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
5044 if (myPointsOnSide == 1)
5046 anArray->AddVertex (myStartPoint);
5050 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5052 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5054 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5056 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5057 anArray->SetVertexColor (anArray->VertexNumber(),
5060 k / myPointsOnSide);
5066 aPresentation->Clear();
5067 if (!myMarkerAspect.IsNull())
5069 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
5071 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
5074 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5075 const Standard_Integer /*theMode*/)
5077 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
5079 if (myPointsOnSide == 1)
5081 gp_Pnt aPoint (myStartPoint);
5082 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5083 theSelection->Add (aSensetivePoint);
5087 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5089 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5091 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5093 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5094 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5095 theSelection->Add (aSensetivePoint);
5101 //=======================================================================
5102 //function : VMarkersTest
5103 //purpose : Draws an array of markers for testing purposes.
5104 //=======================================================================
5105 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5106 Standard_Integer theArgNb,
5107 const char** theArgVec)
5109 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5110 if (aContext.IsNull())
5112 std::cerr << "Call 'vinit' before!\n";
5118 std::cerr << "Usage :\n " << theArgVec[0]
5119 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5123 Standard_Integer anArgIter = 1;
5125 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5126 TCollection_AsciiString aFileName;
5127 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5128 Atof (theArgVec[anArgIter + 1]),
5129 Atof (theArgVec[anArgIter + 2]));
5132 Standard_Integer aPointsOnSide = 10;
5133 Standard_Integer aMarkerType = -1;
5134 Standard_Real aScale = 1.0;
5135 for (; anArgIter < theArgNb; ++anArgIter)
5137 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5138 if (anArg.Search ("PointsOnSide=") > -1)
5140 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5142 else if (anArg.Search ("MarkerType=") > -1)
5144 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5146 else if (anArg.Search ("Scale=") > -1)
5148 aScale = anArg.Token ("=", 2).RealValue();
5150 else if (anArg.Search ("FileName=") > -1)
5152 aFileName = anArg.Token ("=", 2);
5156 std::cerr << "Wrong argument: " << anArg << "\n";
5161 Handle(Graphic3d_AspectMarker3d) anAspect;
5162 Handle(Image_AlienPixMap) anImage;
5163 Quantity_Color aColor (Quantity_NOC_GREEN1);
5164 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5165 && !aFileName.IsEmpty())
5167 anImage = new Image_AlienPixMap();
5168 if (!anImage->Load (aFileName))
5170 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5173 if (anImage->Format() == Image_Format_Gray)
5175 anImage->SetFormat (Image_Format_Alpha);
5177 else if (anImage->Format() == Image_Format_GrayF)
5179 anImage->SetFormat (Image_Format_AlphaF);
5181 anAspect = new Graphic3d_AspectMarker3d (anImage);
5185 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5188 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5189 VDisplayAISObject (aName, aMarkersArray);
5194 //! Auxiliary function to parse font aspect style argument
5195 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
5196 Font_FontAspect& theAspect)
5198 if (theArg == "regular"
5199 || *theArg.ToCString() == 'r')
5201 theAspect = Font_FA_Regular;
5202 return Standard_True;
5204 else if (theArg == "bolditalic")
5206 theAspect = Font_FA_BoldItalic;
5207 return Standard_True;
5209 else if (theArg == "bold"
5210 || *theArg.ToCString() == 'b')
5212 theAspect = Font_FA_Bold;
5213 return Standard_True;
5215 else if (theArg == "italic"
5216 || *theArg.ToCString() == 'i')
5218 theAspect = Font_FA_Italic;
5219 return Standard_True;
5221 return Standard_False;
5224 //! Auxiliary function
5225 static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect)
5229 case Font_FA_Regular: return "regular";
5230 case Font_FA_BoldItalic: return "bolditalic";
5231 case Font_FA_Bold: return "bold";
5232 case Font_FA_Italic: return "italic";
5233 default: return "undefined";
5237 //=======================================================================
5238 //function : TextToBrep
5239 //purpose : Tool for conversion text to occt-shapes
5240 //=======================================================================
5241 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5242 Standard_Integer theArgNb,
5243 const char** theArgVec)
5248 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5252 Standard_Integer anArgIt = 1;
5253 Standard_CString aName = theArgVec[anArgIt++];
5254 Standard_CString aText = theArgVec[anArgIt++];
5256 Font_BRepFont aFont;
5257 TCollection_AsciiString aFontName ("Courier");
5258 Standard_Real aTextHeight = 16.0;
5259 Font_FontAspect aFontAspect = Font_FA_Regular;
5260 Standard_Boolean anIsCompositeCurve = Standard_False;
5261 gp_Ax3 aPenAx3 (gp::XOY());
5262 gp_Dir aNormal (0.0, 0.0, 1.0);
5263 gp_Dir aDirection (1.0, 0.0, 0.0);
5266 Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT;
5267 Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM;
5269 for (; anArgIt < theArgNb; ++anArgIt)
5271 TCollection_AsciiString aParam (theArgVec[anArgIt]);
5274 if (aParam == "-pos"
5275 || aParam == "-position")
5277 if (anArgIt + 3 >= theArgNb)
5279 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5283 aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt]));
5284 aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt]));
5285 aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt]));
5287 else if (aParam == "-halign")
5289 if (++anArgIt >= theArgNb)
5291 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5295 TCollection_AsciiString aType (theArgVec[anArgIt]);
5297 if (aType == "left")
5299 aHJustification = Graphic3d_HTA_LEFT;
5301 else if (aType == "center")
5303 aHJustification = Graphic3d_HTA_CENTER;
5305 else if (aType == "right")
5307 aHJustification = Graphic3d_HTA_RIGHT;
5311 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5315 else if (aParam == "-valign")
5317 if (++anArgIt >= theArgNb)
5319 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5323 TCollection_AsciiString aType (theArgVec[anArgIt]);
5327 aVJustification = Graphic3d_VTA_TOP;
5329 else if (aType == "center")
5331 aVJustification = Graphic3d_VTA_CENTER;
5333 else if (aType == "bottom")
5335 aVJustification = Graphic3d_VTA_BOTTOM;
5337 else if (aType == "topfirstline")
5339 aVJustification = Graphic3d_VTA_TOPFIRSTLINE;
5343 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5347 else if (aParam == "-height")
5349 if (++anArgIt >= theArgNb)
5351 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5355 aTextHeight = Draw::Atof(theArgVec[anArgIt]);
5357 else if (aParam == "-aspect")
5359 if (++anArgIt >= theArgNb)
5361 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5365 TCollection_AsciiString anOption (theArgVec[anArgIt]);
5366 anOption.LowerCase();
5368 if (anOption.IsEqual ("regular"))
5370 aFontAspect = Font_FA_Regular;
5372 else if (anOption.IsEqual ("bold"))
5374 aFontAspect = Font_FA_Bold;
5376 else if (anOption.IsEqual ("italic"))
5378 aFontAspect = Font_FA_Italic;
5380 else if (anOption.IsEqual ("bolditalic"))
5382 aFontAspect = Font_FA_BoldItalic;
5386 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5390 else if (aParam == "-font")
5392 if (++anArgIt >= theArgNb)
5394 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5398 aFontName = theArgVec[anArgIt];
5400 else if (aParam == "-composite")
5402 if (++anArgIt >= theArgNb)
5404 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5408 ViewerTest::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve);
5410 else if (aParam == "-plane")
5412 if (anArgIt + 6 >= theArgNb)
5414 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5418 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
5419 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
5420 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
5421 aNormal.SetCoord (aX, aY, aZ);
5423 aX = Draw::Atof (theArgVec[++anArgIt]);
5424 aY = Draw::Atof (theArgVec[++anArgIt]);
5425 aZ = Draw::Atof (theArgVec[++anArgIt]);
5426 aDirection.SetCoord (aX, aY, aZ);
5430 std::cerr << "Warning! Unknown argument '" << aParam << "'\n";
5434 aFont.SetCompositeCurveMode (anIsCompositeCurve);
5435 if (!aFont.Init (aFontName.ToCString(), aFontAspect, aTextHeight))
5437 std::cerr << "Font initialization error\n";
5441 aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection);
5443 Font_BRepTextBuilder aBuilder;
5444 DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification));
5448 //=======================================================================
5450 //purpose : Font management
5451 //=======================================================================
5453 static int VFont (Draw_Interpretor& theDI,
5454 Standard_Integer theArgNb,
5455 const char** theArgVec)
5457 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5460 // just print the list of available fonts
5461 Standard_Boolean isFirst = Standard_True;
5462 for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts());
5463 anIter.More(); anIter.Next())
5465 const Handle(Font_SystemFont)& aFont = anIter.Value();
5471 theDI << aFont->FontName()->String()
5472 << " " << fontStyleString (aFont->FontAspect())
5473 << " " << aFont->FontPath()->String();
5474 isFirst = Standard_False;
5479 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5481 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5482 TCollection_AsciiString anArgCase (anArg);
5483 anArgCase.LowerCase();
5484 if (anArgCase == "find")
5486 if (++anArgIter >= theArgNb)
5488 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5492 Standard_CString aFontName = theArgVec[anArgIter];
5493 Font_FontAspect aFontAspect = Font_FA_Undefined;
5494 if (++anArgIter < theArgNb)
5496 anArgCase = theArgVec[anArgIter];
5497 anArgCase.LowerCase();
5498 if (!parseFontStyle (anArgCase, aFontAspect))
5503 Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1);
5506 std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5510 theDI << aFont->FontName()->String()
5511 << " " << fontStyleString (aFont->FontAspect())
5512 << " " << aFont->FontPath()->String();
5514 else if (anArgCase == "add"
5515 || anArgCase == "register")
5517 if (++anArgIter >= theArgNb)
5519 std::cerr << "Error: wrong syntax at argument '" << anArg << "'!\n";
5523 Standard_CString aFontPath = theArgVec[anArgIter++];
5524 TCollection_AsciiString aFontName;
5525 Font_FontAspect aFontAspect = Font_FA_Undefined;
5526 Standard_Integer isSingelStroke = -1;
5527 for (; anArgIter < theArgNb; ++anArgIter)
5529 anArgCase = theArgVec[anArgIter];
5530 anArgCase.LowerCase();
5531 if (aFontAspect == Font_FA_Undefined
5532 && parseFontStyle (anArgCase, aFontAspect))
5536 else if (anArgCase == "singlestroke"
5537 || anArgCase == "singleline"
5538 || anArgCase == "oneline")
5542 else if (aFontName.IsEmpty())
5544 aFontName = theArgVec[anArgIter];
5553 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5556 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5560 if (aFontAspect != Font_FA_Undefined
5561 || !aFontName.IsEmpty())
5563 if (aFontAspect == Font_FA_Undefined)
5565 aFontAspect = aFont->FontAspect();
5567 Handle(TCollection_HAsciiString) aName = aFont->FontName();
5568 if (!aFontName.IsEmpty())
5570 aName = new TCollection_HAsciiString (aFontName);
5572 aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath));
5574 if (isSingelStroke != -1)
5576 aFont->SetSingleStrokeFont (isSingelStroke == 1);
5579 aMgr->RegisterFont (aFont, Standard_True);
5580 theDI << aFont->FontName()->String()
5581 << " " << fontStyleString (aFont->FontAspect())
5582 << " " << aFont->FontPath()->String();
5586 std::cerr << "Warning! Unknown argument '" << anArg << "'\n";
5593 //=======================================================================
5594 //function : VSetEdgeType
5595 //purpose : Edges type management
5596 //=======================================================================
5598 static int VSetEdgeType (Draw_Interpretor& theDI,
5599 Standard_Integer theArgNum,
5600 const char** theArgs)
5602 if (theArgNum < 4 || theArgNum > 9)
5604 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5605 << theArgs[0] << "' for more information.\n";
5609 Standard_Boolean isForceRedisplay = Standard_False;
5612 TCollection_AsciiString aName(theArgs[1]);
5613 Handle(AIS_InteractiveObject) anObject;
5614 if (!GetMapOfAIS().Find2 (aName, anObject))
5616 theDI << theArgs[0] << " error: wrong object name.\n";
5620 // Enable triangle edge mode
5621 if (!anObject->Attributes()->HasOwnShadingAspect())
5623 anObject->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
5624 *anObject->Attributes()->ShadingAspect()->Aspect() = *anObject->Attributes()->Link()->ShadingAspect()->Aspect();
5626 const Handle(Prs3d_ShadingAspect)& aFillAreaAspect = anObject->Attributes()->ShadingAspect();
5627 aFillAreaAspect->Aspect()->SetEdgeOn();
5630 for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
5632 TCollection_AsciiString aParam ((theArgs[anIt]));
5633 if (aParam.Value (1) == '-' && !aParam.IsRealValue())
5635 if (aParam.IsEqual ("-type"))
5637 if (theArgNum <= anIt + 1)
5639 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5640 << aParam.ToCString() << "'.\n";
5645 Aspect_TypeOfLine aTypeEnum = Aspect_TOL_SOLID;
5646 if (!ViewerTest::ParseLineType (theArgs[anIt], aTypeEnum))
5648 std::cout << "Syntax error: wrong line type: '" << theArgs[anIt] << "'.\n";
5651 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType (aTypeEnum);
5653 else if (aParam.IsEqual ("-color"))
5655 if (theArgNum <= anIt + 3)
5657 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5658 << aParam.ToCString() << "'.\n";
5662 Standard_Real aR = Draw::Atof(theArgs[++anIt]);
5663 Standard_Real aG = Draw::Atof(theArgs[++anIt]);
5664 Standard_Real aB = Draw::Atof(theArgs[++anIt]);
5665 Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR,
5666 aG > 1 ? aG / 255.0 : aG,
5667 aB > 1 ? aB / 255.0 : aB,
5670 aFillAreaAspect->Aspect()->SetEdgeColor (aColor);
5672 else if (aParam.IsEqual ("-force"))
5674 isForceRedisplay = Standard_True;
5678 theDI << theArgs[0] << " error: unknown parameter '"
5679 << aParam.ToCString() << "'.\n";
5685 // Update shape presentation as aspect parameters were changed
5686 if (isForceRedisplay)
5688 ViewerTest::GetAISContext()->Redisplay (anObject, Standard_False);
5692 anObject->SetAspect (aFillAreaAspect);
5696 ViewerTest::CurrentView()->Redraw();
5701 //=======================================================================
5702 //function : VUnsetEdgeType
5703 //purpose : Unsets edges visibility in shading mode
5704 //=======================================================================
5706 static int VUnsetEdgeType (Draw_Interpretor& theDI,
5707 Standard_Integer theArgNum,
5708 const char** theArgs)
5710 if (theArgNum != 2 && theArgNum != 3)
5712 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5713 << theArgs[0] << "' for more information.\n";
5717 Standard_Boolean isForceRedisplay = Standard_False;
5720 TCollection_AsciiString aName (theArgs[1]);
5721 Handle(AIS_InteractiveObject) anObject;
5722 if (!GetMapOfAIS().Find2 (aName, anObject))
5724 theDI << theArgs[0] << " error: wrong object name.\n";
5728 // Enable trianle edge mode
5729 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff();
5734 TCollection_AsciiString aParam ((theArgs[2]));
5735 if (aParam.IsEqual ("-force"))
5737 isForceRedisplay = Standard_True;
5741 theDI << theArgs[0] << " error: unknown parameter '"
5742 << aParam.ToCString() << "'.\n";
5747 // Update shape presentation as aspect parameters were changed
5748 if (isForceRedisplay)
5750 ViewerTest::GetAISContext()->Redisplay (anObject, Standard_False);
5754 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5758 ViewerTest::CurrentView()->Redraw();
5764 //=======================================================================
5765 //function : VVertexMode
5766 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
5767 //=======================================================================
5769 static int VVertexMode (Draw_Interpretor& theDI,
5770 Standard_Integer theArgNum,
5771 const char** theArgs)
5773 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5774 if (aContext.IsNull())
5776 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5780 // No arguments --> print the current default vertex draw mode
5783 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5784 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5788 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5789 TCollection_AsciiString aParam (theArgs[1]);
5790 if (aParam == "-set")
5794 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5795 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5799 TCollection_AsciiString aModeStr (theArgs[2]);
5800 Prs3d_VertexDrawMode aNewMode =
5801 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5802 (aModeStr == "all" ? Prs3d_VDM_All :
5803 Prs3d_VDM_Inherited);
5805 Standard_Boolean aRedrawNeeded = Standard_False;
5806 AIS_ListOfInteractive anObjs;
5808 // No object(s) specified -> use all displayed
5811 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5812 aContext->DisplayedObjects (anObjs);
5813 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5814 aRedrawNeeded = Standard_True;
5817 Handle(AIS_InteractiveObject) anObject;
5818 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5820 TCollection_AsciiString aName (theArgs[aCount]);
5821 if (!GetMapOfAIS().Find2 (aName, anObject))
5823 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5826 anObjs.Append (anObject);
5829 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5831 anObject = anIt.Value();
5832 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5833 aContext->Redisplay (anObject, Standard_False);
5834 aRedrawNeeded = Standard_True;
5838 ViewerTest::CurrentView()->Redraw();
5843 Handle(AIS_InteractiveObject) anObject;
5845 || !GetMapOfAIS().Find2 (aParam, anObject))
5847 std::cout << "Error: invalid number of arguments" << std::endl;
5851 // One argument (object name) --> print the current vertex draw mode for the object
5852 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5853 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5857 //=======================================================================
5858 //function : VPointCloud
5859 //purpose : Create interactive object for arbitary set of points.
5860 //=======================================================================
5861 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5862 Standard_Integer theArgNum,
5863 const char** theArgs)
5865 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5866 if (anAISContext.IsNull())
5868 std::cerr << "Error: no active view!\n";
5872 // command to execute
5875 CloudForShape, // generate point cloud for shape
5876 CloudSphere, // generate point cloud for generic sphere
5880 // count number of non-optional command arguments
5881 Command aCmd = Unknow;
5882 Standard_Integer aCmdArgs = 0;
5883 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5885 Standard_CString anArg = theArgs[anArgIter];
5886 TCollection_AsciiString aFlag (anArg);
5888 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5895 case 2 : aCmd = CloudForShape; break;
5896 case 7 : aCmd = CloudSphere; break;
5898 std::cout << "Error: wrong number of arguments! See usage:\n";
5899 theDI.PrintHelp (theArgs[0]);
5904 Standard_Boolean toRandColors = Standard_False;
5905 Standard_Boolean hasNormals = Standard_True;
5906 Standard_Boolean isSetArgNorm = Standard_False;
5907 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5909 Standard_CString anArg = theArgs[anArgIter];
5910 TCollection_AsciiString aFlag (anArg);
5912 if (aFlag == "-randcolors"
5913 || aFlag == "-randcolor")
5915 if (isSetArgNorm && hasNormals)
5917 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5920 toRandColors = Standard_True;
5921 hasNormals = Standard_False;
5923 else if (aFlag == "-normals"
5924 || aFlag == "-normal")
5928 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5931 isSetArgNorm = Standard_True;
5932 hasNormals = Standard_True;
5934 else if (aFlag == "-nonormals"
5935 || aFlag == "-nonormal")
5937 isSetArgNorm = Standard_True;
5938 hasNormals = Standard_False;
5942 Standard_CString aName = theArgs[1];
5944 // generate arbitrary set of points
5945 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
5946 if (aCmd == CloudForShape)
5948 Standard_CString aShapeName = theArgs[2];
5949 TopoDS_Shape aShape = DBRep::Get (aShapeName);
5951 if (aShape.IsNull())
5953 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
5957 // calculate number of points
5958 TopLoc_Location aLocation;
5959 Standard_Integer aNbPoints = 0;
5960 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5962 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5963 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5964 if (!aTriangulation.IsNull())
5966 aNbPoints += aTriangulation->NbNodes();
5971 std::cout << "Error: shape should be triangulated!\n";
5975 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5976 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5978 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5979 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5980 if (aTriangulation.IsNull())
5985 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
5986 const gp_Trsf& aTrsf = aLocation.Transformation();
5988 // extract normals from nodes
5989 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
5992 Poly_Connect aPolyConnect (aTriangulation);
5993 StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
5996 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
5998 gp_Pnt aPoint = aNodes (aNodeIter);
5999 if (!aLocation.IsIdentity())
6001 aPoint.Transform (aTrsf);
6004 aNormals (aNodeIter).Transform (aTrsf);
6008 // add vertex into array of points
6009 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
6012 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
6013 1.0, 0.5, Quantity_TOC_HLS);
6014 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
6019 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
6024 else if (aCmd == CloudSphere)
6026 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
6027 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
6028 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
6029 Standard_Real aRadius = Draw::Atof (theArgs[5]);
6030 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
6032 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
6033 aDistribution.LowerCase();
6034 if ( aDistribution != "surface" && aDistribution != "volume" )
6036 std::cout << "Error: wrong arguments! See usage:\n";
6037 theDI.PrintHelp (theArgs[0]);
6040 Standard_Boolean isSurface = aDistribution == "surface";
6042 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
6044 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
6045 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
6047 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
6048 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
6049 Standard_Real aDistance = isSurface ?
6050 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
6052 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
6054 Cos (anAlpha) * Cos (aBeta));
6055 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
6057 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
6060 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
6061 1.0, 0.5, Quantity_TOC_HLS);
6062 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
6067 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
6072 // set array of points in point cloud object
6073 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
6074 aPointCloud->SetPoints (anArrayPoints);
6075 VDisplayAISObject (aName, aPointCloud);
6079 //=======================================================================
6080 //function : VPriority
6081 //purpose : Prints or sets the display priority for an object
6082 //=======================================================================
6084 static int VPriority (Draw_Interpretor& theDI,
6085 Standard_Integer theArgNum,
6086 const char** theArgs)
6088 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6089 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6090 if (aContext.IsNull())
6092 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
6096 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
6097 Standard_Integer aPriority = -1;
6098 Standard_Integer aNbArgs = theArgNum;
6099 if (aLastArg.IsIntegerValue())
6101 aPriority = aLastArg.IntegerValue();
6103 if (aPriority < 0 || aPriority > 10)
6105 std::cout << "Error: the specified display priority value '" << aLastArg
6106 << "' is outside the valid range [0..10]" << std::endl;
6112 anUpdateTool.Invalidate();
6117 std::cout << "Error: wrong number of arguments! See usage:\n";
6118 theDI.PrintHelp (theArgs[0]);
6122 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
6124 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
6129 TCollection_AsciiString aName (theArgs[anArgIter]);
6130 Handle(AIS_InteractiveObject) anIObj;
6131 GetMapOfAIS().Find2 (aName, anIObj);
6132 if (anIObj.IsNull())
6134 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
6140 theDI << aContext->DisplayPriority (anIObj) << " ";
6144 aContext->SetDisplayPriority (anIObj, aPriority);
6150 //! Auxiliary class for command vnormals.
6151 class MyShapeWithNormals : public AIS_Shape
6153 DEFINE_STANDARD_RTTI_INLINE(MyShapeWithNormals, AIS_Shape);
6156 Standard_Real NormalLength;
6157 Standard_Integer NbAlongU;
6158 Standard_Integer NbAlongV;
6159 Standard_Boolean ToUseMesh;
6160 Standard_Boolean ToOrient;
6164 //! Main constructor.
6165 MyShapeWithNormals (const TopoDS_Shape& theShape)
6166 : AIS_Shape (theShape),
6170 ToUseMesh (Standard_False),
6171 ToOrient (Standard_False) {}
6175 //! Comnpute presentation.
6176 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
6177 const Handle(Prs3d_Presentation)& thePrs,
6178 const Standard_Integer theMode) Standard_OVERRIDE
6180 AIS_Shape::Compute (thePrsMgr, thePrs, theMode);
6182 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormalMap;
6185 DBRep_DrawableShape::addMeshNormals (aNormalMap, myshape, NormalLength);
6189 DBRep_DrawableShape::addSurfaceNormals (aNormalMap, myshape, NormalLength, NbAlongU, NbAlongV);
6192 Handle(Graphic3d_Group) aPrsGroup = Prs3d_Root::NewGroup (thePrs);
6193 aPrsGroup->SetGroupPrimitivesAspect (myDrawer->ArrowAspect()->Aspect());
6195 const Standard_Real aArrowAngle = myDrawer->ArrowAspect()->Angle();
6196 const Standard_Real aArrowLength = myDrawer->ArrowAspect()->Length();
6197 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormalMap);
6198 aFaceIt.More(); aFaceIt.Next())
6200 const Standard_Boolean toReverse = ToOrient && aFaceIt.Key().Orientation() == TopAbs_REVERSED;
6201 Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (2 * aFaceIt.Value().Size());
6202 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aPntIt (aFaceIt.Value()); aPntIt.More(); aPntIt.Next())
6204 std::pair<gp_Pnt, gp_Pnt> aPair = aPntIt.Value();
6207 const gp_Vec aDir = aPair.first.XYZ() - aPair.second.XYZ();
6208 aPair.second = aPair.first.XYZ() + aDir.XYZ();
6211 aSegments->AddVertex (aPair.first);
6212 aSegments->AddVertex (aPair.second);
6213 Prs3d_Arrow::Draw (aPrsGroup, aPair.second, gp_Vec(aPair.first, aPair.second), aArrowAngle, aArrowLength);
6216 aPrsGroup->AddPrimitiveArray (aSegments);
6222 //=======================================================================
6223 //function : VNormals
6224 //purpose : Displays/Hides normals calculated on shape geometry or retrieved from triangulation
6225 //=======================================================================
6226 static int VNormals (Draw_Interpretor& theDI,
6227 Standard_Integer theArgNum,
6228 const char** theArgs)
6230 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6231 if (aContext.IsNull())
6233 std::cout << "Error: no view available, call 'vinit' before!\n";
6236 else if (theArgNum < 2)
6238 std::cout << "Error: wrong number of arguments! See usage:\n";
6239 theDI.PrintHelp (theArgs[0]);
6243 Standard_Integer anArgIter = 1;
6244 Standard_CString aShapeName = theArgs[anArgIter++];
6245 TopoDS_Shape aShape = DBRep::Get (aShapeName);
6246 Standard_Boolean isOn = Standard_True;
6247 if (aShape.IsNull())
6249 std::cout << "Error: shape with name '" << aShapeName << "' is not found\n";
6253 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6254 Handle(MyShapeWithNormals) aShapePrs;
6255 if (aMap.IsBound2 (aShapeName))
6257 aShapePrs = Handle(MyShapeWithNormals)::DownCast (aMap.Find2 (aShapeName));
6260 Standard_Boolean isUseMesh = Standard_False;
6261 Standard_Real aLength = 10.0;
6262 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
6263 Standard_Boolean isOriented = Standard_False;
6264 for (; anArgIter < theArgNum; ++anArgIter)
6266 TCollection_AsciiString aParam (theArgs[anArgIter]);
6269 && ViewerTest::ParseOnOff (aParam.ToCString(), isOn))
6273 else if (aParam == "-usemesh"
6274 || aParam == "-mesh")
6276 isUseMesh = Standard_True;
6278 else if (aParam == "-length"
6279 || aParam == "-len")
6282 aLength = anArgIter < theArgNum ? Draw::Atof (theArgs[anArgIter]) : 0.0;
6283 if (Abs (aLength) <= gp::Resolution())
6285 std::cout << "Syntax error: length should not be zero\n";
6289 else if (aParam == "-orient"
6290 || aParam == "-oriented")
6292 isOriented = Standard_True;
6293 if (anArgIter + 1 < theArgNum
6294 && ViewerTest::ParseOnOff (theArgs[anArgIter + 1], isOriented))
6299 else if (aParam == "-nbalongu"
6300 || aParam == "-nbu")
6303 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6306 std::cout << "Syntax error: NbAlongU should be >=1\n";
6310 else if (aParam == "-nbalongv"
6311 || aParam == "-nbv")
6314 aNbAlongV = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6317 std::cout << "Syntax error: NbAlongV should be >=1\n";
6321 else if (aParam == "-nbalong"
6322 || aParam == "-nbuv")
6325 aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
6326 aNbAlongV = aNbAlongU;
6329 std::cout << "Syntax error: NbAlong should be >=1\n";
6335 std::cout << "Syntax error: unknwon argument '" << aParam << "'\n";
6342 if (aShapePrs.IsNull())
6344 aShapePrs = new MyShapeWithNormals (aShape);
6346 aShapePrs->ToUseMesh = isUseMesh;
6347 aShapePrs->ToOrient = isOriented;
6348 aShapePrs->NormalLength = aLength;
6349 aShapePrs->NbAlongU = aNbAlongU;
6350 aShapePrs->NbAlongV = aNbAlongV;
6351 VDisplayAISObject (aShapeName, aShapePrs);
6353 else if (!aShapePrs.IsNull())
6355 VDisplayAISObject (aShapeName, new AIS_Shape (aShape));
6361 //=======================================================================
6362 //function : ObjectsCommands
6364 //=======================================================================
6366 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
6368 const char *group ="AISObjects";
6370 theCommands.Add ("vtrihedron",
6371 "vtrihedron : vtrihedron name"
6372 "\n\t\t: [-dispMode {wireframe|shading} ]"
6373 "\n\t\t: [-origin x y z ]"
6374 "\n\t\t: [-zaxis u v w -xaxis u v w ]"
6375 "\n\t\t: [-drawAxes {X|Y|Z|XY|YZ|XZ|XYZ}]"
6376 "\n\t\t: [-hideLabels {on|off}]"
6377 "\n\t\t: [-hideArrows {on|off}]"
6378 "\n\t\t: [-label {XAxis|YAxis|ZAxis} value]"
6379 "\n\t\t: [-attribute {XAxisLength|YAxisLength|ZAxisLength"
6380 "\n\t\t: |TubeRadiusPercent|ConeRadiusPercent"
6381 "\n\t\t: |ConeLengthPercent|OriginRadiusPercent"
6382 "\n\t\t: |ShadingNumberOfFacettes} value]"
6383 "\n\t\t: [-color {Origin|XAxis|YAxis|ZAxis|XOYAxis|YOZAxis"
6384 "\n\t\t: |XOZAxis|Whole} {r g b | colorName}]"
6385 "\n\t\t: [-textColor {r g b | colorName}]"
6386 "\n\t\t: [-arrowColor {r g b | colorName}]"
6387 "\n\t\t: [-priority {Origin|XAxis|YAxis|ZAxis|XArrow"
6388 "\n\t\t: |YArrow|ZArrow|XOYAxis|YOZAxis"
6389 "\n\t\t: |XOZAxis|Whole} value]"
6391 "\n\t\t: Creates a new *AIS_Trihedron* object or changes parameters of "
6392 "\n\t\t: existing trihedron. If no argument is set,"
6393 "\n\t\t: the default trihedron (0XYZ) is created."
6394 "\n\t\t: -dispMode mode of visualization: wf - wireframe,"
6395 "\n\t\t: sh - shading."
6396 "\n\t\t: Default value is wireframe."
6397 "\n\t\t: -origin allows to set trihedron location."
6398 "\n\t\t: -zaxis/-xaxis allows to set trihedron X and Z"
6399 "\n\t\t: directions. The directions should"
6400 "\n\t\t: be orthogonal. Y direction is calculated."
6401 "\n\t\t: -drawAxes allows to set what axes are drawn in the"
6402 "\n\t\t: trihedron, default state is XYZ"
6403 "\n\t\t: -hideLabels allows to show/hide trihedron labels"
6404 "\n\t\t: -hideArrows allows to show/hide trihedron arrows"
6405 "\n\t\t: -labels allows to change default X/Y/Z titles of axes"
6406 "\n\t\t: -attribute sets parameters of trihedron"
6407 "\n\t\t: -color sets color properties of parts of trihedron"
6408 "\n\t\t: -textColor sets color properties of trihedron labels"
6409 "\n\t\t: -arrowColor sets color properties of trihedron arrows"
6410 "\n\t\t: -priority allows to change default selection priority"
6411 "\n\t\t: of trihedron components",
6412 __FILE__,VTrihedron,group);
6414 theCommands.Add("vtri2d",
6416 "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.",
6417 __FILE__,VTrihedron2D ,group);
6419 theCommands.Add("vplanetri",
6421 "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default",
6422 __FILE__,VPlaneTrihedron ,group);
6424 theCommands.Add("vsize",
6425 "vsize : vsize [name(Default=Current)] [size(Default=100)] "
6426 "\n\t\t: Changes the size of a named or selected trihedron."
6427 "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done."
6428 "\n\t\t: If the value is not defined: it is set to 100 by default.",
6429 __FILE__,VSize,group);
6431 theCommands.Add("vaxis",
6432 "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]"
6433 "\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",
6434 __FILE__,VAxisBuilder,group);
6436 theCommands.Add("vaxispara",
6438 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.",
6439 __FILE__,VAxisBuilder,group);
6441 theCommands.Add("vaxisortho",
6443 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.",
6444 __FILE__,VAxisBuilder,group);
6446 theCommands.Add("vpoint",
6447 "vpoint PointName [Xa] [Ya] [Za] "
6448 "\n\t\t: Creates a point from coordinates. If the values are not defined,"
6449 "\n\t\t: a point is created by interactive selection of a vertice or an edge (in the center of the edge).",
6450 __FILE__,VPointBuilder,group);
6452 theCommands.Add("vplane",
6453 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]"
6454 "\n\t\t: Creates a plane from named or interactively selected entities."
6455 "\n\t\t: TypeOfSensitivity:"
6456 "\n\t\t: 0 - Interior"
6457 "\n\t\t: 1 - Boundary",
6458 __FILE__,VPlaneBuilder,group);
6460 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
6461 " vchangeplane <plane_name>"
6462 " [x=center_x y=center_y z=center_z]"
6463 " [dx=dir_x dy=dir_y dz=dir_z]"
6464 " [sx=size_x sy=size_y]"
6466 " - changes parameters of the plane:\n"
6467 " - x y z - center\n"
6468 " - dx dy dz - normal\n"
6469 " - sx sy - plane sizes\n"
6470 " - noupdate - do not update/redisplay the plane in context\n"
6471 " Please enter coordinates in format \"param=value\" in arbitrary order.",
6472 __FILE__, VChangePlane, group);
6474 theCommands.Add("vplanepara",
6475 "vplanepara PlaneName "
6476 "\n\t\t: Creates a plane from interactively selected vertex and face.",
6477 __FILE__,VPlaneBuilder,group);
6479 theCommands.Add("vplaneortho",
6480 "vplaneortho PlaneName "
6481 "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ",
6482 __FILE__,VPlaneBuilder,group);
6484 theCommands.Add("vline",
6485 "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] "
6486 "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ",
6487 __FILE__,VLineBuilder,group);
6489 theCommands.Add("vcircle",
6490 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]"
6491 "\n\t\t: Creates a circle from named or interactively selected entities."
6492 "\n\t\t: Parameter IsFilled is defined as 0 or 1.",
6493 __FILE__,VCircleBuilder,group);
6495 theCommands.Add ("vdrawtext",
6496 "vdrawtext name text"
6497 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6498 "\n\t\t: [-color {R G B|name}=yellow]"
6499 "\n\t\t: [-halign {left|center|right}=left]"
6500 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6501 "\n\t\t: [-angle angle=0]"
6502 "\n\t\t: [-zoom {0|1}=0]"
6503 "\n\t\t: [-height height=16]"
6504 "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
6505 "\n\t\t: [-font font=Times]"
6507 "\n\t\t: [-perspos {X Y Z}=0 0 0], where"
6508 "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window"
6509 "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..."
6510 "\n\t\t Z coordinate defines the gap from border of view window (except center position)."
6511 "\n\t\t: [-disptype {blend|decal|shadow|subtitle|dimension|normal}=normal}"
6512 "\n\t\t: [-subcolor {R G B|name}=white]"
6513 "\n\t\t: [-noupdate]"
6514 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]"
6515 "\n\t\t: [-flipping]"
6516 "\n\t\t: Display text label at specified position.",
6517 __FILE__, VDrawText, group);
6519 theCommands.Add("vdrawsphere",
6520 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
6521 __FILE__,VDrawSphere,group);
6523 theCommands.Add ("vlocation",
6526 "\n\t\t: [-copyFrom otherName]"
6527 "\n\t\t: [-translate X Y [Z]]"
6528 "\n\t\t: [-rotate x y z dx dy dz angle]"
6529 "\n\t\t: [-scale [X Y Z] scale]"
6530 "\n\t\t: [-mirror x y z dx dy dz]"
6531 "\n\t\t: [-setLocation X Y [Z]]"
6532 "\n\t\t: [-setRotation QX QY QZ QW]"
6533 "\n\t\t: [-setScale [X Y Z] scale]"
6534 "\n\t\t: Object local transformation management:"
6535 "\n\t\t: -reset reset transformation to identity"
6536 "\n\t\t: -translate translate object"
6537 "\n\t\t: -rotate applies rotation to local transformation"
6538 "\n\t\t: -scale applies scale to local transformation"
6539 "\n\t\t: -mirror applies mirror to local transformation"
6540 "\n\t\t: -setLocation assign object location"
6541 "\n\t\t: -setRotation assign object rotation (quaternion)"
6542 "\n\t\t: -setScale assign object scale factor",
6543 __FILE__, VSetLocation, group);
6544 theCommands.Add ("vsetlocation",
6545 "alias for vlocation",
6546 __FILE__, VSetLocation, group);
6548 theCommands.Add ("vcomputehlr",
6549 "vcomputehlr shapeInput hlrResult [-algoType {algo|polyAlgo}=polyAlgo]"
6550 "\n\t\t: [eyeX eyeY eyeZ dirX dirY dirZ upX upY upZ]"
6551 "\n\t\t: [-showTangentEdges {on|off}=off] [-nbIsolines N=0] [-showHiddenEdges {on|off}=off]"
6552 "\n\t\t: Arguments:"
6553 "\n\t\t: shapeInput - name of the initial shape"
6554 "\n\t\t: hlrResult - result HLR object from initial shape"
6555 "\n\t\t: eye, dir are eye position and look direction"
6556 "\n\t\t: up is the look up direction vector"
6557 "\n\t\t: -algoType HLR algorithm to use"
6558 "\n\t\t: -showTangentEdges include tangent edges"
6559 "\n\t\t: -nbIsolines include isolines"
6560 "\n\t\t: -showHiddenEdges include hidden edges"
6561 "\n\t\t: Use vtop to see projected HLR shape.",
6562 __FILE__, VComputeHLR, group);
6564 theCommands.Add("vdrawparray",
6565 "vdrawparray name TypeOfArray={points|segments|polylines|triangles"
6566 "\n\t\t: |trianglefans|trianglestrips|quads|quadstrips|polygons}"
6567 "\n\t\t: [-deinterleaved|-mutable]"
6568 "\n\t\t: [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [texel={'t' tx ty}]]"
6569 "\n\t\t: [bound= {'b' nbVertices [bound_color={'c' r g b}]]"
6570 "\n\t\t: [edge= {'e' vertexId]"
6571 "\n\t\t: [-shape shapeName] [-patch]"
6572 "\n\t\t: Commands create an Interactive Object for specified Primitive Array definition (Graphic3d_ArrayOfPrimitives)"
6573 "\n\t\t: with the main purpose is covering various combinations by tests",
6574 __FILE__,VDrawPArray,group);
6576 theCommands.Add("vconnect",
6577 "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]"
6578 "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.",
6579 __FILE__, VConnect, group);
6581 theCommands.Add("vconnectto",
6582 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
6583 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6584 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
6585 __FILE__, VConnectTo,group);
6587 theCommands.Add("vdisconnect",
6588 "vdisconnect assembly_name (object_name | object_number | 'all')"
6589 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6590 __FILE__,VDisconnect,group);
6592 theCommands.Add("vaddconnected",
6593 "vaddconnected assembly_name object_name"
6594 "Adds object to assembly.",
6595 __FILE__,VAddConnected,group);
6597 theCommands.Add("vlistconnected",
6598 "vlistconnected assembly_name"
6599 "Lists objects in assembly.",
6600 __FILE__,VListConnected,group);
6603 theCommands.Add("vselmode",
6604 "vselmode [object] selectionMode {on|off}"
6605 "\n\t\t: [{-add|-set|-globalOrLocal}=-globalOrLocal]"
6606 "\n\t\t: Switches selection mode for the specified object or for all objects in context."
6607 "\n\t\t: Selection mode is either an integer number specific to Interactive Object,"
6608 "\n\t\t: or sub-shape type in case of AIS_Shape:"
6609 "\n\t\t: Shape, Vertex, Edge, Wire, Face, Shell, Solid, CompSolid, Compound"
6610 "\n\t\t: The integer mode 0 (Shape in case of AIS_Shape) is reserved for selecting object as whole."
6611 "\n\t\t: Additional options:"
6612 "\n\t\t: -add already activated selection modes will be left activated"
6613 "\n\t\t: -set already activated selection modes will be deactivated"
6614 "\n\t\t: -globalOrLocal (default) if new mode is Global selection mode,"
6615 "\n\t\t: then active local selection modes will be deactivated"
6616 "\n\t\t: and the samthen active local selection modes will be deactivated",
6617 __FILE__, VSetSelectionMode, group);
6619 theCommands.Add("vselnext",
6620 "vselnext : hilight next detected",
6621 __FILE__, VSelectionNext, group);
6623 theCommands.Add("vselprev",
6624 "vselnext : hilight previous detected",
6625 __FILE__, VSelectionPrevious, group);
6627 theCommands.Add("vtriangle",
6628 "vtriangle Name PointName PointName PointName"
6629 "\n\t\t: Creates and displays a filled triangle from named points.",
6630 __FILE__, VTriangle,group);
6632 theCommands.Add("vsegment",
6633 "vsegment Name PointName PointName"
6634 "\n\t\t: Creates and displays a segment from named points.",
6635 __FILE__, VTriangle,group);
6637 theCommands.Add("vobjzlayer",
6638 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6639 __FILE__, VObjZLayer, group);
6641 theCommands.Add("vpolygonoffset",
6642 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6643 __FILE__, VPolygonOffset, group);
6645 theCommands.Add ("vshowfaceboundary",
6646 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
6647 "- turns on/off drawing of face boundaries for ais object "
6648 "and defines boundary line style.",
6649 __FILE__, VShowFaceBoundary, group);
6651 theCommands.Add ("vmarkerstest",
6652 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6653 __FILE__, VMarkersTest, group);
6655 theCommands.Add ("text2brep",
6656 "text2brep: name text"
6657 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6658 "\n\t\t: [-halign {left|center|right}=left]"
6659 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6660 "\n\t\t: [-height height=16]"
6661 "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
6662 "\n\t\t: [-font font=Courier]"
6663 "\n\t\t: [-composite {on|off}=off]"
6664 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]",
6665 __FILE__, TextToBRep, group);
6666 theCommands.Add ("vfont",
6667 "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined] [singleStroke]]"
6668 "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
6669 __FILE__, VFont, group);
6671 theCommands.Add ("vsetedgetype",
6672 "vsetedgetype usage:\n"
6673 "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] "
6674 "\n\t\t: Sets edges type and color for input shape",
6675 __FILE__, VSetEdgeType, group);
6677 theCommands.Add ("vunsetedgetype",
6678 "vunsetedgetype usage:\n"
6679 "vunsetedgetype ShapeName [-force]"
6680 "\n\t\t: Unsets edges type and color for input shape",
6681 __FILE__, VUnsetEdgeType, group);
6683 theCommands.Add ("vvertexmode",
6684 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6685 "vvertexmode - prints the default vertex draw mode\n"
6686 "vvertexmode name - prints the vertex draw mode of the given object\n"
6687 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6688 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6689 __FILE__, VVertexMode, group);
6691 theCommands.Add ("vpointcloud",
6692 "vpointcloud name shape [-randColor] [-normals] [-noNormals]"
6693 "\n\t\t: Create an interactive object for arbitary set of points"
6694 "\n\t\t: from triangulated shape."
6696 "vpointcloud name x y z r npts {surface|volume}\n"
6697 " ... [-randColor] [-normals] [-noNormals]"
6698 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6699 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6701 "\n\t\t: Additional options:"
6702 "\n\t\t: -randColor - generate random color per point"
6703 "\n\t\t: -normals - generate normal per point (default)"
6704 "\n\t\t: -noNormals - do not generate normal per point"
6706 __FILE__, VPointCloud, group);
6708 theCommands.Add("vpriority",
6709 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",
6713 theCommands.Add ("vnormals",
6715 "vnormals Shape [{on|off}=on] [-length {10}] [-nbAlongU {1}] [-nbAlongV {1}] [-nbAlong {1}]"
6716 "\n\t\t: [-useMesh] [-oriented {0}1}=0]"
6717 "\n\t\t: Displays/Hides normals calculated on shape geometry or retrieved from triangulation",
6718 __FILE__, VNormals, group);