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_AspectMarker3d.hxx>
108 #include <Graphic3d_Group.hxx>
109 #include <Standard_Real.hxx>
111 #include <AIS_Circle.hxx>
112 #include <BRepBuilderAPI_MakeEdge.hxx>
113 #include <BRepBuilderAPI_MakeFace.hxx>
114 #include <BRepBuilderAPI_MakeWire.hxx>
115 #include <Geom_Circle.hxx>
116 #include <GC_MakeCircle.hxx>
117 #include <Select3D_SensitiveCircle.hxx>
118 #include <SelectMgr_EntityOwner.hxx>
119 #include <SelectMgr_Selection.hxx>
120 #include <StdFail_NotDone.hxx>
121 #include <StdPrs_ShadedShape.hxx>
122 #include <TopoDS_Wire.hxx>
124 #include <AIS_MultipleConnectedInteractive.hxx>
125 #include <AIS_ConnectedInteractive.hxx>
126 #include <AIS_TextLabel.hxx>
127 #include <TopLoc_Location.hxx>
128 #include <TColStd_ListOfInteger.hxx>
129 #include <TColStd_ListIteratorOfListOfInteger.hxx>
131 #include <Select3D_SensitiveSegment.hxx>
132 #include <Select3D_SensitivePrimitiveArray.hxx>
133 #include <Select3D_SensitiveTriangle.hxx>
134 #include <Select3D_SensitiveCurve.hxx>
135 #include <Select3D_SensitivePoint.hxx>
136 #include <BRepAdaptor_Curve.hxx>
137 #include <StdPrs_Curve.hxx>
139 #include <BRepExtrema_ExtPC.hxx>
140 #include <BRepExtrema_ExtPF.hxx>
142 #include <Prs3d_Arrow.hxx>
143 #include <Prs3d_ArrowAspect.hxx>
144 #include <Prs3d_DatumAttribute.hxx>
145 #include <Prs3d_DatumAspect.hxx>
146 #include <Prs3d_Drawer.hxx>
147 #include <Prs3d_VertexDrawMode.hxx>
148 #include <Prs3d_LineAspect.hxx>
149 #include <Prs3d_PointAspect.hxx>
150 #include <Prs3d_Presentation.hxx>
151 #include <Prs3d_TextAspect.hxx>
153 #include <Image_AlienPixMap.hxx>
154 #include <TColStd_HArray1OfAsciiString.hxx>
155 #include <TColStd_HSequenceOfAsciiString.hxx>
157 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
158 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
159 const Handle(AIS_InteractiveObject)& theAISObj,
160 Standard_Boolean theReplaceIfExists = Standard_True);
161 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
162 extern Handle(AIS_InteractiveContext)& TheAISContext();
166 static bool convertToColor (const Handle(TColStd_HSequenceOfAsciiString)& theColorValues,
167 Quantity_Color& theColor)
169 const char* anArgs[3] =
171 theColorValues->Size() >= 1 ? theColorValues->Value (1).ToCString() : "",
172 theColorValues->Size() >= 2 ? theColorValues->Value (2).ToCString() : "",
173 theColorValues->Size() >= 3 ? theColorValues->Value (3).ToCString() : ""
175 return ViewerTest::ParseColor (theColorValues->Size(), anArgs, theColor) != 0;
178 static bool convertToDatumPart (const TCollection_AsciiString& theValue,
179 Prs3d_DatumParts& theDatumPart)
181 TCollection_AsciiString aValue = theValue;
183 if (aValue == "origin") theDatumPart = Prs3d_DP_Origin;
184 else if (aValue == "xaxis") theDatumPart = Prs3d_DP_XAxis;
185 else if (aValue == "yaxis") theDatumPart = Prs3d_DP_YAxis;
186 else if (aValue == "zaxis") theDatumPart = Prs3d_DP_ZAxis;
187 else if (aValue == "xarrow") theDatumPart = Prs3d_DP_XArrow;
188 else if (aValue == "yarrow") theDatumPart = Prs3d_DP_YArrow;
189 else if (aValue == "zarrow") theDatumPart = Prs3d_DP_ZArrow;
190 else if (aValue == "xoyaxis") theDatumPart = Prs3d_DP_XOYAxis;
191 else if (aValue == "yozaxis") theDatumPart = Prs3d_DP_YOZAxis;
192 else if (aValue == "xozaxis") theDatumPart = Prs3d_DP_XOZAxis;
193 else if (aValue == "whole") theDatumPart = Prs3d_DP_None;
201 static void convertToDatumParts (const TCollection_AsciiString& theValue,
202 NCollection_List<Prs3d_DatumParts>& theParts)
204 TCollection_AsciiString aValue = theValue;
205 const Standard_Integer aSplitPos = theValue.Search ("|");
206 Prs3d_DatumParts aPart = Prs3d_DP_None;
209 convertToDatumParts (theValue.SubString (aSplitPos + 1, theValue.Length()), theParts);
210 if (aSplitPos == 1) // first symbol
214 aValue = theValue.SubString (1, aSplitPos - 1);
216 if (convertToDatumPart (aValue, aPart))
218 theParts.Append (aPart);
222 static bool convertToDatumAttribute (const TCollection_AsciiString& theValue,
223 Prs3d_DatumAttribute& theAttribute)
225 TCollection_AsciiString aValue = theValue;
227 if (aValue == "xaxislength") theAttribute = Prs3d_DA_XAxisLength;
228 else if (aValue == "yaxislength") theAttribute = Prs3d_DA_YAxisLength;
229 else if (aValue == "zaxislength") theAttribute = Prs3d_DA_ZAxisLength;
230 else if (aValue == "tuberadiuspercent") theAttribute = Prs3d_DP_ShadingTubeRadiusPercent;
231 else if (aValue == "coneradiuspercent") theAttribute = Prs3d_DP_ShadingConeRadiusPercent;
232 else if (aValue == "conelengthpercent") theAttribute = Prs3d_DP_ShadingConeLengthPercent;
233 else if (aValue == "originradiuspercent") theAttribute = Prs3d_DP_ShadingOriginRadiusPercent;
234 else if (aValue == "shadingnumberoffacettes") theAttribute = Prs3d_DP_ShadingNumberOfFacettes;
240 static void convertToDatumAttributes (const TCollection_AsciiString& theValue,
241 NCollection_List<Prs3d_DatumAttribute>& theAttributes)
243 TCollection_AsciiString aValue = theValue;
244 const Standard_Integer aSplitPos = theValue.Search ("|");
245 Prs3d_DatumAttribute anAttribute = Prs3d_DA_XAxisLength;
248 convertToDatumAttributes (theValue.SubString (aSplitPos + 1, theValue.Length()), theAttributes);
249 if (aSplitPos == 1) // first symbol
253 aValue = theValue.SubString (1, aSplitPos - 1);
255 if (convertToDatumAttribute (aValue, anAttribute))
257 theAttributes.Append (anAttribute);
261 static bool convertToDatumAxes (const TCollection_AsciiString& theValue,
262 Prs3d_DatumAxes& theDatumAxes)
264 TCollection_AsciiString aValue = theValue;
266 if (aValue == "x") theDatumAxes = Prs3d_DA_XAxis;
267 else if (aValue == "y") theDatumAxes = Prs3d_DA_YAxis;
268 else if (aValue == "z") theDatumAxes = Prs3d_DA_ZAxis;
269 else if (aValue == "xy") theDatumAxes = Prs3d_DA_XYAxis;
270 else if (aValue == "zy") theDatumAxes = Prs3d_DA_YZAxis;
271 else if (aValue == "xz") theDatumAxes = Prs3d_DA_XZAxis;
272 else if (aValue == "xyz") theDatumAxes = Prs3d_DA_XYZAxis;
280 static Standard_Boolean setTrihedronParams (Standard_Integer theArgsNb,
281 const char** theArgVec,
282 Handle(AIS_Trihedron) theTrihedron)
284 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
285 TCollection_AsciiString aParseKey;
286 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
288 TCollection_AsciiString anArg (theArgVec [anArgIt]);
289 if (anArg.Value (1) == '-'
290 && !anArg.IsRealValue())
293 aParseKey.Remove (1);
294 aParseKey.LowerCase();
295 std::string aKey = aParseKey.ToCString();
296 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString());
300 if (aParseKey.IsEmpty())
305 aMapOfArgs (aParseKey)->Append (anArg);
309 if ((aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis"))
310 || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")))
312 std::cout << "Syntax error: -xaxis and -zaxis parameters are to set together.\n";
313 return Standard_False;
316 Handle(TColStd_HSequenceOfAsciiString) aValues;
317 Handle(Geom_Axis2Placement) aComponent = theTrihedron->Component();
318 if (aMapOfArgs.Find ("origin", aValues))
320 aComponent->SetLocation (gp_Pnt (aValues->Value (1).RealValue(),
321 aValues->Value (2).RealValue(),
322 aValues->Value (3).RealValue()));
324 Handle(TColStd_HSequenceOfAsciiString) aXValues, aZValues;
325 if (aMapOfArgs.Find ("xaxis", aXValues) && aMapOfArgs.Find ("zaxis", aZValues))
327 gp_Dir aXDir (aXValues->Value (1).RealValue(),
328 aXValues->Value (2).RealValue(),
329 aXValues->Value (3).RealValue());
331 gp_Dir aZDir (aZValues->Value (1).RealValue(),
332 aZValues->Value (2).RealValue(),
333 aZValues->Value (3).RealValue());
335 if (!aZDir.IsNormal (aXDir, M_PI / 180.0))
337 std::cout << "Syntax error - parameters 'xaxis' and 'zaxis' are not applied as VectorX is not normal to VectorZ\n";
338 return Standard_False;
341 aComponent->SetXDirection(aXDir);
342 aComponent->SetDirection (aZDir);
345 if (aMapOfArgs.Find ("dispmode", aValues))
347 TCollection_AsciiString aValue (aValues->Value (1));
348 bool isWireframe = true;
349 if (aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
351 theTrihedron->SetDatumDisplayMode (isWireframe ? Prs3d_DM_WireFrame
355 if (aMapOfArgs.Find ("hidelabels", aValues))
357 Standard_Boolean toHideLabels = Standard_True;
358 if (aValues->Size() == 1)
360 ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideLabels);
362 else if (aValues->Size() != 0)
364 std::cout << "Syntax error: -hidelabels expects parameter 'on' or 'off' after.\n";
365 return Standard_False;
368 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
370 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
372 theTrihedron->Attributes()->DatumAspect()->SetDrawLabels (!toHideLabels);
375 if (aMapOfArgs.Find ("hidearrows", aValues))
377 Standard_Boolean toHideArrows = Standard_True;
378 if (aValues->Size() == 1)
380 ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideArrows);
382 else if (aValues->Size() != 0)
384 std::cout << "Syntax error: -hidearrows expects parameter 'on' or 'off' after.\n";
385 return Standard_False;
388 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
390 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
392 theTrihedron->Attributes()->DatumAspect()->SetDrawArrows (!toHideArrows);
395 if (aMapOfArgs.Find ("color", aValues))
397 NCollection_List<Prs3d_DatumParts> aParts;
398 if (aValues->Size() < 2)
400 std::cout << "Syntax error: -color wrong parameters.\n";
401 return Standard_False;
404 convertToDatumParts (aValues->Value(1), aParts);
405 aValues->Remove (1); // datum part is processed
406 Quantity_Color aColor;
407 if (!convertToColor (aValues, aColor))
409 std::cout << "Syntax error: -color wrong parameters.\n";
410 return Standard_False;
413 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (aParts); anIterator.More(); anIterator.Next())
415 Prs3d_DatumParts aDatumPart = anIterator.Value();
416 if (aDatumPart == Prs3d_DP_None)
418 theTrihedron->SetColor (aColor);
422 theTrihedron->SetDatumPartColor (aDatumPart, aColor);
427 if (aMapOfArgs.Find ("textcolor", aValues))
429 Quantity_Color aColor;
430 if (!convertToColor (aValues, aColor))
432 std::cout << "Syntax error: -textcolor wrong parameters.\n";
433 return Standard_False;
435 theTrihedron->SetTextColor (aColor);
438 if (aMapOfArgs.Find ("arrowcolor", aValues))
440 Quantity_Color aColor;
441 if (!convertToColor (aValues, aColor))
443 std::cout << "Syntax error: -arrowcolor wrong parameters.\n";
444 return Standard_False;
446 theTrihedron->SetArrowColor (aColor);
449 if (aMapOfArgs.Find ("attribute", aValues))
451 NCollection_List<Prs3d_DatumAttribute> anAttributes;
452 if (aValues->Size() != 2)
454 std::cout << "Syntax error: -attribute wrong parameters.\n";
455 return Standard_False;
458 convertToDatumAttributes (aValues->Value (1), anAttributes);
459 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
460 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
461 for (NCollection_List<Prs3d_DatumAttribute>::Iterator anIterator (anAttributes); anIterator.More(); anIterator.Next())
463 theTrihedron->Attributes()->DatumAspect()->SetAttribute (anIterator.Value(), aValues->Value (2).RealValue());
467 if (aMapOfArgs.Find ("priority", aValues))
469 Prs3d_DatumParts aDatumPart;
470 if (aValues->Size() < 2
471 || !convertToDatumPart (aValues->Value (1), aDatumPart))
473 std::cout << "Syntax error: -priority wrong parameters.\n";
474 return Standard_False;
476 theTrihedron->SetSelectionPriority (aDatumPart, aValues->Value (2).IntegerValue());
479 if (aMapOfArgs.Find ("labels", aValues))
481 Prs3d_DatumParts aDatumPart = Prs3d_DP_None;
482 if (aValues->Size() > 2
483 && convertToDatumPart(aValues->Value(1), aDatumPart)
484 && aDatumPart >= Prs3d_DP_XAxis
485 && aDatumPart <= Prs3d_DP_ZAxis) // labels are set to axes only
487 theTrihedron->SetLabel (aDatumPart, aValues->Value (2));
491 std::cout << "Syntax error: -labels wrong parameters.\n";
492 return Standard_False;
496 if (aMapOfArgs.Find ("drawaxes", aValues))
498 Prs3d_DatumAxes aDatumAxes = Prs3d_DA_XAxis;
499 if (aValues->Size() < 1
500 || !convertToDatumAxes (aValues->Value (1), aDatumAxes))
502 std::cout << "Syntax error: -drawaxes wrong parameters.\n";
503 return Standard_False;
505 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
506 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
507 theTrihedron->Attributes()->DatumAspect()->SetDrawDatumAxes (aDatumAxes);
509 return Standard_True;
513 //==============================================================================
514 //function : Vtrihedron 2d
515 //purpose : Create a plane with a 2D trihedron from a faceselection
516 //Draw arg : vtri2d name
517 //==============================================================================
518 static int VTrihedron2D (Draw_Interpretor& /*theDI*/,
519 Standard_Integer theArgsNum,
520 const char** theArgVec)
524 std::cerr << theArgVec[0]<< " error.\n";
528 TopTools_ListOfShape aShapes;
529 ViewerTest::GetSelectedShapes (aShapes);
531 if (aShapes.Extent() != 1)
533 std::cerr << "Error: wrong number of selected shapes.\n";
537 const TopoDS_Shape& aShape = aShapes.First();
539 TopoDS_Face aFace = TopoDS::Face (aShape);
540 TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE);
541 TopoDS_Edge anEdge0 = TopoDS::Edge (aFaceExp.Current());
547 TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() );
548 BRepAdaptor_Curve aCurve0 (anEdge0);
549 BRepAdaptor_Curve aCurve1 (anEdge1);
550 A = aCurve1.Value (0.1);
551 B = aCurve1.Value (0.9);
552 C = aCurve0.Value (0.5);
556 BRepAdaptor_Curve aCurve0 (anEdge0);
557 A = aCurve0.Value (0.1);
558 B = aCurve0.Value (0.9);
559 C = aCurve0.Value (0.5);
562 GC_MakePlane aMkPlane (A,B,C);
564 Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value());
565 TCollection_AsciiString aName (theArgVec[1]);
567 VDisplayAISObject (aName, anAISPlaneTri);
572 //=======================================================================
573 //function : VTrihedron
575 //=======================================================================
576 static int VTrihedron (Draw_Interpretor& ,
577 Standard_Integer theArgsNb,
578 const char** theArgVec)
582 std::cout << "Syntax error: the wrong number of input parameters.\n";
586 TCollection_AsciiString aName (theArgVec[1]);
587 gp_Pln aWorkingPlane;
588 Standard_Boolean toUpdate = Standard_True;
590 NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
591 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
593 Handle(AIS_Trihedron) aTrihedron;
594 Handle(AIS_InteractiveObject) anObject;
595 if (GetMapOfAIS().Find2 (aName, anObject))
597 aTrihedron = Handle(AIS_Trihedron)::DownCast (anObject);
598 if (aTrihedron.IsNull())
600 std::cout << "Syntax error: no trihedron with this name.\n";
606 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (gp_Pnt (0.0, 0.0, 0.0),
608 aTrihedron = new AIS_Trihedron (aPlacement);
611 if (!setTrihedronParams (theArgsNb, theArgVec, aTrihedron))
616 // Redisplay a dimension after parameter changing.
617 if (ViewerTest::GetAISContext()->IsDisplayed (aTrihedron))
619 ViewerTest::GetAISContext()->Redisplay (aTrihedron, toUpdate);
623 VDisplayAISObject (theArgVec[1], aTrihedron);
629 //==============================================================================
632 //purpose : Change the size of a named or selected trihedron
633 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
634 // if no value, the value is set at 100 by default
635 //Draw arg : vsize [name] [size]
636 //==============================================================================
638 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
641 // Declaration de booleens
642 Standard_Boolean ThereIsName;
643 Standard_Boolean ThereIsCurrent;
645 Standard_Boolean hascol;
647 Quantity_Color col = Quantity_NOC_BLACK;
649 // Verification des arguments
650 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;}
652 // Verification du nombre d'arguments
653 if (argc==1) {ThereIsName=Standard_False;value=100;}
654 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
655 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
657 // On set le booleen ThereIsCurrent
658 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
659 else {ThereIsCurrent=Standard_False;}
663 //===============================================================
664 // Il n'y a pas de nom mais des objets selectionnes
665 //===============================================================
666 if (!ThereIsName && ThereIsCurrent)
669 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
672 while ( it.More() ) {
674 Handle(AIS_InteractiveObject) aShape = it.Key1();
676 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
679 // On verifie que l'AIS InteraciveObject selectionne est bien
681 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
683 if (aShape->HasColor())
685 hascol = Standard_True;
687 // On recupere la couleur de aShape
692 hascol = Standard_False;
695 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
696 // pour lui appliquer la methode SetSize()
697 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
699 // C'est bien un triedre,on chage sa valeur!
700 aTrihedron->SetSize(value);
702 // On donne la couleur au Trihedron
703 if(hascol) aTrihedron->SetColor(col);
704 else aTrihedron->UnsetColor();
707 // The trihedron hasn't be errased from the map
708 // so you just have to redisplay it
709 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
718 TheAISContext() ->UpdateCurrentViewer();
721 //===============================================================
722 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
723 //===============================================================
727 //===============================================================
728 // Il y a un nom de triedre passe en argument
729 //===============================================================
731 TCollection_AsciiString name=argv[1];
733 // on verifie que ce nom correspond bien a une shape
734 Handle(AIS_InteractiveObject) aShape;
735 if (GetMapOfAIS().Find2(name, aShape))
737 // On verifie que l'AIS InteraciveObject est bien
739 if (!aShape.IsNull() &&
740 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
742 if (aShape->HasColor())
744 hascol=Standard_True;
746 // On recupere la couleur de aShape
751 hascol = Standard_False;
754 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
755 // pour lui appliquer la methode SetSize()
756 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
758 // C'est bien un triedre,on chage sa valeur
759 aTrihedron->SetSize(value);
761 // On donne la couleur au Trihedron
762 if(hascol) aTrihedron->SetColor(col);
763 else aTrihedron->UnsetColor();
765 // The trihedron hasn't be errased from the map
766 // so you just have to redisplay it
767 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
769 TheAISContext() ->UpdateCurrentViewer();
777 //==============================================================================
779 //==============================================================================
780 //function : VPlaneTrihedron
781 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
782 //Draw arg : vplanetri name
783 //==============================================================================
784 #include <AIS_Plane.hxx>
788 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
791 // Verification des arguments
792 if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
794 if (TheAISContext()->NbSelected() != 1)
796 std::cerr << "Error: Wrong number of selected shapes.\n";
800 TheAISContext()->InitSelected();
801 Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive();
802 Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest);
805 std::cerr << "Error: Selected shape is not a plane.\n";
809 VDisplayAISObject (argv[1], aPlane);
816 //==============================================================================
817 // Fonction First click 2de click
819 // vaxis vertex vertex
821 // vaxispara edge vertex
822 // vaxisortho edge Vertex
823 // vaxisinter Face Face
824 //==============================================================================
826 //==============================================================================
827 //function : VAxisBuilder
829 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
830 //==============================================================================
831 #include <TopoDS_Edge.hxx>
832 #include <TopoDS_Vertex.hxx>
833 #include <TopExp.hxx>
834 #include <Geom_Line.hxx>
836 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
839 Standard_Boolean HasArg;
840 TCollection_AsciiString name;
843 if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
844 if (argc==8) HasArg=Standard_True;
845 else HasArg=Standard_False;
849 TopTools_ListOfShape aShapes;
850 ViewerTest::GetSelectedShapes (aShapes);
852 // Cas ou il y a des arguments
853 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
855 Standard_Real coord[6];
856 for(Standard_Integer i=0;i<=5;i++){
857 coord[i]=Draw::Atof(argv[2+i]);
859 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
861 gp_Vec myVect (p1,p2);
862 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
863 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
864 GetMapOfAIS().Bind (TheAxis,name);
865 TheAISContext()->Display(TheAxis, Standard_True);
871 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
872 if ( !strcasecmp(argv[0], "vaxis")) {
873 if (aShapes.Extent() != 2 && aShapes.Extent() != 1)
875 std::cerr << "Error: Wrong number of selected shapes.\n";
879 const TopoDS_Shape& aShapeA = aShapes.First();
880 if (aShapeA.ShapeType() == TopAbs_VERTEX)
882 if (aShapes.Extent() != 2)
884 std::cerr << "Error: Wron number of selected shapes.\n";
888 const TopoDS_Shape& aShapeB = aShapes.Last();
889 if (aShapeB.ShapeType() != TopAbs_VERTEX)
891 std::cerr << "Syntax error: You should select two vertices or one edge.\n";
895 // Construction de l'axe
896 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
897 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
900 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
901 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
902 GetMapOfAIS().Bind (TheAxis,name);
903 TheAISContext()->Display (TheAxis, Standard_True);
907 TopoDS_Edge ed =TopoDS::Edge (aShapeA);
909 TopExp::Vertices(ed,Va,Vb );
910 gp_Pnt A=BRep_Tool::Pnt(Va);
911 gp_Pnt B=BRep_Tool::Pnt(Vb);
914 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
915 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
916 GetMapOfAIS().Bind (TheAxis,name);
917 TheAISContext()->Display (TheAxis, Standard_True);
923 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
924 else if ( !strcasecmp(argv[0], "vaxispara"))
926 if (aShapes.Extent() != 2)
928 std::cerr << "Error: Wrong number of selected shapes.\n";
932 const TopoDS_Shape& aShapeA = aShapes.First();
933 const TopoDS_Shape& aShapeB = aShapes.Last();
934 if (!(aShapeA.ShapeType() == TopAbs_EDGE
935 && aShapeB.ShapeType() == TopAbs_VERTEX))
937 std::cerr << "Syntax error: You should select face and then vertex.\n";
941 TopoDS_Edge ed=TopoDS::Edge (aShapeA);
942 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
944 TopExp::Vertices(ed,Va,Vc );
945 gp_Pnt A=BRep_Tool::Pnt(Va);
946 gp_Pnt C=BRep_Tool::Pnt(Vc);
949 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
950 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
951 GetMapOfAIS().Bind (TheAxis,name);
952 TheAISContext()->Display (TheAxis, Standard_True);
956 // Fonction axisortho
959 if (aShapes.Extent() != 2)
961 std::cerr << "Error: Wrong number of selected shapes.\n";
965 const TopoDS_Shape& aShapeA = aShapes.First();
966 const TopoDS_Shape& aShapeB = aShapes.Last();
967 if (!(aShapeA.ShapeType() == TopAbs_EDGE
968 && aShapeB.ShapeType() == TopAbs_VERTEX))
970 std::cerr << "Syntax error: You should select face and then vertex.\n";
974 // Construction de l'axe
975 TopoDS_Edge ed=TopoDS::Edge(aShapeA) ;
976 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) );
978 TopExp::Vertices(ed,Va,Vc );
979 gp_Pnt A=BRep_Tool::Pnt(Va);
980 gp_Pnt C=BRep_Tool::Pnt(Vc);
981 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
984 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
985 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
986 GetMapOfAIS().Bind (TheAxis,name);
987 TheAISContext()->Display (TheAxis, Standard_True);
996 //==============================================================================
997 // Fonction First click Result
999 // vpoint vertex AIS_Point=Vertex
1000 // edge AIS_Point=Middle of the edge
1001 //==============================================================================
1003 //==============================================================================
1004 //function : VPointBuilder
1005 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
1006 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
1007 //==============================================================================
1008 #include <TopoDS_Edge.hxx>
1009 #include <TopoDS_Vertex.hxx>
1010 #include <TopExp.hxx>
1011 #include <AIS_Point.hxx>
1012 #include <Geom_CartesianPoint.hxx>
1014 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1017 Standard_Boolean HasArg;
1018 TCollection_AsciiString name;
1021 if (argc<2 || argc>5 ) {di<<" Syntaxe error\n";return 1;}
1022 if (argc==5) HasArg=Standard_True;
1023 else HasArg=Standard_False;
1027 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
1029 Standard_Real thecoord[3];
1030 for(Standard_Integer i=0;i<=2;i++)
1031 thecoord[i]=Draw::Atof(argv[2+i]);
1032 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
1033 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
1034 GetMapOfAIS().Bind (myAISPoint,name);
1035 TheAISContext()->Display (myAISPoint, Standard_True);
1038 // Il n'a pas d'arguments
1041 TopTools_ListOfShape aShapes;
1042 ViewerTest::GetSelectedShapes (aShapes);
1044 if (aShapes.Extent() != 1)
1046 std::cerr << "Error: Wrong number of selected shapes.\n";
1047 std::cerr << "\tYou should select one edge or vertex.\n";
1051 const TopoDS_Shape& aShapeA = aShapes.First();
1053 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1055 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(aShapeA ) );
1056 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
1057 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
1058 GetMapOfAIS().Bind(myAISPoint,name);
1059 TheAISContext()->Display (myAISPoint, Standard_True);
1063 TopoDS_Edge myEdge=TopoDS::Edge(aShapeA);
1064 TopoDS_Vertex myVertexA,myVertexB;
1065 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
1066 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
1067 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
1068 // M est le milieu de [AB]
1069 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
1070 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
1071 GetMapOfAIS().Bind(myAISPointM,name);
1072 TheAISContext()->Display (myAISPointM, Standard_True);
1080 //==============================================================================
1081 // Function 1st click 2de click 3de click
1082 // vplane Vertex Vertex Vertex
1086 // vplanepara Face Vertex
1088 // vplaneortho Face Edge
1090 //==============================================================================
1092 //==============================================================================
1093 //function : VPlaneBuilder
1094 //purpose : Build an AIS_Plane from selected entities or Named AIS components
1095 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
1096 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
1097 // [PlaneName] [PointName] [TypeOfSensitivity]
1098 //==============================================================================
1100 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
1101 Standard_Integer argc,
1105 Standard_Boolean hasArg;
1106 TCollection_AsciiString aName;
1109 if (argc<2 || argc>6 )
1111 std::cout<<" Syntax error\n";
1114 if (argc == 6 || argc==5 || argc==4)
1115 hasArg=Standard_True;
1117 hasArg=Standard_False;
1121 // There are some arguments
1124 Handle(AIS_InteractiveObject) aShapeA;
1125 if (!GetMapOfAIS().Find2 (argv[2], aShapeA))
1127 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
1131 // The first argument is an AIS_Point
1132 if (!aShapeA.IsNull() &&
1133 aShapeA->Type()==AIS_KOI_Datum &&
1134 aShapeA->Signature()==1)
1136 // The second argument must also be an AIS_Point
1137 Handle(AIS_InteractiveObject) aShapeB;
1138 if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1140 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
1143 // If B is not an AIS_Point
1144 if (aShapeB.IsNull() ||
1145 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1147 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
1150 // The third object is an AIS_Point
1151 Handle(AIS_InteractiveObject) aShapeC;
1152 if (!GetMapOfAIS().Find2(argv[4], aShapeC))
1154 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
1157 // If C is not an AIS_Point
1158 if (aShapeC.IsNull() ||
1159 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
1161 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
1165 // Treatment of objects A, B, C
1166 // Downcast an AIS_IO to AIS_Point
1167 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
1168 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
1169 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
1171 Handle(Geom_CartesianPoint ) aCartPointA =
1172 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
1174 Handle(Geom_CartesianPoint ) aCartPointB =
1175 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
1177 Handle(Geom_CartesianPoint ) aCartPointC =
1178 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
1180 // Verification that the three points are different
1181 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
1182 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1183 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
1186 std::cout<<"vplane error: same points\n";return 1;
1188 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1189 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1190 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1193 std::cout<<"vplane error: same points\n";return 1;
1195 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1196 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1197 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1200 std::cout<<"vplane error: same points\n";return 1;
1203 gp_Pnt A = aCartPointA->Pnt();
1204 gp_Pnt B = aCartPointB->Pnt();
1205 gp_Pnt C = aCartPointC->Pnt();
1207 // Construction of AIS_Plane
1208 GC_MakePlane MkPlane (A,B,C);
1209 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1210 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1211 GetMapOfAIS().Bind (anAISPlane,aName );
1214 Standard_Integer aType = Draw::Atoi (argv[5]);
1215 if (aType != 0 && aType != 1)
1217 std::cout << "vplane error: wrong type of sensitivity!\n"
1218 << "Should be one of the following values:\n"
1226 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1229 TheAISContext()->Display (anAISPlane, Standard_True);
1232 // The first argument is an AIS_Axis
1233 // Creation of a plane orthogonal to the axis through a point
1234 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1235 // The second argument should be an AIS_Point
1236 Handle(AIS_InteractiveObject) aShapeB;
1237 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1239 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1242 // If B is not an AIS_Point
1243 if (aShapeB.IsNull() ||
1244 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1246 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1250 // Treatment of objects A and B
1251 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1252 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1254 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1255 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1257 gp_Ax1 anAxis = aGeomLineA->Position();
1258 Handle(Geom_CartesianPoint) aCartPointB =
1259 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1261 gp_Dir D =anAxis.Direction();
1262 gp_Pnt B = aCartPointB->Pnt();
1264 // Construction of AIS_Plane
1265 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1266 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1267 GetMapOfAIS().Bind (anAISPlane,aName );
1270 Standard_Integer aType = Draw::Atoi (argv[4]);
1271 if (aType != 0 && aType != 1)
1273 std::cout << "vplane error: wrong type of sensitivity!\n"
1274 << "Should be one of the following values:\n"
1282 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1285 TheAISContext()->Display (anAISPlane, Standard_True);
1288 // The first argumnet is an AIS_Plane
1289 // Creation of a plane parallel to the plane passing through the point
1290 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1292 // The second argument should be an AIS_Point
1293 Handle(AIS_InteractiveObject) aShapeB;
1294 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
1296 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1299 // B should be an AIS_Point
1300 if (aShapeB.IsNull() ||
1301 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1303 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1307 // Treatment of objects A and B
1308 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1309 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1311 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1312 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1314 Handle(Geom_CartesianPoint) aCartPointB =
1315 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1316 gp_Pnt B= aCartPointB->Pnt();
1318 // Construction of an AIS_Plane
1319 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1320 GetMapOfAIS().Bind (anAISPlane, aName);
1323 Standard_Integer aType = Draw::Atoi (argv[4]);
1324 if (aType != 0 && aType != 1)
1326 std::cout << "vplane error: wrong type of sensitivity!\n"
1327 << "Should be one of the following values:\n"
1335 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1338 TheAISContext()->Display (anAISPlane, Standard_True);
1343 std::cout<<"vplane: error 1st object is not an AIS\n";
1347 // There are no arguments
1350 TopTools_ListOfShape aShapes;
1351 ViewerTest::GetSelectedShapes (aShapes);
1354 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1355 if (!strcasecmp(argv[0], "vplane"))
1357 if (aShapes.Extent() < 1 || aShapes.Extent() > 3)
1359 std::cerr << "Error: Wront number of selected shapes.\n";
1360 std::cerr << "\tYou should one of variant: face, edge and vertex or three vertices.\n";
1364 const TopoDS_Shape& aShapeA = aShapes.First();
1365 if (aShapeA.ShapeType() == TopAbs_VERTEX)
1367 if (aShapes.Extent() == 2)
1369 const TopoDS_Shape& aShapeB = aShapes.Last();
1370 if (aShapeB.ShapeType() != TopAbs_EDGE)
1372 std::cerr << "Syntax error: Together with vertex should be edge.\n";
1376 // Verify that the vertex is not on the edge ShapeB
1377 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1378 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1380 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1381 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1383 // The vertex is on the edge
1384 std::cout<<" vplane: error point is on the edge\n";
1389 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1390 TopoDS_Vertex aVBa, aVBb;
1391 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1392 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1393 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1394 GC_MakePlane MkPlane (A, aBa, aBb);
1395 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1396 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1397 GetMapOfAIS().Bind (anAISPlane, aName);
1398 TheAISContext()->Display (anAISPlane, Standard_True);
1401 else if (aShapes.Extent() == 3)
1403 TopTools_ListOfShape::Iterator anIter (aShapes);
1406 const TopoDS_Shape& aShapeB = anIter.Value();
1409 const TopoDS_Shape& aShapeC = anIter.Value();
1411 if (!(aShapeB.ShapeType() == TopAbs_VERTEX
1412 && aShapeC.ShapeType() == TopAbs_VERTEX))
1414 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1418 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1419 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1420 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1421 GC_MakePlane MkPlane(A, B, C);
1422 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1423 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1424 GetMapOfAIS().Bind (anAISPlane, aName);
1425 TheAISContext()->Display (anAISPlane, Standard_True);
1429 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1433 else if (aShapeA.ShapeType() == TopAbs_EDGE)
1435 if (aShapes.Extent() != 2)
1437 std::cerr << "Error: wrong number of selected shapes.\n";
1441 const TopoDS_Shape& aShapeB = aShapes.Last();
1442 if (aShapeB.ShapeType() != TopAbs_VERTEX)
1444 std::cerr << "Syntax error: Together with edge should be vertex.\n";
1448 // Check that the vertex aShapeB is not on the edge
1449 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1450 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1452 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1453 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1455 // The vertex is on the edge
1456 std::cout<<" vplane: error point is on the edge\n";
1460 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1461 TopoDS_Vertex aVAa, aVAb;
1462 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1463 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1464 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1465 GC_MakePlane MkPlane (B,Aa,Ab);
1466 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1467 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1468 GetMapOfAIS().Bind (anAISPlane ,aName);
1469 TheAISContext()->Display (anAISPlane, Standard_True);
1471 else if (aShapeA.ShapeType() == TopAbs_FACE)
1473 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1474 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1475 if (aSurface.GetType()==GeomAbs_Plane)
1477 gp_Pln aPlane = aSurface.Plane();
1478 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1479 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1480 GetMapOfAIS().Bind (anAISPlane, aName);
1481 TheAISContext()->Display (anAISPlane, Standard_True);
1485 std::cout<<" vplane: error\n";
1491 std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
1496 // Function vPlanePara
1497 // ===================
1498 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1499 else if (!strcasecmp(argv[0], "vplanepara"))
1501 if (aShapes.Extent() != 2)
1503 std::cerr << "Error: Wrong number of selected shapes.\n";
1507 const TopoDS_Shape* aShapeA = &aShapes.First();
1508 const TopoDS_Shape* aShapeB = &aShapes.Last();
1509 if (aShapeA->ShapeType() != TopAbs_VERTEX)
1511 std::swap (aShapeA, aShapeB);
1514 if (!(aShapeA->ShapeType() == TopAbs_VERTEX
1515 && aShapeB->ShapeType() == TopAbs_FACE))
1517 std::cerr << "Syntax error: you should select face and vertex.\n";
1521 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA));
1523 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1524 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1525 if (aSurface.GetType() == GeomAbs_Plane)
1527 gp_Pln aPlane = aSurface.Plane();
1528 // Construct a plane parallel to aGeomPlane through A
1529 aPlane.SetLocation(A);
1530 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1531 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1532 GetMapOfAIS().Bind (aAISPlane ,aName);
1533 TheAISContext()->Display (aAISPlane, Standard_True);
1537 std::cerr << "Error: Builded surface is not a plane.\n";
1542 // Function vplaneortho
1543 // ====================
1544 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1547 if (aShapes.Extent() != 2)
1549 std::cerr << "Error: wrong number of selected shapes.\n";
1553 const TopoDS_Shape* aShapeA = &aShapes.First();
1554 const TopoDS_Shape* aShapeB = &aShapes.Last();
1556 if (aShapeA->ShapeType() != TopAbs_EDGE)
1558 std::swap (aShapeA, aShapeB);
1561 if (!(aShapeA->ShapeType() == TopAbs_EDGE
1562 && aShapeB->ShapeType() == TopAbs_FACE))
1564 std::cerr << "Error: you should select edge and face.\n";
1568 // Construction of plane
1569 TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA);
1570 TopoDS_Vertex aVAa, aVAb;
1571 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1572 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1573 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1577 // Creation of rotation axis
1578 gp_Ax1 aRotAxis (Aa,Dab);
1580 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1581 // The edge must be parallel to the face
1582 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1583 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1584 // Compare to heights
1585 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1586 >Precision::Confusion())
1588 // the edge is not parallel to the face
1589 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1593 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1594 if (aSurface.GetType()==GeomAbs_Plane)
1596 gp_Pln aPlane = aSurface.Plane();
1597 // It rotates a half turn round the axis of rotation
1598 aPlane.Rotate(aRotAxis , M_PI/2);
1600 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1601 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1602 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1603 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1604 GetMapOfAIS().Bind (anAISPlane, aName);
1605 TheAISContext()->Display (anAISPlane, Standard_True);
1609 std::cout<<" vplaneortho: error\n";
1617 //===============================================================================================
1618 //function : VChangePlane
1620 //===============================================================================================
1621 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1623 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1624 if (aContextAIS.IsNull())
1626 std::cout << theArgVec[0] << "AIS context is not available.\n";
1630 if (theArgsNb < 3 || theArgsNb > 11)
1632 std::cerr << theArgVec[0]
1633 << ": incorrect number of command arguments.\n"
1634 << "Type help for more information.\n";
1638 TCollection_AsciiString aName (theArgVec[1]);
1640 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1641 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1644 if ( aPlane.IsNull() )
1646 std::cout << theArgVec[0]
1647 << ": there is no interactive plane with the given name."
1648 << "Type help for more information.\n";
1652 Standard_Real aCenterX = aPlane->Center().X();
1653 Standard_Real aCenterY = aPlane->Center().Y();
1654 Standard_Real aCenterZ = aPlane->Center().Z();
1656 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1657 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1658 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1660 Standard_Real aSizeX = 0.0;
1661 Standard_Real aSizeY = 0.0;
1662 aPlane->Size (aSizeX, aSizeY);
1663 Standard_Boolean isUpdate = Standard_True;
1665 TCollection_AsciiString aPName, aPValue;
1666 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1668 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1669 TCollection_AsciiString anArgCase = anArg;
1670 anArgCase.UpperCase();
1671 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1674 if (aPName.IsEqual ("X"))
1676 aCenterX = aPValue.RealValue();
1678 else if (aPName.IsEqual ("Y"))
1680 aCenterY = aPValue.RealValue();
1682 else if (aPName.IsEqual ("Z"))
1684 aCenterZ = aPValue.RealValue();
1686 else if (aPName.IsEqual ("DX"))
1688 aDirX = aPValue.RealValue();
1690 else if (aPName.IsEqual ("DY"))
1692 aDirY = aPValue.RealValue();
1694 else if (aPName.IsEqual ("DZ"))
1696 aDirZ = aPValue.RealValue();
1698 else if (aPName.IsEqual ("SX"))
1700 aSizeX = aPValue.RealValue();
1702 else if (aPName.IsEqual ("SY"))
1704 aSizeY = aPValue.RealValue();
1707 else if (anArg.IsEqual ("NOUPDATE"))
1709 isUpdate = Standard_False;
1713 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1714 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1715 aPlane->SetCenter (aCenterPnt);
1716 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1717 aPlane->SetSize (aSizeX, aSizeY);
1719 aContextAIS->Update (aPlane, isUpdate);
1724 //==============================================================================
1726 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1727 //==============================================================================
1729 //==============================================================================
1730 //function : VLineBuilder
1731 //purpose : Build an AIS_Line
1732 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1733 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1734 //==============================================================================
1735 #include <Geom_CartesianPoint.hxx>
1736 #include <AIS_Line.hxx>
1739 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1742 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; }
1744 // On recupere les parametres
1745 Handle(AIS_InteractiveObject) theShapeA;
1746 Handle(AIS_InteractiveObject) theShapeB;
1748 // Parametres: AIS_Point AIS_Point
1749 // ===============================
1751 GetMapOfAIS().Find2 (argv[2], theShapeA);
1752 // On verifie que c'est bien une AIS_Point
1753 if (!theShapeA.IsNull() &&
1754 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1755 // on recupere le deuxieme AIS_Point
1756 GetMapOfAIS().Find2 (argv[3], theShapeB);
1757 if (theShapeB.IsNull() ||
1758 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1760 di <<"vline error: wrong type of 2de argument.\n";
1764 else {di <<"vline error: wrong type of 1st argument.\n";return 1; }
1765 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1766 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1767 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
1769 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1770 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
1771 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1773 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1774 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
1775 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1777 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1779 di<<"vline error: same points\n";return 1;
1781 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1782 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1783 GetMapOfAIS().Bind(theAISLine,argv[1] );
1784 TheAISContext()->Display (theAISLine, Standard_True);
1788 // Parametres 6 Reals
1789 // ==================
1792 // On verifie que les deux points ne sont pas confondus
1794 Standard_Real coord[6];
1795 for(Standard_Integer i=0;i<=2;i++){
1796 coord[i]=Draw::Atof(argv[2+i]);
1797 coord[i+3]=Draw::Atof(argv[5+i]);
1800 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1801 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1803 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1804 GetMapOfAIS().Bind(theAISLine,argv[1] );
1805 TheAISContext()->Display (theAISLine, Standard_True);
1809 // Pas de parametres: Selection dans le viewer.
1810 // ============================================
1814 TopTools_ListOfShape aShapes;
1815 ViewerTest::GetSelectedShapes (aShapes);
1816 if (aShapes.Extent() != 2)
1818 std::cerr << "Error: wrong number of selected shapes.\n";
1822 const TopoDS_Shape& aShapeA = aShapes.First();
1823 const TopoDS_Shape& aShapeB = aShapes.Last();
1825 if (!(aShapeA.ShapeType() == TopAbs_VERTEX
1826 && aShapeB.ShapeType() == TopAbs_VERTEX))
1828 std::cerr << "Error: you should select two different vertex.\n";
1832 // Construction de la line
1833 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1834 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
1836 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1837 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1839 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1840 GetMapOfAIS().Bind(theAISLine,argv[1] );
1841 TheAISContext()->Display (theAISLine, Standard_True);
1847 //==============================================================================
1848 // class : FilledCircle
1849 // purpose : creates filled circle based on AIS_InteractiveObject
1851 // This class is used to check method Matches() of class
1852 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1853 // because none of AIS classes provides creation of
1854 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1855 // (look method ComputeSelection() )
1856 //==============================================================================
1858 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1860 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1861 gp_Circ aCirc(anAxes, theRadius);
1862 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1866 class FilledCircle : public AIS_InteractiveObject
1870 DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject);
1872 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1873 FilledCircle(Handle(Geom_Circle) theCircle);
1876 TopoDS_Face ComputeFace();
1878 // Virtual methods implementation
1879 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1880 const Handle(Prs3d_Presentation)& thePresentation,
1881 const Standard_Integer theMode) Standard_OVERRIDE;
1883 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1884 const Standard_Integer theMode) Standard_OVERRIDE;
1887 Handle(Geom_Circle) myCircle;
1888 Standard_Boolean myFilledStatus;
1893 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1895 myCircle = CreateCircle(theCenter, theRadius);
1896 myFilledStatus = Standard_True;
1899 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1901 myCircle = theCircle;
1902 myFilledStatus = Standard_True;
1905 TopoDS_Face FilledCircle::ComputeFace()
1907 // Create edge from myCircle
1908 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1909 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1911 // Create wire from anEdge
1912 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1913 TopoDS_Wire aWire = aWireMaker.Wire();
1915 // Create face from aWire
1916 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1917 TopoDS_Face aFace = aFaceMaker.Face();
1922 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1923 const Handle(Prs3d_Presentation) &thePresentation,
1924 const Standard_Integer theMode)
1926 thePresentation->Clear();
1928 TopoDS_Face aFace = ComputeFace();
1930 if (aFace.IsNull()) return;
1931 if (theMode != 0) return;
1933 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1936 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
1937 const Standard_Integer /*theMode*/)
1939 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
1940 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
1941 myCircle, myFilledStatus);
1942 theSelection->Add(aSensitiveCircle);
1945 //==============================================================================
1947 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
1948 //==============================================================================
1950 //==============================================================================
1951 //function : VCircleBuilder
1952 //purpose : Build an AIS_Circle
1953 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
1954 // PointName PointName PointName IsFilled
1955 //==============================================================================
1957 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
1958 TCollection_AsciiString theName,
1959 Standard_Boolean isFilled)
1961 Handle(AIS_InteractiveObject) aCircle;
1964 aCircle = new FilledCircle(theGeomCircle);
1968 aCircle = new AIS_Circle(theGeomCircle);
1969 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
1972 // Check if there is an object with given name
1973 // and remove it from context
1974 if (GetMapOfAIS().IsBound2(theName))
1976 Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2(theName);
1977 TheAISContext()->Remove(anInterObj, Standard_False);
1978 GetMapOfAIS().UnBind2(theName);
1981 // Bind the circle to its name
1982 GetMapOfAIS().Bind(aCircle, theName);
1984 // Display the circle
1985 TheAISContext()->Display (aCircle, Standard_True);
1989 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
1991 // Verification of the arguments
1992 if (argc>6 || argc<2)
1994 std::cout << "vcircle error: expect 4 arguments.\n";
1995 return 1; // TCL_ERROR
1998 // There are all arguments
2002 TCollection_AsciiString aName(argv[1]);
2003 Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0;
2005 Handle(AIS_InteractiveObject) theShapeA, theShapeB;
2006 GetMapOfAIS().Find2 (argv[2], theShapeA);
2007 GetMapOfAIS().Find2 (argv[3], theShapeB);
2009 // Arguments: AIS_Point AIS_Point AIS_Point
2010 // ========================================
2011 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2012 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2014 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2016 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2017 return 1; // TCL_ERROR
2019 // The third object must be a point
2020 Handle(AIS_InteractiveObject) theShapeC;
2021 GetMapOfAIS().Find2 (argv[4], theShapeC);
2022 if (theShapeC.IsNull() ||
2023 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2025 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2026 return 1; // TCL_ERROR
2029 // Verify that the three points are different
2030 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2031 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2032 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2034 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2035 Handle(Geom_CartesianPoint) myCartPointA =
2036 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2038 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2039 Handle(Geom_CartesianPoint) myCartPointB =
2040 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2042 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2043 Handle(Geom_CartesianPoint) myCartPointC =
2044 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2047 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2048 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2049 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2051 std::cout << "vcircle error: Same points.\n";
2052 return 1; // TCL_ERROR
2055 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2056 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2057 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2059 std::cout << "vcircle error: Same points.\n";
2060 return 1; // TCL_ERROR
2063 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2064 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2065 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2067 std::cout << "vcircle error: Same points.\n";
2068 return 1;// TCL_ERROR
2070 // Construction of the circle
2071 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2072 myCartPointB->Pnt(), myCartPointC->Pnt() );
2073 Handle (Geom_Circle) theGeomCircle;
2076 theGeomCircle = Cir.Value();
2078 catch (StdFail_NotDone)
2080 std::cout << "vcircle error: can't create circle\n";
2081 return -1; // TCL_ERROR
2084 DisplayCircle(theGeomCircle, aName, isFilled);
2087 // Arguments: AIS_Plane AIS_Point Real
2088 // ===================================
2089 else if (theShapeA->Type() == AIS_KOI_Datum &&
2090 theShapeA->Signature() == 7 )
2092 if (theShapeB->Type() != AIS_KOI_Datum ||
2093 theShapeB->Signature() != 1 )
2095 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2096 return 1; // TCL_ERROR
2098 // Check that the radius is >= 0
2099 if (Draw::Atof(argv[4]) <= 0 )
2101 std::cout << "vcircle error: the radius must be >=0.\n";
2102 return 1; // TCL_ERROR
2105 // Recover the normal to the plane
2106 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2107 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2109 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2110 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2111 Handle(Geom_CartesianPoint) myCartPointB =
2112 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2114 gp_Pln mygpPlane = myGeomPlane->Pln();
2115 gp_Ax1 thegpAxe = mygpPlane.Axis();
2116 gp_Dir theDir = thegpAxe.Direction();
2117 gp_Pnt theCenter = myCartPointB->Pnt();
2118 Standard_Real TheR = Draw::Atof(argv[4]);
2119 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2120 Handle (Geom_Circle) theGeomCircle;
2123 theGeomCircle = Cir.Value();
2125 catch (StdFail_NotDone)
2127 std::cout << "vcircle error: can't create circle\n";
2128 return -1; // TCL_ERROR
2131 DisplayCircle(theGeomCircle, aName, isFilled);
2138 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2139 return 1; // TCL_ERROR
2143 // No arguments: selection in the viewer
2144 // =========================================
2147 // Get the name of the circle
2148 TCollection_AsciiString aName(argv[1]);
2150 TopTools_ListOfShape aShapes;
2151 ViewerTest::GetSelectedShapes (aShapes);
2152 if (aShapes.Extent() != 3 && aShapes.Extent() != 2)
2154 std::cerr << "Error: Wrong number of selected shapes.\n";
2158 const TopoDS_Shape& aShapeA = aShapes.First();
2159 if (aShapeA.ShapeType() == TopAbs_VERTEX )
2161 if (aShapes.Extent() != 3)
2163 std::cerr << "Error: wrong number of selected shapes.\n";
2167 TopTools_ListOfShape::Iterator anIter (aShapes);
2170 const TopoDS_Shape& aShapeB = anIter.Value();
2173 const TopoDS_Shape& aShapeC = anIter.Value();
2176 Standard_Boolean isFilled;
2177 std::cout << "Enter filled status (0 or 1)\n";
2180 // Construction of the circle
2181 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
2182 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2183 gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC));
2185 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2186 Handle (Geom_Circle) theGeomCircle;
2189 theGeomCircle = Cir.Value();
2191 catch (StdFail_NotDone)
2193 std::cout << "vcircle error: can't create circle\n";
2194 return -1; // TCL_ERROR
2197 DisplayCircle(theGeomCircle, aName, isFilled);
2200 else if (aShapeA.ShapeType() == TopAbs_FACE)
2202 const TopoDS_Shape& aShapeB = aShapes.Last();
2204 // Recover the radius
2205 Standard_Real theRad;
2208 std::cout << " Enter the value of the radius:\n";
2210 } while (theRad <= 0);
2212 // Get filled status
2213 Standard_Boolean isFilled;
2214 std::cout << "Enter filled status (0 or 1)\n";
2217 // Recover the normal to the plane. tag
2218 TopoDS_Face myFace = TopoDS::Face(aShapeA);
2219 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2220 gp_Pln myPlane = mySurface.Plane();
2221 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2222 gp_Pln mygpPlane = theGeomPlane->Pln();
2223 gp_Ax1 thegpAxe = mygpPlane.Axis();
2224 gp_Dir theDir = thegpAxe.Direction();
2226 // Recover the center
2227 gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2229 // Construct the circle
2230 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2231 Handle (Geom_Circle) theGeomCircle;
2234 theGeomCircle = Cir.Value();
2236 catch (StdFail_NotDone)
2238 std::cout << "vcircle error: can't create circle\n";
2239 return -1; // TCL_ERROR
2242 DisplayCircle(theGeomCircle, aName, isFilled);
2246 std::cerr << "Error: You should select face and vertex or three vertices.\n";
2254 //=======================================================================
2255 //function : VDrawText
2257 //=======================================================================
2258 static int VDrawText (Draw_Interpretor& theDI,
2259 Standard_Integer theArgsNb,
2260 const char** theArgVec)
2262 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2265 std::cout << "Error: wrong number of arguments! See usage:\n";
2266 theDI.PrintHelp (theArgVec[0]);
2269 else if (aContext.IsNull())
2271 std::cout << "Error: no active view!\n";
2275 Standard_Integer anArgIt = 1;
2276 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2277 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2278 Handle(AIS_TextLabel) aTextPrs;
2279 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2281 Standard_Boolean isNewPrs = Standard_False;
2282 if (GetMapOfAIS().IsBound2 (aName))
2284 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2287 if (aTextPrs.IsNull())
2289 isNewPrs = Standard_True;
2290 aTextPrs = new AIS_TextLabel();
2291 aTextPrs->SetFont ("Courier");
2294 aTextPrs->SetText (aText);
2296 Handle(Graphic3d_TransformPers) aTrsfPers;
2297 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2299 Standard_Boolean aHasPlane = Standard_False;
2304 for (; anArgIt < theArgsNb; ++anArgIt)
2306 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2309 if (anAutoUpdater.parseRedrawMode (aParam))
2313 else if (aParam == "-pos"
2314 || aParam == "-position")
2316 if (anArgIt + 3 >= theArgsNb)
2318 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2322 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2323 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2324 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2325 aTextPrs->SetPosition (aPos);
2327 else if (aParam == "-color")
2329 if (anArgIt + 1 >= theArgsNb)
2331 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2335 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2336 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2337 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2340 aTextPrs->SetColor (aNameOfColor);
2343 else if (anArgIt + 3 >= theArgsNb)
2345 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2349 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2350 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2351 if (!aColor.IsRealValue()
2352 || !aGreen.IsRealValue()
2353 || !aBlue.IsRealValue())
2355 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2359 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2363 aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2366 else if (aParam == "-halign")
2368 if (++anArgIt >= theArgsNb)
2370 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2374 TCollection_AsciiString aType (theArgVec[anArgIt]);
2376 if (aType == "left")
2378 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2380 else if (aType == "center")
2382 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2384 else if (aType == "right")
2386 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2390 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2394 else if (aParam == "-valign")
2396 if (++anArgIt >= theArgsNb)
2398 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2402 TCollection_AsciiString aType (theArgVec[anArgIt]);
2406 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2408 else if (aType == "center")
2410 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2412 else if (aType == "bottom")
2414 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2416 else if (aType == "topfirstline")
2418 aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2422 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2426 else if (aParam == "-angle")
2428 if (++anArgIt >= theArgsNb)
2430 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2434 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2436 else if (aParam == "-zoom")
2438 if (++anArgIt >= theArgsNb)
2440 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2444 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2446 else if (aParam == "-height")
2448 if (++anArgIt >= theArgsNb)
2450 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2454 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2456 else if (aParam == "-aspect")
2458 if (++anArgIt >= theArgsNb)
2460 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2464 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2465 anOption.LowerCase();
2466 if (anOption.IsEqual ("regular"))
2468 aTextPrs->SetFontAspect (Font_FA_Regular);
2470 else if (anOption.IsEqual ("bold"))
2472 aTextPrs->SetFontAspect (Font_FA_Bold);
2474 else if (anOption.IsEqual ("italic"))
2476 aTextPrs->SetFontAspect (Font_FA_Italic);
2478 else if (anOption.IsEqual ("bolditalic"))
2480 aTextPrs->SetFontAspect (Font_FA_BoldItalic);
2483 else if (aParam == "-font")
2485 if (++anArgIt >= theArgsNb)
2487 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2491 aTextPrs->SetFont (theArgVec[anArgIt]);
2493 else if (aParam == "-plane")
2495 if (anArgIt + 6 >= theArgsNb)
2497 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2501 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
2502 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
2503 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
2504 aNormal.SetCoord (aX, aY, aZ);
2506 aX = Draw::Atof (theArgVec[++anArgIt]);
2507 aY = Draw::Atof (theArgVec[++anArgIt]);
2508 aZ = Draw::Atof (theArgVec[++anArgIt]);
2509 aDirection.SetCoord (aX, aY, aZ);
2511 aHasPlane = Standard_True;
2513 else if (aParam == "-flipping")
2515 aTextPrs->SetFlipping (Standard_True);
2517 else if (aParam == "-disptype"
2518 || aParam == "-displaytype")
2520 if (++anArgIt >= theArgsNb)
2522 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2525 TCollection_AsciiString aType (theArgVec[anArgIt]);
2527 if (aType == "subtitle")
2528 aDisplayType = Aspect_TODT_SUBTITLE;
2529 else if (aType == "decal")
2530 aDisplayType = Aspect_TODT_DEKALE;
2531 else if (aType == "blend")
2532 aDisplayType = Aspect_TODT_BLEND;
2533 else if (aType == "dimension")
2534 aDisplayType = Aspect_TODT_DIMENSION;
2535 else if (aType == "normal")
2536 aDisplayType = Aspect_TODT_NORMAL;
2537 else if (aType == "shadow")
2538 aDisplayType = Aspect_TODT_SHADOW;
2541 std::cout << "Error: wrong display type '" << aType << "'.\n";
2545 else if (aParam == "-subcolor"
2546 || aParam == "-subtitlecolor")
2548 if (anArgIt + 1 >= theArgsNb)
2550 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2554 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2555 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2556 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2559 aTextPrs->SetColorSubTitle (aNameOfColor);
2562 else if (anArgIt + 3 >= theArgsNb)
2564 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2568 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2569 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2570 if (!aColor.IsRealValue()
2571 || !aGreen.IsRealValue()
2572 || !aBlue.IsRealValue())
2574 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2578 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2582 aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2585 else if (aParam == "-2d")
2587 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d);
2589 else if (aParam == "-trsfperspos"
2590 || aParam == "-perspos")
2592 if (anArgIt + 2 >= theArgsNb)
2594 std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2598 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2599 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2600 TCollection_AsciiString aZ = "0";
2601 if (!aX.IsIntegerValue()
2602 || !aY.IsIntegerValue())
2604 std::cerr << "Error: wrong syntax at '" << aParam << "'.\n";
2607 if (anArgIt + 1 < theArgsNb)
2609 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2610 if (aTemp.IsIntegerValue())
2617 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()));
2621 std::cout << "Error: unknown argument '" << aParam << "'\n";
2628 aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2631 aTextPrs->SetDisplayType (aDisplayType);
2633 if (!aTrsfPers.IsNull())
2635 aContext->SetTransformPersistence (aTextPrs, aTrsfPers);
2636 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2637 if (aTextPrs->Position().Z() != 0)
2639 aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
2642 else if (!aTextPrs->TransformPersistence().IsNull())
2644 aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
2649 ViewerTest::Display (aName, aTextPrs, Standard_False);
2653 aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
2659 #include <gp_Pnt.hxx>
2660 #include <Graphic3d_ArrayOfPoints.hxx>
2661 #include <Graphic3d_ArrayOfPrimitives.hxx>
2662 #include <Graphic3d_ArrayOfTriangles.hxx>
2663 #include <Poly_Array1OfTriangle.hxx>
2664 #include <Poly_Triangle.hxx>
2665 #include <Poly_Triangulation.hxx>
2666 #include <TColgp_Array1OfPnt.hxx>
2667 #include <TShort_Array1OfShortReal.hxx>
2668 #include <TShort_HArray1OfShortReal.hxx>
2670 #include <AIS_Triangulation.hxx>
2671 #include <StdPrs_ToolTriangulatedShape.hxx>
2672 #include <Poly_Connect.hxx>
2673 #include <TColgp_Array1OfDir.hxx>
2674 #include <Graphic3d_GraphicDriver.hxx>
2676 #include <TColStd_Array1OfInteger.hxx>
2677 #include <TColStd_HArray1OfInteger.hxx>
2678 #include <Prs3d_ShadingAspect.hxx>
2679 #include <Graphic3d_MaterialAspect.hxx>
2680 #include <Graphic3d_AspectFillArea3d.hxx>
2682 #include <BRepPrimAPI_MakeCylinder.hxx>
2683 #include <TopoDS_Shape.hxx>
2684 #include <TopExp_Explorer.hxx>
2685 #include <TopAbs.hxx>
2686 #include <StdSelect_ShapeTypeFilter.hxx>
2687 #include <AIS_InteractiveObject.hxx>
2690 //===============================================================================================
2691 //function : CalculationOfSphere
2693 //purpose : Create a Sphere
2694 //===============================================================================================
2696 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2699 double mRadius = Radius;
2700 double mCenter[3] = {X,Y,Z};
2701 int mThetaResolution;
2703 double mStartTheta = 0;//StartTheta;
2704 double mEndTheta = 360;//EndTheta;
2705 double mStartPhi = 0;//StartPhi;
2706 double mEndPhi = 180;//EndPhi;
2707 res = res < 4 ? 4 : res;
2709 mThetaResolution = res;
2710 mPhiResolution = res;
2713 int jStart, jEnd, numOffset;
2714 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2715 double startTheta, endTheta, startPhi, endPhi;
2716 int base, numPoles=0, thetaResolution, phiResolution;
2721 if ( numPieces > mThetaResolution ) {
2722 numPieces = mThetaResolution;
2725 int localThetaResolution = mThetaResolution;
2726 double localStartTheta = mStartTheta;
2727 double localEndTheta = mEndTheta;
2729 while ( localEndTheta < localStartTheta ) {
2730 localEndTheta += 360.0;
2733 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2735 // Change the ivars based on pieces.
2737 start = piece * localThetaResolution / numPieces;
2738 end = (piece+1) * localThetaResolution / numPieces;
2739 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2740 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2741 localThetaResolution = end - start;
2743 // Create north pole if needed
2744 int number_point = 0;
2745 int number_pointArray = 0;
2747 if ( mStartPhi <= 0.0 ) {
2748 number_pointArray++;
2751 if ( mEndPhi >= 180.0 ) {
2752 number_pointArray++;
2756 // Check data, determine increments, and convert to radians
2757 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2758 startTheta *= M_PI / 180.0;
2759 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2760 endTheta *= M_PI / 180.0;
2763 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2764 startPhi *= M_PI / 180.0;
2765 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2766 endPhi *= M_PI / 180.0;
2768 phiResolution = mPhiResolution - numPoles;
2769 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2770 thetaResolution = localThetaResolution;
2771 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2772 ++localThetaResolution;
2774 deltaTheta = (endTheta - startTheta) / thetaResolution;
2776 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2777 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2779 // Create intermediate points
2780 for ( i = 0; i < localThetaResolution; i++ ) {
2781 for ( j = jStart; j < jEnd; j++ ) {
2782 number_pointArray++;
2786 //Generate mesh connectivity
2787 base = phiResolution * localThetaResolution;
2789 int number_triangle = 0 ;
2790 if ( mStartPhi <= 0.0 ) { // around north pole
2791 number_triangle += localThetaResolution;
2794 if ( mEndPhi >= 180.0 ) { // around south pole
2795 number_triangle += localThetaResolution;
2798 // bands in-between poles
2799 for ( i=0; i < localThetaResolution; i++){
2800 for ( j=0; j < (phiResolution-1); j++){
2801 number_triangle +=2;
2805 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2806 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2807 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2809 if ( mStartPhi <= 0.0 ){
2812 x[2] = mCenter[2] + mRadius;
2813 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2816 // Create south pole if needed
2817 if ( mEndPhi >= 180.0 ){
2820 x[2] = mCenter[2] - mRadius;
2821 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2825 for ( i=0; i < localThetaResolution; i++){
2826 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2827 for ( j = jStart; j < jEnd; j++){
2828 phi = startPhi + j*deltaPhi;
2829 radius = mRadius * sin((double)phi);
2830 n[0] = radius * cos((double)theta);
2831 n[1] = radius * sin((double)theta);
2832 n[2] = mRadius * cos((double)phi);
2833 x[0] = n[0] + mCenter[0];
2834 x[1] = n[1] + mCenter[1];
2835 x[2] = n[2] + mCenter[2];
2836 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2842 number_triangle = 1;
2843 if ( mStartPhi <= 0.0 ){// around north pole
2844 for (i=0; i < localThetaResolution; i++){
2845 pts[0] = phiResolution*i + numPoles;
2846 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2848 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2853 if ( mEndPhi >= 180.0 ){ // around south pole
2854 numOffset = phiResolution - 1 + numPoles;
2855 for (i=0; i < localThetaResolution; i++){
2856 pts[0] = phiResolution*i + numOffset;
2857 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2858 pts[1] = numPoles - 1;
2859 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2864 // bands in-between poles
2866 for (i=0; i < localThetaResolution; i++){
2867 for (j=0; j < (phiResolution-1); j++){
2868 pts[0] = phiResolution*i + j + numPoles;
2869 pts[1] = pts[0] + 1;
2870 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2871 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2874 pts[2] = pts[1] - 1;
2875 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2880 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2882 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2884 Standard_Integer index[3];
2885 Standard_Real Tol = Precision::Confusion();
2888 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2889 gp_XYZ eqPlan(0, 0, 0);
2890 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2891 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2892 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2893 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2895 Standard_Real mod = vv.Modulus();
2896 if(mod < Tol) continue;
2900 Standard_Real modmax = eqPlan.Modulus();
2903 Nor = gp_Dir(eqPlan);
2905 Nor = gp_Dir(0., 0., 1.);
2907 Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
2908 Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
2909 Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
2910 Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
2914 polyTriangulation->SetNormals(Normals);
2916 return polyTriangulation;
2919 //===============================================================================================
2920 //function : VDrawSphere
2922 //purpose : Create an AIS shape.
2923 //===============================================================================================
2924 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2927 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2928 if (aContextAIS.IsNull())
2930 std::cout << "Call vinit before!\n";
2935 std::cout << "Use: " << argv[0]
2936 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2940 // read the arguments
2941 TCollection_AsciiString aShapeName (argv[1]);
2942 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2943 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2944 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2945 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2946 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2947 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2948 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
2950 // remove AIS object with given name from map
2951 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2954 std::cout << "Compute Triangulation...\n";
2955 Handle(AIS_Triangulation) aShape
2956 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2959 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2960 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2962 // stupid initialization of Green color in RGBA space as integer
2963 // probably wrong for big-endian CPUs
2964 const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
2966 // setup colors array per vertex
2967 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2968 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2970 aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData()));
2972 aShape->SetColors (aColorArray);
2975 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2976 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2977 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2978 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2979 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2980 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2981 aTotalSize >>= 20; //MB
2982 aNormalsSize >>= 20;
2984 aTrianglesSize >>= 20;
2985 aPolyConnectSize >>= 20;
2988 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2989 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2990 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2991 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2992 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2993 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2996 // Setting material properties, very important for desirable visual result!
2997 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2998 aMat.SetAmbient (0.2f);
2999 aMat.SetSpecular (0.5f);
3000 Handle(Graphic3d_AspectFillArea3d) anAspect
3001 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3003 Quantity_NOC_YELLOW,
3008 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3011 anAspect->SetEdgeOn();
3015 anAspect->SetEdgeOff();
3017 aShAsp->SetAspect (anAspect);
3018 aShape->Attributes()->SetShadingAspect (aShAsp);
3020 VDisplayAISObject (aShapeName, aShape);
3024 //=============================================================================
3025 //function : VComputeHLR
3027 //=============================================================================
3029 static int VComputeHLR (Draw_Interpretor& ,
3030 Standard_Integer theArgNb,
3031 const char** theArgVec)
3033 TCollection_AsciiString aShapeName, aHlrName;
3038 bool hasViewDirArg = false;
3039 Prs3d_TypeOfHLR anAlgoType = Prs3d_TOH_PolyAlgo;
3040 bool toShowTangentEdges = false, toShowHiddenEdges = false;
3041 int aNbIsolines = 0;
3042 if (Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext())
3045 Handle(V3d_View) aView = ViewerTest::CurrentView();
3046 Standard_Integer aWidth, aHeight;
3047 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3048 Standard_Real aRightX, aRightY, aRightZ;
3049 aView->Window()->Size (aWidth, aHeight);
3051 aView->ConvertWithProj (aWidth, aHeight/2,
3052 aRightX, aRightY, aRightZ,
3053 aDirX, aDirY, aDirZ);
3054 aView->ConvertWithProj (aWidth/2, aHeight/2,
3055 aCentX, aCentY, aCentZ,
3056 aDirX, aDirY, aDirZ);
3058 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3059 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3060 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3061 aProjAx.SetLocation (anEye);
3062 aProjAx.SetDirection (aDir);
3063 aProjAx.SetXDirection (aRight);
3065 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3067 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3068 anArgCase.LowerCase();
3069 if (anArgIter + 1 < theArgNb
3070 && (anArgCase == "-algotype"
3071 || anArgCase == "-algo"
3072 || anArgCase == "-type"))
3074 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
3075 anArgNext.LowerCase();
3076 if (anArgNext == "polyalgo")
3078 anAlgoType = Prs3d_TOH_PolyAlgo;
3080 else if (anArgNext == "algo")
3082 anAlgoType = Prs3d_TOH_Algo;
3086 std::cout << "Syntax error: unknown algo type '" << anArgNext << "'\n";
3090 else if (anArgCase == "-showhiddenedges"
3091 || anArgCase == "-hiddenedges"
3092 || anArgCase == "-hidden")
3094 toShowHiddenEdges = true;
3095 if (anArgIter + 1 < theArgNb
3096 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowHiddenEdges))
3101 else if (anArgCase == "-showtangentedges"
3102 || anArgCase == "-tangentedges"
3103 || anArgCase == "-tangent")
3105 toShowTangentEdges = true;
3106 if (anArgIter + 1 < theArgNb
3107 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowTangentEdges))
3112 else if (anArgIter + 1 < theArgNb
3113 && (anArgCase == "-nbiso"
3114 || anArgCase == "-nbisolines"))
3116 aNbIsolines = Draw::Atoi (theArgVec[++anArgIter]);
3118 else if (aSh.IsNull())
3120 aSh = DBRep::Get (theArgVec[anArgIter]);
3121 aShapeName = theArgVec[anArgIter];
3124 BRep_Builder aBrepBuilder;
3125 BRepTools::Read (aSh, theArgVec[anArgIter], aBrepBuilder);
3128 std::cout << "Syntax error: no shape with name " << theArgVec[anArgIter] << " found\n";
3133 else if (aHlrName.IsEmpty())
3135 aHlrName = theArgVec[anArgIter];
3137 else if (!hasViewDirArg
3138 && anArgIter + 8 < theArgNb)
3140 hasViewDirArg = true;
3142 anEye.SetCoord (Draw::Atof (theArgVec[anArgIter + 0]), Draw::Atof (theArgVec[anArgIter + 1]), Draw::Atof (theArgVec[anArgIter + 2]));
3143 aDir .SetCoord (Draw::Atof (theArgVec[anArgIter + 3]), Draw::Atof (theArgVec[anArgIter + 4]), Draw::Atof (theArgVec[anArgIter + 5]));
3144 anUp .SetCoord (Draw::Atof (theArgVec[anArgIter + 6]), Draw::Atof (theArgVec[anArgIter + 7]), Draw::Atof (theArgVec[anArgIter + 8]));
3145 aProjAx.SetLocation (anEye);
3146 aProjAx.SetDirection (aDir);
3147 aProjAx.SetYDirection (anUp);
3152 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n";
3157 if (aHlrName.IsEmpty() || aSh.IsNull()
3158 || (ViewerTest::GetAISContext().IsNull() && hasViewDirArg))
3160 std::cout << "Syntax error: wrong number of arguments\n";
3164 HLRAlgo_Projector aProjector (aProjAx);
3165 TopoDS_Shape aVisible[6];
3166 TopoDS_Shape aHidden[6];
3167 if (anAlgoType == Prs3d_TOH_PolyAlgo)
3169 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3170 aPolyAlgo->Projector (aProjector);
3171 aPolyAlgo->Load (aSh);
3172 aPolyAlgo->Update();
3174 HLRBRep_PolyHLRToShape aHLRToShape;
3175 aHLRToShape.Update (aPolyAlgo);
3177 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3178 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); // extract visible outlines
3179 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3180 if (toShowTangentEdges)
3182 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3184 if (toShowHiddenEdges)
3186 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3187 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3188 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3189 if (toShowTangentEdges)
3191 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3197 Handle(HLRBRep_Algo) aHlrAlgo = new HLRBRep_Algo();
3198 aHlrAlgo->Add (aSh, aNbIsolines);
3199 aHlrAlgo->Projector (aProjector);
3203 HLRBRep_HLRToShape aHLRToShape (aHlrAlgo);
3204 aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound();
3205 aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound();
3206 aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound();
3207 if (toShowTangentEdges)
3209 aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound();
3211 aVisible[HLRBRep_IsoLine] = aHLRToShape.IsoLineVCompound();
3213 if (toShowHiddenEdges)
3215 aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound();
3216 aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound();
3217 aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound();
3218 if (toShowTangentEdges)
3220 aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound();
3222 aHidden[HLRBRep_IsoLine] = aHLRToShape.IsoLineHCompound();
3225 //aVisible[HLRBRep_Sharp] = aHLRToShape.CompoundOfEdges (HLRBRep_Sharp, Standard_True, Standard_True);
3226 //aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound3d();
3229 TopoDS_Compound aCompRes, aCompVis, aCompHid;
3230 BRep_Builder aBuilder;
3231 aBuilder.MakeCompound (aCompVis);
3232 aBuilder.MakeCompound (aCompHid);
3233 aBuilder.MakeCompound (aCompRes);
3234 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3236 if (!aVisible[aTypeIter].IsNull())
3238 aBuilder.Add (aCompVis, aVisible[aTypeIter]);
3240 if (!aHidden[aTypeIter].IsNull())
3242 aBuilder.Add (aCompHid, aHidden[aTypeIter]);
3245 aBuilder.Add (aCompRes, aCompVis);
3246 aBuilder.Add (aCompRes, aCompHid);
3248 // create an AIS shape and display it
3249 if (!ViewerTest::GetAISContext().IsNull())
3251 Handle(AIS_ColoredShape) anObject = new AIS_ColoredShape (aCompRes);
3252 if (toShowHiddenEdges)
3254 Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect (Quantity_Color (Quantity_NOC_RED), Aspect_TOL_DASH, 1.0f);
3255 for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter)
3257 if (!aHidden[aTypeIter].IsNull())
3259 Handle(AIS_ColoredDrawer) aDrawer = anObject->CustomAspects (aHidden[aTypeIter]);
3260 aDrawer->SetLineAspect (aLineAspect);
3261 aDrawer->SetWireAspect (aLineAspect);
3262 aDrawer->SetFreeBoundaryAspect (aLineAspect);
3263 aDrawer->SetUnFreeBoundaryAspect (aLineAspect);
3267 ViewerTest::Display (aHlrName, anObject, true);
3270 DBRep::Set (aHlrName.ToCString(), aCompRes);
3274 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3275 // manipulating and displaying such an array with AIS context
3277 class MyPArrayObject : public AIS_InteractiveObject
3282 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives)& thePArray) : myPArray (thePArray) {}
3284 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
3285 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL);
3287 DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
3289 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
3293 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3294 const Handle(Prs3d_Presentation)& aPresentation,
3295 const Standard_Integer aMode) Standard_OVERRIDE;
3297 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3298 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
3300 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3301 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3302 Standard_Integer &theArgIndex,
3303 Standard_Integer theArgCount,
3304 Standard_Integer theMaxArgs);
3308 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
3309 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3310 Handle(Graphic3d_ArrayOfPrimitives) myPArray;
3314 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3315 const Handle(Prs3d_Presentation)& thePrs,
3316 const Standard_Integer theMode)
3318 if (myPArray.IsNull() || theMode != 0)
3323 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
3324 if (!myMarkerAspect.IsNull())
3326 aGroup->SetGroupPrimitivesAspect (myMarkerAspect);
3328 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
3329 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
3330 aGroup->AddPrimitiveArray (myPArray);
3333 MyPArrayObject::MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
3334 Handle(Graphic3d_AspectMarker3d) theMarkerAspect)
3336 myArrayDescription = theArrayDescription;
3337 myMarkerAspect = theMarkerAspect;
3339 // Parsing array description
3340 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3341 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3342 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
3344 Standard_Integer anArgIndex = 0;
3345 Standard_Integer anArgsCount = myArrayDescription->Length();
3346 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3348 TCollection_AsciiString aCommand;
3349 while (anArgIndex < anArgsCount)
3351 aCommand = myArrayDescription->Value (anArgIndex);
3352 aCommand.LowerCase();
3355 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3357 // vertex has a normal or normal with color or texel
3358 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3359 hasNormals = Standard_True;
3361 // vertex has a color
3362 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3363 hasVColors = Standard_True;
3365 // vertex has a texel
3366 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3367 hasTexels = Standard_True;
3372 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3375 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3376 hasBColors = Standard_True;
3381 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3390 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3391 if (anArrayType == "points")
3393 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3395 else if (anArrayType == "segments")
3396 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3397 else if (anArrayType == "polylines")
3398 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3399 hasVColors, hasBColors);
3400 else if (anArrayType == "triangles")
3401 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3402 hasVColors, hasTexels);
3403 else if (anArrayType == "trianglefans")
3404 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3405 hasNormals, hasVColors,
3406 hasBColors, hasTexels);
3407 else if (anArrayType == "trianglestrips")
3408 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3409 hasNormals, hasVColors,
3410 hasBColors, hasTexels);
3411 else if (anArrayType == "quads")
3412 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,